Produced by Araxis Merge on 2/1/2017 2:56:27 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\ScheduleAndAppointment | CRUDRecurringAppointment.cs | Tue Dec 20 19:51:43 2016 UTC |
| 2 | Wed Feb 1 19:56:27 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 291 |
| 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 CRUDRecurr ingAppoint ment> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Linq; | |||||
| 20 | using Syst em.Service Model; | |||||
| 21 | using Syst em.Service Model.Desc ription; | |||||
| 22 | ||||||
| 23 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 24 | // found i n the SDK\ bin folder . | |||||
| 25 | using Micr osoft.Xrm. Sdk; | |||||
| 26 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 27 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 28 | using Micr osoft.Xrm. Sdk.Discov ery; | |||||
| 29 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 30 | ||||||
| 31 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 32 | // found i n the SDK\ bin folder . | |||||
| 33 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 34 | ||||||
| 35 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 36 | { | |||||
| 37 | /// <s ummary> | |||||
| 38 | /// Th is sample shows how to create, retrieve, update, a nd delete a | |||||
| 39 | /// re curring ap pointment series. | |||||
| 40 | /// </ summary> | |||||
| 41 | public class CRU DRecurring Appointmen t | |||||
| 42 | { | |||||
| 43 | #r egion Clas s Level Me mbers | |||||
| 44 | ||||||
| 45 | // / <summary > | |||||
| 46 | // / Stores t he organiz ation serv ice proxy. | |||||
| 47 | // / </summar y> | |||||
| 48 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 49 | ||||||
| 50 | // Define th e IDs as w ell as str ings neede d for this sample. | |||||
| 51 | pu blic Guid _recurring Appointmen tMasterId; | |||||
| 52 | ||||||
| 53 | #e ndregion C lass Level Members | |||||
| 54 | ||||||
| 55 | #r egion How To Sample Code | |||||
| 56 | // / <summary > | |||||
| 57 | // / Create a nd configu re the org anization service pr oxy. | |||||
| 58 | // / Create a recurring appointme nt. | |||||
| 59 | // / Retrieve the recur ring appoi ntment. | |||||
| 60 | // / Update t he retriev ed recurri ng appoint ment. | |||||
| 61 | // / Optional ly delete any entity records t hat were c reated for this samp le. | |||||
| 62 | // / </summar y> | |||||
| 63 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 64 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 65 | // / created entities.< /param> | |||||
| 66 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 67 | { | |||||
| 68 | try | |||||
| 69 | { | |||||
| 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,server Config.Cre dentials, serverConf ig.DeviceC redentials )) | |||||
| 74 | { | |||||
| 75 | // This st atement is required to enable early-boun d type sup port. | |||||
| 76 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 77 | ||||||
| 78 | ||||||
| 79 | //<snippet CRUDRecurr ingAppoint ment1> | |||||
| 80 | // Define an anonymo us type to define th e possible recurrenc e pattern values. | |||||
| 81 | var Recurr encePatter nTypes = n ew | |||||
| 82 | { | |||||
| 83 | Daily = 0, | |||||
| 84 | Weekly = 1, | |||||
| 85 | Monthl y = 2, | |||||
| 86 | Yearly = 3 | |||||
| 87 | }; | |||||
| 88 | ||||||
| 89 | // Define an anonymo us type to define th e possible values fo r days | |||||
| 90 | // of the week | |||||
| 91 | var DayOfW eek = new | |||||
| 92 | { | |||||
| 93 | Sunday = 0x01, | |||||
| 94 | Monday = 0x02, | |||||
| 95 | Tuesda y = 0x04, | |||||
| 96 | Wednes day = 0x08 , | |||||
| 97 | Thursd ay = 0x10, | |||||
| 98 | Friday = 0x20, | |||||
| 99 | Saturd ay = 0x40 | |||||
| 100 | }; | |||||
| 101 | ||||||
| 102 | // Define an anonymo us type to define th e possible values | |||||
| 103 | // for the recurrenc e rule pat tern end t ype. | |||||
| 104 | var Recurr enceRulePa tternEndTy pe = new | |||||
| 105 | { | |||||
| 106 | NoEndD ate = 1, | |||||
| 107 | Occurr ences = 2, | |||||
| 108 | Patter nEndDate = 3 | |||||
| 109 | }; | |||||
| 110 | ||||||
| 111 | // Create a recurrin g appointm ent | |||||
| 112 | RecurringA ppointment Master new RecurringA ppointment = new Rec urringAppo intmentMas ter | |||||
| 113 | { | |||||
| 114 | Su bject = "S ample Recu rring Appo intment", | |||||
| 115 | St artTime = DateTime.N ow.AddHour s(1), | |||||
| 116 | En dTime = Da teTime.Now .AddHours( 2), | |||||
| 117 | Re currencePa tternType = new Opti onSetValue (Recurrenc ePatternTy pes.Weekly ), | |||||
| 118 | In terval = 1 , | |||||
| 119 | Da ysOfWeekMa sk = DayOf Week.Thurs day, | |||||
| 120 | Pa tternStart Date = Dat eTime.Toda y, | |||||
| 121 | Oc currences = 10, | |||||
| 122 | Pa tternEndTy pe = new O ptionSetVa lue(Recurr enceRulePa tternEndTy pe.Occurre nces) | |||||
| 123 | }; | |||||
| 124 | ||||||
| 125 | _recurring Appointmen tMasterId = _service Proxy.Crea te(newRecu rringAppoi ntment); | |||||
| 126 | Console.Wr iteLine("C reated {0} .", newRec urringAppo intment.Su bject); | |||||
| 127 | ||||||
| 128 | // Retriev e the newl y created recurring appointmen t | |||||
| 129 | QueryExpre ssion recu rringAppoi ntmentQuer y = new Qu eryExpress ion | |||||
| 130 | { | |||||
| 131 | Entity Name = Rec urringAppo intmentMas ter.Entity LogicalNam e, | |||||
| 132 | Column Set = new ColumnSet( "subject") , | |||||
| 133 | Criter ia = new F ilterExpre ssion | |||||
| 134 | { | |||||
| 135 | Co nditions = | |||||
| 136 | { | |||||
| 137 | ne w Conditio nExpressio n | |||||
| 138 | { | |||||
| 139 | Attribut eName = "s ubject", | |||||
| 140 | Operator = Conditi onOperator .Equal, | |||||
| 141 | Values = { "Sample Recurring Appointme nt" } | |||||
| 142 | }, | |||||
| 143 | ne w Conditio nExpressio n | |||||
| 144 | { | |||||
| 145 | Attribut eName = "i nterval", | |||||
| 146 | Operator = Conditi onOperator .Equal, | |||||
| 147 | Values = { 1 } | |||||
| 148 | } | |||||
| 149 | } | |||||
| 150 | }, | |||||
| 151 | PageIn fo = new P agingInfo | |||||
| 152 | { | |||||
| 153 | Co unt = 1, | |||||
| 154 | Pa geNumber = 1 | |||||
| 155 | } | |||||
| 156 | }; | |||||
| 157 | ||||||
| 158 | RecurringA ppointment Master ret rievedRecu rringAppoi ntment = | |||||
| 159 | _servi ceProxy.Re trieveMult iple(recur ringAppoin tmentQuery ). | |||||
| 160 | Entiti es.Select( x => (Recu rringAppoi ntmentMast er)x).Firs tOrDefault (); | |||||
| 161 | ||||||
| 162 | Console.Wr iteLine("R etrieved t he recurri ng appoint ment."); | |||||
| 163 | ||||||
| 164 | // Update the recurr ing appoin tment. | |||||
| 165 | // Update the follow ing for th e retrieve d recurrin g appointm ent series : | |||||
| 166 | // 1. Upda te the sub ject. | |||||
| 167 | // 2. Upda te the num ber of occ urences to 5. | |||||
| 168 | // 3. Upda te the app ointment i nterval to 2. | |||||
| 169 | ||||||
| 170 | retrievedR ecurringAp pointment. Subject = "Updated R ecurring A ppointment "; | |||||
| 171 | retrievedR ecurringAp pointment. Occurrence s = 5; | |||||
| 172 | retrievedR ecurringAp pointment. Interval = 2; | |||||
| 173 | _servicePr oxy.Update (retrieved RecurringA ppointment ); | |||||
| 174 | ||||||
| 175 | Console.Wr iteLine("U pdated the subject, occurrence s, and int erval of t he recurri ng appoint ment."); | |||||
| 176 | //</snippe tCRUDRecur ringAppoin tment1> | |||||
| 177 | ||||||
| 178 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 179 | } | |||||
| 180 | } | |||||
| 181 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 182 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 183 | { | |||||
| 184 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 185 | thro w; | |||||
| 186 | } | |||||
| 187 | } | |||||
| 188 | ||||||
| 189 | // / <summary > | |||||
| 190 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 191 | // / <param n ame="promp t">Indicat es whether to prompt the user to delete | |||||
| 192 | // / the reco rds create d in this sample.</p aram> | |||||
| 193 | // / </summar y> | |||||
| 194 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 195 | { | |||||
| 196 | bool del eteRecords = true; | |||||
| 197 | ||||||
| 198 | if (prom pt) | |||||
| 199 | { | |||||
| 200 | Cons ole.WriteL ine("\nDo you want t hese entit y records to be dele ted? (y/n) "); | |||||
| 201 | Stri ng answer = Console. ReadLine() ; | |||||
| 202 | ||||||
| 203 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" )); | |||||
| 204 | } | |||||
| 205 | ||||||
| 206 | if (dele teRecords) | |||||
| 207 | { | |||||
| 208 | _ser viceProxy. Delete(Rec urringAppo intmentMas ter.Entity LogicalNam e, | |||||
| 209 | _recurring Appointmen tMasterId) ; | |||||
| 210 | ||||||
| 211 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 212 | } | |||||
| 213 | } | |||||
| 214 | ||||||
| 215 | #e ndregion H ow To Samp le Code | |||||
| 216 | ||||||
| 217 | #r egion Main | |||||
| 218 | // / <summary > | |||||
| 219 | // / Standard Main() me thod used by most SD K samples. | |||||
| 220 | // / </summar y> | |||||
| 221 | // / <param n ame="args" ></param> | |||||
| 222 | st atic publi c void Mai n(string[] args) | |||||
| 223 | { | |||||
| 224 | try | |||||
| 225 | { | |||||
| 226 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 227 | // c redentials from the user. | |||||
| 228 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 229 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 230 | ||||||
| 231 | CRUD RecurringA ppointment app = new CRUDRecur ringAppoin tment(); | |||||
| 232 | app. Run(config , true); | |||||
| 233 | } | |||||
| 234 | ||||||
| 235 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 236 | { | |||||
| 237 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 238 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 239 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 240 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 241 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 242 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 243 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 244 | } | |||||
| 245 | catch (S ystem.Time outExcepti on ex) | |||||
| 246 | { | |||||
| 247 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 248 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 249 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 250 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 251 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 252 | } | |||||
| 253 | catch (S ystem.Exce ption ex) | |||||
| 254 | { | |||||
| 255 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 256 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 257 | ||||||
| 258 | // D isplay the details o f the inne r exceptio n. | |||||
| 259 | if ( ex.InnerEx ception != null) | |||||
| 260 | { | |||||
| 261 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 262 | ||||||
| 263 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e | |||||
| 264 | = ex.I nnerExcept ion | |||||
| 265 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 266 | if (fe != null) | |||||
| 267 | { | |||||
| 268 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 269 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 270 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 271 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 272 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 273 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 274 | } | |||||
| 275 | } | |||||
| 276 | } | |||||
| 277 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 278 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 279 | ||||||
| 280 | finally | |||||
| 281 | { | |||||
| 282 | ||||||
| 283 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 284 | Cons ole.ReadLi ne(); | |||||
| 285 | } | |||||
| 286 | ||||||
| 287 | } | |||||
| 288 | #e ndregion M ain | |||||
| 289 | } | |||||
| 290 | } | |||||
| 291 | //</snippe tCRUDRecur ringAppoin tment> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.