339. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2/1/2017 2:56:30 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.

339.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\BulkDelete BulkDeleteBackup.cs Tue Dec 20 19:51:43 2016 UTC
2 Wed Feb 1 19:56:30 2017 UTC

339.2 Comparison summary

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

339.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

339.4 Active regular expressions

No regular expressions were active.

339.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 tBulkDelet eBackup>        
17   using Syst em;        
18   using Syst em.Service Model;        
19   using Micr osoft.Crm. Sdk.Messag es;        
20   using Micr osoft.Xrm. Sdk;        
21   using Micr osoft.Xrm. Sdk.Client ;        
22   using Micr osoft.Xrm. Sdk.Query;        
23          
24   namespace  Microsoft. Crm.Sdk.Sa mples        
25   {        
26       /// <s ummary>        
27       /// Th is sample  shows how  to perform  a bulk de lete async hronous         
28       /// op eration on  the recor ds that ha ve been ma nually exp orted         
29       /// fr om Microso ft Dynamic s CRM by u sing Expor t to Excel  in a grid 's view.        
30       /// </ summary>        
31       public  class Bul kDeleteBac kup        
32       {        
33           #r egion Clas s Level Me mbers        
34           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
35           pr ivate Bulk DeleteResp onse _bulk DeleteResp onse;        
36           pr ivate Guid ? _asyncOp erationId;        
37           pr ivate Guid ? _bulkDel eteOperati onId;        
38           #e ndregion        
39          
40           #r egion How  To Sample  Code        
41          
42           // / <summary >        
43           // / Run the  sample.        
44           // / </summar y>        
45           // / <param n ame="serve rConfig">c onfigurati on for the  server.</ param>        
46           // / <param n ame="promp tToDelete" >        
47           // / whether  or not to  prompt the  user to d elete crea ted record s.        
48           // / </param>        
49           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt ToDelete)        
50           {        
51                using (_ servicePro xy = new O rganizatio nServicePr oxy(server Config.Org anizationU ri, server Config.Hom eRealmUri,        
52                                                                              s erverConfi g.Credenti als, serve rConfig.De viceCreden tials))        
53                {        
54                    // T his statem ent is req uired to e nable earl y-bound ty pe support .        
55                    _ser viceProxy. EnableProx yTypes();        
56          
57                    Perf ormBulkDel eteBackup( );        
58                    Dele teRequired Records(pr omptToDele te);        
59                }        
60           }        
61          
62           // / <summary >        
63           // / Performs  the main  operation  of the sam ple - perf orms a bul k delete o n inactive        
64           // / opportun ities and  activities  to remove  them from  the syste m.        
65           // / </summar y>        
66           pr ivate void  PerformBu lkDeleteBa ckup()        
67           {        
68                try        
69                {        
70                    // Q uery for a  system us er to send  an email  to after t he bulk de lete        
71                    // o peration c ompletes.        
72                    var  userReques t = new Wh oAmIReques t();        
73                    var  userRespon se = (WhoA mIResponse )_serviceP roxy.Execu te(userReq uest);        
74                    Guid  currentUs erId = use rResponse. UserId;        
75          
76                    //<s nippetBulk Delete>        
77                    // C reate a co ndition fo r a bulk d elete requ est.        
78                    // N OTE: This  sample use s very spe cific quer ies for de leting rec ords        
79                    // t hat have b een manual ly exporte d in order  to free s pace.        
80                    Quer yExpressio n opportun itiesQuery  = BuildOp portunityQ uery();        
81          
82                    // C reate the  bulk delet e request.        
83                    Bulk DeleteRequ est bulkDe leteReques t = new Bu lkDeleteRe quest();        
84          
85                    // S et the req uest prope rties.        
86                    bulk DeleteRequ est.JobNam e = "Backu p Bulk Del ete";        
87          
88                    // Q uerying ac tivities        
89                    bulk DeleteRequ est.QueryS et = new Q ueryExpres sion[]        
90                    {        
91                         opportunit iesQuery,        
92                         BuildActiv ityQuery(T ask.Entity LogicalNam e),        
93                         BuildActiv ityQuery(F ax.EntityL ogicalName ),        
94                         BuildActiv ityQuery(P honeCall.E ntityLogic alName),        
95                         BuildActiv ityQuery(E mail.Entit yLogicalNa me),        
96                         BuildActiv ityQuery(L etter.Enti tyLogicalN ame),        
97                         BuildActiv ityQuery(A ppointment .EntityLog icalName),        
98                         BuildActiv ityQuery(S erviceAppo intment.En tityLogica lName),        
99                         BuildActiv ityQuery(C ampaignRes ponse.Enti tyLogicalN ame),        
100                         BuildActiv ityQuery(R ecurringAp pointmentM aster.Enti tyLogicalN ame)        
101                    };        
102          
103                    // S et the sta rt time fo r the bulk  delete.        
104                    bulk DeleteRequ est.StartD ateTime =  DateTime.N ow;        
105          
106                    // S et the req uired recu rrence pat tern.        
107                    bulk DeleteRequ est.Recurr encePatter n = String .Empty;        
108          
109                    // S et email a ctivity pr operties.        
110                    bulk DeleteRequ est.SendEm ailNotific ation = fa lse;        
111                    bulk DeleteRequ est.ToReci pients = n ew Guid[]  { currentU serId };        
112                    bulk DeleteRequ est.CCReci pients = n ew Guid[]  { };        
113          
114                    // S ubmit the  bulk delet e job.        
115                    // N OTE: Becau se this is  an asynch ronous ope ration, th e response  will be i mmediate.        
116                    _bul kDeleteRes ponse =        
117                         (BulkDelet eResponse) _servicePr oxy.Execut e(bulkDele teRequest) ;        
118                    Cons ole.WriteL ine("The b ulk delete  operation  has been  requested. ");        
119                    //</ snippetBul kDelete>        
120          
121                    Chec kSuccess() ;        
122                }        
123                catch (S ystem.Web. Services.P rotocols.S oapExcepti on)        
124                {        
125                    // P erform err or handlin g here.        
126                    thro w;        
127                }        
128                catch (E xception)        
129                {        
130                    thro w;        
131                }        
132           }        
133          
134           // / <summary >        
135           // / This met hod will q uery for t he BulkDel eteOperati on until i t has been        
136           // / complete d or until  the desig nated time  runs out.   It then  checks to  see if        
137           // / the oper ation was  successful .        
138           // / </summar y>        
139           pr ivate void  CheckSucc ess()        
140           {        
141                // Query  for bulk  delete ope ration and  check for  status.        
142                QueryByA ttribute b ulkQuery =  new Query ByAttribut e(        
143                    Bulk DeleteOper ation.Enti tyLogicalN ame);        
144                bulkQuer y.ColumnSe t = new Co lumnSet(tr ue);        
145          
146                // NOTE:  When the  bulk delet e operatio n was subm itted, the  GUID that  was        
147                // retur ned was th e asyncope rationid,  not the bu lkdeleteop erationid.        
148                bulkQuer y.Attribut es.Add("as yncoperati onid");        
149                _asyncOp erationId  = _bulkDel eteRespons e.JobId;        
150                bulkQuer y.Values.A dd(_asyncO perationId );        
151          
152                // With  only the a syncoperat ionid at t his point,  a Retriev eMultiple  is        
153                // requi red to get  the        
154                // bulk  delete ope ration cre ated above .        
155                EntityCo llection e ntityColle ction = _s erviceProx y.Retrieve Multiple(b ulkQuery);        
156                BulkDele teOperatio n createdB ulkDeleteO peration =  null;        
157          
158                // Monit or the asy nc operati on via pol ling until  it is com plete or m ax        
159                // polli ng time ex pires.        
160                const in t ARBITRAR Y_MAX_POLL ING_TIME =  60;        
161                int seco ndsTicker  = ARBITRAR Y_MAX_POLL ING_TIME;        
162                while (s econdsTick er > 0)        
163                {        
164                    // M ake sure t he async o peration w as retriev ed.        
165                    if ( entityColl ection.Ent ities.Coun t > 0)        
166                    {        
167                         // Grab th e one bulk  operation  that has  been creat ed.        
168                         createdBul kDeleteOpe ration = ( BulkDelete Operation) entityColl ection.Ent ities[0];        
169          
170                         // Check t he operati on's state .        
171                         if (create dBulkDelet eOperation .StateCode .Value !=  BulkDelete OperationS tate.Compl eted)        
172                         {        
173                             // The  operation  has not y et complet ed.  Wait  a second f or the        
174                             // sta tus to cha nge.        
175                             System .Threading .Thread.Sl eep(1000);        
176                             second sTicker--;        
177          
178                             // Ret rieve a fr esh versio n of the b ulk delete  operation .        
179                             entity Collection  = _servic eProxy.Ret rieveMulti ple(bulkQu ery);        
180                         }        
181                         else        
182                         {        
183                             // Sto p polling  as the ope ration's s tate is no w complete .        
184                             second sTicker =  0;        
185                         }        
186                    }        
187                    else        
188                    {        
189                         // Wait a  second for  async ope ration to  activate.        
190                         System.Thr eading.Thr ead.Sleep( 1000);        
191                         secondsTic ker--;        
192          
193                         // Retriev e the enti ty again.        
194                         entityColl ection = _ servicePro xy.Retriev eMultiple( bulkQuery) ;        
195                    }        
196                }        
197          
198                // Valid ate that t he operati on was com pleted.        
199                if (crea tedBulkDel eteOperati on != null )        
200                {        
201                    _bul kDeleteOpe rationId =  createdBu lkDeleteOp eration.Bu lkDeleteOp erationId;        
202                    if ( createdBul kDeleteOpe ration.Sta teCode.Val ue != Bulk DeleteOper ationState .Completed )        
203                    {        
204                         Console.Wr iteLine(        
205                             "Polli ng for the  BulkDelet eOperation  took long er than al lowed ({0}  seconds). ",        
206                             ARBITR ARY_MAX_PO LLING_TIME );        
207                    }        
208                    else        
209                    {        
210                         Console.Wr iteLine("T he BulkDel eteOperati on succeed ed.\r\n  S uccesses:  {0}, Failu res: {1}",        
211                             create dBulkDelet eOperation .SuccessCo unt,        
212                             create dBulkDelet eOperation .FailureCo unt);        
213                    }        
214                }        
215                else        
216                {        
217                    Cons ole.WriteL ine("The B ulkDeleteO peration c ould not b e retrieve d.");        
218                }        
219           }        
220          
221           // / <summary >        
222           // / Builds a  query tha t matches  all opport unities th at are not  in the op en state.        
223           // / </summar y>        
224           pr ivate stat ic QueryEx pression B uildOpport unityQuery ()        
225           {        
226                // Creat e a query  that will  match all  opportunit ies that d o not have  a state        
227                // of op en.        
228                var clos edConditio n = new Co nditionExp ression(        
229                    "sta tecode", C onditionOp erator.Not Equal, (in t)Opportun ityState.O pen);        
230          
231                // Creat e a filter  expressio n for a bu lk delete  request.        
232                var clos edFilter =  new Filte rExpressio n();        
233                closedFi lter.Condi tions.Add( closedCond ition);        
234          
235                var quer yExpressio n = new Qu eryExpress ion();        
236          
237                queryExp ression.En tityName =  Opportuni ty.EntityL ogicalName ;        
238                queryExp ression.Cr iteria = c losedFilte r;        
239          
240                // Retur n all reco rds        
241                queryExp ression.Di stinct = f alse;        
242          
243                return q ueryExpres sion;        
244           }        
245          
246           // / <summary >        
247           // / Builds a  query whi ch will ma tch all ac tivities t hat are in  the cance led or        
248           // / complete d state.        
249           // / </summar y>        
250           pr ivate stat ic QueryEx pression B uildActivi tyQuery(St ring entit yName)        
251           {        
252                var canc eledCondit ion = new  ConditionE xpression(        
253                    "sta tecode", C onditionOp erator.Equ al, (int)A ctivityPoi nterState. Canceled);        
254                var comp letedCondi tion = new  Condition Expression (        
255                    "sta tecode", C onditionOp erator.Equ al, (int)A ctivityPoi nterState. Completed) ;        
256          
257                var clos edFilter =  new Filte rExpressio n(LogicalO perator.Or );        
258                closedFi lter.Condi tions.AddR ange(cance ledConditi on, comple tedConditi on);        
259          
260                var quer yExpressio n = new Qu eryExpress ion();        
261          
262                queryExp ression.En tityName =  entityNam e;        
263                queryExp ression.Cr iteria = c losedFilte r;        
264          
265                queryExp ression.Di stinct = f alse;        
266          
267                return q ueryExpres sion;        
268           }        
269          
270           // / <summary >        
271           // / This met hod delete s the Asyn cOperation  and BulkD eleteOpera tion that  were        
272           // / created  in the dat abase, if  the user c onfirms th at deletin g these is        
273           // / desired.        
274           // / </summar y>        
275           pr ivate void  DeleteReq uiredRecor ds(bool pr omptToDele te)        
276           {        
277                var toBe Deleted =  true;        
278                if (prom ptToDelete )        
279                {        
280                    // A sk the use r if the c reated ent ities shou ld be dele ted.        
281                    Cons ole.Write( "\nDo you  want these  entity re cords dele ted? (y/n)  [y]: ");        
282                    Stri ng answer  = Console. ReadLine() ;        
283                    if ( answer.Sta rtsWith("y ") ||        
284                         answer.Sta rtsWith("Y ") ||        
285                         answer ==  String.Emp ty)        
286                    {        
287                         toBeDelete d = true;        
288                    }        
289                    else        
290                    {        
291                         toBeDelete d = false;        
292                    }        
293                }        
294          
295                if (toBe Deleted)        
296                {        
297                    // D elete the  bulk delet e operatio n so that  it won't c lutter the        
298                    // d atabase.        
299                    if ( _bulkDelet eOperation Id.HasValu e)        
300                    {        
301                         _servicePr oxy.Delete (        
302                             BulkDe leteOperat ion.Entity LogicalNam e,        
303                             _bulkD eleteOpera tionId.Val ue);        
304                    }        
305          
306                    if ( _asyncOper ationId.Ha sValue)        
307                    {        
308                         _servicePr oxy.Delete (        
309                             AsyncO peration.E ntityLogic alName, _a syncOperat ionId.Valu e);        
310                    }        
311          
312                    Cons ole.WriteL ine("The A syncOperat ion and Bu lkDeleteOp eration ha ve been de leted.");        
313                }        
314           }        
315          
316           #e ndregion H ow To Samp le Code        
317          
318           #r egion Main  method        
319          
320           // / <summary >        
321           // / Standard  Main() me thod used  by most SD K samples.        
322           // / </summar y>        
323           // / <param n ame="args" ></param>        
324           st atic publi c void Mai n(string[]  args)        
325           {        
326                try        
327                {        
328                    // O btain the  target org anization' s Web addr ess and cl ient logon          
329                    // c redentials  from the  user.        
330                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
331                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
332          
333                    var  app = new  BulkDelete Backup();        
334                    app. Run(config , true);        
335                }        
336                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
337                {        
338                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
339                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
340                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
341                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
342                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
343                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
344                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
345                }        
346                catch (S ystem.Time outExcepti on ex)        
347                {        
348                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
349                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
350                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
351                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
352                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
353                }        
354                catch (S ystem.Exce ption ex)        
355                {        
356                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
357                    Cons ole.WriteL ine(ex.Mes sage);        
358          
359                    // D isplay the  details o f the inne r exceptio n.        
360                    if ( ex.InnerEx ception !=  null)        
361                    {        
362                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
363          
364                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
365                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
366                         if (fe !=  null)        
367                         {        
368                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
369                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
370                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
371                             Consol e.WriteLin e("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
372                             Consol e.WriteLin e("Inner F ault: {0}" ,        
373                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
374                         }        
375                    }        
376                }        
377                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
378                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
379          
380                finally        
381                {        
382                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
383                    Cons ole.ReadLi ne();        
384                }        
385           }        
386           #e ndregion M ain method        
387       }        
388   }        
389   // </snipp etBulkDele teBackup>