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 | AssociateDisassociate.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 | 273 |
| 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 | // | |||||
| 3 | // This f ile is par t of the M icrosoft D ynamics CR M SDK code samples. | |||||
| 4 | // | |||||
| 5 | // Copyri ght (C) Mi crosoft Co rporation. All righ ts reserve d. | |||||
| 6 | // | |||||
| 7 | // This s ource code is intend ed only as a supplem ent to Mic rosoft | |||||
| 8 | // Develo pment Tool s and/or o n-line doc umentation . See the se other | |||||
| 9 | // materi als for de tailed inf ormation r egarding M icrosoft c ode sample s. | |||||
| 10 | // | |||||
| 11 | // THIS C ODE AND IN FORMATION ARE PROVID ED "AS IS" WITHOUT W ARRANTY OF ANY | |||||
| 12 | // KIND, EITHER EXP RESSED OR IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E | |||||
| 13 | // IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR A | |||||
| 14 | // PARTIC ULAR PURPO SE. | |||||
| 15 | // | |||||
| 16 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 17 | //<snippet AssociateD isassociat e> | |||||
| 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.Client ; | |||||
| 26 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 27 | using Micr osoft.Xrm. Sdk.Discov ery; | |||||
| 28 | ||||||
| 29 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 30 | // found i n the SDK\ bin folder . | |||||
| 31 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 32 | ||||||
| 33 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 34 | { | |||||
| 35 | /// <s ummary> | |||||
| 36 | /// De monstrates how to as sign a que ue to a te am. | |||||
| 37 | /// If you want to run thi s sample r epeatedly, you have the option to | |||||
| 38 | /// de lete all t he records created a t the end of executi on. | |||||
| 39 | /// </ summary> | |||||
| 40 | public class Ass ociateDisa ssociate | |||||
| 41 | { | |||||
| 42 | #r egion Clas s Level Me mbers | |||||
| 43 | ||||||
| 44 | // / <summary > | |||||
| 45 | // / Stores t he organiz ation serv ice proxy. | |||||
| 46 | // / </summar y> | |||||
| 47 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 48 | pr ivate IOrg anizationS ervice _se rvice; | |||||
| 49 | ||||||
| 50 | // Define th e IDs need ed for thi s sample. | |||||
| 51 | pu blic Guid _contactId ; | |||||
| 52 | pu blic Guid _account1I d; | |||||
| 53 | pu blic Guid _account2I d; | |||||
| 54 | pu blic Guid _account3I d; | |||||
| 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 | // / Create a team, a q ueue and a role. | |||||
| 62 | // / Add read queue pri vileges to the role. | |||||
| 63 | // / Assign t he role to the team so that th ey can rea d the queu e. | |||||
| 64 | // / Assign t he queue t o the team . | |||||
| 65 | // / Optional ly delete any entity records t hat were c reated for this samp le. | |||||
| 66 | // </summary > | |||||
| 67 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 68 | // / <param n ame="promp tForDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 69 | // / created entities.< /param> | |||||
| 70 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 71 | { | |||||
| 72 | try | |||||
| 73 | { | |||||
| 74 | ||||||
| 75 | // C onnect to the Organi zation ser vice. | |||||
| 76 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 77 | usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri, | |||||
| 78 | s erverConfi g.Credenti als, serve rConfig.De viceCreden tials)) | |||||
| 79 | { | |||||
| 80 | // This st atement is required to enable early-boun d type sup port. | |||||
| 81 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 82 | ||||||
| 83 | _service = (IOrganiz ationServi ce)_servic eProxy; | |||||
| 84 | ||||||
| 85 | // Call th e method t o create a ny data th at this sa mple requi res. | |||||
| 86 | CreateRequ iredRecord s(); | |||||
| 87 | ||||||
| 88 | //<snippet AssociateD isassociat e1> | |||||
| 89 | // Associa te the acc ounts to t he contact record. | |||||
| 90 | ||||||
| 91 | // Create a collecti on of the entities t hat will b e | |||||
| 92 | // associa ted to the contact. | |||||
| 93 | EntityRefe renceColle ction rela tedEntitie s = new En tityRefere nceCollect ion(); | |||||
| 94 | relatedEnt ities.Add( new Entity Reference( Account.En tityLogica lName, _ac count1Id)) ; | |||||
| 95 | relatedEnt ities.Add( new Entity Reference( Account.En tityLogica lName, _ac count2Id)) ; | |||||
| 96 | relatedEnt ities.Add( new Entity Reference( Account.En tityLogica lName, _ac count3Id)) ; | |||||
| 97 | ||||||
| 98 | // Create an object that defin es the rel ationship between th e contact and accoun t. | |||||
| 99 | Relationsh ip relatio nship = ne w Relation ship("acco unt_primar y_contact" ); | |||||
| 100 | ||||||
| 101 | ||||||
| 102 | //Associat e the cont act with t he 3 accou nts. | |||||
| 103 | _service.A ssociate(C ontact.Ent ityLogical Name, _con tactId, re lationship , | |||||
| 104 | relate dEntities) ; | |||||
| 105 | ||||||
| 106 | Console.Wr iteLine("T he entitie s have bee n associat ed."); | |||||
| 107 | ||||||
| 108 | //Disassoc iate the r ecords. | |||||
| 109 | _service.D isassociat e(Contact. EntityLogi calName, _ contactId, relations hip, | |||||
| 110 | relate dEntities) ; | |||||
| 111 | ||||||
| 112 | //</snippe tAssociate Disassocia te1> | |||||
| 113 | ||||||
| 114 | Console.Wr iteLine("T he entitie s have bee n disassoc iated."); | |||||
| 115 | ||||||
| 116 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 117 | } | |||||
| 118 | } | |||||
| 119 | ||||||
| 120 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 121 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 122 | { | |||||
| 123 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 124 | thro w; | |||||
| 125 | } | |||||
| 126 | } | |||||
| 127 | ||||||
| 128 | // / <summary > | |||||
| 129 | // / This met hod create s any enti ty records that this sample re quires. | |||||
| 130 | // / Create a team, a q ueue and a role. | |||||
| 131 | // / Add read queue pri vileges to the role. | |||||
| 132 | // / Assign t he role to the team so that th ey can rea d the queu e. | |||||
| 133 | // / Assign t he queue t o the team . | |||||
| 134 | // / </summar y> | |||||
| 135 | pu blic void CreateRequ iredRecord s() | |||||
| 136 | { | |||||
| 137 | // Insta ntiate a c ontact ent ity record and set i ts propert y values. | |||||
| 138 | // See t he Entity Metadata t opic in th e SDK docu mentatio t o determin e | |||||
| 139 | // which attribute s must be set for ea ch entity. | |||||
| 140 | Contact setupConta ct = new C ontact | |||||
| 141 | { | |||||
| 142 | Fir stName = " John", | |||||
| 143 | Las tName = "D oe" | |||||
| 144 | }; | |||||
| 145 | _contact Id = _serv ice.Create (setupCont act); | |||||
| 146 | Console. WriteLine( "Created { 0} {1}", s etupContac t.FirstNam e, | |||||
| 147 | setu pContact.L astName); | |||||
| 148 | ||||||
| 149 | // Insta ntiate an account en tity recor d and set its proper ty values. | |||||
| 150 | Account setupAccou nt1 = new Account | |||||
| 151 | { | |||||
| 152 | Name = "Exampl e Account 1" | |||||
| 153 | }; | |||||
| 154 | _account 1Id = _ser vice.Creat e(setupAcc ount1); | |||||
| 155 | Console. WriteLine( "Created { 0}", setup Account1.N ame); | |||||
| 156 | ||||||
| 157 | Account setupAccou nt2 = new Account | |||||
| 158 | { | |||||
| 159 | Name = "Exampl e Account 2" | |||||
| 160 | }; | |||||
| 161 | _account 2Id = _ser vice.Creat e(setupAcc ount2); | |||||
| 162 | Console. WriteLine( "Created { 0}", setup Account2.N ame); | |||||
| 163 | ||||||
| 164 | Account setupAccou nt3 = new Account | |||||
| 165 | { | |||||
| 166 | Name = "Exampl e Account 3" | |||||
| 167 | }; | |||||
| 168 | _account 3Id = _ser vice.Creat e(setupAcc ount3); | |||||
| 169 | Console. WriteLine( "Created { 0}", setup Account3.N ame); | |||||
| 170 | } | |||||
| 171 | ||||||
| 172 | // / <summary > | |||||
| 173 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 174 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 175 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 176 | // / </summar y> | |||||
| 177 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 178 | { | |||||
| 179 | bool del eteRecords = true; | |||||
| 180 | ||||||
| 181 | if (prom pt) | |||||
| 182 | { | |||||
| 183 | Cons ole.WriteL ine("\nDo you want t hese entit y records deleted? ( y/n)"); | |||||
| 184 | Stri ng answer = Console. ReadLine() ; | |||||
| 185 | ||||||
| 186 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" )); | |||||
| 187 | } | |||||
| 188 | ||||||
| 189 | if (dele teRecords) | |||||
| 190 | { | |||||
| 191 | _ser vice.Delet e("account ", _accoun t1Id); | |||||
| 192 | _ser vice.Delet e("account ", _accoun t2Id); | |||||
| 193 | _ser vice.Delet e("account ", _accoun t3Id); | |||||
| 194 | ||||||
| 195 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 196 | } | |||||
| 197 | } | |||||
| 198 | ||||||
| 199 | #e ndregion H ow To Samp le Code | |||||
| 200 | ||||||
| 201 | #r egion Main | |||||
| 202 | // / <summary > | |||||
| 203 | // / Standard Main() me thod used by most SD K samples. | |||||
| 204 | // / </summar y> | |||||
| 205 | // / <param n ame="args" ></param> | |||||
| 206 | st atic publi c void Mai n(string[] args) | |||||
| 207 | { | |||||
| 208 | try | |||||
| 209 | { | |||||
| 210 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 211 | // c redentials from the user. | |||||
| 212 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 213 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 214 | ||||||
| 215 | Asso ciateDisas sociate ap p = new As sociateDis associate( ); | |||||
| 216 | app. Run(config , true); | |||||
| 217 | } | |||||
| 218 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 219 | { | |||||
| 220 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 221 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 222 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 223 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 224 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 225 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 226 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 227 | } | |||||
| 228 | catch (S ystem.Time outExcepti on ex) | |||||
| 229 | { | |||||
| 230 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 231 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 232 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 233 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 234 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 235 | } | |||||
| 236 | catch (S ystem.Exce ption ex) | |||||
| 237 | { | |||||
| 238 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 239 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 240 | ||||||
| 241 | // D isplay the details o f the inne r exceptio n. | |||||
| 242 | if ( ex.InnerEx ception != null) | |||||
| 243 | { | |||||
| 244 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 245 | ||||||
| 246 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = | |||||
| 247 | ex.Inn erExceptio n | |||||
| 248 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 249 | if (fe != null) | |||||
| 250 | { | |||||
| 251 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 252 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 253 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 254 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 255 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 256 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 257 | } | |||||
| 258 | } | |||||
| 259 | } | |||||
| 260 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 261 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 262 | ||||||
| 263 | finally | |||||
| 264 | { | |||||
| 265 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 266 | Cons ole.ReadLi ne(); | |||||
| 267 | } | |||||
| 268 | ||||||
| 269 | } | |||||
| 270 | #e ndregion M ain | |||||
| 271 | } | |||||
| 272 | } | |||||
| 273 | //</snippe tAssociate Disassocia te> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.