Beispiel #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()));
                }
            }
        }
        private void GenerateDocumentPlug(string schema)
        {
            if (string.IsNullOrWhiteSpace(schema))
            {
                throw new ArgumentNullException("schema");
            }

            using (Stream schemaStream = GenerateStreamFromString(schema))
            {
                IDocumentPlug documentPlug = DocumentPlugFactory.CreateDocumentPlugFromXmlSchema(schemaStream);

                XElement schemaXml = documentPlug.SerializeToXml();
                schemaXml.Save(Path.Combine(OutputDirName, Path.ChangeExtension(TreeReference, "xml")));

                DocumentPlug = documentPlug;
            }
        }
Beispiel #3
0
        /// <summary>
        /// This function should be used only for unit testing where we don't want to connect to Azure storage
        /// </summary>
        /// <param name="currentTransactionSetType"></param>
        /// <returns></returns>
        public static IDocumentPlug CreateEDIDocumentPlug(int currentTransactionSetType)
        {
            string path, targetNamespace, name;

            switch (currentTransactionSetType)
            {
            case 820:
                path            = "820-R1.xsd";
                targetNamespace = @"urn:x12:schemas:005010X306:820R1:HealthInsuranceExchangeRelatedPayments";
                name            = "X12_005010X306_820R1";
                break;

            case 850:
                path            = "GCommerce.EDI._00401._850.Schemas.Enriched_X12_00401_850";
                targetNamespace = @"http://schemas.microsoft.com/BizTalk/EDI/EDIFACT/2006/EnrichedMessageXML";
                name            = "X12EnrichedMessage";
                break;

            case 277:
                path            = "X12_005010X214_277B3.xsd";
                targetNamespace = @"urn:x12:schemas:005:010:277B3:HealthCareInformationStatusNotification";
                name            = "X12_005010X214_277B3";
                break;

            case 810:
                path            = "X12_00501_810.xsd";
                targetNamespace = @"http://schemas.microsoft.com/BizTalk/EDI/X12/2006";
                name            = "X12_00501_810";
                break;

            default:
                throw new Exception(string.Format("{0} schema not found", currentTransactionSetType));
            }

            IDocumentPlug schemaPlug = DocumentPlugFactory.CreateDocumentPlugFromXmlSchema(path, targetNamespace, name);

            XElement schemaXml = schemaPlug.SerializeToXml();

            schemaXml.Save(string.Format("Schema_{0}.xml", currentTransactionSetType));

            return(schemaPlug);
        }