/* * public static DepotOperationResultStatus ProcessDepotBOMRequest(string targetFormulaKey, int rmFormulaLowerLimitValidation, int rmFormulaUpperLimitValidation, List<BOMIngredient> bomIngredients, int? existingRequestId = 0) * { * //assumptions: all formulations are in WERCS, so we don't need to go to Depot for anything here. * //if a formula for a material in the BOM isn't in WERCS, it should be imported into WERCS before starting the BOM formula request * UpdatedBy = GetCurrentUser(); * * //List<DepotOperationResultStatus> request_ret = new List<DepotOperationResultStatus>(); * //DepotOperationResultStatus r; * //string[] lookupKeys = new string[bomIngredients.Count() - 1]; * * //loop in get_bos_depot and see if there's errors * * DepotOperationResultStatus bos_ret = DbEfFactory.AddDepotBOMRequest(targetFormulaKey, bomIngredients, rmFormulaLowerLimitValidation, rmFormulaUpperLimitValidation, "BOM Request", UpdatedBy, null); * * List<BOMIngredient> depotParts = bomIngredients.Where(p => p.RMSource.ToLower().Contains("depot")).ToList<BOMIngredient>(); * //List<BOMIngredient> wercsParts = bomIngredients.Where(p => p.RMSource.ToLower().Contains("wercs")).ToList<BOMIngredient>(); * if (depotParts?.Any() ?? false) * { * string prodKeys = string.Join(",", depotParts.Select(a => a.RMKey.ToString())); * List<DepotOperationResultStatus> get_bos_depot = ProcessDepotRequest(prodKeys, sourceSystem: "Depot", overrideBOSErrors: true, formulaLowerPercentValidation:0, formulaUpperPercentValidation:0, existingRequestId:bos_ret.RequestId); * } * * //DepotOperationResultStatus ret = new DepotOperationResultStatus(); * if (bos_ret.RequestId > 0 && string.IsNullOrEmpty(bos_ret.ErrorMessage)) * bos_ret = DbEfFactory.ProcessBOMRequest(bos_ret.RequestId, targetFormulaKey, "Depot"); * * return bos_ret; * * } */ public static List <DepotOperationResultStatus> TEST_ProcessDepotGetCalculatedBosRequest(string prodKeys, string sourceSystem, bool overrideBOSErrors, int formulaLowerPercentValidation, int formulaUpperPercentValidation, int?existingRequestId = 0) { UpdatedBy = GetCurrentUser(); //existingRequestId: is this a brand new request (existingRequestId = 0) or a request that was partially processed before List <DepotOperationResultStatus> request_ret = new List <DepotOperationResultStatus>(); DepotOperationResultStatus r; string[] lookupKeys; string prodKeysCommaDelimited = Regex.Replace(prodKeys, @"\r\n?|\n", ","); if (existingRequestId == 0) { lookupKeys = prodKeysCommaDelimited.Replace(" ", "").Split(','); //allow only one or no spaces between commas } else { lookupKeys = DbEfFactory.GetUnprocessedRequestParts(existingRequestId.GetValueOrDefault()); //allow only one or no spaces between commas } IMapper mapper = MapUtil.Mapper; string depotUser = depotAccessRecord.DepotUser; string depotPwd = depotAccessRecord.DepotPass; var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{depotUser}:{depotPwd}")); var depotAuth = new AuthenticationHeaderValue("Basic", credentials); using (HttpClient client = new HttpClient()) { var depot = new GpsDepotClient(depotAccessRecord.DepotUrl, client); string errorMsg = ""; Dictionary <string, DepotPart> bestparts = (mapper.Map <List <Part>, List <DepotPart> >(depot.GetPartsAsync(new PartControllerGetPartsRequest() { BestPartsOnly = true, SrcKeys = lookupKeys, }).GetAwaiter().GetResult().ToList <Part>()) ?? new List <DepotPart>(0)).ToDictionary(p => p.PartSrcKey, p => p, StringComparer.OrdinalIgnoreCase); DepotOperationResultStatus bos_ret = DbEfFactory.AddDepotFormulaRequest(prodKeysCommaDelimited, formulaLowerPercentValidation, formulaUpperPercentValidation, bestparts, "Depot", "Formula Request", UpdatedBy); ICalculatedComponentsResult result; foreach (KeyValuePair <string, DepotPart> thispart in bestparts) { //ICalculatedComponentsResult result = depot.BillOfSubstance.GetCalculatedComponentsForBestPart(sourcekey, forSds: true, requireSDSSpecific: false, includeFragranceComposition: true); //thispart.PartKey = "91119915.004"; //ICalculatedComponentsResult result = depot.BillOfSubstance.GetCalculatedComponentsForPart(thispart.Value, forSds: true, includeFragranceComposition: true, requireSDSSpecific: false); result = depot.GetCalculatedComponentsForPartAsync(part: thispart.Value, forSds: true, includeFragranceComposition: true, includeGpsConfidentialComposition: false ).GetAwaiter().GetResult(); bos_ret.ResultCount = result.CalculatedComponents?.Count() ?? 0; //more processing it... just testing various methods of the depot.BillOfSubstance } } return(request_ret); }
public ActionResult DeleteAction(bool confirm, int id, string SourceSystem) { if (confirm) { DbEfFactory.DeleteDepotFormulaRequest(id, SourceSystem); } return(RedirectToAction("Index")); }
//[Authorize(Roles = "admin")] public ActionResult StageBOMRequest(bool confirm, int id, string SourceSystem) { if (confirm) { DbEfFactory.ProcessBOMRequest(id, "", SourceSystem); } //return RedirectToAction("RequestQueueIndex"); return(RedirectToAction("Index")); }
//[Authorize, ValidateAntiForgeryToken] public ActionResult RequestQueueIndex(int id, string productKeyList, string sourceSystem) { if (string.IsNullOrEmpty(productKeyList)) { return(View(DbEfFactory.GetFormulaImportRequestQueue(id, sourceSystem))); } else { return(View(DbEfFactory.GetFormulaImportRequestQueueByProductList(productKeyList, sourceSystem))); } }
public FileResult RequestQueueExport(int id, string sourceSystem) { DataTable dt = DbEfFactory.GetFormulaImportResultReport(id, sourceSystem); using (XLWorkbook wb = new XLWorkbook()) { wb.Worksheets.Add(dt); using (MemoryStream stream = new MemoryStream()) { wb.SaveAs(stream); return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "RequestReport_" + id.ToString() + ".xlsx")); } } }
private void DisplayBOMRequestResult(int RequestId, string targetFormulaKey) { if ((string.IsNullOrEmpty(targetFormulaKey)) || string.Compare(targetFormulaKey, "none") >= 0) { targetFormulaKey = DbEfFactory.GetBOMRequestTargetKey(RequestId); } List <BOMRequestResultHeader> bomRequestResultHeader = DbEfFactory.GetBOMRequestResultHeader(RequestId, targetFormulaKey); if (bomRequestResultHeader.Count() > 0) { BindBOMResultHeaderGrid(bomRequestResultHeader); } List <BOMRequestResultErrorDetail> bomRequestResultErrorDetail = DbEfFactory.GetBOMRequestResultErrorDetail(RequestId, targetFormulaKey); htmlRequestId.Value = RequestId.ToString(); //bomRequestResultHeader[0].RequestId.ToString(); htmlTargetFormulaKey.Value = targetFormulaKey; // bomRequestResultHeader[0].TargetKey; BindBOMResultErrorDetailGrid(bomRequestResultErrorDetail); lblBOMResultLabel.Text = "BOM Generation Request Result for " + targetFormulaKey + ": "; }
public static async Task <List <DepotOperationResultStatus> > ProcessDepotRequest(string prodKeys, string sourceSystem, bool overrideBOSErrors, int formulaLowerPercentValidation, int formulaUpperPercentValidation, int?existingRequestId = 0, int?parentBOMRequestId = 0, string BOMRequestTargetKey = null) //public static List<DepotOperationResultStatus> ProcessDepotRequest(string prodKeys, string sourceSystem, int formulaLowerPercentValidation, int formulaUpperPercentValidation, int? existingRequestId = 0) { UpdatedBy = GetCurrentUser(); //existingRequestId: is this a brand new request (existingRequestId = 0) or a request that was partially processed before List <DepotOperationResultStatus> request_ret = new List <DepotOperationResultStatus>(); DepotOperationResultStatus r; string[] lookupKeys; string prodKeysCommaDelimited = Regex.Replace(prodKeys, @"\r\n?|\n", ","); if (existingRequestId == 0) { lookupKeys = prodKeysCommaDelimited.Replace(" ", "").Split(','); //allow only one or no spaces between commas } else { lookupKeys = DbEfFactory.GetUnprocessedRequestParts(existingRequestId.GetValueOrDefault()); //allow only one or no spaces between commas } //Dictionary<string, DepotPart> results; DepotOperationResultStatus bos_ret = new DepotOperationResultStatus(); IMapper mapper = MapUtil.Mapper; string depotUser = depotAccessRecord.DepotUser; string depotPwd = depotAccessRecord.DepotPass; var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{depotUser}:{depotPwd}")); var depotAuth = new AuthenticationHeaderValue("Basic", credentials); List <Part> bestpartsList = GetBestParts(prodKeysCommaDelimited); using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = depotAuth; var depot = new GpsDepotClient(depotAccessRecord.DepotUrl, client); string errorMsg = ""; List <DepotPart> depotPartsList = mapper.Map <List <Part>, List <DepotPart> >(bestpartsList); Dictionary <string, DepotPart> bestparts = depotPartsList.ToDictionary(p => p.PartSrcKey, p => p, StringComparer.OrdinalIgnoreCase); // Dictionary<string, DepotPart> bestparts = (mapper.Map<List<Part>, List<DepotPart>>().GetAwaiter().GetResult().ToList<Part>()) //?? new List<DepotPart>(0)).ToDictionary(p => p.PartSrcKey, p => p, StringComparer.OrdinalIgnoreCase); if (bestparts.Count == 0) { //bos_ret.RequestedPart = sourcekey; if (parentBOMRequestId > 0) { bos_ret.ResultCount = 0; bos_ret.RequestId = parentBOMRequestId.GetValueOrDefault(); //bos_ret.ProcessedPartKey= bos_ret.ErrorMessage = "Error encountered, no bestparts found for " + prodKeysCommaDelimited + " in BOM Request# " + parentBOMRequestId.GetValueOrDefault().ToString() + " or service may not be available."; bos_ret.ErrorReceived = true; DbEfFactory.UpdateBOSLoadStatus("bom_load_failed", UpdatedBy, bos_ret); } else { bos_ret.ResultCount = 0; bos_ret.ErrorMessage = "Error encountered, no bestparts found for " + prodKeysCommaDelimited + ", or service may not be available."; DbEfFactory.UpdateBOSLoadStatus("bos_load_failed", UpdatedBy, bos_ret); } request_ret.Add(new DepotOperationResultStatus(bos_ret)); return(request_ret); } if (bestparts.Count > 0 && bestparts.Count < lookupKeys.Length) { errorMsg = ""; foreach (string mykey in lookupKeys) { if (!bestparts.ContainsKey(mykey)) { errorMsg += mykey + ","; } } errorMsg = "The following key(s) are missing bestpart: " + errorMsg.TrimEnd(','); bos_ret.ErrorMessage = "Error encountered, " + errorMsg + " in BOM Request# " + parentBOMRequestId.GetValueOrDefault().ToString() + "."; bos_ret.ErrorReceived = true; //bos_ret.ResultCount = 0; bos_ret.RequestId = parentBOMRequestId.GetValueOrDefault(); request_ret.Add(new DepotOperationResultStatus(bos_ret)); DbEfFactory.UpdateBOSLoadStatus("bom_load_failed", UpdatedBy, bos_ret); //return request_ret; } if (parentBOMRequestId == 0) { bos_ret = DbEfFactory.AddDepotFormulaRequest(prodKeysCommaDelimited, formulaLowerPercentValidation, formulaUpperPercentValidation, bestparts, "Depot", "Formula Request", UpdatedBy); } else { //write PartName, PartType, etc. in the formula_request_queue table... bos_ret = DbEfFactory.UpdateBOMRequestDepotFormula(prodKeysCommaDelimited, formulaLowerPercentValidation, formulaUpperPercentValidation, bestparts, "Depot", parentBOMRequestId.GetValueOrDefault(), BOMRequestTargetKey, UpdatedBy); bos_ret.RequestId = parentBOMRequestId.GetValueOrDefault(); bos_ret.StatusCode = "0"; } foreach (KeyValuePair <string, DepotPart> thispart in bestparts) { //ICalculatedComponentsResult result = depot.BillOfSubstance.GetCalculatedComponentsForBestPart(sourcekey, forSds: true, requireSDSSpecific: false, includeFragranceComposition: true); //thispart.PartKey = "91119915.004"; //ICalculatedComponentsResult result = depot.BillOfSubstance.GetCalculatedComponentsForPart(thispart.Value, forSds: true, includeFragranceComposition: true, requireSDSSpecific: false); ICalculatedComponentsResult result = await depot.GetCalculatedComponentsForPartAsync(thispart.Value, forSds : true, includeFragranceComposition : true, requireSDSSpecific : false, partTypesForAssessmentSpecs : null, allowResultWhenBosErrors : overrideBOSErrors); //use mypartTypesForAssessmentSpecs to override default values bos_ret.ResultCount = result.CalculatedComponents?.Count() ?? 0; if (bos_ret.ResultCount == 0) { //bos_ret.RequestedPart = sourcekey; bos_ret.RequestedPart = thispart.Key; bos_ret.ProcessedPartKey = ""; //bos_ret.ErrorMessage = "No Parts Found for " + sourcekey; bos_ret.ErrorMessage = "No Parts Found for " + thispart.Key + " in BOM Request# " + parentBOMRequestId.GetValueOrDefault().ToString() + "."; bos_ret.ErrorReceived = true; bos_ret.ResultCount = 0; //request_ret.Add(new DepotOperationResultStatus(bos_ret)); DbEfFactory.UpdateBOSLoadStatus("bos_load_missing", UpdatedBy, bos_ret); if ((result.Errors?.Any() ?? false) || (result.Warnings?.Any() ?? false)) { r = DbEfFactory.SaveDepotRequestBos(bos_ret.RequestId, bos_ret.RequestedPart, sourceSystem, UpdatedBy, result, null); } request_ret.Add(new DepotOperationResultStatus(bos_ret)); continue; //fetch the next sourcekey in lookupKeys } else { try { DepotPart part = result?.SourceParts?.FirstOrDefault(); bos_ret.RequestedPart = part.PartSrcKey; bos_ret.ProcessedPartKey = part.PartKey; //part.PartSrcKey+"."+part.PartSrcRevision; bos_ret.PartTypeName = part.PartTypeName; DbEfFactory.UpdateBOSLoadStatus("bos_load_started", UpdatedBy, bos_ret); /* * IEnumerable<string> attrNameFilter = new[]{"PRIMARY CAS #","Primary CAS Region", "CAS #"}; * //IEnumerable<string> partKeys = new[] { part.PartKey }; * * IEnumerable<string> partKeys = GetFormulaComponentList(result.CalculatedComponents); * List<DepotPartAttribute> partMultiCASAttributes=null; * if ((partKeys?.Count() ?? 0) >0) * partMultiCASAttributes = depot.Parts.GetPartAttributesByPartKeys(partKeys, attrNameFilter); */ r = DbEfFactory.SaveDepotRequestBos(bos_ret.RequestId, bos_ret.RequestedPart, sourceSystem, UpdatedBy, result, partMultiCASAttributes: null); bos_ret.ResultCount = result.CalculatedComponents?.Count() ?? -1; // bos?.Count() ?? -1; if (bos_ret.ResultCount == -1) { DbEfFactory.UpdateBOSLoadStatus("bos_load_completed_with_errors", UpdatedBy, bos_ret); } else { DbEfFactory.UpdateBOSLoadStatus("bos_load_completed", UpdatedBy, bos_ret); } bos_ret.SuccessMessage = r.SuccessMessage; bos_ret.ErrorMessage = r.ErrorMessage; //bos_ret.RequestedPart = bos_ret.RequestedPart; //part.PartSrcKey; //bos_ret.ProcessedPartKey = bos_ret.ProcessedPartKey; //part.PartKey; //part.PartSrcKey+"."+part.PartSrcRevision; //request_ret.Add(bos_ret); } //try catch (Exception e) { bos_ret.SuccessMessage = null; bos_ret.ErrorMessage = "Message:" + e.Message + ". "; // InnerException:" + e.InnerException.Message; Logger.Error(e, "Error Processing Depot Rquest"); //request_ret.Add(bos_ret); DbEfFactory.UpdateBOSLoadStatus("bos_load_failed", UpdatedBy, bos_ret); request_ret.Add(new DepotOperationResultStatus(bos_ret)); continue; } } //else //request_ret.Add(bos_ret); request_ret.Add(new DepotOperationResultStatus(bos_ret)); } //foreach } //using return(request_ret); }
public static void StartDTE() { DbEfFactory.StartDTE(); }
// GET: FormulaImportRequest //[Authorize] public ActionResult DepotRequestIndex() { //return View(db.FormulaImportRequestListItems.ToList()); return(View(DbEfFactory.GetFormulaImportRequestsList(FormulaImportRequestType.DEPOT_REQUEST))); }
public ActionResult RequestQueueItemMessagesIndex(int RequestQueueId) { return(View(DbEfFactory.GetRequestQueueItemMessages(RequestQueueId))); }
//[Authorize, ValidateAntiForgeryToken] public ActionResult RequestActivitiesIndex(int id) { return(View(DbEfFactory.GetFormulaImportRequestActivities(id))); }
public async Task <List <DepotOperationResultStatus> > ProcessDepotBOMRequest(string targetFormulaKey, int rmFormulaLowerLimitValidation, int rmFormulaUpperLimitValidation, List <BOMIngredient> bomIngredients, int?parentBOMRequestId = 0, string BOMRequestTargetKey = null) { //assumptions: all formulations are in WERCS, so we don't need to go to Depot for anything here. //if a formula for a material in the BOM isn't in WERCS, it should be imported into WERCS before starting the BOM formula request List <DepotOperationResultStatus> bos_ret = new List <DepotOperationResultStatus>(); DepotOperationResultStatus validatebom_ret = ValidateBOMRequest(targetFormulaKey, bomIngredients); if (validatebom_ret.ErrorMessage?.Length > 0) { bos_ret.Add(validatebom_ret); return(bos_ret); } UpdatedBy = GetCurrentUser(); //List<DepotOperationResultStatus> request_ret = new List<DepotOperationResultStatus>(); //DepotOperationResultStatus r; //string[] lookupKeys = new string[bomIngredients.Count() - 1]; //loop in get_bos_depot and see if there's errors string RequestSourceSystem = "WERCS"; //added handling of PN in the RM list: 20201222 //List<BOMIngredient> pnParts = bomIngredients.Where(p => p.RMSource.ToLower().StartsWith("PN")).ToList<BOMIngredient>(); List <BOMIngredient> pnParts = bomIngredients.Where(p => p.RMKey.ToLower().Contains("_pnmaterial")).ToList <BOMIngredient>(); if (pnParts?.Any() ?? false) { //string pnKeys = string.Join(",", pnParts.Select(a => a.RMKey.ToString().Replace("_PNMaterial", ""))); //string[] pnKeysA; //pnKeys = Regex.Replace(pnKeys, @"\r\n?|\n", ","); //pnKeysA = pnKeys.Replace(" ", "").Split(','); //allow only one or no spaces between commas string pncasTogether = ""; foreach (BOMIngredient part in bomIngredients) { if (part.RMKey.ToLower().Contains("_pnmaterial")) { pncasTogether = part.RMKey.Replace("_PNMaterial", ""); part.RMKey = pncasTogether.Substring(0, pncasTogether.IndexOf("/")); part.RMCas = pncasTogether.Substring(pncasTogether.IndexOf("/") + 1); //decimal rmPercent; part.RMSource = "Wercs"; } } //get_bos_depot = await PassFormulaController.ProcessDepotRequest(prodKeys, sourceSystem: "Depot", overrideBOSErrors: true, formulaLowerPercentValidation: 0, formulaUpperPercentValidation: 0, existingRequestId: 0, parentBOMRequestId: savebom_ret.RequestId, BOMRequestTargetKey: targetFormulaKey); //DepotOperationResultStatus savebomdetail_ret = DbEfFactory.ProcessBOMRequestPNMaterials(savebom_ret.RequestId, targetFormulaKey, pnParts, "Wercs"); } DepotOperationResultStatus savebom_ret = DbEfFactory.AddDepotBOMRequest(targetFormulaKey, bomIngredients, rmFormulaLowerLimitValidation, rmFormulaUpperLimitValidation, "BOM Request", UpdatedBy, RequestSourceSystem); bos_ret.Add(savebom_ret); List <DepotOperationResultStatus> get_bos_depot = new List <DepotOperationResultStatus>(); string prodKeys = ""; bool depotLoadSuccess = true; if (savebom_ret.RequestId == 0) { bos_ret.Add(new DepotOperationResultStatus { RequestId = 0, ErrorMessage = "Error saving BOM request." }); return(bos_ret); } List <BOMIngredient> depotParts = bomIngredients.Where(p => p.RMSource.ToLower().Contains("depot")).ToList <BOMIngredient>(); if (depotParts?.Any() ?? false) { prodKeys = string.Join(",", depotParts.Select(a => a.RMKey.ToString())); get_bos_depot = await PassFormulaController.ProcessDepotRequest(prodKeys, sourceSystem : "Depot", overrideBOSErrors : true, formulaLowerPercentValidation : 0, formulaUpperPercentValidation : 0, existingRequestId : 0, parentBOMRequestId : savebom_ret.RequestId, BOMRequestTargetKey : targetFormulaKey); foreach (DepotOperationResultStatus ret in get_bos_depot) { if (ret?.ErrorMessage?.Length > 0 || ret?.ResultCount == -1) { //bos_ret.Add(new DepotOperationResultStatus { RequestId = savebom_ret.RequestId, ErrorMessage = "Error Importing BOS for " + prodKeys + " from Depot." }); bos_ret.Add(ret); depotLoadSuccess = false; } } if (depotLoadSuccess) { bos_ret.Add(new DepotOperationResultStatus { RequestId = savebom_ret.RequestId, SuccessMessage = "Import of BOS for " + prodKeys + " from Depot completed successfully." }); } //don't check depotLoadSuccess here... Request will be processed regardless and all errors (depot and wercs) will be on the status (result) page /* * else * { * return bos_ret; * } */ } //don't check depotLoadSuccess here... Request will be processed regardless and all errors (depot and wercs) will be on the result/status page //if (depotLoadSuccess) //if no depotParts or depotParts processed successfully //{ string processBOMRequest = ConfigurationManager.AppSettings["ProcessBOMRequest"] ?? "true"; if (string.Compare(processBOMRequest, "true", ignoreCase: true) == 0) { DepotOperationResultStatus savebomdetail_ret = DbEfFactory.ProcessBOMRequest(savebom_ret.RequestId, targetFormulaKey, "Wercs"); DbEfFactory.StartDTE(); //this may already be incoporated in StageBOMRequest bos_ret.Add(savebomdetail_ret); } //} return(bos_ret); }