Produced by Araxis Merge on 2/1/2017 2:56:33 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\Araxis_Merge_Comprasion\Pub_un\BTSSS_CIF_122016.zip\BTSSS_CIF_12_20_16\clean\CRM\trunk\SDK\SampleCode\CS\GeneralProgramming\EarlyBound | Assign.cs | Tue Dec 20 19:51:45 2016 UTC |
| 2 | Wed Feb 1 19:56:33 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 275 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 2 | // This f ile is par t of the M icrosoft D ynamics CR M SDK code samples. | |||||
| 3 | // | |||||
| 4 | // Copyri ght (C) Mi crosoft Co rporation. All righ ts reserve d. | |||||
| 5 | // | |||||
| 6 | // This s ource code is intend ed only as a supplem ent to Mic rosoft | |||||
| 7 | // Develo pment Tool s and/or o n-line doc umentation . See the se other | |||||
| 8 | // materi als for de tailed inf ormation r egarding M icrosoft c ode sample s. | |||||
| 9 | // | |||||
| 10 | // THIS C ODE AND IN FORMATION ARE PROVID ED "AS IS" WITHOUT W ARRANTY OF ANY | |||||
| 11 | // KIND, EITHER EXP RESSED OR IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E | |||||
| 12 | // IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR A | |||||
| 13 | // PARTIC ULAR PURPO SE. | |||||
| 14 | // | |||||
| 15 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 16 | ||||||
| 17 | //<snippet Assign> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Service Model; | |||||
| 20 | using Syst em.Service Model.Desc ription; | |||||
| 21 | ||||||
| 22 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 23 | // found i n the SDK\ bin folder | |||||
| 24 | using Micr osoft.Xrm. Sdk; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 26 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 27 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 28 | ||||||
| 29 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 30 | { | |||||
| 31 | // / <summary > | |||||
| 32 | // / This Sam ple shows how to ass ign an acc ount to an other user . | |||||
| 33 | /// </ summary> | |||||
| 34 | /// <r emarks> | |||||
| 35 | /// No te: This s ample expe cts anothe r user to be present in | |||||
| 36 | /// th e current business u nit other than the c urrent cre dentials. | |||||
| 37 | /// </ remarks> | |||||
| 38 | ||||||
| 39 | ||||||
| 40 | pu blic class Assign | |||||
| 41 | { | |||||
| 42 | #r egion Clas s Level Me mbers | |||||
| 43 | ||||||
| 44 | ||||||
| 45 | // Define th e IDs need ed for thi s sample. | |||||
| 46 | pr ivate Guid _accountI d; | |||||
| 47 | pr ivate Guid _myUserId ; | |||||
| 48 | pr ivate Guid _otherUse rId; | |||||
| 49 | ||||||
| 50 | ||||||
| 51 | ||||||
| 52 | // Declare t he service proxy ref erring the CRUD | |||||
| 53 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 54 | pr ivate IOrg anizationS ervice _se rvice; | |||||
| 55 | ||||||
| 56 | #e ndregion C lass Level Members | |||||
| 57 | ||||||
| 58 | #r egion How To Sample Code | |||||
| 59 | // / <summary > | |||||
| 60 | // / Create a nd configu re the org anization service pr oxy. | |||||
| 61 | // / Retrieve s new owne r's detail s and crea tes an acc ount recor d. | |||||
| 62 | // / Assign t he account to new ow ner. | |||||
| 63 | // / Optional ly delete any entity records t hat were c reated for this samp le. | |||||
| 64 | // </summary > | |||||
| 65 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 66 | // / <param n ame="promp tForDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 67 | // / created entities.< /param> | |||||
| 68 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 69 | { | |||||
| 70 | try | |||||
| 71 | { | |||||
| 72 | ||||||
| 73 | // C onnect to the Organi zation ser vice. | |||||
| 74 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 75 | usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri, | |||||
| 76 | s erverConfi g.Credenti als, serve rConfig.De viceCreden tials)) | |||||
| 77 | { | |||||
| 78 | // This st atement is required to enable early-boun d type sup port. | |||||
| 79 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 80 | ||||||
| 81 | _service = (IOrganiz ationServi ce)_servic eProxy; | |||||
| 82 | ||||||
| 83 | // Call th e method t o create a ny data th at this sa mple requi res. | |||||
| 84 | CreateRequ iredRecord s(); | |||||
| 85 | ||||||
| 86 | //<snippet Assign1> | |||||
| 87 | // Create the Reques t Object a nd Set the Request O bject's Pr operties | |||||
| 88 | AssignRequ est assign = new Ass ignRequest | |||||
| 89 | { | |||||
| 90 | As signee = n ew EntityR eference(S ystemUser. EntityLogi calName, | |||||
| 91 | _otherUs erId), | |||||
| 92 | Ta rget = new EntityRef erence(Acc ount.Entit yLogicalNa me, | |||||
| 93 | _account Id) | |||||
| 94 | }; | |||||
| 95 | ||||||
| 96 | ||||||
| 97 | // Execute the Reque st | |||||
| 98 | _service.E xecute(ass ign); | |||||
| 99 | //</snippe tAssign1> | |||||
| 100 | ||||||
| 101 | Console.Wr iteLine("T he account is owned by new own er."); | |||||
| 102 | ||||||
| 103 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 104 | ||||||
| 105 | } | |||||
| 106 | } | |||||
| 107 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 108 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 109 | { | |||||
| 110 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 111 | thro w; | |||||
| 112 | } | |||||
| 113 | } | |||||
| 114 | ||||||
| 115 | ||||||
| 116 | // / <summary > | |||||
| 117 | // / This met hod create s any enti ty records that this sample re quires. | |||||
| 118 | // / Retrieve s the user details. | |||||
| 119 | // / Create a n account record. | |||||
| 120 | // / </summar y> | |||||
| 121 | pu blic void CreateRequ iredRecord s() | |||||
| 122 | { | |||||
| 123 | WhoAmIRe quest user Request = new WhoAmI Request(); | |||||
| 124 | WhoAmIRe sponse use r = (WhoAm IResponse) _service.E xecute(use rRequest); | |||||
| 125 | ||||||
| 126 | // Curre nt user. | |||||
| 127 | _myUserI d = user.U serId; | |||||
| 128 | ||||||
| 129 | // Query to retrie ve other u sers. | |||||
| 130 | QueryExp ression qu erySystemU ser = new QueryExpre ssion | |||||
| 131 | { | |||||
| 132 | Enti tyName = S ystemUser. EntityLogi calName, | |||||
| 133 | Colu mnSet = ne w ColumnSe t(new Stri ng[] { "sy stemuserid ", "fullna me" }), | |||||
| 134 | Crit eria = new FilterExp ression() | |||||
| 135 | }; | |||||
| 136 | ||||||
| 137 | querySys temUser.Cr iteria.Add Condition( "businessu nitid", | |||||
| 138 | Cond itionOpera tor.Equal, user.Busi nessUnitId ); | |||||
| 139 | querySys temUser.Cr iteria.Add Condition( "systemuse rid", | |||||
| 140 | Cond itionOpera tor.NotEqu al, _myUse rId); | |||||
| 141 | // Exclu ding SYSTE M user. | |||||
| 142 | querySys temUser.Cr iteria.Add Condition( "lastname" , | |||||
| 143 | Cond itionOpera tor.NotEqu al, "SYSTE M"); | |||||
| 144 | // Exclu ding INTEG RATION use r. | |||||
| 145 | querySys temUser.Cr iteria.Add Condition( "lastname" , | |||||
| 146 | Cond itionOpera tor.NotEqu al, "INTEG RATION"); | |||||
| 147 | ||||||
| 148 | DataColl ection<Ent ity> other Users = _s ervice.Ret rieveMulti ple( | |||||
| 149 | quer ySystemUse r).Entitie s; | |||||
| 150 | ||||||
| 151 | int coun t = _servi ce.Retriev eMultiple( querySyste mUser).Ent ities.Coun t; | |||||
| 152 | if ( cou nt > 0) | |||||
| 153 | { | |||||
| 154 | _oth erUserId = (Guid)oth erUsers[co unt-1].Att ributes["s ystemuseri d"]; | |||||
| 155 | ||||||
| 156 | Cons ole.WriteL ine("Retri eved new o wner {0} f or assignm ent.", | |||||
| 157 | otherUsers [count - 1 ].Attribut es["fullna me"]); | |||||
| 158 | } | |||||
| 159 | else | |||||
| 160 | { | |||||
| 161 | thro w new Faul tException ( | |||||
| 162 | "No other user found in the cu rrent busi ness unit for assign ment."); | |||||
| 163 | } | |||||
| 164 | ||||||
| 165 | // Creat e an Accou nt record | |||||
| 166 | Account newAccount = new Acc ount | |||||
| 167 | { | |||||
| 168 | Name = "Exampl e Account" | |||||
| 169 | }; | |||||
| 170 | ||||||
| 171 | _account Id = _serv ice.Create (newAccoun t); | |||||
| 172 | Console. WriteLine( "Created { 0}", newAc count.Name ); | |||||
| 173 | ||||||
| 174 | return; | |||||
| 175 | } | |||||
| 176 | ||||||
| 177 | // / <summary > | |||||
| 178 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 179 | // / <param n ame="promp t">Indicat es whether to prompt the user to delete | |||||
| 180 | // / the reco rds create d in this sample.</p aram> | |||||
| 181 | // / </summar y> | |||||
| 182 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 183 | { | |||||
| 184 | bool del eteRecords = true; | |||||
| 185 | ||||||
| 186 | if (prom pt) | |||||
| 187 | { | |||||
| 188 | Cons ole.WriteL ine("\nDo you want t hese entit y records deleted? ( y/n) [y]: "); | |||||
| 189 | Stri ng answer = Console. ReadLine() ; | |||||
| 190 | ||||||
| 191 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ) || answe r == Strin g.Empty); | |||||
| 192 | } | |||||
| 193 | ||||||
| 194 | if (dele teRecords) | |||||
| 195 | { | |||||
| 196 | _ser vice.Delet e(Account. EntityLogi calName, _ accountId) ; | |||||
| 197 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 198 | } | |||||
| 199 | } | |||||
| 200 | ||||||
| 201 | #e ndregion H ow To Samp le Code | |||||
| 202 | ||||||
| 203 | #r egion Main | |||||
| 204 | // / <summary > | |||||
| 205 | // / Standard Main() me thod used by most SD K samples. | |||||
| 206 | // / </summar y> | |||||
| 207 | // / <param n ame="args" ></param> | |||||
| 208 | st atic publi c void Mai n(string[] args) | |||||
| 209 | { | |||||
| 210 | try | |||||
| 211 | { | |||||
| 212 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 213 | // c redentials from the user. | |||||
| 214 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 215 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 216 | ||||||
| 217 | Assi gn app = n ew Assign( ); | |||||
| 218 | app. Run(config , true); | |||||
| 219 | } | |||||
| 220 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 221 | { | |||||
| 222 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 223 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 224 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 225 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 226 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 227 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 228 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 229 | } | |||||
| 230 | catch (S ystem.Time outExcepti on ex) | |||||
| 231 | { | |||||
| 232 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 233 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 234 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 235 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 236 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 237 | } | |||||
| 238 | catch (S ystem.Exce ption ex) | |||||
| 239 | { | |||||
| 240 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 241 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 242 | ||||||
| 243 | // D isplay the details o f the inne r exceptio n. | |||||
| 244 | if ( ex.InnerEx ception != null) | |||||
| 245 | { | |||||
| 246 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 247 | ||||||
| 248 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e | |||||
| 249 | = ex.I nnerExcept ion | |||||
| 250 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 251 | if (fe != null) | |||||
| 252 | { | |||||
| 253 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 254 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 255 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 256 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 257 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 258 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 259 | } | |||||
| 260 | } | |||||
| 261 | } | |||||
| 262 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 263 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 264 | ||||||
| 265 | finally | |||||
| 266 | { | |||||
| 267 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 268 | Cons ole.ReadLi ne(); | |||||
| 269 | } | |||||
| 270 | ||||||
| 271 | } | |||||
| 272 | #e ndregion M ain | |||||
| 273 | } | |||||
| 274 | } | |||||
| 275 | //</snippe tAssign> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.