Produced by Araxis Merge on 2/1/2017 2:56:52 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\Process\CustomWorkflowActivities\DistanceCalculator | DistanceCalculator.cs | Tue Dec 20 19:51:45 2016 UTC |
| 2 | Wed Feb 1 19:56:52 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 149 |
| 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 DistanceCa lculator> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Activit ies; | |||||
| 19 | using Syst em.Linq; | |||||
| 20 | using Syst em.Net; | |||||
| 21 | using Syst em.Runtime .Serializa tion.Json; | |||||
| 22 | ||||||
| 23 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 24 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 25 | using Micr osoft.Xrm. Sdk; | |||||
| 26 | ||||||
| 27 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.Workf low.dll as sembly | |||||
| 28 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 29 | using Micr osoft.Xrm. Sdk.Workfl ow; | |||||
| 30 | ||||||
| 31 | // These n amespace i s used to deserializ e to JSON object | |||||
| 32 | using Micr osoft.Crm. Sdk.Sample s.BingMaps RestV1; | |||||
| 33 | ||||||
| 34 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 35 | { | |||||
| 36 | ||||||
| 37 | /// <s ummary> | |||||
| 38 | /// Ca lculates t he shortes t distance between t wo points based on t heir zipco des, | |||||
| 39 | /// an d returns the value. | |||||
| 40 | /// In put argume nts: | |||||
| 41 | /// "Starting Zip Code". Type: Str ing. Is th e start po int. | |||||
| 42 | /// "Ending Zi p Code". T ype: Strin g. Is the end point. | |||||
| 43 | /// Ou tput argum ent: | |||||
| 44 | /// "Total Dis tance". Ty pe: Double . Is the t otal dista nce measur ed in km. | |||||
| 45 | /// </ summary> | |||||
| 46 | public sealed pa rtial clas s Distance Calculator : CodeAct ivity | |||||
| 47 | { | |||||
| 48 | // / <summary > | |||||
| 49 | // / Calculat es the sho rtest dist ance betwe en two poi nts based on their z ipcodes, | |||||
| 50 | // / and retu rns the va lue. | |||||
| 51 | // / </summar y> | |||||
| 52 | pr otected ov erride voi d Execute( CodeActivi tyContext executionC ontext) | |||||
| 53 | { | |||||
| 54 | IWorkflo wContext c ontext = e xecutionCo ntext.GetE xtension<I WorkflowCo ntext>(); | |||||
| 55 | IOrganiz ationServi ceFactory serviceFac tory = | |||||
| 56 | exec utionConte xt.GetExte nsion<IOrg anizationS erviceFact ory>(); | |||||
| 57 | IOrganiz ationServi ce service = | |||||
| 58 | serv iceFactory .CreateOrg anizationS ervice(con text.UserI d); | |||||
| 59 | ||||||
| 60 | // Calcu late the d istance be tween thos e two poin ts | |||||
| 61 | // based on the Zi p Codes | |||||
| 62 | double d istance = CalculateD istance( | |||||
| 63 | this .startingZ ipCode.Get (execution Context), | |||||
| 64 | this .endingZip Code.Get(e xecutionCo ntext)); | |||||
| 65 | ||||||
| 66 | // Set t he result in the out put parame ter | |||||
| 67 | this.tot alDistance .Set(execu tionContex t, distanc e); | |||||
| 68 | } | |||||
| 69 | ||||||
| 70 | // / <summary > | |||||
| 71 | // / Calculat es the sho rtest dist ance betwe en two poi nts based on their z ipcodes, | |||||
| 72 | // / and retu rns the va lue. | |||||
| 73 | // / </summar y> | |||||
| 74 | pr ivate doub le Calcula teDistance (string st artPoint, string end Point) | |||||
| 75 | { | |||||
| 76 | double d istance = 0.0; | |||||
| 77 | ||||||
| 78 | // Requi red start and end wa ypoint par ameters (l ocation st ring | |||||
| 79 | // or a pair of la titude and longitude coordinat es). | |||||
| 80 | string f romAddress = startPo int; | |||||
| 81 | string t oAddress = endPoint; | |||||
| 82 | ||||||
| 83 | // Optio nal route calculatio n paramete rs: | |||||
| 84 | // Optim ize route for the sh ortest dis tance. | |||||
| 85 | string o ptimize = "distance" ; | |||||
| 86 | ||||||
| 87 | // Drivi ng travel mode: driv ing/walkin g/transit | |||||
| 88 | string t ravelMode = "driving "; | |||||
| 89 | ||||||
| 90 | // Measu re distanc e: km/mi | |||||
| 91 | string d istanceUni t = "km"; | |||||
| 92 | ||||||
| 93 | // User needs to p ut here hi s/her Bing Maps Key | |||||
| 94 | string B ingMapsKey = "Au9tmA wIDZ2XAQVe dm85L51Euj HtSfgvdFBL pLXBvH-p94 kNrokavf00 POMu74Xz"; | |||||
| 95 | ||||||
| 96 | // Creat e a REST r equest for the route 's details . | |||||
| 97 | string r equestUrl = "http:// dev.virtua learth.net /REST/v1/R outes" + | |||||
| 98 | "?ou tput=json" + "&key=" + BingMap sKey + "&w p.0=" + fr omAddress + | |||||
| 99 | "&wp .1=" + toA ddress + " &optimize= " + optimi ze + | |||||
| 100 | "&tr avelMode=" + travelM ode + "&di stanceUnit =" + dista nceUnit; | |||||
| 101 | ||||||
| 102 | // Send the reques t and pars e the resp onse. | |||||
| 103 | BingMaps RestV1.Res ponse json Response = GetJsonRe sponse(req uestUrl); | |||||
| 104 | ||||||
| 105 | // Get t he shortes t distance | |||||
| 106 | distance = (from R oute r in jsonRespon se.Resourc eSets[0].R esources | |||||
| 107 | orderb y r.Travel Distance a scending | |||||
| 108 | select r.TravelD istance).F irst(); | |||||
| 109 | ||||||
| 110 | return d istance; | |||||
| 111 | } | |||||
| 112 | ||||||
| 113 | // / <summary > | |||||
| 114 | // / Send the request t o the Bing Maps REST API | |||||
| 115 | // / and dese rialize th e JSON res ponse. | |||||
| 116 | // / </summar y> | |||||
| 117 | pr ivate Resp onse GetJs onResponse (string re questUrl) | |||||
| 118 | { | |||||
| 119 | HttpWebR equest req uest = Web Request.Cr eate(reque stUrl) as HttpWebReq uest; | |||||
| 120 | using (H ttpWebResp onse respo nse = requ est.GetRes ponse() as HttpWebRe sponse) | |||||
| 121 | { | |||||
| 122 | if ( response.S tatusCode != HttpSta tusCode.OK ) | |||||
| 123 | throw new Exception( String.For mat( | |||||
| 124 | "Serve r error (H TTP {0}: { 1}).", | |||||
| 125 | respon se.StatusC ode, respo nse.Status Descriptio n)); | |||||
| 126 | Data ContractJs onSerializ er jsonSer ializer = | |||||
| 127 | new DataCo ntractJson Serializer (typeof(Bi ngMapsRest V1.Respons e)); | |||||
| 128 | obje ct objResp onse = | |||||
| 129 | jsonSerial izer.ReadO bject(resp onse.GetRe sponseStre am()); | |||||
| 130 | Bing MapsRestV1 .Response jsonRespon se = | |||||
| 131 | objRespons e as BingM apsRestV1. Response; | |||||
| 132 | retu rn jsonRes ponse; | |||||
| 133 | } | |||||
| 134 | } | |||||
| 135 | ||||||
| 136 | // Define In put/Output Arguments | |||||
| 137 | [R equiredArg ument] | |||||
| 138 | [I nput("Star ting Zip C ode")] | |||||
| 139 | pu blic InArg ument<stri ng> starti ngZipCode { get; set ; } | |||||
| 140 | ||||||
| 141 | [R equiredArg ument] | |||||
| 142 | [I nput("Endi ng Zip Cod e")] | |||||
| 143 | pu blic InArg ument<stri ng> ending ZipCode { get; set; } | |||||
| 144 | ||||||
| 145 | [O utput("Tot al Distanc e")] | |||||
| 146 | pu blic OutAr gument<dou ble> total Distance { get; set; } | |||||
| 147 | } | |||||
| 148 | } | |||||
| 149 | //</snippe tDistanceC alculator> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.