210. Araxis Merge File Comparison Report

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

210.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\BusinessDataModel\BusinessManagement ValidateAndSetState.cs Tue Dec 20 19:51:44 2016 UTC
2 Wed Feb 1 19:56:24 2017 UTC

210.2 Comparison summary

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

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

210.4 Active regular expressions

No regular expressions were active.

210.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   //<snippet ValidateAn dSetState>        
17          
18   using Syst em;        
19   using Syst em.Service Model;        
20   using Micr osoft.Crm. Sdk.Messag es;        
21   using Micr osoft.Xrm. Sdk;        
22   using Micr osoft.Xrm. Sdk.Client ;        
23   using Micr osoft.Xrm. Sdk.Query;        
24          
25   namespace  Microsoft. Crm.Sdk.Sa mples        
26   {        
27       /// <s ummary>        
28       ///  T his sample  shows how  to valida te an inte nded state  change on  an entity  record.        
29       ///  T his sample  will also  show how  to set the  state on  the entity  record.         
30       /// </ summary>        
31       /// <r emarks>        
32       /// At  run-time,  you will  be given t he option  to delete  all the        
33       /// da tabase rec ords creat ed by this  program.        
34       /// </ remarks>        
35       public  class Val idateAndSe tState        
36       {        
37           #r egion Clas s Level Me mbers        
38           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
39           pr ivate Guid  _caseCust omerId;        
40           pr ivate Guid  _caseInci dentId;        
41           #e ndregion        
42          
43           #r egion How  To Sample  Code        
44           // / <summary >        
45           // / This met hod first  connects t o the Orga nization s ervice. Af terwards,         
46           // / case is  created. T he IsValid StateTrans ition is u sed to tes t if a sta te change        
47           // / is valid . The case  is closed , re-opene d and then  closed wi th SetStat e.        
48           // / </summar y>        
49           // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param>        
50           // / <param n ame="promp tforDelete ">When Tru e, the use r will be  prompted t o delete a ll        
51           // / created  entities.< /param>        
52           pu blic void  Run(Server Connection .Configura tion serve rConfig,        
53                bool pro mptForDele te)        
54           {        
55                using (_ servicePro xy = new O rganizatio nServicePr oxy(server Config.Org anizationU ri, server Config.Hom eRealmUri, serverConf ig.Credent ials, serv erConfig.D eviceCrede ntials))        
56                {        
57                    // T his statem ent is req uired to e nable earl y-bound ty pe support .        
58                    _ser viceProxy. EnableProx yTypes();        
59          
60                    //Cr eate the C ontact and  Incident  required f or this sa mple.        
61                    Crea teRequired Records();        
62          
63                    //<s nippetIsVa lidStateTr ansition>        
64                    // C reate an E ntityRefer ence to re present an  open case        
65                    Enti tyReferenc e caseRefe rence = ne w EntityRe ference()        
66                    {        
67                         LogicalNam e = Incide nt.EntityL ogicalName ,        
68                         Id = _case IncidentId        
69                    };        
70          
71                    IsVa lidStateTr ansitionRe quest chec kState =         
72                         new IsVali dStateTran sitionRequ est();        
73          
74                    // S et the tra nsition re quest to a n open cas e        
75                    chec kState.Ent ity = case Reference;        
76          
77                    // C heck to se e if a new  state of  "resolved"  and         
78                    // a  new statu s of "prob lem solved " are vali d        
79                    chec kState.New State = In cidentStat e.Resolved .ToString( );        
80                    chec kState.New Status = ( int)incide nt_statusc ode.Proble mSolved;        
81          
82                    // E xecute the  request        
83                    IsVa lidStateTr ansitionRe sponse che ckStateRes ponse =         
84                         (IsValidSt ateTransit ionRespons e)_service Proxy.Exec ute(checkS tate);        
85                    //</ snippetIsV alidStateT ransition>           
86          
87                    // H andle the  response        
88                    if ( checkState Response.I sValid)        
89                    {        
90                         String cha ngeAnswer  = "y"; //  default to  "y" unles s promptin g for dele te        
91                         if (prompt ForDelete)        
92                         {        
93                             // The  case can  be closed        
94                             Consol e.WriteLin e("Validat e State Re quest retu rned that  the case "  +        
95                                                 "can be  closed.");        
96                             Consol e.Write("\ nDo you wa nt to chan ge the rec ord state?  " +        
97                                                 "(y/n) [ y]: ");        
98                             change Answer = C onsole.Rea dLine();        
99                             Consol e.WriteLin e();        
100                         }        
101          
102                         if (change Answer.Sta rtsWith("y ") || chan geAnswer.S tartsWith( "Y")        
103                             || cha ngeAnswer  == String. Empty)        
104                         {        
105                             // Cal l function  to change  the incid ent to the  closed st ate        
106                             CloseI ncident(ca seReferenc e);        
107                             // Re- open the i ncident an d change i ts state        
108                             SetSta te(caseRef erence);        
109                         }        
110                    }        
111                    else        
112                    {        
113                         // The cas e cannot b e closed        
114                         Console.Wr iteLine("V alidate St ate Reques t returned  that the  " +        
115                                            "c hange is n ot valid." );        
116                    }        
117          
118                    Dele teRequired Records(pr omptForDel ete);        
119                }        
120           }        
121          
122           pr ivate void  CloseInci dent(Entit yReference  caseRefer ence)        
123           {        
124                //<snipp etCloseInc ident>        
125                // First  close the  Incident        
126          
127                // Creat e resoluti on for the  closing i ncident        
128                Incident Resolution  resolutio n = new In cidentReso lution        
129                {        
130                    Subj ect = "Cas e Closed",        
131                };        
132          
133                resoluti on.Inciden tId = case Reference;        
134          
135                // Creat e the requ est to clo se the inc ident, and  set its r esolution  to the         
136                // resol ution crea ted above        
137                CloseInc identReque st closeRe quest = ne w CloseInc identReque st();        
138                closeReq uest.Incid entResolut ion = reso lution;        
139          
140                // Set t he request ed new sta tus for th e closed I ncident        
141                closeReq uest.Statu s =         
142                    new  OptionSetV alue((int) incident_s tatuscode. ProblemSol ved);        
143          
144                // Execu te the clo se request        
145                CloseInc identRespo nse closeR esponse =         
146                    (Clo seIncident Response)_ servicePro xy.Execute (closeRequ est);        
147          
148                //Check  if the inc ident was  successful ly closed        
149                Incident  incident  = _service Proxy.Retr ieve(Incid ent.Entity LogicalNam e,         
150                    _cas eIncidentI d, new Col umnSet(all Columns: t rue)).ToEn tity<Incid ent>();        
151          
152                if (inci dent.State Code.HasVa lue &&         
153                    inci dent.State Code == In cidentStat e.Resolved )        
154                {        
155                    Cons ole.WriteL ine("The i ncident wa s closed o ut as Reso lved.");        
156                }        
157                else        
158                {        
159                    Cons ole.WriteL ine("The i ncident's  state was  not change d.");        
160                }        
161                //</snip petCloseIn cident>          
162           }        
163          
164           pr ivate void  SetState( EntityRefe rence case Reference)        
165           {        
166                //<snipp etSetState >        
167                // Creat e the Requ est Object        
168                SetState Request st ate = new  SetStateRe quest();        
169          
170                // Set t he Request  Object's  Properties        
171                state.St ate = new  OptionSetV alue((int) IncidentSt ate.Active );        
172                state.St atus =         
173                    new  OptionSetV alue((int) incident_s tatuscode. Waitingfor Details);        
174          
175                // Point  the Reque st to the  case whose  state is  being chan ged        
176                state.En tityMonike r = caseRe ference;        
177          
178                // Execu te the Req uest        
179                SetState Response s tateSet =  (SetStateR esponse)_s erviceProx y.Execute( state);        
180          
181                // Check  if the st ate was su ccessfully  set        
182                Incident  incident  = _service Proxy.Retr ieve(Incid ent.Entity LogicalNam e,         
183                    _cas eIncidentI d, new Col umnSet(all Columns: t rue)).ToEn tity<Incid ent>();        
184          
185                if (inci dent.Statu sCode.Valu e == (int) incident_s tatuscode. Waitingfor Details)        
186                {        
187                    Cons ole.WriteL ine("Recor d state se t successf ully.");        
188                }        
189                else        
190                {        
191                    Cons ole.WriteL ine("The r equest to  set the re cord state  failed.") ;        
192                }        
193          
194                //</snip petSetStat e>          
195          
196           }        
197          
198           // / <summary >        
199           // / Creates  any entity  records t hat this s ample requ ires.        
200           // / </summar y>        
201           pu blic void  CreateRequ iredRecord s()        
202           {        
203                // Creat e a custom er for a n ew inciden t        
204                Contact  caseCustom er = new C ontact();        
205          
206                // Set t he contact  propertie s        
207                caseCust omer.First Name = "Ch risten";        
208                caseCust omer.LastN ame = "And erson";        
209          
210                // Creat e the cont act in CRM        
211                _caseCus tomerId =  _servicePr oxy.Create (caseCusto mer);        
212                NotifyEn tityCreate d(Contact. EntityLogi calName, _ caseCustom erId);        
213          
214                // Retri eve the de fault subj ect for a  new incide nt\case        
215                var quer y = new Qu eryExpress ion()        
216                {        
217                    Enti tyName = S ubject.Ent ityLogical Name,        
218                    Colu mnSet = ne w ColumnSe t(allColum ns: true),        
219                    Crit eria = new  FilterExp ression()        
220                };        
221                query.Cr iteria.Add Condition( "title", C onditionOp erator.Equ al,         
222                    "Def ault Subje ct");        
223          
224                var subj ectRecords  = _servic eProxy.Ret rieveMulti ple(query) ;        
225                Entity d efaultSubj ect = subj ectRecords [0];        
226                NotifyEn tityRetrie ved(Subjec t.EntityLo gicalName,  defaultSu bject.Id);        
227          
228                // Creat e a new in cident        
229                Incident  newCase =  new Incid ent();        
230          
231                // Set t he inciden t properti es        
232                newCase. SubjectId  = new Enti tyReferenc e();        
233                newCase. SubjectId. LogicalNam e = Subjec t.EntityLo gicalName;        
234                newCase. SubjectId. Id = defau ltSubject. Id;        
235                newCase. CustomerId  = new Ent ityReferen ce();        
236                newCase. CustomerId .LogicalNa me = Conta ct.EntityL ogicalName ;        
237                newCase. CustomerId .Id = _cas eCustomerI d;        
238                newCase. Title = "N ew Case fr om SDK";        
239          
240                _caseInc identId =  _servicePr oxy.Create (newCase);        
241                NotifyEn tityCreate d(Incident .EntityLog icalName,  _caseIncid entId);        
242          
243           }        
244          
245           // / <summary >        
246           // / Deletes  any entity  records t hat were c reated for  this samp le.        
247           // / <param n ame="promp t">Indicat es whether  to prompt  the user         
248           // / to delet e the reco rds create d in this  sample.</p aram>        
249           // / </summar y>        
250           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
251           {        
252                bool del eteRecords  = true;        
253          
254                if (prom pt)        
255                {        
256                    Cons ole.Write( "\nDo you  want these  entity re cords dele ted? (y/n)  [y]: ");        
257                    Stri ng answer  = Console. ReadLine() ;        
258                    Cons ole.WriteL ine();        
259          
260                    dele teRecords  = (answer. StartsWith ("y") || a nswer.Star tsWith("Y"        
261                         || answer  == String. Empty);        
262                }        
263          
264                if (dele teRecords)        
265                {        
266                    _ser viceProxy. Delete(Inc ident.Enti tyLogicalN ame, _case IncidentId );        
267                    _ser viceProxy. Delete(Con tact.Entit yLogicalNa me, _caseC ustomerId) ;        
268                    Cons ole.WriteL ine("Entit y records  have been  deleted.") ;        
269                }        
270           }        
271          
272           pr ivate void  NotifyEnt ityCreated (String en tityName,  Guid entit yId)        
273           {        
274                Console. WriteLine( "  {0} cre ated with  GUID {{{1} }}",        
275                    enti tyName, en tityId);        
276           }        
277          
278           pr ivate void  NotifyEnt ityRetriev ed(String  entityName , Guid ent ityId)        
279           {        
280                Console. WriteLine( "  Retriev ed {0} wit h GUID {{{ 1}}}",        
281                    enti tyName, en tityId);        
282           }        
283           #e ndregion        
284          
285           #r egion Main  method        
286          
287           // / <summary >        
288           // / Standard  Main() me thod used  by most SD K samples.        
289           // / </summar y>        
290           // / <param n ame="args" ></param>        
291           st atic publi c void Mai n(string[]  args)        
292           {        
293                try        
294                {        
295                    // O btain the  target org anization' s Web addr ess and cl ient logon          
296                    // c redentials  from the  user.        
297                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
298                    Serv erConnecti on.Configu ration con fig =         
299                         serverConn ect.GetSer verConfigu ration();        
300          
301                    var  app = new  ValidateAn dSetState( );        
302                    app. Run(config , true);        
303                }        
304                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
305                {        
306                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
307                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
308                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
309                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
310                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
311                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
312                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
313                }        
314                catch (S ystem.Time outExcepti on ex)        
315                {        
316                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
317                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
318                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
319                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
320                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
321                }        
322                catch (S ystem.Exce ption ex)        
323                {        
324                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
325                    Cons ole.WriteL ine(ex.Mes sage);        
326          
327                    // D isplay the  details o f the inne r exceptio n.        
328                    if ( ex.InnerEx ception !=  null)        
329                    {        
330                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
331          
332                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e =         
333                             ex.Inn erExceptio n        
334                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
335                         if (fe !=  null)        
336                         {        
337                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
338                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
339                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
340                             Consol e.WriteLin e("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
341                             Consol e.WriteLin e("Inner F ault: {0}" ,        
342                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
343                         }        
344                    }        
345                }        
346                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,          
347                // Expir edSecurity TokenExcep tion, Secu rityAccess DeniedExce ption,         
348                // Messa geSecurity Exception,  and Secur ityNegotia tionExcept ion.        
349          
350                finally        
351                {        
352                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
353                    Cons ole.ReadLi ne();        
354                }        
355           }        
356           #e ndregion M ain method        
357       }        
358   }        
359          
360   //</snippe tValidateA ndSetState >