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 | DisableOREnableUser.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 | 222 |
| 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 DisableOrE nableUser> | |||||
| 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 do disable/e nable a sy stem user account. | |||||
| 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 Dis ableOrEnab leUser | |||||
| 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 | ||||||
| 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, it | |||||
| 49 | // / creates/ retrieves a system u ser, and | |||||
| 50 | // / updates the system user to d isable/ena ble the us er account . | |||||
| 51 | // / Note: Cr eating a u ser is onl y supporte d | |||||
| 52 | // / in an on -premises/ active dir ectory env ironment. | |||||
| 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 nippetDisa bleOrEnabl eUser1> | |||||
| 62 | // C onnect to the Organi zation ser vice. | |||||
| 63 | // T he using s tatement a ssures tha t the serv ice proxy is properl y disposed . | |||||
| 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 | // Retriev e a user. | |||||
| 71 | SystemUser user = _s erviceProx y.Retrieve (SystemUse r.EntityLo gicalName, | |||||
| 72 | _userI d, new Col umnSet(new String [] {"systemu serid", "f irstname", "lastname "})).ToEnt ity<System User>(); | |||||
| 73 | ||||||
| 74 | if (user ! = null) | |||||
| 75 | { | |||||
| 76 | Consol e.WriteLin e("{1} {0} user acco unt is ret rieved.", user.LastN ame, user. FirstName) ; | |||||
| 77 | SetSta teRequest request = new SetSta teRequest( ) { | |||||
| 78 | En tityMonike r = user.T oEntityRef erence(), | |||||
| 79 | // Sets the user to di sabled. | |||||
| 80 | St ate = new OptionSetV alue(1), | |||||
| 81 | // Required by request but alway s valued a t -1 in th is context . | |||||
| 82 | St atus = new OptionSet Value(-1) | |||||
| 83 | /* | |||||
| 84 | // Sets the u ser to ena bled. | |||||
| 85 | St ate = new OptionSetV alue(0), | |||||
| 86 | // Required by request but alway s valued a t -1 in th is context . | |||||
| 87 | St atus = new OptionSet Value(-1) | |||||
| 88 | */ | |||||
| 89 | }; | |||||
| 90 | ||||||
| 91 | _servi ceProxy.Ex ecute(requ est); | |||||
| 92 | ||||||
| 93 | Consol e.WriteLin e("User ac count is d isabled.") ; | |||||
| 94 | } | |||||
| 95 | DeleteRequ iredRecord s(promptfo rDelete); | |||||
| 96 | } | |||||
| 97 | //</ snippetDis ableOrEnab leUser1> | |||||
| 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 | // / Creates any entity records t hat this s ample requ ires. | |||||
| 109 | // / </summar y> | |||||
| 110 | pu blic void CreateRequ iredRecord s() | |||||
| 111 | { | |||||
| 112 | // For t his sample , all requ ired entit ies are cr eated in t he Run() m ethod. | |||||
| 113 | // Retri eve a user . | |||||
| 114 | _userId = SystemUs erProvider .RetrieveA UserWithou tAnyRoleAs signed(_se rviceProxy ); | |||||
| 115 | } | |||||
| 116 | ||||||
| 117 | // / <summary > | |||||
| 118 | // / Deletes/ reverts an y entity r ecords tha t were cre ated for t his sample . | |||||
| 119 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 120 | // / to delet e/revert t he records created i n this sam ple.</para m> | |||||
| 121 | // / </summar y> | |||||
| 122 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 123 | { | |||||
| 124 | bool del eteRecords = true; | |||||
| 125 | ||||||
| 126 | if (prom pt) | |||||
| 127 | { | |||||
| 128 | Cons ole.Write( "\nDo you want these entity re cords dele ted/revert ed? (y/n) [y]: "); | |||||
| 129 | Stri ng answer = Console. ReadLine() ; | |||||
| 130 | ||||||
| 131 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ) || answe r == Strin g.Empty); | |||||
| 132 | } | |||||
| 133 | ||||||
| 134 | if (dele teRecords) | |||||
| 135 | { | |||||
| 136 | SetS tateReques t request = new SetS tateReques t() | |||||
| 137 | { | |||||
| 138 | EntityMoni ker = new EntityRefe rence(Syst emUser.Ent ityLogical Name, | |||||
| 139 | _userI d), | |||||
| 140 | //sets the user to e nabled | |||||
| 141 | State = ne w OptionSe tValue(0), | |||||
| 142 | // require d by reque st but alw ays valued at -1 in this conte xt | |||||
| 143 | Status = n ew OptionS etValue(-1 ) | |||||
| 144 | }; | |||||
| 145 | _ser viceProxy. Execute(re quest); | |||||
| 146 | Cons ole.WriteL ine("User account is enabled b ack again. "); | |||||
| 147 | } | |||||
| 148 | } | |||||
| 149 | ||||||
| 150 | #e ndregion H ow To Samp le Code | |||||
| 151 | ||||||
| 152 | #r egion Main method | |||||
| 153 | ||||||
| 154 | // / <summary > | |||||
| 155 | // / Standard Main() me thod used by most SD K samples. | |||||
| 156 | // / </summar y> | |||||
| 157 | // / <param n ame="args" ></param> | |||||
| 158 | st atic publi c void Mai n(string[] args) | |||||
| 159 | { | |||||
| 160 | try | |||||
| 161 | { | |||||
| 162 | // O btain the target org anization' s web addr ess and cl ient logon | |||||
| 163 | // c redentials from the user. | |||||
| 164 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 165 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 166 | ||||||
| 167 | Disa bleOrEnabl eUser app = new Disa bleOrEnabl eUser(); | |||||
| 168 | app. Run( confi g, true ); | |||||
| 169 | } | |||||
| 170 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 171 | { | |||||
| 172 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 173 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 174 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 175 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 176 | Cons ole.WriteL ine("Trace : {0}", ex .Detail.Tr aceText); | |||||
| 177 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 178 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 179 | } | |||||
| 180 | catch (S ystem.Time outExcepti on ex) | |||||
| 181 | { | |||||
| 182 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 183 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 184 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 185 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 186 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 187 | } | |||||
| 188 | catch (S ystem.Exce ption ex) | |||||
| 189 | { | |||||
| 190 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 191 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 192 | ||||||
| 193 | // D isplay the details o f the inne r exceptio n. | |||||
| 194 | if ( ex.InnerEx ception != null) | |||||
| 195 | { | |||||
| 196 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 197 | ||||||
| 198 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 199 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 200 | if (fe != null) | |||||
| 201 | { | |||||
| 202 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 203 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 204 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 205 | Consol e.WriteLin e("Trace: {0}", fe.D etail.Trac eText); | |||||
| 206 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 207 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 208 | } | |||||
| 209 | } | |||||
| 210 | } | |||||
| 211 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 212 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 213 | finally | |||||
| 214 | { | |||||
| 215 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 216 | Cons ole.ReadLi ne(); | |||||
| 217 | } | |||||
| 218 | } | |||||
| 219 | #e ndregion M ain method | |||||
| 220 | } | |||||
| 221 | } | |||||
| 222 | //</snippe tDisableOr EnableUser > |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.