コード例 #1
0
ファイル: Process.cs プロジェクト: mtorres0612/GPP-JobTrigger
        // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        public static bool ProcessIMS(string ThreadName,
                                      string IncFolder,
                                      System.Collections.Hashtable IMSCompleteCountriesName,
                                      System.Collections.Hashtable IMSIncompleteCountriesName,
                                      IAPL.Transport.Transactions.MessageDetails mDetails,
                                      System.Collections.Hashtable FTPFileFoundSentList,
                                      out System.Collections.Hashtable DetailsForIMS)
        {
            bool success = true;

            DetailsForIMS = new System.Collections.Hashtable();
            if (mDetails.IndividualProcess.Equals(1))
            {
                IAPL.Transport.IMS.Process.IMSReportDetails IMSDetailsStruct = new IAPL.Transport.IMS.Process.IMSReportDetails();
                System.Collections.Hashtable IMSData = new System.Collections.Hashtable();

                // Get the country list from the database
                IAPL.Transport.Data.DbTransaction db = new IAPL.Transport.Data.DbTransaction();
                db.GetIMSCountries(IAPL.Transport.Util.ConstantVariables.SP_GetIMSDetails, "IMSCountries");
                if (db.ErrorMessage.Trim().Length > 0)
                {
                    success = false;
                    IAPL.Transport.Util.TextLogger.LogError("MessageTransaction-ProcessIMS()", "Database error: " + db.ErrorMessage);
                }
                else
                {
                    System.Data.DataTable dTable = db.CommonDataTable;
                    if (dTable == null)
                    {
                        success = false;
                    }
                    else
                    {
                        // Set initial value
                        foreach (System.Data.DataRow row in dTable.Rows)
                        {
                            IMSDetailsStruct.CountryCode        = IAPL.Transport.Util.CommonTools.ValueToString((Object)row["Code"]);
                            IMSDetailsStruct.Country            = IAPL.Transport.Util.CommonTools.ValueToString((Object)row["CountryName"]);
                            IMSDetailsStruct.IMSDataSeq         = "";
                            IMSDetailsStruct.SizeKB             = 0;
                            IMSDetailsStruct.DateSent           = System.DateTime.Now;
                            IMSDetailsStruct.ERS_Issue          = "";
                            IMSDetailsStruct.IMSSR_Issue        = "";
                            IMSDetailsStruct.CommentResolution  = "";
                            IMSDetailsStruct.DataFileRecvd      = "";
                            IMSDetailsStruct.TransactionDate    = "";
                            IMSDetailsStruct.RecordCount        = 0;
                            IMSDetailsStruct.IMSExtractionValue = 0;
                            IMSDetailsStruct.SendStatus         = "";
                            IMSData.Add(IMSDetailsStruct.CountryCode, IMSDetailsStruct);
                        }
                    }

                    // Process CompleteCountriesName
                    foreach (System.Collections.DictionaryEntry file in (System.Collections.Hashtable)IMSCompleteCountriesName)
                    {
                        string filename    = file.Value.ToString();
                        string CountryCode = filename.Substring(0, 3);

                        // ------------- Get Struct inside Hashtable then edit value(s) ---------------------
                        IMSReportDetails IMS = (IMSReportDetails)IMSData[CountryCode.ToUpper()];

                        // Version No. (both reports)
                        IMS.IMSDataSeq = filename.Substring(3);

                        // File size in KB (both reports)
                        string IMSFolderPath = mDetails.BackupFolder + @"\" + mDetails.IMSFolder;
                        long   FileSize      = IAPL.Transport.Util.Utility.GetFileSize_Local(IMSFolderPath + @"\" + filename + "." + Process.IMSFileExt);
                        IMS.SizeKB = IAPL.Transport.Util.Utility.ConvertByteToKB(FileSize);

                        // Date Sent (both reports)
                        IMS.DateSent = System.DateTime.Now;

                        // Open file and parse
                        string       filereadbuf;
                        string       IMSLogfile = IMSFolderPath + @"\" + filename + "." + Process.IMSLogExt;
                        int          Size       = (int)IAPL.Transport.Util.Utility.GetFileSize_Local(IMSLogfile);
                        char[]       buf        = new char[Size];
                        StreamReader sr         = new StreamReader(new FileStream(IMSLogfile, FileMode.Open, FileAccess.Read));
                        int          retval     = sr.ReadBlock(buf, 0, Size);
                        filereadbuf = new string(buf);
                        sr.Close();
                        string[] ParsedData = IAPL.Transport.Util.Utility.ParseString(filereadbuf);

                        // Issue (both reports)
                        IMS.ERS_Issue   = ParsedData[2].ToString();
                        IMS.IMSSR_Issue = ParsedData[2].ToString();


                        // Comment/Resolution (IMS Summary Report)
                        IMS.CommentResolution = ParsedData[3].ToString();


                        // Data File Received (IMS Summary Report)
                        if (FTPFileFoundSentList[CountryCode] != null)
                        {
                            IMS.DataFileRecvd = "Yes";
                        }
                        else
                        {
                            IMS.DataFileRecvd = "No File";
                        }


                        // Transaction Date (IMS Summary Report)
                        IMS.TransactionDate = ParsedData[4].ToString();


                        // Record Count (IMS Summary Report)
                        IMS.RecordCount = Convert.ToInt32(ParsedData[5].ToString());


                        // IMS Extraction Value (IMS Summary Report)
                        IMS.IMSExtractionValue = Convert.ToDouble(ParsedData[6].ToString());

                        // Send Status (Exception Report Summary)
                        if (IMS.ERS_Issue.Equals(string.Empty))
                        {
                            IMS.SendStatus = "SUCCESS";
                        }
                        else
                        {
                            IMS.SendStatus = IMS.ERS_Issue;
                        }

                        // ----------------------------------------------------------------------------------

                        // Update Hashtable with edited value(s)
                        IMSData[CountryCode] = IMS;
                    }
                }

                // Temp
                string fileName    = "";
                string desFilePath = "";

                // Email Exception Report Summary
                success = PerformEmailProcess(1, fileName, desFilePath, ThreadName, IMSData, mDetails, false);

                // Email IMS Summary Report
                success = PerformEmailProcess(2, fileName, desFilePath, ThreadName, IMSData, mDetails, false);

                // Delete Processed files from database
                db.DeleteIMSFileProcessed(mDetails.IMSProcessId);
                if (db.ErrorMessage.Trim().Length > 0)
                {
                    success = false;
                    IAPL.Transport.Util.TextLogger.LogError("MessageTransaction-DeleteIMSFileProcessed()", "Database error: " + db.ErrorMessage);
                }
                else
                {
                    // Delete Process from Temp table
                    db.DeleteIMSProcess(mDetails.IMSProcessId);
                    if (db.ErrorMessage.Trim().Length > 0)
                    {
                        success = false;
                        IAPL.Transport.Util.TextLogger.LogError("MessageTransaction-DeleteIMSFileProcessed()", "Database error: " + db.ErrorMessage);
                    }
                }
            }
            return(success);
        }
コード例 #2
0
ファイル: Process.cs プロジェクト: mtorres0612/GPP-JobTrigger
        // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        // **********************************************************
        // Project: ISG12043
        // Developer: Alrazen Estrella
        // Date: Oct. 10, 2008

        public static bool IMSSendEmailWhenNoFilesFound(string ThreadName,
                                                        IAPL.Transport.Transactions.MessageDetails mDetails,
                                                        bool IMSNoFilesFound)
        {
            bool success = true;

            IAPL.Transport.IMS.Process.IMSReportDetails IMSDetailsStruct = new IAPL.Transport.IMS.Process.IMSReportDetails();
            System.Collections.Hashtable IMSData = new System.Collections.Hashtable();

            // Get the country list from the database
            IAPL.Transport.Data.DbTransaction db = new IAPL.Transport.Data.DbTransaction();
            db.GetIMSCountries(IAPL.Transport.Util.ConstantVariables.SP_GetIMSDetails, "IMSCountries");
            if (db.ErrorMessage.Trim().Length > 0)
            {
                success = false;
                IAPL.Transport.Util.TextLogger.LogError("MessageTransaction-ProcessIMS()", "Database error: " + db.ErrorMessage);
            }
            else
            {
                System.Data.DataTable dTable = db.CommonDataTable;
                if (dTable == null)
                {
                    success = false;
                }
                else
                {
                    // Set initial value
                    foreach (System.Data.DataRow row in dTable.Rows)
                    {
                        IMSDetailsStruct.Country           = IAPL.Transport.Util.CommonTools.ValueToString((Object)row["CountryName"]);
                        IMSDetailsStruct.CountryCode       = IAPL.Transport.Util.CommonTools.ValueToString((Object)row["Code"]);
                        IMSDetailsStruct.ERS_Issue         = "NO FILE RECEIVED";
                        IMSDetailsStruct.CommentResolution = "NO FILE RECEIVED";


                        //IMSDetailsStruct.DataFileRecvd = "";
                        //IMSDetailsStruct.TransactionDate = "";
                        //IMSDetailsStruct.RecordCount = 0;
                        //IMSDetailsStruct.IMSExtractionValue = 0;


                        IMSData.Add(IMSDetailsStruct.CountryCode, IMSDetailsStruct);
                    }
                }

                //Gerard Jan 12 2009

                System.Data.DataTable _dt         = db.GetLastSendDate(mDetails.MessageCode, mDetails.ERP, mDetails.Principal);
                IMSMailStatus         _mailStatus = new IMSMailStatus();
                if (_dt.Rows.Count == 0)
                {
                    Console.WriteLine("IMSSendEmailWhenNoFilesFound-- Initial Run -- updating tables");
                    //first run no entries found create an entry
                    db.SaveIMSMailStatus(mDetails.MessageCode, mDetails.Principal, mDetails.ERP);
                    _dt = db.GetLastSendDate(mDetails.MessageCode, mDetails.ERP, mDetails.Principal);
                    //_lastSendDate = Convert.ToDateTime(_dt.Rows[0][0]);
                    _mailStatus.LastSendDate = Convert.ToDateTime(_dt.Rows[0][0]);
                    _mailStatus.MailSent     = Convert.ToBoolean(_dt.Rows[0][1]);

                    Console.WriteLine("IMSSendEmailWhenNoFilesFound Mail is being sent. -- Exception Report sent");
                    //Send both reports

                    //Email Summary Report
                    //success = PerformEmailProcess(1, "", "", ThreadName, IMSData, mDetails, true);
                    // Email Exception Report
                    success = PerformEmailProcess(2, "", "", ThreadName, IMSData, mDetails, true);
                    //Update mail sent
                    db.SaveIMSMailStatus(mDetails.MessageCode, mDetails.Principal, mDetails.ERP);
                }
                else
                {
                    Console.WriteLine("IMSSendEmailWhenNoFilesFound -- Entry Found -- Proceeding with mail send logic.");
                    //entry found
                    _mailStatus.LastSendDate = Convert.ToDateTime(_dt.Rows[0][0]);
                    _mailStatus.MailSent     = Convert.ToBoolean(_dt.Rows[0][1]);

                    if (_mailStatus.MailSent == false)
                    {
                        Console.WriteLine("IMSSendEmailWhenNoFilesFound Mail is being sent. -- Exception Report Sent --");
                        //Send both reports

                        //Email Summary Report
                        //success = PerformEmailProcess(1, "", "", ThreadName, IMSData, mDetails, true);
                        // Email Exception Report Summary
                        success = PerformEmailProcess(2, "", "", ThreadName, IMSData, mDetails, true);
                        //Update mail sent
                        db.SaveIMSMailStatus(mDetails.MessageCode, mDetails.Principal, mDetails.ERP);
                    }
                    else
                    {
                        if (_mailStatus.LastSendDate.ToShortDateString() == DateTime.Now.ToShortDateString())
                        {
                            //Do Nothing
                            Console.WriteLine("IMSSendEmailWhenNoFilesFound Mail already Sent today");
                        }
                        else
                        {
                            //update the mail status then send emails.
                            Console.WriteLine("IMSSendEmailWhenNoFilesFound - new day -- updating imsMailStatus and sending Exception Report mail");
                            //Email Summary Report
                            //success = PerformEmailProcess(1, "", "", ThreadName, IMSData, mDetails, true);
                            // Email Exception Report Summary
                            success = PerformEmailProcess(2, "", "", ThreadName, IMSData, mDetails, true);
                            db.SaveIMSMailStatus(mDetails.MessageCode, mDetails.Principal, mDetails.ERP);
                        }
                    }
                }

                //Mail hasn't been sent so send emails


                // Delete Process from Temp table
                db.DeleteIMSProcess(mDetails.IMSProcessId);
                if (db.ErrorMessage.Trim().Length > 0)
                {
                    success = false;
                    IAPL.Transport.Util.TextLogger.LogError("MessageTransaction-DeleteIMSFileProcessed()", "Database error: " + db.ErrorMessage);
                }
            }
            return(success);
        }