Esempio n. 1
0
        public static int Check_system_status(String source, String URL)
        {
            // 1 - OK, 0 - Error, -1 - Stop Client

            var response = Network_Utils.Get_Request(URL);

            JArray array = JArray.Parse(response);

            int error_status = Network_Utils.Check_error(source, JObject.Parse(array[0].ToString()));

            if (error_status == 0)
            {
                if ((Int32)JObject.Parse(array[1].ToString())["system_status"] == 1)
                {
                    Log_Utils.Add_system_event_and_log(source, "System status is OK", EventLogEntryType.Information);
                    return(1);
                }
                else if ((Int32)JObject.Parse(array[1].ToString())["system_status"] == 0)
                {
                    Log_Utils.Add_system_event_and_log(source, "System is in maintanace mode", EventLogEntryType.Information);
                    return(-1);
                }
                else
                {
                    Log_Utils.Add_system_event_and_log(source, "Check response, response : " + response, EventLogEntryType.Information);
                }
            }
            else if (error_status == 2)
            {
                Log_Utils.Add_system_event_and_log(source, "Check response, response : " + response, EventLogEntryType.Information);
            }

            return(0);
        }
        public static int Start_with_arguments(String source, String file, String arguments)
        {
            //TODO : Handle Exception

            ProcessStartInfo startInfo = new ProcessStartInfo
            {
                CreateNoWindow         = false,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                FileName = file
            };

            Log_Utils.Add_system_event_and_log(source, "File path : " + file, EventLogEntryType.Information);
            Log_Utils.Add_system_event_and_log(source, "File arguments : " + arguments, EventLogEntryType.Information);

            startInfo.Arguments = arguments;

            try
            {
                return(Process.Start(startInfo).Id);
            }
            catch (Exception ex)
            {
                LAST_EXCEPTION = ex;
                return(0);
            }
        }
 public static bool Kill(String source, int process_id)
 {
     try
     {
         Process proc = Process.GetProcessById(process_id);
         proc.Kill();
         return(true);
     }
     catch (Exception ex)
     {
         Log_Utils.Add_system_event_and_log(source, "Kill Exception " + ex.ToString(), EventLogEntryType.Error);
         return(false);
     }
 }
 public static int Check_error(string source, JObject error_node)
 {
     //TODO : Use interface for success
     if ((Int32)error_node["error_status"] == 0)
     {
         return(0);
     }
     else if ((Int32)error_node["error_status"] == 1)
     {
         Log_Utils.Add_system_event_and_log(source, "Error : " + error_node["error"] + " - " + error_node["error_number"], EventLogEntryType.Information);
         return(1);
     }
     else
     {
         return(2);
     }
 }