Produced by Araxis Merge on 2/1/2017 2:56:30 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\DataManagement\Auditing | Program.cs | Tue Dec 20 19:51:43 2016 UTC |
| 2 | Wed Feb 1 19:56:30 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 445 |
| 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 Auditing> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Service Model; | |||||
| 19 | using Syst em.Collect ions.Gener ic; | |||||
| 20 | using Syst em.Linq; | |||||
| 21 | ||||||
| 22 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 23 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 24 | using Micr osoft.Xrm. Sdk; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 26 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 27 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 28 | using Micr osoft.Xrm. Sdk.Metada ta; | |||||
| 29 | ||||||
| 30 | // These n amespaces are found in the Mic rosoft.Crm .Sdk.Proxy .dll assem bly | |||||
| 31 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 32 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 33 | ||||||
| 34 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 35 | { | |||||
| 36 | public class Aud iting | |||||
| 37 | { | |||||
| 38 | #r egion Clas s Level Me mbers | |||||
| 39 | ||||||
| 40 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 41 | pr ivate IOrg anizationS ervice _se rvice; | |||||
| 42 | ||||||
| 43 | pr ivate Guid _newAccou ntId; | |||||
| 44 | ||||||
| 45 | #e ndregion C lass Level Members | |||||
| 46 | ||||||
| 47 | #r egion How To Sample Code | |||||
| 48 | // / <summary > | |||||
| 49 | // / This met hod first connects t o the orga nization s ervice. Ne xt, auditi ng | |||||
| 50 | // / is enabl ed on the organizati on and an account en tity. The account re cord | |||||
| 51 | // / is updat ed and the audit his tory print ed out. | |||||
| 52 | // / </summar y> | |||||
| 53 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 54 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 55 | // / created entities.< /param> | |||||
| 56 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 57 | { | |||||
| 58 | using (_ servicePro xy = new O rganizatio nServicePr oxy(server Config.Org anizationU ri, server Config.Hom eRealmUri, serverCon fig.Creden tials, ser verConfig. DeviceCred entials)) | |||||
| 59 | { | |||||
| 60 | // E nable earl y-bound ty pe support . | |||||
| 61 | _ser viceProxy. EnableProx yTypes(); | |||||
| 62 | ||||||
| 63 | // Y ou can acc ess the se rvice thro ugh the pr oxy, but t his sample uses the interface instead. | |||||
| 64 | _ser vice = _se rviceProxy ; | |||||
| 65 | ||||||
| 66 | #reg ion Enable Auditing for an Acc ount | |||||
| 67 | //<s nippetAudi ting1> | |||||
| 68 | Cons ole.WriteL ine("Enabl ing auditi ng on the organizati on and acc ount entit ies."); | |||||
| 69 | ||||||
| 70 | // E nable audi ting on th e organiza tion. | |||||
| 71 | // F irst, get the organi zation's I D from the system us er record. | |||||
| 72 | Guid orgId = ( (WhoAmIRes ponse)_ser vice.Execu te(new Who AmIRequest ())).Organ izationId; | |||||
| 73 | ||||||
| 74 | // N ext, retri eve the or ganization 's record. | |||||
| 75 | Orga nization o rg = _serv ice.Retrie ve(Organiz ation.Enti tyLogicalN ame, orgId , | |||||
| 76 | new Column Set(new st ring[] { " organizati onid", "is auditenabl ed" })) as Organizat ion; | |||||
| 77 | ||||||
| 78 | // F inally, en able audit ing on the organizat ion. | |||||
| 79 | bool organizat ionAuditin gFlag = or g.IsAuditE nabled.Val ue; | |||||
| 80 | org. IsAuditEna bled = tru e; | |||||
| 81 | _ser vice.Updat e(org); | |||||
| 82 | ||||||
| 83 | // E nable audi ting on ac count enti ties. | |||||
| 84 | bool accountAu ditingFlag = EnableE ntityAudit ing(Accoun t.EntityLo gicalName, true); | |||||
| 85 | //</ snippetAud iting1> | |||||
| 86 | #end region Ena ble Auditi ng for an Account | |||||
| 87 | ||||||
| 88 | Crea teRequired Records(); | |||||
| 89 | ||||||
| 90 | #reg ion Retrie ve the Rec ord Change History | |||||
| 91 | Cons ole.WriteL ine("Retri eving the account ch ange histo ry.\n"); | |||||
| 92 | //<s nippetAudi ting5> | |||||
| 93 | // R etrieve th e audit hi story for the accoun t and disp lay it. | |||||
| 94 | Retr ieveRecord ChangeHist oryRequest changeReq uest = new RetrieveR ecordChang eHistoryRe quest(); | |||||
| 95 | chan geRequest. Target = n ew EntityR eference(A ccount.Ent ityLogical Name, _new AccountId) ; | |||||
| 96 | ||||||
| 97 | Retr ieveRecord ChangeHist oryRespons e changeRe sponse = | |||||
| 98 | (RetrieveR ecordChang eHistoryRe sponse)_se rvice.Exec ute(change Request); | |||||
| 99 | ||||||
| 100 | Audi tDetailCol lection de tails = ch angeRespon se.AuditDe tailCollec tion; | |||||
| 101 | //</ snippetAud iting5> | |||||
| 102 | ||||||
| 103 | fore ach (Attri buteAuditD etail deta il in deta ils.AuditD etails) | |||||
| 104 | { | |||||
| 105 | // Display some of t he detail informatio n in each audit reco rd. | |||||
| 106 | DisplayAud itDetails( detail); | |||||
| 107 | } | |||||
| 108 | #end region Ret rieve the Record Cha nge Histor y | |||||
| 109 | ||||||
| 110 | #reg ion Retrie ve the Att ribute Cha nge Histor y | |||||
| 111 | ||||||
| 112 | //<s nippetAudi ting7> | |||||
| 113 | // U pdate the Telephone1 attribute in the Ac count enti ty record. | |||||
| 114 | Acco unt accoun tToUpdate = new Acco unt(); | |||||
| 115 | acco untToUpdat e.AccountI d = _newAc countId; | |||||
| 116 | acco untToUpdat e.Telephon e1 = "123- 555-5555"; | |||||
| 117 | _ser viceProxy. Update(acc ountToUpda te); | |||||
| 118 | Cons ole.WriteL ine("Updat ed the Tel ephone1 fi eld in the Account e ntity."); | |||||
| 119 | ||||||
| 120 | // R etrieve th e attribut e change h istory. | |||||
| 121 | Cons ole.WriteL ine("Retri eving the attribute change his tory for T elephone1. "); | |||||
| 122 | ||||||
| 123 | var attributeC hangeHisto ryRequest = new Retr ieveAttrib uteChangeH istoryRequ est | |||||
| 124 | { | |||||
| 125 | Target = n ew EntityR eference( | |||||
| 126 | Accoun t.EntityLo gicalName, _newAccou ntId), | |||||
| 127 | AttributeL ogicalName = "teleph one1" | |||||
| 128 | }; | |||||
| 129 | ||||||
| 130 | var attributeC hangeHisto ryResponse = | |||||
| 131 | (RetrieveA ttributeCh angeHistor yResponse) _service.E xecute(att ributeChan geHistoryR equest); | |||||
| 132 | ||||||
| 133 | // D isplay the attribute change hi story. | |||||
| 134 | deta ils = attr ibuteChang eHistoryRe sponse.Aud itDetailCo llection; | |||||
| 135 | //</ snippetAud iting7> | |||||
| 136 | ||||||
| 137 | fore ach (var d etail in d etails.Aud itDetails) | |||||
| 138 | { | |||||
| 139 | DisplayAud itDetails( detail); | |||||
| 140 | } | |||||
| 141 | ||||||
| 142 | // S ave an Aud it record ID for lat er use. | |||||
| 143 | Guid auditSamp leId = det ails.Audit Details.Fi rst().Audi tRecord.Id ; | |||||
| 144 | #end region Ret rieve the Attribute Change His tory | |||||
| 145 | ||||||
| 146 | #reg ion Retrie ve the Aud it Details | |||||
| 147 | //<s nippetAudi ting8> | |||||
| 148 | Cons ole.WriteL ine("Retri eving audi t details for an aud it record. "); | |||||
| 149 | ||||||
| 150 | // R etrieve th e audit de tails and display th em. | |||||
| 151 | var auditDetai lsRequest = new Retr ieveAuditD etailsRequ est | |||||
| 152 | { | |||||
| 153 | AuditId = auditSampl eId | |||||
| 154 | }; | |||||
| 155 | ||||||
| 156 | var auditDetai lsResponse = | |||||
| 157 | (RetrieveA uditDetail sResponse) _service.E xecute(aud itDetailsR equest); | |||||
| 158 | //</ snippetAud iting8> | |||||
| 159 | Disp layAuditDe tails(audi tDetailsRe sponse.Aud itDetail); | |||||
| 160 | ||||||
| 161 | #end region Ret rieve the Audit Deta ils | |||||
| 162 | ||||||
| 163 | #reg ion Revert Auditing | |||||
| 164 | // S et the org anization and accoun t auditing flags bac k to the o ld values | |||||
| 165 | org. IsAuditEna bled = org anizationA uditingFla g; | |||||
| 166 | _ser vice.Updat e(org); | |||||
| 167 | ||||||
| 168 | Enab leEntityAu diting(Acc ount.Entit yLogicalNa me, accoun tAuditingF lag); | |||||
| 169 | ||||||
| 170 | #end region Rev ert Auditi ng | |||||
| 171 | ||||||
| 172 | Dele teRequired Records(pr omptforDel ete); | |||||
| 173 | } | |||||
| 174 | } | |||||
| 175 | ||||||
| 176 | #e ndregion H ow To Samp le Code | |||||
| 177 | ||||||
| 178 | #r egion Clas s methods | |||||
| 179 | // / <summary > | |||||
| 180 | // / Displays audit cha nge histor y details on the con sole. | |||||
| 181 | // / </summar y> | |||||
| 182 | // / <param n ame="detai l"></param > | |||||
| 183 | // <snippetAu diting2> | |||||
| 184 | pr ivate stat ic void Di splayAudit Details(Au ditDetail detail) | |||||
| 185 | { | |||||
| 186 | // Write out some of the cha nge histor y informat ion in the audit rec ord. | |||||
| 187 | Audit re cord = (Au dit)detail .AuditReco rd; | |||||
| 188 | ||||||
| 189 | Console. WriteLine( "\nAudit r ecord crea ted on: {0 }", record .CreatedOn .Value.ToL ocalTime() ); | |||||
| 190 | Console. WriteLine( "Entity: { 0}, Action : {1}, Ope ration: {2 }", | |||||
| 191 | reco rd.ObjectI d.LogicalN ame, recor d.Formatte dValues["a ction"], | |||||
| 192 | reco rd.Formatt edValues[" operation" ]); | |||||
| 193 | ||||||
| 194 | // Show additional details f or certain AuditDeta il sub-typ es. | |||||
| 195 | var deta ilType = d etail.GetT ype(); | |||||
| 196 | if (deta ilType == typeof(Att ributeAudi tDetail)) | |||||
| 197 | { | |||||
| 198 | var attributeD etail = (A ttributeAu ditDetail) detail; | |||||
| 199 | ||||||
| 200 | // D isplay the old and n ew attribu te values. | |||||
| 201 | fore ach (KeyVa luePair<St ring, obje ct> attrib ute in att ributeDeta il.NewValu e.Attribut es) | |||||
| 202 | { | |||||
| 203 | String old Value = "( no value)" , newValue = "(no va lue)"; | |||||
| 204 | ||||||
| 205 | //TODO Dis play the l ookup valu es of thos e attribut es that do not conta in strings . | |||||
| 206 | if (attrib uteDetail. OldValue.C ontains(at tribute.Ke y)) | |||||
| 207 | oldVal ue = attri buteDetail .OldValue[ attribute. Key].ToStr ing(); | |||||
| 208 | ||||||
| 209 | newValue = attribute Detail.New Value[attr ibute.Key] .ToString( ); | |||||
| 210 | ||||||
| 211 | Console.Wr iteLine("A ttribute: {0}, old v alue: {1}, new value : {2}", | |||||
| 212 | attrib ute.Key, o ldValue, n ewValue); | |||||
| 213 | } | |||||
| 214 | ||||||
| 215 | fore ach (KeyVa luePair<St ring, obje ct> attrib ute in att ributeDeta il.OldValu e.Attribut es) | |||||
| 216 | { | |||||
| 217 | if (!attri buteDetail .NewValue. Contains(a ttribute.K ey)) | |||||
| 218 | { | |||||
| 219 | String newValue = "(no val ue)"; | |||||
| 220 | ||||||
| 221 | //TODO Display t he lookup values of those attr ibutes tha t do not c ontain str ings. | |||||
| 222 | String oldValue = attribut eDetail.Ol dValue[att ribute.Key ].ToString (); | |||||
| 223 | ||||||
| 224 | Consol e.WriteLin e("Attribu te: {0}, o ld value: {1}, new v alue: {2}" , | |||||
| 225 | at tribute.Ke y, oldValu e, newValu e); | |||||
| 226 | } | |||||
| 227 | } | |||||
| 228 | } | |||||
| 229 | Console. WriteLine( ); | |||||
| 230 | } | |||||
| 231 | // </snippetA uditing2> | |||||
| 232 | ||||||
| 233 | // / <summary > | |||||
| 234 | // / Enable a uditing on an entity . | |||||
| 235 | // / </summar y> | |||||
| 236 | // / <param n ame="entit yLogicalNa me">The lo gical name of the en tity.</par am> | |||||
| 237 | // / <param n ame="flag" >True to e nable audi ting, othe rwise fals e.</param> | |||||
| 238 | // / <returns >The previ ous value of the IsA uditEnable d attribut e.</return s> | |||||
| 239 | // <snippetAu diting3> | |||||
| 240 | pr ivate bool EnableEnt ityAuditin g(string e ntityLogic alName, bo ol flag) | |||||
| 241 | { | |||||
| 242 | // Retri eve the en tity metad ata. | |||||
| 243 | Retrieve EntityRequ est entity Request = new Retrie veEntityRe quest | |||||
| 244 | { | |||||
| 245 | Logi calName = entityLogi calName, | |||||
| 246 | Enti tyFilters = EntityFi lters.Attr ibutes | |||||
| 247 | }; | |||||
| 248 | ||||||
| 249 | Retrieve EntityResp onse entit yResponse = | |||||
| 250 | (Ret rieveEntit yResponse) _service.E xecute(ent ityRequest ); | |||||
| 251 | ||||||
| 252 | // Enabl e auditing on the en tity. By d efault, th is also en ables audi ting | |||||
| 253 | // on al l the enti ty's attri butes. | |||||
| 254 | EntityMe tadata ent ityMetadat a = entity Response.E ntityMetad ata; | |||||
| 255 | ||||||
| 256 | bool old Value = en tityMetada ta.IsAudit Enabled.Va lue; | |||||
| 257 | entityMe tadata.IsA uditEnable d = new Bo oleanManag edProperty (flag); | |||||
| 258 | ||||||
| 259 | UpdateEn tityReques t updateEn tityReques t = new Up dateEntity Request { Entity = e ntityMetad ata }; | |||||
| 260 | ||||||
| 261 | UpdateEn tityRespon se updateE ntityRespo nse = | |||||
| 262 | (Upd ateEntityR esponse)_s ervice.Exe cute(updat eEntityReq uest); | |||||
| 263 | ||||||
| 264 | return o ldValue; | |||||
| 265 | } | |||||
| 266 | // </snippetA uditing3> | |||||
| 267 | ||||||
| 268 | // / <summary > | |||||
| 269 | // / Creates any entity records t hat this s ample requ ires. | |||||
| 270 | // / </summar y> | |||||
| 271 | pu blic void CreateRequ iredRecord s() | |||||
| 272 | { | |||||
| 273 | Console. Write("Cre ating an a ccount, ") ; | |||||
| 274 | ||||||
| 275 | // Accou nt entity category c odes. | |||||
| 276 | var Cate gories = n ew { Prefe rredCustom er = 1, St andard = 2 }; | |||||
| 277 | ||||||
| 278 | // Creat e a new ac count enti ty. | |||||
| 279 | Account newAccount = new Acc ount { Nam e = "Examp le Account " }; | |||||
| 280 | _newAcco untId = _s ervice.Cre ate(newAcc ount); | |||||
| 281 | ||||||
| 282 | Console. WriteLine( "then upda ting the a ccount."); | |||||
| 283 | ||||||
| 284 | // Set t he values of some ot her attrib utes. | |||||
| 285 | newAccou nt.Account Id = _newA ccountId; | |||||
| 286 | newAccou nt.Account Number = " 1-A"; | |||||
| 287 | newAccou nt.Account CategoryCo de = new O ptionSetVa lue(Catego ries.Prefe rredCustom er); | |||||
| 288 | newAccou nt.Telepho ne1 = "555 -555-5555" ; | |||||
| 289 | ||||||
| 290 | _service .Update(ne wAccount); | |||||
| 291 | } | |||||
| 292 | ||||||
| 293 | // / <summary > | |||||
| 294 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 295 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 296 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 297 | // / </summar y> | |||||
| 298 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 299 | { | |||||
| 300 | bool del eteRecords = true; | |||||
| 301 | ||||||
| 302 | if (prom pt) | |||||
| 303 | { | |||||
| 304 | Cons ole.WriteL ine("\nDo you want t o delete t he account record? ( y/n) [y]: "); | |||||
| 305 | Stri ng answer = Console. ReadLine() ; | |||||
| 306 | ||||||
| 307 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ) || answe r == Strin g.Empty); | |||||
| 308 | } | |||||
| 309 | ||||||
| 310 | if (dele teRecords) | |||||
| 311 | { | |||||
| 312 | _ser vice.Delet e(Account. EntityLogi calName, _ newAccount Id); | |||||
| 313 | Cons ole.WriteL ine("The a ccount rec ord has be en deleted ."); | |||||
| 314 | } | |||||
| 315 | ||||||
| 316 | if (prom pt) | |||||
| 317 | { | |||||
| 318 | Cons ole.WriteL ine("\nDo you want t o delete A LL audit r ecords? (y /n) [n]: " ); | |||||
| 319 | Stri ng answer = Console. ReadLine() ; | |||||
| 320 | ||||||
| 321 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" )); | |||||
| 322 | } | |||||
| 323 | ||||||
| 324 | if (dele teRecords) | |||||
| 325 | { | |||||
| 326 | //<s nippetAudi ting4> | |||||
| 327 | //<s nippetAudi ting6> | |||||
| 328 | // G et the lis t of audit partition s. | |||||
| 329 | Retr ieveAuditP artitionLi stResponse partition Request = | |||||
| 330 | (RetrieveA uditPartit ionListRes ponse)_ser vice.Execu te(new Ret rieveAudit PartitionL istRequest ()); | |||||
| 331 | Audi tPartition DetailColl ection par titions = partitionR equest.Aud itPartitio nDetailCol lection; | |||||
| 332 | //</ snippetAud iting6> | |||||
| 333 | ||||||
| 334 | // C reate a de lete reque st with an end date earlier th an possibl e. | |||||
| 335 | Dele teAuditDat aRequest d eleteReque st = new D eleteAudit DataReques t(); | |||||
| 336 | dele teRequest. EndDate = new DateTi me(2000, 1 , 1); | |||||
| 337 | ||||||
| 338 | // C heck if pa rtitions a re not sup ported as is the cas e with SQL Server St andard edi tion. | |||||
| 339 | if ( partitions .IsLogical Collection ) | |||||
| 340 | { | |||||
| 341 | // Delete all audit records cr eated up u ntil now. | |||||
| 342 | deleteRequ est.EndDat e = DateTi me.Now; | |||||
| 343 | } | |||||
| 344 | ||||||
| 345 | // O therwise, delete all partition s that are older tha n the curr ent partit ion. | |||||
| 346 | // H int: The p artitions in the col lection ar e returned in sorted order whe re the | |||||
| 347 | // p artition w ith the ol dest end d ate is at index 0. | |||||
| 348 | else | |||||
| 349 | { | |||||
| 350 | for (int n = partiti ons.Count - 1; n >= 0; --n) | |||||
| 351 | { | |||||
| 352 | if (pa rtitions[n ].EndDate <= DateTim e.Now && p artitions[ n].EndDate > deleteR equest.End Date) | |||||
| 353 | { | |||||
| 354 | de leteReques t.EndDate = (DateTim e)partitio ns[n].EndD ate; | |||||
| 355 | br eak; | |||||
| 356 | } | |||||
| 357 | } | |||||
| 358 | } | |||||
| 359 | ||||||
| 360 | // D elete the audit reco rds. | |||||
| 361 | if ( deleteRequ est.EndDat e != new D ateTime(20 00, 1, 1)) | |||||
| 362 | { | |||||
| 363 | _service.E xecute(del eteRequest ); | |||||
| 364 | Console.Wr iteLine("A udit recor ds have be en deleted ."); | |||||
| 365 | } | |||||
| 366 | else | |||||
| 367 | Console.Wr iteLine("T here were no audit r ecords tha t could be deleted." ); | |||||
| 368 | //</ snippetAud iting4> | |||||
| 369 | } | |||||
| 370 | } | |||||
| 371 | #e ndregion C lass metho ds | |||||
| 372 | ||||||
| 373 | #r egion Main method | |||||
| 374 | ||||||
| 375 | // / <summary > | |||||
| 376 | // / Standard Main() me thod used by most SD K samples. | |||||
| 377 | // / </summar y> | |||||
| 378 | // / <param n ame="args" ></param> | |||||
| 379 | st atic publi c void Mai n(string[] args) | |||||
| 380 | { | |||||
| 381 | try | |||||
| 382 | { | |||||
| 383 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 384 | // c redentials from the user. | |||||
| 385 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 386 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 387 | ||||||
| 388 | Audi ting app = new Audit ing(); | |||||
| 389 | app. Run(config , true); | |||||
| 390 | } | |||||
| 391 | ||||||
| 392 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 393 | { | |||||
| 394 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 395 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 396 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 397 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 398 | Cons ole.WriteL ine("Trace : {0}", ex .Detail.Tr aceText); | |||||
| 399 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 400 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 401 | } | |||||
| 402 | catch (S ystem.Time outExcepti on ex) | |||||
| 403 | { | |||||
| 404 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 405 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 406 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 407 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 408 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 409 | } | |||||
| 410 | catch (S ystem.Exce ption ex) | |||||
| 411 | { | |||||
| 412 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 413 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 414 | ||||||
| 415 | // D isplay the details o f the inne r exceptio n. | |||||
| 416 | if ( ex.InnerEx ception != null) | |||||
| 417 | { | |||||
| 418 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 419 | ||||||
| 420 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 421 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 422 | if (fe != null) | |||||
| 423 | { | |||||
| 424 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 425 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 426 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 427 | Consol e.WriteLin e("Trace: {0}", fe.D etail.Trac eText); | |||||
| 428 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 429 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 430 | } | |||||
| 431 | } | |||||
| 432 | } | |||||
| 433 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 434 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 435 | ||||||
| 436 | finally | |||||
| 437 | { | |||||
| 438 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 439 | Cons ole.ReadLi ne(); | |||||
| 440 | } | |||||
| 441 | } | |||||
| 442 | #e ndregion M ain method | |||||
| 443 | } | |||||
| 444 | } | |||||
| 445 | //</snippe tAuditing> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.