Example #1
0
        /// <summary>
        /// Process the XML input files
        /// </summary>
        private void ProcessXMLFile(string dataFile)
        {
            ZipPackage zp = new ZipPackage();

            zp.FileName = Path.GetFileName(dataFile);

            string[] parts = dataFile.Split('.');
            string   documentIdentifier = parts[3] + parts[4];

            NexdoxMessaging.SendMessage("    Processing xml file " + Path.GetFileName(dataFile) + "...", true, this);

            if (!File.Exists(dataFile.ToUpper().Replace(".XML", ".job")))
            {
                OutputErrorRecord(Path.GetFileName(dataFile), "Corresponding .job file does not exist");
                return;
            }

            StreamReader      jobInputFileStream = new StreamReader(dataFile.ToUpper().Replace(".XML", ".job"));
            XmlReaderSettings jobSettings        = new XmlReaderSettings();

            jobSettings.XmlResolver = null;
            XmlReader jobData = XmlReader.Create(jobInputFileStream, jobSettings);

            string domicile    = string.Empty;
            string batchNumber = string.Empty;

            jobData.ReadToFollowing("Domicile");
            domicile    = jobData.ReadElementContentAsString().ToUpper();
            zp.Domicile = domicile;

            string managerIdString = string.Empty;

            try
            {
                jobData.ReadToFollowing("Manager_ID");
            }
            catch (Exception e)
            {
                OutputErrorRecord(Path.GetFileName(dataFile), e.Message + "\",\"" + e.StackTrace);
                jobData.Close();
                jobInputFileStream.Close();
                return;
            }

            if (jobData.EOF)
            {
                OutputErrorRecord(Path.GetFileName(dataFile), "The job file is does not contain Manager_ID");
                jobData.Close();
                jobInputFileStream.Close();
                return;
            }
            else
            {
                managerIdString = jobData.ReadElementContentAsString();
                int managerId;
                if (!int.TryParse(managerIdString, out managerId))
                {
                    OutputErrorRecord(Path.GetFileName(dataFile), "Unknown Manager ID: " + managerIdString);
                }
                zp.ManCoID = managerIdString;

                if (Statics.ManagementCompanySettings.Exists(delegate(NTGEN00.ManCoSettings manCoSettings){ return(manCoSettings.ManagementCompanyID == managerId); }))
                {
                    NTGEN00.ManCoSettings manCoSettings = Statics.ManagementCompanySettings[managerId];

                    Statics.zipPackage.Add(zp);

                    //Open data file as xml
                    StreamReader      inputFileStream = new StreamReader(dataFile);
                    XmlReaderSettings settings        = new XmlReaderSettings();
                    settings.XmlResolver = null;
                    XmlReader xmlData = XmlReader.Create(inputFileStream, settings);

                    //Get file name minus extension
                    string fileNameNoExtension = new FileInfo(dataFile).Name;
                    fileNameNoExtension = fileNameNoExtension.Substring(0, fileNameNoExtension.Length - 4);

                    //Can we tell what application it's supposed to go to by doc type
                    string destinationDirectory = string.Empty;
                    string appName    = string.Empty;
                    string docType    = string.Empty;
                    string subDocType = string.Empty;


                    //Get document type
                    xmlData.ReadToFollowing("Doc_Type");

                    if (xmlData.EOF)
                    {
                        destinationDirectory = _appInfo.OutputPath + "InvalidFiles";
                        OutputErrorRecord(Path.GetFileName(dataFile), "No Doc_Type in data file");
                        return;
                    }
                    else
                    {
                        docType         = xmlData.ReadElementContentAsString().ToUpper();
                        zp.DocumentType = docType;
                        xmlData.ReadToFollowing("Doc_Sub_Type");
                        subDocType = xmlData.EOF ? "N/A" : xmlData.ReadElementContentAsString();

                        jobData.Close();
                        jobInputFileStream.Close();

                        string subDocAndDocType = docType + subDocType;
                        if (Statics.Resources.Lookups[LookupEnums.MonitorDirectory].Lookup.Contains(subDocAndDocType))
                        {
                            appName = Statics.Resources.Lookups[LookupEnums.AppName].Lookup.Find(subDocAndDocType);
                            destinationDirectory =
                                Statics.Resources.Lookups[LookupEnums.MonitorDirectory].Lookup.Find(subDocAndDocType);
                        }
                        else
                        {
                            destinationDirectory = _appInfo.OutputPath + "InvalidFiles";
                            OutputErrorRecord(
                                Path.GetFileName(dataFile),
                                string.Format("Doc_Type ({0}) and Sub_Doc_Type ({1}) unknown", docType, subDocType));
                            return;
                        }
                    }



                    if (string.Compare(appName, "ntgen03", true) == 0)
                    {
                        if (manCoSettings.IsEMEA(appName) || manCoSettings.Offshore)
                        {
                            appName = "ntgen23";
                            destinationDirectory = @"\\127.0.0.1\nexdox\ntgen23\monitor";
                        }
                    }
                    else if (string.Compare(appName, "ntgen01", true) == 0)
                    {
                        switch (Statics.CntFilesRoutingMode)
                        {
                        case "PremierSeparately":
                            if (!manCoSettings.Offshore)
                            {
                                appName = (manCoSettings.ManagementCompanyID == 14) || (manCoSettings.ManagementCompanyID == 17)
                              ? "ntprm01"
                              : "ntgen01";
                            }
                            else
                            {
                                appName = "ntgen51";
                            }
                            break;

                        case "PremierAsOnshore":
                            appName = manCoSettings.Offshore ? "ntgen51" : "ntgen01";
                            break;

                        default:
                            break;
                        }

                        destinationDirectory = string.Format(@"\\127.0.0.1\nexdox\{0}\monitor", appName);
                    }

                    if (!manCoSettings.ApplicationsSwitchedOff.Contains(appName))
                    {
                        //Make sure destination directory string ends in a \
                        if (!destinationDirectory.EndsWith("\\"))
                        {
                            destinationDirectory += "\\";
                        }

                        //Move job file to application input directory
                        NexdoxMessaging.SendMessage(
                            string.Format("  Allocating '{0}' files to '{1}' directory.", fileNameNoExtension, destinationDirectory),
                            false,
                            this);

                        if (!File.Exists(string.Format("{0}.job", dataFile.Substring(0, dataFile.Length - 4))))
                        {
                            OutputErrorRecord(Path.GetFileName(dataFile), "No job file supplied with xml file");
                            return;
                        }
                        else if (!Statics.AppsToIgnore.Contains(appName.ToUpper()))
                        {
                            if (!Directory.Exists(destinationDirectory))
                            {
                                Directory.CreateDirectory(destinationDirectory);
                            }

                            //Move data file to application input directory
                            MoveFile(
                                string.Format("{0}.job", dataFile.Substring(0, dataFile.Length - 4)),
                                string.Format("{0}{1}.job", destinationDirectory, fileNameNoExtension));
                            MoveFile(
                                string.Format("{0}.xml", dataFile.Substring(0, dataFile.Length - 4)),
                                string.Format("{0}{1}.xml", destinationDirectory, fileNameNoExtension));

                            _allocatedFiles.Add("\"" + Path.GetFileName(dataFile) + "\",\"" + appName + "\"");


                            zp.Offshore = manCoSettings.Offshore ? true : false;
                            zp.StatusID = 1;


                            if (string.Compare(docType, "CNF", true) == 0)
                            {
                                //All input for NXNOR07 should be processed together
                                _transferFiles.Add(fileNameNoExtension);
                                _transferFileDestinationDirectory = destinationDirectory;
                            }
                            else if (string.Compare(docType, "CNT", true) == 0)
                            {
                                if (string.Compare(subDocType, "SWS", true) == 0 || string.Compare(subDocType, "SWR", true) == 0)
                                {
                                    _contractSWRSWSFiles.Add(fileNameNoExtension);
                                    _contractSWRSWSFileDestinationDirectory = destinationDirectory;
                                }
                                else if (string.Compare(subDocType, "CWR", true) == 0 || string.Compare(subDocType, "CWS", true) == 0)
                                {
                                    _contractCWRCWSFiles.Add(fileNameNoExtension);
                                    _contractCWRCWSFileDestinationDirectory = destinationDirectory;
                                }
                                else
                                {
                                    _contractFiles.Add(fileNameNoExtension);
                                    _contractFileDestinationDirectory = destinationDirectory;
                                }
                            }
                        }
                        else
                        {
                            //ignore these files
                            _ignoreFiles.Add("\"" + Path.GetFileName(dataFile) + "\",\"" + appName + "\"");
                        }
                    }
                    else
                    {
                        OutputErrorRecord(
                            Path.GetFileName(dataFile), "Application: " + appName + " switched off for ManCo ID: " + managerIdString);
                        return;
                    }
                }
                else
                {
                    OutputErrorRecord(Path.GetFileName(dataFile), "Unknown ManCo ID: " + managerIdString);
                    return;
                }
            }
        }
Example #2
0
 public void Add(ZipPackage aZipPackage)
 {
     List.Add(aZipPackage);
 }
Example #3
0
        public void Process()
        {
            NexdoxMessaging.SendMessage("Allocation Stage...", true, this);

            //Todo: Do some kind of sequence checking... there may be a better place to do this than here.

            //Make sure Xceed libraries are enabled
            Xceed.Zip.Licenser.LicenseKey = "ZIN37-T1W1B-SW87P-N8AA";

            string grid = _appInfo.NexdoxGlobalRunID.ToString();

            //Get the input files
            ScanForInputFiles(_appInfo.InputPath);

            //Now add each level of Zip structure to the class
            NexdoxMessaging.SendMessage("Deconstructing Zip Package....", true, this);

            //Top Level first (Big Zip)
            foreach (string zipFile in Directory.GetFiles(_appInfo.InputPath, "*", SearchOption.TopDirectoryOnly))
            {
                ZipPackage zpBig = new ZipPackage()
                {
                    FileName          = Path.GetFileName(zipFile),
                    ParentZipFileName = "",
                    IsBigZip          = true,
                    InputCreationDate = new FileInfo(zipFile).LastWriteTime,
                    StatusID          = 0,
                };

                Statics.zipPackage.Add(zpBig);

                string pathLittleZip = _appInfo.InputPath + Path.ChangeExtension(zpBig.FileName, "");

                //Next Level. (Little Zip)
                foreach (string littlezipFile in Directory.GetFiles(pathLittleZip, "*", SearchOption.TopDirectoryOnly))
                {
                    ZipPackage zpLittle = new ZipPackage()
                    {
                        FileName          = Path.GetFileName(littlezipFile.ToUpper()),
                        ParentZipFileName = zpBig.FileName,
                        IsLittleZip       = true,
                        InputCreationDate = new FileInfo(littlezipFile).LastWriteTime,
                        StatusID          = 0,
                    };
                    Statics.zipPackage.Add(zpLittle);

                    string pathDataFiles = pathLittleZip + "\\" + Path.ChangeExtension(zpLittle.FileName, "");

                    //Now the Data Files
                    foreach (string dataFile in Directory.GetFiles(pathDataFiles, "*", SearchOption.TopDirectoryOnly))
                    {
                        if (Path.GetExtension(dataFile) == ".XML")
                        {
                            foreach (ZipPackage zp in Statics.zipPackage)
                            {
                                if (zp.FileName == Path.GetFileName(dataFile))
                                {
                                    zp.ParentZipFileName = zpLittle.FileName;
                                    zp.InputCreationDate = new FileInfo(littlezipFile).LastWriteTime;
                                }
                            }
                        }
                        else //.CON File
                        {
                            ZipPackage zpData = new ZipPackage()
                            {
                                FileName          = Path.GetFileName(dataFile),
                                ParentZipFileName = zpLittle.FileName,
                                InputCreationDate = new FileInfo(littlezipFile).LastWriteTime,
                                StatusID          = 0,
                            };
                            Statics.zipPackage.Add(zpData);
                        }
                    }
                }
            }

            Statics.zipPackage.SaveToDatabase(_xmlFileService, _zipFileService, _conFileService, _docTypeService, _manCoService, _appInfo);
            Statics.zipPackage.SaveToOutputDir(_appInfo.OutputPath, grid);

            if (_extractedFiles.Count > 0)
            {
                using (
                    StreamWriter extractedFile =
                        new StreamWriter(File.Create(_appInfo.OutputPath + "[" + grid + "]" + "-ExtractedXML.csv")))
                {
                    extractedFile.WriteLine("\"FileName\"");

                    foreach (string file in _extractedFiles)
                    {
                        extractedFile.WriteLine(file);
                    }
                }
            }

            if (_allocatedFiles.Count > 0)
            {
                using (
                    StreamWriter allocatedFile =
                        new StreamWriter(File.Create(_appInfo.OutputPath + "[" + grid + "]" + "-AllocatedXML.csv")))
                {
                    allocatedFile.WriteLine("\"FileName\",\"Application\"");

                    foreach (string file in _allocatedFiles)
                    {
                        allocatedFile.WriteLine(file);
                    }
                }
            }

            if (_zipErrorFiles.Count > 0)
            {
                using (
                    StreamWriter zipErrorFile =
                        new StreamWriter(File.Create(_appInfo.OutputPath + "[" + grid + "]" + "-FailedZIP.csv")))
                {
                    zipErrorFile.WriteLine("\"FileName\",\"Error\"");

                    foreach (string error in _zipErrorFiles)
                    {
                        zipErrorFile.WriteLine(error);
                    }
                }
            }

            if (_pdfErrorFiles.Count > 0)
            {
                using (
                    StreamWriter pdfErrorFile =
                        new StreamWriter(File.Create(_appInfo.OutputPath + "[" + grid + "]" + "-FailedPDF.csv")))
                {
                    pdfErrorFile.WriteLine("\"FileName\",\"Error\"");

                    foreach (string error in _pdfErrorFiles)
                    {
                        pdfErrorFile.WriteLine(error);
                    }
                }
            }

            if (_xmlErrorFiles.Count > 0)
            {
                using (
                    StreamWriter xmlErrorFile =
                        new StreamWriter(File.Create(_appInfo.OutputPath + "[" + grid + "]" + "-FailedXML.csv")))
                {
                    xmlErrorFile.WriteLine("\"FileName\",\"Error\"");

                    foreach (string error in _xmlErrorFiles)
                    {
                        xmlErrorFile.WriteLine(error);
                    }
                }
            }

            if (_ignoreFiles.Count > 0)
            {
                using (
                    StreamWriter ignoredFile =
                        new StreamWriter(File.Create(_appInfo.OutputPath + "[" + grid + "]" + "-ignoredXML.csv")))
                {
                    ignoredFile.WriteLine("\"FileName\",\"Application\"");

                    foreach (string ignore in _ignoreFiles)
                    {
                        ignoredFile.WriteLine(ignore);
                    }
                }
            }

            NexdoxMessaging.SendMessage("Finished Allocation Stage.", true, this);
        }