public Result ProcessData(Request request) { DateTime start; TimeSpan time; Worker.Priority = request.Priority; start = DateTime.Now; Console.WriteLine("Worker.ProcessData called for " + request.JobID + " - " + request.TaskID + "- priority=" + request.Priority); //process Data here and return processed data //Thread.Sleep(Worker.SleepTime); Result result = new Result(); result.JobID = request.JobID; result.TaskID = request.TaskID; // Console.Write("Calculating NPV for trades: { "); // foreach (int id in request.TradeIds) // { // Console.Write(id + " "); //} //Console.Write("}"); try { Dictionary <String, Double[]> resData = CalculateUtil.execute(tradeProxy, localCache, request.TradeIds, request.Rate); result.resultData = resData; time = DateTime.Now - start; result.Processingtime = time.Milliseconds; } catch (Exception e) { Console.WriteLine(e.ToString()); } return(result); }
public async Task <ActionResult> Edit(string path) { string userAuthenResult = await UserAuthentication(); if (!userAuthenResult.Equals(string.Empty)) { return(View(userAuthenResult)); } User user = GetUser(); string token = user.Token; FormControl formControl = await _formControlService.FindByPathForm(path); if (formControl == null) { return(View(ViewName.ERROR_404)); } string assign = formControl.Assign; bool isFormPending = CalculateUtil.IsFormPendingOrExpired(formControl.Start); bool isFormExpired = !CalculateUtil.IsFormPendingOrExpired(formControl.Expired); if (isFormPending || isFormExpired) { return(View(ViewName.ERROR_403)); } bool isFormAssignToUser = await IsFormAssignToUser(token, assign, user.IdGroup); if (assign.Equals(Keywords.AUTHENTICATED) || isFormAssignToUser) { string res1 = await _formService.FindFormWithToken(token, path); JObject resJSON = JObject.Parse(res1); string res2 = await _submissionService.FindSubmissionsByPage(token, path, 1); JArray jsonArray = JArray.Parse(res2); bool isNotSubmitted = jsonArray.Count == 0; if (isNotSubmitted) { ViewBag.Link = string.Empty; ViewBag.Title = Messages.HAS_NOT_SUBMITTED_MESSAGE; } else { ViewBag.Link = APIs.ModifiedForm(path); ViewBag.Title = resJSON.GetValue(Keywords.TITLE).ToString(); ViewBag.Id = ((JObject)jsonArray[0]).GetValue(Keywords.ID).ToString(); ViewBag.Data = ((JObject)jsonArray[0]).GetValue(Keywords.DATA).ToString(); } ViewBag.User = user; return(View(ViewName.EDIT_REPORT)); } return(View(ViewName.ERROR_404)); }
/// <summary> /// 更新棋局 /// </summary> public static void UpdateChessGame() { CalculateUtil.UpdateChessData(); //更新棋局 Dictionary <GameObject, Vector2> temp = new Dictionary <GameObject, Vector2>(); foreach (KeyValuePair <GameObject, Vector2> kvp in CalculateUtil.chess2Vector) { //一定要遍历赋值的,否则如果直接temp=CalculateUtil.chess2Vector就相当于引用了这个静态字典,没用 temp.Add(kvp.Key, kvp.Value); } maps.Add(temp); //添加棋谱 }
// GET: Orders public ActionResult Index() { fakeOrders = fakeOrders.Where(k => (k.orderDate).Year == 2017).ToList(); CalculateUtil cal = new CalculateUtil(); foreach (Order item in fakeOrders) { item.price = cal.CalculateDiscount(item.price, item.quantity); } //return View(fakeOrders); // ascending order by date return(View(fakeOrders.OrderBy(order => order.orderDate).ToList())); }
public void Getdiscount_If_Quantity_More_than_30() { //item.price = cal.CalculateDiscount(item.price, item.quantity); //Arrange Order obj = new Order(); CalculateUtil cal = new CalculateUtil(); obj.quantity = 40; //Act decimal result = cal.CalculateDiscount(obj.price, obj.quantity); //Assert Assert.AreEqual(Convert.ToDecimal(33.5), result); }
public void Getdiscount_If_Quantity_Less_Or_Equal_10() { //item.price = cal.CalculateDiscount(item.price, item.quantity); //Arrange Order obj = new Order(); CalculateUtil cal = new CalculateUtil(); obj.quantity = 5; //Act decimal result = cal.CalculateDiscount(obj.price, obj.quantity); //Assert Assert.AreEqual(Convert.ToDecimal(5.0), result); }
public async Task <List <Form> > FindForms(string token, string email, int page) { List <Form> list = new List <Form>(); string apiURI = APIs.FORM_URL + "?type=form&sort=-created&owner=" + email + "&limit=" + Configs.NUMBER_ROWS_PER_PAGE + "&skip=" + (page - 1) * Configs.NUMBER_ROWS_PER_PAGE + "&select=name,title,path,tags"; HttpResponseMessage response = await _httpUtil.GetAsync(token, apiURI); if (response == null || !response.IsSuccessStatusCode) { return(list); } string content = await response.Content.ReadAsStringAsync(); JArray jArray = JArray.Parse(content); foreach (JObject jObject in jArray) { string name = jObject.GetValue(Keywords.NAME).ToString(); string title = jObject.GetValue(Keywords.TITLE).ToString(); string path = jObject.GetValue(Keywords.PATH).ToString(); long amount = await _submissionService.CountSubmissions(token, path); FormControl formControl = await _formControlService.FindByPathForm(path); if (formControl == null) { return(list); } string start = formControl.Start; string expired = formControl.Expired; string assign = formControl.Assign; List <string> tags = new List <string>(); foreach (string tag in JArray.Parse(jObject.GetValue(Keywords.TAGS).ToString())) { tags.Add(tag); } int durationPercent = CalculateUtil.GetDurationPercent(start, expired); string typeProgressBar = CalculateUtil.GetTypeProgressBar(durationPercent); list.Add(new Form(name, title, path, amount, start, expired, tags, durationPercent, typeProgressBar, assign.Equals(Keywords.ANONYMOUS))); } return(list); }
public static void GenenateJobs() { int parallelThread = 10; for (int i = 0; i < NumberOfJobs / parallelThread; i++) { GridService[] gridServiceA = new GridService[parallelThread]; for (int j = 0; j < parallelThread; j++) { GridService gridService = GridAPI.createService(i + ""); Dictionary <String, String> parameters = new Dictionary <String, String>(); parameters.Add("param1", ((i * 10) + j) + ""); Console.WriteLine("Submiting Job"); Job job = gridService.Submit("Function1", parameters); gridServiceA[j] = gridService; } stopWatch.Start(); Task <ServiceData>[] taskArray = { Task <ServiceData> .Factory.StartNew(() => gridServiceA[0].CollectNext(1000)), Task <ServiceData> .Factory.StartNew(() => gridServiceA[1].CollectNext(1000)), Task <ServiceData> .Factory.StartNew(() => gridServiceA[2].CollectNext(1000)), Task <ServiceData> .Factory.StartNew(() => gridServiceA[3].CollectNext(1000)), Task <ServiceData> .Factory.StartNew(() => gridServiceA[4].CollectNext(1000)), Task <ServiceData> .Factory.StartNew(() => gridServiceA[5].CollectNext(1000)), Task <ServiceData> .Factory.StartNew(() => gridServiceA[6].CollectNext(1000)), Task <ServiceData> .Factory.StartNew(() => gridServiceA[7].CollectNext(1000)), Task <ServiceData> .Factory.StartNew(() => gridServiceA[8].CollectNext(1000)), Task <ServiceData> .Factory.StartNew(() => gridServiceA[9].CollectNext(1000)) }; ServiceData[] serviceDataA = new ServiceData[taskArray.Length]; for (int k = 0; k < taskArray.Length; k++) { serviceDataA[k] = taskArray[k].Result; for (int l = 0; l < serviceDataA[k].Data.Length; l++) { if (serviceDataA[k].Data[l] != null) { CalculateUtil.subreducer(aggResults, serviceDataA[k].Data[l].resultData); totalCalcTime += serviceDataA[k].Data[l].Processingtime; } } Console.WriteLine("From GenenateJobs using Task now Results found for k=" + k); } } }
/// <summary> /// 悔棋点击事件 /// </summary> public void Undo_Click() { if (maps.Count >= 3) { Dictionary <GameObject, Vector2> temp = maps[maps.Count - 1 - 2]; foreach (KeyValuePair <GameObject, Vector2> kvp in temp) { CalculateUtil.ResetChessByMaps(kvp.Key, kvp.Value); } maps.RemoveRange(maps.Count - 2, 2); CalculateUtil.UpdateChessData(); ResetChessReciprocalStateEvent(); Chess_Boss.DetectBeAttacked(CalculateUtil.chess2Vector, CalculateUtil.vector2Chess); } else { //GameObject.Find("UndoButton").GetComponent<Button>().enabled = false; } }
//玩家击打动作 public void play() { if (isTouch) { //获取手柄速度 bingV = VRTK_DeviceFinder.GetControllerRightHand().GetComponent <VRTK_ControllerEvents>().GetVelocity(); if (bingV.magnitude > 0.8f && !isMoved) //如果玩家挥拍了 { isMoved = true; //移动标志位置true gailv(); //判断概率 gestureJudge(); //判断手势 position = qiu.transform.position; //获取球的位置 qiu.GetComponent <Rigidbody>().velocity = speA; //给球一个回去的速度 resultB = CalculateUtil.getPosAndSpeB(position, speA); //计算球落点的位置 posB = resultB[0]; //计算落球点B的位置 shock(); //判断游戏是否结束 Constant.isOutside = false; //顺利运行到这里表示未出界 isTouch = false; //球未到玩家击球范围 } } }
/// <summary> /// 通过AI来移动 /// </summary> /// <param name="chess2Vector"></param> /// <param name="vector2Chess"></param> /// <param name="target">移动的目标位置</param> /// <param name="realMove">是真的移动还是假设移动?</param> public void Move(Dictionary <GameObject, Vector2> chess2Vector, Dictionary <Vector2, GameObject> vector2Chess, Vector2 target, bool realMove) { Vector2[] canMovePoints = CanMovePoints(chess2Vector, vector2Chess).ToArray(); //真正的移动 if (realMove) { } else//假设移动 { for (int i = 0; i < canMovePoints.Length; i++) { if (target == canMovePoints[i]) { //假设移动完后,获取移动后的棋局状况 然后再检测有没有将军 ArrayList moveAssumptionData = CalculateUtil.MoveAssumption(gameObject, target); //这里假设后的检测将军需要检测是否是我方受将军,是则不允许这么走 //.......TODO Chess_Boss.DetectBeAttacked((Dictionary <GameObject, Vector2>)moveAssumptionData[0], (Dictionary <Vector2, GameObject>)moveAssumptionData[1]); } } } }
private async Task <List <Form> > AddFormToList(string token, List <Form> listForm, List <FormControl> listFormControl) { foreach (FormControl formControl in listFormControl) { string path = formControl.PathForm; string start = formControl.Start; string expired = formControl.Expired; int durationPercent = CalculateUtil.GetDurationPercent(start, expired); string typeProgressBar = CalculateUtil.GetTypeProgressBar(durationPercent); string formRes = await _formService.FindFormWithToken(token, path); JObject formResJSON = JObject.Parse(formRes); if (formResJSON.Count == 0) { return(listForm); } string title = formResJSON.GetValue(Keywords.TITLE).ToString(); List <string> tags = new List <string>(); JArray tagsArray = (JArray)formResJSON.GetValue(Keywords.TAGS); foreach (JObject tag in tagsArray) { tags.Add(tag.ToString()); } string submissionsRes = await _submissionService.FindSubmissionsByPage(token, path, 1); JArray submissionResJSON = JArray.Parse(submissionsRes); bool isSubmitted = submissionResJSON.Count != 0; bool isPending = CalculateUtil.IsFormPendingOrExpired(start); listForm.Add(new Form(title, path, start, expired, tags, durationPercent, typeProgressBar, isSubmitted, isPending)); } return(listForm); }
public static void Main(string[] args) { url = args[0]; Int32 batchSize = 10000; numOfTrades = Convert.ToInt32(args[1]); Console.WriteLine("Connecting to Space:" + url); SpaceProxy = GigaSpacesFactory.FindSpace(url); Console.WriteLine("Inserting " + numOfTrades + " Trades in the space"); Int32 k = 0; Trade[] trades; if (numOfTrades <= batchSize) { trades = new Trade[numOfTrades]; for (int i = 0; i < numOfTrades; i++) { trades[i] = CalculateUtil.generateTrade(i + 1); } SpaceProxy.WriteMultiple(trades); } else { for (int i = 0; i < numOfTrades / batchSize; i++) { trades = new Trade[batchSize]; for (int j = 0; j < batchSize; j++) { trades[j] = CalculateUtil.generateTrade(k + 1); k++; } SpaceProxy.WriteMultiple(trades); } } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }