Exemple #1
0
        private static void ValidateAndUploadSpecCert(MapDetail mapDetail, SpecCertGenerationResult result, StreamWriter logFile, bool uploadSpecCert, string specCertType)
        {
            LogInformation(logFile, string.Format("Generating document plug from spec cert {0}", Path.GetFileName(result.SpecCertPath)));

            using (StreamReader stream = new StreamReader(result.SpecCertPath))
            {
                try
                {
                    GCExcelToDocumentPlug excelToDocumentPlug;
                    switch (specCertType)
                    {
                    case "edi":
                        excelToDocumentPlug = new X12GCExcelToDocumentPlug();
                        break;

                    case "xml":
                        excelToDocumentPlug = new XmlGCExcelToDocumentPlug();
                        break;

                    case "flatfile":
                        excelToDocumentPlug = new FlatFileGCExcelToDocumentPlug();
                        break;

                    default:
                        throw new NotSupportedException(string.Format("Spec cert type {0} is not supported", specCertType));
                        break;
                    }

                    IDocumentPlug plug = excelToDocumentPlug.GenerateDocumentPlug(stream.BaseStream, mapDetail.OrgName, mapDetail.DocumentType, mapDetail.Direction, Maarg.Contracts.GCValidate.SpecCertFileType.X12);

                    // Serialize document plug for investigation
                    plug.SerializeToXml().Save(Path.ChangeExtension(result.SpecCertPath, "xml"));

                    if (uploadSpecCert)
                    {
                        // TODO: Add logic to upload to Azure blob
                        LogWarning(logFile, "Upload functionality will be added soon.");
                    }

                    LogInformation(logFile, string.Format("Document plug generated successfully"));
                }
                catch (Exception ex)
                {
                    result.Errors.Add(string.Format("Spec cert validation failed. Error: {0}", ex.ToString()));
                    LogError(logFile, string.Format("Spec cert validation failed. Error: {0}", ex.ToString()));
                }
            }
        }
Exemple #2
0
        private static void CreateErrorLogFile(string fileName, MapDetail mapDetail, SpecCertGenerationResult result, StreamWriter logFile)
        {
            string errorFileName = string.Format("{0} - {1}", Path.GetFileNameWithoutExtension(fileName), Path.ChangeExtension(mapDetail.FileName, "err"));

            LogInformation(logFile, string.Format("Writing errors to {0} file", errorFileName));

            using (StreamWriter errorFile = new StreamWriter(errorFileName))
            {
                errorFile.WriteLine("Errors encountered during spec cert generation/validation from {0} file", mapDetail.FileName);
                errorFile.WriteLine("Errors:");
                foreach (string error in result.Errors)
                {
                    errorFile.WriteLine(error);
                }
            }
        }
Exemple #3
0
        private static int ReadAllBtmFiles(Parameters parameters)
        {
            string fileName = parameters.ZipFileName;

            if (File.Exists(fileName) == false)
            {
                ConsoleExtensions.WriteError("{0} does not exist.", fileName);
                return(1);
            }

            if (Path.GetExtension(fileName) != ".zip")
            {
                ConsoleExtensions.WriteError("{0} is not a zip file.", fileName);
                return(1);
            }

            string logFileName = Path.ChangeExtension(Path.GetFileName(fileName), "log");

            ConsoleExtensions.WriteInfo("Log file for this processing: {0}", logFileName);
            using (StreamWriter logFile = new StreamWriter(logFileName))
            {
                try
                {
                    using (StreamReader sr = new StreamReader(fileName))
                    {
                        LogInformation(logFile, string.Format("Reading maps from {0}", fileName));

                        List <MapDetail> mapsDetailList = BtmFileReader.ReadMap(sr.BaseStream, fileName, parameters.SpecCertType);

                        if (mapsDetailList != null)
                        {
                            LogInformation(logFile, string.Format("{0} maps retrieved.", mapsDetailList.Count));
                            int specCertCount = 0;

                            foreach (MapDetail mapDetail in mapsDetailList)
                            {
                                if (mapDetail.DocumentType != 810 &&
                                    mapDetail.DocumentType != 850 &&
                                    mapDetail.DocumentType != 856)
                                {
                                    //LogInformation(logFile, string.Format("Spec cert generation for document type {0} is not supported", mapDetail.DocumentType));
                                    continue;
                                }

                                LogInformation(logFile, "======================================");
                                LogInformation(logFile, "Map detail:");
                                LogInformation(logFile, string.Format("\t{0}", mapDetail.FileName));
                                LogInformation(logFile, string.Format("\t{0}", mapDetail.FolderName));

                                Maarg.Fatpipe.Plug.Authoring.BtmFileHandler.SpecCertGenerator specCertGenerator = new Maarg.Fatpipe.Plug.Authoring.BtmFileHandler.SpecCertGenerator();
                                try
                                {
                                    SpecCertGenerationResult result = specCertGenerator.GenerateSpecCert(mapDetail, parameters.SpecCertType);

                                    if (result.PathsUsed.Count == 0)
                                    {
                                        LogError(logFile, "No path exist from map in template. No spec cert generated");
                                    }
                                    else
                                    {
                                        LogInformation(logFile, string.Format("Paths used {0}", result.PathsUsed.Count));
                                        specCertCount++;
                                    }

                                    if (result.Errors.Count != 0 || result.PathsUsed.Count == 0)
                                    {
                                        LogWarning(logFile, "Spec cert generated with errors");
                                    }
                                    else
                                    {
                                        LogInformation(logFile, "Spec cert generated successfully");
                                    }

                                    if (result.SpecCertGenerated)
                                    {
                                        ValidateAndUploadSpecCert(mapDetail, result, logFile, parameters.UploadSpecCert, parameters.SpecCertType);
                                    }

                                    if (result.Errors.Count > 0)
                                    {
                                        CreateErrorLogFile(fileName, mapDetail, result, logFile);
                                    }
                                }
                                catch (Exception e)
                                {
                                    LogError(logFile, string.Format("Spec cert generation failed. Exception: {0}", e.ToString()));
                                }
                            }

                            if (specCertCount == 0)
                            {
                                LogError(logFile, "No valid spec cert generated");
                            }
                        }
                        else
                        {
                            LogInformation(logFile, string.Format("No map present in {0}", fileName));
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogError(logFile, string.Format("Error encountered during processing {0} file. Error: {1}", fileName, ex.ToString()));
                }
            }

            return(0);
        }