364. Araxis Merge File Comparison Report

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.

364.1 Files compared

# 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\DataManagement\ExecuteTransaction ExecuteTransaction.cs Tue Dec 20 19:51:43 2016 UTC
2 Wed Feb 1 19:56:31 2017 UTC

364.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 0 0
Changed 0 0
Inserted 0 0
Removed 1 390

364.3 Comparison options

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

364.4 Active regular expressions

No regular expressions were active.

364.5 Comparison detail

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   // <snippe tExecuteTr ansaction>        
17   using Syst em;        
18   using Syst em.Collect ions.Gener ic;        
19   using Syst em.Service Model;        
20   using Micr osoft.Xrm. Sdk;        
21   using Micr osoft.Xrm. Sdk.Client ;        
22   using Micr osoft.Xrm. Sdk.Metada ta;        
23   using Micr osoft.Xrm. Sdk.Messag es;        
24   using Micr osoft.Xrm. Sdk.Query;        
25          
26   namespace  Microsoft. Crm.Sdk.Sa mples        
27   {        
28       class  ExecuteTra nsaction        
29       {        
30           #r egion Clas s Level Me mbers        
31          
32           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
33           pr ivate read only List< Guid> _new AccountIds  = new Lis t<Guid>();        
34          
35           #e ndregion        
36          
37           #r egion How  To Sample  Code        
38          
39           // / <summary >        
40           // / This sam ple demons trates how  to execut e a collec tion of me ssage requ ests in a  single dat abase tran saction,         
41           // / by using  a single  web servic e call and  optionall y return t he results        
42           // / </summar y>        
43           // / <seealso  cref="htt ps://msdn. microsoft. com/en-us/ library/gg 328075.asp x#bkmk_tra nsaction"/ >        
44           // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param>        
45           // / <param n ame="promp tforDelete ">When Tru e, the use r will be  prompted t o delete a ll        
46           // / created  entities.< /param>        
47           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete)        
48           {        
49                ExecuteT ransaction Request re questToCre ateRecords  = null;        
50                try        
51                {        
52                    // G et a refer ence to th e organiza tion servi ce.        
53                    usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri, serve rConfig.Cr edentials,  serverCon fig.Device Credential s))        
54                    {        
55                         // Enable  early-boun d type sup port to ad d/update e ntity reco rds requir ed for thi s sample.        
56                         _servicePr oxy.Enable ProxyTypes ();        
57          
58                         #region Ex ecute Tran saction to  create re cords        
59                         //<snippet ExecuteTra nsaction1>        
60                         // Create  an Execute Transactio nRequest o bject.        
61                         requestToC reateRecor ds = new E xecuteTran sactionReq uest()        
62                         {        
63                             // Cre ate an emp ty organiz ation requ est collec tion.        
64                             Reques ts = new O rganizatio nRequestCo llection() ,        
65                             Return Responses  = true        
66                         };        
67          
68                         // Create  several (l ocal, in m emory) ent ities in a  collectio n.         
69                         EntityColl ection inp ut = GetCo llectionOf EntitiesTo Create();        
70          
71                         // Add a C reateReque st for eac h entity t o the requ est collec tion.        
72                         foreach (v ar entity  in input.E ntities)        
73                         {        
74                             Create Request cr eateReques t = new Cr eateReques t { Target  = entity  };        
75                             reques tToCreateR ecords.Req uests.Add( createRequ est);        
76                         }        
77          
78                         // Execute  all the r equests in  the reque st collect ion using  a single w eb method  call.        
79                         try        
80                         {        
81                             var re sponseForC reateRecor ds =        
82                                 (E xecuteTran sactionRes ponse)_ser viceProxy. Execute(re questToCre ateRecords );        
83          
84                             int i  = 0;        
85                             // Dis play the r esults ret urned in t he respons es.        
86                             foreac h (var res ponseItem  in respons eForCreate Records.Re sponses)        
87                             {        
88                                 if  (response Item != nu ll)        
89                                      DisplayR esponse(re questToCre ateRecords .Requests[ i], respon seItem);        
90                                 i+ +;        
91                             }        
92                         }        
93                         catch (Fau ltExceptio n<Organiza tionServic eFault> ex )        
94                         {        
95                             Consol e.WriteLin e("Create  request fa iled for t he account {0} and th e reason b eing: {1}" ,        
96                                 (( ExecuteTra nsactionFa ult)(ex.De tail)).Fau ltedReques tIndex + 1 , ex.Detai l.Message) ;        
97                             throw;        
98                         }        
99          
100                         //</snippe tExecuteTr ansaction1 >        
101                         #endregion  Execute T ransaction  to create  records        
102          
103                         #region Ex ecute Tran saction to  update re cords        
104                         //<snippet ExecuteTra nsaction2>        
105                         ExecuteTra nsactionRe quest requ estForUpda tes = new  ExecuteTra nsactionRe quest()        
106                         {        
107                             Reques ts = new O rganizatio nRequestCo llection()        
108                         };        
109          
110                         // Update  the entiti es that we re previou sly create d.        
111                         EntityColl ection upd ate = GetC ollectionO fEntitiesT oUpdate();        
112          
113                         foreach (v ar entity  in update. Entities)        
114                         {        
115                             Update Request up dateReques t = new Up dateReques t { Target  = entity  };        
116                             reques tForUpdate s.Requests .Add(updat eRequest);        
117                         }        
118          
119                         try        
120                         {        
121                             Execut eTransacti onResponse  responseF orUpdates  =        
122                                 (E xecuteTran sactionRes ponse)_ser viceProxy. Execute(re questForUp dates);        
123                             Consol e.WriteLin e("Entity  records ar e updated. ");        
124                         }        
125                         catch (Fau ltExceptio n<Organiza tionServic eFault> ex )        
126                         {        
127                             Consol e.WriteLin e("Update  request fa iled for t he account {0} and th e reason b eing: {1}" ,        
128                                 (( ExecuteTra nsactionFa ult)(ex.De tail)).Fau ltedReques tIndex + 1 , ex.Detai l.Message) ;        
129                         }        
130                         //</snippe tExecuteTr ansaction2 >        
131                         #endregion  Execute T ransaction  for updat e records        
132          
133                         //<snippet ExecuteTra nsaction3>        
134                         DeleteRequ iredRecord s(promptfo rDelete);        
135                         //</snippe tExecuteTr ansaction3 >        
136                    }        
137                }        
138                catch (F aultExcept ion<Organi zationServ iceFault>  fault)        
139                {        
140                    // C heck if th e maximum  batch size  has been  exceeded.  The maximu m batch si ze is only  included  in the fau lt if it        
141                    // t he input r equest col lection co unt exceed s the maxi mum batch  size.        
142                    if ( fault.Deta il.ErrorDe tails.Cont ains("MaxB atchSize") )        
143                    {        
144                         int maxBat chSize = C onvert.ToI nt32(fault .Detail.Er rorDetails ["MaxBatch Size"]);        
145                         if (maxBat chSize < r equestToCr eateRecord s.Requests .Count)        
146                         {        
147                             // Her e you coul d reduce t he size of  your requ est collec tion and r e-submit t he Execute Transactio n request.        
148                             // For  this samp le, that o nly issues  a few req uests per  batch, we  will just  print out  some info.  However,        
149                             // thi s code wil l never be  executed  because th e default  max batch  size is 10 00.        
150                             Consol e.WriteLin e("The inp ut request  collectio n contains  %0 reques ts, which  exceeds th e maximum  allowed (% 1)",        
151                                 re questToCre ateRecords .Requests. Count, max BatchSize) ;        
152                         }        
153                    }        
154                    // R e-throw so  Main() ca n process  the fault.        
155                    thro w;        
156                }        
157           }        
158          
159           #r egion Publ ic Methods        
160          
161           // / <summary >        
162           // / Deletes  any entity  records t hat were c reated for  this samp le.        
163           // / <param n ame="promp t">Indicat es whether  to prompt  the user         
164           // / to delet e the reco rds create d in this  sample.</p aram>        
165           // / </summar y>        
166           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
167           {        
168                bool del eteRecords  = true;        
169          
170                if (prom pt)        
171                {        
172                    Cons ole.WriteL ine("\nDo  you want t o delete t he account  record? ( y/n) [y]:  ");        
173                    Stri ng answer  = Console. ReadLine() ;        
174          
175                    dele teRecords  = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ) || answe r == Strin g.Empty);        
176                }        
177          
178                if (!del eteRecords )        
179                    retu rn;        
180          
181                ExecuteM ultipleReq uest reque stWithNoRe sults = ne w ExecuteM ultipleReq uest()        
182                {        
183                    // S et the exe cution beh avior to c ontinue an d to not r eturn resp onses.        
184                    Sett ings = new  ExecuteMu ltipleSett ings()        
185                    {        
186                         ContinueOn Error = tr ue,        
187                         ReturnResp onses = fa lse        
188                    },        
189                    Requ ests = new  Organizat ionRequest Collection ()        
190                };        
191          
192                // Get a ll the ent ities into  a collect ion to del ete        
193                EntityCo llection d elete = Ge tCollectio nOfEntitie sToDelete( );        
194                foreach  (var entit y in delet e.Entities )        
195                {        
196                    Dele teRequest  deleteRequ est = new  DeleteRequ est { Targ et = entit y.ToEntity Reference( ) };        
197                    requ estWithNoR esults.Req uests.Add( deleteRequ est);        
198                }        
199          
200                ExecuteM ultipleRes ponse resp onseWithNo Results =        
201                    (Exe cuteMultip leResponse )_serviceP roxy.Execu te(request WithNoResu lts);        
202          
203                // There  should be  no respon ses unless  there was  an error.          
204                if (resp onseWithNo Results.Re sponses.Co unt > 0)        
205                {        
206                    fore ach (var r esponseIte m in respo nseWithNoR esults.Res ponses)        
207                    {        
208                         if (respon seItem.Fau lt != null )        
209                             Displa yFault(req uestWithNo Results.Re quests[res ponseItem. RequestInd ex],        
210                                 re sponseItem .RequestIn dex, respo nseItem.Fa ult);        
211                    }        
212                }        
213                else        
214                {        
215                    Cons ole.WriteL ine("All a ccount rec ords have  been delet ed success fully.");        
216                }        
217           }        
218          
219           #e ndregion        
220          
221           #r egion Priv ate Method s        
222          
223           // / <summary >        
224           // / Create a  collectio n of new e ntity obje cts.        
225           // / </summar y>        
226           // / <returns >A collect ion of ent ity object s.</return s>        
227           pr ivate Enti tyCollecti on GetColl ectionOfEn titiesToCr eate()        
228           {        
229                return n ew EntityC ollection( )        
230                {        
231                    Enti tyName = A ccount.Ent ityLogical Name,        
232                    Enti ties = {        
233                         new Accoun t { Name =  "ExecuteT ransaction  Example A ccount 1"  },        
234                         new Accoun t { Name =  "ExecuteT ransaction  Example A ccount 2"  },        
235                         new Accoun t { Name =  "ExecuteT ransaction  Example A ccount 3"  },        
236                         new Accoun t { Name =  "ExecuteT ransaction  Example A ccount 4"  },        
237                         new Accoun t { Name =  "ExecuteT ransaction  Example A ccount 5"  }        
238                    }        
239                };        
240           }        
241          
242           // / <summary >        
243           // / Display  the respon se of an o rganizatio n message  request.        
244           // / </summar y>        
245           // / <param n ame="organ izationReq uest">The  organizati on message  request.< /param>        
246           // / <param n ame="organ izationRes ponse">The  organizat ion messag e response .</param>        
247           pr ivate void  DisplayRe sponse(Org anizationR equest org anizationR equest, Or ganization Response o rganizatio nResponse)        
248           {        
249                Console. WriteLine( "Created "  + ((Accou nt)organiz ationReque st.Paramet ers["Targe t"]).Name        
250                    + "  with accou nt id as "  + organiz ationRespo nse.Result s["id"].To String());        
251                _newAcco untIds.Add (new Guid( organizati onResponse .Results[" id"].ToStr ing()));        
252           }        
253          
254           // / <summary >        
255           // / Create a  collectio n of entit y objects  for updati ng. Give t hese entit ies a new        
256           // / name for  the updat e.        
257           // / </summar y>        
258           // / <returns >An entity  collectio n.</return s>        
259           pr ivate Enti tyCollecti on GetColl ectionOfEn titiesToUp date()        
260           {        
261                EntityCo llection c ollection  = new Enti tyCollecti on()        
262                {        
263                    Enti tyName = A ccount.Ent ityLogical Name        
264                };        
265          
266                for (int  i = 1; i  <= _newAcc ountIds.Co unt; i++)        
267                {        
268                    coll ection.Ent ities.Add(        
269                         new Accoun t        
270                         {        
271                             Name =  "Updated  Account Na me " + i.T oString(),        
272                             Id = _ newAccount Ids[i - 1]        
273                         });        
274                }        
275          
276                return c ollection;        
277           }        
278          
279           // / <summary >        
280           // / Delete a  collectio n of entit y objects.        
281           // / </summar y>        
282           // / <returns >A collect ion of ent ity object s</returns >        
283           pr ivate Enti tyCollecti on GetColl ectionOfEn titiesToDe lete()        
284           {        
285                EntityCo llection c ollection  = new Enti tyCollecti on()        
286                {        
287                    Enti tyName = A ccount.Ent ityLogical Name        
288                };        
289          
290                for (int  i = 1; i  <= _newAcc ountIds.Co unt; i++)        
291                {        
292                    coll ection.Ent ities.Add(        
293                         new Accoun t        
294                         {        
295                             Id = _ newAccount Ids[i - 1]        
296                         });        
297                }        
298          
299                return c ollection;        
300           }        
301          
302           // / <summary >        
303           // / Display  the fault  that resul ted from p rocessing  an organiz ation mess age reques t.        
304           // / </summar y>        
305           // / <param n ame="organ izationReq uest">The  organizati on message  request.< /param>        
306           // / <param n ame="count ">nth requ est number  from Exec uteMultipl e request< /param>        
307           // / <param n ame="organ izationSer viceFault" >A WCF fau lt.</param >        
308           pr ivate void  DisplayFa ult(Organi zationRequ est organi zationRequ est, int c ount,        
309                Organiza tionServic eFault org anizationS erviceFaul t)        
310           {        
311                Console. WriteLine( "A fault o ccurred wh en process ing {1} re quest, at  index {0}  in the req uest colle ction with  a fault m essage: {2 }", count  + 1,        
312                    orga nizationRe quest.Requ estName,        
313                    orga nizationSe rviceFault .Message);        
314           }        
315          
316           #e ndregion        
317          
318           #e ndregion H ow To Samp le Code        
319          
320           #r egion Main  method        
321          
322           // / <summary >        
323           // / Standard  Main() me thod used  by most SD K samples.        
324           // / </summar y>        
325           // / <param n ame="args" ></param>        
326           st atic void  Main(strin g[] args)        
327           {        
328                try        
329                {        
330                    // O btain the  target org anization' s Web addr ess and cl ient logon          
331                    // c redentials  from the  user.        
332                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
333                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
334          
335                    var  app = new  ExecuteTra nsaction() ;        
336                    app. Run(config , true);        
337                }        
338          
339                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
340                {        
341                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
342                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
343                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
344                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
345                    Cons ole.WriteL ine("Trace : {0}", ex .Detail.Tr aceText);        
346                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
347                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
348                }        
349                catch (S ystem.Time outExcepti on ex)        
350                {        
351                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
352                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
353                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
354                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
355                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
356                }        
357                catch (S ystem.Exce ption ex)        
358                {        
359                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
360                    Cons ole.WriteL ine(ex.Mes sage);        
361          
362                    // D isplay the  details o f the inne r exceptio n.        
363                    if ( ex.InnerEx ception !=  null)        
364                    {        
365                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
366          
367                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
368                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
369                         if (fe !=  null)        
370                         {        
371                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
372                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
373                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
374                             Consol e.WriteLin e("Trace:  {0}", fe.D etail.Trac eText);        
375                             Consol e.WriteLin e("Inner F ault: {0}" ,        
376                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
377                         }        
378                    }        
379                }        
380                finally        
381                {        
382                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
383                    Cons ole.ReadLi ne();        
384                }        
385           }        
386          
387           #e ndregion M ain method        
388       }        
389   }        
390   // </snipp etExecuteT ransaction >