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\Service | CloseAnIncident.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 | 277 |
| 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 | ||||||
| 17 | //<snippet CloseAnInc ident> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Service Model; | |||||
| 20 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 21 | using Micr osoft.Xrm. Sdk; | |||||
| 22 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 23 | ||||||
| 24 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 25 | { | |||||
| 26 | public class Clo seAnIncide nt | |||||
| 27 | { | |||||
| 28 | #r egion Clas s Level Me mbers | |||||
| 29 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 30 | pr ivate Guid _incident Id; | |||||
| 31 | pr ivate Guid _appointm entId; | |||||
| 32 | pr ivate Guid _accountI d; | |||||
| 33 | #e ndregion | |||||
| 34 | ||||||
| 35 | #r egion How To Sample Code | |||||
| 36 | ||||||
| 37 | pu blic void Run(Server Connection .Configura tion serve rConfig, | |||||
| 38 | bool pro mptforDele te) | |||||
| 39 | { | |||||
| 40 | using (_ servicePro xy = new O rganizatio nServicePr oxy(server Config.Org anizationU ri, server Config.Hom eRealmUri, | |||||
| 41 | s erverConfi g.Credenti als, serve rConfig.De viceCreden tials)) | |||||
| 42 | { | |||||
| 43 | // T his statem ent is req uired to e nable earl y bound ty pe support . | |||||
| 44 | _ser viceProxy. EnableProx yTypes(); | |||||
| 45 | Crea teRequired Records(); | |||||
| 46 | RunI ncidentMan ipulation( ); | |||||
| 47 | Dele teRecords( promptforD elete); | |||||
| 48 | } | |||||
| 49 | } | |||||
| 50 | ||||||
| 51 | pr ivate void RunIncide ntManipula tion() | |||||
| 52 | { | |||||
| 53 | Console. WriteLine( "=== Creat ing and Cl osing an I ncident (C ase) ===") ; | |||||
| 54 | ||||||
| 55 | // Creat e an incid ent. | |||||
| 56 | var inci dent = new Incident | |||||
| 57 | { | |||||
| 58 | Cust omerId = n ew EntityR eference(A ccount.Ent ityLogical Name, _acc ountId), | |||||
| 59 | Titl e = "Sampl e Incident " | |||||
| 60 | }; | |||||
| 61 | ||||||
| 62 | _inciden tId = _ser viceProxy. Create(inc ident); | |||||
| 63 | NotifyEn tityCreate d(Incident .EntityLog icalName, _incidentI d); | |||||
| 64 | ||||||
| 65 | // C reate a 30 -minute ap pointment regarding the incide nt. | |||||
| 66 | var appo intment = new Appoin tment | |||||
| 67 | { | |||||
| 68 | Sche duledStart = DateTim e.Now, | |||||
| 69 | Sche duledEnd = DateTime. Now.Add(ne w TimeSpan (0, 30, 0) ), | |||||
| 70 | Subj ect = "Sam ple 30-min ute Appoin tment", | |||||
| 71 | Rega rdingObjec tId = new EntityRefe rence(Inci dent.Entit yLogicalNa me, | |||||
| 72 | _incidentI d) | |||||
| 73 | }; | |||||
| 74 | ||||||
| 75 | _appoint mentId = _ servicePro xy.Create( appointmen t); | |||||
| 76 | NotifyEn tityCreate d(Appointm ent.Entity LogicalNam e, _appoin tmentId); | |||||
| 77 | ||||||
| 78 | // Show th e time spe nt on the incident b efore clos ing the ap pointment. | |||||
| 79 | NotifyTi meSpentOnI ncident(); | |||||
| 80 | // Check t he validit y of the s tate trans ition to c losed on t he inciden t. | |||||
| 81 | NotifyVa lidityOfIn cidentSolv edStateCha nge(); | |||||
| 82 | //<snipp etCloseAnI ncident1> | |||||
| 83 | // Close the appoi ntment. | |||||
| 84 | var setA ppointment StateReq = new SetSt ateRequest | |||||
| 85 | { | |||||
| 86 | Enti tyMoniker = new Enti tyReferenc e(Appointm ent.Entity LogicalNam e, | |||||
| 87 | _appointme ntId), | |||||
| 88 | Stat e = new Op tionSetVal ue((int)Ap pointmentS tate.Compl eted), | |||||
| 89 | Stat us = new O ptionSetVa lue((int)a ppointment _statuscod e.Complete d) | |||||
| 90 | }; | |||||
| 91 | ||||||
| 92 | _service Proxy.Exec ute(setApp ointmentSt ateReq); | |||||
| 93 | ||||||
| 94 | Console. WriteLine( " Appoint ment state set to co mpleted.") ; | |||||
| 95 | //</snip petCloseAn Incident1> | |||||
| 96 | ||||||
| 97 | // Show the time s pent on th e incident after clo sing the a ppointment . | |||||
| 98 | NotifyTi meSpentOnI ncident(); | |||||
| 99 | // Check t he validit y of the s tate trans ition to c losed agai n. | |||||
| 100 | NotifyVa lidityOfIn cidentSolv edStateCha nge(); | |||||
| 101 | ||||||
| 102 | // C reate the incident's resolutio n. | |||||
| 103 | var inci dentResolu tion = new IncidentR esolution | |||||
| 104 | { | |||||
| 105 | Subj ect = "Res olved Samp le Inciden t", | |||||
| 106 | Inci dentId = n ew EntityR eference(I ncident.En tityLogica lName, _in cidentId) | |||||
| 107 | }; | |||||
| 108 | ||||||
| 109 | //<snipp etCloseAnI ncident2> | |||||
| 110 | // Close the incid ent with t he resolut ion. | |||||
| 111 | var clos eIncidentR equest = n ew CloseIn cidentRequ est | |||||
| 112 | { | |||||
| 113 | Inci dentResolu tion = inc identResol ution, | |||||
| 114 | Stat us = new O ptionSetVa lue((int)i ncident_st atuscode.P roblemSolv ed) | |||||
| 115 | }; | |||||
| 116 | ||||||
| 117 | _service Proxy.Exec ute(closeI ncidentReq uest); | |||||
| 118 | ||||||
| 119 | Console. WriteLine( " Inciden t closed." ); | |||||
| 120 | //</snip petCloseAn Incident2> | |||||
| 121 | } | |||||
| 122 | ||||||
| 123 | pr ivate void NotifyVal idityOfInc identSolve dStateChan ge() | |||||
| 124 | { | |||||
| 125 | //<snipp etCloseAnI ncident3> | |||||
| 126 | // Valid ate the st ate transi tion. | |||||
| 127 | var isVa lidRequest = new IsV alidStateT ransitionR equest | |||||
| 128 | { | |||||
| 129 | Enti ty = new E ntityRefer ence(Incid ent.Entity LogicalNam e, _incide ntId), | |||||
| 130 | NewS tate = Inc identState .Resolved. ToString() , | |||||
| 131 | NewS tatus = (i nt)inciden t_statusco de.Problem Solved | |||||
| 132 | }; | |||||
| 133 | ||||||
| 134 | var resp onse = | |||||
| 135 | (IsV alidStateT ransitionR esponse)_s erviceProx y.Execute( isValidReq uest); | |||||
| 136 | var isVa lidString = response .IsValid ? "is valid " : "is no t valid"; | |||||
| 137 | Console. WriteLine( " The tra nsition to a complet ed status reason {0} .", | |||||
| 138 | isVa lidString) ; | |||||
| 139 | //</snip petCloseAn Incident3> | |||||
| 140 | } | |||||
| 141 | ||||||
| 142 | pr ivate void NotifyTim eSpentOnIn cident() | |||||
| 143 | { | |||||
| 144 | //<snipp etCloseAnI ncident4> | |||||
| 145 | // Calcu late the t otal numbe r of minut es spent o n an incid ent. | |||||
| 146 | var calc ulateReque stTime = n ew Calcula teTotalTim eIncidentR equest | |||||
| 147 | { | |||||
| 148 | Inci dentId = _ incidentId | |||||
| 149 | }; | |||||
| 150 | var resp onse = | |||||
| 151 | (Cal culateTota lTimeIncid entRespons e)_service Proxy.Exec ute(calcul ateRequest Time); | |||||
| 152 | ||||||
| 153 | Console. WriteLine( " {0} min utes have been spent on the in cident.", | |||||
| 154 | resp onse.Total Time); | |||||
| 155 | //</snip petCloseAn Incident4> | |||||
| 156 | } | |||||
| 157 | ||||||
| 158 | pr ivate void NotifyEnt ityCreated (String en tityName, Guid entit yId) | |||||
| 159 | { | |||||
| 160 | Console. WriteLine( " {0} cre ated with GUID {{{1} }}", | |||||
| 161 | enti tyName, en tityId); | |||||
| 162 | } | |||||
| 163 | ||||||
| 164 | pr ivate void CreateReq uiredRecor ds() | |||||
| 165 | { | |||||
| 166 | // Creat e an accou nt to act as a custo mer for th e incident . | |||||
| 167 | var acco unt = new Account | |||||
| 168 | { | |||||
| 169 | Name = "Litwar e, Inc.", | |||||
| 170 | Addr ess1_State OrProvince = "Colora do" | |||||
| 171 | }; | |||||
| 172 | _account Id = (_ser viceProxy. Create(acc ount)); | |||||
| 173 | } | |||||
| 174 | ||||||
| 175 | pr ivate void DeleteRec ords(bool prompt) | |||||
| 176 | { | |||||
| 177 | bool toB eDeleted = true; | |||||
| 178 | ||||||
| 179 | if (prom pt) | |||||
| 180 | { | |||||
| 181 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 182 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 183 | Stri ng answer = Console. ReadLine() ; | |||||
| 184 | if ( answer.Sta rtsWith("y ") || | |||||
| 185 | answer.Sta rtsWith("Y ") || | |||||
| 186 | answer == String.Emp ty) | |||||
| 187 | { | |||||
| 188 | toBeDelete d = true; | |||||
| 189 | } | |||||
| 190 | else | |||||
| 191 | { | |||||
| 192 | toBeDelete d = false; | |||||
| 193 | } | |||||
| 194 | } | |||||
| 195 | ||||||
| 196 | if (toBe Deleted) | |||||
| 197 | { | |||||
| 198 | // T he account is all th at needs t o be delet ed. Every thing else will be | |||||
| 199 | // d eleted wit h it. | |||||
| 200 | _ser viceProxy. Delete(Acc ount.Entit yLogicalNa me, _accou ntId); | |||||
| 201 | } | |||||
| 202 | } | |||||
| 203 | ||||||
| 204 | #e ndregion H ow To Samp le Code | |||||
| 205 | ||||||
| 206 | #r egion Main method | |||||
| 207 | ||||||
| 208 | // / <summary > | |||||
| 209 | // / Standard Main() me thod used by most SD K samples. | |||||
| 210 | // / </summar y> | |||||
| 211 | // / <param n ame="args" ></param> | |||||
| 212 | st atic publi c void Mai n(string[] args) | |||||
| 213 | { | |||||
| 214 | try | |||||
| 215 | { | |||||
| 216 | // O btain the target org anization' s web addr ess and cl ient logon | |||||
| 217 | // c redentials from the user. | |||||
| 218 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 219 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 220 | ||||||
| 221 | var app = new CloseAnInc ident(); | |||||
| 222 | app. Run(config , true); | |||||
| 223 | } | |||||
| 224 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 225 | { | |||||
| 226 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 227 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 228 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 229 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 230 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 231 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 232 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 233 | } | |||||
| 234 | catch (S ystem.Time outExcepti on ex) | |||||
| 235 | { | |||||
| 236 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 237 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 238 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 239 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 240 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 241 | } | |||||
| 242 | catch (S ystem.Exce ption ex) | |||||
| 243 | { | |||||
| 244 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 245 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 246 | ||||||
| 247 | // D isplay the details o f the inne r exceptio n. | |||||
| 248 | if ( ex.InnerEx ception != null) | |||||
| 249 | { | |||||
| 250 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 251 | ||||||
| 252 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 253 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 254 | if (fe != null) | |||||
| 255 | { | |||||
| 256 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 257 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 258 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 259 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 260 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 261 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 262 | } | |||||
| 263 | } | |||||
| 264 | } | |||||
| 265 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 266 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 267 | ||||||
| 268 | finally | |||||
| 269 | { | |||||
| 270 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 271 | Cons ole.ReadLi ne(); | |||||
| 272 | } | |||||
| 273 | } | |||||
| 274 | #e ndregion M ain method | |||||
| 275 | } | |||||
| 276 | } | |||||
| 277 | //</snippe tCloseAnIn cident> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.