protected override void OnStart(string[] args)
        {
            try
            {
                //Thread.Sleep(15000);
                var displayName = GetServiceName();
                string configFile = AppDomain.CurrentDomain.BaseDirectory + "\\" + displayName + ".exe.config";
                if (File.Exists(configFile))
                {
                    AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configFile);
                }
                webClient = new CPServiceClient();
                string systemProcess = string.Empty;
                if (ConfigurationManager.AppSettings["SystemProcess"] != null) systemProcess = ConfigurationManager.AppSettings["SystemProcess"].ToString();

                //ServiceLogManager.GetLogger(this.GetType().Name).Info(string.Format("Started {0} Background Service", systemProcess));
                processor = new TaskProcessorCore(webClient.GetSystemProcessByName(systemProcess));
                processor.OnGetSystemProcessThread += new TaskProcessorCore.GetSystemProcessThreadEventHandler(processor_OnGetSystemProcessThread);
                processor.OnUpdateSystemProcess += new TaskProcessorCore.UpdateSystemProcessThreadEventHandler(processor_OnUpdateSystemProcess);
                processor.StartEngines();

                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            }
            catch (Exception e)
            {
                throw;
            }
        }
        protected override void OnStart(string[] args)
        {
            try
            {
                //Thread.Sleep(15000);
                var    displayName = GetServiceName();
                string configFile  = AppDomain.CurrentDomain.BaseDirectory + "\\" + displayName + ".exe.config";
                if (File.Exists(configFile))
                {
                    AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configFile);
                }
                webClient = new CPServiceClient();
                string systemProcess = string.Empty;
                if (ConfigurationManager.AppSettings["SystemProcess"] != null)
                {
                    systemProcess = ConfigurationManager.AppSettings["SystemProcess"].ToString();
                }

                //ServiceLogManager.GetLogger(this.GetType().Name).Info(string.Format("Started {0} Background Service", systemProcess));
                processor = new TaskProcessorCore(webClient.GetSystemProcessByName(systemProcess));
                processor.OnGetSystemProcessThread += new TaskProcessorCore.GetSystemProcessThreadEventHandler(processor_OnGetSystemProcessThread);
                processor.OnUpdateSystemProcess    += new TaskProcessorCore.UpdateSystemProcessThreadEventHandler(processor_OnUpdateSystemProcess);
                processor.StartEngines();

                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            }
            catch (Exception e)
            {
                throw;
            }
        }
        public void ToggleContinuous(string id)
        {
            int systemProcessThreadID = 0;

            int.TryParse(id, out systemProcessThreadID);
            if (systemProcessThreadID > 0)
            {
                //ControlPanel.Core.ICPWebClient webClient = ControlPanel.Core.IoC.Resolve<ControlPanel.Core.ICPWebClient>("CPWebClient");
                CPServiceClient webClient = new CPServiceClient();
                webClient.ToggleSystemProcessThreadContinuous(systemProcessThreadID);
            }
            GetAllSystemProcess();
        }
        public void ToggleEnabled(string id)
        {
            int systemProcessThreadID = 0;

            int.TryParse(id, out systemProcessThreadID);
            if (systemProcessThreadID > 0)
            {
                //ControlPanel.Core.ICPWebClient webClient = ControlPanel.Core.IoC.Resolve<ControlPanel.Core.ICPWebClient>("CPWebClient");
                CPServiceClient webClient = new CPServiceClient();
                webClient.ToggleSystemProcessThreadEnabled(systemProcessThreadID);
            }
            GetAllSystemProcess();
            var u   = HttpContext.Current.Request.Url.AbsoluteUri;
            var url = HttpContext.Current.Request.Url.Query;

            HttpContext.Current.Response.Redirect(u.Replace(url, ""));
        }
        public void GetAllSystemProcess()
        {
            CPServiceClient webClient = new CPServiceClient();
            List <ControlPanel.Core.Entities.SystemProcess> systemProcesses = webClient.GetAllSystemProcess();
            DateTime?lastUpdateDate = null;

            if (systemProcesses != null && systemProcesses.Count > 0)
            {
                systemProcesses = systemProcesses.OrderBy(x => x.DisplayOrder).ToList();
                foreach (ControlPanel.Core.Entities.SystemProcess systemProcess in systemProcesses)
                {
                    systemProcess.SystemProcessThreadList = webClient.GetSystemProcessThreadsByProcessID(systemProcess.SystemProcessId);
                    if (systemProcess.SystemProcessThreadList != null)
                    {
                        systemProcess.SystemProcessThreadList = systemProcess.SystemProcessThreadList.OrderBy(x => x.DisplayOrder.Length).ThenBy(x => x.DisplayOrder).ToList();
                        var currentMax = systemProcess.SystemProcessThreadList.Select(x => x.LastUpdateDate).Max();
                        foreach (var dt in systemProcess.SystemProcessThreadList)
                        {
                            if (dt.LastSuccessfullyExecuted != null)
                            {
                                dt.LastExecutedSeconds = (DateTime.UtcNow - dt.LastSuccessfullyExecuted.Value.ToUniversalTime()).ToString(@"hh\:mm\:ss");
                            }
                        }
                        if (!lastUpdateDate.HasValue || currentMax > lastUpdateDate)
                        {
                            lastUpdateDate = currentMax;
                        }
                    }
                }

                jsondata = new JavaScriptSerializer().Serialize(systemProcesses);

                if (lastUpdateDate.HasValue)
                {
                    lastupdatedate = lastUpdateDate.Value.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
                }
            }

            //jsondata = new JavaScriptSerializer().Serialize(systemProcesses);

            //lastupdatedate = lastUpdateDate.Value.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
        }
        public static string GetUpdatedSystemProcessThreads(string ThreadLastUpdateDateStr, string EventLogLastUpdateDateStr)
        {
            try
            {
                DateTime ThreadLastUpdateDate = DateTime.UtcNow;
                if (DateTime.TryParse(ThreadLastUpdateDateStr, out ThreadLastUpdateDate))
                {
                    ThreadLastUpdateDate = ThreadLastUpdateDate.ToUniversalTime();
                }
                DateTime EventLogLastUpdateDate = DateTime.UtcNow;

                if (DateTime.TryParse(EventLogLastUpdateDateStr, out EventLogLastUpdateDate))
                {
                    EventLogLastUpdateDate = EventLogLastUpdateDate.ToUniversalTime();
                }
                // ControlPanel.Core.ICPWebClient webClient = ControlPanel.Core.IoC.Resolve<ControlPanel.Core.ICPWebClient>("CPWebClient");
                CPServiceClient webClient       = new CPServiceClient();
                var             threads         = webClient.GetSystemProcessThreadsByLastUpdateDate(ThreadLastUpdateDate);
                var             eventLogs       = webClient.GetEventLogByLastUpdateDate(EventLogLastUpdateDate);
                DateTime        maxThreadDate   = ThreadLastUpdateDate;
                DateTime        maxEventLogDate = EventLogLastUpdateDate;

                if (threads.Data == null)
                {
                    threads.Data = new List <ControlPanel.Core.Entities.SystemProcessThread>();
                }
                else if (threads.Data.Count > 0)
                {
                    maxThreadDate = threads.Data.Select(x => x.LastUpdateDate).Max().Value;
                }

                foreach (var dt in threads.Data)
                {
                    if (dt.LastSuccessfullyExecuted != null)
                    {
                        dt.LastExecutedSeconds = (DateTime.UtcNow - dt.LastSuccessfullyExecuted.Value.ToUniversalTime()).ToString(@"hh\:mm\:ss");
                    }
                }

                if (eventLogs == null)
                {
                    eventLogs = new List <ControlPanel.Core.Entities.SystemEventLog>();
                }
                else if (eventLogs.Count > 0)
                {
                    maxEventLogDate = eventLogs.Select(x => x.DateOccured).Max();
                }

                if (threads.Data != null && threads.Data.Count > 0)
                {
                    return(JSONhelper.GetString(new ControlPanelUpdateModel()
                    {
                        Threads = threads.Data, ThreadLastUpdateDate = maxThreadDate, EventLogs = eventLogs, EventLogLastUpdateDate = maxEventLogDate
                    }));
                }
                else
                {
                    return(JSONhelper.GetString(new ControlPanelUpdateModel()
                    {
                        ThreadLastUpdateDate = ThreadLastUpdateDate, EventLogLastUpdateDate = EventLogLastUpdateDate
                    }));
                }
            }
            catch (Exception exp) { return(exp.Message); }
        }
 public void ToggleEnabled(string id)
 {
     int systemProcessThreadID = 0;
     int.TryParse(id, out systemProcessThreadID);
     if (systemProcessThreadID > 0)
     {
         //ControlPanel.Core.ICPWebClient webClient = ControlPanel.Core.IoC.Resolve<ControlPanel.Core.ICPWebClient>("CPWebClient");
         CPServiceClient webClient = new CPServiceClient();
         webClient.ToggleSystemProcessThreadEnabled(systemProcessThreadID);
     }
     GetAllSystemProcess();
     var u = HttpContext.Current.Request.Url.AbsoluteUri;
     var url =  HttpContext.Current.Request.Url.Query;
     HttpContext.Current.Response.Redirect(u.Replace(url,""));
 }
 public void ToggleContinuous(string id)
 {
     int systemProcessThreadID = 0;
     int.TryParse(id, out systemProcessThreadID);
     if (systemProcessThreadID > 0)
     {
         //ControlPanel.Core.ICPWebClient webClient = ControlPanel.Core.IoC.Resolve<ControlPanel.Core.ICPWebClient>("CPWebClient");
         CPServiceClient webClient = new CPServiceClient();
         webClient.ToggleSystemProcessThreadContinuous(systemProcessThreadID);
     }
     GetAllSystemProcess();
 }
        public void GetAllSystemProcess()
        {
            CPServiceClient webClient = new CPServiceClient();
            List<ControlPanel.Core.Entities.SystemProcess> systemProcesses = webClient.GetAllSystemProcess();
            DateTime? lastUpdateDate = null;
            if (systemProcesses != null && systemProcesses.Count > 0)
            {
                systemProcesses = systemProcesses.OrderBy(x => x.DisplayOrder).ToList();
                foreach (ControlPanel.Core.Entities.SystemProcess systemProcess in systemProcesses)
                {
                    systemProcess.SystemProcessThreadList = webClient.GetSystemProcessThreadsByProcessID(systemProcess.SystemProcessId);
                    if (systemProcess.SystemProcessThreadList != null)
                    {
                        systemProcess.SystemProcessThreadList = systemProcess.SystemProcessThreadList.OrderBy(x => x.DisplayOrder.Length).ThenBy(x => x.DisplayOrder).ToList();
                        var currentMax = systemProcess.SystemProcessThreadList.Select(x => x.LastUpdateDate).Max();
                        foreach (var dt in systemProcess.SystemProcessThreadList)
                        {
                            if (dt.LastSuccessfullyExecuted != null)
                                dt.LastExecutedSeconds = (DateTime.UtcNow - dt.LastSuccessfullyExecuted.Value.ToUniversalTime()).ToString(@"hh\:mm\:ss");
                        }
                        if (!lastUpdateDate.HasValue || currentMax > lastUpdateDate)
                            lastUpdateDate = currentMax;
                    }
                }

                jsondata = new JavaScriptSerializer().Serialize(systemProcesses);

                if (lastUpdateDate.HasValue)
                lastupdatedate = lastUpdateDate.Value.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
            }

            //jsondata = new JavaScriptSerializer().Serialize(systemProcesses);

            //lastupdatedate = lastUpdateDate.Value.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
        }
        public static string GetUpdatedSystemProcessThreads(string ThreadLastUpdateDateStr, string EventLogLastUpdateDateStr)
        {
            try
            {
                DateTime ThreadLastUpdateDate = DateTime.UtcNow;
                if (DateTime.TryParse(ThreadLastUpdateDateStr, out ThreadLastUpdateDate))
                {
                    ThreadLastUpdateDate = ThreadLastUpdateDate.ToUniversalTime();
                }
                DateTime EventLogLastUpdateDate = DateTime.UtcNow;

                if (DateTime.TryParse(EventLogLastUpdateDateStr, out EventLogLastUpdateDate))
                {
                    EventLogLastUpdateDate = EventLogLastUpdateDate.ToUniversalTime();
                }
               // ControlPanel.Core.ICPWebClient webClient = ControlPanel.Core.IoC.Resolve<ControlPanel.Core.ICPWebClient>("CPWebClient");
                CPServiceClient webClient = new CPServiceClient();
                var threads = webClient.GetSystemProcessThreadsByLastUpdateDate(ThreadLastUpdateDate);
                var eventLogs = webClient.GetEventLogByLastUpdateDate(EventLogLastUpdateDate);
                DateTime maxThreadDate = ThreadLastUpdateDate;
                DateTime maxEventLogDate = EventLogLastUpdateDate;

                if (threads.Data == null)
                    threads.Data = new List<ControlPanel.Core.Entities.SystemProcessThread>();
                else if (threads.Data.Count > 0)
                    maxThreadDate = threads.Data.Select(x => x.LastUpdateDate).Max().Value;

                foreach (var dt in threads.Data)
                {
                    if (dt.LastSuccessfullyExecuted != null)
                        dt.LastExecutedSeconds = (DateTime.UtcNow - dt.LastSuccessfullyExecuted.Value.ToUniversalTime()).ToString(@"hh\:mm\:ss");
                }

                if (eventLogs == null) eventLogs = new List<ControlPanel.Core.Entities.SystemEventLog>();
                else if (eventLogs.Count > 0)
                    maxEventLogDate = eventLogs.Select(x => x.DateOccured).Max();

                if (threads.Data != null && threads.Data.Count > 0)

                    return JSONhelper.GetString(new ControlPanelUpdateModel() { Threads = threads.Data, ThreadLastUpdateDate = maxThreadDate, EventLogs = eventLogs, EventLogLastUpdateDate = maxEventLogDate });
                else return JSONhelper.GetString(new ControlPanelUpdateModel() { ThreadLastUpdateDate = ThreadLastUpdateDate, EventLogLastUpdateDate = EventLogLastUpdateDate });
            }
            catch (Exception exp) { return exp.Message; }
        }