Пример #1
0
        public DataTransfer <GetOutput> Get(string id)
        {
            DataTransfer <GetOutput> tranfer = new DataTransfer <GetOutput>();

            System.Int32 systemprocessthreadid = 0;
            if (!string.IsNullOrEmpty(id) && System.Int32.TryParse(id, out systemprocessthreadid))
            {
                SystemProcessThread systemprocessthread = _iSystemProcessThreadRepository.GetSystemProcessThread(systemprocessthreadid);
                if (systemprocessthread != null)
                {
                    tranfer.IsSuccess = true;
                    GetOutput output = new GetOutput();
                    output.CopyFrom(systemprocessthread);
                    tranfer.Data = output;
                }
                else
                {
                    tranfer.IsSuccess = false;
                    tranfer.Errors    = new string[1];
                    tranfer.Errors[0] = "Error: No record found.";
                }
            }
            else
            {
                tranfer.IsSuccess = false;
                tranfer.Errors    = new string[1];
                tranfer.Errors[0] = "Error: Invalid request.";
            }
            return(tranfer);
        }
Пример #2
0
        public SystemProcessThread UpdateSystemProcessThread(SystemProcessThread processThread)
        {
            // ISystemProcessThreadService systemProcessThreadService = IoC.Resolve<ISystemProcessThreadService>("SystemProcessThreadService");
            SystemProcessThreadService systemProcessThreadService = new SystemProcessThreadService();

            return(systemProcessThreadService.UpdateSystemProcessThread(processThread));
        }
Пример #3
0
        private void UpdateSystemProcessThread(SystemProcessThread systemProcessThread)
        {
            SystemProcessThread thread = processThreads.Where(x => x.SystemProcessThreadId == systemProcessThread.SystemProcessThreadId).FirstOrDefault();

            thread.LastUpdateDate = DateTime.UtcNow;
            thread = systemProcessThread;
        }
Пример #4
0
        public DataTransfer <PutOutput> Update(PutInput Input)
        {
            DataTransfer <PutOutput> transer = new DataTransfer <PutOutput>();
            SystemProcessThread      systemprocessthreadinput  = new SystemProcessThread();
            SystemProcessThread      systemprocessthreadoutput = new SystemProcessThread();
            PutOutput output = new PutOutput();

            systemprocessthreadinput.CopyFrom(Input);
            SystemProcessThread systemprocessthread = _iSystemProcessThreadRepository.GetSystemProcessThread(systemprocessthreadinput.SystemProcessThreadId);

            if (systemprocessthread != null)
            {
                systemprocessthreadoutput = _iSystemProcessThreadRepository.UpdateSystemProcessThread(systemprocessthreadinput);
                if (systemprocessthreadoutput != null)
                {
                    output.CopyFrom(systemprocessthreadoutput);
                    transer.IsSuccess = true;
                    transer.Data      = output;
                }
                else
                {
                    transer.IsSuccess = false;
                    transer.Errors    = new string[1];
                    transer.Errors[0] = "Error: Could not update.";
                }
            }
            else
            {
                transer.IsSuccess = false;
                transer.Errors    = new string[1];
                transer.Errors[0] = "Error: Record not found.";
            }
            return(transer);
        }
Пример #5
0
        void thread_OnReportEngineState(string threadName, GenericServiceThread.EngineStatusList state)
        {
            SystemProcessThread systemProcessThread = GetSystemProcessThread(threadName);

            if (systemProcessThread != null)
            {
                systemProcessThread.Status = state.ToString();
                UpdateSystemProcessThread(_OnUpdateSystemProcess(systemProcessThread));
            }
        }
Пример #6
0
 //static void exceptionManager_ErrorLog_Handler(object sender, ExceptionManagementEventArgs e)
 //{
 //    string errorID = string.Empty;
 //    try
 //    {
 //        errorID = WCFServiceContext<IMOService>.ServiceContext.LogException(e.ErrorToLog, true);
 //        //Logging to file
 //        ExceptionManagement exceptionManager = new ExceptionManagement();
 //        Log errorLog = exceptionManager.GetLog(e.ErrorToLog);
 //        errorLog.ElmahId = errorID;
 //        exceptionManager.LogToFile(errorLog);
 //    }
 //    catch (Exception ex)
 //    {
 //        throw ex;
 //    }
 //}
 public void StopThread(SystemProcessThread systemProcessThread)
 {
     processThreads.Where(x => x.Name == systemProcessThread.Name).First().Enabled =
         false;
     if (_OnUpdateSystemProcess != null)
     {
         systemProcessThread.Enabled = false;
         systemProcessThread         = _OnUpdateSystemProcess(systemProcessThread);
     }
 }
        public virtual SystemProcessThread UpdateSystemProcessThread(SystemProcessThread entity, string connectionString)
        {
            entity.LastUpdateDate = DateTime.UtcNow;
            string sql = @"Update SystemProcessThread set  [SystemProcessID]=@SystemProcessID
							, [Name]=@Name
							, [SpringEntryName]=@SpringEntryName
							, [Description]=@Description
							, [Enabled]=@Enabled
							, [Continuous]=@Continuous
							, [SleepTime]=@SleepTime
							, [AutoStart]=@AutoStart
							, [Status]=@Status
							, [Message]=@Message
							, [ScheduledTime]=@ScheduledTime
							, [StartRange]=@StartRange
							, [EndRange]=@EndRange
							, [LastSuccessfullyExecuted]=@LastSuccessfullyExecuted
							, [ContinuousDelay]=@ContinuousDelay
							, [IsDeleted]=@IsDeleted
							, [DisplayOrder]=@DisplayOrder
							, [Argument]=@Argument
							, [LastUpdateDate]=@LastUpdateDate
							, [ExecutionTime]=@ExecutionTime
							, [EstimatedExecutionTime]=@EstimatedExecutionTime
							, [ShowUpdateInLog]=@ShowUpdateInLog 
							 where SystemProcessThreadID=@SystemProcessThreadID"                            ;

            SqlParameter[] parameterArray = new SqlParameter[] {
                new SqlParameter("@SystemProcessID", entity.SystemProcessId)
                , new SqlParameter("@Name", entity.Name)
                , new SqlParameter("@SpringEntryName", entity.SpringEntryName ?? (object)DBNull.Value)
                , new SqlParameter("@Description", entity.Description ?? (object)DBNull.Value)
                , new SqlParameter("@Enabled", entity.Enabled)
                , new SqlParameter("@Continuous", entity.Continuous)
                , new SqlParameter("@SleepTime", entity.SleepTime)
                , new SqlParameter("@AutoStart", entity.AutoStart)
                , new SqlParameter("@Status", entity.Status ?? (object)DBNull.Value)
                , new SqlParameter("@Message", entity.Message ?? (object)DBNull.Value)
                , new SqlParameter("@ScheduledTime", entity.ScheduledTime ?? (object)DBNull.Value)
                , new SqlParameter("@StartRange", entity.StartRange ?? (object)DBNull.Value)
                , new SqlParameter("@EndRange", entity.EndRange ?? (object)DBNull.Value)
                , new SqlParameter("@LastSuccessfullyExecuted", entity.LastSuccessfullyExecuted ?? (object)DBNull.Value)
                , new SqlParameter("@ContinuousDelay", entity.ContinuousDelay)
                , new SqlParameter("@IsDeleted", entity.IsDeleted)
                , new SqlParameter("@DisplayOrder", entity.DisplayOrder)
                , new SqlParameter("@Argument", entity.Argument ?? (object)DBNull.Value)
                , new SqlParameter("@LastUpdateDate", entity.LastUpdateDate ?? (object)DBNull.Value)
                , new SqlParameter("@ExecutionTime", entity.ExecutionTime ?? (object)DBNull.Value)
                , new SqlParameter("@EstimatedExecutionTime", entity.EstimatedExecutionTime ?? (object)DBNull.Value)
                , new SqlParameter("@ShowUpdateInLog", entity.ShowUpdateInLog ?? (object)DBNull.Value)
                , new SqlParameter("@SystemProcessThreadID", entity.SystemProcessThreadId)
            };
            SqlHelper.ExecuteNonQuery(string.IsNullOrEmpty(connectionString) ? this.ConnectionString : connectionString, CommandType.Text, sql, parameterArray);
            return(GetSystemProcessThread(entity.SystemProcessThreadId, connectionString));
        }
Пример #8
0
        private GenericServiceThread InitializeThread(SystemProcessThread serviceThread)
        {
            GenericServiceThread thread = new GenericServiceThread(serviceThread.Name, userAccountId);

            thread.OnExecute           += new GenericServiceThread.GOEventHandler(Execute);
            thread.OnSetStatusMessage  += new GenericServiceThread.SetStatusMessageEventHandler(thread_OnSetStatusMessage);
            thread.OnReportEngineState += new GenericServiceThread.ReportEngineStateEventHandler(thread_OnReportEngineState);
            thread.OnSetEngineState    += new GenericServiceThread.SetEngineStateEventHandler(thread_OnSetEngineState);
            thread.Init(false, serviceThread.SleepTime, serviceThread.Enabled);
            return(thread);
        }
Пример #9
0
        void thread_OnSetEngineState(string threadName, bool?enabled, bool?continuous, bool resetName)
        {
            SystemProcessThread systemProcessThread = GetSystemProcessThread(threadName);

            if (resetName)
            {
                systemProcessThread.Name = threadName;
            }
            systemProcessThread.Enabled    = enabled == null ? systemProcessThread.Enabled : (bool)enabled;
            systemProcessThread.Continuous = continuous == null ? systemProcessThread.Continuous : (bool)continuous;

            UpdateSystemProcessThread(_OnUpdateSystemProcess(systemProcessThread));
            //lastChecked = DateTime.Now;
        }
Пример #10
0
        void thread_OnSetStatusMessage(string threadName, string messageText)
        {
            SystemProcessThread systemProcessThread = GetSystemProcessThread(threadName);

            if (systemProcessThread != null)
            {
                string status = messageText;
                if (string.IsNullOrEmpty(messageText))
                {
                    systemProcessThread.Message = status;
                    UpdateSystemProcessThread(_OnUpdateSystemProcess(systemProcessThread));
                    return;
                }

                systemProcessThread.Message = status;
                UpdateSystemProcessThread(_OnUpdateSystemProcess(systemProcessThread));
            }
        }
Пример #11
0
        public virtual SystemProcessThread InsertSystemProcessThread(SystemProcessThread entity)
        {
            SystemProcessThread other = new SystemProcessThread();

            other = entity;
            if (entity.IsTransient())
            {
                string         sql            = @"Insert into SystemProcessThread ( [SystemProcessID]
				,[Name]
				,[SpringEntryName]
				,[Description]
				,[Enabled]
				,[Continuous]
				,[SleepTime]
				,[AutoStart]
				,[Status]
				,[Message]
				,[ScheduledTime]
				,[StartRange]
				,[EndRange]
				,[LastSuccessfullyExecuted]
				,[ContinuousDelay]
				,[IsDeleted]
				,[DisplayOrder]
				,[Argument]
				,[LastUpdateDate]
				,[ExecutionTime]
				,[EstimatedExecutionTime]
				,[ShowUpdateInLog]
				,[TenantId] )
				Values
				( @SystemProcessID
				, @Name
				, @SpringEntryName
				, @Description
				, @Enabled
				, @Continuous
				, @SleepTime
				, @AutoStart
				, @Status
				, @Message
				, @ScheduledTime
				, @StartRange
				, @EndRange
				, @LastSuccessfullyExecuted
				, @ContinuousDelay
				, @IsDeleted
				, @DisplayOrder
				, @Argument
				, @LastUpdateDate
				, @ExecutionTime
				, @EstimatedExecutionTime
				, @ShowUpdateInLog
				, @TenantId );
				Select scope_identity()"                ;
                SqlParameter[] parameterArray = new SqlParameter[] {
                    new SqlParameter("@SystemProcessID", entity.SystemProcessId)
                    , new SqlParameter("@Name", entity.Name)
                    , new SqlParameter("@SpringEntryName", entity.SpringEntryName ?? (object)DBNull.Value)
                    , new SqlParameter("@Description", entity.Description ?? (object)DBNull.Value)
                    , new SqlParameter("@Enabled", entity.Enabled)
                    , new SqlParameter("@Continuous", entity.Continuous)
                    , new SqlParameter("@SleepTime", entity.SleepTime)
                    , new SqlParameter("@AutoStart", entity.AutoStart)
                    , new SqlParameter("@Status", entity.Status ?? (object)DBNull.Value)
                    , new SqlParameter("@Message", entity.Message ?? (object)DBNull.Value)
                    , new SqlParameter("@ScheduledTime", entity.ScheduledTime ?? (object)DBNull.Value)
                    , new SqlParameter("@StartRange", entity.StartRange ?? (object)DBNull.Value)
                    , new SqlParameter("@EndRange", entity.EndRange ?? (object)DBNull.Value)
                    , new SqlParameter("@LastSuccessfullyExecuted", entity.LastSuccessfullyExecuted ?? (object)DBNull.Value)
                    , new SqlParameter("@ContinuousDelay", entity.ContinuousDelay)
                    , new SqlParameter("@IsDeleted", entity.IsDeleted)
                    , new SqlParameter("@DisplayOrder", entity.DisplayOrder)
                    , new SqlParameter("@Argument", entity.Argument ?? (object)DBNull.Value)
                    , new SqlParameter("@LastUpdateDate", entity.LastUpdateDate ?? (object)DBNull.Value)
                    , new SqlParameter("@ExecutionTime", entity.ExecutionTime ?? (object)DBNull.Value)
                    , new SqlParameter("@EstimatedExecutionTime", entity.EstimatedExecutionTime ?? (object)DBNull.Value)
                    , new SqlParameter("@ShowUpdateInLog", entity.ShowUpdateInLog ?? (object)DBNull.Value)
                    , new SqlParameter("@TenantId", entity.TenantId ?? (object)DBNull.Value)
                };
                var identity = SqlHelper.ExecuteScalar(this.ConnectionString, CommandType.Text, sql, parameterArray);
                if (identity == DBNull.Value)
                {
                    throw new DataException("Identity column was null as a result of the insert operation.");
                }
                return(GetSystemProcessThread(Convert.ToInt32(identity)));
            }
            return(entity);
        }
Пример #12
0
 public SystemProcessThread UpdateSystemProcessThread(SystemProcessThread entity)
 {
     return(_iSystemProcessThreadRepository.UpdateSystemProcessThread(entity));
 }
Пример #13
0
        void Execute(string threadName, out bool executed)
        {
            // ILog log = MO.Core.ServiceLogManager.GetLogger(threadName);
            executed = false;
            try
            {
                SystemProcessThread systemProcessThread = _OnGetSystemProcessThread(threadName);
                if (systemProcessThread.Continuous && systemProcessThread.Enabled == false)
                {
                    if (systemProcessThread.ScheduledTime.HasValue)
                    {
                        TimeSpan duration = DateTime.UtcNow - DateTime.UtcNow.Date;
                        if (duration.TotalSeconds >= systemProcessThread.ScheduledTime.Value.TotalSeconds && duration.TotalSeconds <= systemProcessThread.ScheduledTime.Value.TotalSeconds + systemProcessThread.SleepTime)
                        {
                            systemProcessThread.Enabled = true;
                            systemProcessThread         = _OnUpdateSystemProcess(systemProcessThread);
                        }
                    }
                    else
                    {
                        if (systemProcessThread.LastSuccessfullyExecuted.HasValue)
                        {
                            TimeSpan duration = DateTime.UtcNow - systemProcessThread.LastSuccessfullyExecuted.Value;
                            if (duration.TotalSeconds >= systemProcessThread.ContinuousDelay)
                            {
                                systemProcessThread.Enabled = true;
                                systemProcessThread         = _OnUpdateSystemProcess(systemProcessThread);
                            }
                        }
                        else
                        {
                            systemProcessThread.Enabled = true;
                            systemProcessThread         = _OnUpdateSystemProcess(systemProcessThread);
                        }
                    }
                }
                if (systemProcessThread.Enabled)
                {
                    try

                    {
                        thread_OnReportEngineState(threadName, GenericServiceThread.EngineStatusList.Running);
                        ISystemProcessThread systemProcess = null;
                        if (systemProcessThread.SpringEntryName == "PerformanceStatisticThread")
                        {
                            systemProcess = new PerformanceStatisticThread();
                        }
                        else if (systemProcessThread.SpringEntryName == "DeleteDataThread")
                        {
                            systemProcess = new DeleteDataThread();
                        }
                        else
                        {
                            systemProcess = IoC.Resolve <ISystemProcessThread>(systemProcessThread.SpringEntryName);
                        }
                        systemProcess.ThreadName = threadName;
                        systemProcess.LastSuccessfullyExecuted = systemProcessThread.LastSuccessfullyExecuted;
                        systemProcess.ScheduledTime            = systemProcessThread.ScheduledTime;
                        systemProcess.StartRange = systemProcessThread.StartRange;
                        systemProcess.EndRange   = systemProcessThread.EndRange;

                        executed = true;
                        try
                        {
                            DateTime dt            = DateTime.UtcNow;
                            string   message       = systemProcess.Execute(systemProcessThread.Argument);
                            TimeSpan executionTime = DateTime.UtcNow.Subtract(dt);
                            systemProcessThread = _OnGetSystemProcessThread(threadName);
                            systemProcessThread.LastSuccessfullyExecuted = DateTime.UtcNow;
                            systemProcessThread.Status        = GenericServiceThread.EngineStatusList.Sleeping.ToString();
                            systemProcessThread.Message       = message;
                            systemProcessThread.ExecutionTime = executionTime.TotalMilliseconds;
                            //  log.Info(string.Format("{0} Worker Thread Completed", threadName));
                            StopThread(systemProcessThread);
                        }
                        catch (SqlException ex)
                        {
                            if (ex.Number == 1205 || ex.Number == -2)
                            {
                            }
                            else
                            {
                                StopThread(systemProcessThread);
                                throw ex;
                            }
                        }
                        catch (Exception ex)
                        {
                            StopThread(systemProcessThread);
                            throw ex;
                        }
                    }
                    catch (Exception ex)
                    {
                        systemProcessThread.Status  = GenericServiceThread.EngineStatusList.Exception.ToString();
                        systemProcessThread.Message = string.Format("{0} at {1}", ex.Message, DateTime.UtcNow.ToISOString());
                        StopThread(systemProcessThread);
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }
Пример #14
0
 public SystemProcessThread InsertSystemProcessThread(SystemProcessThread entity)
 {
     return(_iSystemProcessThreadRepository.InsertSystemProcessThread(entity));
 }
 SystemProcessThread processor_OnUpdateSystemProcess(SystemProcessThread systemProcessThread)
 {
     systemProcessThread.LastUpdateDate = DateTime.UtcNow;
     return(webClient.UpdateSystemProcessThread(systemProcessThread));
 }
Пример #16
0
        public virtual SystemProcessThread SystemProcessThreadFromDataRow(DataRow dr)
        {
            if (dr == null)
            {
                return(null);
            }
            SystemProcessThread entity = new SystemProcessThread();

            if (dr.Table.Columns.Contains("SystemProcessThreadID"))
            {
                entity.SystemProcessThreadId = (System.Int32)dr["SystemProcessThreadID"];
            }
            if (dr.Table.Columns.Contains("SystemProcessID"))
            {
                entity.SystemProcessId = (System.Int32)dr["SystemProcessID"];
            }
            if (dr.Table.Columns.Contains("Name"))
            {
                entity.Name = dr["Name"].ToString();
            }
            if (dr.Table.Columns.Contains("SpringEntryName"))
            {
                entity.SpringEntryName = dr["SpringEntryName"].ToString();
            }
            if (dr.Table.Columns.Contains("Description"))
            {
                entity.Description = dr["Description"].ToString();
            }
            if (dr.Table.Columns.Contains("Enabled"))
            {
                entity.Enabled = (System.Boolean)dr["Enabled"];
            }
            if (dr.Table.Columns.Contains("Continuous"))
            {
                entity.Continuous = (System.Boolean)dr["Continuous"];
            }
            if (dr.Table.Columns.Contains("SleepTime"))
            {
                entity.SleepTime = (System.Int32)dr["SleepTime"];
            }
            if (dr.Table.Columns.Contains("AutoStart"))
            {
                entity.AutoStart = (System.Boolean)dr["AutoStart"];
            }
            if (dr.Table.Columns.Contains("Status"))
            {
                entity.Status = dr["Status"].ToString();
            }
            if (dr.Table.Columns.Contains("Message"))
            {
                entity.Message = dr["Message"].ToString();
            }
            if (dr.Table.Columns.Contains("ScheduledTime"))
            {
                entity.ScheduledTime = dr["ScheduledTime"] == DBNull.Value?(TimeSpan?)null:(TimeSpan?)dr["ScheduledTime"];
            }
            if (dr.Table.Columns.Contains("StartRange"))
            {
                entity.StartRange = dr["StartRange"] == DBNull.Value?(System.Int32?)null : (System.Int32?)dr["StartRange"];
            }
            if (dr.Table.Columns.Contains("EndRange"))
            {
                entity.EndRange = dr["EndRange"] == DBNull.Value?(System.Int32?)null : (System.Int32?)dr["EndRange"];
            }
            if (dr.Table.Columns.Contains("LastSuccessfullyExecuted"))
            {
                entity.LastSuccessfullyExecuted = dr["LastSuccessfullyExecuted"] == DBNull.Value?(System.DateTime?)null : (System.DateTime?)dr["LastSuccessfullyExecuted"];
            }
            if (dr.Table.Columns.Contains("ContinuousDelay"))
            {
                entity.ContinuousDelay = (System.Int32)dr["ContinuousDelay"];
            }
            if (dr.Table.Columns.Contains("IsDeleted"))
            {
                entity.IsDeleted = (System.Boolean)dr["IsDeleted"];
            }
            if (dr.Table.Columns.Contains("DisplayOrder"))
            {
                entity.DisplayOrder = dr["DisplayOrder"].ToString();
            }
            if (dr.Table.Columns.Contains("Argument"))
            {
                entity.Argument = dr["Argument"].ToString();
            }
            if (dr.Table.Columns.Contains("LastUpdateDate"))
            {
                entity.LastUpdateDate = dr["LastUpdateDate"] == DBNull.Value?(System.DateTime?)null : (System.DateTime?)dr["LastUpdateDate"];
            }
            if (dr.Table.Columns.Contains("ExecutionTime"))
            {
                entity.ExecutionTime = dr["ExecutionTime"] == DBNull.Value?(System.Double?)null : (System.Double?)dr["ExecutionTime"];
            }
            if (dr.Table.Columns.Contains("EstimatedExecutionTime"))
            {
                entity.EstimatedExecutionTime = dr["EstimatedExecutionTime"] == DBNull.Value?(System.Double?)null : (System.Double?)dr["EstimatedExecutionTime"];
            }
            if (dr.Table.Columns.Contains("ShowUpdateInLog"))
            {
                entity.ShowUpdateInLog = dr["ShowUpdateInLog"] == DBNull.Value?(System.Boolean?)null : (System.Boolean?)dr["ShowUpdateInLog"];
            }
            if (dr.Table.Columns.Contains("TenantId"))
            {
                entity.TenantId = dr["TenantId"] == DBNull.Value?(System.Int32?)null : (System.Int32?)dr["TenantId"];
            }
            return(entity);
        }
Пример #17
0
 public virtual SystemProcessThread DeleteSystemProcessThread(SystemProcessThread entity)
 {
     this.DeleteSystemProcessThread(entity.SystemProcessThreadId);
     return(entity);
 }
Пример #18
0
 public SystemProcessThread InsertSystemProcessThread(SystemProcessThread entity, string connectionString)
 {
     return(_iSystemProcessThreadRepository.InsertSystemProcessThread(entity, connectionString));
 }
 public override SystemProcessThread UpdateSystemProcessThread(SystemProcessThread entity)
 {
     entity.LastUpdateDate = DateTime.UtcNow;
     return(base.UpdateSystemProcessThread(entity));
 }