Produced by Araxis Merge on 2/1/2017 2:56:23 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\BusinessDataModel\BusinessManagement | CreateConnection.cs | Tue Dec 20 19:51:44 2016 UTC |
| 2 | Wed Feb 1 19:56:23 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 308 |
| 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 CreateConn ection> | |||||
| 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 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 29 | ||||||
| 30 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 31 | // found i n the SDK\ bin folder . | |||||
| 32 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 33 | ||||||
| 34 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 35 | { | |||||
| 36 | /// <s ummary> | |||||
| 37 | /// Th is sample shows how to create a connecti on between two entit ies. | |||||
| 38 | /// </ summary> | |||||
| 39 | public class Cre ateConnect ion | |||||
| 40 | { | |||||
| 41 | #r egion Clas s Level Me mbers | |||||
| 42 | ||||||
| 43 | // / <summary > | |||||
| 44 | // / Stores t he organiz ation serv ice proxy. | |||||
| 45 | // / </summar y> | |||||
| 46 | Or ganization ServicePro xy _servic eProxy; | |||||
| 47 | ||||||
| 48 | // Define th e IDs need ed for thi s sample. | |||||
| 49 | pu blic Guid _connectio nRoleId; | |||||
| 50 | pu blic Guid _connectio nId; | |||||
| 51 | pu blic Guid _accountId ; | |||||
| 52 | pu blic Guid _contactId ; | |||||
| 53 | ||||||
| 54 | #e ndregion C lass Level Members | |||||
| 55 | ||||||
| 56 | #r egion How To Sample Code | |||||
| 57 | // / <summary > | |||||
| 58 | // / Create a nd configu re the org anization service pr oxy. | |||||
| 59 | // / Call the method to create an y data tha t this sam ple requir es. | |||||
| 60 | // / Create a new conne ction betw een the ac count and the contac t. | |||||
| 61 | // / Optional ly delete any entity records t hat were c reated for this samp le. | |||||
| 62 | // / </summar y> | |||||
| 63 | /// <param nam e="serverC onfig">Con tains serv er connect ion inform ation.</pa ram> | |||||
| 64 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 65 | // / created entities.< /param> | |||||
| 66 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 67 | { | |||||
| 68 | try | |||||
| 69 | { | |||||
| 70 | // C onnect to the Organi zation ser vice. | |||||
| 71 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 72 | usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri, | |||||
| 73 | s erverConfi g.Credenti als, serve rConfig.De viceCreden tials)) | |||||
| 74 | { | |||||
| 75 | // This st atement is required to enable early-boun d type sup port. | |||||
| 76 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 77 | ||||||
| 78 | ||||||
| 79 | // Call th e method t o create a ny data th at this sa mple requi res. | |||||
| 80 | CreateRequ iredRecord s(); | |||||
| 81 | ||||||
| 82 | //<snippet CreateConn ection1> | |||||
| 83 | // Create a connecti on between the accou nt and the contact. | |||||
| 84 | // Assign a connecti on role to a record. | |||||
| 85 | Connection newConnec tion = new Connectio n | |||||
| 86 | { | |||||
| 87 | Record 1Id = new EntityRefe rence(Acco unt.Entity LogicalNam e, | |||||
| 88 | _a ccountId), | |||||
| 89 | Record 1RoleId = new Entity Reference( Connection Role.Entit yLogicalNa me, | |||||
| 90 | _c onnectionR oleId), | |||||
| 91 | Record 2RoleId = new Entity Reference( Connection Role.Entit yLogicalNa me, | |||||
| 92 | _c onnectionR oleId), | |||||
| 93 | Record 2Id = new EntityRefe rence(Cont act.Entity LogicalNam e, | |||||
| 94 | _c ontactId) | |||||
| 95 | }; | |||||
| 96 | ||||||
| 97 | _connectio nId = _ser viceProxy. Create(new Connection ); | |||||
| 98 | //</snippe tCreateCon nection1> | |||||
| 99 | ||||||
| 100 | Console.Wr iteLine( | |||||
| 101 | "Creat ed a conne ction betw een the ac count and the contac t."); | |||||
| 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 | // / <summary > | |||||
| 116 | // / This met hod create s any enti ty records that this sample re quires. | |||||
| 117 | // / Create a new conne ctionrole instance. | |||||
| 118 | // / Create r elated Con nection Ro le Object Type Code records | |||||
| 119 | // / for the account an d the cont act entiti es. | |||||
| 120 | // / </summar y> | |||||
| 121 | pu blic void CreateRequ iredRecord s() | |||||
| 122 | { | |||||
| 123 | // Creat e a Connec tion Role for accoun t and cont act | |||||
| 124 | Connecti onRole new Connection Role = new Connectio nRole | |||||
| 125 | { | |||||
| 126 | Name = "Exampl e Connecti on Role", | |||||
| 127 | Cate gory = new OptionSet Value((int )connectio nrole_cate gory.Busin ess) | |||||
| 128 | }; | |||||
| 129 | ||||||
| 130 | _connect ionRoleId = _service Proxy.Crea te(newConn ectionRole ); | |||||
| 131 | Console. WriteLine( "Created { 0}.", newC onnectionR ole.Name); | |||||
| 132 | ||||||
| 133 | // Creat e a relate d Connecti on Role Ob ject Type Code recor d for Acco unt | |||||
| 134 | Connecti onRoleObje ctTypeCode newAccoun tConnectio nRoleTypeC ode | |||||
| 135 | = ne w Connecti onRoleObje ctTypeCode | |||||
| 136 | { | |||||
| 137 | Connection RoleId = n ew EntityR eference( | |||||
| 138 | Connec tionRole.E ntityLogic alName, _c onnectionR oleId), | |||||
| 139 | Associated ObjectType Code = Acc ount.Entit yLogicalNa me | |||||
| 140 | }; | |||||
| 141 | ||||||
| 142 | _service Proxy.Crea te(newAcco untConnect ionRoleTyp eCode); | |||||
| 143 | Console. WriteLine( | |||||
| 144 | "Cre ated a rel ated Conne ction Role Object Ty pe Code re cord for A ccount." | |||||
| 145 | ); | |||||
| 146 | ||||||
| 147 | // Creat e a relate d Connecti on Role Ob ject Type Code recor d for Cont act | |||||
| 148 | Connecti onRoleObje ctTypeCode newContac tConnectio nRoleTypeC ode | |||||
| 149 | = ne w Connecti onRoleObje ctTypeCode | |||||
| 150 | { | |||||
| 151 | Connection RoleId = n ew EntityR eference( | |||||
| 152 | Connec tionRole.E ntityLogic alName, _c onnectionR oleId), | |||||
| 153 | Associated ObjectType Code = Con tact.Entit yLogicalNa me | |||||
| 154 | }; | |||||
| 155 | ||||||
| 156 | _service Proxy.Crea te(newCont actConnect ionRoleTyp eCode); | |||||
| 157 | Console. WriteLine( | |||||
| 158 | "Cre ated a rel ated Conne ction Role Object Ty pe Code re cord for C ontact." | |||||
| 159 | ); | |||||
| 160 | ||||||
| 161 | // Assoc iate the c onnection role with itself. | |||||
| 162 | Associat eRequest a ssociateCo nnectionRo les = new AssociateR equest | |||||
| 163 | { | |||||
| 164 | Targ et = new E ntityRefer ence(Conne ctionRole. EntityLogi calName, | |||||
| 165 | _connectio nRoleId), | |||||
| 166 | Rela tedEntitie s = new En tityRefere nceCollect ion() | |||||
| 167 | { | |||||
| 168 | ne w EntityRe ference(Co nnectionRo le.EntityL ogicalName , | |||||
| 169 | _connect ionRoleId) | |||||
| 170 | }, | |||||
| 171 | // T he name of the relat ionship co nnection r ole associ ation | |||||
| 172 | // r elationshi p in MS CR M. | |||||
| 173 | Rela tionship = new Relat ionship() | |||||
| 174 | { | |||||
| 175 | PrimaryEnt ityRole = EntityRole .Referenci ng, // Ref erencing o r Referenc ed based o n N:1 or 1 :N reflexi ve relatio nship. | |||||
| 176 | SchemaName = "connec tionroleas sociation_ associatio n" | |||||
| 177 | } | |||||
| 178 | }; | |||||
| 179 | ||||||
| 180 | _service Proxy.Exec ute(associ ateConnect ionRoles); | |||||
| 181 | Console. WriteLine( "Associate d the conn ection rol e with its elf."); | |||||
| 182 | ||||||
| 183 | // Creat e an Accou nt | |||||
| 184 | Account setupAccou nt = new A ccount { N ame = "Exa mple Accou nt" }; | |||||
| 185 | _account Id = _serv iceProxy.C reate(setu pAccount); | |||||
| 186 | Console. WriteLine( "Created { 0}.", setu pAccount.N ame); | |||||
| 187 | ||||||
| 188 | // Creat e a Contac t | |||||
| 189 | Contact setupConta ct = new C ontact { L astName = "Example C ontact" }; | |||||
| 190 | _contact Id = _serv iceProxy.C reate(setu pContact); | |||||
| 191 | Console. WriteLine( "Created { 0}.", setu pContact.L astName); | |||||
| 192 | ||||||
| 193 | return; | |||||
| 194 | } | |||||
| 195 | ||||||
| 196 | // / <summary > | |||||
| 197 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 198 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 199 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 200 | // / </summar y> | |||||
| 201 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 202 | { | |||||
| 203 | bool toB eDeleted = true; | |||||
| 204 | ||||||
| 205 | if (prom pt) | |||||
| 206 | { | |||||
| 207 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 208 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 209 | Stri ng answer = Console. ReadLine() ; | |||||
| 210 | if ( answer.Sta rtsWith("y ") || | |||||
| 211 | answer.Sta rtsWith("Y ") || | |||||
| 212 | answer == String.Emp ty) | |||||
| 213 | { | |||||
| 214 | toBeDelete d = true; | |||||
| 215 | } | |||||
| 216 | else | |||||
| 217 | { | |||||
| 218 | toBeDelete d = false; | |||||
| 219 | } | |||||
| 220 | } | |||||
| 221 | ||||||
| 222 | if (toBe Deleted) | |||||
| 223 | { | |||||
| 224 | _ser viceProxy. Delete(Con nection.En tityLogica lName, _co nnectionId ); | |||||
| 225 | _ser viceProxy. Delete(Acc ount.Entit yLogicalNa me, _accou ntId); | |||||
| 226 | _ser viceProxy. Delete(Con tact.Entit yLogicalNa me, _conta ctId); | |||||
| 227 | _ser viceProxy. Delete(Con nectionRol e.EntityLo gicalName, _connecti onRoleId); | |||||
| 228 | ||||||
| 229 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 230 | } | |||||
| 231 | } | |||||
| 232 | ||||||
| 233 | #e ndregion H ow To Samp le Code | |||||
| 234 | ||||||
| 235 | #r egion Main | |||||
| 236 | // / <summary > | |||||
| 237 | // / Standard Main() me thod used by most SD K samples. | |||||
| 238 | // / </summar y> | |||||
| 239 | // / <param n ame="args" ></param> | |||||
| 240 | st atic publi c void Mai n(string[] args) | |||||
| 241 | { | |||||
| 242 | try | |||||
| 243 | { | |||||
| 244 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 245 | // c redentials from the user. | |||||
| 246 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 247 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 248 | ||||||
| 249 | Crea teConnecti on app = n ew CreateC onnection( ); | |||||
| 250 | app. Run(config , true); | |||||
| 251 | } | |||||
| 252 | ||||||
| 253 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 254 | { | |||||
| 255 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 256 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 257 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 258 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 259 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 260 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 261 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 262 | } | |||||
| 263 | catch (S ystem.Time outExcepti on ex) | |||||
| 264 | { | |||||
| 265 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 266 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 267 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 268 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 269 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 270 | } | |||||
| 271 | catch (S ystem.Exce ption ex) | |||||
| 272 | { | |||||
| 273 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 274 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 275 | ||||||
| 276 | // D isplay the details o f the inne r exceptio n. | |||||
| 277 | if ( ex.InnerEx ception != null) | |||||
| 278 | { | |||||
| 279 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 280 | ||||||
| 281 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e | |||||
| 282 | = ex.I nnerExcept ion | |||||
| 283 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 284 | if (fe != null) | |||||
| 285 | { | |||||
| 286 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 287 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 288 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 289 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 290 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 291 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 292 | } | |||||
| 293 | } | |||||
| 294 | } | |||||
| 295 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 296 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 297 | ||||||
| 298 | finally | |||||
| 299 | { | |||||
| 300 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 301 | Cons ole.ReadLi ne(); | |||||
| 302 | } | |||||
| 303 | ||||||
| 304 | } | |||||
| 305 | #e ndregion M ain | |||||
| 306 | } | |||||
| 307 | } | |||||
| 308 | //</snippe tCreateCon nection> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.