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\ScheduleAndAppointment | ScheduleResource.cs | Tue Dec 20 19:51:43 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 | 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 right s reserved . | |||||
| 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 ScheduleRe source> | |||||
| 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 schedul e a resour ce. | |||||
| 39 | /// </ summary> | |||||
| 40 | public class Sch eduleResou rce | |||||
| 41 | { | |||||
| 42 | #r egion Clas s Level Me mbers | |||||
| 43 | ||||||
| 44 | // / <summary > | |||||
| 45 | // / Stores t he organiz ation serv ice proxy. | |||||
| 46 | // / </summar y> | |||||
| 47 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 48 | ||||||
| 49 | // Define th e IDs need ed for thi s sample. | |||||
| 50 | pu blic Guid _vanId; | |||||
| 51 | pu blic Guid _groupId; | |||||
| 52 | pu blic Guid _specId; | |||||
| 53 | pu blic Guid _plumberSe rviceId; | |||||
| 54 | ||||||
| 55 | #e ndregion C lass Level Members | |||||
| 56 | ||||||
| 57 | #r egion How To Sample Code | |||||
| 58 | // / <summary > | |||||
| 59 | // / Create a nd configu re the org anization service pr oxy. | |||||
| 60 | // / Initiate the metho d to creat e any data that this sample re quires. | |||||
| 61 | // / Schedule a resourc e. | |||||
| 62 | // / Optional ly delete any entity records t hat were c reated for this samp le. | |||||
| 63 | // / </summar y> | |||||
| 64 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 65 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 66 | // / created entities.< /param> | |||||
| 67 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 68 | { | |||||
| 69 | try | |||||
| 70 | { | |||||
| 71 | ||||||
| 72 | // C onnect to the Organi zation ser vice. | |||||
| 73 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 74 | 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 )) | |||||
| 75 | { | |||||
| 76 | // This st atement is required to enable early-boun d type sup port. | |||||
| 77 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 78 | ||||||
| 79 | // Call th e method t o create a ny data th at this sa mple requi res. | |||||
| 80 | CreateRequ iredRecord s(); | |||||
| 81 | ||||||
| 82 | //<snippet ScheduleRe source1> | |||||
| 83 | // Create the van re quired res ource obje ct. | |||||
| 84 | RequiredRe source van Req = new RequiredRe source | |||||
| 85 | { | |||||
| 86 | Resour ceId = _va nId, | |||||
| 87 | Resour ceSpecId = _specId | |||||
| 88 | }; | |||||
| 89 | ||||||
| 90 | // Create the appoin tment requ est. | |||||
| 91 | Appointmen tRequest a ppointment Req = new Appointmen tRequest | |||||
| 92 | { | |||||
| 93 | Requir edResource s = new Re quiredReso urce[] { v anReq }, | |||||
| 94 | Direct ion = Sear chDirectio n.Backward , | |||||
| 95 | Durati on = 60, | |||||
| 96 | Number OfResults = 10, | |||||
| 97 | Servic eId = _plu mberServic eId, | |||||
| 98 | // The search wi ndow descr ibes the t ime when t he resouce can be sc heduled. | |||||
| 99 | // It must be se t. | |||||
| 100 | Search WindowStar t = DateTi me.Now.ToU niversalTi me(), | |||||
| 101 | Search WindowEnd = DateTime .Now.AddDa ys(7).ToUn iversalTim e(), | |||||
| 102 | UserTi meZoneCode = 1 | |||||
| 103 | }; | |||||
| 104 | ||||||
| 105 | // Verify whether th ere are op enings ava ilable to schedule t he appoint ment using this reso urce | |||||
| 106 | SearchRequ est search = new Sea rchRequest | |||||
| 107 | { | |||||
| 108 | Appoin tmentReque st = appoi ntmentReq | |||||
| 109 | }; | |||||
| 110 | SearchResp onse searc hed = (Sea rchRespons e)_service Proxy.Exec ute(search ); | |||||
| 111 | ||||||
| 112 | if (search ed.SearchR esults.Pro posals.Len gth > 0) | |||||
| 113 | { | |||||
| 114 | Consol e.WriteLin e("Opening s are avai lable to s chedule th e resource ."); | |||||
| 115 | } | |||||
| 116 | //</snippe tScheduleR esource1> | |||||
| 117 | ||||||
| 118 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 119 | } | |||||
| 120 | } | |||||
| 121 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 122 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 123 | { | |||||
| 124 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 125 | thro w; | |||||
| 126 | } | |||||
| 127 | } | |||||
| 128 | ||||||
| 129 | // / <summary > | |||||
| 130 | // / This met hod create s any enti ty records that this sample re quires. | |||||
| 131 | // / </summar y> | |||||
| 132 | pu blic void CreateRequ iredRecord s() | |||||
| 133 | { | |||||
| 134 | // Get t he current user's in formation. | |||||
| 135 | WhoAmIRe quest user Request = new WhoAmI Request(); | |||||
| 136 | WhoAmIRe sponse use rResponse = (WhoAmIR esponse)_s erviceProx y.Execute( userReques t); | |||||
| 137 | ||||||
| 138 | // Creat e the van resource. | |||||
| 139 | Equipmen t van = ne w Equipmen t | |||||
| 140 | { | |||||
| 141 | Name = "Van 1" , | |||||
| 142 | Time ZoneCode = 1, | |||||
| 143 | Busi nessUnitId = new Ent ityReferen ce(Busines sUnit.Enti tyLogicalN ame, userR esponse.Bu sinessUnit Id) | |||||
| 144 | }; | |||||
| 145 | ||||||
| 146 | _vanId = _serviceP roxy.Creat e(van); | |||||
| 147 | ||||||
| 148 | Console. WriteLine( "Created a sample eq uipment: { 0}.", van. Name); | |||||
| 149 | ||||||
| 150 | // Creat e the cont raints for creating the plumbe r resource group | |||||
| 151 | System.T ext.String Builder bu ilder = ne w System.T ext.String Builder("< Constraint s>"); | |||||
| 152 | builder. Append("<C onstraint> "); | |||||
| 153 | builder. Append("<E xpression> "); | |||||
| 154 | builder. Append("<B ody>resour ce[\"Id\"] == "); | |||||
| 155 | builder. Append(use rResponse. UserId.ToS tring("B") ); | |||||
| 156 | builder. Append(" | | resource [\"Id\"] = = "); | |||||
| 157 | builder. Append(_va nId.ToStri ng("B")); | |||||
| 158 | builder. Append("</ Body>"); | |||||
| 159 | builder. Append("<P arameters> "); | |||||
| 160 | builder. Append("<P arameter n ame=\"reso urce\" />" ); | |||||
| 161 | builder. Append("</ Parameters >"); | |||||
| 162 | builder. Append("</ Expression >"); | |||||
| 163 | builder. Append("</ Constraint >"); | |||||
| 164 | builder. Append("</ Constraint s>"); | |||||
| 165 | ||||||
| 166 | // Defin e an anony mous type to define the possib le constra int based group type code valu es. | |||||
| 167 | var Cons traintBase dGroupType Code = new | |||||
| 168 | { | |||||
| 169 | Stat ic = 0, | |||||
| 170 | Dyna mic = 1, | |||||
| 171 | Impl icit = 2 | |||||
| 172 | }; | |||||
| 173 | // Creat e the plum ber resour ce group. | |||||
| 174 | Constrai ntBasedGro up group = new Const raintBased Group | |||||
| 175 | { | |||||
| 176 | Busi nessUnitId = new Ent ityReferen ce(Busines sUnit.Enti tyLogicalN ame, userR esponse.Bu sinessUnit Id), | |||||
| 177 | Name = "Plumbe r with Van 1", | |||||
| 178 | Cons traints = builder.To String(), | |||||
| 179 | Grou pTypeCode = new Opti onSetValue (Constrain tBasedGrou pTypeCode. Static), | |||||
| 180 | }; | |||||
| 181 | ||||||
| 182 | _groupId = _servic eProxy.Cre ate(group) ; | |||||
| 183 | ||||||
| 184 | Console. WriteLine( "Created a sample re source gro up: {0}.", group.Nam e); | |||||
| 185 | ||||||
| 186 | // Creat e the reso urce speci fication. | |||||
| 187 | Resource Spec spec = new Reso urceSpec | |||||
| 188 | { | |||||
| 189 | Busi nessUnitId = new Ent ityReferen ce(Busines sUnit.Enti tyLogicalN ame, userR esponse.Bu sinessUnit Id), | |||||
| 190 | Obje ctiveExpre ssion = @" | |||||
| 191 | <Expressio n> | |||||
| 192 | <B ody>udf "" Random""(f actory,res ource,appo intment,re quest,left offset,rig htoffset)< /Body> | |||||
| 193 | <P arameters> | |||||
| 194 | <Par ameter nam e=""factor y"" /> | |||||
| 195 | <Par ameter nam e=""resour ce"" /> | |||||
| 196 | <Par ameter nam e=""appoin tment"" /> | |||||
| 197 | <Par ameter nam e=""reques t"" /> | |||||
| 198 | <Par ameter nam e=""leftof fset"" /> | |||||
| 199 | <Par ameter nam e=""righto ffset"" /> | |||||
| 200 | </ Parameters > | |||||
| 201 | <P roperties Evaluation Interval=" "P0D"" eva luationcos t=""0"" /> | |||||
| 202 | </Expressi on>", | |||||
| 203 | Requ iredCount = 1, | |||||
| 204 | Name = "Test S pec", | |||||
| 205 | Grou pObjectId = _groupId | |||||
| 206 | }; | |||||
| 207 | _specId = _service Proxy.Crea te(spec); | |||||
| 208 | ||||||
| 209 | // Creat e the plum ber requir ed resourc e object. | |||||
| 210 | Required Resource p lumberReq = new Requ iredResour ce | |||||
| 211 | { | |||||
| 212 | Reso urceId = u serRespons e.UserId, // assum e current user is th e plumber | |||||
| 213 | Reso urceSpecId = _specId | |||||
| 214 | }; | |||||
| 215 | ||||||
| 216 | ||||||
| 217 | // Creat e the serv ice for th e equipmen t. | |||||
| 218 | Service plumberSer vice = new Service | |||||
| 219 | { | |||||
| 220 | Name = "Plumbe r 1", | |||||
| 221 | Dura tion = 60, | |||||
| 222 | Init ialStatusC ode = new OptionSetV alue(1), | |||||
| 223 | Gran ularity = "FREQ=MINU TELY;INTER VAL=15;", | |||||
| 224 | Reso urceSpecId = new Ent ityReferen ce(Resourc eSpec.Enti tyLogicalN ame, _spec Id) | |||||
| 225 | }; | |||||
| 226 | ||||||
| 227 | _plumber ServiceId = _service Proxy.Crea te(plumber Service); | |||||
| 228 | ||||||
| 229 | Console. WriteLine( "Created a sample se rvice for the equipm ent: {0}." , plumberS ervice.Nam e); | |||||
| 230 | } | |||||
| 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(Ser vice.Entit yLogicalNa me, _plumb erServiceI d); | |||||
| 253 | _ser viceProxy. Delete(Equ ipment.Ent ityLogical Name, _van Id); | |||||
| 254 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 255 | } | |||||
| 256 | } | |||||
| 257 | ||||||
| 258 | #e ndregion H ow To Samp le Code | |||||
| 259 | ||||||
| 260 | #r egion Main | |||||
| 261 | // / <summary > | |||||
| 262 | // / Standard Main() me thod used by most SD K samples. | |||||
| 263 | // / </summar y> | |||||
| 264 | // / <param n ame="args" ></param> | |||||
| 265 | st atic publi c void Mai n(string[] args) | |||||
| 266 | { | |||||
| 267 | try | |||||
| 268 | { | |||||
| 269 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 270 | // c redentials from the user. | |||||
| 271 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 272 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 273 | ||||||
| 274 | Sche duleResour ce app = n ew Schedul eResource( ); | |||||
| 275 | app. Run(config , true); | |||||
| 276 | } | |||||
| 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 | finally | |||||
| 324 | { | |||||
| 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 tScheduleR esource> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.