Produced by Araxis Merge on 2/1/2017 2:56:49 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\ModernAndMobileApps\ModernOdataApp | CurrentEnvironment.cs | Tue Dec 20 19:51:47 2016 UTC |
| 2 | Wed Feb 1 19:56:49 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 172 |
| 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 | // | |||||
| 3 | // This f ile is par t of the M icrosoft D ynamics CR M SDK Code Samples. | |||||
| 4 | // | |||||
| 5 | // Copyri ght (C) Mi crosoft Co rporation. All righ ts reserve d. | |||||
| 6 | // | |||||
| 7 | // This s ource code is intend ed only as a supplem ent to Mic rosoft | |||||
| 8 | // Develo pment Tool s and/or o nline docu mentation. See thes e other | |||||
| 9 | // materi als for de tailed inf ormation r egarding M icrosoft c ode sample s. | |||||
| 10 | // | |||||
| 11 | // THIS C ODE AND IN FORMATION ARE PROVID ED "AS IS" WITHOUT W ARRANTY OF ANY | |||||
| 12 | // KIND, EITHER EXP RESSED OR IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E | |||||
| 13 | // IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR A | |||||
| 14 | // PARTIC ULAR PURPO SE. | |||||
| 15 | // | |||||
| 16 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 17 | ||||||
| 18 | //<snippet ModernOdat aApp> | |||||
| 19 | using Micr osoft.Iden tityModel. Clients.Ac tiveDirect ory; | |||||
| 20 | using Syst em; | |||||
| 21 | using Syst em.Threadi ng.Tasks; | |||||
| 22 | using Wind ows.UI.Pop ups; | |||||
| 23 | using Wind ows.Securi ty.Authent ication.We b; | |||||
| 24 | using Syst em.Net; | |||||
| 25 | using Syst em.Threadi ng; | |||||
| 26 | using Syst em.IO; | |||||
| 27 | using Syst em.Text; | |||||
| 28 | ||||||
| 29 | namespace ModernOdat aApp | |||||
| 30 | { | |||||
| 31 | /// <s ummary> | |||||
| 32 | /// Ma nages auth entication with the organizati on web ser vice. | |||||
| 33 | /// </ summary> | |||||
| 34 | public static cl ass Curren tEnvironme nt | |||||
| 35 | { | |||||
| 36 | # region Cla ss Level M embers | |||||
| 37 | ||||||
| 38 | pr ivate stat ic Authent icationCon text _auth entication Context; | |||||
| 39 | ||||||
| 40 | // TODO Set these stri ng values as appropp riate for your app r egistratio n and orga nization. | |||||
| 41 | // For more informatio n, see the SDK topic "Walkthro ugh: Regis ter an app with Acti ve Directo ry". | |||||
| 42 | pr ivate cons t string _ clientID = "893262be -fbdc-4556 -9325-9f86 3b69495b"; | |||||
| 43 | pu blic const string Cr mServiceUr l = "https ://my-doma in.crm.dyn amics.com/ "; | |||||
| 44 | ||||||
| 45 | # endregion | |||||
| 46 | ||||||
| 47 | // <summary> | |||||
| 48 | // / Perform any requir ed app ini tializatio n. | |||||
| 49 | // / This is where auth entication with Acti ve Directo ry is perf ormed. | |||||
| 50 | pu blic stati c async Ta sk<string> Initializ e() | |||||
| 51 | { | |||||
| 52 | Uri serv iceUrl = n ew System. Uri(CrmSer viceUrl + "/XRMServi ces/2011/O rganizatio n.svc/web? SdkClientV ersion=6.1 .0000.0000 "); | |||||
| 53 | ||||||
| 54 | // Dyami cs CRM Onl ine OAuth URL. | |||||
| 55 | string _ oauthUrl = Discovery Authority( serviceUrl ); | |||||
| 56 | ||||||
| 57 | // Obtai n the redi rect URL f or the app . This is only neede d for app registrati on. | |||||
| 58 | Uri redi rectUri = WebAuthent icationBro ker.GetCur rentApplic ationCallb ackUri(); | |||||
| 59 | ||||||
| 60 | // Obtai n an authe ntication token to a ccess the web servic e. | |||||
| 61 | _authent icationCon text = new Authentic ationConte xt(_oauthU rl, false) ; | |||||
| 62 | Authenti cationResu lt result = await _a uthenticat ionContext .AcquireTo kenAsync(C rmServiceU rl, _clien tID, redir ectUri); | |||||
| 63 | ||||||
| 64 | // Verif y that an access tok en was suc cessfully acquired. | |||||
| 65 | if (resu lt.Status != Authent icationSta tus.Succes s) | |||||
| 66 | { | |||||
| 67 | if ( result.Err or == "aut henticatio n_failed") | |||||
| 68 | { | |||||
| 69 | // Try aga in. | |||||
| 70 | _authentic ationConte xt = new A uthenticat ionContext (_oauthUrl , false); | |||||
| 71 | result = a wait _auth entication Context.Ac quireToken Async(CrmS erviceUrl, _clientID , redirect Uri); | |||||
| 72 | } | |||||
| 73 | else | |||||
| 74 | { | |||||
| 75 | DisplayErr orWhenAcqu ireTokenFa ils(result ); | |||||
| 76 | } | |||||
| 77 | } | |||||
| 78 | return r esult.Acce ssToken; | |||||
| 79 | } | |||||
| 80 | ||||||
| 81 | // <snippetMo dernOdataA ppAuthDisc overy> | |||||
| 82 | // / <summary > | |||||
| 83 | // / Discover the authe ntication authority. | |||||
| 84 | // / </summar y> | |||||
| 85 | // / <param n ame="servi ceUrl">The URL of th e organiza tion's SOA P endpoint . </param> | |||||
| 86 | // / <returns >The autho rity URL.< /returns> | |||||
| 87 | // / <remarks >The servi ce URL mus t contain the SdkCli ent proper ty.</remar ks> | |||||
| 88 | // / <example >https://c ontoso.crm .dynamics. com/XRMSer vices/2011 /Organizat ion.svc/we b?SdkClien tVersion=6 .1.0.533;< /example> | |||||
| 89 | pu blic stati c string D iscoveryAu thority(Ur i serviceU rl) | |||||
| 90 | { | |||||
| 91 | // Use A uthenticat ionParamet ers to sen d a reques t to the o rganizatio n's endpoi nt and | |||||
| 92 | // recei ve tenant informatio n in the 4 01 challen ge. | |||||
| 93 | Microsof t.Identity Model.Clie nts.Active Directory. Authentica tionParame ters param eters = nu ll; | |||||
| 94 | HttpWebR esponse re sponse = n ull; | |||||
| 95 | try | |||||
| 96 | { | |||||
| 97 | // C reate a we b request where the authorizat ion header contains the word " Bearer". | |||||
| 98 | Http WebRequest httpWebRe quest = (H ttpWebRequ est)WebReq uest.Creat e(serviceU rl); | |||||
| 99 | ||||||
| 100 | // T he respons e is to be encoded. | |||||
| 101 | http WebRequest .ContentTy pe = "appl ication/x- www-form-u rlencoded" ; | |||||
| 102 | resp onse = (Ht tpWebRespo nse)httpWe bRequest.G etResponse (); | |||||
| 103 | } | |||||
| 104 | ||||||
| 105 | catch (W ebExceptio n ex) | |||||
| 106 | { | |||||
| 107 | resp onse = (Ht tpWebRespo nse)ex.Res ponse; | |||||
| 108 | ||||||
| 109 | // A 401 error should be returned. Extract a ny paramet ers from t he respons e. | |||||
| 110 | // T he respons e should c ontain an authorizat ion_uri pa rameter. | |||||
| 111 | para meters = M icrosoft.I dentityMod el.Clients .ActiveDir ectory.Aut henticatio nParameter s. | |||||
| 112 | CreateFrom ResponseAu thenticate Header((re sponse.Hea ders)["WWW -Authentic ate"]); | |||||
| 113 | } | |||||
| 114 | finally | |||||
| 115 | { | |||||
| 116 | if ( response ! = null) | |||||
| 117 | response.D ispose(); | |||||
| 118 | } | |||||
| 119 | // Retur n the auth ority URL. | |||||
| 120 | return p arameters. Authority; | |||||
| 121 | } | |||||
| 122 | // </snippetM odernOdata AppAuthDis covery> | |||||
| 123 | ||||||
| 124 | // / <summary > | |||||
| 125 | // / Returns a response from an I nternet re source. | |||||
| 126 | // / </summar y> | |||||
| 127 | pu blic stati c WebRespo nse GetRes ponse(this WebReques t request) | |||||
| 128 | { | |||||
| 129 | AutoRese tEvent aut oResetEven t = new Au toResetEve nt(false); | |||||
| 130 | IAsyncRe sult async Result = r equest.Beg inGetRespo nse(r => a utoResetEv ent.Set(), null); | |||||
| 131 | ||||||
| 132 | // Wait until the call is fi nished | |||||
| 133 | autoRese tEvent.Wai tOne(Defau ltRequestT imeout); | |||||
| 134 | return r equest.End GetRespons e(asyncRes ult); | |||||
| 135 | } | |||||
| 136 | ||||||
| 137 | // / <summary > | |||||
| 138 | // / Get the DefaultReq uestTimeou t from the server. | |||||
| 139 | // / </summar y> | |||||
| 140 | pu blic stati c TimeSpan DefaultRe questTimeo ut { get; set; } | |||||
| 141 | ||||||
| 142 | // / <summary > | |||||
| 143 | // / Display an error m essage to the user. | |||||
| 144 | // / </summar y> | |||||
| 145 | // / <param n ame="resul t">The aut henticatio n result r eturned fr om Acquire TokenAsync ().</param > | |||||
| 146 | pr ivate stat ic async v oid Displa yErrorWhen AcquireTok enFails(Au thenticati onResult r esult) | |||||
| 147 | { | |||||
| 148 | MessageD ialog dial og; | |||||
| 149 | ||||||
| 150 | switch ( result.Err or) | |||||
| 151 | { | |||||
| 152 | case "authenti cation_can celed": | |||||
| 153 | // User ca ncelled, s o no need to display a message . | |||||
| 154 | break; | |||||
| 155 | case "temporar ily_unavai lable": | |||||
| 156 | case "server_e rror": | |||||
| 157 | dialog = n ew Message Dialog("Pl ease retry the opera tion. If t he error c ontinues, please con tact your administra tor.", | |||||
| 158 | "Sorry , an error has occur red."); | |||||
| 159 | await dial og.ShowAsy nc(); | |||||
| 160 | break; | |||||
| 161 | defa ult: | |||||
| 162 | // An erro r occurred when acqu iring a to ken so sho w the erro r descript ion in a M essageDial og. | |||||
| 163 | dialog = n ew Message Dialog(str ing.Format ( | |||||
| 164 | "If th e error co ntinues, p lease cont act your a dministrat or.\n\nErr or: {0}\n\ nError Des cription:\ n\n{1}", | |||||
| 165 | result .Error, re sult.Error Descriptio n), "Sorry , an error has occur red."); | |||||
| 166 | await dial og.ShowAsy nc(); | |||||
| 167 | break; | |||||
| 168 | } | |||||
| 169 | } | |||||
| 170 | } | |||||
| 171 | } | |||||
| 172 | //</snippe tModernOda taApp> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.