public async Task<PCalcResultInfo> Calculate(EnvironmentInfo environment, ProductDescriptionInfo productDescription, ActionResultInfo actionResult) { var result = new PCalcResultInfo(); result.ProductDescription = productDescription; DescriptionInfo desc = GetRandomDescription(); result.QueryType = GetQueryType(desc); result.QueryDescription = desc.ToTransferDescription(); return result; }
public void SetUp() { Assert.IsTrue(m_AmxFile.Exists); Assert.IsTrue(m_TableFile.Exists); m_Environment = new EnvironmentInfo { Culture = "deDE", SenderZipCode = "121" }; m_Weight = new WeightInfo { WeightUnit = EWeightUnit.TenthGram, WeightValue = 200 }; m_ExpectedMaximum = TimeSpan.FromMilliseconds(1000); m_Watch.Reset(); m_Watch.Start(); }
public async Task<PCalcResultInfo> StartCalculation(EnvironmentInfo environment, WeightInfo weight) { //lookup correct entry ScenarioResult initResult = await m_ScenarioRunner.RunAsync(InitFileHandler(environment)); if (initResult.Success == false || m_Handler.IsValid == false) { return ReturnErrorResult(initResult); } ScenarioResult<PCalcResultInfo> startResult = m_ScenarioRunner.Run(() => Start(environment, weight, m_Handler)); if(startResult.Success == false) { return ReturnErrorResult(startResult); } return startResult.Value; }
private void RunStart() { EnvironmentInfo environment = new EnvironmentInfo { Culture = "deDE", SenderZipCode = "121" }; WeightInfo weight = new WeightInfo { WeightUnit = EWeightUnit.TenthGram, WeightValue = 200 }; Assert.That(new FileInfo("Pt2097152.amx").Exists, Is.True); Assert.That(new FileInfo("Pt2097152.bin").Exists, Is.True); using (var context = new PCalcProxyContext(environment, new FileInfo("Pt2097152.amx").FullName, new FileInfo("Pt2097152.bin").FullName)) { Assert.That(context.Proxy, Is.Not.Null); IPCalcProxy proxy = context.Proxy; proxy.Start(environment, weight); } }
public async Task<PCalcResultInfo> Calculate(EnvironmentInfo environment, ProductDescriptionInfo productDescription, ActionResultInfo actionResult) { //lookup correct entry ScenarioResult initResult = await m_ScenarioRunner.RunAsync(InitFileHandler(environment)); if (initResult.Success == false || m_Handler.IsValid == false) { return ReturnErrorResult(initResult); } ScenarioResult<PCalcResultInfo> calcResult = m_ScenarioRunner.Run(() => Calculate(environment, productDescription, actionResult, m_Handler)); if (calcResult.Success == false) { return ReturnErrorResult(calcResult); } return calcResult.Value; }
public async Task<PCalcResultInfo> UpdateWeight(EnvironmentInfo environment, ProductDescriptionInfo productDescription) { //lookup correct entry ScenarioResult initResult = await m_ScenarioRunner.RunAsync(InitFileHandler(environment)); if (initResult.Success == false || m_Handler.IsValid == false) { return ReturnErrorResult(initResult); } ScenarioResult<PCalcResultInfo> updateWeightResult = m_ScenarioRunner.Run(() => UpdateWeight(environment, productDescription, m_Handler)); if (updateWeightResult.Success == false) { return ReturnErrorResult(updateWeightResult); } return updateWeightResult.Value; }
public ActionResult Index() { string pawnFile = HttpContext.Server.MapPath("~/App_Data/Pt2097152.amx"); string tableFile = HttpContext.Server.MapPath("~/App_Data/Pt2097152.bin"); EnvironmentInfo env = new EnvironmentInfo() { Culture = "de", SenderZipCode = "123" }; using (var context = new PCalcProxyContext(env, pawnFile, tableFile)) { IPCalcProxy proxy = context.Proxy; PCalcResultInfo result = null; result = proxy.Start(env, new WeightInfo() { WeightUnit = EWeightUnit.Gram, WeightValue = 20 }); result = proxy.Calculate(env, result.ProductDescription, new ActionResultInfo() { Action = EActionId.ShowMenu, Label = 0, Results = new List<AnyInfo> { new AnyInfo() { AnyType = EAnyType.INT32, AnyValue = "0" } } }); result = proxy.Calculate(env, result.ProductDescription, new ActionResultInfo() { Action = EActionId.ShowMenu, Label = 0, Results = new List<AnyInfo> { new AnyInfo() { AnyType = EAnyType.INT32, AnyValue = "0" } } }); } return View(); }
public async Task<PCalcResultInfo> StartCalculation(EnvironmentInfo environment, WeightInfo weight) { var result = new PCalcResultInfo(); result.ProductDescription = new ProductDescriptionInfo() { Postage = new PostageInfo() { CurrencySymbol = "$", PostageDecimals = 2, PostageValue = 200 }, ProductCode = 1, ProductId = 34, RateVersion = 2007654, ScaleMode = EScaleMode.NO_SCALE, State = EProductDescriptionState.Incomplete, Weight = weight, WeightClass = 1 }; DescriptionInfo desc = GetRandomDescription(); result.QueryType = GetQueryType(desc); result.QueryDescription = desc.ToTransferDescription(); return result; }
public async Task Initialize(EnvironmentInfo environment) { IEnumerable<RateTableInfo> rateTables = await m_Manager.GetFiltered(string.Empty, string.Empty, environment.CarrierId, DateTime.MinValue, environment.UtcDate, environment.Culture, 0, 0, true); RateTableInfo currentTable = rateTables.OrderByDescending(t => t.ValidFrom).FirstOrDefault(); if (null != currentTable) { List<string> otherRateCalculationFiles = new List<string>(); string storagePath = Path.Combine(Path.GetTempPath(), RT_FOLDER); if(Directory.Exists(storagePath) == false) { Directory.CreateDirectory(storagePath); } foreach (var file in currentTable.PackageFiles) { string filePath = Path.Combine(storagePath, string.Format("{0}_{1}_{2}",currentTable.Variant, currentTable.VersionNumber, file.FileName)); if (File.Exists(filePath) == false) { using (FileStream fs = File.Create(filePath)) { await fs.WriteAsync(file.FileData.ToArray(), 0, file.FileData.Count()); } } if (file.FileType == EFileType.PawnCode) { m_PawnFile = filePath; } else if (file.FileType == EFileType.RateTable) { m_RateTableFile = filePath; } else { otherRateCalculationFiles.Add(filePath); } } m_AdditionalFiles = otherRateCalculationFiles.ToArray(); } }
private void AddOrUpdateTempData(PCalcResultInfo result, EnvironmentInfo environment) { if (TempData.ContainsKey(PCALC_RESULT)) { TempData[PCALC_RESULT] = result; } else { TempData.Add(PCALC_RESULT, result); } if (TempData.ContainsKey(ENVIRONMENT)) { TempData[ENVIRONMENT] = environment; } else { TempData.Add(ENVIRONMENT, environment); } }
private void AddViewData(PCalcResultInfo result, EnvironmentInfo environment) { ViewData.Add(PRODUCT_DESCRIPTION, result?.ProductDescription); ViewData.Add(WEIGHT, result?.ProductDescription?.Weight); ViewData.Add(POSTAGE, result?.ProductDescription?.Postage); ViewData.Add(REQUEST_DESCRIPTION, result?.DedicatedDescription); ViewData.Add(ENVIRONMENT, environment); }
public async Task<PCalcResultInfo> UpdateWeight(EnvironmentInfo environment, ProductDescriptionInfo productDescription) { throw new NotImplementedException(); }
private async Task<ActionResult> HandleCalculation(ActionResultInfo actionResult, EnvironmentInfo environment) { PCalcResultInfo lastResult = GetLastPcalcResult(); if (null == lastResult) { return HandleGeneralError("Index", ProductCalculationViewModel.Create(EQueryType.None), "Unable to retrieve last product"); } if (null == environment) { return HandleGeneralError("Index", ProductCalculationViewModel.Create(EQueryType.None), "Unable to retrieve environment information"); } CalculateRequest calc = new CalculateRequest(); calc.Environment = environment; calc.ProductDescription = lastResult.ProductDescription; calc.ActionResult = actionResult; ApiResponse<PCalcResultInfo> response = await m_Repository.Calculate(calc); if (IsApiError(response) || PcalcResultIsValid(response.ApiResult) == false) { return HandleGeneralPcalcError("Index", ProductCalculationViewModel.Create(EQueryType.None), response.ApiResult); } AddOrUpdateTempData(response.ApiResult, calc.Environment); AddViewData(response.ApiResult, environment); return View("Index", ProductCalculationViewModel.Create(response.ApiResult.QueryType)); }
private PCalcResultInfo Start(EnvironmentInfo info, WeightInfo weight) { using (var context = new PCalcProxyContext(info, m_AmxFile.FullName, m_TableFile.FullName)) { IPCalcProxy proxy = context.Proxy; Assert.That(proxy, Is.Not.Null); return proxy.Start(m_Environment, weight); } }
private PCalcResultInfo Calculate(EnvironmentInfo info, ProductDescriptionInfo product, ActionResultInfo actionResult) { using (var context = new PCalcProxyContext(info, m_AmxFile.FullName, m_TableFile.FullName)) { IPCalcProxy proxy = context.Proxy; Assert.That(proxy, Is.Not.Null); return proxy.Calculate(info, product, actionResult); } }
private async Task<ScenarioResult<RateCalculationFileHandler>> InitFileHandler(EnvironmentInfo info) { await m_Handler.Initialize(info); return new ScenarioResult<RateCalculationFileHandler>() { Success = true, Value = m_Handler }; }
private ScenarioResult<PCalcResultInfo> Start(EnvironmentInfo environment, WeightInfo weight, RateCalculationFileHandler handler) { using (var context = new PCalcProxyContext(environment, handler.PawnFile, handler.RateTableFile, handler.AdditionalFiles)) { IPCalcProxy proxy = context.Proxy; PCalcResultInfo result = proxy.Start(environment, weight); HandleCurrencySymbol(result, environment); return new ScenarioResult<PCalcResultInfo>() { Value = result }; } }
private ScenarioResult<PCalcResultInfo> UpdateWeight(EnvironmentInfo environment, ProductDescriptionInfo description, RateCalculationFileHandler handler) { using (var context = new PCalcProxyContext(environment, handler.PawnFile, handler.RateTableFile, handler.AdditionalFiles)) { IPCalcProxy proxy = context.Proxy; PCalcResultInfo result = proxy.Calculate(environment, description); HandleCurrencySymbol(result, environment); return new ScenarioResult<PCalcResultInfo>() { Value = result }; } }
public void SetUp() { m_TestCount++; m_Environment = new EnvironmentInfo() { Culture = "de", UtcDate = DateTime.Now.AddDays(m_TestCount), SenderZipCode = "123" }; }
private void HandleCurrencySymbol(PCalcResultInfo result, EnvironmentInfo environment) { if(null != result && null != result.ProductDescription && null != result.ProductDescription.Postage && null != environment ) { m_ScenarioRunner.Run(() => { CultureInfo info = new CultureInfo(environment.Culture); result.ProductDescription.Postage.CurrencySymbol = info.NumberFormat.CurrencySymbol; result.ProductDescription.Postage.CurrencyDecimalSeparator = info.NumberFormat.CurrencyDecimalSeparator; }); } }