Produced by Araxis Merge on 2/1/2017 2:56:23 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\BusinessManagement | AddPrincipalToQueue.cs | Tue Dec 20 19:51:44 2016 UTC |
| 2 | Wed Feb 1 19:56:23 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 364 |
| 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 | // | |||||
| 3 | // This f ile is par t of the M icrosoft D ynamics CR M SDK code samples. | |||||
| 4 | // | |||||
| 5 | // Copyri ght (C) Mi crosoft Co rporation. All righ ts reserve d. | |||||
| 6 | // | |||||
| 7 | // This s ource code is intend ed only as a supplem ent to Mic rosoft | |||||
| 8 | // Develo pment Tool s and/or o n-line doc umentation . See the se other | |||||
| 9 | // materi als for de tailed inf ormation r egarding M icrosoft c ode sample s. | |||||
| 10 | // | |||||
| 11 | // THIS C ODE AND IN FORMATION ARE PROVID ED "AS IS" WITHOUT W ARRANTY OF ANY | |||||
| 12 | // KIND, EITHER EXP RESSED OR IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E | |||||
| 13 | // IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR A | |||||
| 14 | // PARTIC ULAR PURPO SE. | |||||
| 15 | // | |||||
| 16 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 17 | //<snippet AddPrincip alToQueue> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Linq; | |||||
| 20 | using Syst em.Threadi ng; | |||||
| 21 | using Syst em.Service Model; | |||||
| 22 | using Syst em.Service Model.Desc ription; | |||||
| 23 | using Syst em.Collect ions.Gener ic; | |||||
| 24 | ||||||
| 25 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 26 | // found i n the SDK\ bin folder . | |||||
| 27 | using Micr osoft.Xrm. Sdk; | |||||
| 28 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 29 | using Micr osoft.Xrm. Sdk.Discov ery; | |||||
| 30 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 31 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 32 | ||||||
| 33 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 34 | // found i n the SDK\ bin folder . | |||||
| 35 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 36 | ||||||
| 37 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 38 | { | |||||
| 39 | /// <s ummary> | |||||
| 40 | /// Th is Sample shows how to share a queue to the team. | |||||
| 41 | /// </ summary> | |||||
| 42 | public class Add PrincipalT oQueue | |||||
| 43 | { | |||||
| 44 | ||||||
| 45 | #r egion Clas s Level Me mbers | |||||
| 46 | ||||||
| 47 | ||||||
| 48 | // Define th e IDs need ed for thi s sample. | |||||
| 49 | pr ivate Guid _queueId; | |||||
| 50 | pr ivate Guid _teamId; | |||||
| 51 | pr ivate Guid _roleId; | |||||
| 52 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 53 | ||||||
| 54 | #e ndregion C lass Level Members | |||||
| 55 | ||||||
| 56 | #r egion How To Sample Code | |||||
| 57 | // / <summary > | |||||
| 58 | // / Create a nd configu re the org anization service pr oxy. | |||||
| 59 | // / Initiate the metho d to creat e any data that this sample re quires. | |||||
| 60 | // / Share a queue to t he team. | |||||
| 61 | // / Optional ly delete any entity records t hat were c reated for this samp le. | |||||
| 62 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 63 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 64 | // / created entities.< /param> | |||||
| 65 | // / </summar y> | |||||
| 66 | ||||||
| 67 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 68 | { | |||||
| 69 | try | |||||
| 70 | { | |||||
| 71 | // C onnect to the Organi zation ser vice. | |||||
| 72 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 73 | 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)) | |||||
| 74 | { | |||||
| 75 | // This st atement is required to enable early-boun d type sup port. | |||||
| 76 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 77 | ||||||
| 78 | CreateRequ iredRecord s(); | |||||
| 79 | ||||||
| 80 | ////<snipp etAddPrinc ipalToQueu e1> | |||||
| 81 | ColumnSet columnSet = new Colu mnSet("nam e"); | |||||
| 82 | Entity tea m = _servi ceProxy.Re trieve(Tea m.EntityLo gicalName, _teamId, columnSet) ; | |||||
| 83 | AddPrincip alToQueueR equest add PrincipalT oQueueRequ est = new AddPrincip alToQueueR equest | |||||
| 84 | { | |||||
| 85 | Princi pal = team , | |||||
| 86 | QueueI d = _queue Id | |||||
| 87 | }; | |||||
| 88 | ||||||
| 89 | _servicePr oxy.Execut e(addPrinc ipalToQueu eRequest); | |||||
| 90 | ||||||
| 91 | //</snippe tAddPrinci palToQueue 1> | |||||
| 92 | ||||||
| 93 | Console.Wr iteLine("T he team ha s been add ed to the queue."); | |||||
| 94 | ||||||
| 95 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 96 | ||||||
| 97 | } | |||||
| 98 | } | |||||
| 99 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 100 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 101 | { | |||||
| 102 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 103 | thro w; | |||||
| 104 | } | |||||
| 105 | } | |||||
| 106 | ||||||
| 107 | // / <summary > | |||||
| 108 | // / This met hod create s any enti ty records that this sample re quires. | |||||
| 109 | // / Create a queue rec ord. | |||||
| 110 | // / Create a team reco rd. | |||||
| 111 | // / Create a role and add queue privileges . | |||||
| 112 | // / Assign r ole to tea m. | |||||
| 113 | // / </summar y> | |||||
| 114 | pu blic void CreateRequ iredRecord s() | |||||
| 115 | { | |||||
| 116 | var Queu eViewType = new | |||||
| 117 | { | |||||
| 118 | Publ ic = 0, | |||||
| 119 | Priv ate = 1 | |||||
| 120 | }; | |||||
| 121 | // Creat e a queue instance a nd set its property values. | |||||
| 122 | Queue ne wQueue = n ew Queue | |||||
| 123 | { | |||||
| 124 | Name = "Exampl e Queue", | |||||
| 125 | Desc ription = "This is a n example queue.", | |||||
| 126 | Queu eViewType = new Opti onSetValue (QueueView Type.Priva te) | |||||
| 127 | }; | |||||
| 128 | ||||||
| 129 | // Creat e a new qu eue and st ore its re turned GUI D in a var iable for later use. | |||||
| 130 | _queueId = _servic eProxy.Cre ate(newQue ue); | |||||
| 131 | Console. WriteLine( "Created { 0}", newQu eue.Name); | |||||
| 132 | ||||||
| 133 | // Retri eve the de fault busi ness unit for the cr eation of the team a nd role. | |||||
| 134 | QueryExp ression qu eryDefault BusinessUn it = new Q ueryExpres sion | |||||
| 135 | { | |||||
| 136 | Enti tyName = B usinessUni t.EntityLo gicalName, | |||||
| 137 | Colu mnSet = ne w ColumnSe t("busines sunitid"), | |||||
| 138 | Crit eria = new FilterExp ression | |||||
| 139 | { | |||||
| 140 | Conditions = | |||||
| 141 | { | |||||
| 142 | ne w Conditio nExpressio n | |||||
| 143 | { | |||||
| 144 | Attribut eName = "p arentbusin essunitid" , | |||||
| 145 | Operator = Conditi onOperator .Null | |||||
| 146 | } | |||||
| 147 | } | |||||
| 148 | } | |||||
| 149 | }; | |||||
| 150 | ||||||
| 151 | Business Unit defau ltBusiness Unit = | |||||
| 152 | (Bus inessUnit) _servicePr oxy.Retrie veMultiple ( | |||||
| 153 | quer yDefaultBu sinessUnit ).Entities [0]; | |||||
| 154 | ||||||
| 155 | // Creat e a new ex ample team . | |||||
| 156 | Team set upTeam = n ew Team | |||||
| 157 | { | |||||
| 158 | Name = "Exampl e Team", | |||||
| 159 | Busi nessUnitId = new Ent ityReferen ce(Busines sUnit.Enti tyLogicalN ame, | |||||
| 160 | defaultBus inessUnit. BusinessUn itId.Value ) | |||||
| 161 | }; | |||||
| 162 | ||||||
| 163 | _teamId = _service Proxy.Crea te(setupTe am); | |||||
| 164 | Console. WriteLine( "Created { 0}", setup Team.Name) ; | |||||
| 165 | ||||||
| 166 | // Creat e a new ex ample role . | |||||
| 167 | Role set upRole = n ew Role | |||||
| 168 | { | |||||
| 169 | Name = "Exampl e Role", | |||||
| 170 | Busi nessUnitId = new Ent ityReferen ce(Busines sUnit.Enti tyLogicalN ame, | |||||
| 171 | defaultBus inessUnit. BusinessUn itId.Value ) | |||||
| 172 | }; | |||||
| 173 | ||||||
| 174 | _roleId = _service Proxy.Crea te(setupRo le); | |||||
| 175 | Console. WriteLine( "Created { 0}", setup Role.Name) ; | |||||
| 176 | ||||||
| 177 | // Retri eve the pr vReadQueue and prvAp pendToQueu e privileg es. | |||||
| 178 | QueryExp ression qu eryQueuePr ivileges = new Query Expression | |||||
| 179 | { | |||||
| 180 | Enti tyName = P rivilege.E ntityLogic alName, | |||||
| 181 | Colu mnSet = ne w ColumnSe t("privile geid", "na me"), | |||||
| 182 | Crit eria = new FilterExp ression | |||||
| 183 | { | |||||
| 184 | Conditions = | |||||
| 185 | { | |||||
| 186 | ne w Conditio nExpressio n | |||||
| 187 | { | |||||
| 188 | Attribut eName = "n ame", | |||||
| 189 | Operator = Conditi onOperator .In, | |||||
| 190 | Values = { "prvRea dQueue", " prvAppendT oQueue" } | |||||
| 191 | } | |||||
| 192 | } | |||||
| 193 | } | |||||
| 194 | }; | |||||
| 195 | ||||||
| 196 | DataColl ection<Ent ity> retri evedQueueP rivileges = | |||||
| 197 | _ser viceProxy. RetrieveMu ltiple(que ryQueuePri vileges).E ntities; | |||||
| 198 | ||||||
| 199 | Console. WriteLine( "Retrieved prvReadQu eue and pr vAppendToQ ueue privi leges."); | |||||
| 200 | ||||||
| 201 | // Defin e a list t o hold the RolePrivi leges we'l l need to add | |||||
| 202 | List<Rol ePrivilege > rolePriv ileges = n ew List<Ro lePrivileg e>(); | |||||
| 203 | ||||||
| 204 | foreach (Privilege privilege in retrie vedQueuePr ivileges) | |||||
| 205 | { | |||||
| 206 | Role Privilege rolePrivil ege = new RolePrivil ege( | |||||
| 207 | (int)Privi legeDepth. Local, pri vilege.Pri vilegeId.V alue); | |||||
| 208 | role Privileges .Add(roleP rivilege); | |||||
| 209 | } | |||||
| 210 | ||||||
| 211 | // Add t he prvRead Queue and prvAppendT oQueue pri vileges to the examp le role. | |||||
| 212 | AddPrivi legesRoleR equest add Privileges Request = new AddPri vilegesRol eRequest | |||||
| 213 | { | |||||
| 214 | Role Id = _role Id, | |||||
| 215 | Priv ileges = r olePrivile ges.ToArra y() | |||||
| 216 | }; | |||||
| 217 | _service Proxy.Exec ute(addPri vilegesReq uest); | |||||
| 218 | Console. WriteLine( "Retrieved privilege s are adde d to {0}." , setupRol e.Name); | |||||
| 219 | ||||||
| 220 | ||||||
| 221 | // Add t he example role to t he example team. | |||||
| 222 | _service Proxy.Asso ciate( | |||||
| 223 | Team.En tityLogica lName, | |||||
| 224 | _teamId , | |||||
| 225 | new Rel ationship( "teamroles _associati on"), | |||||
| 226 | new Ent ityReferen ceCollecti on() { new EntityRef erence(Rol e.EntityLo gicalName, _roleId) }); | |||||
| 227 | ||||||
| 228 | // It ta kes some t ime for th e privileg es to prop ogate to t he team. | |||||
| 229 | // Verif y this is complete b efore cont inuing. | |||||
| 230 | ||||||
| 231 | bool tea mLacksPriv ilege = tr ue; | |||||
| 232 | while (t eamLacksPr ivilege) | |||||
| 233 | { | |||||
| 234 | Retr ieveTeamPr ivilegesRe quest retr ieveTeamPr ivilegesRe quest = | |||||
| 235 | new Retrie veTeamPriv ilegesRequ est | |||||
| 236 | { | |||||
| 237 | TeamId = _ teamId | |||||
| 238 | }; | |||||
| 239 | ||||||
| 240 | Retr ieveTeamPr ivilegesRe sponse ret rieveTeamP rivilegesR esponse = | |||||
| 241 | (RetrieveT eamPrivile gesRespons e)_service Proxy.Exec ute( | |||||
| 242 | retrieveTe amPrivileg esRequest) ; | |||||
| 243 | ||||||
| 244 | if ( retrieveTe amPrivileg esResponse .RolePrivi leges.Any( | |||||
| 245 | rp => rp.P rivilegeId == rolePr ivileges[0 ].Privileg eId) && | |||||
| 246 | retrieveTe amPrivileg esResponse .RolePrivi leges.Any( | |||||
| 247 | rp => rp.P rivilegeId == rolePr ivileges[1 ].Privileg eId)) | |||||
| 248 | { | |||||
| 249 | teamLacksP rivilege = false; | |||||
| 250 | } | |||||
| 251 | else | |||||
| 252 | { | |||||
| 253 | Thread.Sle ep(1000); | |||||
| 254 | } | |||||
| 255 | } | |||||
| 256 | ||||||
| 257 | Console. WriteLine( "{0} has b een added to {1}", | |||||
| 258 | setup Role.Name, setupTeam .Name); | |||||
| 259 | return; | |||||
| 260 | } | |||||
| 261 | ||||||
| 262 | // / <summary > | |||||
| 263 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 264 | // / <param n ame="promp t">Indicat es whether to prompt the user to | |||||
| 265 | // / delete t he records created i n this sam ple.</para m> | |||||
| 266 | // / </summar y> | |||||
| 267 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 268 | { | |||||
| 269 | bool del eteRecords = true; | |||||
| 270 | ||||||
| 271 | if (prom pt) | |||||
| 272 | { | |||||
| 273 | Cons ole.WriteL ine("\nDo you want t hese entit y records deleted? ( y/n)"); | |||||
| 274 | Stri ng answer = Console. ReadLine() ; | |||||
| 275 | ||||||
| 276 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" )); | |||||
| 277 | } | |||||
| 278 | ||||||
| 279 | if (dele teRecords) | |||||
| 280 | { | |||||
| 281 | _ser viceProxy. Delete(Que ue.EntityL ogicalName , _queueId ); | |||||
| 282 | _ser viceProxy. Delete(Tea m.EntityLo gicalName, _teamId); | |||||
| 283 | _ser viceProxy. Delete(Rol e.EntityLo gicalName, _roleId); | |||||
| 284 | ||||||
| 285 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 286 | } | |||||
| 287 | } | |||||
| 288 | #e ndregion H ow To Samp le Code | |||||
| 289 | ||||||
| 290 | #r egion Main | |||||
| 291 | // / <summary > | |||||
| 292 | // / Main. Ru ns the sam ple and pr ovides err or output. | |||||
| 293 | // / <param n ame="args" >Array of arguments to Main me thod.</par am> | |||||
| 294 | // / </summar y> | |||||
| 295 | st atic publi c void Mai n(string[] args) | |||||
| 296 | { | |||||
| 297 | try | |||||
| 298 | { | |||||
| 299 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 300 | // c redentials from the user. | |||||
| 301 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 302 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 303 | ||||||
| 304 | AddP rincipalTo Queue app = new AddP rincipalTo Queue(); | |||||
| 305 | app. Run(config , true); | |||||
| 306 | } | |||||
| 307 | ||||||
| 308 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 309 | { | |||||
| 310 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 311 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 312 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 313 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 314 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 315 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 316 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 317 | } | |||||
| 318 | catch (S ystem.Time outExcepti on ex) | |||||
| 319 | { | |||||
| 320 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 321 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 322 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 323 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 324 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 325 | } | |||||
| 326 | catch (S ystem.Exce ption ex) | |||||
| 327 | { | |||||
| 328 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 329 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 330 | ||||||
| 331 | // D isplay the details o f the inne r exceptio n. | |||||
| 332 | if ( ex.InnerEx ception != null) | |||||
| 333 | { | |||||
| 334 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 335 | ||||||
| 336 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e | |||||
| 337 | = ex.I nnerExcept ion | |||||
| 338 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 339 | if (fe != null) | |||||
| 340 | { | |||||
| 341 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 342 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 343 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 344 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 345 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 346 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 347 | } | |||||
| 348 | } | |||||
| 349 | } | |||||
| 350 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 351 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 352 | ||||||
| 353 | ||||||
| 354 | finally | |||||
| 355 | { | |||||
| 356 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 357 | Cons ole.ReadLi ne(); | |||||
| 358 | } | |||||
| 359 | ||||||
| 360 | } | |||||
| 361 | #e ndregion M ain | |||||
| 362 | } | |||||
| 363 | } | |||||
| 364 | //</snippe tAddPrinci palToQueue > |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.