643. Araxis Merge File Comparison Report

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

643.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\QuickStart SimplifiedConnection.cs Tue Dec 20 19:51:42 2016 UTC
2 Wed Feb 1 19:56:54 2017 UTC

643.2 Comparison summary

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

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

643.4 Active regular expressions

No regular expressions were active.

643.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 Simplified Connection >        
17   using Syst em;        
18   using Syst em.Configu ration;        
19   using Syst em.Service Model;        
20          
21   // These n amespaces  are found  in the Mic rosoft.Crm .Sdk.Proxy .dll assem bly        
22   // located  in the SD K\bin fold er of the  SDK downlo ad.        
23   using Micr osoft.Crm. Sdk.Messag es;        
24          
25   // These n amespaces  are found  in the Mic rosoft.Xrm .Sdk.dll a ssembly        
26   // located  in the SD K\bin fold er of the  SDK downlo ad.        
27   using Micr osoft.Xrm. Sdk;        
28   using Micr osoft.Xrm. Sdk.Query;        
29   using Micr osoft.Xrm. Tooling.Co nnector;        
30          
31   // These n amespaces  are found  in the Mic rosoft.Xrm .Client.dl l assembly        
32   // located  in the SD K\bin fold er of the  SDK downlo ad.        
33   using Syst em.Collect ions.Gener ic;        
34          
35   namespace  Microsoft. Crm.Sdk.Sa mples        
36   {        
37       /// <s ummary>        
38       /// Th is sample  uses the C rmConnecti on class f ound in th e Microsof t.Xrm.Clie nt        
39       /// na mespace to  connect t o and auth enticate w ith the or ganization  web servi ce.        
40       ///         
41       /// Ne xt, the sa mple demon strates ho w to do ba sic entity  operation s like cre ate,        
42       /// re trieve, up date, and  delete.</s ummary>        
43       /// <r emarks>        
44       /// At  run-time,  you will  be given t he option  to delete  all the da tabase        
45       /// re cords crea ted by thi s program.        
46       ///         
47       /// No  helper co de from Cr mServiceHe lpers.cs i s used in  this sampl e.</remark s>        
48       /// <s ee cref="h ttp://msdn .microsoft .com/en-us /library/g g695810.as px"/>        
49       public  class Sim plifiedCon nection        
50       {        
51           #r egion Clas s Level Me mbers        
52          
53           pr ivate Guid  _accountI d;        
54           pr ivate IOrg anizationS ervice _or gService;        
55                   
56           #e ndregion C lass Level  Members        
57          
58            / // <summar y>        
59           // / The Run( ) method f irst conne cts to the  Organizat ion servic e. Afterwa rds,        
60           // / basic cr eate, retr ieve, upda te, and de lete entit y operatio ns are per formed.        
61           // / </summar y>        
62           // / <param n ame="conne ctionStrin g">Provide s service  connection  informati on.</param >        
63           // / <param n ame="promp tforDelete ">When Tru e, the use r will be  prompted t o delete a ll        
64           // / created  entities.< /param>        
65           pu blic void  Run(String  connectio nString, b ool prompt forDelete)        
66           {        
67                try        
68                {        
69                    // C onnect to  the CRM we b service  using a co nnection s tring.        
70                    CrmS erviceClie nt conn =  new Xrm.To oling.Conn ector.CrmS erviceClie nt(connect ionString) ;        
71            
72                    // C ast the pr oxy client  to the IO rganizatio nService i nterface.        
73                    _org Service =  (IOrganiza tionServic e)conn.Org anizationW ebProxyCli ent != nul l ? (IOrga nizationSe rvice)conn .Organizat ionWebProx yClient :  (IOrganiza tionServic e)conn.Org anizationS erviceProx y;        
74                         
75                    //Cr eate any e ntity reco rds this s ample requ ires.        
76                    Crea teRequired Records();        
77          
78                    // O btain info rmation ab out the lo gged on us er from th e web serv ice.        
79                    Guid  userid =  ((WhoAmIRe sponse)_or gService.E xecute(new  WhoAmIReq uest())).U serId;        
80                    Syst emUser sys temUser =  (SystemUse r)_orgServ ice.Retrie ve("system user", use rid,        
81                         new Column Set(new st ring[] { " firstname" , "lastnam e" }));        
82                    Cons ole.WriteL ine("Logge d on user  is {0} {1} .", system User.First Name, syst emUser.Las tName);        
83          
84                    // R etrieve th e version  of Microso ft Dynamic s CRM.        
85                    Retr ieveVersio nRequest v ersionRequ est = new  RetrieveVe rsionReque st();        
86                    Retr ieveVersio nResponse  versionRes ponse =        
87                         (RetrieveV ersionResp onse)_orgS ervice.Exe cute(versi onRequest) ;        
88                    Cons ole.WriteL ine("Micro soft Dynam ics CRM ve rsion {0}. ", version Response.V ersion);        
89          
90                    // I nstantiate  an accoun t object.  Note the u se of opti on set enu merations  defined in  OptionSet s.cs.        
91                    // R efer to th e Entity M etadata to pic in the  SDK docum entation t o determin e which at tributes m ust        
92                    // b e set for  each entit y.        
93                    Acco unt accoun t = new Ac count { Na me = "Four th Coffee"  };        
94                    acco unt.Accoun tCategoryC ode = new  OptionSetV alue((int) AccountAcc ountCatego ryCode.Pre ferredCust omer);        
95                    acco unt.Custom erTypeCode  = new Opt ionSetValu e((int)Acc ountCustom erTypeCode .Investor) ;        
96          
97                    // C reate an a ccount rec ord named  Fourth Cof fee.        
98                    _acc ountId = _ orgService .Create(ac count);        
99          
100                    Cons ole.Write( "{0} {1} c reated, ",  account.L ogicalName , account. Name);        
101          
102                    // R etrieve th e several  attributes  from the  new accoun t.        
103                    Colu mnSet cols  = new Col umnSet(        
104                         new String [] { "name ", "addres s1_postalc ode", "las tusedincam paign" });        
105          
106                    Acco unt retrie vedAccount  = (Accoun t)_orgServ ice.Retrie ve("accoun t", _accou ntId, cols );        
107                    Cons ole.Write( "retrieved , ");        
108          
109                    // U pdate the  postal cod e attribut e.        
110                    retr ievedAccou nt.Address 1_PostalCo de = "9805 2";        
111          
112                    // T he address  2 postal  code was s et acciden tally, so  set it to  null.        
113                    retr ievedAccou nt.Address 2_PostalCo de = null;        
114          
115                    // S hows use o f a Money  value.        
116                    retr ievedAccou nt.Revenue  = new Mon ey(5000000 );        
117          
118                    // S hows use o f a Boolea n value.        
119                    retr ievedAccou nt.CreditO nHold = fa lse;        
120          
121                    // U pdate the  account re cord.        
122                    _org Service.Up date(retri evedAccoun t);        
123                    Cons ole.WriteL ine("and u pdated.");        
124          
125                    // D elete any  entity rec ords this  sample cre ated.        
126                    Dele teRequired Records(pr omptforDel ete);        
127                }        
128          
129                // Catch  any servi ce fault e xceptions  that Micro soft Dynam ics CRM th rows.        
130                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>)        
131                {        
132                    // Y ou can han dle an exc eption her e or pass  it back to  the calli ng method.        
133                    thro w;        
134                }        
135           }        
136          
137           #r egion Publ ic Methods        
138           // / <summary >        
139           // / Creates  any entity  records t his sample  requires.        
140           // / </summar y>        
141           pu blic void  CreateRequ iredRecord s()        
142           {        
143                // For t his sample , all requ ired entit ies are cr eated in t he Run() m ethod.        
144           }        
145          
146           // / <summary >        
147           // / Deletes  any entity  records t hat were c reated for  this samp le.        
148           // / <param n ame="promp t">Indicat es whether  to prompt  the user         
149           // / to delet e the reco rds create d in this  sample.</p aram>        
150           // / </summar y>        
151           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
152           {        
153                bool del eteRecords  = true;        
154          
155                if (prom pt)        
156                {        
157                    Cons ole.Write( "\nDo you  want these  entity re cords dele ted? (y/n)  [y]: ");        
158                    Stri ng answer  = Console. ReadLine() ;        
159          
160                    dele teRecords  = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ) || answe r == Strin g.Empty);        
161                }        
162          
163                if (dele teRecords)        
164                {        
165                    _org Service.De lete(Accou nt.EntityL ogicalName , _account Id);        
166                    Cons ole.WriteL ine("Entit y records  have been  deleted.") ;        
167                }        
168           }        
169          
170           #e ndregion P ublic Meth ods        
171          
172           #r egion Priv ate Method s        
173          
174           // / <summary >        
175           // / Gets web  service c onnection  informatio n from the  app.confi g file.        
176           // / If there  is more t han one av ailable, t he user is  prompted  to select        
177           // / the desi red connec tion confi guration b y name.        
178           // / </summar y>        
179           // / <returns >A string  containing  web servi ce connect ion config uration in formation. </returns>        
180           pr ivate stat ic String  GetService Configurat ion()        
181           {        
182                // Get a vailable c onnection  strings fr om app.con fig.        
183                int coun t = Config urationMan ager.Conne ctionStrin gs.Count;        
184          
185                // Creat e a filter  list of c onnection  strings so  that we h ave a list  of valid        
186                // conne ction stri ngs for Mi crosoft Dy namics CRM  only.        
187                List<Key ValuePair< String, St ring>> fil teredConne ctionStrin gs =         
188                    new  List<KeyVa luePair<St ring, Stri ng>>();        
189          
190                for (int  a = 0; a  < count; a ++)        
191                {        
192                    if ( isValidCon nectionStr ing(Config urationMan ager.Conne ctionStrin gs[a].Conn ectionStri ng))        
193                         filteredCo nnectionSt rings.Add        
194                             (new K eyValuePai r<string,  string>        
195                                 (C onfigurati onManager. Connection Strings[a] .Name,        
196                                 Co nfiguratio nManager.C onnectionS trings[a]. Connection String));        
197                }        
198          
199                // No va lid connec tions stri ngs found.  Write out  and error  message.        
200                if (filt eredConnec tionString s.Count ==  0)        
201                {        
202                    Cons ole.WriteL ine("An ap p.config f ile contai ning at le ast one va lid Micros oft Dynami cs CRM " +        
203                         "connectio n string c onfigurati on must ex ist in the  run-time  folder.");        
204                    Cons ole.WriteL ine("\nThe re are sev eral comme nted out e xample con nection st rings in "  +        
205                         "the provi ded app.co nfig file.  Uncomment  one of th em and mod ify the st ring accor ding " +        
206                         "to your M icrosoft D ynamics CR M installa tion. Then  re-run th e sample." );        
207                    retu rn null;        
208                }        
209          
210                // If on e valid co nnection s tring is f ound, use  that.        
211                if (filt eredConnec tionString s.Count ==  1)        
212                {        
213                    retu rn filtere dConnectio nStrings[0 ].Value;        
214                }        
215          
216                // If mo re than on e valid co nnection s tring is f ound, let  the user d ecide whic h to use.        
217                if (filt eredConnec tionString s.Count >  1)        
218                {        
219                    Cons ole.WriteL ine("The f ollowing c onnections  are avail able:");        
220                    Cons ole.WriteL ine("----- ---------- ---------- ---------- ---------- ---");        
221          
222                    for  (int i = 0 ; i < filt eredConnec tionString s.Count; i ++)        
223                    {        
224                         Console.Wr ite("\n({0 }) {1}\t",        
225                         i + 1, fil teredConne ctionStrin gs[i].Key) ;        
226                    }        
227          
228                    Cons ole.WriteL ine();        
229          
230                    Cons ole.Write( "\nType th e number o f the conn ection to  use (1-{0} ) [{0}] :  ",         
231                         filteredCo nnectionSt rings.Coun t);        
232                    Stri ng input =  Console.R eadLine();        
233                    int  configNumb er;        
234                    if ( input == S tring.Empt y) input =  filteredC onnectionS trings.Cou nt.ToStrin g();        
235                    if ( !Int32.Try Parse(inpu t, out con figNumber)  || config Number > c ount ||         
236                         configNumb er == 0)        
237                    {        
238                         Console.Wr iteLine("O ption not  valid.");        
239                         return nul l;        
240                    }        
241          
242                    retu rn filtere dConnectio nStrings[c onfigNumbe r - 1].Val ue;        
243          
244                }        
245                return n ull;        
246                        
247           }        
248          
249          
250           // / <summary >        
251           // / Verifies  if a conn ection str ing is val id for Mic rosoft Dyn amics CRM.        
252           // / </summar y>        
253           // / <returns >True for  a valid st ring, othe rwise Fals e.</return s>        
254           pr ivate stat ic Boolean  isValidCo nnectionSt ring(Strin g connecti onString)        
255           {        
256                // At a  minimum, a  connectio n string m ust contai n one of t hese argum ents.        
257                if (conn ectionStri ng.Contain s("Url=")  ||        
258                    conn ectionStri ng.Contain s("Server= ") ||        
259                    conn ectionStri ng.Contain s("Service Uri="))        
260                    retu rn true;        
261          
262                return f alse;        
263           }        
264                   
265           #e ndregion P rivate Met hods        
266          
267           #r egion Main  method        
268          
269           // / <summary >        
270           // / Standard  Main() me thod used  by most SD K samples.        
271           // / </summar y>        
272           // / <param n ame="args" ></param>        
273           st atic publi c void Mai n(string[]  args)        
274           {        
275                try        
276                {        
277                    // O btain conn ection con figuration  informati on for the  Microsoft  Dynamics        
278                    // C RM organiz ation web  service.        
279                    Stri ng connect ionString  = GetServi ceConfigur ation();        
280          
281                    if ( connection String !=  null)        
282                    {        
283                         Simplified Connection  app = new  Simplifie dConnectio n();        
284                         app.Run(co nnectionSt ring, true );        
285                    }        
286                }        
287          
288                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
289                {        
290                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
291                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
292                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
293                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
294                    Cons ole.WriteL ine("Trace : {0}", ex .Detail.Tr aceText);        
295                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
296                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
297                }        
298                catch (S ystem.Time outExcepti on ex)        
299                {        
300                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
301                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
302                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
303                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
304                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
305                }        
306                catch (S ystem.Exce ption ex)        
307                {        
308                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
309                    Cons ole.WriteL ine(ex.Mes sage);        
310          
311                    // D isplay the  details o f the inne r exceptio n.        
312                    if ( ex.InnerEx ception !=  null)        
313                    {        
314                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
315          
316                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
317                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
318                         if (fe !=  null)        
319                         {        
320                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
321                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
322                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
323                             Consol e.WriteLin e("Trace:  {0}", fe.D etail.Trac eText);        
324                             Consol e.WriteLin e("Inner F ault: {0}" ,        
325                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
326                         }        
327                    }        
328                }        
329                        
330                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
331                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
332          
333                finally        
334                {        
335                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
336                    Cons ole.ReadLi ne();        
337                }        
338           }        
339           #e ndregion M ain method        
340       }        
341   }        
342   //</snippe tSimplifie dConnectio n>