Produced by Araxis Merge on 2/1/2017 2:56:21 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\RestListener | RestListener.cs | Tue Dec 20 19:51:42 2016 UTC |
| 2 | Wed Feb 1 19:56:21 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 313 |
| 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 RestListen er> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Collect ions.Gener ic; | |||||
| 20 | using Syst em.Service Model; | |||||
| 21 | using Syst em.Service Model.Web; | |||||
| 22 | using Syst em.Text; | |||||
| 23 | ||||||
| 24 | // This na mespace is found in the Micros oft.Xrm.Sd k.dll asse mbly | |||||
| 25 | // found i n the SDK\ bin folder . | |||||
| 26 | using Micr osoft.Xrm. Sdk; | |||||
| 27 | ||||||
| 28 | // This na mespace is found in Microsoft. ServiceBus .dll assem bly | |||||
| 29 | // found i n the Wind ows Azure SDK | |||||
| 30 | using Micr osoft.Serv iceBus; | |||||
| 31 | ||||||
| 32 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 33 | { | |||||
| 34 | /// <s ummary> | |||||
| 35 | /// Cr eates a RE ST endpoin t listenin g for mess ages from the Window s Azure Se rvice Bus. | |||||
| 36 | /// </ summary> | |||||
| 37 | public class Res tListener | |||||
| 38 | { | |||||
| 39 | #r egion How- To Sample Code | |||||
| 40 | ||||||
| 41 | // / <summary > | |||||
| 42 | // / The Exec ute method is called when a me ssage is p osted to t he Azure S ervice | |||||
| 43 | // / Bus. | |||||
| 44 | // / </summar y> | |||||
| 45 | [S erviceBeha vior] | |||||
| 46 | pr ivate clas s RestServ iceEndPoin t : IWebHt tpServiceE ndpointPlu gin | |||||
| 47 | { | |||||
| 48 | #region IRestServi ceEndpoint Plugin Mem ber | |||||
| 49 | ||||||
| 50 | /// <sum mary> | |||||
| 51 | /// This method is called wh en a messa ge is post ed to the Azure Serv ice Bus. | |||||
| 52 | /// </su mmary> | |||||
| 53 | /// <par am name="c ontext">Da ta for the request.< /param> | |||||
| 54 | /// <ret urns>A 'Su ccess' str ing.</retu rns> | |||||
| 55 | public s tring Exec ute(Remote ExecutionC ontext con text) | |||||
| 56 | { | |||||
| 57 | Util ity.Print( context); | |||||
| 58 | retu rn "Succes s"; | |||||
| 59 | } | |||||
| 60 | ||||||
| 61 | #endregi on | |||||
| 62 | } | |||||
| 63 | ||||||
| 64 | // / <summary > | |||||
| 65 | // / Prompts for requir ed informa tion and h osts a ser vice until the user ends the | |||||
| 66 | // / session. | |||||
| 67 | // / </summar y> | |||||
| 68 | pu blic void Run() | |||||
| 69 | { | |||||
| 70 | //<snipp etRestList ener1> | |||||
| 71 | ServiceB usEnvironm ent.System Connectivi ty.Mode = Connectivi tyMode.Htt p; | |||||
| 72 | ||||||
| 73 | Console. Write("Ent er your Az ure servic e namespac e: "); | |||||
| 74 | string s erviceName space = Co nsole.Read Line(); | |||||
| 75 | ||||||
| 76 | // The s ervice nam espace iss uer name t o use. If one hasn' t been set up | |||||
| 77 | // expli citly it w ill be the default i ssuer name listed on the servi ce | |||||
| 78 | // names pace. | |||||
| 79 | Console. Write("Ent er your se rvice name space issu er name: " ); | |||||
| 80 | string i ssuerName = Console. ReadLine() ; | |||||
| 81 | ||||||
| 82 | // Issue r secret i s the Wind ows Azure Service Bu s namespac e current management key. | |||||
| 83 | Console. Write("Ent er your se rvice name space issu er key: ") ; | |||||
| 84 | string i ssuerKey = Console.R eadLine(); | |||||
| 85 | ||||||
| 86 | // Input the same path that was specif ied in the Service B us Configu ration dia log | |||||
| 87 | // when registerin g the Azur e-aware pl ug-in with the Plug- in Registr ation tool . | |||||
| 88 | Console. Write("Ent er your en dpoint pat h: "); | |||||
| 89 | string s ervicePath = Console .ReadLine( ); | |||||
| 90 | ||||||
| 91 | // Lever age the Az ure API to create th e correct URI. | |||||
| 92 | Uri addr ess = Serv iceBusEnvi ronment.Cr eateServic eUri( | |||||
| 93 | Uri. UriSchemeH ttps, | |||||
| 94 | serv iceNamespa ce, | |||||
| 95 | serv icePath); | |||||
| 96 | ||||||
| 97 | Console. WriteLine( "The servi ce address is: " + a ddress); | |||||
| 98 | ||||||
| 99 | // Creat e the shar ed secret credential s object f or the end point matc hing the | |||||
| 100 | // Azure access co ntrol serv ices issue r | |||||
| 101 | var shar edSecretSe rviceBusCr edential = new Trans portClient EndpointBe havior() | |||||
| 102 | { | |||||
| 103 | Toke nProvider = TokenPro vider.Crea teSharedSe cretTokenP rovider(is suerName, issuerKey) | |||||
| 104 | }; | |||||
| 105 | ||||||
| 106 | // Using an HTTP b inding ins tead of a SOAP bindi ng for thi s RESTful endpoint. | |||||
| 107 | WebHttpR elayBindin g binding = new WebH ttpRelayBi nding(); | |||||
| 108 | binding. Security.M ode = EndT oEndWebHtt pSecurityM ode.Transp ort; | |||||
| 109 | ||||||
| 110 | // Creat e the serv ice host f or Azure t o post mes sages to. | |||||
| 111 | WebServi ceHost hos t = new We bServiceHo st(typeof( RestServic eEndPoint) ); | |||||
| 112 | host.Add ServiceEnd point(type of(IWebHtt pServiceEn dpointPlug in), bindi ng, addres s); | |||||
| 113 | ||||||
| 114 | // Creat e the Serv iceRegistr ySettings behavior f or the end point. | |||||
| 115 | var serv iceRegistr ySettings = new Serv iceRegistr ySettings( DiscoveryT ype.Public ); | |||||
| 116 | ||||||
| 117 | // Add t he service bus crede ntials to all endpoi nts specif ied in con figuration . | |||||
| 118 | ||||||
| 119 | foreach (var endpo int in hos t.Descript ion.Endpoi nts) | |||||
| 120 | { | |||||
| 121 | endp oint.Behav iors.Add(s erviceRegi strySettin gs); | |||||
| 122 | endp oint.Behav iors.Add(s haredSecre tServiceBu sCredentia l); | |||||
| 123 | } | |||||
| 124 | ||||||
| 125 | // Begin listening for messa ges posted to Azure. | |||||
| 126 | host.Ope n(); | |||||
| 127 | ||||||
| 128 | Console. WriteLine( Environmen t.NewLine + "Listeni ng for mes sages from Azure" + | |||||
| 129 | Envi ronment.Ne wLine + "P ress [Ente r] to exit "); | |||||
| 130 | ||||||
| 131 | // Keep the listen er open un til Enter is pressed . | |||||
| 132 | Console. ReadLine() ; | |||||
| 133 | ||||||
| 134 | Console. Write("Clo sing the s ervice hos t..."); | |||||
| 135 | host.Clo se(); | |||||
| 136 | Console. WriteLine( " done."); | |||||
| 137 | //</snip petRestLis tener1> | |||||
| 138 | } | |||||
| 139 | ||||||
| 140 | // / <summary > | |||||
| 141 | // / Containt s methods to display the Remot eExecution Context pr ovided whe n a | |||||
| 142 | // / message is posted to the Azu re Service Bus. | |||||
| 143 | // / </summar y> | |||||
| 144 | pr ivate stat ic class U tility | |||||
| 145 | { | |||||
| 146 | /// <sum mary> | |||||
| 147 | /// Writ es out the RemoteExe cutionCont ext to the Console. | |||||
| 148 | /// </su mmary> | |||||
| 149 | /// <par am name="c ontext"></ param> | |||||
| 150 | public s tatic void Print(Rem oteExecuti onContext context) | |||||
| 151 | { | |||||
| 152 | Cons ole.WriteL ine("----- -----"); | |||||
| 153 | if ( context == null) | |||||
| 154 | { | |||||
| 155 | Console.Wr iteLine("C ontext is null."); | |||||
| 156 | return; | |||||
| 157 | } | |||||
| 158 | ||||||
| 159 | Cons ole.WriteL ine("UserI d: {0}", c ontext.Use rId); | |||||
| 160 | Cons ole.WriteL ine("Organ izationId: {0}", con text.Organ izationId) ; | |||||
| 161 | Cons ole.WriteL ine("Organ izationNam e: {0}", c ontext.Org anizationN ame); | |||||
| 162 | Cons ole.WriteL ine("Messa geName: {0 }", contex t.MessageN ame); | |||||
| 163 | Cons ole.WriteL ine("Stage : {0}", co ntext.Stag e); | |||||
| 164 | Cons ole.WriteL ine("Mode: {0}", con text.Mode) ; | |||||
| 165 | Cons ole.WriteL ine("Prima ryEntityNa me: {0}", context.Pr imaryEntit yName); | |||||
| 166 | Cons ole.WriteL ine("Secon daryEntity Name: {0}" , context. SecondaryE ntityName) ; | |||||
| 167 | ||||||
| 168 | Cons ole.WriteL ine("Busin essUnitId: {0}", con text.Busin essUnitId) ; | |||||
| 169 | Cons ole.WriteL ine("Corre lationId: {0}", cont ext.Correl ationId); | |||||
| 170 | Cons ole.WriteL ine("Depth : {0}", co ntext.Dept h); | |||||
| 171 | Cons ole.WriteL ine("Initi atingUserI d: {0}", c ontext.Ini tiatingUse rId); | |||||
| 172 | Cons ole.WriteL ine("IsExe cutingOffl ine: {0}", context.I sExecuting Offline); | |||||
| 173 | Cons ole.WriteL ine("IsInT ransaction : {0}", co ntext.IsIn Transactio n); | |||||
| 174 | Cons ole.WriteL ine("Isola tionMode: {0}", cont ext.Isolat ionMode); | |||||
| 175 | Cons ole.WriteL ine("Mode: {0}", con text.Mode) ; | |||||
| 176 | Cons ole.WriteL ine("Opera tionCreate dOn: {0}", context.O perationCr eatedOn.To String()); | |||||
| 177 | Cons ole.WriteL ine("Opera tionId: {0 }", contex t.Operatio nId); | |||||
| 178 | Cons ole.WriteL ine("Prima ryEntityId : {0}", co ntext.Prim aryEntityI d); | |||||
| 179 | Cons ole.WriteL ine("Ownin gExtension LogicalNa me: {0}", context.Ow ningExtens ion.Logica lName); | |||||
| 180 | Cons ole.WriteL ine("Ownin gExtension Name: {0} ", context .OwningExt ension.Nam e); | |||||
| 181 | Cons ole.WriteL ine("Ownin gExtension Id: {0}", context.O wningExten sion.Id); | |||||
| 182 | Cons ole.WriteL ine("Share dVariables : {0}", (c ontext.Sha redVariabl es == null | |||||
| 183 | ? "NULL" : Serialize ParameterC ollection( context.Sh aredVariab les))); | |||||
| 184 | Cons ole.WriteL ine("Input Parameters : {0}", (c ontext.Inp utParamete rs == null | |||||
| 185 | ? "NULL" : Serialize ParameterC ollection( context.In putParamet ers))); | |||||
| 186 | Cons ole.WriteL ine("Outpu tParameter s: {0}", ( context.Ou tputParame ters == nu ll | |||||
| 187 | ? "NULL" : Serialize ParameterC ollection( context.Ou tputParame ters))); | |||||
| 188 | Cons ole.WriteL ine("PreEn tityImages : {0}", (c ontext.Pre EntityImag es == null | |||||
| 189 | ? "NULL" : Serialize EntityImag eCollectio n(context. PreEntityI mages))); | |||||
| 190 | Cons ole.WriteL ine("PostE ntityImage s: {0}", ( context.Po stEntityIm ages == nu ll | |||||
| 191 | ? "NULL" : Serialize EntityImag eCollectio n(context. PostEntity Images))); | |||||
| 192 | Cons ole.WriteL ine("----- -----"); | |||||
| 193 | } | |||||
| 194 | ||||||
| 195 | /// <sum mary> | |||||
| 196 | /// Writ es out the attribute s of an en tity. | |||||
| 197 | /// </su mmary> | |||||
| 198 | /// <par am name="e ">The enti ty to seri alize.</pa ram> | |||||
| 199 | /// <ret urns>A hum an readabl e represen tation of the entity .</returns > | |||||
| 200 | private static str ing Serial izeEntity( Entity e) | |||||
| 201 | { | |||||
| 202 | Stri ngBuilder sb = new S tringBuild er(); | |||||
| 203 | sb.A ppendForma t("{0} Log icalName: {1}{0} Ent ityId: {2} {0} Attrib utes: [", | |||||
| 204 | Environmen t.NewLine, | |||||
| 205 | e.LogicalN ame, | |||||
| 206 | e.Id); | |||||
| 207 | fore ach (KeyVa luePair<st ring, obje ct> parame ter in e.A ttributes) | |||||
| 208 | { | |||||
| 209 | sb.AppendF ormat("{0} : {1}; ", parameter. Key, param eter.Value ); | |||||
| 210 | } | |||||
| 211 | sb.A ppend("]") ; | |||||
| 212 | retu rn sb.ToSt ring(); | |||||
| 213 | } | |||||
| 214 | ||||||
| 215 | /// <sum mary> | |||||
| 216 | /// Flat tens a col lection in to a delim ited strin g. | |||||
| 217 | /// </su mmary> | |||||
| 218 | /// <par am name="p arameterCo llection"> The values must be o f type Ent ity | |||||
| 219 | /// to p rint the v alues.</pa ram> | |||||
| 220 | /// <ret urns>A str ing repres enting the collectio n passed i n.</return s> | |||||
| 221 | private static str ing Serial izeParamet erCollecti on(Paramet erCollecti on paramet erCollecti on) | |||||
| 222 | { | |||||
| 223 | Stri ngBuilder sb = new S tringBuild er(); | |||||
| 224 | fore ach (KeyVa luePair<st ring, obje ct> parame ter in par ameterColl ection) | |||||
| 225 | { | |||||
| 226 | Entity e = parameter .Value as Entity; | |||||
| 227 | if (e != n ull) | |||||
| 228 | { | |||||
| 229 | sb.App endFormat( "{0}: {1}" , paramete r.Key, Ser ializeEnti ty(e)); | |||||
| 230 | } | |||||
| 231 | else | |||||
| 232 | { | |||||
| 233 | sb.App endFormat( "{0}: {1}; ", parame ter.Key, p arameter.V alue); | |||||
| 234 | } | |||||
| 235 | } | |||||
| 236 | retu rn sb.ToSt ring(); | |||||
| 237 | } | |||||
| 238 | ||||||
| 239 | /// <sum mary> | |||||
| 240 | /// Flat tens a col lection in to a delim ited strin g. | |||||
| 241 | /// </su mmary> | |||||
| 242 | /// <par am name="e ntityImage Collection ">The coll ection to flatten.</ param> | |||||
| 243 | /// <ret urns>A str ing repres entation o f the coll ection.</r eturns> | |||||
| 244 | private static str ing Serial izeEntityI mageCollec tion(Entit yImageColl ection ent ityImageCo llection) | |||||
| 245 | { | |||||
| 246 | Stri ngBuilder sb = new S tringBuild er(); | |||||
| 247 | fore ach (KeyVa luePair<st ring, Enti ty> entity Image in e ntityImage Collection ) | |||||
| 248 | { | |||||
| 249 | sb.AppendF ormat("{0} {1}: {2}", Environme nt.NewLine , entityIm age.Key, | |||||
| 250 | Serial izeEntity( entityImag e.Value)); | |||||
| 251 | } | |||||
| 252 | retu rn sb.ToSt ring(); | |||||
| 253 | } | |||||
| 254 | } | |||||
| 255 | ||||||
| 256 | #e ndregion H ow-To Samp le Code | |||||
| 257 | ||||||
| 258 | // / <summary > | |||||
| 259 | // / Standard Main() me thod used by most SD K samples. | |||||
| 260 | // / </summar y> | |||||
| 261 | st atic publi c void Mai n() | |||||
| 262 | { | |||||
| 263 | try | |||||
| 264 | { | |||||
| 265 | Rest Listener a pp = new R estListene r(); | |||||
| 266 | app. Run(); | |||||
| 267 | } | |||||
| 268 | catch (F aultExcept ion<Servic eEndpointF ault> ex) | |||||
| 269 | { | |||||
| 270 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 271 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 272 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 273 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : "Has Inner Faul t"); | |||||
| 274 | } | |||||
| 275 | catch (S ystem.Time outExcepti on ex) | |||||
| 276 | { | |||||
| 277 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 278 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 279 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 280 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 281 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 282 | } | |||||
| 283 | catch (S ystem.Exce ption ex) | |||||
| 284 | { | |||||
| 285 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 286 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 287 | ||||||
| 288 | // D isplay the details o f the inne r exceptio n. | |||||
| 289 | if ( ex.InnerEx ception != null) | |||||
| 290 | { | |||||
| 291 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 292 | ||||||
| 293 | FaultExcep tion<Servi ceEndpoint Fault> fe = ex.Inner Exception | |||||
| 294 | as Fau ltExceptio n<ServiceE ndpointFau lt>; | |||||
| 295 | if (fe != null) | |||||
| 296 | { | |||||
| 297 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 298 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 299 | nu ll == ex.I nnerExcept ion.Messag e ? "No In ner Fault" : "Has In ner Fault" ); | |||||
| 300 | } | |||||
| 301 | } | |||||
| 302 | } | |||||
| 303 | ||||||
| 304 | finally | |||||
| 305 | { | |||||
| 306 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 307 | Cons ole.ReadLi ne(); | |||||
| 308 | } | |||||
| 309 | } | |||||
| 310 | } | |||||
| 311 | } | |||||
| 312 | ||||||
| 313 | //</snippe tRestListe ner> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.