Produced by Araxis Merge on 2/1/2017 2:56:33 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\GeneralProgramming\EarlyBound | AssignRecordToTeam.cs | Tue Dec 20 19:51:45 2016 UTC |
| 2 | Wed Feb 1 19:56:33 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 366 |
| 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 AssignReco rdToTeam> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Service Model; | |||||
| 20 | using Syst em.Service Model.Desc ription; | |||||
| 21 | ||||||
| 22 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 23 | // found i n the SDK\ bin folder . | |||||
| 24 | using Micr osoft.Xrm. Sdk; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 26 | using Micr osoft.Xrm. Sdk.Discov ery; | |||||
| 27 | ||||||
| 28 | ||||||
| 29 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 30 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 31 | ||||||
| 32 | ||||||
| 33 | ||||||
| 34 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 35 | { | |||||
| 36 | ||||||
| 37 | /// <s ummary> | |||||
| 38 | /// De monstrates how to as sign a rec ord to a t eam. | |||||
| 39 | /// If you want to run thi s sample r epeatedly, you have the option to | |||||
| 40 | /// de lete all t he records created a t the end of executi on. | |||||
| 41 | /// </ summary> | |||||
| 42 | public class Ass ignRecordT oTeam | |||||
| 43 | { | |||||
| 44 | #r egion Clas s Level Me mbers | |||||
| 45 | ||||||
| 46 | // / <summary > | |||||
| 47 | // / Stores t he organiz ation serv ice interf ace. | |||||
| 48 | // / </summar y> | |||||
| 49 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 50 | pr ivate IOrg anizationS ervice _se rvice; | |||||
| 51 | ||||||
| 52 | // Define th e IDs need ed for thi s sample. | |||||
| 53 | pu blic Guid _accountId ; | |||||
| 54 | pu blic Guid _teamId; | |||||
| 55 | pu blic Guid _roleId; | |||||
| 56 | ||||||
| 57 | #e ndregion C lass Level Members | |||||
| 58 | ||||||
| 59 | #r egion How To Sample Code | |||||
| 60 | // / <summary > | |||||
| 61 | // / Create a nd configu re the org anization service pr oxy. | |||||
| 62 | // / Create a team, an account an d a role. | |||||
| 63 | // / Add read account p rivileges to the rol e. | |||||
| 64 | // / Assign t he role to the team so that th ey can rea d the acco unt. | |||||
| 65 | // / Assign t he account to the te am. | |||||
| 66 | // / Optional ly delete the accoun t, team an d role rec ords. | |||||
| 67 | // / <para na me="organi zationFrie ndlyName"> The friend ly name of | |||||
| 68 | // / the targ et organiz ation.</pa ra> | |||||
| 69 | // / <para na me="discov eryServer" >The name of the dis covery ser ver.</para > | |||||
| 70 | // / <param n ame="promp tForDelete ">Indicate s whether to prompt the user | |||||
| 71 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 72 | // / </summar y> | |||||
| 73 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 74 | { | |||||
| 75 | try | |||||
| 76 | { | |||||
| 77 | // C onnect to the Organi zation ser vice. | |||||
| 78 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 79 | usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri, | |||||
| 80 | s erverConfi g.Credenti als, serve rConfig.De viceCreden tials)) | |||||
| 81 | { | |||||
| 82 | // This st atement is required to enable early-boun d type sup port. | |||||
| 83 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 84 | ||||||
| 85 | _service = (IOrganiz ationServi ce)_servic eProxy; | |||||
| 86 | ||||||
| 87 | // Call th e method t o create a ny data th at this sa mple requi res. | |||||
| 88 | CreateRequ iredRecord s(); | |||||
| 89 | ||||||
| 90 | //<snippet AssignReco rdToTeam1> | |||||
| 91 | // Assign the accoun t to a tea m. | |||||
| 92 | AssignRequ est assign Request = new Assign Request() | |||||
| 93 | { | |||||
| 94 | Assign ee = new E ntityRefer ence | |||||
| 95 | { | |||||
| 96 | Lo gicalName = Team.Ent ityLogical Name, | |||||
| 97 | Id = _teamId | |||||
| 98 | }, | |||||
| 99 | ||||||
| 100 | Target = new Ent ityReferen ce(Account .EntityLog icalName, _accountId ) | |||||
| 101 | }; | |||||
| 102 | ||||||
| 103 | _service.E xecute(ass ignRequest ); | |||||
| 104 | //</snippe tAssignRec ordToTeam1 > | |||||
| 105 | ||||||
| 106 | Console.Wr iteLine("T he account is owned by the tea m."); | |||||
| 107 | ||||||
| 108 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 109 | } | |||||
| 110 | } | |||||
| 111 | ||||||
| 112 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 113 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 114 | { | |||||
| 115 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 116 | thro w; | |||||
| 117 | } | |||||
| 118 | } | |||||
| 119 | ||||||
| 120 | // / <summary > | |||||
| 121 | // / This met hod create s any enti ty records that this sample re quires. | |||||
| 122 | // / Create a team, an account an d a role. | |||||
| 123 | // / Add read account p rivileges to the rol e. | |||||
| 124 | // / Assign t he role to the team so that th ey can rea d the acco unt. | |||||
| 125 | // / Assign t he account to the te am. | |||||
| 126 | // / </summar y> | |||||
| 127 | pu blic void CreateRequ iredRecord s() | |||||
| 128 | { | |||||
| 129 | // Insta ntiate an account en tity recor d and set its proper ty values. | |||||
| 130 | // See t he Entity Metadata t opic in th e SDK docu mentation to determi ne | |||||
| 131 | // which attribute s must be set for ea ch entity. | |||||
| 132 | Account setupAccou nt = new A ccount | |||||
| 133 | { | |||||
| 134 | Name = "Exampl e Account" | |||||
| 135 | }; | |||||
| 136 | ||||||
| 137 | // Creat e the acco unt record . | |||||
| 138 | _account Id = _serv ice.Create (setupAcco unt); | |||||
| 139 | Console. WriteLine( "Created { 0}", setup Account.Na me); | |||||
| 140 | ||||||
| 141 | // Retri eve the de fault busi ness unit needed to create the team and role. | |||||
| 142 | QueryExp ression qu eryDefault BusinessUn it = new Q ueryExpres sion | |||||
| 143 | { | |||||
| 144 | Enti tyName = B usinessUni t.EntityLo gicalName, | |||||
| 145 | Colu mnSet = ne w ColumnSe t("busines sunitid" ) , | |||||
| 146 | Crit eria = new FilterExp ression() | |||||
| 147 | }; | |||||
| 148 | ||||||
| 149 | queryDef aultBusine ssUnit.Cri teria.AddC ondition(" parentbusi nessunitid ", | |||||
| 150 | Cond itionOpera tor.Null); | |||||
| 151 | ||||||
| 152 | Business Unit defau ltBusiness Unit = (Bu sinessUnit )_service. RetrieveMu ltiple( | |||||
| 153 | quer yDefaultBu sinessUnit ).Entities [0]; | |||||
| 154 | ||||||
| 155 | // Insta ntiate a t eam entity record an d set its property v alues. | |||||
| 156 | // See t he Entity Metadata t opic in th e SDK docu mentation to determi ne | |||||
| 157 | // which attribute s must be set for ea ch entity. | |||||
| 158 | Team set upTeam = n ew Team | |||||
| 159 | { | |||||
| 160 | Name = "Exampl e Team", | |||||
| 161 | Busi nessUnitId = new Ent ityReferen ce(Busines sUnit.Enti tyLogicalN ame, | |||||
| 162 | defaultBus inessUnit. Id) | |||||
| 163 | }; | |||||
| 164 | ||||||
| 165 | // Creat e a team r ecord. | |||||
| 166 | _teamId = _service .Create(se tupTeam); | |||||
| 167 | Console. WriteLine( "Created { 0}", setup Team.Name) ; | |||||
| 168 | ||||||
| 169 | // Insta ntiate a r ole entity record an d set its property v alues. | |||||
| 170 | // See t he Entity Metadata t opic in th e SDK docu mentation to determi ne | |||||
| 171 | // which attribute s must be set for ea ch entity. | |||||
| 172 | Role set upRole = n ew Role | |||||
| 173 | { | |||||
| 174 | Name = "Exampl e Role", | |||||
| 175 | Busi nessUnitId = new Ent ityReferen ce(Busines sUnit.Enti tyLogicalN ame, | |||||
| 176 | defaultBus inessUnit. Id) | |||||
| 177 | }; | |||||
| 178 | ||||||
| 179 | // Creat e a role r ecord. Typ ically you would use an existi ng role th at has the | |||||
| 180 | // the c orrect pri vileges. F or this sa mple we ne ed to be s ure the ro le has | |||||
| 181 | // at le ast the pr ivilege to read acco unt record s. | |||||
| 182 | _roleId = _service .Create(se tupRole); | |||||
| 183 | Console. WriteLine( "Created { 0}", setup Role.Name) ; | |||||
| 184 | ||||||
| 185 | // Creat e a query expression to find t he prvRead AccountPri vilege. | |||||
| 186 | QueryExp ression qu eryReadAcc ountPrivil ege = new QueryExpre ssion | |||||
| 187 | { | |||||
| 188 | Enti tyName = P rivilege.E ntityLogic alName, | |||||
| 189 | Colu mnSet = ne w ColumnSe t("privile geid", "na me"), | |||||
| 190 | Crit eria = new FilterExp ression() | |||||
| 191 | }; | |||||
| 192 | queryRea dAccountPr ivilege.Cr iteria.Add Condition( "name", | |||||
| 193 | Cond itionOpera tor.Equal, "prvReadA ccount"); | |||||
| 194 | ||||||
| 195 | // Retri eve the pr vReadAccou nt privile ge. | |||||
| 196 | Entity r eadAccount Privilege = _service .RetrieveM ultiple( | |||||
| 197 | quer yReadAccou ntPrivileg e)[0]; | |||||
| 198 | Console. WriteLine( "Retrieved {0}", rea dAccountPr ivilege.At tributes[" name"]); | |||||
| 199 | ||||||
| 200 | //<snipp etAssignRe cordToTeam 2> | |||||
| 201 | // Add t he prvRead Account pr ivilege to the examp le roles t o assure t he | |||||
| 202 | // team can read a ccounts. | |||||
| 203 | AddPrivi legesRoleR equest add Privileges Request = new AddPri vilegesRol eRequest | |||||
| 204 | { | |||||
| 205 | Role Id = _role Id, | |||||
| 206 | Priv ileges = n ew[] | |||||
| 207 | { | |||||
| 208 | // Grant p rvReadAcco unt privil ege. | |||||
| 209 | new RolePr ivilege | |||||
| 210 | { | |||||
| 211 | Privil egeId = re adAccountP rivilege.I d | |||||
| 212 | } | |||||
| 213 | } | |||||
| 214 | }; | |||||
| 215 | _service .Execute(a ddPrivileg esRequest) ; | |||||
| 216 | //</snip petAssignR ecordToTea m2> | |||||
| 217 | ||||||
| 218 | Console. WriteLine( "Added pri vilege to role"); | |||||
| 219 | ||||||
| 220 | // Add t he role to the team. | |||||
| 221 | _service .Associate ( | |||||
| 222 | Team.En tityLogica lName, | |||||
| 223 | _teamId , | |||||
| 224 | new Rel ationship( "teamroles _associati on"), | |||||
| 225 | new Ent ityReferen ceCollecti on() { new EntityRef erence(Rol e.EntityLo gicalName, _roleId) }); | |||||
| 226 | ||||||
| 227 | Console. WriteLine( "Assigned team to ro le"); | |||||
| 228 | ||||||
| 229 | //<snipp etAssignRe cordToTeam 3> | |||||
| 230 | // It ta kes some t ime for th e privileg es to prop agate to t he team. D elay the | |||||
| 231 | // appli cation unt il the pri vilege has been assi gned. | |||||
| 232 | bool tea mLacksPriv ilege = tr ue; | |||||
| 233 | while (t eamLacksPr ivilege) | |||||
| 234 | { | |||||
| 235 | Retr ieveTeamPr ivilegesRe quest retr ieveTeamPr ivilegesRe quest = | |||||
| 236 | new Retrie veTeamPriv ilegesRequ est | |||||
| 237 | { | |||||
| 238 | TeamId = _ teamId | |||||
| 239 | }; | |||||
| 240 | ||||||
| 241 | Retr ieveTeamPr ivilegesRe sponse ret rieveTeamP rivilegesR esponse = | |||||
| 242 | (RetrieveT eamPrivile gesRespons e)_service .Execute( | |||||
| 243 | retrieveTe amPrivileg esRequest) ; | |||||
| 244 | ||||||
| 245 | fore ach (RoleP rivilege r p in | |||||
| 246 | retrieveTe amPrivileg esResponse .RolePrivi leges) | |||||
| 247 | { | |||||
| 248 | if (rp.Pri vilegeId = = readAcco untPrivile ge.Id) | |||||
| 249 | { | |||||
| 250 | teamLa cksPrivile ge = false ; | |||||
| 251 | break; | |||||
| 252 | } | |||||
| 253 | else | |||||
| 254 | { | |||||
| 255 | System .Threading .Thread.Cu rrentThrea d.Join(500 ); | |||||
| 256 | } | |||||
| 257 | } | |||||
| 258 | } | |||||
| 259 | //</snip petAssignR ecordToTea m3> | |||||
| 260 | ||||||
| 261 | return; | |||||
| 262 | } | |||||
| 263 | ||||||
| 264 | // / <summary > | |||||
| 265 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 266 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 267 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 268 | // / </summar y> | |||||
| 269 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 270 | { | |||||
| 271 | bool del eteRecords = true; | |||||
| 272 | ||||||
| 273 | if (prom pt) | |||||
| 274 | { | |||||
| 275 | Cons ole.WriteL ine("\nDo you want t hese entit y records deleted? ( y/n)"); | |||||
| 276 | Stri ng answer = Console. ReadLine() ; | |||||
| 277 | ||||||
| 278 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" )); | |||||
| 279 | } | |||||
| 280 | ||||||
| 281 | if (dele teRecords) | |||||
| 282 | { | |||||
| 283 | _ser vice.Delet e("account ", _accoun tId); | |||||
| 284 | _ser vice.Delet e("team", _teamId); | |||||
| 285 | _ser vice.Delet e("role", _roleId); | |||||
| 286 | ||||||
| 287 | ||||||
| 288 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 289 | } | |||||
| 290 | } | |||||
| 291 | ||||||
| 292 | #e ndregion H ow To Samp le Code | |||||
| 293 | ||||||
| 294 | #r egion Main | |||||
| 295 | // / <summary > | |||||
| 296 | // / Main. Ru ns the sam ple and pr ovides err or output. | |||||
| 297 | // / <param n ame="args" >Array of arguments to Main me thod.</par am> | |||||
| 298 | // / </summar y> | |||||
| 299 | st atic publi c void Mai n(string[] args) | |||||
| 300 | { | |||||
| 301 | ||||||
| 302 | try | |||||
| 303 | { | |||||
| 304 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 305 | // c redentials from the user. | |||||
| 306 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 307 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 308 | ||||||
| 309 | Assi gnRecordTo Team app = new Assig nRecordToT eam(); | |||||
| 310 | app. Run(config , true); | |||||
| 311 | } | |||||
| 312 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 313 | { | |||||
| 314 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 315 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 316 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 317 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 318 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 319 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 320 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 321 | } | |||||
| 322 | catch (S ystem.Time outExcepti on ex) | |||||
| 323 | { | |||||
| 324 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 325 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 326 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 327 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 328 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 329 | } | |||||
| 330 | catch (S ystem.Exce ption ex) | |||||
| 331 | { | |||||
| 332 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 333 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 334 | ||||||
| 335 | // D isplay the details o f the inne r exceptio n. | |||||
| 336 | if ( ex.InnerEx ception != null) | |||||
| 337 | { | |||||
| 338 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 339 | ||||||
| 340 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = | |||||
| 341 | ex.Inn erExceptio n | |||||
| 342 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 343 | if (fe != null) | |||||
| 344 | { | |||||
| 345 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 346 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 347 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 348 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 349 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 350 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 351 | } | |||||
| 352 | } | |||||
| 353 | } | |||||
| 354 | finally | |||||
| 355 | { | |||||
| 356 | ||||||
| 357 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 358 | Cons ole.ReadLi ne(); | |||||
| 359 | } | |||||
| 360 | ||||||
| 361 | } | |||||
| 362 | #e ndregion M ain | |||||
| 363 | ||||||
| 364 | } | |||||
| 365 | } | |||||
| 366 | //</snippe tAssignRec ordToTeam> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.