Ejemplo n.º 1
0
 /// <summary>
 /// بعد از ايجاد ورك فلو
 /// </summary>
 /// <param name="WorkflowEventArg"></param>
 protected virtual void OnAfterCreateWorkflow(CreateWorkflowEventArgs WorkflowEventArg)
 {
     if (AfterCreateWorkflow != null)
     {
         AfterCreateWorkflow(this, WorkflowEventArg);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// قبل از ايجاد ورك فلو
        /// </summary>
        /// <param name="WorkflowEventArg"></param>
        protected virtual void OnBeforeCreateWorkflow(CreateWorkflowEventArgs WorkflowEventArg)
        {
            if (BeforeCreateWorkflow != null)
            {
                BeforeCreateWorkflow(this, (CreateWorkflowEventArgs)WorkflowEventArg);
            }

            if (WorkflowEventArg.Cancel == true)
            {
                throw new WFUserException(WorkflowEventArg.CancelMessage);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// يك فرآيند جديد را آغاز ميكند
        /// </summary>
        /// <param name="InstanceID">شناسه فرآيند جديد</param>
        /// <param name="WorkflowCode">كدفرآيند</param>
        /// <param name="EntityID">شناسه موجوديت</param>
        /// <param name="ExtraInfo">اطلاعات اضافه</param>
        /// <param name="UserName">نام كاربري ايجاد كننده</param>
        /// <param name="ds">ديتاست</param>
        public void CreateWorkflowInstance(WorkflowInstance wfInstance, string userName, string firstPerformer, string extraInfo, int priorityNo, bool isAuthoforward = false)
        {
            try
            {
                //if (wfs.IsWorkflowCreatedBefore(this.WorkflowID, wfInstance.EntityID))
                //    throw new WFUserException("براي اين موجوديت قبلا ورك فلو ثبت شده است.");

                Workflow wf = wfs.GetWorkflowByID(this.WorkflowID);

                wfInstance.InsertUser = userName;
                wfInstance.InsertDate = DateTime.Now;
                wfInstance.WorkflowID = this.WorkflowID;
                wfInstance.WorkflowInstanceStatusID = (int)WorkflowInstanceStatusEnum.Waiting;
                wfInstance.ExtraInfo = extraInfo;

                if (string.IsNullOrEmpty(wfInstance.WorkflowInstanceTitle))
                {
                    wfInstance.WorkflowInstanceTitle = wf.WorkflowTitle;
                }
                if (string.IsNullOrEmpty(wfInstance.EntityName))
                {
                    wfInstance.EntityName = wf.EntityName;
                }
                if (string.IsNullOrEmpty(wfInstance.EntityTitle))
                {
                    wfInstance.EntityTitle = wf.EntityTitle;
                }
                if (string.IsNullOrEmpty(wfInstance.EntityUrl))
                {
                    wfInstance.EntityUrl = wf.EntityUrl;
                }

                // inserting to database
                var ObjectContext = wfs.ObjectContext;
                var task          = (from o in ObjectContext.Task
                                     where (o.TaskTypeID == 0 && o.WorkflowID == this.WorkflowID) // فعاليت آغازين
                                     select o).First();

                TaskInstance ti = new TaskInstance();
                ti.TaskInstanceID     = Guid.NewGuid();
                ti.PriorityID         = priorityNo;
                ti.WorkflowInstanceID = wfInstance.WorkflowInstanceID;
                ti.TaskID             = task.TaskID;
                ti.TaskCode           = task.TaskCode;
                ti.TaskTitle          = task.TaskTitle;
                if (string.IsNullOrEmpty(firstPerformer) == false)
                {
                    ti.PerformerID = firstPerformer;
                }
                else if (string.IsNullOrEmpty(task.PerformerID) == false)
                {
                    ti.PerformerID = task.PerformerID;
                }
                //else
                //    throw new Exception("PerformerID is not selected");
                ti.EntityName  = wfInstance.EntityName;
                ti.EntityID    = wfInstance.EntityID;
                ti.EntityTitle = wfInstance.EntityTitle;
                ti.EntityUrl   = wfInstance.EntityUrl;
                //ti.EntityDateTime = wfInstance.entitydat
                ti.InsertUser           = userName;
                ti.InsertDate           = DateTime.Now;
                ti.TaskInstanceStatusID = (int)TaskInstanceStatusEnum.Waiting; // در حال انتظار
                ti.NotificationStatusID = (int)NotificationStatusEnum.Waiting; // در حال انتظار
                //ti.ExtraInt = isauthoforward;
                ti.ExtraInt2 = isAuthoforward ? 1 : 0;
                CreateWorkflowEventArgs WorkflowEventArg = new CreateWorkflowEventArgs(wfInstance, ti, userName);
                OnBeforeCreateWorkflow(WorkflowEventArg);

                ObjectContext.WorkflowInstance.AddObject(wfInstance);
                ObjectContext.TaskInstance.AddObject(ti);

                OnAfterCreateWorkflow(WorkflowEventArg);

                ObjectContext.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }