//Average wait time before job started public static async Task <double> AverageWaitTime(DateTimeOffset givenDate) { string jobQuery; if (Period == StatPeriod.Day) { givenDate = BeginningOfDay(givenDate); jobQuery = string.Format("$filter=Entered gt {0} and Entered lt {1} and Started ne {2}", FilterFormatDTO(givenDate), FilterFormatDTO(givenDate.AddDays(1)), FilterFormatDTO(default(DateTimeOffset))); } else { givenDate = BeginningOfMonth(givenDate); jobQuery = string.Format("$filter=Entered gt {0} and Entered lt {1} and Started ne {2}", FilterFormatDTO(givenDate), FilterFormatDTO(givenDate.AddMonths(1)), FilterFormatDTO(default(DateTimeOffset))); } var jobs = await WebApiHelper.Get <Job>(jobQuery); if (jobs.Count > 0) { double total = 0; foreach (Job job in jobs) { TimeSpan difference = (job.Started.DateTime - job.Entered.DateTime); total += difference.TotalHours; } return(total / jobs.Count); } return(0); }
private static void Main(string[] args) { int staffId = int.Parse(AppSettingsConfig.StaffId); var tokenResult = WebApiHelper.GetSignToken(staffId); //staffId = 100; Dictionary <string, string> parames = new Dictionary <string, string> { { "id", "1" }, { "name", "wahaha" } }; Tuple <string, string> parameters = WebApiHelper.GetQueryString(parames); var product1 = WebApiHelper.Get <ProductResultMsg>("http://localhost:806/api/product/getproduct", parameters.Item1, parameters.Item2, staffId, true); Product product = new Product { Id = 1, Name = "安慕希", Count = 10, Price = 58.8 }; var product2 = WebApiHelper.Post <ProductResultMsg>("http://localhost:806/api/product/addProduct", JsonConvert.SerializeObject(product), staffId); Console.Read(); }
private void btnGetOrders_Click(object sender, EventArgs e) { /* * int timetype, * DateTime starttime, * DateTime endtime, * string companyname, * string orderno, * int productid, * int paystate, * int payment, * string companyidstr, * string saleIdStr, * string exactcompany */ string appkey = @"K97BiACFY291214Ci2PSHFOQPEMVBEB0"; Dictionary <string, string> parames = new Dictionary <string, string>(); parames.Add("timetype", "1"); parames.Add("starttime", "2019-03-10 00:00:00"); parames.Add("endtime", "2029-03-10 00:00:00"); parames.Add("companyname", String.Empty); parames.Add("orderno", String.Empty); parames.Add("productid", "0"); parames.Add("paystate", "0"); //?? parames.Add("payment", "0"); //?? parames.Add("companyidstr", String.Empty); parames.Add("saleIdStr", String.Empty); parames.Add("exactcompany", String.Empty); Tuple <string, string> parameters = WebApiHelper.GetQueryString(parames); var companies = WebApiHelper.Get <HttpResponseMsg>("http://localhost:65152/api/Order/GetOrders", parameters.Item1, parameters.Item2, appkey); }
// GET: Modules public async Task <ActionResult> Index() { IWebApiHelper webapi = new WebApiHelper("module", false); var all_modules = await webapi.Get <List <Module> >(""); return(View(all_modules)); }
private static async Task <SelectList> GetEditions(Guid?id) { IWebApiHelper webapi = new WebApiHelper("edition", false); var all_editions = await webapi.Get <List <Edition> >(""); var list = new List <SelectListItem>(); foreach (var edition in all_editions) { var item = new SelectListItem { Selected = false, Text = edition.Name, Value = edition.Id.ToString() }; list.Add(item); } int index = 1; if (id.HasValue) { var selected = list.Where(i => i.Value == id.ToString()).First(); selected.Selected = true; index = list.FindIndex(i => i.Value == id.ToString()); } else { list.First().Selected = true; } return(new SelectList(list, "Value", "Text", index)); }
// GET: Editions public async Task <ActionResult> Index() { IWebApiHelper webapi = new WebApiHelper("edition", false); var all_editions = await webapi.Get <List <Edition> >(""); return(View(all_editions)); }
public MenuGroup GetTopMenu(string etmCode) { var url = _menuApiServerAddress + "/Api/Menu"; return(WebApiHelper.Get <MenuGroup>(url, new { menutype = "TopMenu", etmid = etmCode ?? "" } )); }
// GET: Sections public async Task <ActionResult> Index(Guid?id) { IWebApiHelper webapi = new WebApiHelper("section", false); var all_sections = new List <Section>(); if (id.HasValue) { all_sections = await webapi.Get <List <Section> >("by_editionid/" + id.ToString()); } else { all_sections = await webapi.Get <List <Section> >(""); } return(View(all_sections)); }
public IList <City> GetCities(string provinceName) { if (provinceName == null) { throw new ArgumentNullException("provinceName"); } return(WebApiHelper.Get <List <City> >(_apiUrl, new { provinceName })); }
public string Get(string url, Dictionary <string, string> parames) { int staffId = int.Parse(AppSettingsConfig.StaffId); var tokenResult = WebApiHelper.GetSignToken(staffId); Tuple <string, string> parameters = WebApiHelper.GetQueryString(parames); var data = WebApiHelper.Get <HospitalMsg>(url, parameters.Item1, parameters.Item2, staffId); return(JsonConvert.SerializeObject(data)); }
public bool IsExist(string id, string identityNumber, string memberId) { if (String.IsNullOrEmpty(identityNumber)) { throw new ArgumentNullException("contactId", "contact's identityNumber is null."); } string param = string.Format("?id={0}&identityNumber={1}&memberId={2}", id, identityNumber, memberId); return(WebApiHelper.Get <bool>(_memberAddressUrl + param)); }
public void QueryProduct() { Dictionary <string, string> parames = new Dictionary <string, string>(); parames.Add("id", "1"); parames.Add("name", "wahaha"); Tuple <string, string> parameters = WebApiHelper.GetQueryString(parames); var product = WebApiHelper.Get <ProductResultMsg>(GetWebApiUrl, parameters.Item1, parameters.Item2, ModuleId); Console.WriteLine(product.Data.ToString()); Console.WriteLine(product.Result.Id.ToString() + ":" + product.Result.Name + ":" + product.Result.Price.ToString()); }
public static List <T> GetList() { Type type = typeof(T); int staffId = int.Parse(AppSettingsConfig.StaffId); var tokenResult = WebApiHelper.GetSignToken(staffId); string json = JsonConvert.SerializeObject(tokenResult.Data); Token token = JsonConvert.DeserializeObject <Token>(json); var d = token.SignToken; HttpCookie cookie = new HttpCookie("token"); cookie["guid"] = d.ToString(); HttpContext.Current.Response.Cookies.Add(cookie); string url = ""; switch (type.Name) { case "AdminInfo": url = "BBRecyleAPI/GetAdmin"; break; case "UserInfo": url = "BBRecyleAPI/GetUser"; break; case "BookInfo": url = "BBRecyleAPI/GetBook"; break; case "CollectorInfo": url = "BBRecyleAPI/GetCollector"; break; case "Recycles": url = "BBRecyleAPI/GetRec"; break; case "OrderInfo": url = "BBRecyleAPI/GetOrder"; break; case "DealRecord": url = "BBRecyleAPI/GetDeal"; break; } var obj = WebApiHelper.Get <ProductResultMsg <T> >(url, null, null, staffId); //string json = HttpClientHelper.SendRequest(url,"get"); List <T> list = JsonConvert.DeserializeObject <List <T> >(obj.Data.ToString()); return(list); }
// GET: Sections/Delete/5 public async Task <ActionResult> Delete(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IWebApiHelper webapi = new WebApiHelper("section", false); var section = await webapi.Get <Section>(id.ToString()); if (section == null) { return(HttpNotFound()); } return(View(section)); }
// GET: Modules/Edit/5 public async Task <ActionResult> Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IWebApiHelper webapi = new WebApiHelper("module", false); var module = await webapi.Get <Module>(id.ToString()); if (module == null) { return(HttpNotFound()); } return(View(module)); }
static void Main(string[] args) { int staffId = 1; var tokenResult = WebApiHelper.GetSignToken(staffId); Dictionary <string, string> parames = new Dictionary <string, string>(); parames.Add("id", "1"); parames.Add("name", "wahaha"); Tuple <string, string> parameters = WebApiHelper.GetQueryString(parames); var product1 = WebApiHelper.Get <ProductResultMsg>("http://localhost:56086/api/product/getproduct", parameters.Item1, parameters.Item2, staffId); Product product = new Product() { Id = 1, Name = "安慕希", Count = 10, Price = 58.8 }; var product2 = WebApiHelper.Post <ProductResultMsg>("http://localhost:56086/api/product/AddProduct", JsonConvert.SerializeObject(product), staffId); Console.Read(); }
public IList <City> GetDistricts(string provinceName, string cityName) { if (provinceName == null) { throw new ArgumentNullException("provinceName"); } if (cityName == null) { throw new ArgumentNullException("cityName"); } //string provinceName, string cityName, bool isHot return(WebApiHelper.Get <List <City> >(_apiUrl, new { provinceName = provinceName, cityName = cityName, isHot = false })); }
private async void DoStats(DateTimeOffset date) { var averageQueueSize = await StatGenerator.AverageQueueSize(date); var averageWaitTime = await StatGenerator.AverageWaitTime(date); var jobResponseRate = await StatGenerator.JobResponseRate(date); var queueEmptyTime = await StatGenerator.QueueEmptyTime(date); //var technicianIdleTime = await StatGenerator.TechnicianIdleTime(date); AverageWaitTime.Text = averageWaitTime.ToString("0.00") + " hour(s)"; AverageQueueSize.Text = averageQueueSize.ToString("0.00") + " job(s)"; JobResponseRate.Text = jobResponseRate.ToString() + " jobs(s)"; EmptyQueueTime.Text = queueEmptyTime.ToString("0.00") + "%"; List <Technician> technicians = await WebApiHelper.Get <Technician>(); ObservableCollection <IdleTechnician> idleTechnicians = new ObservableCollection <IdleTechnician>(); Random random = new Random(); foreach (var tech in technicians) { if (IsMonth) { idleTechnicians.Add(new IdleTechnician { idleHours = (int)(random.NextDouble() * 160), t = tech }); } else { idleTechnicians.Add(new IdleTechnician { idleHours = (int)(random.NextDouble() * 8), t = tech }); } } TechnicianList.DataSource = idleTechnicians; TechnicianList.DataBind(); }
public HttpResponseMessage GetProduct([FromBody] QueryOptions queryOptions) { Dictionary <string, string> dicParams = new Dictionary <string, string>(); if (null != queryOptions.Items) { foreach (var item in queryOptions.Items) { dicParams.Add(item.Key, item.Value); } } Tuple <string, string> parameters = WebApiHelper.GetQueryString(dicParams); var product = WebApiHelper.Get <ProductResultMsg>(GetWebApiUrl, parameters.Item1, parameters.Item2, "A09"); return(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(product), Encoding.GetEncoding("UTF-8"), "application/json") }); }
//Number of jobs entered on this day (or this month) not started on the entry date public static async Task <int> JobResponseRate(DateTimeOffset givenDate) { string jobQuery; if (Period == StatPeriod.Day) { givenDate = BeginningOfDay(givenDate); jobQuery = string.Format("$filter=Entered gt {0} and Entered lt {1} and Started gt {1}", FilterFormatDTO(givenDate), FilterFormatDTO(givenDate.AddDays(1))); } else { givenDate = BeginningOfMonth(givenDate); jobQuery = string.Format("$filter=Entered gt {0} and Entered lt {1} and Started gt {1}", FilterFormatDTO(givenDate), FilterFormatDTO(givenDate.AddMonths(1))); } var jobs = await WebApiHelper.Get <Job>(jobQuery); return(jobs.Where(x => x.Started >= EarliestPointNextDay(x.Entered)).Count()); }
private static async Task <List <SelectListItem> > GetEditions() { IWebApiHelper webapi = new WebApiHelper("edition", false); var all_editions = await webapi.Get <List <Edition> >(""); var list = new List <SelectListItem>(); foreach (var edition in all_editions) { var item = new SelectListItem { Selected = false, Text = edition.Name, Value = edition.Id.ToString() }; list.Add(item); } list.First().Selected = true; return(list); }
static void Main(string[] args) { int staffId = int.Parse(AppSettingsConfig.StaffId); //1、访问指定的api,获取token var tokenResult = WebApiHelper.GetSignToken(staffId); Dictionary <string, string> parames = new Dictionary <string, string>(); parames.Add("id", "1"); parames.Add("name", "wahaha"); Tuple <string, string> parameters = WebApiHelper.GetQueryString(parames); //2、将获得token,以及请求的参数,根据服务器提供的签名算法计算得出的签名进行访问api var product1 = WebApiHelper.Get <ProductResultMsg>("http://localhost:14826/api/product/getproduct", parameters.Item1, parameters.Item2, staffId); Product product = new Product() { Id = 1, Name = "安慕希", Count = 10, Price = 58.8 }; var product2 = WebApiHelper.Post <ProductResultMsg>("http://localhost:14826/api/product/addProduct", JsonConvert.SerializeObject(product), staffId); Console.Read(); }
/// <summary> /// Token约定方式调用WebApi服务 /// </summary> /// <param name="context"></param> private static void CallWebApi(IJobExecutionContext context) { var url = context.JobDetail.JobDataMap["requestUrl"].ToString(); //服务url var api = context.JobDetail.JobDataMap["webApi"].ToString(); //webapi var id = "10000"; //密钥 //规范url格式 if (!url.Contains("http")) { url = "http://" + url; } //规范api格式 if (!api.Contains("http")) { api = "http://" + api; } var tokenResult = WebApiHelper.GetSignToken(id, api); //调用api拿到token参数 Dictionary <string, string> parames = StringHelper.getUrlParams(url); //获取url参数 Tuple <string, string> parameters = WebApiHelper.GetQueryString(parames); //拼接get参数 WebApiHelper.Get <object>(url, parameters.Item1, parameters.Item2, id, api); //token约定方式调用webapi }
private void btnCompanylist_Click(object sender, EventArgs e) { /*int staffId = int.Parse(AppSettingsConfig.StaffId); * var tokenResult = WebApiHelper.GetSignToken(staffId); * Dictionary<string, string> parames = new Dictionary<string, string>(); * parames.Add("id", "1"); * parames.Add("name", "wahaha"); * Tuple<string, string> parameters = WebApiHelper.GetQueryString(parames); * //var product1 = WebApiHelper.Get<ProductResultMsg>("http://*****:*****@"K97BiACFY291214Ci2PSHFOQPEMVBEB0"; //var tokenResult = WebApiHelper.GetSignToken(appkey); Dictionary <string, string> parames = new Dictionary <string, string>(); parames.Add("companyname", "艾尔国际A12"); Tuple <string, string> parameters = WebApiHelper.GetQueryString(parames); //2.GetListByCompanyName var companies = WebApiHelper.Get <HttpResponseMsg>("http://localhost:65152/api/Company/GetCompaniesByName", parameters.Item1, parameters.Item2, appkey); }
public static async Task <Dictionary <int, TimeSpan> > GetQueueSizeTimes(DateTimeOffset givenDate) { int lastQueueSize; string jobQuery; if (Period == StatPeriod.Day) { givenDate = BeginningOfDay(givenDate); DailyStatistic previousStat = (await WebApiHelper.Get <DailyStatistic>(string.Format("$filter=Date lt {0}&$top=1&$orderby=Date desc", FilterFormatDTO(givenDate)))).FirstOrDefault(); lastQueueSize = previousStat == null ? 0 : previousStat.LastQueueLength; jobQuery = string.Format("$filter=(Entered gt {0} and Entered lt {1}) or (Finished gt {0} and Finished lt {1})", FilterFormatDTO(givenDate), FilterFormatDTO(givenDate.AddDays(1))); } else { givenDate = BeginningOfMonth(givenDate); DailyStatistic previousStat = (await WebApiHelper.Get <DailyStatistic>(string.Format("$filter=Date lt {0}&$top=1&$orderby=Date desc", FilterFormatDTO(givenDate)))).FirstOrDefault(); lastQueueSize = previousStat == null ? 0 : previousStat.LastQueueLength; jobQuery = string.Format("$filter=(Entered gt {0} and Entered lt {1}) or (Finished gt {0} and Finished lt {1})", FilterFormatDTO(givenDate), FilterFormatDTO(givenDate.AddMonths(1))); } var jobs = await WebApiHelper.Get <Job>(jobQuery); var entered = jobs.Where(x => givenDate <= x.Entered && x.Entered < givenDate.AddDays(1)); var removed = jobs.Where(x => givenDate <= x.Finished && x.Finished < givenDate.AddDays(1)); List <QueueChange> changes = new List <QueueChange>(); foreach (var entry in entered) { changes.Add(new QueueChange() { type = QueueChange.ChangeType.Entered, date = entry.Entered }); } foreach (var removal in removed) { changes.Add(new QueueChange() { type = QueueChange.ChangeType.Removed, date = removal.Finished }); } var orderedChanges = changes.OrderBy(x => x.date).ToList(); if (DateTimeOffset.Now < givenDate.AddDays(1)) { orderedChanges.Add(new QueueChange() { date = DateTimeOffset.Now }); } else { orderedChanges.Add(new QueueChange() { date = givenDate.AddDays(1) }); } Dictionary <int, TimeSpan> sizeByTime = new Dictionary <int, TimeSpan>(); int prevSize = lastQueueSize; DateTimeOffset prevDate = givenDate; for (int i = 0; i < orderedChanges.Count(); i++) { if (!sizeByTime.ContainsKey(prevSize)) { sizeByTime[prevSize] = new TimeSpan(); } sizeByTime[prevSize] += orderedChanges[i].date.DateTime - prevDate.DateTime; if (orderedChanges[i].type == QueueChange.ChangeType.Entered) { prevSize++; } else { prevSize--; } } return(sizeByTime); }
public IList <Province> GetProvinces() { var url = Path.Combine(_apiUrl, "api/Location/Get"); return(WebApiHelper.Get <List <Province> >(url)); }
public JObject GetProcessList(JObject json) { json = json ?? new JObject(); Pagination page = json["Pagination"] == null?Pagination.GetDefaultPagination("GoodNo") : JsonConvert.DeserializeObject <Pagination>(json["Pagination"].ToString()); if (json["Param"]["SelectType"].ToString() == "good") { vw_MallGoodMainInfo goodInfo = JsonConvert.DeserializeObject <vw_MallGoodMainInfo>((json["Param"] ?? "").ToString()); return(service.GetGoodList(goodInfo, null, null, page));//获取商品信息 } else if (json["Param"]["SelectType"].ToString() == "order") { //思路:开发待处理视图。 //1.根据当前账号获取账号所有的权限(角色)。 //2.根据当前角色找到对应的虚拟账号。 //3.到最后取待处理的视图时候就是 Receiver in (‘虚拟账号1’,‘虚拟账号2 ’) v_framework_notify OrderInfo = JsonConvert.DeserializeObject <v_framework_notify>((json["Param"] ?? "").ToString()); CurrentLogin loginContent = (CurrentLogin)HttpContext.Current.Session["CurrentLogin"]; //获取处理人集合 string GetReceiverApi = AppSettingsConfig.GetBaseApi + "/api/Flow/GetReceivers"; Dictionary <string, string> parames = new Dictionary <string, string>(); parames.Add("userId", loginContent.User_Id); Tuple <string, string> parameters = WebApiHelper.GetQueryString(parames); var result = WebApiHelper.Get <dynamic>(GetReceiverApi, parameters.Item1, parameters.Item2, loginContent.User_Id); //拼接处理人的,in条件。(后续功能扩充,如果除了需要把公共账号相关表单带出来,还需要当前登录人带出来,就从session里面取UserID加到in的条件userStr里面。) string userStr = string.Empty; if ((bool)result["result"]) { List <dynamic> receives = JsonConvert.DeserializeObject <List <dynamic> >(result["content"].ToString()); foreach (var item in receives) { userStr += "," + item.ROLESERIAL; } } //把自身权限加入 userStr = userStr + "," + loginContent.User_Id; JObject ret = new JObject(); Expression <Func <v_framework_notify, bool> > expression = PredicateExtensions.True <v_framework_notify>(); if (OrderInfo != null) { if (!string.IsNullOrEmpty(OrderInfo.OrderNo)) { expression = expression.And(c => c.OrderNo.Contains(OrderInfo.OrderNo)); } if (!string.IsNullOrEmpty(OrderInfo.CURSTATUS_NAME)) { expression = expression.And(c => c.OrderNo.Contains(OrderInfo.CURSTATUS_NAME)); } if (!string.IsNullOrEmpty(OrderInfo.WFM_ID)) { expression = expression.And(c => c.WFM_ID.Contains(OrderInfo.WFM_ID)); } if (OrderInfo.Flow_ID > 0) { expression = expression.And(c => c.Flow_ID == OrderInfo.Flow_ID); } if (OrderInfo.CURSTATUS_ID > 0) { expression = expression.And(c => c.CURSTATUS_ID == OrderInfo.CURSTATUS_ID); } expression = expression.And(c => userStr.Contains(c.Receiver) && !c.IsWaster_ && c.IsFinish != 1); } //查询列表数据 ret = processService.GetList(expression, page); if ((bool)ret["result"]) { List <v_framework_notify> result_notify = JsonConvert.DeserializeObject <List <v_framework_notify> >(ret["content"].ToString()); foreach (var item in result_notify) { vw_MallGoodMainInfo good = service.FindList(c => c.GoodNo == item.GoodNo).FirstOrDefault(); item.GoodTitle = (good == null?"":good.GoodTitle); item.GameName = (good == null ? "" : good.GameName); item.GoodTypeName = (good == null ? "" : good.GoodTypeName); item.GoodKeyWord = (good == null ? "" : good.GoodKeyWord); } //插入进去。 ret["content"] = JToken.FromObject(result_notify); } return(ret); } else { return(null); } }
public IList <City> GetCities(string provinceId) { var url = Path.Combine(_apiUrl, " api/Location/Get"); return(WebApiHelper.Get <List <City> >(url)); }
public IList <City> GetDistricts(string cityId) { var url = Path.Combine(_apiUrl, " api/Location/Get"); return(WebApiHelper.Get <List <City> >(url)); }
public IList <Contact> List(string memberId) { return(WebApiHelper.Get <IList <Contact> >(_memberAddressUrl + "?memberId=" + memberId)); }