/* * Developer: Hamza haq * Date: 17-9-19 * Action: update calculation_Values to database * Input: CalculationValuesToUpdate * output: result */ public async Task <Boolean> Update(CalculationValues CalculationValuesToUpdate) { using (IDbConnection conn = Connection) { var result = await conn.UpdateAsync <CalculationValues>(CalculationValuesToUpdate); return(result); } }
/* * Developer: Hamza haq * Date: 17-9-19 * Action: creating new calculation_Values to database * Input: new attribute * output: attribute id */ public async Task <string> Create(CalculationValues NewCalculationValues) { using (IDbConnection conn = Connection) { var result = await conn.InsertAsync <CalculationValues>(NewCalculationValues); return(result.ToString()); } }
public bool IsBlockInTheWay(Vector3D origin, Vector3D targetPos) { Vector3I relativePos = grid.WorldToGridInteger(origin); Vector3I relativeTargetPos = grid.WorldToGridInteger(targetPos); Vector3I direction = (Vector3I)(relativeTargetPos - relativePos); CalculationValues calcPackage = new CalculationValues { relativePosRounded = relativePos, direction = direction }; return(cachedBlockSearch.Execute(calcPackage)); }
public async Task <string> PostAsync([FromBody] string value) { string NewInsertionID = "0"; try { CalculationValues newAttributes = JsonConvert.DeserializeObject <CalculationValues>(value); NewInsertionID = await _CalculationValuesRepo.Create(newAttributes); } catch (Exception ex) { var logger = _loggerFactory.CreateLogger("internal_error_log"); logger.LogInformation("Problem happened in making new attribute type with message" + ex.Message); } return(NewInsertionID); }
public async Task <List <CalculationValues> > GetAsync(int id) { List <CalculationValues> ToReturn = new List <CalculationValues>(); try { CalculationValues Res = await _CalculationValuesRepo.GetById(id); ToReturn.Add(Res); } catch (Exception ex) { var logger = _loggerFactory.CreateLogger("internal_error_log"); logger.LogInformation("Problem happened in selecting the data for GetAsync with message" + ex.Message); } return(ToReturn); }
/* * Developer: Hamza haq * Date: 17-9-19 * Action: creating new calculation_Values to database * Input: refference_id , calculation_id, value, IncreaseQty * output: calculation id */ public async Task <string> CreateProductCalculation(string refference_id, int calculation_id, double value, bool IncreaseQty) { var returnResult = ""; CalculationValues _CalculatedValue = new CalculationValues(); string CalculatedValueExistsQuery = "SELECT * FROM calculation_values WHERE calculation_id='" + calculation_id + "' and reffrence_id='" + refference_id + "';"; using (IDbConnection conn = Connection) { var CalculatedValueExists = await conn.QueryAsync <CalculationValues>(CalculatedValueExistsQuery); if (CalculatedValueExists == null || CalculatedValueExists.Count() == 0) { _CalculatedValue.reffrence_id = refference_id; _CalculatedValue.calculation_id = calculation_id; _CalculatedValue.value = value; var result = await conn.InsertAsync <CalculationValues>(_CalculatedValue); returnResult = result.ToString(); } else { _CalculatedValue = CalculatedValueExists.First(); if (IncreaseQty) { _CalculatedValue.value = _CalculatedValue.value + value; } else { _CalculatedValue.value = _CalculatedValue.value - value; } var result = await conn.UpdateAsync <CalculationValues>(_CalculatedValue); returnResult = result.ToString(); } } return(returnResult); }
public async Task <string> Update(int id, [FromBody] string value) { string UpdateResult = "Success"; bool UpdateProcessOutput = false; try { CalculationValues CalculationValuesToUpdate = JsonConvert.DeserializeObject <CalculationValues>(value); CalculationValuesToUpdate.calculation_id = id; UpdateProcessOutput = await _CalculationValuesRepo.Update(CalculationValuesToUpdate); } catch (Exception ex) { var logger = _loggerFactory.CreateLogger("internal_error_log"); logger.LogInformation("Problem happened in updating attribute type with message" + ex.Message); UpdateResult = "Failed"; } if (!UpdateProcessOutput) { UpdateResult = "Creation failed due to reason: No specific reson"; } return(UpdateResult); }
public bool IsBlockInTheWay(CalculationValues calcValues) { BoundingBox box = new BoundingBox(grid.Min, grid.Max); var Ray = new Ray(calcValues.relativePosRounded, calcValues.direction); float? intersects = box.Intersects(Ray); if (!intersects.HasValue) { return(false); } Vector3D searchDir = Vector3D.Normalize(calcValues.direction); Vector3I startPos = (Vector3I)((Vector3D)calcValues.relativePosRounded + ((intersects.Value + 1) * searchDir)); int x1 = startPos.X; int y1 = startPos.Y; int z1 = startPos.Z; int x2 = startPos.X + calcValues.direction.X; int y2 = startPos.Y + calcValues.direction.Y; int z2 = startPos.Z + calcValues.direction.Z; // Bresenham algorythm, implementation borrowed from https://gist.github.com/yamamushi/5823518 int i, dx, dy, dz, l, m, n, x_inc, y_inc, z_inc, err_1, err_2, dx2, dy2, dz2; int[] point = new int[3]; point[0] = x1; point[1] = y1; point[2] = z1; dx = x2 - x1; dy = y2 - y1; dz = z2 - z1; x_inc = (dx < 0) ? -1 : 1; l = Math.Abs(dx); y_inc = (dy < 0) ? -1 : 1; m = Math.Abs(dy); z_inc = (dz < 0) ? -1 : 1; n = Math.Abs(dz); dx2 = l << 1; dy2 = m << 1; dz2 = n << 1; if ((l >= m) && (l >= n)) { err_1 = dy2 - l; err_2 = dz2 - l; for (i = 0; i < l; i++) { if (!((point[0] <= grid.Max.X && point[0] >= grid.Min.X) && (point[1] <= grid.Max.Y && point[1] >= grid.Min.Y) && (point[2] <= grid.Max.Z && point[2] >= grid.Min.Z))) { return(false); } if (cubeExists.Execute(new Vector3I(point[0], point[1], point[2]))) { return(true); } if (err_1 > 0) { point[1] += y_inc; err_1 -= dx2; } if (err_2 > 0) { point[2] += z_inc; err_2 -= dx2; } err_1 += dy2; err_2 += dz2; point[0] += x_inc; } } else if ((m >= l) && (m >= n)) { err_1 = dx2 - m; err_2 = dz2 - m; for (i = 0; i < m; i++) { if (!((point[0] <= grid.Max.X && point[0] >= grid.Min.X) && (point[1] <= grid.Max.Y && point[1] >= grid.Min.Y) && (point[2] <= grid.Max.Z && point[2] >= grid.Min.Z))) { return(false); } if (cubeExists.Execute(new Vector3I(point[0], point[1], point[2]))) { return(true); } if (err_1 > 0) { point[0] += x_inc; err_1 -= dy2; } if (err_2 > 0) { point[2] += z_inc; err_2 -= dy2; } err_1 += dx2; err_2 += dz2; point[1] += y_inc; } } else { err_1 = dy2 - n; err_2 = dx2 - n; for (i = 0; i < n; i++) { if (!((point[0] <= grid.Max.X && point[0] >= grid.Min.X) && (point[1] <= grid.Max.Y && point[1] >= grid.Min.Y) && (point[2] <= grid.Max.Z && point[2] >= grid.Min.Z))) { return(false); } if (cubeExists.Execute(new Vector3I(point[0], point[1], point[2]))) { return(true); } if (err_1 > 0) { point[1] += y_inc; err_1 -= dz2; } if (err_2 > 0) { point[0] += x_inc; err_2 -= dz2; } err_1 += dy2; err_2 += dx2; point[2] += z_inc; } } if (cubeExists.Execute(new Vector3I(point[0], point[1], point[2]))) { return(true); } return(false); }
private void CreateRandomCalculationCaptchaText() { CalculationValues[] Calculations = new CalculationValues[3]; bool PowerUsing = false; char[] Operation; Random Rnd = new Random(); int Result = 0; int BracketBlock = 0; int Index = 0; bool IsHaveBracket = (Rnd.Next(1, 255) % 2) == 0; string BlkBeg1 = string.Empty, BlkEnd1 = string.Empty, BlkBeg2 = string.Empty, BlkEnd2 = string.Empty; string[] Pows = new string[] { "", "", "" }; if (IsHaveBracket) BracketBlock = (Rnd.Next(1, 255) % 2) == 0 ? 1 : 2; for (int i = 0; i < 3; i++) { PowerUsing = IncludePower ? ((Rnd.Next(1, 9999) % 2) == 0) : false; Calculations[i].IsHavePower = PowerUsing; Calculations[i].Number = Rnd.Next(1, 4); if (Calculations[i].IsHavePower) { Calculations[i].Power = Rnd.Next(1, 4); Pows[i] = Powers[Calculations[i].Power].ToString(); } } Operation = new char[] { Operations[Rnd.Next(0, 3)], Operations[Rnd.Next(0, 3)] }; if (IsHaveBracket) { Index = BracketBlock - 1; Result += Calculate(Operation[Index],CalculateItem(Calculations[Index]),CalculateItem(Calculations[Index+1])); if (BracketBlock == 1) Result = Calculate(Operation[1],Result,CalculateItem(Calculations[2])); else Result = Calculate(Operation[0], CalculateItem(Calculations[0]), Result); } else { Result = Calculate(Operation[0], CalculateItem(Calculations[0]), CalculateItem(Calculations[1])); Result = Calculate(Operation[1], Result, CalculateItem(Calculations[2])); } if (IsHaveBracket) { if (BracketBlock == 1) { BlkBeg1 = "("; BlkEnd1 = ")"; } else { BlkBeg2 = "("; BlkEnd2 = ")"; } } CaptchaString = string.Format(FormatStr, BlkBeg1, Calculations[0].Number, Pows[0], Operation[0], BlkBeg2, Calculations[1].Number, Pows[1], BlkEnd1, Operation[1], Calculations[2].Number, Pows[2], BlkEnd2 ); CaptchaCalculationResult = Result.ToString(); }
private int CalculateItem(CalculationValues Value) { int Result = Value.Number; if (Value.IsHavePower) Result = (int)Math.Pow(i2d(Value.Number), i2d(Value.Power)); return Result; }