Produced by Araxis Merge on 2/1/2017 2:56:20 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\Azure\PersistentQueueListener | PersistentQueueListener.cs | Tue Dec 20 19:51:42 2016 UTC |
| 2 | Wed Feb 1 19:56:20 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 328 |
| 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 Persistent QueueListe ner> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Service Model; | |||||
| 20 | using Syst em.Service Model.Chan nels; | |||||
| 21 | using Syst em.Collect ions.Gener ic; | |||||
| 22 | using Syst em.Text; | |||||
| 23 | ||||||
| 24 | using Micr osoft.Serv iceBus; | |||||
| 25 | using Micr osoft.Serv iceBus.Mes saging; | |||||
| 26 | using Micr osoft.Xrm. Sdk; | |||||
| 27 | ||||||
| 28 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 29 | { | |||||
| 30 | class Program | |||||
| 31 | { | |||||
| 32 | pu blic stati c void Mai n(string[] args) | |||||
| 33 | { | |||||
| 34 | Consumer consumer = new Cons umer(); | |||||
| 35 | ||||||
| 36 | consumer .CreateQue ueClient() ; | |||||
| 37 | consumer .ProcessMe ssages(); | |||||
| 38 | consumer .DeleteQue ue(); | |||||
| 39 | } | |||||
| 40 | } | |||||
| 41 | ||||||
| 42 | intern al class C onsumer | |||||
| 43 | { | |||||
| 44 | pr ivate cons t String M yQueuePath = "MyQueu e"; | |||||
| 45 | pr ivate Queu eDescripti on queueDe scription; | |||||
| 46 | pr ivate Queu eClient qu eueClient; | |||||
| 47 | pr ivate Uri namespaceU ri; | |||||
| 48 | pr ivate Tran sportClien tEndpointB ehavior cr edential; | |||||
| 49 | ||||||
| 50 | pu blic Consu mer() | |||||
| 51 | { | |||||
| 52 | Console. Write("You r Service Namespace: "); | |||||
| 53 | string s erviceName space = Co nsole.Read Line(); | |||||
| 54 | Console. Write("You r Issuer N ame: "); | |||||
| 55 | string i ssuerName = Console. ReadLine() ; | |||||
| 56 | Console. Write("You r Issuer S ecret: "); | |||||
| 57 | string i ssuerSecre t = Consol e.ReadLine (); | |||||
| 58 | ||||||
| 59 | // Confi gure queue settings. | |||||
| 60 | this.que ueDescript ion = new QueueDescr iption(MyQ ueuePath); | |||||
| 61 | // Setti ng Max Siz e and TTL for demons tration pu rpose | |||||
| 62 | // but c an be chan ged per us er discret ion to sui te their s ystem need s. | |||||
| 63 | // Refer service b us documen tation to understand the limit ations. | |||||
| 64 | // Setti ng Queue m ax size to 1GB where as defaul t Max Size is 5GB. | |||||
| 65 | this.que ueDescript ion.MaxSiz eInMegabyt es = 1024; | |||||
| 66 | // Setti ng message TTL to 5 days where as defaul t TTL is 1 4 days. | |||||
| 67 | this.que ueDescript ion.Defaul tMessageTi meToLive = TimeSpan. FromDays(5 ); | |||||
| 68 | ||||||
| 69 | // Creat e manageme nt credent ials. | |||||
| 70 | this.cre dential = new Transp ortClientE ndpointBeh avior() | |||||
| 71 | { | |||||
| 72 | Toke nProvider = TokenPro vider.Crea teSharedSe cretTokenP rovider(is suerName, issuerSecr et) | |||||
| 73 | }; | |||||
| 74 | ||||||
| 75 | // Creat e the URI for the qu eue. | |||||
| 76 | this.nam espaceUri = ServiceB usEnvironm ent.Create ServiceUri ("sb", ser viceNamesp ace, Strin g.Empty); | |||||
| 77 | Console. WriteLine( "Service B us Namespa ce Uri add ress '{0}' ", this.na mespaceUri .AbsoluteU ri); | |||||
| 78 | } | |||||
| 79 | ||||||
| 80 | pu blic void CreateQueu eClient() | |||||
| 81 | { | |||||
| 82 | // get t he existin g queue or create a new queue if it does n't exist. | |||||
| 83 | this.que ueClient = GetOrCrea teQueue(na mespaceUri , this.cre dential.To kenProvide r); | |||||
| 84 | } | |||||
| 85 | ||||||
| 86 | pu blic void ProcessMes sages() | |||||
| 87 | { | |||||
| 88 | // Get r eceive mod e (PeekLoc k or Recei veAndDelet e) from qu eueClient. | |||||
| 89 | ReceiveM ode mode = this.queu eClient.Mo de; | |||||
| 90 | while (t rue) | |||||
| 91 | { | |||||
| 92 | Cons ole.Write( "Press [En ter] to re trieve a m essage fro m the queu e (type qu it to exit ): "); | |||||
| 93 | stri ng line = Console.Re adLine(); | |||||
| 94 | ||||||
| 95 | if ( !string.Is NullOrEmpt y(line) && string.Eq uals(line, "quit", S tringCompa rison.Ordi nalIgnoreC ase)) | |||||
| 96 | { | |||||
| 97 | break; | |||||
| 98 | } | |||||
| 99 | ||||||
| 100 | // R etrieve a message fr om the que ue. | |||||
| 101 | Cons ole.WriteL ine("Waiti ng for a m essage fro m the queu e... "); | |||||
| 102 | Brok eredMessag e message; | |||||
| 103 | try | |||||
| 104 | { | |||||
| 105 | message = this.queue Client.Rec eive(); | |||||
| 106 | // Check i f the mess age receiv ed. | |||||
| 107 | if (messag e != null) | |||||
| 108 | { | |||||
| 109 | try | |||||
| 110 | { | |||||
| 111 | // Verify En tityLogica lName and RequestNam e message properties | |||||
| 112 | // to only p rocess spe cific mess age sent f rom Micros oft Dynami cs CRM. | |||||
| 113 | st ring keyRo ot = "http ://schemas .microsoft .com/xrm/2 011/Claims /"; | |||||
| 114 | st ring entit yLogicalNa meKey = "E ntityLogic alName"; | |||||
| 115 | st ring reque stNameKey = "Request Name"; | |||||
| 116 | ob ject entit yLogicalNa meValue; | |||||
| 117 | ob ject reque stNameValu e; | |||||
| 118 | me ssage.Prop erties.Try GetValue(k eyRoot + e ntityLogic alNameKey, out entit yLogicalNa meValue); | |||||
| 119 | me ssage.Prop erties.Try GetValue(k eyRoot + r equestName Key, out r equestName Value); | |||||
| 120 | ||||||
| 121 | // Filter me ssage with specific message pr operties. i.e. Entit yLogicalNa me=letter and Reques tName=Crea te | |||||
| 122 | if (entityLo gicalNameV alue != nu ll && requ estNameVal ue != null ) | |||||
| 123 | { | |||||
| 124 | if (enti tyLogicalN ameValue.T oString() == "letter " && reque stNameValu e.ToString () == "Cre ate") | |||||
| 125 | { | |||||
| 126 | Cons ole.WriteL ine("----- ---------- ---------- -------"); | |||||
| 127 | Cons ole.WriteL ine(string .Format("M essage rec eived: Id = {0}", me ssage.Mess ageId)); | |||||
| 128 | // D isplay mes sage prope rties that are set o n the brok ered messa ge. | |||||
| 129 | Util ity.PrintM essageProp erties(mes sage.Prope rties); | |||||
| 130 | // D isplay bod y details. | |||||
| 131 | Util ity.Print( message.Ge tBody<Remo teExecutio nContext>( )); | |||||
| 132 | Cons ole.WriteL ine("----- ---------- ---------- -------"); | |||||
| 133 | } | |||||
| 134 | else | |||||
| 135 | { | |||||
| 136 | cont inue; | |||||
| 137 | } | |||||
| 138 | } | |||||
| 139 | el se | |||||
| 140 | { | |||||
| 141 | continue ; | |||||
| 142 | } | |||||
| 143 | // If receiv e mode is PeekLock t hen set me ssage comp lete to re move messa ge from qu eue. | |||||
| 144 | if (mode == ReceiveMod e.PeekLock ) | |||||
| 145 | { | |||||
| 146 | message. Complete() ; | |||||
| 147 | } | |||||
| 148 | } | |||||
| 149 | catch (System.Ex ception ex ) | |||||
| 150 | { | |||||
| 151 | // Indicate a problem, unlock me ssage in q ueue. | |||||
| 152 | if (mode == ReceiveMod e.PeekLock ) | |||||
| 153 | { | |||||
| 154 | message. Abandon(); | |||||
| 155 | } | |||||
| 156 | Co nsole.Writ eLine(ex.M essage); | |||||
| 157 | co ntinue; | |||||
| 158 | } | |||||
| 159 | } | |||||
| 160 | else | |||||
| 161 | { | |||||
| 162 | break; | |||||
| 163 | } | |||||
| 164 | } | |||||
| 165 | catc h (System. TimeoutExc eption e) | |||||
| 166 | { | |||||
| 167 | Console.Wr iteLine(e. Message); | |||||
| 168 | continue; | |||||
| 169 | } | |||||
| 170 | catc h (System. ServiceMod el.FaultEx ception e) | |||||
| 171 | { | |||||
| 172 | Console.Wr iteLine(e. Message); | |||||
| 173 | continue; | |||||
| 174 | } | |||||
| 175 | } | |||||
| 176 | } | |||||
| 177 | ||||||
| 178 | pu blic void DeleteQueu e() | |||||
| 179 | { | |||||
| 180 | DeleteQu eueInterna l(namespac eUri, MyQu euePath, c redential. TokenProvi der); | |||||
| 181 | } | |||||
| 182 | ||||||
| 183 | pr ivate void DeleteQue ueInternal (Uri addre ss, string path, Tok enProvider tokenProv ider) | |||||
| 184 | { | |||||
| 185 | var sett ings = new Namespace ManagerSet tings() { TokenProvi der = toke nProvider }; | |||||
| 186 | var name spaceClien t = new Se rviceBus.N amespaceMa nager(addr ess, setti ngs); | |||||
| 187 | try | |||||
| 188 | { | |||||
| 189 | name spaceClien t.DeleteQu eue(path); | |||||
| 190 | Cons ole.WriteL ine("Queue deleted s uccessfull y."); | |||||
| 191 | } | |||||
| 192 | catch (F aultExcept ion e) | |||||
| 193 | { | |||||
| 194 | Cons ole.WriteL ine("Excep tion when deleting q ueue.. {0} ", e); | |||||
| 195 | } | |||||
| 196 | } | |||||
| 197 | ||||||
| 198 | pr ivate Queu eClient Ge tOrCreateQ ueue(Uri n amespaceUr i, TokenPr ovider tok enProvider ) | |||||
| 199 | { | |||||
| 200 | Namespac eManager n amespaceCl ient = new Namespace Manager(na mespaceUri , tokenPro vider); | |||||
| 201 | ||||||
| 202 | // Creat e queue if not alrea dy exist. | |||||
| 203 | if (!nam espaceClie nt.QueueEx ists(MyQue uePath)) | |||||
| 204 | { | |||||
| 205 | name spaceClien t.CreateQu eue(this.q ueueDescri ption); | |||||
| 206 | Cons ole.WriteL ine("Queue created." ); | |||||
| 207 | } | |||||
| 208 | else | |||||
| 209 | { | |||||
| 210 | Cons ole.WriteL ine("Queue already e xists."); | |||||
| 211 | } | |||||
| 212 | ||||||
| 213 | Messagin gFactory f actory = M essagingFa ctory.Crea te(namespa ceUri, tok enProvider ); | |||||
| 214 | Console. WriteLine( "Creating queue clie nt..."); | |||||
| 215 | return f actory.Cre ateQueueCl ient(MyQue uePath, Re ceiveMode. PeekLock); | |||||
| 216 | } | |||||
| 217 | } | |||||
| 218 | ||||||
| 219 | intern al static class Util ity | |||||
| 220 | { | |||||
| 221 | pu blic stati c void Pri nt(RemoteE xecutionCo ntext cont ext) | |||||
| 222 | { | |||||
| 223 | if (cont ext == nul l) | |||||
| 224 | { | |||||
| 225 | Cons ole.WriteL ine("Conte xt is null ."); | |||||
| 226 | retu rn; | |||||
| 227 | } | |||||
| 228 | ||||||
| 229 | Console. WriteLine( "UserId: { 0}", conte xt.UserId) ; | |||||
| 230 | Console. WriteLine( "Organizat ionId: {0} ", context .Organizat ionId); | |||||
| 231 | Console. WriteLine( "Organizat ionName: { 0}", conte xt.Organiz ationName) ; | |||||
| 232 | Console. WriteLine( "MessageNa me: {0}", context.Me ssageName) ; | |||||
| 233 | Console. WriteLine( "Stage: {0 }", contex t.Stage); | |||||
| 234 | Console. WriteLine( "Mode: {0} ", context .Mode); | |||||
| 235 | Console. WriteLine( "PrimaryEn tityName: {0}", cont ext.Primar yEntityNam e); | |||||
| 236 | Console. WriteLine( "Secondary EntityName : {0}", co ntext.Seco ndaryEntit yName); | |||||
| 237 | ||||||
| 238 | Console. WriteLine( "BusinessU nitId: {0} ", context .BusinessU nitId); | |||||
| 239 | Console. WriteLine( "Correlati onId: {0}" , context. Correlatio nId); | |||||
| 240 | Console. WriteLine( "Depth: {0 }", contex t.Depth); | |||||
| 241 | Console. WriteLine( "Initiatin gUserId: { 0}", conte xt.Initiat ingUserId) ; | |||||
| 242 | Console. WriteLine( "IsExecuti ngOffline: {0}", con text.IsExe cutingOffl ine); | |||||
| 243 | Console. WriteLine( "IsInTrans action: {0 }", contex t.IsInTran saction); | |||||
| 244 | Console. WriteLine( "Isolation Mode: {0}" , context. IsolationM ode); | |||||
| 245 | Console. WriteLine( "Mode: {0} ", context .Mode); | |||||
| 246 | Console. WriteLine( "Operation CreatedOn: {0}", con text.Opera tionCreate dOn.ToStri ng()); | |||||
| 247 | Console. WriteLine( "Operation Id: {0}", context.Op erationId) ; | |||||
| 248 | Console. WriteLine( "PrimaryEn tityId: {0 }", contex t.PrimaryE ntityId); | |||||
| 249 | Console. WriteLine( "OwningExt ension Log icalName: {0}", cont ext.Owning Extension. LogicalNam e); | |||||
| 250 | Console. WriteLine( "OwningExt ension Nam e: {0}", c ontext.Own ingExtensi on.Name); | |||||
| 251 | Console. WriteLine( "OwningExt ension Id: {0}", con text.Ownin gExtension .Id); | |||||
| 252 | Console. WriteLine( "SharedVar iables: {0 }", (conte xt.SharedV ariables = = null ? " NULL" : | |||||
| 253 | Seri alizeParam eterCollec tion(conte xt.SharedV ariables)) ); | |||||
| 254 | Console. WriteLine( "InputPara meters: {0 }", (conte xt.InputPa rameters = = null ? " NULL" : | |||||
| 255 | Seri alizeParam eterCollec tion(conte xt.InputPa rameters)) ); | |||||
| 256 | Console. WriteLine( "OutputPar ameters: { 0}", (cont ext.Output Parameters == null ? "NULL" : | |||||
| 257 | Seri alizeParam eterCollec tion(conte xt.OutputP arameters) )); | |||||
| 258 | Console. WriteLine( "PreEntity Images: {0 }", (conte xt.PreEnti tyImages = = null ? " NULL" : | |||||
| 259 | Seri alizeEntit yImageColl ection(con text.PreEn tityImages ))); | |||||
| 260 | Console. WriteLine( "PostEntit yImages: { 0}", (cont ext.PostEn tityImages == null ? "NULL" : | |||||
| 261 | Seri alizeEntit yImageColl ection(con text.PostE ntityImage s))); | |||||
| 262 | } | |||||
| 263 | ||||||
| 264 | #r egion Priv ate method s. | |||||
| 265 | pr ivate stat ic string SerializeE ntity(Enti ty e) | |||||
| 266 | { | |||||
| 267 | StringBu ilder sb = new Strin gBuilder() ; | |||||
| 268 | sb.Appen d(Environm ent.NewLin e); | |||||
| 269 | sb.Appen d(" Logica lName: " + e.Logical Name); | |||||
| 270 | sb.Appen d(Environm ent.NewLin e); | |||||
| 271 | sb.Appen d(" Entity Id: " + e. Id); | |||||
| 272 | sb.Appen d(Environm ent.NewLin e); | |||||
| 273 | sb.Appen d(" Attrib utes: ["); | |||||
| 274 | foreach (KeyValueP air<string , object> parameter in e.Attri butes) | |||||
| 275 | { | |||||
| 276 | sb.A ppend(para meter.Key + ": " + p arameter.V alue + "; "); | |||||
| 277 | } | |||||
| 278 | sb.Appen d("]"); | |||||
| 279 | return s b.ToString (); | |||||
| 280 | } | |||||
| 281 | ||||||
| 282 | pr ivate stat ic string SerializeP arameterCo llection(P arameterCo llection p arameterCo llection) | |||||
| 283 | { | |||||
| 284 | StringBu ilder sb = new Strin gBuilder() ; | |||||
| 285 | foreach (KeyValueP air<string , object> parameter in paramet erCollecti on) | |||||
| 286 | { | |||||
| 287 | if ( parameter. Value != n ull && par ameter.Val ue.GetType () == type of(Entity) ) | |||||
| 288 | { | |||||
| 289 | Entity e = (Entity)p arameter.V alue; | |||||
| 290 | sb.Append( parameter. Key + ": " + Seriali zeEntity(e )); | |||||
| 291 | } | |||||
| 292 | else | |||||
| 293 | { | |||||
| 294 | sb.Append( parameter. Key + ": " + paramet er.Value + "; "); | |||||
| 295 | } | |||||
| 296 | } | |||||
| 297 | return s b.ToString (); | |||||
| 298 | } | |||||
| 299 | pr ivate stat ic string SerializeE ntityImage Collection (EntityIma geCollecti on entityI mageCollec tion) | |||||
| 300 | { | |||||
| 301 | StringBu ilder sb = new Strin gBuilder() ; | |||||
| 302 | foreach (KeyValueP air<string , Entity> entityImag e in entit yImageColl ection) | |||||
| 303 | { | |||||
| 304 | sb.A ppend(Envi ronment.Ne wLine); | |||||
| 305 | sb.A ppend(enti tyImage.Ke y + ": " + Serialize Entity(ent ityImage.V alue)); | |||||
| 306 | } | |||||
| 307 | return s b.ToString (); | |||||
| 308 | } | |||||
| 309 | #e ndregion | |||||
| 310 | ||||||
| 311 | in ternal sta tic void P rintMessag ePropertie s(IDiction ary<string , object> iDictionar y) | |||||
| 312 | { | |||||
| 313 | if (iDic tionary.Co unt == 0) | |||||
| 314 | { | |||||
| 315 | Cons ole.WriteL ine("No Me ssage prop erties fou nd."); | |||||
| 316 | retu rn; | |||||
| 317 | } | |||||
| 318 | foreach (var item in iDictio nary) | |||||
| 319 | { | |||||
| 320 | Stri ng key = ( item.Key ! = null) ? item.Key.T oString() : ""; | |||||
| 321 | Stri ng value = (item.Val ue != null )? item.Va lue.ToStri ng() : ""; | |||||
| 322 | Cons ole.WriteL ine( key + " " + val ue); | |||||
| 323 | } | |||||
| 324 | } | |||||
| 325 | } | |||||
| 326 | } | |||||
| 327 | //</snippe tPersisten tQueueList ener> | |||||
| 328 |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.