Produced by Araxis Merge on 2/1/2017 2:56:24 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\BusinessManagement | TransactionCurrencyExchangeRate.cs | Tue Dec 20 19:51:44 2016 UTC |
| 2 | Wed Feb 1 19:56:24 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 264 |
| 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 Transactio nCurrencyE xchangeRat e> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Linq; | |||||
| 19 | using Syst em.Service Model; | |||||
| 20 | ||||||
| 21 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 22 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 23 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 24 | using Micr osoft.Xrm. Sdk.Discov ery; | |||||
| 25 | ||||||
| 26 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 27 | // found i n the SDK\ bin folder . | |||||
| 28 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 29 | ||||||
| 30 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 31 | { | |||||
| 32 | /// <s ummary> | |||||
| 33 | /// De monstrates how to re trieve a c urrency's exchange r ates. | |||||
| 34 | /// </ summary> | |||||
| 35 | /// <p aram name= "serverCon fig">Conta ins server connectio n informat ion.</para m> | |||||
| 36 | /// <p aram name= "promptfor Delete">Wh en True, t he user wi ll be prom pted to de lete all | |||||
| 37 | /// cr eated enti ties.</par am> | |||||
| 38 | public class Tra nsactionCu rrencyExch angeRate | |||||
| 39 | { | |||||
| 40 | #r egion Clas s Level Me mbers | |||||
| 41 | ||||||
| 42 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 43 | pr ivate Serv iceContext _context; | |||||
| 44 | ||||||
| 45 | pr ivate Tran sactionCur rency _cur rency; | |||||
| 46 | ||||||
| 47 | #e ndregion C lass Level Members | |||||
| 48 | ||||||
| 49 | #r egion How To Sample Code | |||||
| 50 | // / <summary > | |||||
| 51 | // / This met hod first creates a new curren cy within the system , setting its | |||||
| 52 | // / exchange rate to a pre-defin ed value. It then is sues a | |||||
| 53 | // / Retrieve ExchangeRa teRequest to get the exchange rate from the create d | |||||
| 54 | // / currency to the or ganization 's base cu rrency. Fi nally, it retrieves the | |||||
| 55 | // / organiza tion's bas e currency and displ ays the co nversion r ate. | |||||
| 56 | // / </summar y> | |||||
| 57 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 58 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 59 | // / created entities.< /param> | |||||
| 60 | ||||||
| 61 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 62 | { | |||||
| 63 | try | |||||
| 64 | { | |||||
| 65 | //<s nippetTran sactionCur rencyExcha ngeRate1> | |||||
| 66 | // C onnect to the Organi zation ser vice. | |||||
| 67 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 68 | usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri,server Config.Cre dentials, serverConf ig.DeviceC redentials )) | |||||
| 69 | // u sing the s ervice con text makes retrievin g entities easier | |||||
| 70 | usin g (_contex t = new Se rviceConte xt(_servic eProxy)) | |||||
| 71 | { | |||||
| 72 | // This st atement is required to enable early-boun d type sup port. | |||||
| 73 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 74 | ||||||
| 75 | String cur rentOrgani zatoinUniq ueName = G etCurrentO rganizatio nName(serv erConfig); | |||||
| 76 | ||||||
| 77 | CreateRequ iredRecord s(); | |||||
| 78 | ||||||
| 79 | RetrieveEx changeRate Request re quest = ne w Retrieve ExchangeRa teRequest( ) | |||||
| 80 | { | |||||
| 81 | Transa ctionCurre ncyId = _c urrency.Id | |||||
| 82 | }; | |||||
| 83 | RetrieveEx changeRate Response r esponse = | |||||
| 84 | (Retri eveExchang eRateRespo nse)_servi ceProxy.Ex ecute(requ est); | |||||
| 85 | Console.Wr iteLine(" Retrieved exchange rate for c reated cur rency"); | |||||
| 86 | ||||||
| 87 | // get the base curr ency for t he current org | |||||
| 88 | var baseCu rrencyName = | |||||
| 89 | (from currency i n _context .Transacti onCurrency Set | |||||
| 90 | join org in _co ntext.Orga nizationSe t | |||||
| 91 | on cu rrency.Id equals org .BaseCurre ncyId.Id | |||||
| 92 | where org.Name == current Organizato inUniqueNa me | |||||
| 93 | selec t currency .CurrencyN ame).First OrDefault( ); | |||||
| 94 | Console.Wr iteLine(" This orga nization's base curr ency is {0 }", | |||||
| 95 | baseCu rrencyName ); | |||||
| 96 | ||||||
| 97 | Console.Wr iteLine( | |||||
| 98 | " The conversio n from {0} -> {1} is {2}", | |||||
| 99 | _curre ncy.Curren cyName, | |||||
| 100 | baseCu rrencyName , | |||||
| 101 | respon se.Exchang eRate); | |||||
| 102 | ||||||
| 103 | DeleteRequ iredRecord s(promptfo rDelete); | |||||
| 104 | } | |||||
| 105 | //</ snippetTra nsactionCu rrencyExch angeRate1> | |||||
| 106 | } | |||||
| 107 | ||||||
| 108 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 109 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 110 | { | |||||
| 111 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 112 | thro w; | |||||
| 113 | } | |||||
| 114 | } | |||||
| 115 | ||||||
| 116 | pr ivate stri ng GetCurr entOrganiz ationName( ServerConn ection.Con figuration serverCon fig) | |||||
| 117 | { | |||||
| 118 | using (D iscoverySe rviceProxy _discover yProxy = n ew Discove ryServiceP roxy(serve rConfig.Di scoveryUri , | |||||
| 119 | server Config.Hom eRealmUri, serverCon fig.Creden tials, ser verConfig. DeviceCred entials)) | |||||
| 120 | { | |||||
| 121 | Retr ieveOrgani zationsReq uest orgsR equest = | |||||
| 122 | new RetrieveOr ganization sRequest() | |||||
| 123 | { | |||||
| 124 | AccessType = Endpoin tAccessTyp e.Default, | |||||
| 125 | Release = Organizati onRelease. Current | |||||
| 126 | }; | |||||
| 127 | Retr ieveOrgani zationsRes ponse orga nizations = | |||||
| 128 | (RetrieveO rganizatio nsResponse )_discover yProxy.Exe cute(orgsR equest); | |||||
| 129 | ||||||
| 130 | fore ach (Organ izationDet ail organi zation in organizati ons.Detail s) | |||||
| 131 | { | |||||
| 132 | foreach (v ar endpoin t in organ ization.En dpoints) | |||||
| 133 | { | |||||
| 134 | if (en dpoint.Val ue.ToLower Invariant( ) == serve rConfig.Or ganization Uri.ToStri ng().ToLow erInvarian t()) | |||||
| 135 | re turn organ ization.Fr iendlyName ; | |||||
| 136 | } | |||||
| 137 | } | |||||
| 138 | } | |||||
| 139 | return S tring.Empt y; | |||||
| 140 | } | |||||
| 141 | ||||||
| 142 | #r egion Publ ic Methods | |||||
| 143 | ||||||
| 144 | pu blic void CreateRequ iredRecord s() | |||||
| 145 | { | |||||
| 146 | Console. WriteLine( " Creatin g currency 'Canadian Dollar'") ; | |||||
| 147 | // Creat e another currency | |||||
| 148 | _currenc y = new Tr ansactionC urrency() | |||||
| 149 | { | |||||
| 150 | Curr encyName = "Canadian Dollar", | |||||
| 151 | Curr encyPrecis ion = 2, | |||||
| 152 | Exch angeRate = (decimal) 0.9755, | |||||
| 153 | ISOC urrencyCod e = "CAD", // Canadi an Dollar currency c ode | |||||
| 154 | Curr encySymbol = "$" | |||||
| 155 | }; | |||||
| 156 | _currenc y.Id = _se rviceProxy .Create(_c urrency); | |||||
| 157 | } | |||||
| 158 | ||||||
| 159 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 160 | { | |||||
| 161 | bool toB eDeleted = true; | |||||
| 162 | ||||||
| 163 | if (prom pt) | |||||
| 164 | { | |||||
| 165 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 166 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 167 | Stri ng answer = Console. ReadLine() ; | |||||
| 168 | if ( answer.Sta rtsWith("y ") || | |||||
| 169 | answer.Sta rtsWith("Y ") || | |||||
| 170 | answer == String.Emp ty) | |||||
| 171 | { | |||||
| 172 | toBeDelete d = true; | |||||
| 173 | } | |||||
| 174 | else | |||||
| 175 | { | |||||
| 176 | toBeDelete d = false; | |||||
| 177 | } | |||||
| 178 | } | |||||
| 179 | ||||||
| 180 | if (toBe Deleted) | |||||
| 181 | { | |||||
| 182 | _ser viceProxy. Delete(Tra nsactionCu rrency.Ent ityLogical Name, | |||||
| 183 | _currency. Id); | |||||
| 184 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 185 | } | |||||
| 186 | } | |||||
| 187 | ||||||
| 188 | #e ndregion | |||||
| 189 | ||||||
| 190 | #e ndregion H ow To Samp le Code | |||||
| 191 | ||||||
| 192 | #r egion Main method | |||||
| 193 | ||||||
| 194 | // / <summary > | |||||
| 195 | // / Standard Main() me thod used by most SD K samples. | |||||
| 196 | // / </summar y> | |||||
| 197 | // / <param n ame="args" ></param> | |||||
| 198 | st atic publi c void Mai n(string[] args) | |||||
| 199 | { | |||||
| 200 | try | |||||
| 201 | { | |||||
| 202 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 203 | // c redentials from the user. | |||||
| 204 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 205 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 206 | ||||||
| 207 | Tran sactionCur rencyExcha ngeRate ap p = new Tr ansactionC urrencyExc hangeRate( ); | |||||
| 208 | app. Run(config , true); | |||||
| 209 | } | |||||
| 210 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 211 | { | |||||
| 212 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 213 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 214 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 215 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 216 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 217 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 218 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 219 | } | |||||
| 220 | catch (S ystem.Time outExcepti on ex) | |||||
| 221 | { | |||||
| 222 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 223 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 224 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 225 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 226 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 227 | } | |||||
| 228 | catch (S ystem.Exce ption ex) | |||||
| 229 | { | |||||
| 230 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 231 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 232 | ||||||
| 233 | // D isplay the details o f the inne r exceptio n. | |||||
| 234 | if ( ex.InnerEx ception != null) | |||||
| 235 | { | |||||
| 236 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 237 | ||||||
| 238 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 239 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 240 | if (fe != null) | |||||
| 241 | { | |||||
| 242 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 243 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 244 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 245 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 246 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 247 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 248 | } | |||||
| 249 | } | |||||
| 250 | } | |||||
| 251 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 252 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 253 | ||||||
| 254 | finally | |||||
| 255 | { | |||||
| 256 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 257 | Cons ole.ReadLi ne(); | |||||
| 258 | } | |||||
| 259 | } | |||||
| 260 | ||||||
| 261 | #e ndregion M ain method | |||||
| 262 | } | |||||
| 263 | } | |||||
| 264 | //</snippe tTransacti onCurrency ExchangeRa te> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.