public async Task <HttpResponseMessage> GetRatings(string query) { if (string.IsNullOrEmpty(query)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Search query is missing")); } try { (HttpStatusCode Status, string Data)result = await WebRequestService.GetRequest($"{api}/beers?beer_name={query}"); if (result.Status != HttpStatusCode.OK || string.IsNullOrEmpty(result.Data)) { return(Request.CreateResponse(HttpStatusCode.BadGateway, "Proxy server did not return a valid response")); } ICollection <BeerItem> beerList = PunkService.GetRating(result.Data); if (beerList == null || beerList.Count < 1) { return(Request.CreateResponse(HttpStatusCode.NoContent, "Search query did not match any beers")); } return(Request.CreateResponse(HttpStatusCode.OK, beerList)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
protected override async Task Execute(IDMCommandContext context) { string webrequest = WebRequestService.EDSM_MultipleSystemsInfo_URL(new string[] { SystemA_name, SystemB_name }, showId: true, showCoords: true); RequestJSONResult requestResult = await WebRequestService.GetWebJSONAsync(webrequest); if (requestResult.IsSuccess) { if (requestResult.JSON.IsArray && requestResult.JSON.Array.Count < 1) { await context.Channel.SendEmbedAsync("System not found in database!", true); } else { if (printJson) { await context.Channel.SendEmbedAsync("General System Info", string.Format("```json\n{0}```", requestResult.JSON.Build(true).MaxLength(2037))); } EmbedBuilder distanceEmbed = GetDistanceEmbed(requestResult.JSON); await context.Channel.SendEmbedAsync(distanceEmbed); } } else if (requestResult.IsException) { await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. Exception Message: `{0}`", requestResult.ThrownException.Message), true); } else { await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. HTTP Error: `{0} {1}`", (int)requestResult.Status, requestResult.Status.ToString()), true); } }
public async Task <HttpResponseMessage> RateBeer(int id, [FromBody] UserRating rating) { try { if (rating == null || rating.Rating < 0 || rating.Rating > 5) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Rating is Invalid")); } //validate Id var result = await WebRequestService.GetRequest($"{api}/beers/{id}"); if (result.Item1 == HttpStatusCode.OK && !string.IsNullOrEmpty(result.Item2)) { JArray list = JArray.Parse(result.Item2); if (list.Count < 1) { return(Request.CreateResponse(HttpStatusCode.BadGateway, "Beer doesn't exists")); } PunkService.SaveRating(id, rating); return(Request.CreateResponse(HttpStatusCode.OK, "Ratings saved")); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Beer Id")); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <ActionResult> CreateWebsite(Models.WebSiteViewModel model) { if (ModelState.IsValid) { var adminManager = new AdminManager(); string locationUrl = "https://restapi.amap.com/v3/geocode/geo"; string lkey = ConfigurationManager.AppSettings["GdAppKey"].ToString(); string sk = ConfigurationManager.AppSettings["GdSecretKey"].ToString(); string[] addressArray = model.Province.Split('省', '市'); string province = string.Empty; string city = string.Empty; string district = string.Empty; string websiteLocation = string.Empty; try { province = addressArray[0]; city = addressArray[1]; district = addressArray[2]; websiteLocation = WebRequestService.QueryGDLocationByName(locationUrl, lkey, sk, province + city + district + model.Address, city); } catch (Exception) { return(Content("<script>alert('地址格式错误');history.go(-1);</script>")); } try { var website = new LogisticsSystem.DTO.WebSiteInfoDto() { Name = model.Name, ChargeMan = model.ChargeMan, ChargeManTel = model.ChargeManTel, Province = model.Province, Address = model.Address, Location = websiteLocation, Type = model.Type }; string adminId = Session["userId"].ToString(); await adminManager.CreateWebSite(website, Guid.Parse(adminId)); return(Content("<script>alert('创建成功');history.go(-1);</script>")); } catch (Exception error) { return(Content("<script>alert(" + error.Message + ");history.go(-1);</script>")); } } else { return(View()); } }
public static void AquireToken(string udid, Action <bool, string> onCompleted) { WebRequestService.RequestRaw( $"{DomainUrl}{Routes.Authenticate}", $@"{{""clientToken"" : ""{udid}""}}", UnityWebRequest.kHttpVerbPOST, new Dictionary <string, string> { { ContentTypeHeaderName, AppJsonHeader } }, onCompleted); }
protected override async Task Execute(IDMCommandContext context) { string requestSystem = WebRequestService.EDSM_SystemInfo_URL(systemName, true, true, true, true, true); string requestStations = WebRequestService.EDSM_SystemStations_URL(systemName); string requestTraffic = WebRequestService.EDSM_SystemTraffic_URL(systemName); string requestDeaths = WebRequestService.EDSM_SystemDeaths_URL(systemName); if (webRequests) { EmbedBuilder embed = new EmbedBuilder() { Title = "Webrequests", Color = BotCore.EmbedColor, Description = $"[System]({requestSystem}) `{requestSystem}`\n[Stations]({requestStations}) `{requestStations}`\n[Traffic]({requestTraffic}) `{requestTraffic}`\n[Deaths]({requestDeaths}) `{requestDeaths}`" }; await context.Channel.SendEmbedAsync(embed); } RequestJSONResult requestResultSystem = await WebRequestService.GetWebJSONAsync(requestSystem); RequestJSONResult requestResultStations = await WebRequestService.GetWebJSONAsync(requestStations); RequestJSONResult requestResultTraffic = await WebRequestService.GetWebJSONAsync(requestTraffic); RequestJSONResult requestResultDeaths = await WebRequestService.GetWebJSONAsync(requestDeaths); if (requestResultSystem.IsSuccess) { if (requestResultSystem.JSON.IsArray && requestResultSystem.JSON.Array.Count < 1) { await context.Channel.SendEmbedAsync("System not found in database!", true); } else { if (printJson) { await context.Channel.SendEmbedAsync("General System Info", string.Format("```json\n{0}```", requestResultSystem.JSON.Build(true).MaxLength(2037))); await context.Channel.SendEmbedAsync("Station Info", string.Format("```json\n{0}```", requestResultStations.JSON.Build(true).MaxLength(2037))); } EmbedBuilder systemEmbed = GetSystemInfoEmbed(requestResultSystem.JSON, requestResultStations.JSON, requestResultTraffic.JSON, requestResultDeaths.JSON, out List <EmbedFieldBuilder> allStations); await context.Channel.SendEmbedAsync(systemEmbed); } } else if (requestResultSystem.IsException) { await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. Exception Message: `{0}`", requestResultSystem.ThrownException.Message), true); } else { await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. HTTP Error: `{0} {1}`", (int)requestResultSystem.Status, requestResultSystem.Status.ToString()), true); } }
public static void GetClub(string clubId, Action <bool, Club> onCompleted) { WebRequestService.RequestObject( $"{DomainUrl}{Routes.GetClub}{clubId}", string.Empty, UnityWebRequest.kHttpVerbGET, new Dictionary <string, string> { { ContentTypeHeaderName, AppJsonHeader }, { AuthorizationHeaderName, string.Format(AuthorizationHeaderFormat, BearerToken) } }, onCompleted); }
public MarketService( ILogger <MarketService> logger, WebRequestService requestService, SteamUrlService steamUrlService, ProfileSettings profileSettings, LocalCacheService localCacheService) { _logger = logger; _requestService = requestService; _steamUrlService = steamUrlService; _profileSettings = profileSettings; _localCacheService = localCacheService; }
public static void SetUserClub(string clubId, Action <bool, User> onCompleted) { WebRequestService.RequestObject( $"{DomainUrl}{Routes.SetUserClub}", $@"{{""club"" : ""{clubId}""}}", UnityWebRequest.kHttpVerbPOST, new Dictionary <string, string> { { ContentTypeHeaderName, AppJsonHeader }, { AuthorizationHeaderName, string.Format(AuthorizationHeaderFormat, BearerToken) } }, onCompleted); }
public static void SetUserLocation(float latitude, float longtitude, Action <bool, User> onCompleted) { WebRequestService.RequestObject( $"{DomainUrl}{Routes.SetUserLocation}", $@"{{""lat"" : ""{latitude}"", ""lng"" : ""{longtitude}""}}", UnityWebRequest.kHttpVerbPOST, new Dictionary <string, string> { { ContentTypeHeaderName, AppJsonHeader }, { AuthorizationHeaderName, string.Format(AuthorizationHeaderFormat, BearerToken) } }, onCompleted); }
public async Task <bool> GetBestStation(string hideMinorFaction = null) { string request = WebRequestService.EDSM_SystemStations_URL(Name); RequestJSONResult result = await WebRequestService.GetWebJSONAsync(request); if (result.IsSuccess) { // Setup Stations if ((result.JSON != null) && result.JSON.TryGetArrayField("stations", out JSONContainer stationsJSON)) { foreach (JSONField stationField in stationsJSON.Array) { if (stationField.IsObject) { StationInfo info = new StationInfo(); if (info.FromJSON(stationField.Container)) { if (string.IsNullOrEmpty(hideMinorFaction) || info.ControllingFaction != hideMinorFaction) { if (BestStation == null) { BestStation = info; } else if (info.IsBetterThan(BestStation)) { BestStation = info; } } } } } return(true); } } return(false); }
public LightspeedShopService(LightspeedConfig config) { _webRequestServices = new WebRequestService(config); }
public LightspeedInventoryService(LightspeedConfig config) { _webRequestServices = new WebRequestService(config); }
public HealthCheckService(ILogger <HealthCheckService> logger, SteamUrlService steamUrlService, WebRequestService requestService) { _logger = logger; _steamUrlService = steamUrlService; _requestService = requestService; }
public async Task <ActionResult> TakeOrder(Models.Front.OrderViewModel model) { if (ModelState.IsValid) { try { var userManager = new UserManager(); string barcode = BarcodeFactory.GetBarcode(); bool isInsurance = !(model.CargoValue == null || model.CargoValue == ""); string senderPostcode = string.Empty; //寄方邮编 string receiverPostcode = string.Empty; //收方邮编 string senderLocation = string.Empty; //寄方地址经纬度 string receiverLocation = string.Empty; //收方地址经纬度 string region = string.Empty; //寄方邮编 string jsonPath = Server.MapPath("~/App_Data/PostCode.json"); string province = model.SLocation.Trim().Split(' ')[0]; string city = model.SLocation.Trim().Split(' ')[1] == "市辖区" ? province : model.SLocation.Trim().Split(' ')[1]; string district = model.SLocation.Trim().Split(' ')[2]; string address = model.SAddress; string key = ConfigurationManager.AppSettings["PostCodeKey"].ToString(); string url = "http://v.juhe.cn/postcode/search"; region = Region.GetRegion(province); if (model.SAddress.Contains("乡") || model.SAddress.Contains("镇")) { string paddress = address.Contains("乡") ? address.Substring(0, address.IndexOf("乡") + 1) : address.Substring(0, address.IndexOf("镇") + 1); senderPostcode = WebRequestService.QueryPostCodeByName(url, key, province, city, district, paddress, jsonPath); } else { senderPostcode = WebRequestService.QueryPostCodeByName(url, key, province, city, district, jsonPath); } //收方邮编 string rprovince = model.RLocation.Trim().Split(' ')[0]; string rcity = model.RLocation.Trim().Split(' ')[1] == "市辖区" ? rprovince : model.RLocation.Trim().Split(' ')[1]; string rdistrict = model.RLocation.Trim().Split(' ')[2]; string raddress = model.RAddress; if (model.RAddress.Contains("乡") || model.RAddress.Contains("镇")) { string paddress = raddress.Contains("乡") ? raddress.Substring(0, raddress.IndexOf("乡") + 1) : raddress.Substring(0, raddress.IndexOf("镇") + 1); receiverPostcode = WebRequestService.QueryPostCodeByName(url, key, rprovince, rcity, rdistrict, paddress, jsonPath); } else { receiverPostcode = WebRequestService.QueryPostCodeByName(url, key, rprovince, rcity, rdistrict, jsonPath); } //寄方地址经纬度 string locationUrl = "https://restapi.amap.com/v3/geocode/geo"; string lkey = ConfigurationManager.AppSettings["GdAppKey"].ToString(); string sk = ConfigurationManager.AppSettings["GdSecretKey"].ToString(); senderLocation = WebRequestService.QueryGDLocationByName(locationUrl, lkey, sk, province + city + district + address, city); //收方地址经纬度 receiverLocation = WebRequestService.QueryGDLocationByName(locationUrl, lkey, sk, rprovince + rcity + rdistrict + raddress, rcity); double freight = MaverickCost.CalcFreight(Convert.ToDouble(model.CargoWeight) * Convert.ToDouble(model.CargoUnit), Convert.ToDouble(model.CargoVolume) * Convert.ToDouble(model.CargoUnit)); double serviceCharge = 0; //得到起始网点 var webLocations = userManager.GetAllWebSiteLocationByType("1", city); string origns = string.Join("|", webLocations.Values); List <string> res = WebRequestService.CalcGroupDistance(origns, senderLocation, lkey, sk); string min = res[1]; int minIndex = 0, flag = 0; Guid webSiteId = new Guid(); for (int i = 1; i < res.Count; i++) { if (int.Parse(res[i]) < int.Parse(min)) { min = res[i]; minIndex = i; } } foreach (var locationkey in webLocations.Keys) { if (minIndex == flag) { webSiteId = locationkey; break; } ++flag; } var orderInfo = new LogisticsSystem.DTO.OrderInfoDto() { SName = model.SenderName, SMobliePhone = model.SMobliePhone.Trim(), SProvince = province + city + district, SAddress = model.SAddress.Trim(), SPostCode = senderPostcode, STelPhone = string.IsNullOrEmpty(model.STelPhone) ? "NULL" : model.STelPhone.Trim(), SFirmName = string.IsNullOrEmpty(model.SCompany) ? "NULL" : model.SCompany.Trim(), SLocation = senderLocation, RName = model.ReceiverName.Trim(), RMobliePhone = model.RMobliePhone.Trim(), RProvince = rprovince + rcity + rdistrict, RAddress = raddress, RPostCode = receiverPostcode, RTelPhone = string.IsNullOrEmpty(model.RTelPhone) ? "NULL" : model.RTelPhone.Trim(), RFirmName = string.IsNullOrEmpty(model.RCompany) ? "NULL" : model.RCompany.Trim(), RLocation = receiverLocation, BarCode = barcode, Region = region, Freight = freight, IsInsured = isInsurance, CargoName = model.CargoName.Trim(), CargoWeight = model.CargoWeight.Trim(), CargoVolume = model.CargoVolume.Trim(), UitNum = model.CargoUnit.Trim(), PayType = model.PayType.Trim() == "1", Mark = string.IsNullOrEmpty(model.Mark) ? "NULL" : model.Mark.Trim().Replace(' ', ','), TakeTime = model.TakeTime.Trim(), Risk = string.IsNullOrEmpty(model.Risk) ? "NULL" : model.Risk.Trim(), CargoValue = string.IsNullOrEmpty(model.CargoValue) ? "NULL" : model.CargoValue.Trim(), ServiceCharge = serviceCharge, StartWebsiteId = webSiteId }; await userManager.CreateOrder(orderInfo); } catch (Exception error) { return(Content("<script>alert('" + error.Message + "');history.go(-1);</script>")); } } else { return(Content("<script>alert('数据丢失了!');history.go(-1);</script>")); } return(Content("<script>alert('下单成功,感谢对本公司的信任!');window.location.href='/User/MainPage';</script>")); }
protected override async Task Execute(IDMCommandContext context) { string radiusRequest = WebRequestService.EDSM_MultipleSystemsRadius(SystemName, 50); RequestJSONResult requestResultRadius = await WebRequestService.GetWebJSONAsync(radiusRequest); if (!requestResultRadius.IsSuccess) { if (requestResultRadius.IsException) { await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. Exception Message: `{0}`", requestResultRadius.ThrownException.Message), true); } else { await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. HTTP Error: `{0} {1}`", (int)requestResultRadius.Status, requestResultRadius.Status.ToString()), true); } return; } if (requestResultRadius.JSON.IsObject) { await context.Channel.SendEmbedAsync("System not found in database!", true); return; } Dictionary <string, System> systemInfos = GetNames(requestResultRadius.JSON); List <System> allSystems = new List <System>(systemInfos.Values); foreach (System system in allSystems) { system.SetETTA(JumpRange); } allSystems.Sort(new SystemComparer() { RawDistance = true }); const int requestCnt = 20; System[] requestSystems = new System[requestCnt]; allSystems.CopyTo(0, requestSystems, 0, requestCnt); string infoRequest = WebRequestService.EDSM_MultipleSystemsInfo_URL(requestSystems.Select(system => { return(system.Name); }), true, true, true, true); RequestJSONResult requestResultInfo = await WebRequestService.GetWebJSONAsync(infoRequest); if (!requestResultInfo.IsSuccess) { if (requestResultInfo.IsException) { await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. Exception Message: `{0}`", requestResultInfo.ThrownException.Message), true); } else { await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. HTTP Error: `{0} {1}`", (int)requestResultInfo.Status, requestResultInfo.Status.ToString()), true); } return; } System targetSystem = default; if (requestResultInfo.JSON.IsArray) { foreach (JSONField systemField in requestResultInfo.JSON.Array) { if (systemField.IsObject) { if (systemField.Container.TryGetField("name", out string name)) { if (systemInfos.TryGetValue(name, out System system)) { system.FromJSON(systemField.Container); if (system.Distance == 0) { targetSystem = system; } } } } } } if (targetSystem.Name == null) { await context.Channel.SendEmbedAsync(string.Format("Internal Error! " + Macros.GetCodeLocation(), true)); return; } string hideFaction = Mode == CommandMode.Crime ? targetSystem.Name : null; List <System> validSystems = new List <System>(); foreach (System system in requestSystems) { if (await system.GetBestStation()) { system.SetETTA(JumpRange); validSystems.Add(system); } } validSystems.Sort(new SystemComparer()); EmbedBuilder embed = new EmbedBuilder() { Author = new EmbedAuthorBuilder() { Url = targetSystem.GetEDSM_URL(), Name = $"Suggestions for a temporary base near {targetSystem.Name}" }, Color = BotCore.EmbedColor }; for (int i = 0; i < 5 && i < validSystems.Count; i++) { System system = validSystems[i]; embed.AddField($"\"{system.Name}\" - \"{system.BestStation.Name}\"", $"{(system.RequirePermit ? $"{UnicodeEmoteService.Warning} Permit: `{system.PermitName}` " : string.Empty)} {system.BestStation.Services_Link}"); } await context.Channel.SendEmbedAsync(embed); }
public InventoryService(ProfileSettings profileSettings, SteamUrlService steamUrlService, WebRequestService requestService) { _profileSettings = profileSettings; _steamUrlService = steamUrlService; _requestService = requestService; }
protected override async Task Execute(IDMCommandContext context) { EmbedBuilder inaraEmbed; if (!WebRequestService.CanMakeInaraRequests) { inaraEmbed = new EmbedBuilder() { Color = BotCore.ErrorColor, Title = INARAREQUESTFAILURE, Description = "Can not make inara requests, as appname and/or apikey config variables are not set!" }; } else { JSONContainer inaraRequestcontent = WebRequestService.Inara_CMDR_Profile(cmdrName); if (printJson) { await context.Channel.SendEmbedAsync(new EmbedBuilder() { Title = "Request JSON sending to Inara", Color = BotCore.EmbedColor, Description = $"```json\n{inaraRequestcontent.Build(true).MaxLength(EmbedHelper.EMBEDDESCRIPTION_MAX - 11)}```" }); } RequestJSONResult requestResultInara = await WebRequestService.GetWebJSONAsync("https://inara.cz/inapi/v1/", inaraRequestcontent); if (requestResultInara.IsSuccess && string.IsNullOrEmpty(requestResultInara.jsonParseError)) { inaraEmbed = GetInaraCMDREmbed(requestResultInara.JSON, cmdrName); if (printJson) { await context.Channel.SendEmbedAsync(new EmbedBuilder() { Title = "Result JSON from Inara", Color = BotCore.EmbedColor, Description = $"```json\n{requestResultInara.JSON.Build(true).MaxLength(EmbedHelper.EMBEDDESCRIPTION_MAX - 11)}```" }); } } else if (!string.IsNullOrEmpty(requestResultInara.jsonParseError)) { inaraEmbed = new EmbedBuilder() { Color = BotCore.ErrorColor, Title = INARAREQUESTFAILURE, Description = $"JSON parse error: `{requestResultInara.jsonParseError}`!" }; } else if (requestResultInara.IsException) { inaraEmbed = new EmbedBuilder() { Color = BotCore.ErrorColor, Title = INARAREQUESTFAILURE, Description = $"Could not connect to Inaras services. Exception Message: `{requestResultInara.ThrownException.Message}`" }; } else { inaraEmbed = new EmbedBuilder() { Color = BotCore.ErrorColor, Title = INARAREQUESTFAILURE, Description = $"Could not connect to Inaras services. HTTP Error Message: `{(int)requestResultInara.Status} {requestResultInara.Status}`" }; } } EmbedBuilder edsmEmbed; RequestJSONResult requestResultEDSM = await WebRequestService.GetWebJSONAsync(WebRequestService.EDSM_Commander_Location(cmdrName, true, false)); if (requestResultEDSM.IsSuccess && string.IsNullOrEmpty(requestResultEDSM.jsonParseError)) { edsmEmbed = GetEDSMCMDREmbed(requestResultEDSM.JSON, cmdrName); if (printJson) { await context.Channel.SendEmbedAsync(new EmbedBuilder() { Title = "Result JSON from EDSM", Color = BotCore.EmbedColor, Description = $"```json\n{requestResultEDSM.JSON.Build(true).MaxLength(EmbedHelper.EMBEDDESCRIPTION_MAX - 11)}```" }); } } else if (!string.IsNullOrEmpty(requestResultEDSM.jsonParseError)) { edsmEmbed = new EmbedBuilder() { Color = BotCore.ErrorColor, Title = EDSMREQUESTFAILURE, Description = $"JSON parse error: `{requestResultEDSM.jsonParseError}`!" }; } else if (requestResultEDSM.IsException) { edsmEmbed = new EmbedBuilder() { Color = BotCore.ErrorColor, Title = EDSMREQUESTFAILURE, Description = $"Could not connect to Inaras services. Exception Message: `{requestResultEDSM.ThrownException.Message}`" }; } else { edsmEmbed = new EmbedBuilder() { Color = BotCore.ErrorColor, Title = EDSMREQUESTFAILURE, Description = $"Could not connect to Inaras services. HTTP Error Message: `{(int)requestResultEDSM.Status} {requestResultEDSM.Status}`" }; } inaraEmbed.Footer = new EmbedFooterBuilder() { Text = "Inara" }; edsmEmbed.Footer = new EmbedFooterBuilder() { Text = "EDSM" }; await context.Channel.SendEmbedAsync(inaraEmbed); await context.Channel.SendEmbedAsync(edsmEmbed); }
public ActionResult DynamicPathPlaning(string para, string orderId, string truckId, string name, string type) { string[] paraArray = para.Split('/'); const int STNum = 3, WorkHour = 11, AvgTime = 2; var staffManager = new StaffManager(); Guid id; //the website's id string location = string.Empty; //the website's location //get order's data List <LogisticsSystem.DTO.OrderListDto> datas = staffManager.GetOrderByWebsite(out id, out location, name, type).Where(p => long.Parse(p.OrderId) <= long.Parse(orderId)).ToList(); //避免处理期间有新的订单生成 //get truck's data var truck = staffManager.GetTruckByWebsite(id).Where(p => p.TruckId == Guid.Parse(truckId)).FirstOrDefault(); if (truck.ContainerHeight == "0") { truck.Volumn = (Convert.ToDouble(truck.ContainerLength) * Convert.ToDouble(truck.ContainerWidth) * Convert.ToDouble(truck.TruckHeight)).ToString("f2"); } else { truck.Volumn = (Convert.ToDouble(truck.ContainerLength) * Convert.ToDouble(truck.ContainerWidth) * Convert.ToDouble(truck.ContainerHeight)).ToString("f2"); } string[] locations = new string[paraArray.Length]; //the location matrix double[,] dist = new double[paraArray.Length, paraArray.Length]; //the distance matrix double[] valueCoefficient = new double[paraArray.Length]; //The Value Coefficient Matrix double[,] coefficients = new double[STNum, paraArray.Length]; //The Restraint Coefficient Matrix locations[0] = location; valueCoefficient[0] = 0; coefficients[0, 0] = double.MaxValue; coefficients[1, 0] = double.MaxValue; coefficients[2, 0] = double.MaxValue; //initialize matrix for (int i = 1; i < paraArray.Length; i++) { var num = int.Parse(paraArray[i]) - 1; valueCoefficient[i] = Convert.ToDouble(datas[num].Income); locations[i] = datas[num].Location; coefficients[0, i] = Convert.ToDouble(datas[num].CargoWeight) * Convert.ToDouble(datas[num].UnitNUm); coefficients[1, i] = Convert.ToDouble(datas[num].CargoVolume) * Convert.ToDouble(datas[num].UnitNUm); coefficients[2, i] = 0.25; } coefficients[0, paraArray.Length - 1] = Convert.ToDouble(truck.Load) * 1000; coefficients[1, paraArray.Length - 1] = Convert.ToDouble(truck.Volumn); coefficients[2, paraArray.Length - 1] = WorkHour - AvgTime; //calculate distance string key = ConfigurationManager.AppSettings["GdAppKey"]; string skey = ConfigurationManager.AppSettings["GdSecretKey"]; for (int i = 0; i < paraArray.Length; i++) { var aimLocation = locations[i]; locations.ToList().Remove(aimLocation); var orignLocationStr = string.Join("|", locations); List <string> distances = WebRequestService.CalcGroupDistance(orignLocationStr, aimLocation, key, skey, "1"); for (int j = 0; j < distances.Count; j++) { dist[i, j] = double.Parse(distances[j]); } dist[i, i] = 0; } //Analyze soulation DPP dPP = new DPP(); double _maxValue; List <string> soulation = dPP.GetSulotion(dist, valueCoefficient, coefficients, out _maxValue); string _path = string.Join("/", soulation); return(Json(new { path = _path.Trim('/'), maxValue = _maxValue }, JsonRequestBehavior.AllowGet)); }
public BoosterPackService(SteamUrlService steamUrlService, WebRequestService webRequestService, ProfileSettings profileSettings) { _steamUrlService = steamUrlService; _webRequestService = webRequestService; _profileSettings = profileSettings; }