307. Araxis Merge File Comparison Report

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

307.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\Client\WebResources\ImportWebResources\ImportWebResources ImportWebResources.cs Tue Dec 20 19:51:45 2016 UTC
2 Wed Feb 1 19:56:29 2017 UTC

307.2 Comparison summary

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

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

307.4 Active regular expressions

No regular expressions were active.

307.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 ImportWebR esources>        
17   using Syst em;        
18   using Syst em.Service Model;        
19   using Syst em.Service Model.Desc ription;        
20          
21   // These n amespaces  are found  in the Mic rosoft.Xrm .Sdk.dll a ssembly        
22   // located  in the SD K\bin fold er of the  SDK downlo ad.        
23   using Micr osoft.Xrm. Sdk;        
24   using Micr osoft.Xrm. Sdk.Query;        
25   using Micr osoft.Xrm. Sdk.Client ;        
26   using Micr osoft.Xrm. Sdk.Messag es;        
27   using Micr osoft.Xrm. Sdk.Metada ta;        
28   using Micr osoft.Crm. Sdk.Messag es;        
29          
30   //These re ferences a re require d for this  sample        
31   using Syst em.IO;        
32   using Syst em.Xml.Lin q;        
33   using Syst em.Linq;        
34          
35          
36   namespace  Microsoft. Crm.Sdk.Sa mples        
37   {        
38       /// <s ummary>        
39       /// De monstrates  how to im port Web R esources.< /summary>        
40       /// <r emarks>        
41       /// Th e Web Reso urces will  be define d in an XM L document .</remarks >        
42       public  class Imp ortWebReso urces        
43       {        
44           #r egion Clas s Level Me mbers        
45          
46          
47           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
48          
49           // Define Ids  needed in  this samp le        
50           pr ivate Guid  _crmSdkPu blisherId;        
51           pr ivate Syst em.String  _customiza tionPrefix ;        
52           pr ivate Bool ean _creat edPublishe r = false;        
53           pr ivate Guid  _importWe bResources SampleSolu tionId;        
54           pr ivate Syst em.String  _ImportWeb ResourcesS olutionUni queName;        
55           pr ivate Syst em.Guid[]  _webResour ceIds = ne w System.G uid[5];        
56          
57          
58          
59          
60           #e ndregion C lass Level  Members        
61          
62           #r egion How  To Sample  Code        
63           // / <summary >        
64           // / This met hod first  connects t o the Orga nization s ervice. Af terwards,        
65           // / basic cr eate, retr ieve, upda te, and de lete entit y operatio ns are per formed.        
66           // / </summar y>        
67           // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param>        
68           // / <param n ame="promp tforDelete ">When Tru e, the use r will be  prompted t o delete a ll        
69           // / created  entities.< /param>        
70           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete)        
71           {        
72                try        
73                {        
74          
75                    // C onnect to  the Organi zation ser vice.         
76                    // T he using s tatement a ssures tha t the serv ice proxy  will be pr operly dis posed.        
77                    usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri, serve rConfig.Cr edentials,  serverCon fig.Device Credential s))        
78                    {        
79                         // This st atement is  required  to enable  early-boun d type sup port.        
80                         _servicePr oxy.Enable ProxyTypes ();        
81          
82                         CreateRequ iredRecord s();        
83          
84                         //<snippet ImportWebR esources1>        
85          
86                         //Read the  descripti ve data fr om the XML  file        
87                         XDocument  xmlDoc = X Document.L oad("../.. /ImportJob .xml");        
88          
89                         //Create a  collectio n of anony mous type  references  to each o f the Web  Resources        
90                         var webRes ources = f rom webRes ource in x mlDoc.Desc endants("w ebResource ")        
91                                             s elect new        
92                                             {        
93                                                  path =  webResourc e.Element( "path").Va lue,        
94                                                  display Name = web Resource.E lement("di splayName" ).Value,        
95                                                  descrip tion = web Resource.E lement("de scription" ).Value,        
96                                                  name =  webResourc e.Element( "name").Va lue,        
97                                                  type =  webResourc e.Element( "type").Va lue        
98                                             } ;        
99          
100                         // Loop th rough the  collection  creating  Web Resour ces        
101                         int counte r = 0;        
102                         foreach (v ar webReso urce in we bResources )        
103                         {        
104                             //<sni ppetImport WebResourc es2>        
105                             //Set  the Web Re source pro perties        
106                             WebRes ource wr =  new WebRe source        
107                             {        
108                                 Co ntent = ge tEncodedFi leContents (@"../../"  + webReso urce.path) ,        
109                                 Di splayName  = webResou rce.displa yName,        
110                                 De scription  = webResou rce.descri ption,        
111                                 Na me = _cust omizationP refix + we bResource. name,        
112                                 Lo gicalName  = WebResou rce.Entity LogicalNam e,        
113                                 We bResourceT ype = new  OptionSetV alue(Int32 .Parse(web Resource.t ype))        
114                             };        
115          
116                             // Usi ng CreateR equest bec ause we wa nt to add  an optiona l paramete r        
117                             Create Request cr  = new Cre ateRequest        
118                             {        
119                                 Ta rget = wr        
120                             };        
121                             //Set  the Soluti onUniqueNa me optiona l paramete r so the W eb Resourc es will be        
122                             // cre ated in th e context  of a speci fic soluti on.        
123                             cr.Par ameters.Ad d("Solutio nUniqueNam e", _Impor tWebResour cesSolutio nUniqueNam e);        
124          
125                             Create Response c resp = (Cr eateRespon se)_servic eProxy.Exe cute(cr);        
126                             //</sn ippetImpor tWebResour ces2>        
127                             // Cap ture the i d values f or the Web  Resources  so the sa mple can d elete them .        
128                             _webRe sourceIds[ counter] =  cresp.id;        
129                             counte r++;        
130                             Consol e.WriteLin e("Created  Web Resou rce: {0}",  webResour ce.display Name);        
131                         }        
132          
133                         //</snippe tImportWeb Resources1 >        
134                         DeleteRequ iredRecord s(promptfo rDelete);        
135          
136                    }        
137          
138                }        
139          
140                // Catch  any servi ce fault e xceptions  that Micro soft Dynam ics CRM th rows.        
141                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>)        
142                {        
143                    // Y ou can han dle an exc eption her e or pass  it back to  the calli ng method.        
144                    thro w;        
145                }        
146           }        
147          
148           // <snippetIm portWebRes ources3>        
149           // Encodes th e Web Reso urce File        
150           st atic publi c string g etEncodedF ileContent s(String p athToFile)        
151           {        
152                FileStre am fs = ne w FileStre am(pathToF ile, FileM ode.Open,  FileAccess .Read);        
153                byte[] b inaryData  = new byte [fs.Length ];        
154                long byt esRead = f s.Read(bin aryData, 0 , (int)fs. Length);        
155                fs.Close ();        
156                return S ystem.Conv ert.ToBase 64String(b inaryData,  0, binary Data.Lengt h);        
157           }        
158           // </snippetI mportWebRe sources3>        
159          
160           // / <summary >        
161           // / This met hod create s a publis her and a  solution t o use when  adding th e Web reso urces.        
162           // / </summar y>        
163           pu blic void  CreateRequ iredRecord s()        
164           {        
165          
166                //Define  a new pub lisher        
167                Publishe r _crmSdkP ublisher =  new Publi sher        
168                {        
169                    Uniq ueName = " microsoftd ynamicscrm sdksamples importwebr esourcessa mple",        
170                    Frie ndlyName =  "Microsof t Dynamics  CRM SDK S amples Imp ort Web Re sources Sa mple",        
171                    Supp ortingWebs iteUrl = " http://msd n.microsof t.com/en-u s/dynamics /crm/defau lt.aspx",        
172                    Cust omizationP refix = "s ample",        
173                    EMai lAddress =  "someone@ microsoft. com",        
174                    Desc ription =  "This publ isher is u sed by the  Import We b Resource s sample f rom the Mi crosoft Dy namics CRM  Software  Developmen t Kit (SDK ) document ation."        
175                };        
176          
177                //Does p ublisher a lready exi st?        
178                QueryExp ression qu erySDKSamp lePublishe r = new Qu eryExpress ion        
179                {        
180                    Enti tyName = P ublisher.E ntityLogic alName,         
181                    Colu mnSet = ne w ColumnSe t("publish erid", "cu stomizatio nprefix",  "friendlyn ame", "isr eadonly"),        
182                    Crit eria = new  FilterExp ression()        
183                };        
184          
185                querySDK SamplePubl isher.Crit eria.AddCo ndition("u niquename" , Conditio nOperator. Equal, _cr mSdkPublis her.Unique Name);        
186                EntityCo llection q uerySDKSam plePublish erResults  = _service Proxy.Retr ieveMultip le(querySD KSamplePub lisher);        
187                Publishe r SDKSampl ePublisher Results =  null;        
188          
189                //If it  already ex ists, use  it        
190                if (quer ySDKSample PublisherR esults.Ent ities.Coun t > 0)        
191                {        
192                    SDKS amplePubli sherResult s = (Publi sher)query SDKSampleP ublisherRe sults.Enti ties[0];                         
193                    _crm SdkPublish erId = (Gu id)SDKSamp lePublishe rResults.P ublisherId ;        
194                    _cus tomization Prefix = S DKSamplePu blisherRes ults.Custo mizationPr efix;        
195          
196                    Cons ole.WriteL ine("Using  existing  publisher:  {0}", SDK SamplePubl isherResul ts.Friendl yName);        
197                }        
198                //If it  doesn't ex ist, creat e it        
199                if (SDKS amplePubli sherResult s == null)        
200                {        
201                    _crm SdkPublish erId = _se rviceProxy .Create(_c rmSdkPubli sher);        
202                    Cons ole.WriteL ine(String .Format("C reated pub lisher: {0 }.", _crmS dkPublishe r.Friendly Name));        
203                    _cus tomization Prefix = _ crmSdkPubl isher.Cust omizationP refix;        
204                    // S et this fl ag to dele te the pub lisher if  this sampl e created  it.        
205                    _cre atedPublis her = true ;        
206                    Cons ole.WriteL ine("Creat ed new pub lisher: {0 }", _crmSd kPublisher .FriendlyN ame);        
207                }        
208          
209                // Creat e a Soluti on        
210                //Define  a solutio n        
211                Solution  solution  = new Solu tion        
212                {        
213                    Uniq ueName = " ImportWebR esourcesSa mple",        
214                    Frie ndlyName =  "Import W eb Resourc es Sample  Solution",        
215                    Publ isherId =  new Entity Reference( Publisher. EntityLogi calName, _ crmSdkPubl isherId),        
216                    Desc ription =  "This solu tion was c reated by  the Import WebResourc es sample  code in th e Microsof t Dynamics  CRM SDK s amples.",        
217                    Vers ion = "1.0 "        
218                };        
219                // Save  save this  variable   to use whe n creating  the Web r esources i n the cont ext of thi s solution .        
220                _ImportW ebResource sSolutionU niqueName  = solution .UniqueNam e;        
221          
222                //Check  whether it  already e xists        
223                QueryExp ression qu eryCheckFo rSampleSol ution = ne w QueryExp ression        
224                {        
225                    Enti tyName = S olution.En tityLogica lName,        
226                    Colu mnSet = ne w ColumnSe t("friendl yname"),        
227                    Crit eria = new  FilterExp ression()        
228                };        
229                queryChe ckForSampl eSolution. Criteria.A ddConditio n("uniquen ame", Cond itionOpera tor.Equal,  solution. UniqueName );        
230          
231                //Create  the solut ion if it  does not a lready exi st.        
232                EntityCo llection q uerySample SolutionRe sults = _s erviceProx y.Retrieve Multiple(q ueryCheckF orSampleSo lution);        
233                Solution  SampleSol utionResul ts = null;        
234                if (quer ySampleSol utionResul ts.Entitie s.Count >  0)        
235                {        
236                    Samp leSolution Results =  (Solution) querySampl eSolutionR esults.Ent ities[0];        
237                    _imp ortWebReso urcesSampl eSolutionI d = (Guid) SampleSolu tionResult s.Solution Id;        
238                    Cons ole.WriteL ine("Using  existing  solution:  {0}", Samp leSolution Results.Fr iendlyName );        
239                }        
240                if (Samp leSolution Results ==  null)        
241                {        
242                    _imp ortWebReso urcesSampl eSolutionI d = _servi ceProxy.Cr eate(solut ion);        
243                    Cons ole.WriteL ine("Creat ed new sol ution: {0} ", solutio n.Friendly Name);        
244                }        
245          
246          
247          
248           }        
249          
250           // / <summary >        
251           // / Deletes  the custom  entity re cord that  was create d for this  sample.        
252           // / <param n ame="promp t">Indicat es whether  to prompt  the user         
253           // / to delet e the enti ty created  in this s ample.</pa ram>        
254           // / </summar y>        
255           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
256           {        
257                bool del eteRecords  = true;        
258          
259                if (prom pt)        
260                {        
261                    Cons ole.WriteL ine("\nDo  you want t hese entit y records  deleted? ( y/n) [y]:  ");        
262                    Stri ng answer  = Console. ReadLine() ;        
263          
264                    dele teRecords  = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ) || answe r == Strin g.Empty);        
265                }        
266          
267                if (dele teRecords)        
268                {        
269                    //de lete Web R esources        
270                    fore ach (Guid  id in _web ResourceId s)        
271                    {        
272                         _servicePr oxy.Delete (WebResour ce.EntityL ogicalName , id);        
273                    }        
274                    Cons ole.WriteL ine("Web R esource re cords have  been dele ted.");        
275                    //De lete Solut ion        
276          
277                    _ser viceProxy. Delete(Sol ution.Enti tyLogicalN ame, _impo rtWebResou rcesSample SolutionId );        
278                    Cons ole.WriteL ine("Solut ion has be en deleted .");        
279          
280                    //        
281                    if ( _createdPu blisher)        
282                    {        
283                         // Delete  the publis her        
284                         _servicePr oxy.Delete (Publisher .EntityLog icalName,  _crmSdkPub lisherId);        
285                         Console.Wr iteLine("P ublisher h as been de leted.");        
286                    }        
287          
288                }        
289           }        
290           #e ndregion H ow To Samp le Code        
291          
292           #r egion Main  method        
293          
294           // / <summary >        
295           // / Standard  Main() me thod used  by most SD K samples.        
296           // / </summar y>        
297           // / <param n ame="args" ></param>        
298           st atic publi c void Mai n(string[]  args)        
299           {        
300                try        
301                {        
302                    // O btain the  target org anization' s Web addr ess and cl ient logon          
303                    // c redentials  from the  user.        
304                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
305                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
306          
307                    Impo rtWebResou rces app =  new Impor tWebResour ces();        
308                    app. Run(config , true);        
309                }        
310                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
311                {        
312                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
313                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
314                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
315                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
316                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
317                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
318                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
319                }        
320                catch (S ystem.Time outExcepti on ex)        
321                {        
322                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
323                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
324                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
325                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
326                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
327                }        
328                catch (S ystem.Exce ption ex)        
329                {        
330                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
331                    Cons ole.WriteL ine(ex.Mes sage);        
332          
333                    // D isplay the  details o f the inne r exceptio n.        
334                    if ( ex.InnerEx ception !=  null)        
335                    {        
336                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
337          
338                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
339                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
340                         if (fe !=  null)        
341                         {        
342                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
343                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
344                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
345                             Consol e.WriteLin e("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
346                             Consol e.WriteLin e("Inner F ault: {0}" ,        
347                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
348                         }        
349                    }        
350                }        
351                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
352                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
353          
354                finally        
355                {        
356                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
357                    Cons ole.ReadLi ne();        
358                }        
359           }        
360           #e ndregion M ain method        
361       }        
362   }        
363   //</snippe tImportWeb Resources>