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 | InitializeFrom.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 | 270 |
| 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 | //<snippet Initialize From> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Service Model; | |||||
| 19 | ||||||
| 20 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 21 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 22 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 23 | ||||||
| 24 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 25 | // found i n the SDK\ bin folder . | |||||
| 26 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 27 | ||||||
| 28 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 29 | { | |||||
| 30 | /// <s ummary> | |||||
| 31 | /// Th is sample shows how to use the Initializ eFrom mess age to cre ate new re cords | |||||
| 32 | /// fr om existin g records | |||||
| 33 | /// </ summary> | |||||
| 34 | /// <p aram name= "serverCon fig">Conta ins server connectio n informat ion.</para m> | |||||
| 35 | /// <p aram name= "promptfor Delete">Wh en True, t he user wi ll be prom pted to de lete all | |||||
| 36 | /// cr eated enti ties.</par am> | |||||
| 37 | public class Ini tializeFro m | |||||
| 38 | { | |||||
| 39 | #r egion Clas s Level Me mbers | |||||
| 40 | ||||||
| 41 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 42 | ||||||
| 43 | pr ivate Acco unt _initi alAccount; | |||||
| 44 | pr ivate Lead _initialL ead; | |||||
| 45 | ||||||
| 46 | #e ndregion C lass Level Members | |||||
| 47 | ||||||
| 48 | #r egion How To Sample Code | |||||
| 49 | // / <summary > | |||||
| 50 | // / This met hod first creates an account a nd a lead, then init ializes a new | |||||
| 51 | // / account from the a lready exi sting acco unt and a new opport unity from the | |||||
| 52 | // / already existing l ead. | |||||
| 53 | // / </summar y> | |||||
| 54 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 55 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 56 | // / created entities.< /param> | |||||
| 57 | ||||||
| 58 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 59 | { | |||||
| 60 | try | |||||
| 61 | { | |||||
| 62 | // C onnect to the Organi zation ser vice. | |||||
| 63 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly | |||||
| 64 | // d isposed. | |||||
| 65 | usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri,server Config.Cre dentials, serverConf ig.DeviceC redentials )) | |||||
| 66 | { | |||||
| 67 | // This st atement is required to enable early-boun d type sup port. | |||||
| 68 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 69 | ||||||
| 70 | CreateRequ iredRecord s(); | |||||
| 71 | ||||||
| 72 | //<snippet Initialize From1> | |||||
| 73 | ||||||
| 74 | #region In itialize A ccount fro m Account | |||||
| 75 | Console.Wr iteLine(); | |||||
| 76 | Console.Wr iteLine(" Initializ ing new Ac count from the initi al Account "); | |||||
| 77 | ||||||
| 78 | // Create the reques t object | |||||
| 79 | Initialize FromReques t initiali ze = new I nitializeF romRequest (); | |||||
| 80 | ||||||
| 81 | // Set the propertie s of the r equest obj ect | |||||
| 82 | initialize .TargetEnt ityName = Account.En tityLogica lName.ToSt ring(); | |||||
| 83 | ||||||
| 84 | // Create the Entity Moniker | |||||
| 85 | initialize .EntityMon iker = _in itialAccou nt.ToEntit yReference (); | |||||
| 86 | ||||||
| 87 | // Execute the reque st | |||||
| 88 | Initialize FromRespon se initial ized = | |||||
| 89 | (Initi alizeFromR esponse)_s erviceProx y.Execute( initialize ); | |||||
| 90 | ||||||
| 91 | if (initia lized.Enti ty != null ) | |||||
| 92 | Consol e.WriteLin e(" New A ccount ini tialized s uccessfull y"); | |||||
| 93 | ||||||
| 94 | Console.Wr iteLine(); | |||||
| 95 | #endregion | |||||
| 96 | ||||||
| 97 | #region In itialize O pportunity from Lead | |||||
| 98 | Console.Wr iteLine(" Initializ ing an Opp ortunity f rom the in itial Lead "); | |||||
| 99 | ||||||
| 100 | // Create the reques t object | |||||
| 101 | initialize .TargetEnt ityName = Opportunit y.EntityLo gicalName. ToString() ; | |||||
| 102 | ||||||
| 103 | // Create the Entity Moniker | |||||
| 104 | initialize .EntityMon iker = _in itialLead. ToEntityRe ference(); | |||||
| 105 | ||||||
| 106 | // Execute the reque st | |||||
| 107 | initialize d = | |||||
| 108 | (Initi alizeFromR esponse)_s erviceProx y.Execute( initialize ); | |||||
| 109 | ||||||
| 110 | if (initia lized.Enti ty != null && | |||||
| 111 | initia lized.Enti ty.Logical Name == Op portunity. EntityLogi calName) | |||||
| 112 | { | |||||
| 113 | var op portunity = (Opportu nity)initi alized.Ent ity; | |||||
| 114 | Consol e.WriteLin e(" New O pportunity initializ ed success fully (Nam e={0})", | |||||
| 115 | op portunity. Name); | |||||
| 116 | } | |||||
| 117 | #endregion | |||||
| 118 | //</snippe tInitializ eFrom1> | |||||
| 119 | ||||||
| 120 | DeleteRequ iredRecord s(promptfo rDelete); | |||||
| 121 | } | |||||
| 122 | } | |||||
| 123 | ||||||
| 124 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 125 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 126 | { | |||||
| 127 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 128 | thro w; | |||||
| 129 | } | |||||
| 130 | } | |||||
| 131 | ||||||
| 132 | #r egion Publ ic methods | |||||
| 133 | ||||||
| 134 | // / <summary > | |||||
| 135 | // / Creates any entity records t hat this s ample requ ires. | |||||
| 136 | // / </summar y> | |||||
| 137 | pu blic void CreateRequ iredRecord s() | |||||
| 138 | { | |||||
| 139 | _initial Account = new Accoun t() | |||||
| 140 | { | |||||
| 141 | Name = "Contos o, Ltd" | |||||
| 142 | }; | |||||
| 143 | _initial Account.Id = _servic eProxy.Cre ate(_initi alAccount) ; | |||||
| 144 | Console. WriteLine( " Created initial A ccount (Na me={0})", | |||||
| 145 | _ini tialAccoun t.Name); | |||||
| 146 | ||||||
| 147 | _initial Lead = new Lead() | |||||
| 148 | { | |||||
| 149 | Subj ect = "A S ample Lead ", | |||||
| 150 | Last Name = "Wi lcox", | |||||
| 151 | Firs tName = "C olin", | |||||
| 152 | }; | |||||
| 153 | _initial Lead.Id = _servicePr oxy.Create (_initialL ead); | |||||
| 154 | Console. WriteLine( " Created initial L ead (Subje ct={0}, Na me={1} {2} )", | |||||
| 155 | _ini tialLead.S ubject, | |||||
| 156 | _ini tialLead.F irstName, | |||||
| 157 | _ini tialLead.L astName); | |||||
| 158 | } | |||||
| 159 | ||||||
| 160 | // / <summary > | |||||
| 161 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 162 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 163 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 164 | // / </summar y> | |||||
| 165 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 166 | { | |||||
| 167 | bool toB eDeleted = true; | |||||
| 168 | ||||||
| 169 | if (prom pt) | |||||
| 170 | { | |||||
| 171 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 172 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 173 | Stri ng answer = Console. ReadLine() ; | |||||
| 174 | if ( answer.Sta rtsWith("y ") || | |||||
| 175 | answer.Sta rtsWith("Y ") || | |||||
| 176 | answer == String.Emp ty) | |||||
| 177 | { | |||||
| 178 | toBeDelete d = true; | |||||
| 179 | } | |||||
| 180 | else | |||||
| 181 | { | |||||
| 182 | toBeDelete d = false; | |||||
| 183 | } | |||||
| 184 | } | |||||
| 185 | ||||||
| 186 | if (toBe Deleted) | |||||
| 187 | { | |||||
| 188 | _ser viceProxy. Delete(Acc ount.Entit yLogicalNa me, _initi alAccount. Id); | |||||
| 189 | _ser viceProxy. Delete(Lea d.EntityLo gicalName, _initialL ead.Id); | |||||
| 190 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 191 | } | |||||
| 192 | } | |||||
| 193 | #e ndregion P ublic Meth ods | |||||
| 194 | ||||||
| 195 | #e ndregion H ow To Samp le Code | |||||
| 196 | ||||||
| 197 | #r egion Main method | |||||
| 198 | ||||||
| 199 | // / <summary > | |||||
| 200 | // / Standard Main() me thod used by most SD K samples. | |||||
| 201 | // / </summar y> | |||||
| 202 | // / <param n ame="args" ></param> | |||||
| 203 | st atic publi c void Mai n(string[] args) | |||||
| 204 | { | |||||
| 205 | try | |||||
| 206 | { | |||||
| 207 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 208 | // c redentials from the user. | |||||
| 209 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 210 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 211 | ||||||
| 212 | Init ializeFrom app = new Initializ eFrom(); | |||||
| 213 | app. Run(config , true); | |||||
| 214 | } | |||||
| 215 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 216 | { | |||||
| 217 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 218 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 219 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 220 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 221 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 222 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 223 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 224 | } | |||||
| 225 | catch (S ystem.Time outExcepti on ex) | |||||
| 226 | { | |||||
| 227 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 228 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 229 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 230 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 231 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 232 | } | |||||
| 233 | catch (S ystem.Exce ption ex) | |||||
| 234 | { | |||||
| 235 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 236 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 237 | ||||||
| 238 | // D isplay the details o f the inne r exceptio n. | |||||
| 239 | if ( ex.InnerEx ception != null) | |||||
| 240 | { | |||||
| 241 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 242 | ||||||
| 243 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 244 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 245 | if (fe != null) | |||||
| 246 | { | |||||
| 247 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 248 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 249 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 250 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 251 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 252 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 253 | } | |||||
| 254 | } | |||||
| 255 | } | |||||
| 256 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 257 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 258 | ||||||
| 259 | finally | |||||
| 260 | { | |||||
| 261 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 262 | Cons ole.ReadLi ne(); | |||||
| 263 | } | |||||
| 264 | } | |||||
| 265 | ||||||
| 266 | #e ndregion M ain method | |||||
| 267 | } | |||||
| 268 | } | |||||
| 269 | //</snippe tInitializ eFrom> | |||||
| 270 |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.