Produced by Araxis Merge on 2/1/2017 2:56:28 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.
| # | 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\BusinessDataModel\UsersAndRoles | RetrieveAUser.cs | Tue Dec 20 19:51:44 2016 UTC |
| 2 | Wed Feb 1 19:56:28 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 233 |
| 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 |
No regular expressions were active.
| 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 RetrieveAU ser> | |||||
| 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.Crm. Sdk.Messag es; | |||||
| 27 | ||||||
| 28 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 29 | { | |||||
| 30 | /// <s ummary> | |||||
| 31 | /// De monstrates how to cr eate a bas ic query t o find a u ser. | |||||
| 32 | /// </ summary> | |||||
| 33 | /// <r emarks> | |||||
| 34 | /// At run-time, you will be given t he option to revert the role | |||||
| 35 | /// as sociation created by this prog ram.</rema rks> | |||||
| 36 | public class Ret rieveAUser | |||||
| 37 | { | |||||
| 38 | #r egion Clas s Level Me mbers | |||||
| 39 | ||||||
| 40 | // Define th e IDs need ed for thi s sample. | |||||
| 41 | pr ivate Stri ng _domain ; | |||||
| 42 | pr ivate Stri ng _userNa me; | |||||
| 43 | pr ivate Stri ng _firstN ame; | |||||
| 44 | pr ivate Stri ng _lastNa me; | |||||
| 45 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 46 | ||||||
| 47 | #e ndregion C lass Level Members | |||||
| 48 | ||||||
| 49 | #r egion How To Sample Code | |||||
| 50 | // / <summary > | |||||
| 51 | // / This met hod first connects t o the Orga nization s ervice. Af terwards, it | |||||
| 52 | // / creates/ retrieves a system u ser, | |||||
| 53 | // / retrieve s user det ails, and | |||||
| 54 | // / creates a query to find the system use r using do main\usern ame or fir st and las t name det ails. | |||||
| 55 | // / Note: Cr eating a u ser is onl y supporte d | |||||
| 56 | // / in an on -premises/ active dir ectory env ironment. | |||||
| 57 | // / </summar y> | |||||
| 58 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 59 | // / <param n ame="promp tforDelete ">When Tru e, the use r is promp ted to del ete all | |||||
| 60 | // / created entities.< /param> | |||||
| 61 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 62 | { | |||||
| 63 | try | |||||
| 64 | { | |||||
| 65 | //<s nippetRetr ieveAUser1 > | |||||
| 66 | // C onnect to the Organi zation ser vice. | |||||
| 67 | // T he using s tatement a ssures tha t the serv ice proxy is properl y disposed . | |||||
| 68 | 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 )) | |||||
| 69 | { | |||||
| 70 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 71 | ||||||
| 72 | CreateRequ iredRecord s(); | |||||
| 73 | ||||||
| 74 | // Find a user using domain\us ername or first and last name details. | |||||
| 75 | QueryExpre ssion user Query = ne w QueryExp ression | |||||
| 76 | { | |||||
| 77 | Entity Name = "sy stemuser", | |||||
| 78 | // Ret rieve all columns. | |||||
| 79 | Column Set = new ColumnSet( new String [] { "syst emuserid", "domainna me", "full name" }), | |||||
| 80 | ||||||
| 81 | Criter ia = | |||||
| 82 | { | |||||
| 83 | Fi lterOperat or = Logic alOperator .Or, | |||||
| 84 | Fi lters = | |||||
| 85 | { | |||||
| 86 | new Filt erExpressi on | |||||
| 87 | { | |||||
| 88 | Filt erOperator = Logical Operator.A nd, | |||||
| 89 | Cond itions = | |||||
| 90 | { | |||||
| 91 | new Condit ionExpress ion("domai nname", Co nditionOpe rator.Equa l, _domain + _userNa me) | |||||
| 92 | } | |||||
| 93 | }, | |||||
| 94 | new Filt erExpressi on | |||||
| 95 | { | |||||
| 96 | Filt erOperator = Logical Operator.A nd, | |||||
| 97 | Cond itions = | |||||
| 98 | { | |||||
| 99 | new Condit ionExpress ion("first name", Con ditionOper ator.Equal , _firstNa me), | |||||
| 100 | new Condit ionExpress ion("lastn ame", Cond itionOpera tor.Equal, _lastName ) | |||||
| 101 | } | |||||
| 102 | } | |||||
| 103 | } | |||||
| 104 | ||||||
| 105 | } | |||||
| 106 | }; | |||||
| 107 | ||||||
| 108 | ||||||
| 109 | EntityColl ection ent ities = _s erviceProx y.Retrieve Multiple(u serQuery); | |||||
| 110 | ||||||
| 111 | if (entiti es.Entitie s.Count > 0) | |||||
| 112 | { | |||||
| 113 | System User user = entities [0].ToEnti ty<SystemU ser>(); | |||||
| 114 | ||||||
| 115 | // Wri te out som e key user propertie s. | |||||
| 116 | Consol e.WriteLin e("Id: {0} ", user.Id ); | |||||
| 117 | Consol e.WriteLin e("DomainN ame: {0}", user.Doma inName); | |||||
| 118 | Consol e.WriteLin e("FullNam e: {0}", u ser.FullNa me); | |||||
| 119 | } | |||||
| 120 | } | |||||
| 121 | //</ snippetRet rieveAUser 1> | |||||
| 122 | } | |||||
| 123 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 124 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 125 | { | |||||
| 126 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 127 | thro w; | |||||
| 128 | } | |||||
| 129 | } | |||||
| 130 | ||||||
| 131 | // / <summary > | |||||
| 132 | // / Creates any entity records t hat this s ample requ ires. | |||||
| 133 | // / </summar y> | |||||
| 134 | pu blic void CreateRequ iredRecord s() | |||||
| 135 | { | |||||
| 136 | // For t his sample , all requ ired entit ies are cr eated in t he Run() m ethod. | |||||
| 137 | // Creat e/retrieve a user to get assoc iated user details. | |||||
| 138 | SystemUs er user = _servicePr oxy.Retrie ve(SystemU ser.Entity LogicalNam e, | |||||
| 139 | Syst emUserProv ider.Retri eveAUserWi thoutAnyRo leAssigned (_serviceP roxy), | |||||
| 140 | new ColumnSet( new String [] { "doma inname", " firstname" , "lastnam e" })).ToE ntity<Syst emUser>(); | |||||
| 141 | ||||||
| 142 | ||||||
| 143 | // Extra ct the dom ain, usern ame, first name and l astname fr om the use r record. | |||||
| 144 | String[] userPath = user.Dom ainName.Sp lit(new ch ar[] { '\\ ' }); | |||||
| 145 | if (user Path.Lengt h > 1) | |||||
| 146 | { | |||||
| 147 | _dom ain = user Path[0] + "\\"; | |||||
| 148 | _use rName = us erPath[1]; | |||||
| 149 | } | |||||
| 150 | else | |||||
| 151 | { | |||||
| 152 | _dom ain = Stri ng.Empty; | |||||
| 153 | _use rName = us erPath[0]; | |||||
| 154 | } | |||||
| 155 | ||||||
| 156 | _firstNa me = user. FirstName; | |||||
| 157 | _lastNam e = user.L astName; | |||||
| 158 | } | |||||
| 159 | ||||||
| 160 | #e ndregion H ow To Samp le Code | |||||
| 161 | ||||||
| 162 | #r egion Main method | |||||
| 163 | ||||||
| 164 | // / <summary > | |||||
| 165 | // / Standard Main() me thod used by most SD K samples. | |||||
| 166 | // / </summar y> | |||||
| 167 | // / <param n ame="args" ></param> | |||||
| 168 | st atic publi c void Mai n(string[] args) | |||||
| 169 | { | |||||
| 170 | try | |||||
| 171 | { | |||||
| 172 | // O btain the target org anization' s web addr ess and cl ient logon | |||||
| 173 | // c redentials from the user. | |||||
| 174 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 175 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 176 | ||||||
| 177 | Retr ieveAUser app = new RetrieveAU ser(); | |||||
| 178 | app. Run(config , true); | |||||
| 179 | } | |||||
| 180 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 181 | { | |||||
| 182 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 183 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 184 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 185 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 186 | Cons ole.WriteL ine("Trace : {0}", ex .Detail.Tr aceText); | |||||
| 187 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 188 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 189 | } | |||||
| 190 | catch (S ystem.Time outExcepti on ex) | |||||
| 191 | { | |||||
| 192 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 193 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 194 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 195 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 196 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 197 | } | |||||
| 198 | catch (S ystem.Exce ption ex) | |||||
| 199 | { | |||||
| 200 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 201 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 202 | ||||||
| 203 | // D isplay the details o f the inne r exceptio n. | |||||
| 204 | if ( ex.InnerEx ception != null) | |||||
| 205 | { | |||||
| 206 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 207 | ||||||
| 208 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 209 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 210 | if (fe != null) | |||||
| 211 | { | |||||
| 212 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 213 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 214 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 215 | Consol e.WriteLin e("Trace: {0}", fe.D etail.Trac eText); | |||||
| 216 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 217 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 218 | } | |||||
| 219 | } | |||||
| 220 | } | |||||
| 221 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 222 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 223 | finally | |||||
| 224 | { | |||||
| 225 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 226 | Cons ole.ReadLi ne(); | |||||
| 227 | } | |||||
| 228 | } | |||||
| 229 | #e ndregion M ain method | |||||
| 230 | } | |||||
| 231 | } | |||||
| 232 | //</snippe tRetrieveA User> | |||||
| 233 |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.