public Service.Shop.Models.Region.Region GetRegionByRegionId(int regionId) { using (var client = new RegionClient()) { var serviceResult = client.GetRegionByRegionId(regionId); serviceResult.ThrowIfException(true); return(serviceResult.Result); } }
public ActionResult GetRegionByRegionId(int regionId) { using (var client = new RegionClient()) { var allProvinceResult = client.GetRegionByRegionId(regionId); allProvinceResult.ThrowIfException(true); return(Json(allProvinceResult.Result, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 获取所有省份信息 /// </summary> /// <returns></returns> public async Task <IEnumerable <SimpleRegion> > GetAllProvince() { using (var client = new RegionClient()) { var clientResult = await client.GetAllProvinceAsync(); clientResult.ThrowIfException(true); return(clientResult.Result); } }
/// <summary> /// 根据所有地区信息 /// </summary> /// <param name="categoryName"></param> /// <returns></returns> public async Task <List <MiniRegion> > GetAllMiniRegionAsync() { using (var client = new RegionClient()) { var clientResult = await client.GetAllMiniRegionAsync(); clientResult.ThrowIfException(true); return(clientResult.Result?.ToList()); } }
/// <summary> /// 根据地区Id获取地区信息 /// </summary> /// <param name="regionId"></param> /// <returns></returns> public async Task <Region> GetRegionByRegionIdAsync(int regionId) { using (var client = new RegionClient()) { var clientResult = await client.GetRegionByRegionIdAsync(regionId); clientResult.ThrowIfException(true); return(clientResult.Result); } }
/// <summary> /// 通过regionId获取市/区 /// </summary> /// <param name="regionId"></param> /// <returns>Json格式</returns> public async Task <ActionResult> GetRegionByRegionId(int regionId) { Tuhu.Service.Shop.Models.Region.Region result = null; using (var client = new RegionClient()) { var serviceResult = await client.GetRegionByRegionIdAsync(regionId); serviceResult.ThrowIfException(true); result = serviceResult.Result; } return(Json(new { isSuccess = result != null, Data = result }, JsonRequestBehavior.AllowGet)); }
public void Execute(IJobExecutionContext context) { List <MiniRegion> miniRegion = new List <MiniRegion>(); try { logger.Info("开始刷新轮胎区域活动缓存"); var allActivityId = GetAllActivityId(); if (allActivityId != null && allActivityId.Any()) { using (var client = new RegionClient()) { var data = client.GetAllMiniRegion(); data.ThrowIfException(true, "获取所有地区服务失败"); miniRegion = data.Result.ToList(); } if (miniRegion != null && miniRegion.Any()) { foreach (var activityId in allActivityId) { foreach (var region in miniRegion) { using (var client = new ConfigClient()) { var result = client.RefreshRegionMarketingCache(activityId, region.RegionId); result.ThrowIfException(true); if (!result.Result) { logger.Error("刷新轮胎区域活动失败"); } } } } } else { logger.Info("未获取到地区"); } } else { logger.Info("没有已配置的活动"); } } catch (Exception ex) { logger.Error("刷新轮胎区域活动缓存Job异常", ex); } logger.Info("刷新轮胎区域活动缓存任务完成"); }
public static List <MiniRegion> GetAllRegion() { using (var client = new RegionClient()) { var vals = client.GetAllMiniRegion(); var data = new List <MiniRegion>(); if (vals.Success) { foreach (var item in vals.Result.ToList()) { var val = new MiniRegion() { RegionId = item.RegionId, RegionName = item.RegionName, PinYin = item.PinYin }; if (item.RegionId == 1 || item.RegionId == 2 || item.RegionId == 19 || item.RegionId == 20) { val.ChildRegions = new List <MiniRegion>() { new MiniRegion() { RegionId = item.RegionId, RegionName = item.RegionName, PinYin = item.PinYin } }; } else { var child = new List <MiniRegion>(); foreach (var it in item.ChildRegions) { child.Add(new MiniRegion() { RegionId = it.RegionId, RegionName = it.RegionName, PinYin = it.PinYin }); } val.ChildRegions = child; } data.Add(val); } return(data); } else { return(null); } } }
/// <summary> /// 获取所有省份 /// </summary> /// <returns>Json格式</returns> public async Task <ActionResult> GetAllProvince() { IEnumerable <SimpleRegion> result = null; using (var client = new RegionClient()) { var serviceResult = await client.GetAllProvinceAsync(); serviceResult.ThrowIfException(true); result = serviceResult.Result; } return(Json(new { Status = result != null, Data = result }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 通过regionId获取市/区 /// </summary> /// <param name="regionId"></param> /// <returns>Json格式</returns> public async Task <ActionResult> GetRegionByRegionId(int regionId) { List <Tuhu.Service.Shop.Models.Region.Region> result = null; using (var client = new RegionClient()) { var serviceResult = await client.GetRegionByRegionIdAsync(regionId); serviceResult.ThrowIfException(true); result = serviceResult?.Result?.ChildRegions.ToList().GroupBy(x => x.CityId).Select(s => s.First()).ToList(); } return(Json(new { isSuccess = result != null, Data = result }, JsonRequestBehavior.AllowGet)); }
protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) { OSDMap args = RegionClient.GetOSDMap((string)request["body"]); if (args == null) { responsedata["int_response_code"] = 400; responsedata["str_response_string"] = "false"; return; } // retrieve the regionhandle ulong regionhandle = 0; bool authorize = false; if (args.ContainsKey("destination_handle")) { UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); } if (args.ContainsKey("authorize_user")) // not implemented on the sending side yet { bool.TryParse(args["authorize_user"].AsString(), out authorize); } AgentCircuitData aCircuit = new AgentCircuitData(); try { aCircuit.UnpackAgentCircuitData(args); } catch (Exception ex) { m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildCreate message {0}", ex.Message); return; } OSDMap resp = new OSDMap(2); string reason = String.Empty; // This is the meaning of POST agent bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit, authorize, out reason); resp["reason"] = OSD.FromString(reason); resp["success"] = OSD.FromBoolean(result); // TODO: add reason if not String.Empty? responsedata["int_response_code"] = 200; responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); }
public JsonResult GetAllCitys(int ProvinceId) { using (var client = new RegionClient()) { var regions = client.GetRegionByRegionId(ProvinceId); regions.ThrowIfException(true); if (regions.Result.ChildRegions.FirstOrDefault().IsBelongMunicipality) { return(Json(regions.Result.ChildRegions.Select(s => new { id = s.CityId, name = s.CityName }).Distinct().ToArray())); } else { return(Json(regions.Result.ChildRegions.Select(s => new { id = s.CityId, name = s.CityName }).ToArray())); } } }
private void InitCurrentRegion() { var ret = new RegionClient(_Url).GetByID(1, true); if (ret.Result == ResultCode.Successful && ret.QueryObject != null) { _CurrentRegion = new MonitorRegion(ret.QueryObject); } if (this.ActionBar != null) { this.ActionBar.Title = _CurrentRegion != null ? _CurrentRegion.Name : "没有设置区域"; } if (_CurrentRegion != null) { _FirstTime = true; } }
/// <summary> /// 根据regionId获取region /// </summary> /// <param name="regionId"></param> /// <returns></returns> public static Region GetRegionByRegionId(int regionId) { Region result = null; try { using (var client = new RegionClient()) { var getResult = client.GetRegionByRegionId(regionId); getResult.ThrowIfException(true); result = getResult.Result; } } catch (Exception ex) { logger.Error(ex); } return(result); }
/// <summary> /// 获取所有省 /// </summary> /// <param name="regionId"></param> /// <returns></returns> public static IEnumerable <SimpleRegion> GetAllProvince() { IEnumerable <SimpleRegion> result = null; try { using (var client = new RegionClient()) { var getResult = client.GetAllProvince(); getResult.ThrowIfException(true); result = getResult.Result; } } catch (Exception ex) { logger.Error(ex); } return(result); }
/// <summary> /// Gets the ID of the given region. /// </summary> /// <param name="client">The RegionClient instance to use to retrieve the region /// ID.</param> /// <param name="name">The name of the region to retrieve the ID for.</param> /// <returns>The ID of the given region.</returns> /// <exception cref="ArgumentException">If the region cannot be found.</exception> public static int GetRegionId(this RegionClient client, string name) { var regions = client.GetRegions(); KeyValuePair <int, Region> region; try { region = regions.Regions.Single( r => r.Value.name == name); } catch (InvalidOperationException e) { throw new ArgumentException( $"Cannot find region called {name}", nameof(name), e); } return(region.Key); }
public List <MiniRegion> GetAllMiniRegion() { List <MiniRegion> result = new List <MiniRegion>(); try { using (var client = new RegionClient()) { var data = client.GetAllMiniRegion(); data.ThrowIfException(true, "获取所有地区服务失败"); result = data.Result.ToList(); } } catch (Exception ex) { logger.Error(ex); } return(result); }
public async Task <JsonResult> GetAllProvinces() { try { using (var client = new RegionClient()) { var regions = await client.GetAllProvinceAsync(); regions.ThrowIfException(true); var result = regions.Result.Select(s => new { id = s.ProvinceId, name = s.ProvinceName }).ToArray(); return(Json(result)); } } catch (Exception ex) { logger.Error($"GetAllProvinces:{ex.Message}", ex); } return(Json(null)); }
/// <summary> /// 获取所有年检所在的乡 /// </summary> /// <returns></returns> public List <InspectionRegion> GetAllInspectionVillageByCityId(int cityId, int provinceId) { var result = null as List <InspectionRegion>; try { using (var client = new RegionClient()) { var regionresponse = client.GetRegionByRegionId(cityId); if (regionresponse != null && regionresponse.Result != null) { if (Cities.Select(p => p.RegionId).Contains(provinceId)) { result = new List <InspectionRegion>() { new InspectionRegion() { RegionId = regionresponse.Result.RegionId, RegionName = regionresponse.Result.RegionName } }; } else if (regionresponse.Result.ChildRegions.Any()) { result = regionresponse.Result.ChildRegions.Select(p => new InspectionRegion() { RegionId = p.RegionId, RegionName = p.RegionName }).ToList(); } } } } catch (Exception ex) { Logger.Error("GetAllInspectionVillageByCityId", ex); } return(result ?? new List <InspectionRegion>()); }
public Tuple <List <BatteryFastDeliveryModel>, int> SelectBatteryFastDelivery(string serviceTypePid, int pageIndex, int pageSize) { int totalCount = 0; List <BatteryFastDeliveryModel> fastDeliveryInfos = null; List <BatteryFastDeliveryProductsModel> batteryList = null; try { fastDeliveryInfos = dbScopeManagerConfigRead.Execute(conn => DalBatteryFastDelivery.SelectBatteryFastDelivery(conn, serviceTypePid, pageIndex, pageSize, out totalCount)); var fastDeliveryIdsStr = string.Join(",", fastDeliveryInfos.Select(s => s.PKID).ToList()); batteryList = dbScopeManagerConfigRead.Execute(conn => DalBatteryFastDelivery.GetBatteryFastDeliveryProductsByFastDeliveryId(conn, fastDeliveryIdsStr)); var batteryDic = batteryList.GroupBy(item => item.FastDeliveryId) .ToDictionary(i => i.Key, i => i.ToList().GroupBy(t => t.Brand).ToDictionary(j => j.Key, j => j.Select(s => s.ProductPid).Take(5).ToList())); using (var client = new RegionClient()) { foreach (var fastDeliveryInfo in fastDeliveryInfos) { fastDeliveryInfo.Products = batteryDic.ContainsKey(fastDeliveryInfo.PKID) ? batteryDic[fastDeliveryInfo.PKID] : null; var serviceResult = client.GetSimpleRegionByRegionId(fastDeliveryInfo.RegionId); serviceResult.ThrowIfException(true); if (serviceResult?.Result != null) { fastDeliveryInfo.ProvinceName = serviceResult.Result.ProvinceName; fastDeliveryInfo.CityName = serviceResult.Result.CityName; fastDeliveryInfo.DistrictName = serviceResult.Result.DistrictName; } } return(new Tuple <List <BatteryFastDeliveryModel>, int>(fastDeliveryInfos, totalCount)); } } catch (Exception ex) { Logger.Error("SelectBatteryFastDelivery", ex); return(new Tuple <List <BatteryFastDeliveryModel>, int>(null, 0)); } }
private DateTime _LastDateTime = DateTime.Now.AddDays(-3); //从某个时间点的刷卡记录开始算起,一般来说人员不会在区域里面呆超过三天 #endregion #region 私有方法 private void InitCurrentRegion() { var region = new RegionClient(AppSettings.Current.ConnStr).GetByID(1, true).QueryObject; if (region == null) //获取失败再根据设置的当前区域从数据库获取 { lblRegion.Text = "没有设置当前区域"; lblRegion.ForeColor = Color.Red; return; } _CurrentRegion = new MonitorRegion(region); lblRegion.Text = string.Format("{0} 在场人数", _CurrentRegion.Name); lblRegion.ForeColor = Color.Black; if (_ReadCardEventThread == null) { _ReadCardEventThread = new Thread(new ThreadStart(FreshRegion_Thread)); _ReadCardEventThread.IsBackground = true; _ReadCardEventThread.Start(); } tmrGetEvents.Enabled = _CurrentRegion != null; tmrTimeout.Enabled = _CurrentRegion != null; }
protected virtual void DoRegionPost(Hashtable request, Hashtable responsedata, UUID id) { OSDMap args = RegionClient.GetOSDMap((string)request["body"]); if (args == null) { responsedata["int_response_code"] = 400; responsedata["str_response_string"] = "false"; return; } // retrieve the regionhandle ulong regionhandle = 0; if (args["destination_handle"] != null) { UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); } RegionInfo aRegion = new RegionInfo(); try { aRegion.UnpackRegionInfoData(args); } catch (Exception ex) { m_log.InfoFormat("[REST COMMS]: exception on unpacking HelloNeighbour message {0}", ex.Message); return; } // This is the meaning of POST region bool result = m_localBackend.SendHelloNeighbour(regionhandle, aRegion); responsedata["int_response_code"] = 200; responsedata["str_response_string"] = result.ToString(); }
protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, ulong regionhandle) { OSDMap args = RegionClient.GetOSDMap((string)request["body"]); if (args == null) { responsedata["int_response_code"] = 400; responsedata["str_response_string"] = "false"; return; } Vector3 pos = Vector3.Zero; string sogXmlStr = String.Empty, extraStr = String.Empty, stateXmlStr = String.Empty; if (args.ContainsKey("sog")) { sogXmlStr = args["sog"].AsString(); } if (args.ContainsKey("extra")) { extraStr = args["extra"].AsString(); } if (args.ContainsKey("pos")) { pos = args["pos"].AsVector3(); } UUID regionID = m_localBackend.GetRegionID(regionhandle); SceneObjectGroup sog = null; try { sog = SceneObjectSerializer.FromXml2Format(sogXmlStr); sog.ExtraFromXmlString(extraStr); } catch (Exception ex) { m_log.InfoFormat("[REST COMMS]: exception on deserializing scene object {0}", ex.Message); responsedata["int_response_code"] = 400; responsedata["str_response_string"] = "false"; return; } if (args.ContainsKey("pos")) { sog.AbsolutePosition = pos; } if (args.ContainsKey("avatars")) { sog.AvatarsToExpect = args["avatars"].AsInteger(); } if ((args.ContainsKey("state")) && m_aScene.m_allowScriptCrossings) { stateXmlStr = args["state"].AsString(); if (!String.IsNullOrEmpty(stateXmlStr)) { try { sog.SetState(stateXmlStr, regionID); } catch (Exception ex) { m_log.InfoFormat("[REST COMMS]: exception on setting state for scene object {0}", ex.Message); } } } // This is the meaning of POST object bool result = m_localBackend.SendCreateObject(regionhandle, sog, null, false, pos, args["pos"] == null); responsedata["int_response_code"] = 200; responsedata["str_response_string"] = result.ToString(); }
protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) { if (m_safemode) { // Authentication string authority = string.Empty; string authToken = string.Empty; if (!GetAuthentication(request, out authority, out authToken)) { m_log.InfoFormat("[REST COMMS]: Authentication failed for agent message {0}", request["uri"]); responsedata["int_response_code"] = 403; responsedata["str_response_string"] = "Forbidden"; return; } if (!VerifyKey(id, authority, authToken)) { m_log.InfoFormat("[REST COMMS]: Authentication failed for agent message {0}", request["uri"]); responsedata["int_response_code"] = 403; responsedata["str_response_string"] = "Forbidden"; return; } m_log.DebugFormat("[REST COMMS]: Authentication succeeded for {0}", id); } OSDMap args = RegionClient.GetOSDMap((string)request["body"]); if (args == null) { responsedata["int_response_code"] = 400; responsedata["str_response_string"] = "false"; return; } // retrieve the regionhandle ulong regionhandle = 0; if (args["destination_handle"] != null) { UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); } AgentCircuitData aCircuit = new AgentCircuitData(); try { aCircuit.UnpackAgentCircuitData(args); } catch (Exception ex) { m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildCreate message {0}", ex.Message); return; } OSDMap resp = new OSDMap(2); string reason = String.Empty; // This is the meaning of POST agent m_regionClient.AdjustUserInformation(aCircuit); bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit, out reason); resp["reason"] = OSD.FromString(reason); resp["success"] = OSD.FromBoolean(result); // TODO: add reason if not String.Empty? responsedata["int_response_code"] = 200; responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); }
protected virtual void DoAgentPut(Hashtable request, Hashtable responsedata) { OSDMap args = RegionClient.GetOSDMap((string)request["body"]); if (args == null) { responsedata["int_response_code"] = 400; responsedata["str_response_string"] = "false"; return; } // retrieve the regionhandle ulong regionhandle = 0; if (args["destination_handle"] != null) { UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); } string messageType; if (args["message_type"] != null) { messageType = args["message_type"].AsString(); } else { m_log.Warn("[REST COMMS]: Agent Put Message Type not found. "); messageType = "AgentData"; } bool result = true; if ("AgentData".Equals(messageType)) { AgentData agent = new AgentData(); try { agent.Unpack(args); } catch (Exception ex) { m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); return; } //agent.Dump(); // This is one of the meanings of PUT agent result = m_localBackend.SendChildAgentUpdate(regionhandle, agent); } else if ("AgentPosition".Equals(messageType)) { AgentPosition agent = new AgentPosition(); try { agent.Unpack(args); } catch (Exception ex) { m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); return; } //agent.Dump(); // This is one of the meanings of PUT agent result = m_localBackend.SendChildAgentUpdate(regionhandle, agent); } responsedata["int_response_code"] = 200; responsedata["str_response_string"] = result.ToString(); }