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 | RescheduleandCancelRecurringAppointment.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 | 334 |
| 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 thes e 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 Reschedule andCancelR ecurringAp pointmentI nstance> | |||||
| 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 resched ule an ins tance and cancel | |||||
| 39 | /// th e last ins tance of a recurring appointme nt series. | |||||
| 40 | /// </ summary> | |||||
| 41 | public class Res cheduleand CancelRecu rringAppoi ntmentInst ance | |||||
| 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 | // / Initiate the metho d to creat e any data that this sample re quires. | |||||
| 59 | // / Reschedu le an inst ance of th e recurrin g appointm ent series . | |||||
| 60 | // / Cancel a nother ins tance of t he recurri ng appoint ment serie s. | |||||
| 61 | // / Optional ly delete any entity records t hat were c reated for this samp le. | |||||
| 62 | / // </summa ry> | |||||
| 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 | // Call th e method t o create a ny data th at this sa mple requi res. | |||||
| 79 | CreateRequ iredRecord s(); | |||||
| 80 | ||||||
| 81 | //<snippet Reschedule andCancelR ecurringAp pointmentI nstance1> | |||||
| 82 | // Retriev e the indi vidual app ointment i nstance th at falls o n or after | |||||
| 83 | // 10 days from toda y. Basical ly this wi ll be the second ins tance in t he | |||||
| 84 | // recurri ng appoint ment serie s. | |||||
| 85 | ||||||
| 86 | QueryExpre ssion inst anceQuery = new Quer yExpressio n | |||||
| 87 | { | |||||
| 88 | Entity Name = App ointment.E ntityLogic alName, | |||||
| 89 | Column Set = new ColumnSet | |||||
| 90 | { | |||||
| 91 | Co lumns = { "activityi d", "sched uledstart" , "schedul edend" } | |||||
| 92 | }, | |||||
| 93 | Criter ia = new F ilterExpre ssion | |||||
| 94 | { | |||||
| 95 | Co nditions = | |||||
| 96 | { | |||||
| 97 | ne w Conditio nExpressio n | |||||
| 98 | { | |||||
| 99 | Attribut eName = "s eriesid", | |||||
| 100 | Operator = Conditi onOperator .Equal, | |||||
| 101 | Values = { _recurr ingAppoint mentMaster Id } | |||||
| 102 | }, | |||||
| 103 | ne w Conditio nExpressio n | |||||
| 104 | { | |||||
| 105 | Attribu teName = " scheduleds tart", | |||||
| 106 | Operato r = Condit ionOperato r.OnOrAfte r, | |||||
| 107 | Values = { DateTi me.Today.A ddDays(10) } | |||||
| 108 | } | |||||
| 109 | } | |||||
| 110 | } | |||||
| 111 | }; | |||||
| 112 | ||||||
| 113 | EntityColl ection ind ividualApp ointments = _service Proxy.Retr ieveMultip le(instanc eQuery); | |||||
| 114 | ||||||
| 115 | //<snippet Reschedule andCancelR ecurringAp pointmentI nstance2> | |||||
| 116 | ||||||
| 117 | #region Re schedule a n instance of recurr ing appoin tment | |||||
| 118 | ||||||
| 119 | // Update the schedu led start and end da tes of the appointme nt | |||||
| 120 | // to resc hedule it. | |||||
| 121 | Appointmen t updateAp pointment = new Appo intment | |||||
| 122 | { | |||||
| 123 | Activi tyId = ind ividualApp ointments. Entities.S elect(x => (Appointm ent)x).Fir st().Activ ityId, | |||||
| 124 | Schedu ledStart = individua lAppointme nts.Entiti es.Select( x => (Appo intment)x) .First().S cheduledSt art.Value. AddHours(1 ), | |||||
| 125 | Schedu ledEnd = i ndividualA ppointment s.Entities .Select(x => (Appoin tment)x).F irst().Sch eduledEnd. Value.AddH ours(2) | |||||
| 126 | }; | |||||
| 127 | ||||||
| 128 | Reschedule Request re schedule = new Resch eduleReque st | |||||
| 129 | { | |||||
| 130 | Target = updateA ppointment | |||||
| 131 | }; | |||||
| 132 | ||||||
| 133 | Reschedule Response r escheduled = (Resche duleRespon se)_servic eProxy.Exe cute(resch edule); | |||||
| 134 | Console.Wr iteLine("R escheduled the secon d instance of the re curring ap pointment. "); | |||||
| 135 | ||||||
| 136 | #endregion Reschedul e an insta nce of rec urring app ointment | |||||
| 137 | //</snippe tReschedul eandCancel RecurringA ppointment Instance2> | |||||
| 138 | //<snippet Reschedule andCancelR ecurringAp pointmentI nstance3> | |||||
| 139 | ||||||
| 140 | #region Ca ncel an in stance of recurring appointmen t | |||||
| 141 | ||||||
| 142 | // Cancel the last i nstance of the appoi ntment. Th e status o f this app ointment | |||||
| 143 | // instanc e is set t o 'Cancele d'. You ca n view thi s appoinym ent instan ce under | |||||
| 144 | // the 'Al l Activiti es' view. | |||||
| 145 | SetStateRe quest appo intmentReq uest = new SetStateR equest | |||||
| 146 | { | |||||
| 147 | State = new Opti onSetValue ((int)Appo intmentSta te.Cancele d), | |||||
| 148 | Status = new Opt ionSetValu e(4), | |||||
| 149 | Entity Moniker = new Entity Reference( Appointmen t.EntityLo gicalName, | |||||
| 150 | ne w Guid(ind ividualApp ointments. Entities.S elect(x => (Appointm ent)x).Las t().Activi tyId.ToStr ing())) | |||||
| 151 | }; | |||||
| 152 | ||||||
| 153 | _servicePr oxy.Execut e(appointm entRequest ); | |||||
| 154 | Console.Wr iteLine("C anceled th e last ins tance of t he recurri ng appoint ment."); | |||||
| 155 | ||||||
| 156 | #endregion Cancel an instance of recurri ng appoint ment | |||||
| 157 | //</snippe tReschedul eandCancel RecurringA ppointment Instance3> | |||||
| 158 | //</snippe tReschedul eandCancel RecurringA ppointment Instance1> | |||||
| 159 | ||||||
| 160 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 161 | ||||||
| 162 | } | |||||
| 163 | } | |||||
| 164 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 165 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 166 | { | |||||
| 167 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 168 | thro w; | |||||
| 169 | } | |||||
| 170 | } | |||||
| 171 | ||||||
| 172 | // / <summary > | |||||
| 173 | // / This met hod create s any enti ty records that this sample re quires. | |||||
| 174 | // / Create a new recur ring appoi ntment. | |||||
| 175 | // / </summar y> | |||||
| 176 | pu blic void CreateRequ iredRecord s() | |||||
| 177 | { | |||||
| 178 | // Defin e an anony mous type to define the possib le recurre nce patter n values. | |||||
| 179 | var Recu rrencePatt ernTypes = new | |||||
| 180 | { | |||||
| 181 | Dail y = 0, | |||||
| 182 | Week ly = 1, | |||||
| 183 | Mont hly = 2, | |||||
| 184 | Year ly = 3 | |||||
| 185 | }; | |||||
| 186 | ||||||
| 187 | // Defin e an anony mous type to define the possib le values for days | |||||
| 188 | // of th e week | |||||
| 189 | var DayO fWeek = ne w | |||||
| 190 | { | |||||
| 191 | Sund ay = 0x01, | |||||
| 192 | Mond ay = 0x02, | |||||
| 193 | Tues day = 0x04 , | |||||
| 194 | Wedn esday = 0x 08, | |||||
| 195 | Thur sday = 0x1 0, | |||||
| 196 | Frid ay = 0x20, | |||||
| 197 | Satu rday = 0x4 0 | |||||
| 198 | }; | |||||
| 199 | ||||||
| 200 | // Defin e an anony mous type to define the possib le values | |||||
| 201 | // for t he recurre nce rule p attern end type. | |||||
| 202 | var Recu rrenceRule PatternEnd Type = new | |||||
| 203 | { | |||||
| 204 | NoEn dDate = 1, | |||||
| 205 | Occu rrences = 2, | |||||
| 206 | Patt ernEndDate = 3, | |||||
| 207 | }; | |||||
| 208 | ||||||
| 209 | // Creat e a new re curring ap pointment | |||||
| 210 | Recurrin gAppointme ntMaster n ewRecurrin gAppointme nt = | |||||
| 211 | new RecurringA ppointment Master | |||||
| 212 | { | |||||
| 213 | Subject = "Sample Re curring Ap pointment" , | |||||
| 214 | StartTime = DateTime .Now.AddHo urs(1), | |||||
| 215 | EndTime = DateTime.N ow.AddHour s(2), | |||||
| 216 | Recurrence PatternTyp e = new Op tionSetVal ue( | |||||
| 217 | Recurr encePatter nTypes.Wee kly), | |||||
| 218 | Interval = 1, | |||||
| 219 | DaysOfWeek Mask = Day OfWeek.Thu rsday, | |||||
| 220 | PatternSta rtDate = D ateTime.To day, | |||||
| 221 | Occurrence s = 5, | |||||
| 222 | PatternEnd Type = new OptionSet Value( | |||||
| 223 | Recurr enceRulePa tternEndTy pe.Occurre nces) | |||||
| 224 | ||||||
| 225 | }; | |||||
| 226 | ||||||
| 227 | _recurri ngAppointm entMasterI d = _servi ceProxy.Cr eate(newRe curringApp ointment); | |||||
| 228 | Console. WriteLine( "Created { 0}", newRe curringApp ointment.S ubject); | |||||
| 229 | ||||||
| 230 | return; | |||||
| 231 | } | |||||
| 232 | ||||||
| 233 | // / <summary > | |||||
| 234 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 235 | // / <param n ame="promp t">Indicat es whether to prompt the user to delete | |||||
| 236 | // / the reco rds create d in this sample.</p aram> | |||||
| 237 | // / </summar y> | |||||
| 238 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 239 | { | |||||
| 240 | bool del eteRecords = true; | |||||
| 241 | ||||||
| 242 | if (prom pt) | |||||
| 243 | { | |||||
| 244 | Cons ole.WriteL ine("\nDo you want t hese entit y records to be dele ted? (y/n) "); | |||||
| 245 | Stri ng answer = Console. ReadLine() ; | |||||
| 246 | ||||||
| 247 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" )); | |||||
| 248 | } | |||||
| 249 | ||||||
| 250 | if (dele teRecords) | |||||
| 251 | { | |||||
| 252 | _ser viceProxy. Delete(Rec urringAppo intmentMas ter.Entity LogicalNam e, | |||||
| 253 | _recurring Appointmen tMasterId) ; | |||||
| 254 | ||||||
| 255 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 256 | } | |||||
| 257 | } | |||||
| 258 | ||||||
| 259 | #e ndregion H ow To Samp le Code | |||||
| 260 | ||||||
| 261 | #r egion Main | |||||
| 262 | // / <summary > | |||||
| 263 | // / Standard Main() me thod used by most SD K samples. | |||||
| 264 | // / </summar y> | |||||
| 265 | // / <param n ame="args" ></param> | |||||
| 266 | st atic publi c void Mai n(string[] args) | |||||
| 267 | { | |||||
| 268 | try | |||||
| 269 | { | |||||
| 270 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 271 | // c redentials from the user. | |||||
| 272 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 273 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 274 | ||||||
| 275 | Conv ertAnAppoi ntmenttoRe curringApp ointment a pp = new C onvertAnAp pointmentt oRecurring Appointmen t(); | |||||
| 276 | app. Run(config , true); | |||||
| 277 | } | |||||
| 278 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 279 | { | |||||
| 280 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 281 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 282 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 283 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 284 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 285 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 286 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 287 | } | |||||
| 288 | catch (S ystem.Time outExcepti on ex) | |||||
| 289 | { | |||||
| 290 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 291 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 292 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 293 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 294 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 295 | } | |||||
| 296 | catch (S ystem.Exce ption ex) | |||||
| 297 | { | |||||
| 298 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 299 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 300 | ||||||
| 301 | // D isplay the details o f the inne r exceptio n. | |||||
| 302 | if ( ex.InnerEx ception != null) | |||||
| 303 | { | |||||
| 304 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 305 | ||||||
| 306 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e | |||||
| 307 | = ex.I nnerExcept ion | |||||
| 308 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 309 | if (fe != null) | |||||
| 310 | { | |||||
| 311 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 312 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 313 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 314 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 315 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 316 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 317 | } | |||||
| 318 | } | |||||
| 319 | } | |||||
| 320 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 321 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 322 | ||||||
| 323 | ||||||
| 324 | finally | |||||
| 325 | { | |||||
| 326 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 327 | Cons ole.ReadLi ne(); | |||||
| 328 | } | |||||
| 329 | ||||||
| 330 | } | |||||
| 331 | #e ndregion M ain | |||||
| 332 | } | |||||
| 333 | } | |||||
| 334 | //</snippe tReschedul eandCancel RecurringA ppointment Instance> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.