355. Araxis Merge File Comparison Report

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

355.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\DataManagement\DuplicateDetection InvokeDuplicateDetectionForCreateAndUpdate.cs Tue Dec 20 19:51:43 2016 UTC
2 Wed Feb 1 19:56:31 2017 UTC

355.2 Comparison summary

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

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

355.4 Active regular expressions

No regular expressions were active.

355.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 InvokeDupl icateDetec tionForCre ateAndUpda te>        
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          
28   using Micr osoft.Crm. Sdk.Messag es;        
29          
30   namespace  Microsoft. Crm.Sdk.Sa mples        
31   {        
32       /// <s ummary>        
33       /// De monstrates  how to do  basic ent ity operat ions like  create, an d        
34       /// up date, usin g Duplicat e Detectio n attribut e.</summar y>        
35       /// <r emarks>        
36       /// At  run-time,  you will  be given t he option  to delete  all the        
37       /// da tabase rec ords creat ed by this  program.< /remarks>        
38       public  class Inv okeDuplica teDetectio nForCreate AndUpdate        
39       {        
40           #r egion Clas s Level Me mbers        
41          
42           pr ivate Guid  _accountI d;        
43           pr ivate Guid  _ruleId;        
44           pr ivate Guid  _dupAccou ntId;        
45           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
46           pr ivate IOrg anizationS ervice _se rvice;        
47          
48           #e ndregion C lass Level  Members        
49          
50           #r egion How  To Sample  Code        
51           // / <summary >        
52           // / This met hod first  connects t o the Orga nization s ervice. Af terwards,        
53           // / basic cr eate, retr ieve, upda te, and de lete entit y operatio ns are per formed.        
54           // / </summar y>        
55           // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param>        
56           // / <param n ame="promp tforDelete ">When Tru e, the use r will be  prompted t o delete a ll        
57           // / created  entities.< /param>        
58           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete)        
59           {        
60                try        
61                {        
62                    //<s nippetInvo keDuplicat eDetection ForCreateA ndUpdate1>        
63                    // C onnect to  the Organi zation ser vice.         
64                    // T he using s tatement a ssures tha t the serv ice proxy  will be pr operly dis posed.        
65                    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 ))        
66                    {        
67                         // This st atement is  required  to enable  early-boun d type sup port.        
68                         _servicePr oxy.Enable ProxyTypes ();        
69          
70                         _service =  (IOrganiz ationServi ce)_servic eProxy;        
71          
72                         CreateRequ iredRecord s();        
73          
74                         // Create  and accoun t record w ith the na med Prosew are, Inc.  and alread y existing  Account N umber.        
75                         Account ac count = ne w Account         
76                         {        
77                             Name =  "Prosewar e, Inc.",        
78                             Accoun tNumber =  "ACC005"        
79                         };        
80          
81                         // Create  operation  by suppres sing dupli cate detec tion        
82                         CreateRequ est reqCre ate = new  CreateRequ est();        
83                         reqCreate. Target = a ccount;        
84                         reqCreate. Parameters .Add("Supp ressDuplic ateDetecti on", true) ; // Chang e to false  to activa te the dup licate det ection.        
85                         CreateResp onse creat eResponse  = (CreateR esponse)_s ervice.Exe cute(reqCr eate);        
86                         _dupAccoun tId = crea teResponse .id;        
87                         Console.Wr ite("Accou nt: {0} {1 } created  with Suppr essDuplica teDetectio n to true,  ",         
88                             accoun t.Name, ac count.Acco untNumber) ;        
89                                
90                         // Retriev e the acco unt contai ning with  its few at tributes.        
91                         ColumnSet  cols = new  ColumnSet (        
92                             new St ring[] { " name", "ac countnumbe r"});        
93          
94                         Account re trievedAcc ount = (Ac count)_ser vice.Retri eve("accou nt", _dupA ccountId,  cols);        
95                         Console.Wr ite("retri eved, ");        
96          
97                         // Update  the existi ng account  with new  account nu mber.        
98                         retrievedA ccount.Acc ountNumber  = "ACC006 ";                             
99          
100                         // Update  operation  – update r ecord, if  a duplicat e is not f ound.        
101                         UpdateRequ est reqUpd ate = new  UpdateRequ est();        
102                         reqUpdate. Target = r etrievedAc count;        
103                         reqUpdate[ "SuppressD uplicateDe tection"]  = false; / / Duplicat e detectio n is activ ated.        
104          
105                         // Update  the accoun t record.        
106                         UpdateResp onse updat eResponse  = (UpdateR esponse)_s ervice.Exe cute(reqUp date);        
107                         Console.Wr iteLine("a nd updated .");        
108          
109                         DeleteRequ iredRecord s(promptfo rDelete);        
110                    }        
111                    //</ snippetInv okeDuplica teDetectio nForCreate AndUpdate1 >        
112                }        
113                // Catch  any servi ce fault e xceptions  that Micro soft Dynam ics CRM th rows.        
114                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>)        
115                {        
116                    // Y ou can han dle an exc eption her e or pass  it back to  the calli ng method.        
117                    thro w;        
118                }        
119           }        
120          
121           // / <summary >        
122           // / Creates  any entity  records t hat this s ample requ ires.        
123           // / </summar y>        
124           pu blic void  CreateRequ iredRecord s()        
125           {        
126                // Creat e an accou nt record  named Four th Coffee.        
127                Account  account =  new Accoun        
128                {         
129                    Name  = "Fourth  Coffee",        
130                    Acco untNumber  = "ACC005"        
131                };                     
132                _account Id = _serv ice.Create (account);        
133                Console. Write("Acc ount {0} { 1} created , ", accou nt.Name, a ccount.Acc ountNumber );        
134          
135                // Creat e a duplic ate detect ion rule        
136                Duplicat eRule acco untDuplica teRule = n ew Duplica teRule        
137                {        
138                    Name  = "Duplic ateRule: A ccounts wi th the sam e Account  Number",        
139                    Base EntityName  = "accoun t",        
140                    Matc hingEntity Name = "ac count"                                          
141                };        
142                _ruleId  = _service .Create(ac countDupli cateRule);                      
143          
144                // Creat e a duplic ate detect ion rule c ondition        
145                Duplicat eRuleCondi tion accou ntDupCondi tion = new  Duplicate RuleCondit ion        
146                {        
147                    Base AttributeN ame = "acc ountnumber ",        
148                    Matc hingAttrib uteName =  "accountnu mber",        
149                    Oper atorCode =  new Optio nSetValue( 0), // Exa ct Match.        
150                    Rega rdingObjec tId = new  EntityRefe rence(Dupl icateRule. EntityLogi calName, _ ruleId)        
151                };        
152                Guid con ditionId =  _service. Create(acc ountDupCon dition);        
153          
154                Console. Write("'{0 }' created , ", accou ntDuplicat eRule.Name );        
155          
156                // Execu te the pub lish reque st.        
157                PublishD uplicateRu leResponse  response         
158                    (Pub lishDuplic ateRuleRes ponse)_ser vice.Execu te(new Pub lishDuplic ateRuleReq uest() { D uplicateRu leId = _ru leId });        
159          
160                // When  the publis hDuplicate Rule reque st returns , the stat e of the r ule will s till be "P ublishing"  (StatusCo de = 1).        
161                // we ne ed to wait  for the p ublishing  operation  to complet e, so we k eep pollin g the stat e of the        
162                // rule  until it b ecomes "Pu blished" ( StatusCode  = 2).        
163                int i =  0;        
164                Duplicat eRule retr ievedRule         
165                    (Dup licateRule )_service. Retrieve(D uplicateRu le.EntityL ogicalName , _ruleId,  new Colum nSet(new S tring[] {  "statuscod e" }));        
166                while (r etrievedRu le.StatusC ode.Value  == 1 && i  < 20)        
167                {        
168                    i++;        
169                    Syst em.Threadi ng.Thread. Sleep(1000 );        
170                    retr ievedRule         
171                         (Duplicate Rule)_serv ice.Retrie ve(Duplica teRule.Ent ityLogical Name, _rul eId, new C olumnSet(n ew String[ ] { "statu scode" })) ;        
172                }        
173          
174                Console. Write("pub lished.\n" );        
175           }        
176          
177           // / <summary >        
178           // / Deletes  any entity  records t hat were c reated for  this samp le.        
179           // / <param n ame="promp t">Indicat es whether  to prompt  the user         
180           // / to delet e the reco rds create d in this  sample.</p aram>        
181           // / </summar y>        
182           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
183           {        
184                bool del eteRecords  = true;        
185          
186                if (prom pt)        
187                {        
188                    Cons ole.WriteL ine("\nDo  you want t hese entit y records  deleted? ( y/n) [y]:  ");        
189                    Stri ng answer  = Console. ReadLine() ;        
190          
191                    dele teRecords  = (answer. StartsWith ("y") ||        
192                                      answer.S tartsWith( "Y") ||        
193                                      answer = = String.E mpty);        
194                }        
195          
196                if (dele teRecords)        
197                {        
198                    _ser vice.Delet e(Account. EntityLogi calName, _ accountId) ;        
199                    Unpu blishDupli cateRuleRe quest unpu blishReque st = new U npublishDu plicateRul eRequest        
200                    {        
201                         DuplicateR uleId = _r uleId        
202                    };        
203                    _ser vice.Execu te(unpubli shRequest) ;        
204                    _ser vice.Delet e(Duplicat eRule.Enti tyLogicalN ame, _rule Id);        
205                    _ser vice.Delet e(Account. EntityLogi calName, _ dupAccount Id);        
206                    Cons ole.WriteL ine("Entit y records  have been  deleted.") ;        
207                }        
208           }        
209          
210           #e ndregion H ow To Samp le Code        
211          
212           #r egion Main  method        
213          
214           // / <summary >        
215           // / Standard  Main() me thod used  by most SD K samples.        
216           // / </summar y>        
217           // / <param n ame="args" ></param>        
218           st atic publi c void Mai n(string[]  args)        
219           {        
220                try        
221                {        
222                    // O btain the  target org anization' s Web addr ess and cl ient logon          
223                    // c redentials  from the  user.        
224                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
225                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
226          
227                    Invo keDuplicat eDetection ForCreateA ndUpdate a pp = new I nvokeDupli cateDetect ionForCrea teAndUpdat e();        
228                    app. Run(config , true);        
229                }        
230                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
231                {        
232                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
233                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
234                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
235                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
236                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
237                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
238                }        
239                catch (S ystem.Time outExcepti on ex)        
240                {        
241                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
242                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
243                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
244                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
245                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
246                }        
247                catch (S ystem.Exce ption ex)        
248                {        
249                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
250                    Cons ole.WriteL ine(ex.Mes sage);        
251          
252                    // D isplay the  details o f the inne r exceptio n.        
253                    if ( ex.InnerEx ception !=  null)        
254                    {        
255                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
256          
257                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
258                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
259                         if (fe !=  null)        
260                         {        
261                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
262                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
263                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
264                             Consol e.WriteLin e("Trace:  {0}", fe.D etail.Trac eText);        
265                             Consol e.WriteLin e("Inner F ault: {0}" ,        
266                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
267                         }        
268                    }        
269                }        
270                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
271                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
272                finally        
273                {        
274                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
275                    Cons ole.ReadLi ne();        
276                }        
277           }        
278           #e ndregion M ain method        
279       }        
280   }        
281   //</snippe tInvokeDup licateDete ctionForCr eateAndUpd ate>        
282