Beispiel #1
0
        internal StatusCode Init(string parameter, string comment)
        {
            StatusCode retVal;

            try
            {
                //User Check
                retVal = CheckStatusAndOwner(STATUS_INIT);
                if (!retVal.IsSucceeded)
                {
                    return(retVal);
                }
                TaskDataParameter = parameter;
                if (TaskDataID != -1)
                {
                    return
                        (new CommonStatusCode(CommonStatusCode.TASK_ALREADY_GENERATED, new object[] { ApplicationID, TaskInfoID, TaskDataParameter, TaskDataID }, Config, ApplicationID));
                }
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    retVal = createNewTask(comment, null);
                    if (!retVal.IsSucceeded)
                    {
                        return(retVal);
                    }
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                retVal =
                    new CommonStatusCode(CommonStatusCode.TASK_LIBRARY_INTERNAL_ERROR, new object[] { ApplicationID, TaskInfoID, TaskDataParameter, TaskDataID }, ex, Config, ApplicationID);
            }
            return(retVal);
        }
Beispiel #2
0
 public StatusCode ExcecuteDelegateTask(string parameter, string comment)
 {
     lock (LockObject)
     {
         StatusCode retVal;
         try
         {
             //Just Lock the existing Instance * No Commit!!
             using (new TransactionScope(TransactionScopeOption.RequiresNew, _lock_timespan))
             {
                 lockInstanceAndRefreshCurrentTaskData();
                 retVal = CheckStatusAndOwner(STATUS_EXECUTE);
                 if (!retVal.IsSucceeded)
                 {
                     return(retVal);
                 }
                 retVal = executionDecision(parameter, comment);
             }
         }
         catch (Exception ex)
         {
             retVal =
                 new CommonStatusCode(CommonStatusCode.TASK_LIBRARY_INTERNAL_ERROR, new object[] { ApplicationID, TaskInfoID, TaskDataParameter, TaskDataID }, ex, Config, ApplicationID);
         }
         return(retVal);
     }
 }
Beispiel #3
0
        private void ErrorProc(StatusCode retVal)
        {
            StatusCode retVal2 = StatusCode.SUCCEED_STATUS;

            try
            {
                retVal2 = ExecutionUnit.OnError();
            }
            catch (Exception ex)
            {
                retVal2 =
                    new CommonStatusCode(CommonStatusCode.UNKNOWN_THREAD_ERROR, ex, Manager.Config, Manager.ApplicationId);
            }
            try
            {
                Manager.RegisterError(retVal);
            }
            catch (Exception ex)
            {
                new CommonStatusCode(CommonStatusCode.UNKNOWN_THREAD_MANAGER_ERROR, ex, Manager.Config, Manager.ApplicationId);
            }

            if (retVal2 != StatusCode.SUCCEED_STATUS)
            {
                try
                {
                    Manager.RegisterError(retVal2);
                }
                catch (Exception ex)
                {
                    new CommonStatusCode(CommonStatusCode.UNKNOWN_THREAD_MANAGER_ERROR, ex, Manager.Config, Manager.ApplicationId);
                }
            }
        }
Beispiel #4
0
        public StatusCode Reject(string parameter, string comment, long latest_instance_id)
        {
            lock (LockObject)
            {
                StatusCode retVal;
                LatestInstanceID = latest_instance_id;
                try
                {
                    //Just Lock the existing Instance * No Commit!!
                    using (new TransactionScope(TransactionScopeOption.RequiresNew, _lock_timespan))
                    {
                        lockInstanceAndRefreshCurrentTaskData();
                        retVal = CheckStatusAndOwner(STATUS_REJECT);
                        if (!retVal.IsSucceeded)
                        {
                            return(retVal);
                        }
                        //Create New Instance
                        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
                        {
                            retVal =
                                createNewInstance(parameter, STATUS_REJECT, null,
                                                  null,
                                                  comment);
                            scope.Complete();
                        }
                    }
                    if (!retVal.IsSucceeded)
                    {
                        return(retVal);
                    }


                    using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
                    {
                        retVal = OnReject(parameter, comment);
                        if (!retVal.IsSucceeded)
                        {
                            return(retVal);
                        }
                        if (IsEmailNecessary(STATUS_REJECT))
                        {
                            retVal = sendProposalMailFromRequestedStatus(ProposalRecipients, comment, STATUS_REJECT);
                            if (!retVal.IsSucceeded)
                            {
                                return(retVal);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    retVal =
                        new CommonStatusCode(CommonStatusCode.TASK_LIBRARY_INTERNAL_ERROR, new object[] { ApplicationID, TaskInfoID, TaskDataParameter, TaskDataID }, ex, Config, ApplicationID);
                }
                return(retVal);
            }
        }
Beispiel #5
0
        private StatusCode doExec(string parameter)
        {
            StatusCode retVal;

            try
            {
                try
                {
                    using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
                    {
                        retVal = OnExec(parameter ?? TaskDataParameter);
                    }
                    if (retVal.IsSucceeded)
                    {
                        Notify("[Task] " + this.CurrentTaskInfo.description + " Done");
                    }
                }
                catch (Exception ex)
                {
                    retVal =
                        new CommonStatusCode(CommonStatusCode.TASK_EXECUTION_FAILED, new object[] { ApplicationID, TaskInfoID, TaskDataParameter, TaskDataID }, ex, Config, ApplicationID);
                }
                //Create new Instance
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    if (!retVal.IsSucceeded)
                    {
                        StatusCode retVal2 = createNewInstance(parameter, STATUS_FAIL, null, retVal, null);
                        if (retVal2.IsSucceeded)
                        {
                            retVal = retVal2;
                        }
                    }
                    else
                    {
                        retVal =
                            createNewInstance(parameter, STATUS_COMPLETE,
                                              null, null, null);
                    }
                    scope.Complete();
                }
            }
            catch (Exception ex2)
            {
                retVal =
                    new CommonStatusCode(CommonStatusCode.TASK_LIBRARY_INTERNAL_ERROR, new object[] { ApplicationID, TaskInfoID, TaskDataParameter, TaskDataID }, ex2, Config, ApplicationID);
            }
            TaskFinished?.Invoke(this, null);
            return(retVal);
        }
Beispiel #6
0
        private StatusCode internalInit(List <Models.Service> lstService, List <Models.ServiceType> lstType)
        {
            StatusCode retVal = StatusCode.SUCCEED_STATUS;

            //foreach (Data.CommonData.server_service_cdtblRow r in commonData.server_service_cdtbl.Rows)
            foreach (Models.Service service in lstService)
            {
                try
                {
                    Type               found_type     = null;
                    Assembly           found_assembly = null;
                    Models.ServiceType serviceType    = lstType.Where(st => st.id == service.service_type_id).FirstOrDefault();
                    string             assembly_name  = serviceType.assembly_name;
                    string             full_name      = serviceType.class_name;
                    if (string.IsNullOrEmpty(assembly_name) == false)
                    {
                        try
                        {
                            found_assembly = AppDomain.CurrentDomain.Load(assembly_name);
                        }
                        catch (Exception) { }
                    }
                    if (found_assembly == null)
                    {
                        foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                        {
                            found_assembly = assembly;
                            found_type     = assembly.GetType(full_name);
                            if (found_type != null)
                            {
                                break;
                            }
                        }
                    }

                    IService svc = (IService)found_assembly.CreateInstance(full_name);
                    svc.Init(Config, Access.JsonAccess.Deserialize <Models.ParameterSet>(service.parameter), service);
                    ServiceManager.lstService.Add(svc);
                }
                catch (Exception ex)
                {
                    retVal = new CommonStatusCode(CommonStatusCode.SERVICE_LOAD_ERROR, new object[] { service.id }, ex, Config, ApplicationID);
                }
            }

            return(retVal);
        }
Beispiel #7
0
 /// <summary>
 /// Writes a status message to the output stream.
 /// </summary>
 /// <param name="code">Status code.</param>
 /// <param name="status">Status message.</param>
 protected void WriteOutputStatus(CommonStatusCode code, string status)
 {
     WriteOutputStatus((int)code, status);
 }
Beispiel #8
0
        internal void ExecThreadItem()
        {
            StatusCode     retVal         = StatusCode.SUCCEED_STATUS;
            PoolItemStatus current_status = Status;

            while (current_status == PoolItemStatus.Active || current_status == PoolItemStatus.UnitAttached)
            {
                //System.Threading.Thread.Sleep(0);
                isReadyForEvent = true;
                auto_event.WaitOne();
                isReadyForEvent = false;
                if (ExecutionUnit != null)
                {
                    retVal = StatusCode.SUCCEED_STATUS;
                    ThreadPoolItemEventArg eventArg = new ThreadPoolItemEventArg(ExecutionUnit);

                    Status = PoolItemStatus.Running;
                    //new CommonStatusCode(CommonStatusCode.ITEM_STARTED, arg, Manager.Config, Manager.ApplicationId);
                    if (UnitStarted != null)
                    {
                        UnitStarted(this, eventArg);
                    }
                    try
                    {
                        retVal = ExecutionUnit.OnStart();
                    }
                    catch (Exception ex)
                    {
                        retVal =
                            new CommonStatusCode(CommonStatusCode.UNKNOWN_THREAD_ERROR, ex, Manager.Config, Manager.ApplicationId);
                    }

                    if (retVal != StatusCode.SUCCEED_STATUS)
                    {
                        ErrorProc(retVal);
                    }
                    else
                    {
                        try
                        {
                            retVal = ExecutionUnit.OnExec();
                        }
                        catch (Exception ex)
                        {
                            retVal =
                                new CommonStatusCode(CommonStatusCode.UNKNOWN_THREAD_ERROR, ex, Manager.Config, Manager.ApplicationId);
                        }
                        if (retVal != StatusCode.SUCCEED_STATUS)
                        {
                            ErrorProc(retVal);
                        }
                        else
                        {
                            try
                            {
                                retVal = ExecutionUnit.OnEnd();
                            }
                            catch (Exception ex)
                            {
                                retVal =
                                    new CommonStatusCode(CommonStatusCode.UNKNOWN_THREAD_ERROR, ex, Manager.Config, Manager.ApplicationId);
                            }
                            if (retVal != StatusCode.SUCCEED_STATUS)
                            {
                                ErrorProc(retVal);
                            }
                        }
                    }
                    //new CommonStatusCode(CommonStatusCode.ITEM_FINISHED, arg, Manager.Config, Manager.ApplicationId);
                    ExecutionUnit = null;
                    Status        = PoolItemStatus.Active;

                    if (UnitFinished != null)
                    {
                        UnitFinished(this, eventArg);
                    }
                }
                else
                {
                    //object[] args= new object[2];
                    //args[0] = ItemId;
                    //args[1] = current_status;
                    //new CommonStatusCode(CommonStatusCode.ITEM_TRIGGERED_WITH_INVALID_STATUS, args, Manager.Config, Manager.ApplicationId);
                }
                current_status = Status;
                System.Threading.Thread.Sleep(0);
            }
        }
 /// <summary>
 /// Writes a status message to the output stream.
 /// </summary>
 /// <param name="code">Status code.</param>
 /// <param name="status">Status message.</param>
 protected void WriteOutputStatus(CommonStatusCode code, string status)
 {
     WriteOutputStatus((int)code, status);
 }