460. Araxis Merge File Comparison Report

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

460.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\Metadata\Attributes StateModelTransitions.cs Tue Dec 20 19:51:47 2016 UTC
2 Wed Feb 1 19:56:46 2017 UTC

460.2 Comparison summary

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

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

460.4 Active regular expressions

No regular expressions were active.

460.5 Comparison detail

1   // ======= ========== ========== ========== ========== ========== ========== ==        
2   //        
3   //  This f ile is par t of the M icrosoft D ynamics CR M SDK code  samples.        
4   //        
5   //  Copyri ght (C) Mi crosoft Co rporation.   All righ ts reserve d.        
6   //        
7   //  This s ource code  is intend ed only as  a supplem ent to Mic rosoft        
8   //  Develo pment Tool s and/or o n-line doc umentation .  See the se other        
9   //  materi als for de tailed inf ormation r egarding M icrosoft c ode sample s.        
10   //        
11   //  THIS C ODE AND IN FORMATION  ARE PROVID ED "AS IS"  WITHOUT W ARRANTY OF  ANY        
12   //  KIND,  EITHER EXP RESSED OR  IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E        
13   //  IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR  A        
14   //  PARTIC ULAR PURPO SE.        
15   //        
16   // ======= ========== ========== ========== ========== ========== ========== ==        
17   //<snippet StateModel Transition s>        
18          
19   using Syst em;        
20   using Syst em.Linq;        
21   using Syst em.Xml.Lin q;        
22   using Syst em.Service Model;        
23   using Syst em.Service Model.Desc ription;        
24   using Syst em.Collect ions.Gener ic;        
25   using Syst em.Xml.Ser ialization ;        
26   using Syst em.Xml;        
27          
28   // These n amespaces  are found  in the Mic rosoft.Xrm .Sdk.dll a ssembly        
29   // found i n the SDK\ bin folder .        
30   using Micr osoft.Xrm. Sdk;        
31   using Micr osoft.Xrm. Sdk.Query;        
32   using Micr osoft.Xrm. Sdk.Metada ta;        
33   using Micr osoft.Xrm. Sdk.Metada ta.Query;        
34   using Micr osoft.Xrm. Sdk.Client ;        
35   using Micr osoft.Xrm. Sdk.Messag es;        
36          
37   // This na mespace is  found in  Microsoft. Crm.Sdk.Pr oxy.dll as sembly        
38   // found i n the SDK\ bin folder .        
39   using Micr osoft.Crm. Sdk.Messag es;        
40          
41   namespace  Microsoft. Crm.Sdk.Sa mples        
42   {        
43    class Sta teModelTra nsitions        
44    {        
45     #region  Class Leve l Members        
46     /// <sum mary>        
47     /// Stor es the org anization  service pr oxy.        
48     /// </su mmary>        
49     Organiza tionServic eProxy _se rviceProxy ;        
50     #endregi on Class L evel Membe rs        
51          
52     #region  How To Sam ple Code        
53     /// <sum mary>        
54     /// Crea te and con figure the  organizat ion servic e proxy.        
55     /// Retr ieve statu s options  for the In cident ent ity        
56     /// Use  GetValidSt atusOption s to get v alid statu s transiti ons for ea ch status  option        
57     /// </su mmary>        
58     /// <par am name="s erverConfi g">Contain s server c onnection  informatio n.</param>        
59     /// <par am name="p romptForDe lete">When  True, the  user will  be prompt ed to dele te all        
60     /// crea ted entiti es.</param >        
61     public v oid Run(Se rverConnec tion.Confi guration s erverConfi g, bool pr omptForDel ete)        
62     {        
63      try        
64      {        
65          
66       // Con nect to th e Organiza tion servi ce.         
67       // The  using sta tement ass ures that  the servic e proxy wi ll be prop erly dispo sed.        
68       using  (_serviceP roxy = new  Organizat ionService Proxy(serv erConfig.O rganizatio nUri, serv erConfig.H omeRealmUr i,serverCo nfig.Crede ntials, se rverConfig .DeviceCre dentials))        
69       {        
70        // Th is stateme nt is requ ired to en able early -bound typ e support.        
71        _serv iceProxy.E nableProxy Types();        
72        //<sn ippetState ModelTrans itions.run >        
73        Strin g entityLo gicalName  = "inciden t";        
74        // Re trieve sta tus option s for the  Incident e ntity        
75          
76        //Ret rieve just  the incid ent entity  and its a ttributes        
77        Metad ataFilterE xpression  entityFilt er = new M etadataFil terExpress ion(Logica lOperator. And);        
78        entit yFilter.Co nditions.A dd(new Met adataCondi tionExpres sion("Logi calName",  MetadataCo nditionOpe rator.Equa ls, entity LogicalNam e));        
79        Metad ataPropert iesExpress ion entity Properties  = new Met adataPrope rtiesExpre ssion(new  string[] {  "Attribut es" });        
80                
81        //Ret rieve just  the statu s attribut e and the  OptionSet  property        
82        Metad ataFilterE xpression  attributeF ilter = ne w Metadata FilterExpr ession(Log icalOperat or.And);        
83        attri buteFilter .Condition s.Add(new  MetadataCo nditionExp ression("A ttributeTy pe", Metad ataConditi onOperator .Equals, A ttributeTy peCode.Sta tus));        
84        Metad ataPropert iesExpress ion attrib utePropert ies = new  MetadataPr opertiesEx pression(n ew string[ ] { "Optio nSet" });        
85                
86        //Ins tantiate t he entity  query        
87        Entit yQueryExpr ession que ry = new E ntityQuery Expression ()        
88        {        
89         Crit eria = ent ityFilter,        
90         Prop erties = e ntityPrope rties,        
91         Attr ibuteQuery  = new Att ributeQuer yExpressio n() { Crit eria = att ributeFilt er, Proper ties = att ributeProp erties }        
92        };        
93          
94        //Ret rieve the  metadata        
95        Retri eveMetadat aChangesRe quest requ est = new  RetrieveMe tadataChan gesRequest () { Query  = query } ;        
96        Retri eveMetadat aChangesRe sponse res ponse = (R etrieveMet adataChang esResponse )_serviceP roxy.Execu te(request );        
97          
98          
99        Statu sAttribute Metadata s tatusAttri bute = (St atusAttrib uteMetadat a)response .EntityMet adata[0].A ttributes[ 0];        
100        Optio nMetadataC ollection  statusOpti ons = stat usAttribut e.OptionSe t.Options;        
101        //Loo p through  each of th e status o ptions        
102        forea ch (Status OptionMeta data optio n in statu sOptions)        
103        {        
104         Stri ng StatusO ptionLabel  = GetOpti onSetLabel (statusAtt ribute, op tion.Value .Value);        
105         Cons ole.WriteL ine("[{0}]  {1} recor ds can tra nsition to :", Status OptionLabe l, entityL ogicalName );        
106         List <StatusOpt ion> valid StatusOpti ons = GetV alidStatus Options(en tityLogica lName, opt ion.Value. Value);        
107         //Lo op through  each vali d transiti on for the  option        
108         fore ach (Statu sOption op t in valid StatusOpti ons)        
109         {        
110          Con sole.Write Line("{0,- 3}{1,-10}{ 2,-5}{3,-1 0}", opt.S tateValue,  opt.State Label, opt .StatusVal ue, opt.St atusLabel) ;        
111         }        
112         Cons ole.WriteL ine("");        
113        }        
114        //</s nippetStat eModelTran sitions.ru n>        
115       }        
116      }        
117          
118      // Catc h any serv ice fault  exceptions  that Micr osoft Dyna mics CRM t hrows.        
119      catch ( FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault>)        
120      {        
121       // You  can handl e an excep tion here  or pass it  back to t he calling  method.        
122       throw;        
123      }        
124     }        
125          
126          
127     #endregi on How To  Sample Cod e        
128          
129     #region  Main        
130     /// <sum mary>        
131     /// Stan dard Main( ) method u sed by mos t SDK samp les.        
132     /// </su mmary>        
133     /// <par am name="a rgs"></par am>        
134     static p ublic void  Main(stri ng[] args)        
135     {        
136      try        
137      {        
138       // Obt ain the ta rget organ ization's  Web addres s and clie nt logon         
139       // cre dentials f rom the us er.        
140       Server Connection  serverCon nect = new  ServerCon nection();        
141       Server Connection .Configura tion confi g = server Connect.Ge tServerCon figuration ();        
142          
143       StateM odelTransi tions app  = new Stat eModelTran sitions();        
144       app.Ru n(config,  true);        
145      }        
146      catch ( FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> e x)        
147      {        
148       Consol e.WriteLin e("The app lication t erminated  with an er ror.");        
149       Consol e.WriteLin e("Timesta mp: {0}",  ex.Detail. Timestamp) ;        
150       Consol e.WriteLin e("Code: { 0}", ex.De tail.Error Code);        
151       Consol e.WriteLin e("Message : {0}", ex .Detail.Me ssage);        
152       Consol e.WriteLin e("Plugin  Trace: {0} ", ex.Deta il.TraceTe xt);        
153       Consol e.WriteLin e("Inner F ault: {0}" ,        
154           nu ll == ex.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
155      }        
156      catch ( System.Tim eoutExcept ion ex)        
157      {        
158       Consol e.WriteLin e("The app lication t erminated  with an er ror.");        
159       Consol e.WriteLin e("Message : {0}", ex .Message);        
160       Consol e.WriteLin e("Stack T race: {0}" , ex.Stack Trace);        
161       Consol e.WriteLin e("Inner F ault: {0}" ,        
162           nu ll == ex.I nnerExcept ion.Messag e ? "No In ner Fault"  : ex.Inne rException .Message);        
163      }        
164      catch ( System.Exc eption ex)        
165      {        
166       Consol e.WriteLin e("The app lication t erminated  with an er ror.");        
167       Consol e.WriteLin e(ex.Messa ge);        
168          
169       // Dis play the d etails of  the inner  exception.        
170       if (ex .InnerExce ption != n ull)        
171       {        
172        Conso le.WriteLi ne(ex.Inne rException .Message);        
173          
174        Fault Exception< Microsoft. Xrm.Sdk.Or ganization ServiceFau lt> fe        
175            =  ex.InnerE xception        
176            a s FaultExc eption<Mic rosoft.Xrm .Sdk.Organ izationSer viceFault> ;        
177        if (f e != null)        
178        {        
179         Cons ole.WriteL ine("Times tamp: {0}" , fe.Detai l.Timestam p);        
180         Cons ole.WriteL ine("Code:  {0}", fe. Detail.Err orCode);        
181         Cons ole.WriteL ine("Messa ge: {0}",  fe.Detail. Message);        
182         Cons ole.WriteL ine("Plugi n Trace: { 0}", fe.De tail.Trace Text);        
183         Cons ole.WriteL ine("Inner  Fault: {0 }",        
184              null == fe .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
185        }        
186       }        
187      }        
188      // Addi tional exc eptions to  catch: Se curityToke nValidatio nException , ExpiredS ecurityTok enExceptio n,        
189      // Secu rityAccess DeniedExce ption, Mes sageSecuri tyExceptio n, and Sec urityNegot iationExce ption.        
190          
191      finally        
192      {        
193          
194       Consol e.WriteLin e("Press < Enter> to  exit.");        
195       Consol e.ReadLine ();        
196      }        
197          
198     }        
199     #endregi on Main        
200          
201     #region  Methods us ed in Samp le        
202     //<snipp etStateMod elTransiti ons.GetVal idStatusOp tions>        
203     /// <sum mary>        
204     /// Retu rns valid  status opt ion transi tions rega rdless of  whether st ate transi tions are  enabled fo r the enti ty        
205     /// </su mmary>        
206     /// <par am name="e ntityLogic alName">Th e logical  name of th e entity</ param>        
207     /// <par am name="c urrentStat usValue">T he current  status of  the entit y instance </param>        
208     /// <ret urns>A lis t of Statu sOptions t hat repres ent the va lid transi tions</ret urns>        
209     public L ist<Status Option> Ge tValidStat usOptions( String ent ityLogical Name, int  currentSta tusValue)        
210     {        
211          
212      List<St atusOption > validSta tusOptions  = new Lis t<StatusOp tion>();        
213          
214      //Check  entity Me tadata        
215          
216      //Retri eve just o ne entity  definition        
217      Metadat aFilterExp ression en tityFilter  = new Met adataFilte rExpressio n(LogicalO perator.An d);        
218      entityF ilter.Cond itions.Add (new Metad ataConditi onExpressi on("Logica lName", Me tadataCond itionOpera tor.Equals , entityLo gicalName) );        
219      //Retur n the attr ibutes and  the Enfor ceStateTra nsitions p roperty        
220      Metadat aPropertie sExpressio n entityPr operties =  new Metad ataPropert iesExpress ion(new st ring[] { " Attributes ", "Enforc eStateTran sitions" } );        
221          
222      //Retri eve only S tate or St atus attri butes        
223      Metadat aFilterExp ression at tributeFil ter = new  MetadataFi lterExpres sion(Logic alOperator .Or);        
224      attribu teFilter.C onditions. Add(new Me tadataCond itionExpre ssion("Att ributeType ", Metadat aCondition Operator.E quals, Att ributeType Code.Statu s));        
225      attribu teFilter.C onditions. Add(new Me tadataCond itionExpre ssion("Att ributeType ", Metadat aCondition Operator.E quals, Att ributeType Code.State ));        
226          
227      //Retri eve only t he OptionS et propert y of the a ttributes        
228      Metadat aPropertie sExpressio n attribut ePropertie s = new Me tadataProp ertiesExpr ession(new  string[]  { "OptionS et" });        
229          
230      //Set t he query        
231      EntityQ ueryExpres sion query  = new Ent ityQueryEx pression()        
232      {        
233       Criter ia = entit yFilter,        
234       Proper ties = ent ityPropert ies,        
235       Attrib uteQuery =  new Attri buteQueryE xpression( ) { Criter ia = attri buteFilter , Properti es = attri buteProper ties }        
236      };        
237          
238      //Retri eve the me tadata        
239      Retriev eMetadataC hangesRequ est reques t = new Re trieveMeta dataChange sRequest()  { Query =  query };        
240      Retriev eMetadataC hangesResp onse respo nse = (Ret rieveMetad ataChanges Response)_ servicePro xy.Execute (request);        
241          
242      //Check  the value  of Enforc eStateTran sitions        
243      Boolean ? EnforceS tateTransi tions = re sponse.Ent ityMetadat a[0].Enfor ceStateTra nsitions;        
244          
245      //Captu re the sta te and sta tus attrib utes        
246      StatusA ttributeMe tadata sta tusAttribu te = new S tatusAttri buteMetada ta();        
247      StateAt tributeMet adata stat eAttribute  = new Sta teAttribut eMetadata( );        
248          
249      foreach  (Attribut eMetadata  attributeM etadata in  response. EntityMeta data[0].At tributes)        
250      {        
251       switch  (attribut eMetadata. AttributeT ype)        
252       {        
253        case  AttributeT ypeCode.St atus:        
254         stat usAttribut e = (Statu sAttribute Metadata)a ttributeMe tadata;        
255         brea k;        
256        case  AttributeT ypeCode.St ate:        
257         stat eAttribute  = (StateA ttributeMe tadata)att ributeMeta data;        
258         brea k;        
259       }        
260      }        
261          
262          
263      if (Enf orceStateT ransitions .HasValue  && Enforce StateTrans itions.Val ue == true )        
264      {        
265       //When  EnforceSt ateTransit ions is tr ue use the  Transitio nData to f ilter the  valid opti ons        
266       foreac h (StatusO ptionMetad ata option  in status Attribute. OptionSet. Options)        
267       {        
268        if (o ption.Valu e == curre ntStatusVa lue)        
269        {        
270         if ( option.Tra nsitionDat a != Strin g.Empty)        
271         {        
272          XDo cument tra nsitionDat a = XDocum ent.Parse( option.Tra nsitionDat a);        
273          
274          IEn umerable<X Element> e lements =  (((XElemen t)transiti onData.Fir stNode)).D escendants ();        
275          
276          for each (XEle ment e in  elements)        
277          {        
278           in t statusOp tionValue  = Convert. ToInt32(e. Attribute( "tostatusi d").Value) ;        
279           St ring statu sLabel = G etOptionSe tLabel(sta tusAttribu te, status OptionValu e);        
280          
281           st ring state Label = St ring.Empty ;        
282           in t? stateVa lue = null ;        
283           fo reach (Sta tusOptionM etadata st atusOption  in status Attribute. OptionSet. Options)        
284           {        
285            i f (statusO ption.Valu e.Value ==  statusOpt ionValue)        
286            {        
287              stateValue  = statusO ption.Stat e.Value;        
288              stateLabel  = GetOpti onSetLabel (stateAttr ibute, sta teValue.Va lue);        
289            }        
290          
291           }        
292          
293          
294           va lidStatusO ptions.Add (new Statu sOption()        
295           {        
296            S tateLabel  = stateLab el,        
297            S tateValue  = stateVal ue.Value,        
298            S tatusLabel  = statusL abel,        
299            S tatusValue  = option. Value.Valu e        
300           }) ;        
301          }        
302         }        
303        }        
304       }        
305          
306      }        
307      else        
308      {        
309       ////Wh en Enforce StateTrans itions is  false do n ot filter  the availa ble option s        
310          
311       foreac h (StatusO ptionMetad ata option  in status Attribute. OptionSet. Options)        
312       {        
313        if (o ption.Valu e != curre ntStatusVa lue)        
314        {        
315          
316         Stri ng statusL abel = "";        
317         try        
318         {        
319          sta tusLabel =  option.La bel.UserLo calizedLab el.Label;        
320         }        
321         catc h (Excepti on)        
322         {        
323          sta tusLabel =  option.La bel.Locali zedLabels[ 0].Label;        
324         };        
325          
326         Stri ng stateLa bel = GetO ptionSetLa bel(stateA ttribute,  option.Sta te.Value);        
327          
328         vali dStatusOpt ions.Add(n ew StatusO ption()        
329         {        
330          Sta teLabel =  stateLabel ,        
331          Sta teValue =  option.Sta te.Value,        
332          Sta tusLabel =  statusLab el,        
333          Sta tusValue =  option.Va lue.Value        
334          
335         });        
336        }        
337       }        
338      }        
339      return  validStatu sOptions;        
340          
341     }        
342     //</snip petStateMo delTransit ions.GetVa lidStatusO ptions>        
343          
344     //<snipp etStateMod elTransiti ons.GetOpt ionSetLabe l>        
345     /// <sum mary>        
346     /// Retu rns a stri ng represe nting the  label of a n option i n an optio nset        
347     /// </su mmary>        
348     /// <par am name="a ttribute"> The metada ta for an  an attribu te with op tions</par am>        
349     /// <par am name="v alue">The  value of t he option< /param>        
350     /// <ret urns>The l abel for t he option< /returns>        
351     public S tring GetO ptionSetLa bel(EnumAt tributeMet adata attr ibute, int  value)        
352      {        
353       String  label = " ";        
354       foreac h (OptionM etadata op tion in at tribute.Op tionSet.Op tions)        
355       {        
356        if (o ption.Valu e.Value ==  value)        
357        {        
358         try        
359         {        
360          lab el = optio n.Label.Us erLocalize dLabel.Lab el;        
361         }        
362         catc h (Excepti on)        
363         {        
364          lab el = optio n.Label.Lo calizedLab els[0].Lab el;        
365         };        
366        }        
367       }        
368       return  label;        
369      }        
370     //</snip petStateMo delTransit ions.GetOp tionSetLab el>        
371     #endregi on Methods  used in S ample        
372    }        
373    //<snippe tStateMode lTransitio ns.StatusO ption>        
374    public cl ass Status Option        
375    {        
376     public i nt StatusV alue { get ; set; }        
377     public S tring Stat usLabel {  get; set;  }        
378     public i nt StateVa lue { get;  set; }        
379     public S tring Stat eLabel { g et; set; }        
380    }        
381    //</snipp etStateMod elTransiti ons.Status Option>        
382   }        
383   //</snippe tStateMode lTransitio ns>