Exemple #1
0
        public static void LogSystemError(ILogger log, string version, Exception ex)
        {
            log.LogError(ex, $"R2PLoader failed at: {DateTime.Now}");
            string msg = DateTime.Now.ToUniversalTime() + ":" + version + ":" + ex.Message;

            AzureFileHelper.WriteFile("system/AzureDataHubProduction.System.log", msg, true);
        }
Exemple #2
0
 public static void WriteLogFile(string plant, string msg)
 {
     if (!string.IsNullOrEmpty(plant))
     {
         AzureFileHelper.WriteFile("system/" + "AzureDataHubProduction." + plant + ".log", msg, true);
     }
     else
     {
         AzureFileHelper.WriteFile("system/AzureDataHubProduction.System.log", msg, true);
     }
 }
        public void ProcessFile(ILogger log, string version)
        {
            SuncorProductionFile.SetLogFileWriter(LogHelper.WriteLogFile);
            this.ProducitionFile = null;
            DateTime day = GetCurrentDay(this.PlantName);

            if (this.IsHoneywellPB)
            {
                this.ProducitionFile = new HoneywellPBParser().LoadFile(this.TempFileName, this.PlantName, day);
            }
            if (this.IsMontrealSulphur)
            {
                this.ProducitionFile = new MontrealSulphurParser().LoadFile(this.TempFileName, this.PlantName, this.ProductCode, day);
            }
            if (this.IsDPS)
            {
                this.ProducitionFile = new DPSParser().LoadFile(this.TempFileName, this.PlantName, day);
            }
            if (this.IsDenver)
            {
                this.ProducitionFile = new SigmafineParser().LoadExcel(this.TempFileName, this.PlantName, day);
            }
            if (this.IsTerraNova)
            {
                this.ProducitionFile = new TerraNovaParser().LoadFile(this.TempFileName, this.PlantName, day);
            }
            if (this.IsSarnia)
            {
            }
            if (this.ProducitionFile != null)
            {
                this.ProducitionFile.SaveRecords();
                this.SuccessfulRecords = this.ProducitionFile.SavedRecords.Count;
                this.FailedRecords     = this.ProducitionFile.FailedRecords.Count;
                if (this.ProducitionFile.SavedRecords.Count > 0)
                {
                    string json = this.ProducitionFile.ExportR2PJson();
                    if (!MulesoftPush.PostProduction(json))
                    {
                        LogHelper.LogSystemError(log, version, "Json NOT sent to Mulesoft");
                        this.ProducitionFile.Warnings.Add(new WarningMessage("Json NOT sent to Mulesoft"));
                    }
                    AzureFileHelper.WriteFile(this.AzureFullPathName.Replace("immediateScan", "tempJsonOutput") + ".json", json, false);
                }
            }
        }
        public static DateTime GetCurrentDay(string plant)
        {
            DateTime day               = DateTime.Today;
            string   fileName          = $"system/currentDate.{plant}.txt";
            string   currentDateString = AzureFileHelper.ReadFile(fileName);

            // only use the first line
            if (!String.IsNullOrEmpty(currentDateString))
            {
                string currentDateString1stLine = currentDateString.Split('\n')[0];
                try {
                    day = DateTime.Parse(currentDateString1stLine);
                } catch (Exception ex) {
                    throw new Exception("Invalid Date Format for system/currentDate." + plant + ".txt");
                }
                // move the currentDate.txt to processed
                AzureFileHelper.WriteFile(fileName.Replace(".txt", ".processed.txt"), currentDateString, false);
                AzureFileHelper.DeleteFile(fileName);
            }
            return(day);
        }