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 | DoesUserBelongToRole.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 | 260 |
| 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 DoesUserBe longToRole > | |||||
| 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 ch eck a role associati on with th e system 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 Doe sUserBelon gToRole | |||||
| 37 | { | |||||
| 38 | #r egion Clas s Level Me mbers | |||||
| 39 | ||||||
| 40 | // Define th e IDs need ed for thi s sample. | |||||
| 41 | pr ivate Guid _userId; | |||||
| 42 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 43 | pr ivate Stri ng _givenR ole = "sal esperson"; | |||||
| 44 | #e ndregion C lass Level Members | |||||
| 45 | ||||||
| 46 | #r egion How To Sample Code | |||||
| 47 | // / <summary > | |||||
| 48 | // / This met hod first connects t o the Orga nization s ervice. Af terwards, | |||||
| 49 | // / creates/ retrieve a system us er, | |||||
| 50 | // / retrieve a system user to ch eck if it is associa te with th e salesper son role. | |||||
| 51 | // / Note: Cr eating a u ser is onl y supporte d | |||||
| 52 | // / in on-pr emises/act ive direct ory enviro nment. | |||||
| 53 | // / </summar y> | |||||
| 54 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 55 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 56 | // / created entities.< /param> | |||||
| 57 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 58 | { | |||||
| 59 | try | |||||
| 60 | { | |||||
| 61 | //<s nippetDoes UserBelong ToRole1> | |||||
| 62 | // C onnect to the Organi zation ser vice. | |||||
| 63 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 64 | 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 )) | |||||
| 65 | { | |||||
| 66 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 67 | ||||||
| 68 | CreateRequ iredRecord s(); | |||||
| 69 | ||||||
| 70 | ||||||
| 71 | // Retriev e a user. | |||||
| 72 | SystemUser user = _s erviceProx y.Retrieve (SystemUse r.EntityLo gicalName, | |||||
| 73 | _userI d, new Col umnSet(new String [] {"systemu serid", "f irstname", "lastname "})).ToEnt ity<System User>(); | |||||
| 74 | ||||||
| 75 | if (user ! = null) | |||||
| 76 | { | |||||
| 77 | Consol e.WriteLin e("{1} {0} user acco unt is ret rieved.", user.LastN ame, user. FirstName) ; | |||||
| 78 | // Fin d a role. | |||||
| 79 | QueryE xpression query = ne w QueryExp ression | |||||
| 80 | { | |||||
| 81 | En tityName = Role.Enti tyLogicalN ame, | |||||
| 82 | Co lumnSet = new Column Set("rolei d"), | |||||
| 83 | Cr iteria = n ew FilterE xpression | |||||
| 84 | { | |||||
| 85 | Conditio ns = | |||||
| 86 | { | |||||
| 87 | ||||||
| 88 | new ConditionE xpression | |||||
| 89 | { | |||||
| 90 | AttributeN ame = "nam e", | |||||
| 91 | Operator = Condition Operator.E qual, | |||||
| 92 | Values = { _givenRole } | |||||
| 93 | } | |||||
| 94 | } | |||||
| 95 | } | |||||
| 96 | }; | |||||
| 97 | ||||||
| 98 | // Get the role. | |||||
| 99 | Entity Collection givenRole s = _servi ceProxy.Re trieveMult iple(query ); | |||||
| 100 | ||||||
| 101 | if (gi venRoles.E ntities.Co unt > 0) | |||||
| 102 | { | |||||
| 103 | Ro le givenRo le = given Roles.Enti ties[0].To Entity<Rol e>(); | |||||
| 104 | ||||||
| 105 | Co nsole.Writ eLine("Rol e {0} is r etrieved." , _givenRo le); | |||||
| 106 | ||||||
| 107 | Co nsole.Writ eLine("Che cking asso ciation be tween user and role. "); | |||||
| 108 | // Establish a SystemU ser link f or a query . | |||||
| 109 | Li nkEntity s ystemUserL ink = new LinkEntity () | |||||
| 110 | { | |||||
| 111 | LinkFrom EntityName = SystemU serRoles.E ntityLogic alName, | |||||
| 112 | LinkFrom AttributeN ame = "sys temuserid" , | |||||
| 113 | LinkToEn tityName = SystemUse r.EntityLo gicalName, | |||||
| 114 | LinkToAt tributeNam e = "syste muserid", | |||||
| 115 | LinkCrit eria = | |||||
| 116 | { | |||||
| 117 | Cond itions = | |||||
| 118 | { | |||||
| 119 | new Condit ionExpress ion( | |||||
| 120 | "syste muserid", ConditionO perator.Eq ual, user. Id) | |||||
| 121 | } | |||||
| 122 | } | |||||
| 123 | }; | |||||
| 124 | ||||||
| 125 | // Build the query. | |||||
| 126 | Qu eryExpress ion linkQu ery = new QueryExpre ssion() | |||||
| 127 | { | |||||
| 128 | EntityNa me = Role. EntityLogi calName, | |||||
| 129 | ColumnSe t = new Co lumnSet("r oleid"), | |||||
| 130 | LinkEnti ties = | |||||
| 131 | { | |||||
| 132 | new LinkEntity () | |||||
| 133 | { | |||||
| 134 | LinkFromEn tityName = Role.Enti tyLogicalN ame, | |||||
| 135 | LinkFromAt tributeNam e = "rolei d", | |||||
| 136 | LinkToEnti tyName = S ystemUserR oles.Entit yLogicalNa me, | |||||
| 137 | LinkToAttr ibuteName = "roleid" , | |||||
| 138 | LinkEntiti es = {syst emUserLink } | |||||
| 139 | } | |||||
| 140 | }, | |||||
| 141 | Criteria = | |||||
| 142 | { | |||||
| 143 | Cond itions = | |||||
| 144 | { | |||||
| 145 | new Condit ionExpress ion("rolei d", Condit ionOperato r.Equal, g ivenRole.I d) | |||||
| 146 | } | |||||
| 147 | } | |||||
| 148 | }; | |||||
| 149 | ||||||
| 150 | // Retrieve matching r oles. | |||||
| 151 | En tityCollec tion match Entities = _serviceP roxy.Retri eveMultipl e(linkQuer y); | |||||
| 152 | ||||||
| 153 | // if an ent ity is ret urned then the user is a membe r | |||||
| 154 | // of the ro le | |||||
| 155 | Bo olean isUs erInRole = (matchEnt ities.Enti ties.Count > 0); | |||||
| 156 | ||||||
| 157 | if (isUserInR ole) | |||||
| 158 | Console. WriteLine( "User do n ot belong to the rol e."); | |||||
| 159 | el se | |||||
| 160 | Console. WriteLine( "User belo ng to this role."); | |||||
| 161 | ||||||
| 162 | } | |||||
| 163 | } | |||||
| 164 | } | |||||
| 165 | //</ snippetDoe sUserBelon gToRole1> | |||||
| 166 | } | |||||
| 167 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 168 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 169 | { | |||||
| 170 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 171 | thro w; | |||||
| 172 | } | |||||
| 173 | } | |||||
| 174 | ||||||
| 175 | // / <summary > | |||||
| 176 | // / Creates any entity records t hat this s ample requ ires. | |||||
| 177 | // / </summar y> | |||||
| 178 | pu blic void CreateRequ iredRecord s() | |||||
| 179 | { | |||||
| 180 | // For t his sample , all requ ired entit ies are cr eated in t he Run() m ethod. | |||||
| 181 | // Creat e/Retrieve a user. | |||||
| 182 | _userId = SystemUs erProvider .RetrieveA UserWithou tAnyRoleAs signed(_se rviceProxy ); | |||||
| 183 | ||||||
| 184 | if (_use rId != Gui d.Empty) | |||||
| 185 | Cons ole.WriteL ine("{0} u ser retrie ved.", _us erId); | |||||
| 186 | } | |||||
| 187 | ||||||
| 188 | #e ndregion H ow To Samp le Code | |||||
| 189 | ||||||
| 190 | #r egion Main method | |||||
| 191 | ||||||
| 192 | // / <summary > | |||||
| 193 | // / Standard Main() me thod used by most SD K samples. | |||||
| 194 | // / </summar y> | |||||
| 195 | // / <param n ame="args" ></param> | |||||
| 196 | st atic publi c void Mai n(string[] args) | |||||
| 197 | { | |||||
| 198 | try | |||||
| 199 | { | |||||
| 200 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 201 | // c redentials from the user. | |||||
| 202 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 203 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 204 | ||||||
| 205 | Does UserBelong ToRole app = new Doe sUserBelon gToRole(); | |||||
| 206 | app. Run(config , true); | |||||
| 207 | } | |||||
| 208 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 209 | { | |||||
| 210 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 211 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 212 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 213 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 214 | Cons ole.WriteL ine("Trace : {0}", ex .Detail.Tr aceText); | |||||
| 215 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 216 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 217 | } | |||||
| 218 | catch (S ystem.Time outExcepti on ex) | |||||
| 219 | { | |||||
| 220 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 221 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 222 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 223 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 224 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 225 | } | |||||
| 226 | catch (S ystem.Exce ption ex) | |||||
| 227 | { | |||||
| 228 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 229 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 230 | ||||||
| 231 | // D isplay the details o f the inne r exceptio n. | |||||
| 232 | if ( ex.InnerEx ception != null) | |||||
| 233 | { | |||||
| 234 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 235 | ||||||
| 236 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 237 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 238 | if (fe != null) | |||||
| 239 | { | |||||
| 240 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 241 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 242 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 243 | Consol e.WriteLin e("Trace: {0}", fe.D etail.Trac eText); | |||||
| 244 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 245 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 246 | } | |||||
| 247 | } | |||||
| 248 | } | |||||
| 249 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 250 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 251 | finally | |||||
| 252 | { | |||||
| 253 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 254 | Cons ole.ReadLi ne(); | |||||
| 255 | } | |||||
| 256 | } | |||||
| 257 | #e ndregion M ain method | |||||
| 258 | } | |||||
| 259 | } | |||||
| 260 | //</snippe tDoesUserB elongToRol e> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.