433. Araxis Merge File Comparison Report

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

433.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\GeneralProgramming\Queries FetchXmlAndQueryExpressionQueryConversion.cs Tue Dec 20 19:51:46 2016 UTC
2 Wed Feb 1 19:56:34 2017 UTC

433.2 Comparison summary

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

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

433.4 Active regular expressions

No regular expressions were active.

433.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 FetchXmlAn dQueryExpr essionQuer yConversio n>        
17   using Syst em;        
18   using Syst em.Collect ions.Gener ic;        
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       public  class Fet chXmlAndQu eryExpress ionQueryCo nversion        
28       {        
29                   
30           #r egion Clas s Level Me mbers        
31           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
32           pr ivate Guid  _accountI d;        
33           pr ivate read only List< Guid> _con tactIdList  = new Lis t<Guid>();        
34           pr ivate read only List< Guid> _opp ortunityId List = new  List<Guid >();        
35           #e ndregion        
36          
37           #r egion How  To Sample  Code        
38           pu blic void  Run(Server Connection .Configura tion serve rConfig,        
39                bool pro mptforDele te)        
40           {        
41                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))        
42                {        
43                    // T his statem ent is req uired to e nable earl y-bound ty pe support .        
44                    _ser viceProxy. EnableProx yTypes();        
45                    Crea teRequired Records();        
46                    DoQu eryExpress ionToFetch XmlConvers ion();        
47                    DoFe tchXmlToQu eryExpress ionConvers ion();        
48                    Dele teRequired Records(pr omptforDel ete);        
49                }        
50           }        
51          
52           pr ivate void  DoQueryEx pressionTo FetchXmlCo nversion()        
53           {        
54                //<snipp etFetchXml AndQueryEx pressionQu eryConvers ion2>        
55                // Build  a query e xpression  that we wi ll turn in to FetchXM L.        
56                var quer yExpressio n = new Qu eryExpress ion()        
57                {        
58                    Dist inct = fal se,        
59                    Enti tyName = C ontact.Ent ityLogical Name,        
60                    Colu mnSet = ne w ColumnSe t("fullnam e", "addre ss1_teleph one1"),        
61                    Link Entities =          
62                         {        
63                             new Li nkEntity         
64                             {        
65                                 Jo inOperator  = JoinOpe rator.Left Outer,        
66                                 Li nkFromAttr ibuteName  = "parentc ustomerid" ,        
67                                 Li nkFromEnti tyName = C ontact.Ent ityLogical Name,        
68                                 Li nkToAttrib uteName =  "accountid ",        
69                                 Li nkToEntity Name = Acc ount.Entit yLogicalNa me,        
70                                 Li nkCriteria  =         
71                                 {        
72                                      Conditio ns =         
73                                      {        
74                                          new  ConditionE xpression( "name", Co nditionOpe rator.Equa l, "Litwar e, Inc.")        
75                                      }        
76                                 }        
77                             }        
78                         },        
79                    Crit eria =        
80                    {        
81                         Filters =         
82                             {        
83                                 ne w FilterEx pression        
84                                 {        
85                                      FilterOp erator = L ogicalOper ator.And,        
86                                      Conditio ns =         
87                                      {        
88                                          new  ConditionE xpression( "address1_ stateorpro vince", Co nditionOpe rator.Equa l, "WA"),        
89                                          new  ConditionE xpression( "address1_ city", Con ditionOper ator.In, n ew String[ ] {"Redmon d", "Belle vue" , "Ki rkland", " Seattle"}) ,        
90                                          new  ConditionE xpression( "createdon ", Conditi onOperator .LastXDays , 30),        
91                                          new  ConditionE xpression( "emailaddr ess1", Con ditionOper ator.NotNu ll)        
92                                      },        
93                                 },        
94                                 ne w FilterEx pression        
95                                 {        
96                                      FilterOp erator = L ogicalOper ator.Or,        
97                                      Conditio ns =        
98                                      {        
99                                          new  ConditionE xpression( "address1_ telephone1 ", Conditi onOperator .Like, "(2 06)%"),        
100                                          new  ConditionE xpression( "address1_ telephone1 ", Conditi onOperator .Like, "(4 25)%")        
101                                      }        
102                                 }        
103                             }        
104                    }        
105                };        
106          
107                // Run t he query a s a query  expression .        
108                EntityCo llection q ueryExpres sionResult  =        
109                    _ser viceProxy. RetrieveMu ltiple(que ryExpressi on);        
110                Console. WriteLine( "Output fo r query as  QueryExpr ession:");        
111                DisplayC ontactQuer yResults(q ueryExpres sionResult );        
112          
113                // Conve rt the que ry express ion to Fet chXML.        
114                var conv ersionRequ est = new  QueryExpre ssionToFet chXmlReque st        
115                {        
116                    Quer y = queryE xpression        
117                };        
118                var conv ersionResp onse =        
119                    (Que ryExpressi onToFetchX mlResponse )_serviceP roxy.Execu te(convers ionRequest );        
120          
121                // Use t he convert ed query t o make a r etrieve mu ltiple req uest to Mi crosoft Dy namics CRM .        
122                String f etchXml =  conversion Response.F etchXml;        
123                var fetc hQuery = n ew FetchEx pression(f etchXml);        
124                EntityCo llection r esult = _s erviceProx y.Retrieve Multiple(f etchQuery) ;        
125          
126                // Displ ay the res ults.        
127                Console. WriteLine( "\nOutput  for query  after conv ersion to  FetchXML:" );        
128                DisplayC ontactQuer yResults(r esult);        
129                //</snip petFetchXm lAndQueryE xpressionQ ueryConver sion2>        
130          
131           }        
132          
133           pr ivate stat ic void Di splayConta ctQueryRes ults(Entit yCollectio n result)        
134           {        
135                Console. WriteLine( "List all  contacts m atching sp ecified pa rameters") ;        
136                Console. WriteLine( "========= ========== ========== ========== ========") ;        
137                foreach  (Entity en tity in re sult.Entit ies)        
138                {        
139                    var  contact =  entity.ToE ntity<Cont act>();        
140                    Cons ole.WriteL ine("Conta ct ID: {0} ", contact .Id);        
141                    Cons ole.WriteL ine("Conta ct Name: { 0}", conta ct.FullNam e);        
142                    Cons ole.WriteL ine("Conta ct Phone:  {0}", cont act.Addres s1_Telepho ne1);        
143                }        
144                Console. WriteLine( "<End of L isting>");        
145                Console. WriteLine( );        
146           }        
147          
148           pr ivate void  DoFetchXm lToQueryEx pressionCo nversion()        
149           {        
150                //<snipp etFetchXml AndQueryEx pressionQu eryConvers ion1>        
151                // Creat e a Fetch  query that  we will c onvert int o a query  expression .        
152                var fetc hXml =        
153                    @"<f etch mappi ng='logica l' version ='1.0'>        
154                             <entit y name='op portunity' >        
155                                      <attribu te name='n ame' />        
156                                      <filter>        
157                                               <condition  attribute ='estimate dclosedate ' operator ='next-x-f iscal-year s' value=' 3' />        
158                                      </filter >        
159                                      <link-en tity name= 'account'  from='acco untid' to= 'customeri d'>        
160                                               <link-enti ty name='c ontact' fr om='parent customerid ' to='acco untid'>        
161                                                       <a ttribute n ame='fulln ame' />        
162                                                       <f ilter>        
163                                                                <con dition att ribute='ad dress1_cit y' operato r='eq' val ue='Bellev ue' />        
164                                                                <con dition att ribute='ad dress1_sta teorprovin ce' operat or='eq' va lue='WA' / >        
165                                                       </ filter>        
166                                               </link-ent ity>        
167                                      </link-e ntity>        
168                             </enti ty>        
169                    </fe tch>";        
170          
171                // Run t he query w ith the Fe tchXML.        
172                var fetc hExpressio n = new Fe tchExpress ion(fetchX ml);        
173                EntityCo llection f etchResult  =        
174                    _ser viceProxy. RetrieveMu ltiple(fet chExpressi on);        
175                Console. WriteLine( "\nOutput  for query  as FetchXM L:");        
176                DisplayO pportunity QueryResul ts(fetchRe sult);        
177          
178                // Conve rt the Fet chXML into  a query e xpression.        
179                var conv ersionRequ est = new  FetchXmlTo QueryExpre ssionReque st        
180                {        
181                    Fetc hXml = fet chXml        
182                };        
183          
184                var conv ersionResp onse =        
185                    (Fet chXmlToQue ryExpressi onResponse )_serviceP roxy.Execu te(convers ionRequest );        
186          
187                // Use t he newly c onverted q uery expre ssion to m ake a retr ieve multi ple        
188                // reque st to Micr osoft Dyna mics CRM.        
189                QueryExp ression qu eryExpress ion = conv ersionResp onse.Query ;        
190          
191                EntityCo llection r esult = _s erviceProx y.Retrieve Multiple(q ueryExpres sion);        
192          
193                // Displ ay the res ults.        
194                Console. WriteLine( "\nOutput  for query  after conv ersion to  QueryExpre ssion:");        
195                DisplayO pportunity QueryResul ts(result) ;        
196                //</snip petFetchXm lAndQueryE xpressionQ ueryConver sion1>        
197          
198           }        
199          
200           pr ivate stat ic void Di splayOppor tunityQuer yResults(E ntityColle ction resu lt)        
201           {        
202                Console. WriteLine( "List all  opportunit ies matchi ng specifi ed paramet ers.");        
203                Console. WriteLine( "========= ========== ========== ========== ========== ========== ========== ======");        
204                foreach  (Entity en tity in re sult.Entit ies)        
205                {        
206                    var  opportunit y = entity .ToEntity< Opportunit y>();        
207                    Cons ole.WriteL ine("Oppor tunity ID:  {0}", opp ortunity.I d);        
208                    Cons ole.WriteL ine("Oppor tunity: {0 }", opport unity.Name );        
209                    var  aliased =  (AliasedVa lue)opport unity["con tact2.full name"];        
210                    var  contactNam e = (Strin g)aliased. Value;        
211                    Cons ole.WriteL ine("Assoc iated cont act: {0}",  contactNa me);        
212                }        
213                Console. WriteLine( "<End of L isting>");        
214                Console. WriteLine( );        
215           }        
216          
217           // / <summary >        
218           // / Creates  any entity  records t hat this s ample requ ires.        
219           // / </summar y>        
220           pu blic void  CreateRequ iredRecord s()        
221           {        
222          
223                // Creat e an accou nt.        
224                var acco unt = new  Account        
225                {        
226                    Name  = "Litwar e, Inc.",        
227                    Addr ess1_State OrProvince  = "Colora do"        
228                };        
229                _account Id = (_ser viceProxy. Create(acc ount));        
230          
231                // Creat e the two  contacts.        
232                var cont act = new  Contact()        
233                {        
234                    Firs tName = "B en",        
235                    Last Name = "An drews",        
236                    EMai lAddress1  = "sample@ example.co m",        
237                    Addr ess1_City  = "Redmond ",        
238                    Addr ess1_State OrProvince  = "WA",        
239                    Addr ess1_Telep hone1 = "( 206)555-55 55",        
240                    Pare ntCustomer Id = new E ntityRefer ence        
241                    {        
242                         Id = _acco untId,        
243                         LogicalNam e = accoun t.LogicalN ame        
244                    }        
245                };        
246                _contact IdList.Add (_serviceP roxy.Creat e(contact) );        
247          
248                contact  = new Cont act()        
249                {        
250                    Firs tName = "C olin",        
251                    Last Name = "Wi lcox",        
252                    EMai lAddress1  = "sample@ example.co m",        
253                    Addr ess1_City  = "Bellevu e",        
254                    Addr ess1_State OrProvince  = "WA",        
255                    Addr ess1_Telep hone1 = "( 425)555-55 55",        
256                    Pare ntCustomer Id = new E ntityRefer ence        
257                    {        
258                         Id = _acco untId,        
259                         LogicalNam e = accoun t.LogicalN ame        
260                    }        
261                };        
262                _contact IdList.Add (_serviceP roxy.Creat e(contact) );        
263          
264                // Creat e two oppo rtunities.        
265                var oppo rtunity =  new Opport unity()        
266                {        
267                    Name  = "Litwar e, Inc. Op portunity  1",        
268                    Esti matedClose Date = Dat eTime.Now. AddMonths( 6),        
269                    Cust omerId = n ew EntityR eference        
270                    {        
271                         Id = _acco untId,        
272                         LogicalNam e = accoun t.LogicalN ame        
273                    }        
274                };        
275                _opportu nityIdList .Add(_serv iceProxy.C reate(oppo rtunity));        
276          
277                opportun ity = new  Opportunit y()        
278                {        
279                    Name  = "Litwar e, Inc. Op portunity  2",        
280                    Esti matedClose Date = Dat eTime.Now. AddYears(4 ),        
281                    Cust omerId = n ew EntityR eference        
282                    {        
283                         Id = _acco untId,        
284                         LogicalNam e = accoun t.LogicalN ame        
285                    }        
286                };        
287                _opportu nityIdList .Add(_serv iceProxy.C reate(oppo rtunity));        
288           }        
289          
290           // / <summary >        
291           // / Deletes  any entity  records t hat were c reated for  this samp le.        
292           // / <param n ame="promp t">Indicat es whether  to prompt  the user         
293           // / to delet e the reco rds create d in this  sample.</p aram>        
294           // / </summar y>        
295           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
296           {        
297                bool toB eDeleted =  true;        
298          
299                if (prom pt)        
300                {        
301                    // A sk the use r if the c reated ent ities shou ld be dele ted.        
302                    Cons ole.Write( "\nDo you  want these  entity re cords dele ted? (y/n)  [y]: ");        
303                    Stri ng answer  = Console. ReadLine() ;        
304                    if ( answer.Sta rtsWith("y ") ||        
305                         answer.Sta rtsWith("Y ") ||        
306                         answer ==  String.Emp ty)        
307                    {        
308                         toBeDelete d = true;        
309                    }        
310                    else        
311                    {        
312                         toBeDelete d = false;        
313                    }        
314                }        
315          
316                if (toBe Deleted)        
317                {        
318                    // D elete all  records cr eated in t his sample .        
319                    fore ach (Guid  contactId  in _contac tIdList)        
320                    {        
321                         _servicePr oxy.Delete (Contact.E ntityLogic alName, co ntactId);        
322                    }        
323          
324                    fore ach (Guid  opportunit yId in _op portunityI dList)        
325                    {        
326                         _servicePr oxy.Delete (Opportuni ty.EntityL ogicalName , opportun ityId);        
327                    }        
328          
329                    _ser viceProxy. Delete(Acc ount.Entit yLogicalNa me, _accou ntId);        
330          
331                    Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. ");        
332                }        
333           }        
334          
335           #e ndregion        
336          
337           #r egion Main  method        
338          
339           // / <summary >        
340           // / Standard  Main() me thod used  by most SD K samples.        
341           // / </summar y>        
342           // / <param n ame="args" ></param>        
343           st atic publi c void Mai n(string[]  args)        
344           {        
345                try        
346                {        
347                    // O btain the  target org anization' s web addr ess and cl ient logon          
348                    // c redentials  from the  user.        
349                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
350                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
351          
352                    var  app = new  FetchXmlAn dQueryExpr essionQuer yConversio n();        
353                    app. Run(config , true);        
354                }        
355                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
356                {        
357                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
358                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
359                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
360                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
361                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
362                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
363                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
364                }        
365                catch (S ystem.Time outExcepti on ex)        
366                {        
367                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
368                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
369                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
370                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
371                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
372                }        
373                catch (S ystem.Exce ption ex)        
374                {        
375                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
376                    Cons ole.WriteL ine(ex.Mes sage);        
377          
378                    // D isplay the  details o f the inne r exceptio n.        
379                    if ( ex.InnerEx ception !=  null)        
380                    {        
381                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
382          
383                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
384                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
385                         if (fe !=  null)        
386                         {        
387                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
388                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
389                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
390                             Consol e.WriteLin e("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
391                             Consol e.WriteLin e("Inner F ault: {0}" ,        
392                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
393                         }        
394                    }        
395                }        
396                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
397                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
398          
399                finally        
400                {        
401                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
402                    Cons ole.ReadLi ne();        
403                }        
404           }        
405           #e ndregion M ain method        
406       }        
407   }        
408   //</snippe tFetchXmlA ndQueryExp ressionQue ryConversi on>