static int Main(string[] args) { if (args.Length != 1) { Usage(); return(-1); } // Parse arguments MfgBom.CostEstimation.CostEstimationRequest request; AVM.DDP.MetaTBManifest manifest; String pathResultsFolder; var result = ParseArgs(args, out request, out manifest, out pathResultsFolder); if (result != 0) { return(result); } CostEstimationResult estimationResult; try { // Process costing request estimationResult = MfgBom.CostEstimation.Estimation.ProcessRequest(request); } catch (OctopartQueryException e) { Console.Error.WriteLine(e.Message); return(2); } // Dump result to JSON var pathResult = Path.Combine(pathResultsFolder, "CostEstimationResults.json"); using (StreamWriter outfile = new StreamWriter(pathResult)) { outfile.Write(estimationResult.Serialize()); } var artifactResult = new AVM.DDP.MetaTBManifest.Artifact() { Location = "CostEstimationResults.json", Tag = "BomCostAnalysis::CostEstimationResults" }; manifest.Artifacts.Add(artifactResult); // Populate manifest metrics var metricCost = manifest.Metrics.FirstOrDefault(m => m.Name == "part_cost_per_design"); if (metricCost == null) { metricCost = new AVM.DDP.MetaTBManifest.Metric() { Name = "part_cost_per_design", DisplayedName = "Part Cost Per Design", Unit = "USD", GMEID = null }; if (manifest.Metrics == null) { manifest.Metrics = new List <AVM.DDP.MetaTBManifest.Metric>(); } manifest.Metrics.Add(metricCost); } metricCost.Value = estimationResult.per_design_parts_cost.ToString(); // Save UserBomTable var ubt = MfgBom.Converters.CostEstResult2UserBomTable.Convert(estimationResult); var pathUbt = Path.Combine(pathResultsFolder, "BomTable.csv"); using (StreamWriter outfile = new StreamWriter(pathUbt)) { outfile.Write(ubt.ToCsv()); } // Also save it as HTML, for MOT-335 var pathBomHtml = Path.Combine(pathResultsFolder, "BomTable.html"); using (StreamWriter outfile = new StreamWriter(pathBomHtml)) { outfile.Write(ubt.ToHtml()); // MOT-335 } var artifactUbt = new AVM.DDP.MetaTBManifest.Artifact() { Location = "BomTable.csv", Tag = "BomCostAnalysis::BomTable" }; manifest.Artifacts.Add(artifactUbt); // Save manifest changes manifest.Serialize(); return(0); }
static int Main(string[] args) { if (args.Length != 1) { Usage(); return -1; } // Parse arguments MfgBom.CostEstimation.CostEstimationRequest request; AVM.DDP.MetaTBManifest manifest; String pathResultsFolder; var result = ParseArgs(args, out request, out manifest, out pathResultsFolder); if (result != 0) { return result; } // Process costing request var estimationResult = MfgBom.CostEstimation.Estimation.ProcessRequest(request); // Dump result to JSON var pathResult = Path.Combine(pathResultsFolder, "CostEstimationResults.json"); using (StreamWriter outfile = new StreamWriter(pathResult)) { outfile.Write(estimationResult.Serialize()); } var artifactResult = new AVM.DDP.MetaTBManifest.Artifact() { Location = "CostEstimationResults.json", Tag = "BomCostAnalysis::CostEstimationResults" }; manifest.Artifacts.Add(artifactResult); // Populate manifest metrics var metricCost = manifest.Metrics.FirstOrDefault(m => m.Name == "part_cost_per_design"); if (metricCost == null) { metricCost = new AVM.DDP.MetaTBManifest.Metric() { Name = "part_cost_per_design", DisplayedName = "Part Cost Per Design", Unit = "USD", GMEID = null }; if (manifest.Metrics == null) { manifest.Metrics = new List<AVM.DDP.MetaTBManifest.Metric>(); } manifest.Metrics.Add(metricCost); } metricCost.Value = estimationResult.per_design_parts_cost.ToString(); // Save UserBomTable var ubt = MfgBom.Converters.CostEstResult2UserBomTable.Convert(estimationResult); var pathUbt = Path.Combine(pathResultsFolder, "BomTable.csv"); using (StreamWriter outfile = new StreamWriter(pathUbt)) { outfile.Write(ubt.ToCsv()); } // Also save it as HTML, for MOT-335 var pathBomHtml = Path.Combine(pathResultsFolder, "BomTable.html"); using (StreamWriter outfile = new StreamWriter(pathBomHtml)) { outfile.Write(ubt.ToHtml()); // MOT-335 } var artifactUbt = new AVM.DDP.MetaTBManifest.Artifact() { Location = "BomTable.csv", Tag = "BomCostAnalysis::BomTable" }; manifest.Artifacts.Add(artifactUbt); // Save manifest changes manifest.Serialize(); return 0; }