Produced by Araxis Merge on 2/1/2017 2:56:31 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\DeploymentService | UseAsyncDeploymentServiceMessages.cs | Tue Dec 20 19:51:43 2016 UTC |
| 2 | Wed Feb 1 19:56:31 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 356 |
| 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 UseAsyncDe ploymentSe rviceMessa ges> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Service Model; | |||||
| 19 | using Syst em.Threadi ng; | |||||
| 20 | ||||||
| 21 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 22 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 23 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 24 | using Micr osoft.Xrm. Sdk.Deploy ment; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Deploy ment.Proxy ; | |||||
| 26 | using Syst em.Net; | |||||
| 27 | ||||||
| 28 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 29 | { | |||||
| 30 | /// <s ummary> | |||||
| 31 | /// Th is sample demonstrat es how to use the De ployment W eb Service to create an | |||||
| 32 | /// or ganization and poll the status of the jo b. | |||||
| 33 | /// </ summary> | |||||
| 34 | /// <r emarks> | |||||
| 35 | /// At run-time, you will be given t he option to delete all the | |||||
| 36 | /// da tabase rec ords creat ed by this program. | |||||
| 37 | /// </ remarks> | |||||
| 38 | public class Use AsyncDeplo ymentServi ceMessages | |||||
| 39 | { | |||||
| 40 | #r egion Clas s Level Me mbers | |||||
| 41 | ||||||
| 42 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 43 | ||||||
| 44 | // Friendly Name for t he organiz ation data base | |||||
| 45 | pr ivate Stri ng _friend lyName = " Alpine1"; | |||||
| 46 | ||||||
| 47 | // Unique Na me for the organizat ion | |||||
| 48 | pr ivate Stri ng _unique Name = "Al pine1"; | |||||
| 49 | ||||||
| 50 | // Name of t he SQL ser ver on whi ch the org anization database i s installe d | |||||
| 51 | pr ivate Stri ng _sqlSer verName = "sqlServer Name"; | |||||
| 52 | ||||||
| 53 | // URL of th e Microsof t SQL Serv er on whic h the Micr osoft Dyna mics CRM C onnector | |||||
| 54 | // for SQL S erver Repo rting Serv ices is in stalled: | |||||
| 55 | // Format: " http://rep ortServerN ame/report server" | |||||
| 56 | pr ivate Stri ng _srsUrl = "http:/ /reportSer verName/re portserver "; | |||||
| 57 | ||||||
| 58 | // Name of t he system administra tor for th e new orga nization | |||||
| 59 | // Format: " domain\\us er" | |||||
| 60 | pr ivate Stri ng _sysAdm inName = " domain\\us er"; | |||||
| 61 | ||||||
| 62 | pr ivate Guid _organiza tionID; | |||||
| 63 | pr ivate Depl oymentServ iceClient client; | |||||
| 64 | ||||||
| 65 | #e ndregion C lass Level Members | |||||
| 66 | ||||||
| 67 | #r egion How To Sample Code | |||||
| 68 | // / <summary > | |||||
| 69 | // / Demonstr ates how t o use the Deployment Web Servi ce to crea te an orga nization | |||||
| 70 | // / and poll the statu s of the j ob. | |||||
| 71 | // / </summar y> | |||||
| 72 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 73 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete | |||||
| 74 | // / all crea ted entiti es.</param > | |||||
| 75 | ||||||
| 76 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 77 | { | |||||
| 78 | try | |||||
| 79 | { | |||||
| 80 | // C onnect to the Organi zation ser vice. | |||||
| 81 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 82 | 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 )) | |||||
| 83 | { | |||||
| 84 | // This st atement is required to enable early-boun d type sup port. | |||||
| 85 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 86 | ||||||
| 87 | CreateRequ iredRecord s(serverCo nfig, prom ptforDelet e); | |||||
| 88 | ||||||
| 89 | //<snippet UseAsyncDe ploymentSe rviceMessa ges1> | |||||
| 90 | // Instant iate Deplo ymentServi ceClient f or calling the servi ce. | |||||
| 91 | client = | |||||
| 92 | ProxyC lientHelpe r.CreateCl ient( | |||||
| 93 | new Ur i(serverCo nfig.Disco veryUri.To String() | |||||
| 94 | .R eplace("Se rvices", " Deployment ") | |||||
| 95 | .R eplace("Di scovery", "Deploymen t"))); | |||||
| 96 | ||||||
| 97 | // Setting credentia ls from th e current security c ontext. | |||||
| 98 | if (server Config.Cre dentials = = null) | |||||
| 99 | { | |||||
| 100 | client .ClientCre dentials.W indows.Cli entCredent ial = | |||||
| 101 | Cr edentialCa che.Defaul tNetworkCr edentials; | |||||
| 102 | } | |||||
| 103 | else | |||||
| 104 | { | |||||
| 105 | client .ClientCre dentials.W indows.Cli entCredent ial = | |||||
| 106 | se rverConfig .Credentia ls.Windows .ClientCre dential; | |||||
| 107 | } | |||||
| 108 | ||||||
| 109 | using (cli ent) | |||||
| 110 | { | |||||
| 111 | // Set propertie s for the new organi zation | |||||
| 112 | Micros oft.Xrm.Sd k.Deployme nt.Organiz ation orga nization = | |||||
| 113 | ne w Microsof t.Xrm.Sdk. Deployment .Organizat ion | |||||
| 114 | { | |||||
| 115 | Ba seCurrency Code = "US D", | |||||
| 116 | Ba seCurrency Name = "US Dollar", | |||||
| 117 | Ba seCurrency Precision = 2, | |||||
| 118 | Ba seCurrency Symbol = " $", | |||||
| 119 | Ba seLanguage Code = 103 3, | |||||
| 120 | Fr iendlyName = _friend lyName, | |||||
| 121 | Un iqueName = _uniqueNa me, | |||||
| 122 | Sq lCollation = "Latin1 _General_C I_AI", | |||||
| 123 | Sq lServerNam e = _sqlSe rverName, | |||||
| 124 | Sr sUrl = _sr sUrl, | |||||
| 125 | Sq mIsEnabled = false | |||||
| 126 | }; | |||||
| 127 | ||||||
| 128 | // Cre ate a requ est for th e deployme nt web ser vice | |||||
| 129 | // CRM server ap p pool mus t have per missions o n SQL serv er | |||||
| 130 | BeginC reateOrgan izationReq uest reque st = | |||||
| 131 | ne w BeginCre ateOrganiz ationReque st | |||||
| 132 | { | |||||
| 133 | Or ganization = organiz ation, | |||||
| 134 | Sy sAdminName = _sysAdm inName | |||||
| 135 | }; | |||||
| 136 | ||||||
| 137 | // Exe cute the r equest | |||||
| 138 | BeginC reateOrgan izationRes ponse resp onse = | |||||
| 139 | (B eginCreate Organizati onResponse )client.Ex ecute(requ est); | |||||
| 140 | ||||||
| 141 | // The operation is asynch ronous, so the respo nse object contains | |||||
| 142 | // a u nique iden tifier for the opera tion | |||||
| 143 | Guid o perationId = respons e.Operatio nId; | |||||
| 144 | ||||||
| 145 | // Ret rieve the Operation using the OperationI d | |||||
| 146 | Retrie veRequest retrieveOp erationSta tus = new RetrieveRe quest(); | |||||
| 147 | retrie veOperatio nStatus.En tityType = | |||||
| 148 | De ploymentEn tityType.D eferredOpe rationStat us; | |||||
| 149 | retrie veOperatio nStatus.In stanceTag = | |||||
| 150 | ne w EntityIn stanceId { Id = oper ationId }; | |||||
| 151 | ||||||
| 152 | Retrie veResponse retrieveR esponse; | |||||
| 153 | Deferr edOperatio nStatus de ferredOper ationStatu s; | |||||
| 154 | ||||||
| 155 | Consol e.WriteLin e("Retriev ing state of the job ..."); | |||||
| 156 | ||||||
| 157 | // Ret rieve the Operation State unti l Organiza tion is cr eated | |||||
| 158 | do | |||||
| 159 | { | |||||
| 160 | // Wait 3 se cs to not overload s erver | |||||
| 161 | Th read.Sleep (3000); | |||||
| 162 | ||||||
| 163 | re trieveResp onse = | |||||
| 164 | (R etrieveRes ponse)clie nt.Execute (retrieveO perationSt atus); | |||||
| 165 | ||||||
| 166 | de ferredOper ationStatu s = | |||||
| 167 | ((Deferr edOperatio nStatus)re trieveResp onse.Entit y); | |||||
| 168 | } | |||||
| 169 | while (deferredO perationSt atus.State != | |||||
| 170 | De ferredOper ationState .Processin g && | |||||
| 171 | de ferredOper ationStatu s.State != | |||||
| 172 | De ferredOper ationState .Completed ); | |||||
| 173 | ||||||
| 174 | // Pol l Organiza tionStatus Request | |||||
| 175 | Retrie veRequest retrieveRe qServer = new Retrie veRequest( ); | |||||
| 176 | retrie veReqServe r.EntityTy pe = Deplo ymentEntit yType.Orga nization; | |||||
| 177 | retrie veReqServe r.Instance Tag = new EntityInst anceId(); | |||||
| 178 | retrie veReqServe r.Instance Tag.Name = organizat ion.Unique Name; | |||||
| 179 | ||||||
| 180 | Retrie veResponse retrieveR espServer; | |||||
| 181 | Organi zationStat e orgState ; | |||||
| 182 | ||||||
| 183 | Consol e.WriteLin e("Retriev ing state of the org anization. .."); | |||||
| 184 | ||||||
| 185 | // Ret rieve and check the Organizati on State u ntil is en abled | |||||
| 186 | do | |||||
| 187 | { | |||||
| 188 | re trieveResp Server = | |||||
| 189 | (Retriev eResponse) client.Exe cute(retri eveReqServ er); | |||||
| 190 | _o rganizatio nID = | |||||
| 191 | ((Micros oft.Xrm.Sd k.Deployme nt.Organiz ation)retr ieveRespSe rver.Entit y).Id; | |||||
| 192 | or gState = | |||||
| 193 | ((Micros oft.Xrm.Sd k.Deployme nt.Organiz ation)retr ieveRespSe rver.Entit y).State; | |||||
| 194 | ||||||
| 195 | // Wait 5 se cs to not overload s erver | |||||
| 196 | Th read.Sleep (5000); | |||||
| 197 | } | |||||
| 198 | while (orgState != Organiz ationState .Enabled); | |||||
| 199 | ||||||
| 200 | Consol e.WriteLin e("Organiz ation has been creat ed!"); | |||||
| 201 | ||||||
| 202 | // </snippetU seAsyncDep loymentSer viceMessag es1> | |||||
| 203 | Delete RequiredRe cords(prom ptforDelet e); | |||||
| 204 | ||||||
| 205 | } | |||||
| 206 | } | |||||
| 207 | } | |||||
| 208 | ||||||
| 209 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 210 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 211 | { | |||||
| 212 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 213 | thro w; | |||||
| 214 | } | |||||
| 215 | } | |||||
| 216 | ||||||
| 217 | #r egion Publ ic methods | |||||
| 218 | ||||||
| 219 | // / <summary > | |||||
| 220 | // / Creates any entity records t hat this s ample requ ires. | |||||
| 221 | // / </summar y> | |||||
| 222 | pu blic void CreateRequ iredRecord s(ServerCo nnection.C onfigurati on config, Boolean p rompt) | |||||
| 223 | { | |||||
| 224 | // For p rompt and AD environ ment, pass current s erver deta ils. | |||||
| 225 | if (prom pt & confi g.Endpoint Type == Au thenticati onProvider Type.Activ eDirectory ) | |||||
| 226 | { | |||||
| 227 | this ._sqlServe rName = co nfig.Serve rAddress; | |||||
| 228 | this ._sysAdmin Name = con fig.Server Address + "dom\\admi nistrator" ; | |||||
| 229 | this ._srsUrl = "http://" + config. ServerAddr ess + "/re portserver "; | |||||
| 230 | } | |||||
| 231 | } | |||||
| 232 | ||||||
| 233 | // / <summary > | |||||
| 234 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 235 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 236 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 237 | // / </summar y> | |||||
| 238 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 239 | { | |||||
| 240 | bool toB eDeleted = true; | |||||
| 241 | ||||||
| 242 | if (prom pt) | |||||
| 243 | { | |||||
| 244 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 245 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 246 | Stri ng answer = Console. ReadLine() ; | |||||
| 247 | if ( answer.Sta rtsWith("y ") || | |||||
| 248 | answer.Sta rtsWith("Y ") || | |||||
| 249 | answer == String.Emp ty) | |||||
| 250 | { | |||||
| 251 | toBeDelete d = true; | |||||
| 252 | } | |||||
| 253 | else | |||||
| 254 | { | |||||
| 255 | toBeDelete d = false; | |||||
| 256 | } | |||||
| 257 | } | |||||
| 258 | ||||||
| 259 | if (toBe Deleted) | |||||
| 260 | { | |||||
| 261 | // F irst disab le the org | |||||
| 262 | Enti tyInstance Id organiz ationCreat ed = new E ntityInsta nceId(); | |||||
| 263 | orga nizationCr eated.Id = _organiza tionID; | |||||
| 264 | Micr osoft.Xrm. Sdk.Deploy ment.Organ ization or ganization = | |||||
| 265 | (Microsoft .Xrm.Sdk.D eployment. Organizati on)client. Retrieve( | |||||
| 266 | Deployment EntityType .Organizat ion, organ izationCre ated); | |||||
| 267 | ||||||
| 268 | // U pdate stat us to disa bled | |||||
| 269 | orga nization.S tate = Org anizationS tate.Disab led; | |||||
| 270 | ||||||
| 271 | clie nt.Update( organizati on); | |||||
| 272 | Cons ole.WriteL ine("Organ ization ha s been dis abled."); | |||||
| 273 | ||||||
| 274 | // S econd dele te it | |||||
| 275 | clie nt.Delete( Deployment EntityType .Organizat ion, organ izationCre ated); | |||||
| 276 | Cons ole.WriteL ine("Organ ization ha s been del eted."); | |||||
| 277 | } | |||||
| 278 | } | |||||
| 279 | #e ndregion P ublic Meth ods | |||||
| 280 | ||||||
| 281 | #e ndregion H ow To Samp le Code | |||||
| 282 | ||||||
| 283 | #r egion Main method | |||||
| 284 | ||||||
| 285 | // / <summary > | |||||
| 286 | // / Standard Main() me thod used by most SD K samples. | |||||
| 287 | // / </summar y> | |||||
| 288 | // / <param n ame="args" ></param> | |||||
| 289 | st atic publi c void Mai n(string[] args) | |||||
| 290 | { | |||||
| 291 | try | |||||
| 292 | { | |||||
| 293 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 294 | // c redentials from the user. | |||||
| 295 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 296 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 297 | ||||||
| 298 | UseA syncDeploy mentServic eMessages app = new UseAsyncDe ploymentSe rviceMessa ges(); | |||||
| 299 | app. Run(config , true); | |||||
| 300 | } | |||||
| 301 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 302 | { | |||||
| 303 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 304 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 305 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 306 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 307 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 308 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 309 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 310 | } | |||||
| 311 | catch (S ystem.Time outExcepti on ex) | |||||
| 312 | { | |||||
| 313 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 314 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 315 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 316 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 317 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 318 | } | |||||
| 319 | catch (S ystem.Exce ption ex) | |||||
| 320 | { | |||||
| 321 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 322 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 323 | ||||||
| 324 | // D isplay the details o f the inne r exceptio n. | |||||
| 325 | if ( ex.InnerEx ception != null) | |||||
| 326 | { | |||||
| 327 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 328 | ||||||
| 329 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 330 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 331 | if (fe != null) | |||||
| 332 | { | |||||
| 333 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 334 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 335 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 336 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 337 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 338 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 339 | } | |||||
| 340 | } | |||||
| 341 | } | |||||
| 342 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 343 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 344 | ||||||
| 345 | finally | |||||
| 346 | { | |||||
| 347 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 348 | Cons ole.ReadLi ne(); | |||||
| 349 | } | |||||
| 350 | } | |||||
| 351 | ||||||
| 352 | #e ndregion M ain method | |||||
| 353 | } | |||||
| 354 | } | |||||
| 355 | //</snippe tUseAsyncD eploymentS erviceMess ages> | |||||
| 356 |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.