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 | SharingRecords.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 | 302 |
| 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 SharingRec ords> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Service Model; | |||||
| 19 | ||||||
| 20 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 21 | // found i n the SDK\ bin folder . | |||||
| 22 | using Micr osoft.Xrm. Sdk; | |||||
| 23 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 24 | ||||||
| 25 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 26 | // found i n the SDK\ bin folder . | |||||
| 27 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 28 | ||||||
| 29 | ||||||
| 30 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 31 | ||||||
| 32 | { | |||||
| 33 | /// <s ummary> | |||||
| 34 | /// De monstrates sharing r ecords via access me ssages. | |||||
| 35 | /// </ summary> | |||||
| 36 | public class Sha ringRecord s | |||||
| 37 | { | |||||
| 38 | ||||||
| 39 | #r egion Clas s Level Me mbers | |||||
| 40 | ||||||
| 41 | pr ivate Guid _userId; | |||||
| 42 | pr ivate Guid _accountI d; | |||||
| 43 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 44 | pr ivate IOrg anizationS ervice _se rvice; | |||||
| 45 | ||||||
| 46 | #e ndregion C lass Level Members | |||||
| 47 | ||||||
| 48 | #r egion How- To Sample Code | |||||
| 49 | // / <summary > | |||||
| 50 | // / Demonstr ates shari ng records by exerci sing vario us access messages i ncluding: | |||||
| 51 | // / Grant, M odify, Rev oke, Retri evePrincip alAccess, and | |||||
| 52 | // / Retrieve Principals AndAccess. | |||||
| 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 nippetShar ingRecords 1> | |||||
| 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 | // This st atement is required to enable early-boun d type sup port. | |||||
| 67 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 68 | ||||||
| 69 | _service = (IOrganiz ationServi ce)_servic eProxy; | |||||
| 70 | ||||||
| 71 | CreateRequ iredRecord s(); | |||||
| 72 | ||||||
| 73 | #region Gr antAccess Message | |||||
| 74 | ||||||
| 75 | // Create the reques t object a nd set the target an d principa l access | |||||
| 76 | // object. | |||||
| 77 | GrantAcces sRequest g rantReques t = new Gr antAccessR equest() | |||||
| 78 | { | |||||
| 79 | Target = new Ent ityReferen ce(Account .EntityLog icalName, _accountId ), | |||||
| 80 | Princi palAccess = new Prin cipalAcces s() | |||||
| 81 | { | |||||
| 82 | Pr incipal = new Entity Reference( SystemUser .EntityLog icalName, _userId), | |||||
| 83 | Ac cessMask = AccessRig hts.WriteA ccess | Ac cessRights .ReadAcces s | Access Rights.Sha reAccess | |||||
| 84 | } | |||||
| 85 | }; | |||||
| 86 | ||||||
| 87 | // Execute the reque st. | |||||
| 88 | GrantAcces sResponse grantRespo nse = | |||||
| 89 | (Grant AccessResp onse)_serv ice.Execut e(grantReq uest); | |||||
| 90 | ||||||
| 91 | Console.Wr ite("Acces s Granted "); | |||||
| 92 | ||||||
| 93 | #endregion | |||||
| 94 | ||||||
| 95 | #region Mo difyAccess Message | |||||
| 96 | ||||||
| 97 | // Create the reques t object a nd set the target an d principa l access | |||||
| 98 | // object. | |||||
| 99 | ModifyAcce ssRequest modifyRequ est = new ModifyAcce ssRequest( ) | |||||
| 100 | { | |||||
| 101 | Target = new Ent ityReferen ce(Account .EntityLog icalName, _accountId ), | |||||
| 102 | Princi palAccess = new Prin cipalAcces s() | |||||
| 103 | { | |||||
| 104 | Pr incipal = new Entity Reference( SystemUser .EntityLog icalName, _userId), | |||||
| 105 | Ac cessMask = AccessRig hts.ReadAc cess | Acc essRights. ShareAcces s | |||||
| 106 | } | |||||
| 107 | }; | |||||
| 108 | ||||||
| 109 | // Execute the reque st. | |||||
| 110 | ModifyAcce ssResponse modifyRes ponse = | |||||
| 111 | (Modif yAccessRes ponse)_ser vice.Execu te(modifyR equest); | |||||
| 112 | ||||||
| 113 | Console.Wr ite("and M odified. " ); | |||||
| 114 | ||||||
| 115 | #endregion | |||||
| 116 | ||||||
| 117 | #region Re trievePrin cipalAcces s Message | |||||
| 118 | ||||||
| 119 | // Create the reques t object a nd set the target an d principa l. | |||||
| 120 | RetrievePr incipalAcc essRequest retrieveR equest = n ew Retriev ePrincipal AccessRequ est() | |||||
| 121 | { | |||||
| 122 | Target = new Ent ityReferen ce(Account .EntityLog icalName, _accountId ), | |||||
| 123 | Princi pal = new EntityRefe rence(Syst emUser.Ent ityLogical Name, _use rId) | |||||
| 124 | }; | |||||
| 125 | ||||||
| 126 | // Execute the reque st. | |||||
| 127 | RetrievePr incipalAcc essRespons e retrieve Response = | |||||
| 128 | (Retri evePrincip alAccessRe sponse)_se rvice.Exec ute(retrie veRequest) ; | |||||
| 129 | ||||||
| 130 | Console.Wr ite("Retri eved princ ipal acces s. "); | |||||
| 131 | ||||||
| 132 | #endregion | |||||
| 133 | ||||||
| 134 | #region Re trieveShar edPrincipa lsAndAcces s Message | |||||
| 135 | ||||||
| 136 | // Create the reques t object a nd set the target. | |||||
| 137 | RetrieveSh aredPrinci palsAndAcc essRequest retrieveS haredReque st = | |||||
| 138 | new Re trieveShar edPrincipa lsAndAcces sRequest() | |||||
| 139 | { | |||||
| 140 | Target = new Ent ityReferen ce(Account .EntityLog icalName, _accountId ) | |||||
| 141 | }; | |||||
| 142 | ||||||
| 143 | // Execute the reque st. | |||||
| 144 | RetrieveSh aredPrinci palsAndAcc essRespons e retrieve SharedResp onse = | |||||
| 145 | (Retri eveSharedP rincipalsA ndAccessRe sponse)_se rvice.Exec ute(retrie veSharedRe quest); | |||||
| 146 | ||||||
| 147 | Console.Wr ite("Retri eved princ ipals and access. ") ; | |||||
| 148 | ||||||
| 149 | #endregion | |||||
| 150 | ||||||
| 151 | #region Re vokeAccess Message | |||||
| 152 | ||||||
| 153 | // Create the reques t object a nd set the target an d revokee. | |||||
| 154 | RevokeAcce ssRequest revokeRequ est = new RevokeAcce ssRequest( ) | |||||
| 155 | { | |||||
| 156 | Target = new Ent ityReferen ce(Account .EntityLog icalName, _accountId ), | |||||
| 157 | Revoke e = new En tityRefere nce(System User.Entit yLogicalNa me, _userI d) | |||||
| 158 | }; | |||||
| 159 | ||||||
| 160 | // Execute the reque st. | |||||
| 161 | RevokeAcce ssResponse revokeRes ponse = | |||||
| 162 | (Revok eAccessRes ponse)_ser vice.Execu te(revokeR equest); | |||||
| 163 | ||||||
| 164 | Console.Wr ite("Revok ed Access. "); | |||||
| 165 | ||||||
| 166 | #endregion | |||||
| 167 | ||||||
| 168 | DeleteRequ iredRecord s(promptfo rDelete); | |||||
| 169 | } | |||||
| 170 | //</ snippetSha ringRecord s1> | |||||
| 171 | } | |||||
| 172 | ||||||
| 173 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 174 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 175 | { | |||||
| 176 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 177 | thro w; | |||||
| 178 | } | |||||
| 179 | } | |||||
| 180 | ||||||
| 181 | // / <summary > | |||||
| 182 | // / Creates any entity records t hat this s ample requ ires. | |||||
| 183 | // / </summar y> | |||||
| 184 | pu blic void CreateRequ iredRecord s() | |||||
| 185 | { | |||||
| 186 | // Get t he GUID of the Marke ting Manag er | |||||
| 187 | _userId = SystemUs erProvider .RetrieveM arketingMa nager(_ser viceProxy) ; | |||||
| 188 | ||||||
| 189 | // Insta ntiate an Account ob ject. | |||||
| 190 | // See t he Entity Metadata t opic in th e SDK docu mentation to determi ne | |||||
| 191 | // which attribute s must be set for ea ch entity. | |||||
| 192 | Account setupAccou nt = new A ccount() | |||||
| 193 | { | |||||
| 194 | Name = "Fourth Coffee" | |||||
| 195 | }; | |||||
| 196 | _account Id = _serv ice.Create (setupAcco unt); | |||||
| 197 | } | |||||
| 198 | ||||||
| 199 | // / <summary > | |||||
| 200 | // / Deletes any entity records a nd files t hat were c reated for this samp le. | |||||
| 201 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 202 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 203 | // / </summar y> | |||||
| 204 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 205 | { | |||||
| 206 | // The s ystem user named "Sa mantha Smi th" that w as created by this s ample will | |||||
| 207 | // conti nue to exi st on your system be cause syst em users c annot be d eleted | |||||
| 208 | // in Mi crosoft Dy namics CRM . They ca n only be enabled or disabled. | |||||
| 209 | // If no t promptin g the user , go ahead and clean up. | |||||
| 210 | ||||||
| 211 | if (!pro mpt) | |||||
| 212 | { | |||||
| 213 | _ser vice.Delet e(Account. EntityLogi calName, _ accountId) ; | |||||
| 214 | Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. "); | |||||
| 215 | retu rn; | |||||
| 216 | } | |||||
| 217 | ||||||
| 218 | // Ask t he user if the creat ed entitie s should b e deleted. | |||||
| 219 | Console. Write("\nD o you want these ent ity record s deleted? (y/n) [y] : "); | |||||
| 220 | String a nswer = Co nsole.Read Line(); | |||||
| 221 | ||||||
| 222 | if (answ er.StartsW ith("y") | | answer.S tartsWith( "Y") || an swer == St ring.Empty ) | |||||
| 223 | { | |||||
| 224 | _ser vice.Delet e(Account. EntityLogi calName, _ accountId) ; | |||||
| 225 | Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. "); | |||||
| 226 | } | |||||
| 227 | } | |||||
| 228 | ||||||
| 229 | #e ndregion H ow-To Samp le Code | |||||
| 230 | ||||||
| 231 | #r egion Main method | |||||
| 232 | ||||||
| 233 | // / <summary > | |||||
| 234 | // / Standard Main() me thod used by most SD K samples. | |||||
| 235 | // / </summar y> | |||||
| 236 | // / <param n ame="args" ></param> | |||||
| 237 | st atic publi c void Mai n(string[] args) | |||||
| 238 | { | |||||
| 239 | try | |||||
| 240 | { | |||||
| 241 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 242 | // c redentials from the user. | |||||
| 243 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 244 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 245 | ||||||
| 246 | Shar ingRecords app = new SharingRe cords(); | |||||
| 247 | app. Run(config , true); | |||||
| 248 | } | |||||
| 249 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 250 | { | |||||
| 251 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 252 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 253 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 254 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 255 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 256 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 257 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 258 | } | |||||
| 259 | catch (S ystem.Time outExcepti on ex) | |||||
| 260 | { | |||||
| 261 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 262 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 263 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 264 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 265 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 266 | } | |||||
| 267 | catch (S ystem.Exce ption ex) | |||||
| 268 | { | |||||
| 269 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 270 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 271 | ||||||
| 272 | // D isplay the details o f the inne r exceptio n. | |||||
| 273 | if ( ex.InnerEx ception != null) | |||||
| 274 | { | |||||
| 275 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 276 | ||||||
| 277 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 278 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 279 | if (fe != null) | |||||
| 280 | { | |||||
| 281 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 282 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 283 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 284 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 285 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 286 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 287 | } | |||||
| 288 | } | |||||
| 289 | } | |||||
| 290 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 291 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 292 | ||||||
| 293 | finally | |||||
| 294 | { | |||||
| 295 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 296 | Cons ole.ReadLi ne(); | |||||
| 297 | } | |||||
| 298 | } | |||||
| 299 | #e ndregion M ain method | |||||
| 300 | } | |||||
| 301 | } | |||||
| 302 | //</snippe tSharingRe cords> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.