Produced by Araxis Merge on 2/1/2017 2:56:22 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\ActivityFeeds | WorkingWithActivityFeeds.cs | Tue Dec 20 19:51:43 2016 UTC |
| 2 | Wed Feb 1 19:56:22 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 873 |
| 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 WorkingWit hActivityF eeds> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Collect ions.Gener ic; | |||||
| 19 | using Syst em.Linq; | |||||
| 20 | using Syst em.Service Model; | |||||
| 21 | using Syst em.Threadi ng; | |||||
| 22 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 23 | using Micr osoft.Xrm. Sdk; | |||||
| 24 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 26 | ||||||
| 27 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 28 | { | |||||
| 29 | /// <s ummary> | |||||
| 30 | /// De monstrates how to wo rk with th e new Acti vity Feeds entities, including Post, | |||||
| 31 | /// Po stFollow, and PostCo mment.</su mmary> | |||||
| 32 | /// <r emarks> | |||||
| 33 | /// At run-time, you will be given t he option to delete all the | |||||
| 34 | /// da tabase rec ords creat ed by this program.< /remarks> | |||||
| 35 | public class Wor kingWithAc tivityFeed s | |||||
| 36 | { | |||||
| 37 | #r egion Loca l Sample T ypes | |||||
| 38 | pr ivate clas s InvalidS ampleExecu tionExcept ion : Exce ption | |||||
| 39 | { | |||||
| 40 | public I nvalidSamp leExecutio nException (String me ssage) | |||||
| 41 | : ba se(message ) | |||||
| 42 | { | |||||
| 43 | } | |||||
| 44 | } | |||||
| 45 | #e ndregion L ocal Sampl e Types | |||||
| 46 | ||||||
| 47 | #r egion Clas s Level Me mbers | |||||
| 48 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 49 | pr ivate Serv iceContext _serviceC ontext; | |||||
| 50 | pr ivate msdy n_PostConf ig _origin alLeadConf ig; | |||||
| 51 | pr ivate msdy n_PostConf ig _origin alSystemUs erConfig; | |||||
| 52 | pr ivate msdy n_PostConf ig _system userConfig ; | |||||
| 53 | pr ivate msdy n_PostConf ig _leadCo nfig; | |||||
| 54 | pr ivate List <msdyn_Pos tRuleConfi g> _postRu leConfigs = | |||||
| 55 | new List <msdyn_Pos tRuleConfi g>(); | |||||
| 56 | pr ivate Lead _lead1; | |||||
| 57 | pr ivate Lead _lead2; | |||||
| 58 | pr ivate Lead _lead3; | |||||
| 59 | pr ivate Post Follow _fo llow1; | |||||
| 60 | pr ivate Post Follow _fo llow2; | |||||
| 61 | pr ivate Post Follow _fo llow3; | |||||
| 62 | pr ivate List <EntityRef erence> _g eneratedEn tities = n ew List<En tityRefere nce>(); | |||||
| 63 | pr ivate Post _post1; | |||||
| 64 | pr ivate Post _post2; | |||||
| 65 | pr ivate Post _post3; | |||||
| 66 | pr ivate Post _post4; | |||||
| 67 | pr ivate Post _leadPost 1; | |||||
| 68 | #e ndregion C lass Level Members | |||||
| 69 | ||||||
| 70 | #r egion How To Sample Code | |||||
| 71 | ||||||
| 72 | // / <summary > | |||||
| 73 | // / This met hod first connects t o the Orga nization s ervice. Af terwards, activity | |||||
| 74 | // / feeds ar e enabled, posts and comments are made t o entity r ecords and user | |||||
| 75 | // / walls an d auto pos t rules ar e demonstr ated. | |||||
| 76 | // / </summar y> | |||||
| 77 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 78 | // / <param n ame="promp tForDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 79 | // / created entities.< /param> | |||||
| 80 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 81 | { | |||||
| 82 | using (_ servicePro xy = new O rganizatio nServicePr oxy(server Config.Org anizationU ri, server Config.Hom eRealmUri, serverConf ig.Credent ials, serv erConfig.D eviceCrede ntials)) | |||||
| 83 | { | |||||
| 84 | // T his statem ent is req uired to e nable earl y-bound ty pe support . | |||||
| 85 | _ser viceProxy. EnableProx yTypes(); | |||||
| 86 | _ser viceContex t = new Se rviceConte xt(_servic eProxy); | |||||
| 87 | ||||||
| 88 | try | |||||
| 89 | { | |||||
| 90 | ConfigureA ctivityFee ds(); | |||||
| 91 | PostToReco rdWalls(); | |||||
| 92 | PostToPers onalWalls( ); | |||||
| 93 | ShowRecord Walls(); | |||||
| 94 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 95 | } | |||||
| 96 | catc h (Invalid SampleExec utionExcep tion e) | |||||
| 97 | { | |||||
| 98 | Console.Wr iteLine(e. Message); | |||||
| 99 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 100 | } | |||||
| 101 | } | |||||
| 102 | } | |||||
| 103 | ||||||
| 104 | pr ivate void Configure ActivityFe eds() | |||||
| 105 | { | |||||
| 106 | Console. WriteLine( "== Config uring Acti vity Feeds =="); | |||||
| 107 | ||||||
| 108 | // Get t he origina l systemus er config in order t o keep a c opy for re verting | |||||
| 109 | // after the sampl e has comp leted. | |||||
| 110 | _origina lSystemUse rConfig = | |||||
| 111 | (fro m c in _se rviceConte xt.msdyn_P ostConfigS et | |||||
| 112 | whe re c.msdyn _EntityNam e == Syste mUser.Enti tyLogicalN ame | |||||
| 113 | sel ect new ms dyn_PostCo nfig | |||||
| 114 | { | |||||
| 115 | msdyn_Pos tConfigId = c.msdyn_ PostConfig Id, | |||||
| 116 | msdyn_Con figureWall = c.msdyn _Configure Wall, | |||||
| 117 | msdyn_Ent ityName = c.msdyn_En tityName | |||||
| 118 | }). FirstOrDef ault(); | |||||
| 119 | ||||||
| 120 | // Retri eve or Cre ate an ins tance of m sdyn_PostC onfig to e nable acti vity | |||||
| 121 | // feeds for leads (or make sure they are alread y enabled) . | |||||
| 122 | // If a new msdyn_ PostConfig record ge ts created , activity feeds for | |||||
| 123 | // syste musers wil l be enabl ed automat ically. | |||||
| 124 | _leadCon fig = | |||||
| 125 | (fro m c in _se rviceConte xt.msdyn_P ostConfigS et | |||||
| 126 | whe re c.msdyn _EntityNam e == Lead. EntityLogi calName | |||||
| 127 | sel ect new ms dyn_PostCo nfig | |||||
| 128 | { | |||||
| 129 | msdyn_Pos tConfigId = c.msdyn_ PostConfig Id, | |||||
| 130 | msdyn_Ent ityName = c.msdyn_En tityName, | |||||
| 131 | msdyn_Con figureWall = c.msdyn _Configure Wall | |||||
| 132 | }). FirstOrDef ault(); | |||||
| 133 | ||||||
| 134 | if (_lea dConfig == null) | |||||
| 135 | { | |||||
| 136 | // C reate the configurat ion record for leads . | |||||
| 137 | _lea dConfig = new msdyn_ PostConfig | |||||
| 138 | { | |||||
| 139 | msdyn_Enti tyName = L ead.Entity LogicalNam e, | |||||
| 140 | msdyn_Conf igureWall = true | |||||
| 141 | }; | |||||
| 142 | ||||||
| 143 | _ser viceContex t.AddObjec t(_leadCon fig); | |||||
| 144 | _ser viceContex t.SaveChan ges(); | |||||
| 145 | Cons ole.WriteL ine( | |||||
| 146 | " The lea d activity feed wall configura tion was c reated."); | |||||
| 147 | } | |||||
| 148 | else | |||||
| 149 | { | |||||
| 150 | // S tore the o riginal Le ad Config so that we can rever t changes later. | |||||
| 151 | _ori ginalLeadC onfig = Cl oneRelevan tConfigura tion(_lead Config); | |||||
| 152 | ||||||
| 153 | if ( !_leadConf ig.msdyn_C onfigureWa ll.HasValu e | |||||
| 154 | || !_leadC onfig.msdy n_Configur eWall.Valu e) | |||||
| 155 | { | |||||
| 156 | _leadConfi g.msdyn_Co nfigureWal l = true; | |||||
| 157 | ||||||
| 158 | _serviceCo ntext.Upda teObject(_ leadConfig ); | |||||
| 159 | _serviceCo ntext.Save Changes(); | |||||
| 160 | Console.Wr iteLine( | |||||
| 161 | " The lead acti vity feed wall was e nabled."); | |||||
| 162 | } | |||||
| 163 | } | |||||
| 164 | ||||||
| 165 | // Get t he origina l systemus er config in order t o keep a c opy for re verting | |||||
| 166 | // after the sampl e has comp leted. | |||||
| 167 | _systemu serConfig = | |||||
| 168 | (fro m c in _se rviceConte xt.msdyn_P ostConfigS et | |||||
| 169 | whe re c.msdyn _EntityNam e == Syste mUser.Enti tyLogicalN ame | |||||
| 170 | sel ect new ms dyn_PostCo nfig | |||||
| 171 | { | |||||
| 172 | msdyn_Pos tConfigId = c.msdyn_ PostConfig Id, | |||||
| 173 | msdyn_Con figureWall = c.msdyn _Configure Wall, | |||||
| 174 | msdyn_Ent ityName = c.msdyn_En tityName | |||||
| 175 | }). FirstOrDef ault(); | |||||
| 176 | ||||||
| 177 | // Ensur e that the wall for systemuser is enable d if there is alread y a | |||||
| 178 | // syste muser conf iguration defined. | |||||
| 179 | if (_sys temuserCon fig != nul l && | |||||
| 180 | (!_s ystemuserC onfig.msdy n_Configur eWall.HasV alue | |||||
| 181 | || ! _systemuse rConfig.ms dyn_Config ureWall.Va lue)) | |||||
| 182 | { | |||||
| 183 | _sys temuserCon fig.msdyn_ ConfigureW all = true ; | |||||
| 184 | ||||||
| 185 | _ser viceContex t.UpdateOb ject(_syst emuserConf ig); | |||||
| 186 | _ser viceContex t.SaveChan ges(); | |||||
| 187 | Cons ole.WriteL ine(" The systemuse r activity feed wall was enabl ed."); | |||||
| 188 | } | |||||
| 189 | ||||||
| 190 | // Publi sh the lea d and syst emuser ent ities so t hat they w ill have r ecord | |||||
| 191 | // walls on their forms. | |||||
| 192 | PublishS ystemUserA ndLead(); | |||||
| 193 | ||||||
| 194 | // Activ ate the au to post ru le configu rations. N ew Lead qu alified sh ould be | |||||
| 195 | // activ ated autom atically w hen the ru le is gene rated by C RM. | |||||
| 196 | var lead Rules = | |||||
| 197 | (fro m r in _se rviceConte xt.msdyn_P ostRuleCon figSet | |||||
| 198 | whe re r.msdyn _RuleId == "LeadQual ify.Yes.Ru le" | |||||
| 199 | || r.msdyn _RuleId == "LeadCrea te.Rule" | |||||
| 200 | sel ect r).ToL ist(); | |||||
| 201 | if (lead Rules.Coun t() != 2) | |||||
| 202 | { | |||||
| 203 | thro w new Inva lidSampleE xecutionEx ception( | |||||
| 204 | " O ne or both of the le ad config rules do n ot exist. This can b e fixed by deleting the lead p ost config ."); | |||||
| 205 | } | |||||
| 206 | foreach (var confi gRule in l eadRules) | |||||
| 207 | { | |||||
| 208 | _pos tRuleConfi gs.Add(con figRule); | |||||
| 209 | Acti vateRuleCo nfig(confi gRule); | |||||
| 210 | } | |||||
| 211 | } | |||||
| 212 | ||||||
| 213 | pr ivate void PostToRec ordWalls() | |||||
| 214 | { | |||||
| 215 | Console. WriteLine( "\r\n== Wo rking with Record Wa lls =="); | |||||
| 216 | // Creat e the lead s. | |||||
| 217 | CreateRe quiredReco rds(); | |||||
| 218 | ||||||
| 219 | // Follo w each of the leads. | |||||
| 220 | _follow1 = new Pos tFollow | |||||
| 221 | { | |||||
| 222 | Rega rdingObjec tId = _lea d1.ToEntit yReference () | |||||
| 223 | }; | |||||
| 224 | _service Context.Ad dObject(_f ollow1); | |||||
| 225 | ||||||
| 226 | _follow2 = new Pos tFollow | |||||
| 227 | { | |||||
| 228 | Rega rdingObjec tId = _lea d2.ToEntit yReference () | |||||
| 229 | }; | |||||
| 230 | _service Context.Ad dObject(_f ollow2); | |||||
| 231 | ||||||
| 232 | _follow3 = new Pos tFollow | |||||
| 233 | { | |||||
| 234 | Rega rdingObjec tId = _lea d3.ToEntit yReference () | |||||
| 235 | }; | |||||
| 236 | _service Context.Ad dObject(_f ollow3); | |||||
| 237 | ||||||
| 238 | _service Context.Sa veChanges( ); | |||||
| 239 | Console. WriteLine( " The 3 l eads are n ow followe d."); | |||||
| 240 | ||||||
| 241 | // Creat e posts, m entions, a nd comment s related to the lea ds. | |||||
| 242 | // Creat e a post r elated to lead 1 wit h a mentio n and a co mment. | |||||
| 243 | _leadPos t1 = new P ost | |||||
| 244 | { | |||||
| 245 | Rega rdingObjec tId = _lea d1.ToEntit yReference (), | |||||
| 246 | Sour ce = new O ptionSetVa lue((int)P ostSource. AutoPost), | |||||
| 247 | // I nclude a m ention in the post t ext. | |||||
| 248 | Text = String. Format("Th is lead is similar t o @[{0},{1 },\"{2}\"] ", | |||||
| 249 | Lead.Entit yTypeCode, _lead2.Id , _lead2.F ullName) | |||||
| 250 | }; | |||||
| 251 | ||||||
| 252 | _service Context.Ad dObject(_l eadPost1); | |||||
| 253 | _service Context.Sa veChanges( ); | |||||
| 254 | Console. WriteLine( " Post 1 has been c reated."); | |||||
| 255 | ||||||
| 256 | // It is n't necess ary to kee p track of the comme nt because the comme nt will | |||||
| 257 | // be de leted when its paren t post is deleted. | |||||
| 258 | var comm ent1 = new PostComme nt | |||||
| 259 | { | |||||
| 260 | Post Id = _lead Post1.ToEn tityRefere nce(), | |||||
| 261 | Text = "Sample comment 1 " | |||||
| 262 | }; | |||||
| 263 | _service Context.Ad dObject(co mment1); | |||||
| 264 | _service Context.Sa veChanges( ); | |||||
| 265 | Console. WriteLine( " Comment 1 has bee n created. "); | |||||
| 266 | ||||||
| 267 | // Creat e a post r elated to lead 2 wit h three co mments. | |||||
| 268 | var post 2 = new Po st | |||||
| 269 | { | |||||
| 270 | Rega rdingObjec tId = _lea d2.ToEntit yReference (), | |||||
| 271 | Sour ce = new O ptionSetVa lue((int)P ostSource. ManualPost ), | |||||
| 272 | Text = "This l ead was cr eated for a sample." | |||||
| 273 | }; | |||||
| 274 | ||||||
| 275 | _service Context.Ad dObject(po st2); | |||||
| 276 | _service Context.Sa veChanges( ); | |||||
| 277 | Console. WriteLine( " Post 2 has been c reated."); | |||||
| 278 | ||||||
| 279 | var comm ent2 = new PostComme nt | |||||
| 280 | { | |||||
| 281 | Post Id = post2 .ToEntityR eference() , | |||||
| 282 | Text = "Sample comment 2 " | |||||
| 283 | }; | |||||
| 284 | ||||||
| 285 | var comm ent3 = new PostComme nt | |||||
| 286 | { | |||||
| 287 | Post Id = post2 .ToEntityR eference() , | |||||
| 288 | Text = "Sample comment 3 " | |||||
| 289 | }; | |||||
| 290 | ||||||
| 291 | var comm ent4 = new PostComme nt | |||||
| 292 | { | |||||
| 293 | Post Id = post2 .ToEntityR eference() , | |||||
| 294 | Text = "Sample comment 4 " | |||||
| 295 | }; | |||||
| 296 | ||||||
| 297 | _service Context.Ad dObject(co mment2); | |||||
| 298 | _service Context.Ad dObject(co mment3); | |||||
| 299 | _service Context.Ad dObject(co mment4); | |||||
| 300 | _service Context.Sa veChanges( ); | |||||
| 301 | Console. WriteLine( " Comment s 2, 3, an d 4 have b een create d."); | |||||
| 302 | ||||||
| 303 | // Quali fy some le ads. Sinc e there is an active post rule config fo r | |||||
| 304 | // quali fication o f a lead, this shoul d generate an auto p ost to the record | |||||
| 305 | // wall of each le ad that is qualified . | |||||
| 306 | ||||||
| 307 | // Quali fy lead 2. | |||||
| 308 | var qual ifyLead2Re quest = ne w QualifyL eadRequest | |||||
| 309 | { | |||||
| 310 | Crea teAccount = true, | |||||
| 311 | Lead Id = _lead 2.ToEntity Reference( ), | |||||
| 312 | Stat us = new O ptionSetVa lue((int)l ead_status code.Quali fied) | |||||
| 313 | }; | |||||
| 314 | ||||||
| 315 | var qual ifyLead2Re sponse = ( QualifyLea dResponse) _servicePr oxy.Execut e( | |||||
| 316 | qual ifyLead2Re quest); | |||||
| 317 | ||||||
| 318 | // Store the gener ated Accou nt to dele te it late r. | |||||
| 319 | foreach (var entit yRef in qu alifyLead2 Response.C reatedEnti ties) | |||||
| 320 | { | |||||
| 321 | _gen eratedEnti ties.Add(e ntityRef); | |||||
| 322 | } | |||||
| 323 | ||||||
| 324 | Console. WriteLine( " Lead 2 was qualif ied."); | |||||
| 325 | ||||||
| 326 | // Quali fy lead 3. | |||||
| 327 | var qual ifyLead3Re quest = ne w QualifyL eadRequest | |||||
| 328 | { | |||||
| 329 | Crea teAccount = true, | |||||
| 330 | Lead Id = _lead 3.ToEntity Reference( ), | |||||
| 331 | Stat us = new O ptionSetVa lue((int)l ead_status code.Quali fied) | |||||
| 332 | }; | |||||
| 333 | ||||||
| 334 | var qual ifyLead3Re sponse = ( QualifyLea dResponse) _servicePr oxy.Execut e( | |||||
| 335 | qual ifyLead3Re quest); | |||||
| 336 | ||||||
| 337 | foreach (var entit yRef in qu alifyLead3 Response.C reatedEnti ties) | |||||
| 338 | { | |||||
| 339 | _gen eratedEnti ties.Add(e ntityRef); | |||||
| 340 | } | |||||
| 341 | ||||||
| 342 | Console. WriteLine( " Lead 3 was qualif ied."); | |||||
| 343 | } | |||||
| 344 | ||||||
| 345 | pr ivate void PostToPer sonalWalls () | |||||
| 346 | { | |||||
| 347 | Console. WriteLine( "\r\n== Wo rking with Personal Walls ==") ; | |||||
| 348 | // Creat e manual ( user) post s on a use r's Person al wall. | |||||
| 349 | var whoA mIRequest = new WhoA mIRequest( ); | |||||
| 350 | var whoA mIResponse = (WhoAmI Response)_ servicePro xy.Execute (whoAmIReq uest); | |||||
| 351 | var curr entUserRef = new Ent ityReferen ce( | |||||
| 352 | Syst emUser.Ent ityLogical Name, whoA mIResponse .UserId); | |||||
| 353 | ||||||
| 354 | // Creat e a post t hat mentio ns lead 1. | |||||
| 355 | // The R egarding o bject shou ld be set to the use r whose wa ll the pos t should | |||||
| 356 | // be po sted to (w e'll just use the cu rrent user ). | |||||
| 357 | _post1 = new Post | |||||
| 358 | { | |||||
| 359 | Rega rdingObjec tId = curr entUserRef , | |||||
| 360 | Sour ce = new O ptionSetVa lue((int)P ostSource. ManualPost ), | |||||
| 361 | Text = String. Format("I' d rather n ot pursue @[{0},{1}, \"{2}\"]", | |||||
| 362 | Lead.Entit yTypeCode, _lead1.Id , _lead1.F ullName) | |||||
| 363 | }; | |||||
| 364 | ||||||
| 365 | _service Context.Ad dObject(_p ost1); | |||||
| 366 | _service Context.Sa veChanges( ); | |||||
| 367 | Console. WriteLine( " Persona l wall pos t 1 was cr eated."); | |||||
| 368 | ||||||
| 369 | // Creat e a relate d comment. | |||||
| 370 | var comm ent1 = new PostComme nt | |||||
| 371 | { | |||||
| 372 | Post Id = _post 1.ToEntity Reference( ), | |||||
| 373 | Text = "Person al wall co mment 1." | |||||
| 374 | }; | |||||
| 375 | ||||||
| 376 | _service Context.Ad dObject(co mment1); | |||||
| 377 | _service Context.Sa veChanges( ); | |||||
| 378 | Console. WriteLine( " Persona l wall com ment 1 was created." ); | |||||
| 379 | ||||||
| 380 | _post2 = new Post | |||||
| 381 | { | |||||
| 382 | Rega rdingObjec tId = curr entUserRef , | |||||
| 383 | Sour ce = new O ptionSetVa lue((int)P ostSource. AutoPost), | |||||
| 384 | Text = "Person al wall po st 2." | |||||
| 385 | }; | |||||
| 386 | ||||||
| 387 | _service Context.Ad dObject(_p ost2); | |||||
| 388 | _service Context.Sa veChanges( ); | |||||
| 389 | Console. WriteLine( " Persona l wall pos t 2 was cr eated."); | |||||
| 390 | ||||||
| 391 | // Creat e a few re lated comm ents. | |||||
| 392 | var comm ent2 = new PostComme nt | |||||
| 393 | { | |||||
| 394 | Post Id = _post 2.ToEntity Reference( ), | |||||
| 395 | Text = "Person al wall co mment 2." | |||||
| 396 | }; | |||||
| 397 | ||||||
| 398 | var comm ent3 = new PostComme nt | |||||
| 399 | { | |||||
| 400 | Post Id = _post 2.ToEntity Reference( ), | |||||
| 401 | Text = "Person al wall co mment 3." | |||||
| 402 | }; | |||||
| 403 | ||||||
| 404 | var comm ent4 = new PostComme nt | |||||
| 405 | { | |||||
| 406 | Post Id = _post 2.ToEntity Reference( ), | |||||
| 407 | Text = "Person al wall co mment 4." | |||||
| 408 | }; | |||||
| 409 | ||||||
| 410 | var comm ent5 = new PostComme nt | |||||
| 411 | { | |||||
| 412 | Post Id = _post 2.ToEntity Reference( ), | |||||
| 413 | Text = "Person al wall co mment 5." | |||||
| 414 | }; | |||||
| 415 | ||||||
| 416 | _service Context.Ad dObject(co mment2); | |||||
| 417 | _service Context.Ad dObject(co mment3); | |||||
| 418 | _service Context.Ad dObject(co mment4); | |||||
| 419 | _service Context.Ad dObject(co mment5); | |||||
| 420 | _service Context.Sa veChanges( ); | |||||
| 421 | Console. WriteLine( " Persona l wall com ments 2, 3 , 4, and 5 were crea ted."); | |||||
| 422 | ||||||
| 423 | // Creat e a couple more post s just to show how p aging work s. | |||||
| 424 | _post3 = new Post | |||||
| 425 | { | |||||
| 426 | Rega rdingObjec tId = curr entUserRef , | |||||
| 427 | Sour ce = new O ptionSetVa lue((int)P ostSource. ManualPost ), | |||||
| 428 | Text = "Person al wall po st 3." | |||||
| 429 | }; | |||||
| 430 | ||||||
| 431 | _post4 = new Post | |||||
| 432 | { | |||||
| 433 | Rega rdingObjec tId = curr entUserRef , | |||||
| 434 | Sour ce = new O ptionSetVa lue((int)P ostSource. AutoPost), | |||||
| 435 | Text = "Person al wall po st 4." | |||||
| 436 | }; | |||||
| 437 | ||||||
| 438 | _service Context.Ad dObject(_p ost3); | |||||
| 439 | _service Context.Ad dObject(_p ost4); | |||||
| 440 | _service Context.Sa veChanges( ); | |||||
| 441 | Console. WriteLine( " Persona l wall pos ts 3 and 4 were crea ted."); | |||||
| 442 | ||||||
| 443 | // Retri eve this u ser's pers onal wall. | |||||
| 444 | // Retri eve the fi rst page o f posts. | |||||
| 445 | DisplayP ersonalWal lPage(1); | |||||
| 446 | ||||||
| 447 | // Retri eve the se cond page of posts. | |||||
| 448 | DisplayP ersonalWal lPage(2); | |||||
| 449 | ||||||
| 450 | // Sleep for a sec ond so tha t the time of the ne wly create d comment will | |||||
| 451 | // clear ly be late r than the previousl y created posts/comm ents (othe rwise | |||||
| 452 | // Post 3 will not be escala ted to the top of th e wall). | |||||
| 453 | Thread.S leep(1000) ; | |||||
| 454 | ||||||
| 455 | // Creat e a new co mment on t he last po st, which will bring the post to the | |||||
| 456 | // top. | |||||
| 457 | var newP ostComment = new Pos tComment | |||||
| 458 | { | |||||
| 459 | Post Id = _post 3.ToEntity Reference( ), | |||||
| 460 | Text = "New co mment to s how that n ew comment s affect p ost orderi ng." | |||||
| 461 | }; | |||||
| 462 | ||||||
| 463 | _service Context.Ad dObject(ne wPostComme nt); | |||||
| 464 | _service Context.Sa veChanges( ); | |||||
| 465 | Console. WriteLine( "\r\n A n ew comment was creat ed to show effects o n post ord ering."); | |||||
| 466 | ||||||
| 467 | // Displ ay the fir st page of the perso nal wall t o showcase the chang e in | |||||
| 468 | // order ing. Post 3 should be at the top. | |||||
| 469 | DisplayP ersonalWal lPage(1); | |||||
| 470 | ||||||
| 471 | // Show paging of comments. | |||||
| 472 | // Retri eve commen ts 2 at a time, star ting with page 1. | |||||
| 473 | var comm entsQuery = new Quer yExpressio n(PostComm ent.Entity LogicalNam e) | |||||
| 474 | { | |||||
| 475 | Colu mnSet = ne w ColumnSe t(true), | |||||
| 476 | Crit eria = new FilterExp ression(Lo gicalOpera tor.And), | |||||
| 477 | Page Info = new PagingInf o | |||||
| 478 | { | |||||
| 479 | Count = 2, | |||||
| 480 | PageNumber = 1, | |||||
| 481 | ReturnTota lRecordCou nt = true | |||||
| 482 | } | |||||
| 483 | }; | |||||
| 484 | ||||||
| 485 | comments Query.Crit eria.AddCo ndition( | |||||
| 486 | "pos tid", Cond itionOpera tor.Equal, _post2.Id ); | |||||
| 487 | ||||||
| 488 | // Conti nue queryi ng for com ments unti l there ar e no furth er comment s to | |||||
| 489 | // be re trieved. | |||||
| 490 | EntityCo llection c ommentsRes ult; | |||||
| 491 | do | |||||
| 492 | { | |||||
| 493 | comm entsResult = _servic eProxy.Ret rieveMulti ple(commen tsQuery); | |||||
| 494 | ||||||
| 495 | // D isplay the comments that we re trieved. | |||||
| 496 | Cons ole.WriteL ine("\r\n Comments for lead 2 page {0}" , | |||||
| 497 | commentsQu ery.PageIn fo.PageNum ber); | |||||
| 498 | fore ach (PostC omment com ment in co mmentsResu lt.Entitie s) | |||||
| 499 | { | |||||
| 500 | DisplayCom ment(comme nt); | |||||
| 501 | } | |||||
| 502 | ||||||
| 503 | comm entsQuery. PageInfo.P ageNumber += 1; | |||||
| 504 | } | |||||
| 505 | while (c ommentsRes ult.MoreRe cords); | |||||
| 506 | } | |||||
| 507 | ||||||
| 508 | pr ivate void ShowRecor dWalls() | |||||
| 509 | { | |||||
| 510 | Console. WriteLine( "\r\n== Sh owing Reco rd Walls = ="); | |||||
| 511 | ||||||
| 512 | // Creat e a new po st on one of the lea ds. | |||||
| 513 | var newL eadPost = new Post | |||||
| 514 | { | |||||
| 515 | Sour ce = new O ptionSetVa lue((int)P ostSource. AutoPost), | |||||
| 516 | Text = "New le ad post.", | |||||
| 517 | Rega rdingObjec tId = _lea d2.ToEntit yReference (), | |||||
| 518 | }; | |||||
| 519 | ||||||
| 520 | _service Context.Ad dObject(ne wLeadPost) ; | |||||
| 521 | _service Context.Sa veChanges( ); | |||||
| 522 | Console. WriteLine( " The new lead 2 po st has bee n created. "); | |||||
| 523 | ||||||
| 524 | DisplayR ecordWall( _lead1); | |||||
| 525 | DisplayR ecordWall( _lead2); | |||||
| 526 | DisplayR ecordWall( _lead3); | |||||
| 527 | } | |||||
| 528 | // <snippetRe trieveReco rdWall> | |||||
| 529 | pr ivate void DisplayRe cordWall(L ead lead) | |||||
| 530 | { | |||||
| 531 | // Displ ay the fir st page of the recor d wall. | |||||
| 532 | var retr ieveRecord WallReq = new Retrie veRecordWa llRequest | |||||
| 533 | { | |||||
| 534 | Enti ty = lead. ToEntityRe ference(), | |||||
| 535 | Comm entsPerPos t = 2, | |||||
| 536 | Page Size = 10, | |||||
| 537 | Page Number = 1 | |||||
| 538 | }; | |||||
| 539 | ||||||
| 540 | var retr ieveRecord WallRes = | |||||
| 541 | (Ret rieveRecor dWallRespo nse)_servi ceProxy.Ex ecute(retr ieveRecord WallReq); | |||||
| 542 | ||||||
| 543 | Console. WriteLine( "\r\n Pos ts for lea d {0}:", l ead.FullNa me); | |||||
| 544 | foreach (Post post in retrie veRecordWa llRes.Enti tyCollecti on.Entitie s) | |||||
| 545 | { | |||||
| 546 | Disp layPost(po st); | |||||
| 547 | } | |||||
| 548 | } | |||||
| 549 | // </snippetR etrieveRec ordWall> | |||||
| 550 | ||||||
| 551 | // <snippetRe trievePers onalWall> | |||||
| 552 | pr ivate void DisplayPe rsonalWall Page(int p ageNumber) | |||||
| 553 | { | |||||
| 554 | // Retri eve the pa ge of post s. We'll only retri eve 5 at a time so t hat | |||||
| 555 | // we wi ll have mo re than on e page. | |||||
| 556 | var page Size = 5; | |||||
| 557 | ||||||
| 558 | var pers onalWallPa geReq = ne w Retrieve PersonalWa llRequest | |||||
| 559 | { | |||||
| 560 | Comm entsPerPos t = 2, | |||||
| 561 | Page Number = p ageNumber, | |||||
| 562 | Page Size = pag eSize | |||||
| 563 | }; | |||||
| 564 | var pers onalWallPa geRes = | |||||
| 565 | (Ret rievePerso nalWallRes ponse)_ser viceProxy. Execute(pe rsonalWall PageReq); | |||||
| 566 | ||||||
| 567 | Console. WriteLine( "\r\n Per sonal Wall Page {0} Posts:", p ageNumber) ; | |||||
| 568 | foreach (Post post in person alWallPage Res.Entity Collection .Entities) | |||||
| 569 | { | |||||
| 570 | Disp layPost(po st); | |||||
| 571 | } | |||||
| 572 | } | |||||
| 573 | // </snippetR etrievePer sonalWall> | |||||
| 574 | ||||||
| 575 | pr ivate void DisplayPo st(Post po st) | |||||
| 576 | { | |||||
| 577 | Console. WriteLine( " Post, {0}, {1}, {2}: {3}" , | |||||
| 578 | post .CreatedBy .Name, | |||||
| 579 | (Pos tType)post .Type.Valu e, | |||||
| 580 | (Pos tSource)po st.Source. Value, | |||||
| 581 | Shor ten(post.T ext)); | |||||
| 582 | ||||||
| 583 | if (post .Post_Comm ents != nu ll) | |||||
| 584 | { | |||||
| 585 | fore ach (var c omment in post.Post_ Comments) | |||||
| 586 | { | |||||
| 587 | DisplayCom ment(comme nt); | |||||
| 588 | } | |||||
| 589 | } | |||||
| 590 | } | |||||
| 591 | ||||||
| 592 | pr ivate void DisplayCo mment(Post Comment co mment) | |||||
| 593 | { | |||||
| 594 | Console. WriteLine( " Com ment, {0}: {1}", | |||||
| 595 | commen t.CreatedB y.Name, Sh orten(comm ent.Text)) ; | |||||
| 596 | } | |||||
| 597 | ||||||
| 598 | pr ivate Stri ng Shorten (String x) | |||||
| 599 | { | |||||
| 600 | return x .Length > 33 ? x.Sub string(0, 30) + "... " : x; | |||||
| 601 | } | |||||
| 602 | ||||||
| 603 | pr ivate void CreateReq uiredRecor ds() | |||||
| 604 | { | |||||
| 605 | // Creat e leads fo r relating activity feed recor ds to. Sin ce there i s an | |||||
| 606 | // activ e post rul e config f or creatio n of a new lead, cre ating the leads | |||||
| 607 | // shoul d add an a uto post t o the reco rd wall fo r each of the leads. | |||||
| 608 | _lead1 = new Lead | |||||
| 609 | { | |||||
| 610 | Comp anyName = "A. Datum Corporatio n", | |||||
| 611 | Firs tName = "H enriette", | |||||
| 612 | Midd leName = " Thaulow", | |||||
| 613 | Last Name = "An dersen", | |||||
| 614 | Subj ect = "Act ivity Feed s Sample 1 " | |||||
| 615 | }; | |||||
| 616 | _service Context.Ad dObject(_l ead1); | |||||
| 617 | ||||||
| 618 | _lead2 = new Lead | |||||
| 619 | { | |||||
| 620 | Comp anyName = "Adventure Works", | |||||
| 621 | Firs tName = "M ary", | |||||
| 622 | Midd leName = " Kay", | |||||
| 623 | Last Name = "An dersen", | |||||
| 624 | Subj ect = "Act ivity Feed s Sample 2 " | |||||
| 625 | }; | |||||
| 626 | _service Context.Ad dObject(_l ead2); | |||||
| 627 | ||||||
| 628 | _lead3 = new Lead | |||||
| 629 | { | |||||
| 630 | Comp anyName = "Fabrikam, Inc.", | |||||
| 631 | Firs tName = "A ndrew", | |||||
| 632 | Last Name = "Su llivan", | |||||
| 633 | Subj ect = "Act ivity Feed s Sample 3 " | |||||
| 634 | }; | |||||
| 635 | _service Context.Ad dObject(_l ead3); | |||||
| 636 | ||||||
| 637 | _service Context.Sa veChanges( ); | |||||
| 638 | ||||||
| 639 | var colu mnSet = ne w ColumnSe t(true); | |||||
| 640 | _lead1 = (Lead)_se rviceProxy .Retrieve( | |||||
| 641 | Lead .EntityLog icalName, _lead1.Id, columnSet ); | |||||
| 642 | _lead2 = (Lead)_se rviceProxy .Retrieve( | |||||
| 643 | Lead .EntityLog icalName, _lead2.Id, columnSet ); | |||||
| 644 | _lead3 = (Lead)_se rviceProxy .Retrieve( | |||||
| 645 | Lead .EntityLog icalName, _lead3.Id, columnSet ); | |||||
| 646 | ||||||
| 647 | Console. WriteLine( " The lea ds have be en created ."); | |||||
| 648 | } | |||||
| 649 | ||||||
| 650 | pr ivate void ActivateR uleConfig( msdyn_Post RuleConfig qualifyLe adRule) | |||||
| 651 | { | |||||
| 652 | _service Proxy.Exec ute(new Se tStateRequ est | |||||
| 653 | { | |||||
| 654 | Enti tyMoniker = qualifyL eadRule.To EntityRefe rence(), | |||||
| 655 | Stat e = new Op tionSetVal ue((int)ms dyn_PostRu leConfigSt ate.Active ), | |||||
| 656 | Stat us = new O ptionSetVa lue((int)m sdyn_postr uleconfig_ statuscode .Active) | |||||
| 657 | }); | |||||
| 658 | } | |||||
| 659 | ||||||
| 660 | pr ivate msdy n_PostConf ig CloneRe levantConf iguration( msdyn_Post Config con fig) | |||||
| 661 | { | |||||
| 662 | return n ew msdyn_P ostConfig | |||||
| 663 | { | |||||
| 664 | msdy n_Configur eWall = co nfig.msdyn _Configure Wall, | |||||
| 665 | msdy n_EntityNa me = confi g.msdyn_En tityName, | |||||
| 666 | msdy n_PostConf igId = con fig.msdyn_ PostConfig Id | |||||
| 667 | }; | |||||
| 668 | } | |||||
| 669 | ||||||
| 670 | pr ivate void PublishSy stemUserAn dLead() | |||||
| 671 | { | |||||
| 672 | // The s ystemuser and lead e ntities mu st be publ ished beca use otherw ise the | |||||
| 673 | // recor d walls on the respe ctive form s will not update. | |||||
| 674 | _service Proxy.Exec ute(new Pu blishXmlRe quest | |||||
| 675 | { | |||||
| 676 | Para meterXml = @" | |||||
| 677 | <importexp ortxml> | |||||
| 678 | <entit ies> | |||||
| 679 | <e ntity>syst emuser</en tity> | |||||
| 680 | <e ntity>lead </entity> | |||||
| 681 | </enti ties> | |||||
| 682 | </importex portxml>" | |||||
| 683 | }); | |||||
| 684 | Console. WriteLine( " The sys temuser an d lead ent ities were published ."); | |||||
| 685 | } | |||||
| 686 | ||||||
| 687 | pr ivate void DeleteReq uiredRecor ds(bool pr ompt) | |||||
| 688 | { | |||||
| 689 | var toBe Deleted = true; | |||||
| 690 | if (prom pt) | |||||
| 691 | { | |||||
| 692 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 693 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 694 | Stri ng answer = Console. ReadLine() ; | |||||
| 695 | if ( answer.Sta rtsWith("y ") || | |||||
| 696 | answer.Sta rtsWith("Y ") || | |||||
| 697 | answer == String.Emp ty) | |||||
| 698 | { | |||||
| 699 | toBeDelete d = true; | |||||
| 700 | } | |||||
| 701 | else | |||||
| 702 | { | |||||
| 703 | toBeDelete d = false; | |||||
| 704 | } | |||||
| 705 | } | |||||
| 706 | ||||||
| 707 | if (toBe Deleted) | |||||
| 708 | { | |||||
| 709 | // H andle reve rting the configurat ions appro priately - delete th em | |||||
| 710 | // i f they did not exist before. Otherwise update the m to their | |||||
| 711 | // o riginal va lues. Lea d must be reverted f irst since it must b e deleted | |||||
| 712 | // f irst if sy stemuser i s to be de leted. | |||||
| 713 | Reve rtPostConf ig(_origin alLeadConf ig, _leadC onfig); | |||||
| 714 | Reve rtPostConf ig(_origin alSystemUs erConfig, _systemuse rConfig); | |||||
| 715 | ||||||
| 716 | // R evert the form chang es. | |||||
| 717 | Publ ishSystemU serAndLead (); | |||||
| 718 | ||||||
| 719 | // D elete the leads. | |||||
| 720 | Dele teFromCont ext(_lead1 ); | |||||
| 721 | Dele teFromCont ext(_lead2 ); | |||||
| 722 | Dele teFromCont ext(_lead3 ); | |||||
| 723 | var saveResult = _servic eContext.S aveChanges (); | |||||
| 724 | Cons ole.WriteL ine(" The leads hav e been del eted."); | |||||
| 725 | ||||||
| 726 | Cons ole.WriteL ine(" The post foll ow records were dele ted with t he leads." ); | |||||
| 727 | Cons ole.WriteL ine(" Pos ts that we re related to leads were delet ed with th e leads.") ; | |||||
| 728 | ||||||
| 729 | // D elete post s that are n't regard ing entiti es that we re deleted . | |||||
| 730 | Dele teFromCont ext(_post1 ); | |||||
| 731 | Dele teFromCont ext(_post2 ); | |||||
| 732 | Dele teFromCont ext(_post3 ); | |||||
| 733 | Dele teFromCont ext(_post4 ); | |||||
| 734 | _ser viceContex t.SaveChan ges(); | |||||
| 735 | Cons ole.WriteL ine(" Pos ts that we ren't rega rding dele ted entiti es were de leted."); | |||||
| 736 | ||||||
| 737 | // D elete the generated entities. | |||||
| 738 | fore ach (var e ntityRef i n _generat edEntities ) | |||||
| 739 | { | |||||
| 740 | _servicePr oxy.Delete (entityRef .LogicalNa me, entity Ref.Id); | |||||
| 741 | } | |||||
| 742 | Cons ole.WriteL ine(" All generated entities have been deleted.") ; | |||||
| 743 | } | |||||
| 744 | } | |||||
| 745 | ||||||
| 746 | pr ivate void DeleteFro mContext(E ntity enti ty) | |||||
| 747 | { | |||||
| 748 | if (!_se rviceConte xt.IsAttac hed(entity )) | |||||
| 749 | { | |||||
| 750 | _ser viceContex t.Attach(e ntity); | |||||
| 751 | } | |||||
| 752 | _service Context.De leteObject (entity); | |||||
| 753 | _service Context.Sa veChanges( ); | |||||
| 754 | } | |||||
| 755 | ||||||
| 756 | pr ivate void RevertPos tConfig(ms dyn_PostCo nfig origi nalConfig, | |||||
| 757 | msdyn_Po stConfig n ewConfig) | |||||
| 758 | { | |||||
| 759 | if (orig inalConfig != null) | |||||
| 760 | { | |||||
| 761 | // R evert the rule confi gs. | |||||
| 762 | fore ach (var r ule in _po stRuleConf igs.Where( | |||||
| 763 | x => x.msd yn_PostCon figId.Id = = newConfi g.msdyn_Po stConfigId )) | |||||
| 764 | { | |||||
| 765 | // Set the state to the origin al value. | |||||
| 766 | _servicePr oxy.Execut e(new SetS tateReques t | |||||
| 767 | { | |||||
| 768 | Entity Moniker = rule.ToEnt ityReferen ce(), | |||||
| 769 | State = new Opti onSetValue ((int)rule .statecode ), | |||||
| 770 | Status = rule.st atuscode | |||||
| 771 | }); | |||||
| 772 | } | |||||
| 773 | ||||||
| 774 | // U pdate the config to the values from the original c onfig. | |||||
| 775 | // M ake sure t he context is not tr acking the new confi g and is t racking | |||||
| 776 | // t he origina l config. | |||||
| 777 | if ( !_serviceC ontext.IsA ttached(or iginalConf ig)) | |||||
| 778 | { | |||||
| 779 | if (_servi ceContext. IsAttached (newConfig )) | |||||
| 780 | { | |||||
| 781 | _servi ceContext. Detach(new Config); | |||||
| 782 | } | |||||
| 783 | _serviceCo ntext.Atta ch(origina lConfig); | |||||
| 784 | } | |||||
| 785 | _ser viceContex t.UpdateOb ject(origi nalConfig) ; | |||||
| 786 | _ser viceContex t.SaveChan ges(); | |||||
| 787 | Cons ole.WriteL ine( | |||||
| 788 | " The {0} activity feed confi guration w as reverte d.", | |||||
| 789 | originalCo nfig.msdyn _EntityNam e); | |||||
| 790 | } | |||||
| 791 | else | |||||
| 792 | { | |||||
| 793 | _ser viceProxy. Delete(new Config.Log icalName, | |||||
| 794 | newConfig. Id); | |||||
| 795 | Cons ole.WriteL ine( | |||||
| 796 | " The {0} activity feed confi guration w as deleted .", | |||||
| 797 | newConfig. msdyn_Enti tyName); | |||||
| 798 | } | |||||
| 799 | } | |||||
| 800 | ||||||
| 801 | #e ndregion H ow To Samp le Code | |||||
| 802 | ||||||
| 803 | #r egion Main method | |||||
| 804 | ||||||
| 805 | // / <summary > | |||||
| 806 | // / Standard Main() me thod used by most SD K samples. | |||||
| 807 | // / </summar y> | |||||
| 808 | // / <param n ame="args" ></param> | |||||
| 809 | st atic publi c void Mai n(string[] args) | |||||
| 810 | { | |||||
| 811 | try | |||||
| 812 | { | |||||
| 813 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 814 | // c redentials from the user. | |||||
| 815 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 816 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 817 | ||||||
| 818 | var app = new WorkingWit hActivityF eeds(); | |||||
| 819 | app. Run(config , true); | |||||
| 820 | } | |||||
| 821 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 822 | { | |||||
| 823 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 824 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 825 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 826 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 827 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 828 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 829 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 830 | } | |||||
| 831 | catch (S ystem.Time outExcepti on ex) | |||||
| 832 | { | |||||
| 833 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 834 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 835 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 836 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 837 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 838 | } | |||||
| 839 | catch (S ystem.Exce ption ex) | |||||
| 840 | { | |||||
| 841 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 842 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 843 | ||||||
| 844 | // D isplay the details o f the inne r exceptio n. | |||||
| 845 | if ( ex.InnerEx ception != null) | |||||
| 846 | { | |||||
| 847 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 848 | ||||||
| 849 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 850 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 851 | if (fe != null) | |||||
| 852 | { | |||||
| 853 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 854 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 855 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 856 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 857 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 858 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 859 | } | |||||
| 860 | } | |||||
| 861 | } | |||||
| 862 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 863 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 864 | finally | |||||
| 865 | { | |||||
| 866 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 867 | Cons ole.ReadLi ne(); | |||||
| 868 | } | |||||
| 869 | } | |||||
| 870 | #e ndregion M ain method | |||||
| 871 | } | |||||
| 872 | } | |||||
| 873 | //</snippe tWorkingWi thActivity Feeds> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.