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

432.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 FetchPagingWithCookie.cs Tue Dec 20 19:51:46 2016 UTC
2 Wed Feb 1 19:56:34 2017 UTC

432.2 Comparison summary

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

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

432.4 Active regular expressions

No regular expressions were active.

432.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 FetchPagin gWithCooki e>        
18   using Syst em;        
19   using Syst em.Service Model;        
20   using Syst em.Service Model.Desc ription;        
21   using Syst em.Collect ions.Gener ic;        
22   using Syst em.Text;        
23   using Syst em.Xml;        
24   using Syst em.IO;        
25          
26   // These n amespaces  are found  in the Mic rosoft.Xrm .Sdk.dll a ssembly        
27   // found i n the SDK\ bin folder .        
28   using Micr osoft.Xrm. Sdk;        
29   using Micr osoft.Xrm. Sdk.Client ;        
30   using Micr osoft.Xrm. Sdk.Query;        
31   using Micr osoft.Xrm. Sdk.Discov ery;        
32          
33   // This na mespace is  found in  Microsoft. Crm.Sdk.Pr oxy.dll as sembly        
34   // found i n the SDK\ bin folder .        
35   using Micr osoft.Crm. Sdk.Messag es;        
36   using Micr osoft.Xrm. Sdk.Messag es;        
37          
38          
39   namespace  Microsoft. Crm.Sdk.Sa mples        
40   {        
41       /// <s ummary>        
42       /// De monstrates  how to us e the Fetc h XML meth od with a  paging        
43       /// co okie to re trieve a b atch of re cords.        
44       /// If  you want  to run thi s sample r epeatedly,  you have  the option  to         
45       /// de lete all t he records  created a t the end  of executi on.        
46       /// </ summary>        
47       class  FetchPagin gWithCooki e        
48       {        
49           #r egion Clas s Level Me mbers        
50          
51           // / <summary >        
52           // / Stores t he organiz ation serv ice proxy.        
53           // / </summar y>        
54           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
55           pr ivate IOrg anizationS ervice _se rvice;        
56          
57           //  Define th e IDs need ed for thi s sample.        
58           pu blic Guid  _parentAcc ountId;        
59           pu blic Guid[ ] _childAc countIds;        
60          
61           #e ndregion C lass Level  Members        
62          
63           #r egion How  To Sample  Code        
64           // / <summary >        
65           // / Create a nd configu re the org anization  service pr oxy.        
66           // / Create a  parent ac count reco rd and sub sequent 10  child acc ount recor ds.        
67           // / Retrieve  batch of  records us ing Retrie veMultiple  message w ith paging  cookie.        
68           // / Optional ly delete  any entity  records t hat were c reated for  this samp le.        
69           // / </summar y>        
70           // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param>        
71           // / <param n ame="promp tForDelete ">When Tru e, the use r will be  prompted t o delete a ll        
72           // / created  entities.< /param>        
73           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete)        
74           {        
75                try        
76                {        
77                             
78                    // C onnect to  the Organi zation ser vice.         
79                    // T he using s tatement a ssures tha t the serv ice proxy  will be pr operly dis posed.        
80                    usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri,server Config.Cre dentials,  serverConf ig.DeviceC redentials ))        
81                    {        
82                         // This st atement is  required  to enable  early-boun d type sup port.        
83                         _servicePr oxy.Enable ProxyTypes ();        
84          
85                         _service =  (IOrganiz ationServi ce)_servic eProxy;        
86          
87                         // Call th e method t o create a ny data th at this sa mple requi res.        
88                         CreateRequ iredRecord s();        
89          
90                         //<snippet FetchPagin gWithCooki e1>        
91                         // Define  the fetch  attributes .        
92                         // Set the  number of  records p er page to  retrieve.        
93                         int fetchC ount = 3;        
94                         // Initial ize the pa ge number.        
95                         int pageNu mber = 1;        
96                         // Initial ize the nu mber of re cords.        
97                         int record Count = 0;        
98                         // Specify  the curre nt paging  cookie. Fo r retrievi ng the fir st page,         
99                         // pagingC ookie shou ld be null .        
100                         string pag ingCookie  = null;        
101          
102                         // Create  the FetchX ml string  for retrie ving all c hild accou nts to a p arent acco unt.        
103                         // This fe tch query  is using 1  placehold er to spec ify the pa rent accou nt id         
104                         // for fil tering out  required  accounts.  Filter que ry is opti onal.        
105                         // Fetch q uery also  includes o ptional or der criter ia that, i n this cas e, is used          
106                         // to orde r the resu lts in asc ending ord er on the  name data  column.        
107                         string fet chXml = st ring.Forma t(@"<fetch  version=' 1.0'         
108                                                            mapping= 'logical'         
109                                                            output-f ormat='xml -platform' >        
110                                                            <entity  name='acco unt'>        
111                                                                <att ribute nam e='name' / >        
112                                                                <att ribute nam e='emailad dress1' />        
113                                                                <ord er attribu te='name'  descending ='false'/>        
114                                                                <fil ter type=' and'>        
115                                                                                      <con dition att ribute='pa rentaccoun tid'         
116                                                                         operat or='eq' va lue='{0}'  uiname=''  uitype=''  />        
117                                                                </fi lter>        
118                                                            </entity >        
119                                                       </ fetch>",        
120                                                            _parentA ccountId);        
121          
122                         Console.Wr iteLine("R etrieving  data in pa ges\n");         
123                         Console.Wr iteLine("# \tAccount  Name\t\t\t Email Addr ess");        
124          
125                         while (tru e)        
126                         {        
127                             // Bui ld fetchXm l string w ith the pl aceholders .        
128                             string  xml = Cre ateXml(fet chXml, pag ingCookie,  pageNumbe r, fetchCo unt);        
129          
130                             // Exc ute the fe tch query  and get th e xml resu lt.        
131                             Retrie veMultiple Request fe tchRequest 1 = new Re trieveMult ipleReques t        
132                             {        
133                                 Qu ery = new  FetchExpre ssion(xml)        
134                             };        
135          
136                             Entity Collection  returnCol lection =  ((Retrieve MultipleRe sponse)_se rvice.Exec ute(fetchR equest1)). EntityColl ection;        
137                                     
138                             foreac h (var c i n returnCo llection.E ntities)        
139                             {        
140                                 Sy stem.Conso le.WriteLi ne("{0}.\t {1}\t\t{2} ", ++recor dCount, c. Attributes ["name"],  c.Attribut es["emaila ddress1"]  );        
141                             }                                  
142                                     
143                             // Che ck for mor erecords,  if it retu rns 1.        
144                             if (re turnCollec tion.MoreR ecords)        
145                             {        
146                                 Co nsole.Writ eLine("\n* ********** *****\nPag e number { 0}\n****** ********** ", pageNum ber);        
147                                 Co nsole.Writ eLine("#\t Account Na me\t\t\tEm ail Addres s");        
148                                         
149                                 //  Increment  the page  number to  retrieve t he next pa ge.        
150                                 pa geNumber++ ;        
151          
152                                 //  Set the p aging cook ie to the  paging coo kie return ed from cu rrent resu lts.                                       
153                                 pa gingCookie  = returnC ollection. PagingCook ie;        
154                             }        
155                             else        
156                             {        
157                                 //  If no mor e records  in the res ult nodes,  exit the  loop.        
158                                 br eak;        
159                             }        
160                         }        
161                         //</snippe tFetchPagi ngWithCook ie1>                              
162          
163                         DeleteRequ iredRecord s(promptFo rDelete);        
164                    }        
165                }        
166                // Catch  any servi ce fault e xceptions  that Micro soft Dynam ics CRM th rows.        
167                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>)        
168                {        
169                    // Y ou can han dle an exc eption her e or pass  it back to  the calli ng method.        
170                    thro w;        
171                }        
172                return;        
173           }        
174          
175                   
176           pu blic strin g ExtractN odeValue(X mlNode par entNode, s tring name )        
177           {        
178                XmlNode  childNode  = parentNo de.SelectS ingleNode( name);        
179          
180                if (null  == childN ode)        
181                {        
182                    retu rn null;        
183                }        
184                return c hildNode.I nnerText;        
185           }        
186          
187           pu blic strin g ExtractA ttribute(X mlDocument  doc, stri ng name)        
188           {        
189                XmlAttri buteCollec tion attrs  = doc.Doc umentEleme nt.Attribu tes;        
190                XmlAttri bute attr  = (XmlAttr ibute)attr s.GetNamed Item(name) ;        
191                if (null  == attr)        
192                {        
193                    retu rn null;        
194                }        
195                return a ttr.Value;        
196           }        
197          
198           pu blic strin g CreateXm l(string x ml, string  cookie, i nt page, i nt count)        
199           {        
200                StringRe ader strin gReader =  new String Reader(xml );        
201                XmlTextR eader read er = new X mlTextRead er(stringR eader);        
202          
203                // Load  document        
204                XmlDocum ent doc =  new XmlDoc ument();        
205                doc.Load (reader);        
206          
207                return C reateXml(d oc, cookie , page, co unt);        
208           }        
209          
210           pu blic strin g CreateXm l(XmlDocum ent doc, s tring cook ie, int pa ge, int co unt)        
211           {        
212                XmlAttri buteCollec tion attrs  = doc.Doc umentEleme nt.Attribu tes;        
213          
214                if (cook ie != null )        
215                {        
216                    XmlA ttribute p agingAttr  = doc.Crea teAttribut e("paging- cookie");        
217                    pagi ngAttr.Val ue = cooki e;        
218                    attr s.Append(p agingAttr) ;        
219                }        
220          
221                XmlAttri bute pageA ttr = doc. CreateAttr ibute("pag e");        
222                pageAttr .Value = S ystem.Conv ert.ToStri ng(page);        
223                attrs.Ap pend(pageA ttr);        
224          
225                XmlAttri bute count Attr = doc .CreateAtt ribute("co unt");        
226                countAtt r.Value =  System.Con vert.ToStr ing(count) ;        
227                attrs.Ap pend(count Attr);        
228          
229                StringBu ilder sb =  new Strin gBuilder(1 024);        
230                StringWr iter strin gWriter =  new String Writer(sb) ;        
231          
232                XmlTextW riter writ er = new X mlTextWrit er(stringW riter);        
233                doc.Writ eTo(writer );        
234                writer.C lose();        
235          
236                return s b.ToString ();        
237           }        
238          
239           // / <summary >        
240           // / This met hod create s any enti ty records  that this  sample re quires.        
241           // / Create a  parent ac count reco rd.        
242           // / Create 1 0 child ac counts to  the parent  account r ecord.        
243           // / </summar y>        
244           pu blic void  CreateRequ iredRecord s()        
245           {        
246                // Insta ntiate a a ccount ent ity record  and set i ts propert y values.        
247                // See t he Entity  Metadata t opic in th e SDK docu mentation        
248                // to de termine wh ich attrib utes must  be set for  each enti ty.        
249                // Creat e the pare nt account .        
250                Account  parentAcco unt = new  Account        
251                {        
252                    Name  = "Root T est Accoun t",        
253                    EMai lAddress1  = "root@ro ot.com"        
254                };        
255                        
256                        
257                _parentA ccountId =  _service. Create(par entAccount );        
258          
259                // Creat e 10 child  accounts.        
260                _childAc countIds =  new Guid[ 10];         
261                int coun t = 1;        
262                while (t rue)        
263                {        
264                    Acco unt childA ccount = n ew Account        
265                    {        
266                         Name = "Ch ild Test A ccount " +  count.ToS tring(),        
267                         EMailAddre ss1 = "chi ld" + coun t.ToString () + "@roo t.com",        
268                         EMailAddre ss2 = "sam e@root.com ",        
269                         ParentAcco untId = ne w EntityRe ference(Ac count.Enti tyLogicalN ame, _pare ntAccountI d)        
270                    };        
271                            
272                    _chi ldAccountI ds[count -  1] = _ser vice.Creat e(childAcc ount);        
273          
274                    // J ump out of  the loop  after crea ting 10 ch ild accoun ts.        
275                    if ( count == 1 0)        
276                         break;        
277                    // I ncrement t he count.        
278                    coun t++;        
279                }                     
280                return;        
281           }        
282          
283           // / <summary >        
284           // / Deletes  any entity  records t hat were c reated for  this samp le.        
285           // / <param n ame="promp t">Indicat es whether  to prompt  the user  to delete  the record s created  in this sa mple.</par am>        
286           // / </summar y>        
287           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
288           {        
289                bool del eteRecords  = true;        
290          
291                if (prom pt)        
292                {        
293                    Cons ole.WriteL ine("\nDo  you want t hese entit y records  deleted? ( y/n)");        
294                    Stri ng answer  = Console. ReadLine() ;        
295          
296                    dele teRecords  = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ));        
297                }        
298          
299                if (dele teRecords)        
300                {        
301                    // R emove the  test paren t account.        
302                    _ser vice.Delet e(Account. EntityLogi calName, _ parentAcco untId);        
303                            
304                    // R emove 10 t est child  accounts.        
305                    int  deleteCoun t = 0;        
306                    whil e (deleteC ount < 10)        
307                    {        
308                         _service.D elete(Acco unt.Entity LogicalNam e, _childA ccountIds[ deleteCoun t]);        
309                         ++deleteCo unt;        
310                    }        
311          
312                    Cons ole.WriteL ine("Entit y records  have been  deleted.") ;        
313                }        
314           }        
315                            
316           #e ndregion H ow To Samp le Code        
317          
318           #r egion Main        
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                    Fetc hPagingWit hCookie ap p = new Fe tchPagingW ithCookie( );        
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           }        
387           #e ndregion M ain        
388          
389       }        
390   }        
391   //</snippe tFetchPagi ngWithCook ie>