382. Araxis Merge File Comparison Report

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

382.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\Authentication\AuthenticateWithNoHelp AuthenticateWithNoHelp.cs Tue Dec 20 19:51:46 2016 UTC
2 Wed Feb 1 19:56:32 2017 UTC

382.2 Comparison summary

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

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

382.4 Active regular expressions

No regular expressions were active.

382.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 Authentica teWithNoHe lp>        
17   using Syst em;        
18   using Syst em.Service Model;        
19   using Syst em.Service Model.Desc ription;        
20   using Syst em.Reflect ion;        
21          
22   // These n amespaces  are found  in the Mic rosoft.Xrm .Sdk.dll a ssembly        
23   // located  in the SD K\bin fold er of the  SDK downlo ad.        
24   using Micr osoft.Xrm. Sdk;        
25   using Micr osoft.Xrm. Sdk.Query;        
26   using Micr osoft.Xrm. Sdk.Client ;        
27   using Micr osoft.Xrm. Sdk.Discov ery;        
28   using Micr osoft.Crm. Sdk.Messag es;        
29          
30   namespace  Microsoft. Crm.Sdk.Sa mples        
31   {        
32       /// <s ummary>        
33       /// De monstrate  how to do  basic auth entication  using ISe rviceManag ement and  SecurityTo kenRespons e.        
34       /// </ summary>        
35       class  Authentica teWithNoHe lp        
36       {        
37           #r egion Clas s Level Me mbers        
38           //  To get di scovery se rvice addr ess and or ganization  unique na me,         
39           //  Sign in t o your CRM  org and c lick Setti ngs, Custo mization,  Developer  Resources.        
40           //  On Develo per Resour ce page, f ind the di scovery se rvice addr ess under  Service En dpoints an d organiza tion uniqu e name und er Your Or ganization  Informati on.        
41           pr ivate Stri ng _discov eryService Address =  "https://d ev.crm.dyn amics.com/ XRMService s/2011/Dis covery.svc ";        
42           pr ivate Stri ng _organi zationUniq ueName = " Organizati onUniqueNa me";        
43           //  Provide y our user n ame and pa ssword.        
44           pr ivate Stri ng _userNa me = "user name@mydom ain.com";        
45           pr ivate Stri ng _passwo rd = "pass word";        
46          
47           //  Provide d omain name  for the O n-Premises  org.        
48           pr ivate Stri ng _domain  = "mydoma in";        
49          
50           #e ndregion C lass Level  Members        
51          
52           #r egion How  To Sample  Code        
53           // / <summary >        
54           //        
55           // / </summar y>        
56           pu blic void  Run()        
57           {        
58                //<snipp etAuthenti cateWithNo Help1>        
59                IService Management <IDiscover yService>  serviceMan agement =        
60                             Servic eConfigura tionFactor y.CreateMa nagement<I DiscoveryS ervice>(        
61                             new Ur i(_discove ryServiceA ddress));        
62                Authenti cationProv iderType e ndpointTyp e = servic eManagemen t.Authenti cationType ;        
63          
64                // Set t he credent ials.        
65                Authenti cationCred entials au thCredenti als = GetC redentials (serviceMa nagement,  endpointTy pe);        
66          
67          
68                String o rganizatio nUri = Str ing.Empty;        
69                // Get t he discove ry service  proxy.        
70                using (D iscoverySe rviceProxy  discovery Proxy =        
71                    GetP roxy<IDisc overyServi ce, Discov eryService Proxy>(ser viceManage ment, auth Credential s))        
72                {        
73                    // O btain orga nization i nformation  from the  Discovery  service.         
74                    if ( discoveryP roxy != nu ll)        
75                    {        
76                         // Obtain  informatio n about th e organiza tions that  the syste m user bel ongs to.        
77                         Organizati onDetailCo llection o rgs = Disc overOrgani zations(di scoveryPro xy);        
78                         // Obtains  the Web a ddress (Ur i) of the  target org anization.        
79                         organizati onUri = Fi ndOrganiza tion(_orga nizationUn iqueName,        
80                             orgs.T oArray()). Endpoints[ EndpointTy pe.Organiz ationServi ce];        
81          
82                    }        
83                }        
84                //</snip petAuthent icateWithN oHelp1>        
85          
86          
87                if (!Str ing.IsNull OrWhiteSpa ce(organiz ationUri))        
88                {        
89                    //<s nippetAuth enticateWi thNoHelp3>        
90                    ISer viceManage ment<IOrga nizationSe rvice> org ServiceMan agement =        
91                         ServiceCon figuration Factory.Cr eateManage ment<IOrga nizationSe rvice>(        
92                         new Uri(or ganization Uri));        
93          
94                    // S et the cre dentials.        
95                    Auth entication Credential s credenti als = GetC redentials (orgServic eManagemen t, endpoin tType);        
96          
97                    // G et the org anization  service pr oxy.        
98                    usin g (Organiz ationServi ceProxy or ganization Proxy =        
99                         GetProxy<I Organizati onService,  Organizat ionService Proxy>(org ServiceMan agement, c redentials ))        
100                    {        
101                         // This st atement is  required  to enable  early-boun d type sup port.        
102                         organizati onProxy.En ableProxyT ypes();        
103          
104                         // Now mak e an SDK c all with t he organiz ation serv ice proxy.        
105                         // Display  informati on about t he logged  on user.        
106                         Guid useri d = ((WhoA mIResponse )organizat ionProxy.E xecute(        
107                             new Wh oAmIReques t())).User Id;        
108                         SystemUser  systemUse r = organi zationProx y.Retrieve ("systemus er", useri d,        
109                             new Co lumnSet(ne w string[]  { "firstn ame", "las tname" })) .ToEntity< SystemUser >();        
110                         Console.Wr iteLine("L ogged on u ser is {0}  {1}.",        
111                             system User.First Name, syst emUser.Las tName);        
112                    }        
113                    //</ snippetAut henticateW ithNoHelp3 >        
114                }        
115          
116           }        
117          
118           // <snippetAu thenticate WithNoHelp 2>        
119           // / <summary >        
120           // / Obtain t he Authent icationCre dentials b ased on Au thenticati onProvider Type.        
121           // / </summar y>        
122           // / <param n ame="servi ce">A serv ice manage ment objec t.</param>        
123           // / <param n ame="endpo intType">A n Authenti cationProv iderType o f the CRM  environmen t.</param>        
124           // / <returns >Get fille d credenti als.</retu rns>        
125           pr ivate Auth entication Credential s GetCrede ntials<TSe rvice>(ISe rviceManag ement<TSer vice> serv ice, Authe nticationP roviderTyp e endpoint Type)        
126           {        
127                Authenti cationCred entials au thCredenti als = new  Authentica tionCreden tials();        
128          
129                switch ( endpointTy pe)        
130                {        
131                    case  Authentic ationProvi derType.Ac tiveDirect ory:        
132                         authCreden tials.Clie ntCredenti als.Window s.ClientCr edential =        
133                             new Sy stem.Net.N etworkCred ential(_us erName,        
134                                 _p assword,        
135                                 _d omain);        
136                         break;        
137                    case  Authentic ationProvi derType.Li veId:        
138                         authCreden tials.Clie ntCredenti als.UserNa me.UserNam e = _userN ame;        
139                         authCreden tials.Clie ntCredenti als.UserNa me.Passwor d = _passw ord;        
140                         authCreden tials.Supp ortingCred entials =  new Authen ticationCr edentials( );        
141                         authCreden tials.Supp ortingCred entials.Cl ientCreden tials =        
142                             Micros oft.Crm.Se rvices.Uti lity.Devic eIdManager .LoadOrReg isterDevic e();        
143                         break;        
144                    defa ult: // Fo r Federate d and Onli neFederate d environm ents.                              
145                         authCreden tials.Clie ntCredenti als.UserNa me.UserNam e = _userN ame;        
146                         authCreden tials.Clie ntCredenti als.UserNa me.Passwor d = _passw ord;        
147                         // For Onl ineFederat ed single- sign on, y ou could j ust use cu rrent User PrincipalN ame instea d of passi ng user na me and pas sword.        
148                         // authCre dentials.U serPrincip alName = U serPrincip al.Current .UserPrinc ipalName;   // Window s Kerberos        
149          
150                         // The ser vice is co nfigured f or User Id  authentic ation, but  the user  might prov ide Micros oft        
151                         // account  credentia ls. If so,  the suppo rting cred entials mu st contain  the devic e credenti als.        
152                         if (endpoi ntType ==  Authentica tionProvid erType.Onl ineFederat ion)        
153                         {        
154                             Identi tyProvider  provider  = service. GetIdentit yProvider( authCreden tials.Clie ntCredenti als.UserNa me.UserNam e);        
155                             if (pr ovider !=  null && pr ovider.Ide ntityProvi derType ==  IdentityP roviderTyp e.LiveId)        
156                             {        
157                                 au thCredenti als.Suppor tingCreden tials = ne w Authenti cationCred entials();        
158                                 au thCredenti als.Suppor tingCreden tials.Clie ntCredenti als =        
159                                      Microsof t.Crm.Serv ices.Utili ty.DeviceI dManager.L oadOrRegis terDevice( );        
160                             }        
161                         }        
162          
163                         break;        
164                }        
165          
166                return a uthCredent ials;        
167           }        
168           // </snippetA uthenticat eWithNoHel p2>        
169          
170           // / <summary >        
171           // / Discover s the orga nizations  that the c alling use r belongs  to.        
172           // / </summar y>        
173           // / <param n ame="servi ce">A Disc overy serv ice proxy  instance.< /param>        
174           // / <returns >Array con taining de tailed inf ormation o n each org anization  that         
175           // / the user  belongs t o.</return s>        
176           pu blic Organ izationDet ailCollect ion Discov erOrganiza tions(        
177                IDiscove ryService  service)        
178           {        
179                if (serv ice == nul l) throw n ew Argumen tNullExcep tion("serv ice");        
180                Retrieve Organizati onsRequest  orgReques t = new Re trieveOrga nizationsR equest();        
181                Retrieve Organizati onsRespons e orgRespo nse =        
182                    (Ret rieveOrgan izationsRe sponse)ser vice.Execu te(orgRequ est);        
183          
184                return o rgResponse .Details;        
185           }        
186          
187           // / <summary >        
188           // / Finds a  specific o rganizatio n detail i n the arra y of organ ization de tails        
189           // / returned  from the  Discovery  service.        
190           // / </summar y>        
191           // / <param n ame="orgUn iqueName"> The unique  name of t he organiz ation to f ind.</para m>        
192           // / <param n ame="orgDe tails">Arr ay of orga nization d etail obje ct returne d from the  discovery  service.< /param>        
193           // / <returns >Organizat ion detail s or null  if the org anization  was not fo und.</retu rns>        
194           // / <seealso  cref="Dis coveryOrga nizations" />        
195           pu blic Organ izationDet ail FindOr ganization (string or gUniqueNam e,        
196                Organiza tionDetail [] orgDeta ils)        
197           {        
198                if (Stri ng.IsNullO rWhiteSpac e(orgUniqu eName))        
199                    thro w new Argu mentNullEx ception("o rgUniqueNa me");        
200                if (orgD etails ==  null)        
201                    thro w new Argu mentNullEx ception("o rgDetails" );        
202                Organiza tionDetail  orgDetail  = null;        
203          
204                foreach  (Organizat ionDetail  detail in  orgDetails )        
205                {        
206                    if ( String.Com pare(detai l.UniqueNa me, orgUni queName,        
207                         StringComp arison.Inv ariantCult ureIgnoreC ase) == 0)        
208                    {        
209                         orgDetail  = detail;        
210                         break;        
211                    }        
212                }        
213                return o rgDetail;        
214           }        
215          
216           // / <summary >        
217           // / Generic  method to  obtain dis covery/org anization  service pr oxy instan ce.        
218           // / </summar y>        
219           // / <typepar am name="T Service">        
220           // / Set IDis coveryServ ice or IOr ganization Service ty pe to requ est respec tive servi ce proxy i nstance.        
221           // / </typepa ram>        
222           // / <typepar am name="T Proxy">        
223           // / Set the  return typ e to eithe r Discover yServicePr oxy or Org anizationS erviceProx y type bas ed on TSer vice type.        
224           // / </typepa ram>        
225           // / <param n ame="servi ceManageme nt">An ins tance of I ServiceMan agement</p aram>        
226           // / <param n ame="authC redentials ">The user 's Microso ft Dynamic s CRM logo n credenti als.</para m>        
227           // / <returns ></returns >        
228           // / <snippet Authentica teWithNoHe lp4>        
229           pr ivate TPro xy GetProx y<TService , TProxy>(        
230                IService Management <TService>  serviceMa nagement,        
231                Authenti cationCred entials au thCredenti als)        
232                where TS ervice : c lass        
233                where TP roxy : Ser viceProxy< TService>        
234           {        
235                Type cla ssType = t ypeof(TPro xy);        
236          
237                if (serv iceManagem ent.Authen ticationTy pe !=        
238                    Auth entication ProviderTy pe.ActiveD irectory)        
239                {        
240                    Auth entication Credential s tokenCre dentials =        
241                         serviceMan agement.Au thenticate (authCrede ntials);        
242                    // O btain disc overy/orga nization s ervice pro xy for Fed erated, Li veId and O nlineFeder ated envir onments.         
243                    // I nstantiate  a new cla ss of type  using the  2 paramet er constru ctor of ty pe IServic eManagemen t and Secu rityTokenR esponse.        
244                    retu rn (TProxy )classType        
245                         .GetConstr uctor(new  Type[] { t ypeof(ISer viceManage ment<TServ ice>), typ eof(Securi tyTokenRes ponse) })        
246                         .Invoke(ne w object[]  { service Management , tokenCre dentials.S ecurityTok enResponse  });        
247                }        
248          
249                // Obtai n discover y/organiza tion servi ce proxy f or ActiveD irectory e nvironment .        
250                // Insta ntiate a n ew class o f type usi ng the 2 p arameter c onstructor  of type I ServiceMan agement an d ClientCr edentials.        
251                return ( TProxy)cla ssType        
252                    .Get Constructo r(new Type [] { typeo f(IService Management <TService> ), typeof( ClientCred entials) } )        
253                    .Inv oke(new ob ject[] { s erviceMana gement, au thCredenti als.Client Credential s });        
254           }        
255           // / </snippe tAuthentic ateWithNoH elp4>        
256          
257           #e ndregion H ow To Samp le Code        
258          
259           #r egion Main  method        
260          
261           // / <summary >        
262           // / Standard  Main() me thod used  by most SD K samples.        
263           // / </summar y>        
264           // / <param n ame="args" ></param>        
265           st atic publi c void Mai n(string[]  args)        
266           {        
267                try        
268                {        
269                    Auth enticateWi thNoHelp a pp = new A uthenticat eWithNoHel p();        
270                    app. Run();        
271                }        
272                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
273                {        
274                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
275                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
276                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
277                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
278                    Cons ole.WriteL ine("Trace : {0}", ex .Detail.Tr aceText);        
279                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
280                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
281                }        
282                catch (S ystem.Time outExcepti on ex)        
283                {        
284                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
285                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
286                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
287                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
288                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
289                }        
290                catch (S ystem.Exce ption ex)        
291                {        
292                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
293                    Cons ole.WriteL ine(ex.Mes sage);        
294          
295                    // D isplay the  details o f the inne r exceptio n.        
296                    if ( ex.InnerEx ception !=  null)        
297                    {        
298                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
299          
300                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
301                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
302                         if (fe !=  null)        
303                         {        
304                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
305                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
306                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
307                             Consol e.WriteLin e("Trace:  {0}", fe.D etail.Trac eText);        
308                             Consol e.WriteLin e("Inner F ault: {0}" ,        
309                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
310                         }        
311                    }        
312                }        
313                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
314                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
315          
316                finally        
317                {        
318                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
319                    Cons ole.ReadLi ne();        
320                }        
321           }        
322           #e ndregion M ain method        
323       }        
324   }        
325   //</snippe tAuthentic ateWithNoH elp>