public void logfile(int controlId, string logName, string logDescription, String noteData)
 {
     try
     {
         using (var dbLog = new REU_RegistrationEntities())
         {
             Log_File logFileInsert = dbLog.Log_File.Create();
             logFileInsert.Log_Date = DateTime.Now;
             if (controlId != 0)
             {
                 if (SessionWrapper.LoggedUser != null)
                 {
                     logFileInsert.Login_Id = SessionWrapper.LoggedUser.Employee_Id;
                 }
                 else
                 {
                     logFileInsert.Login_Id = 1;
                 }
                 logFileInsert.Form_Id = currentPage();
             }
             logFileInsert.Log_Name        = logName;
             logFileInsert.Log_Description = logDescription;
             logFileInsert.Log_Note        = noteData;
             dbLog.Log_File.Add(logFileInsert);
             dbLog.SaveChanges();
         }
     }
     catch (Exception er) { }
 }
Exemple #2
0
        public void LogFile()
        {
            var config   = new LoggingConfiguration();
            var loglevel = LogLevel.Debug;

            var layout = @"${message}";

            var consoleTarget = new ColoredConsoleTarget();

            config.AddTarget("console", consoleTarget);

            consoleTarget.Layout = layout;

            var rule1 = new LoggingRule("*", loglevel, consoleTarget);

            config.LoggingRules.Add(rule1);

            LogManager.Configuration = config;
            var l = LogManager.GetLogger("foo");

            var lf = Log_File.Load(@"D:\SynologyDrive\ntfs\RomanoffFileSystem\$LogFile");
            //ss..Count.Should().Be(41);

//            Debug.WriteLine($"{lf.PrimaryRstrPage}");
//            Debug.WriteLine($"{lf.SecondaryRstrPage}");
//            Debug.WriteLine($"{lf.NormalPageArea.Count:N0}");
        }
Exemple #3
0
        public static void Main(String[] args)
        {
            bool Test_UMR  = false;
            bool Read_Only = false;

            foreach (string arg in args)
            {
                if (arg.Equals(@"/u"))
                {
                    Test_UMR = true;
                }
                if (arg.Equals(@"/r"))
                {
                    Read_Only = true;
                }
            }

            if (Test_UMR)
            {
                Test_Space.Testing.Main_Test();
                return;
            }

            System.IO.StreamWriter Log_File;
#if DEBUG
            Log_File = System.IO.File.AppendText(@"PhaseOpt_Kar_Main_Test.log");
#else
            Log_File = System.IO.File.AppendText(@"PhaseOpt_Kar_Main.log");
#endif

            Log_File.WriteLine("{0}: PhaseOpt startup", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();

#if DEBUG
            PhaseOpt_KAR PO_A = new PhaseOpt_KAR(@"PhaseOpt_Kar_A_Test.log");
            PhaseOpt_KAR PO_B = new PhaseOpt_KAR(@"PhaseOpt_Kar_B_Test.log");

            PO_A.Read_Config("PhaseOpt_A_Test.xml");
            PO_B.Read_Config("PhaseOpt_B_Test.xml");
#else
            PhaseOpt_KAR PO_A = new PhaseOpt_KAR(@"PhaseOpt_Kar_A.log");
            PhaseOpt_KAR PO_B = new PhaseOpt_KAR(@"PhaseOpt_Kar_B.log");

            PO_A.Read_Config("PhaseOpt_A.xml");
            PO_B.Read_Config("PhaseOpt_B.xml");
#endif
            PO_A.Name = "GC A";
            PO_B.Name = "GC B";
            PO_A.Connect_DB();
            PO_B.Connect_DB();

            if (Read_Only)
            {
                PO_A.DB_Connection.IP21_Read_Only = true;
                PO_B.DB_Connection.IP21_Read_Only = true;
            }

            DateTime Start_Time;
            double   Sleep_Time       = 0.0;
            int      errors_A         = 0;
            int      errors_B         = 0;
            int      errors_current_A = 0;
            int      errors_current_B = 0;

            while (true)
            {
                Start_Time = DateTime.Now;

                Log_File.WriteLine("{0}: Read composition A", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                Log_File.WriteLine("{0}: Read composition B", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();

                Log_File.WriteLine("{0}: Read from IP21 A", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                Log_File.WriteLine("{0}: Read from IP21 B", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();

                Parallel.Invoke(
                    () =>
                {
                    PO_A.Read_Composition();
                    PO_A.Read_Current_Kalsto_Composition();
                    errors_A         = PO_A.Validate();
                    errors_current_A = PO_A.Validate_Current();
                },

                    () =>
                {
                    PO_B.Read_Composition();
                    PO_B.Read_Current_Kalsto_Composition();
                    errors_B         = PO_B.Validate();
                    errors_current_B = PO_B.Validate_Current();
                }
                    );

                // Calculate composition mixes, cricondenbar and set status flag
                Parallel.Invoke(
                    () =>
                {
                    if (errors_A < 1)
                    {
                        PO_A.Calculate_Karsto();
                        Log_File.WriteLine("{0}: Calculate CCB at Kårstø A", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                    }
                    else
                    {
                        Log_File.WriteLine("{0}: Errors in A.", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                    }
                },

                    () =>
                {
                    if (errors_B < 1)
                    {
                        PO_B.Calculate_Karsto();
                        Log_File.WriteLine("{0}: Calculate CCB at Kårstø B", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                    }
                    else
                    {
                        Log_File.WriteLine("{0}: Errors in B.", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                    }
                },
                    // Read and calculate cricondenbar for current
                    // compositions at Kalstø
                    () =>
                {
                    if (errors_A < 1)
                    {
                        PO_A.Calculate_Kalsto_Statpipe();
                        Log_File.WriteLine("{0}: Calculate Statpipe stream at Kalstø A", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                    }
                    else
                    {
                        Log_File.WriteLine("{0}: Errors in Statpipe current composition A", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                    }
                },

                    () =>
                {
                    if (errors_A < 1)
                    {
                        PO_A.Calculate_Kalsto_Asgard();
                        Log_File.WriteLine("{0}: Calculate Åsgard stream at Kalstø A", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                    }
                    else
                    {
                        Log_File.WriteLine("{0}: Errors in Asgard current composition A", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                    }
                },

                    () =>
                {
                    if (errors_B < 1)
                    {
                        PO_B.Calculate_Kalsto_Statpipe();
                        Log_File.WriteLine("{0}: Calculate Statpipe stream at Kalstø B", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                    }
                    else
                    {
                        Log_File.WriteLine("{0}: Errors in Statpipe current composition B", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                    }
                },

                    () =>
                {
                    if (errors_B < 1)
                    {
                        PO_B.Calculate_Kalsto_Asgard();
                        Log_File.WriteLine("{0}: Calculate Åsgard stream at Kalstø B", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                    }
                    else
                    {
                        Log_File.WriteLine("{0}: Errors in Asgard current composition B", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                    }
                }
                    );

                Log_File.WriteLine("{0}: Read current composition from IP21 A", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();
                Log_File.WriteLine("{0}: Read current composition from IP21 B", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Log_File.Flush();

                PO_A.Trigger_Watchdog();

                if (errors_A < 1)
                {
                    PO_A.Calculate_Dropout_Curves(PO_A.Mix_To_T410, PO_A.T400);
                    PO_A.Calculate_Dropout_Curves(PO_A.Mix_To_T100, PO_A.T100);
                }

                Sleep_Time = (Start_Time.AddSeconds(150.0) - DateTime.Now).TotalMilliseconds;
                if (Sleep_Time > 1.0)
                {
                    Console.WriteLine("Waiting {0} seconds", Sleep_Time / 1000.0);
                    System.Threading.Thread.Sleep((int)Sleep_Time);
                }
            }
        }
Exemple #4
0
        protected override void Execute(CodeActivityContext context)
        {
            string Out_File_Path = Path.Get(context);
            string File_Format   = Format.ToString();
            string Log_File_Path = "";

            string[]     Log_files = Directory.GetFiles(Environment.ExpandEnvironmentVariables("%LocalAppData%/UiPath/Logs/"));
            StreamWriter Text_File = null;
            StreamWriter Html_File = null;
            Application  Excel_App = null;
            Workbook     wb        = null;
            Worksheet    ws        = null;

            DateTime Mod_Time = DateTime.MinValue;

            foreach (string Log_File in Log_files)
            {
                if (File.GetLastWriteTime(Log_File) > Mod_Time && Log_File.Contains("_Execution"))
                {
                    Mod_Time      = File.GetLastWriteTime(Log_File);
                    Log_File_Path = Log_File;
                }
            }
            //Console.WriteLine(Log_File_Path);
            System.IO.StreamReader file = new System.IO.StreamReader(Log_File_Path);
            if (File_Format == "txt")
            {
                Text_File = new StreamWriter(Out_File_Path + ".txt");
            }

            if (File_Format == "html")
            {
                Html_File = new StreamWriter(Out_File_Path + ".html");
                Html_File.WriteLine("<html>");
            }

            if (File_Format == "xlsx")
            {
                Excel_App = new Application();
                wb        = Excel_App.Workbooks.Add();
                ws        = wb.Sheets[1];
                ws.Columns[2].NumberFormat = "HH:MM:SS";
            }


            string Job_Id_Pattern = "\"jobId\":\"(.*)\",\"robotName\"";
            string line;
            string Job_Id = "";

            //string pattern = "(.*) (.*) {\"message\":\"(.*)\",\"level\":\"(.*)\",\"logType\":\"(.*)\",\"timeStamp\":\"(.*)\",\"fingerprint\":\"(.*)\",\"windowsIdentity\":\"(.*)\",\"machineName\":\"(.*)\",\"processName\":\"(.*)\",\"processVersion\":\"(.*)\",\"jobId\":\"(.*)\",\"robotName\":\"(.*)\",\"machineId\":(.*)";
            while ((line = file.ReadLine()) != null)
            {
                //Console.WriteLine(line);
                MatchCollection Job_Id_Matches = Regex.Matches(line, Job_Id_Pattern);
                Match           match          = Job_Id_Matches[0];

                Job_Id = match.Groups[1].ToString();
            }
            file.Close();
            file = new System.IO.StreamReader(Log_File_Path);
            int row = 1, column = 1;

            while ((line = file.ReadLine()) != null)
            {
                MatchCollection Job_Id_Matches = Regex.Matches(line, Job_Id_Pattern);
                Match           match          = Job_Id_Matches[0];


                if (Job_Id == match.Groups[1].ToString())
                {
                    string          pattern             = "(.*) (.*) {\"message\":\"(.*)\",\"level\".*\"timeStamp\":\"(.*)T.*,\"fingerprint\"";
                    MatchCollection Target_data_Matches = Regex.Matches(line, pattern);
                    Match           Target_Data_Match   = Target_data_Matches[0];
                    string          Date        = Target_Data_Match.Groups[4].ToString();
                    string          Time        = Target_Data_Match.Groups[1].ToString();
                    string          Log_Level   = Target_Data_Match.Groups[2].ToString();
                    string          Message     = Target_Data_Match.Groups[3].ToString();
                    string          Result_Line = Date + "   " + Time + "   " + Log_Level + "   " + Message;
                    if (File_Format == "txt")
                    {
                        Text_File.WriteLine(Result_Line);
                    }

                    if (File_Format == "html")
                    {
                        if (Log_Level == "Error" || Log_Level == "Fatal")
                        {
                            Result_Line = "<p><font color=\"red\">" + Result_Line + "</Font></p>";
                        }
                        else if (Log_Level == "Warn")
                        {
                            Result_Line = "<p><font color=\"orange\">" + Result_Line + "</Font></p>";
                        }
                        else
                        {
                            Result_Line = "<p>" + Result_Line + "</p>";
                        }
                        Html_File.WriteLine(Result_Line);
                    }

                    if (File_Format == "xlsx")
                    {
                        ws.Cells[row, column]     = Date;
                        ws.Cells[row, column + 1] = Time;
                        ws.Cells[row, column + 2] = Log_Level;
                        ws.Cells[row, column + 3] = Message;
                        row++;
                    }
                    //Console.WriteLine(Result_Line);
                }
            }

            if (File_Format == "html")
            {
                Html_File.WriteLine("</html>");
                Html_File.Close();
            }

            if (File_Format == "txt")
            {
                Text_File.Close();
            }

            if (File_Format == "xlsx")
            {
                Excel_App.DisplayAlerts = false;
                wb.SaveAs(Out_File_Path + ".xlsx", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing,
                          Type.Missing, Type.Missing);
                wb.Close();
                Excel_App.Quit();
            }
            // Console.Read();
            // System.Data.DataTable dt = new System.Data.DataTable();
        }