Esempio n. 1
0
        /// <summary>
        /// Update Holiday
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="id"></param>
        /// <param name="status"></param>
        /// <param name="holiday">Holiday</param>
        public void UpdateHoliday(string user, int id, HolidayStatus status, IEnumerable <string> holiday)
        {
            using (var uofw = new FlowTasksUnitOfWork())
            {
                var hday = uofw.Holidays.Find(h => h.HolidayId == id).FirstOrDefault();
                if (hday == null)
                {
                    return;
                }

                hday.Status = status.ToString();

                if (holiday != null)
                {
                    var holidayList = holiday as IList <string> ?? holiday.ToList();

                    hday.Year = GetYearFromDate(holidayList.FirstOrDefault());

                    if (holidayList.Any())
                    {
                        hday.Dates = String.Join(",", holidayList);
                    }
                }

                uofw.Commit();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Add Workflow
        /// </summary>
        /// <param name="workflowCode">WorkflowCode</param>
        /// <param name="serviceUrl">ServiceUrl</param>
        /// <param name="bindingConfiguration">BindingConfiguration</param>
        /// <param name="serviceEndpoint">ServiceEndpoint</param>
        public void AddWorkflow(string workflowCode, string serviceUrl, string bindingConfiguration, string serviceEndpoint)
        {
            using (var uofw = new FlowTasksUnitOfWork())
            {
                var wfc = uofw.WorkflowCodes.FirstOrDefault(wc => wc.Code == workflowCode);
                if (wfc == null)
                {
                    wfc = new WorkflowCode {
                        Code = workflowCode, Description = "Added by Skecth"
                    };
                    uofw.WorkflowCodes.Insert(wfc);
                }
                else
                {
                    var wfcfg = uofw.WorkflowConfigurations.FirstOrDefault(w => w.WorkflowCode.Code == wfc.Code && w.ExpiryDate == null, w => w.WorkflowCode);
                    if (wfcfg != null)
                    {
                        wfcfg.ExpiryDate = DateTime.Now;
                    }
                }

                var newcfg = new WorkflowConfiguration
                {
                    WorkflowCode         = wfc,
                    ServiceUrl           = serviceUrl,
                    BindingConfiguration = bindingConfiguration,
                    ServiceEndpoint      = serviceEndpoint,
                    EffectiveDate        = DateTime.Now
                };

                uofw.WorkflowConfigurations.Insert(newcfg);

                uofw.Commit();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Create Topic
        /// </summary>
        /// <param name="title">Title</param>
        /// <param name="message">Message</param>
        /// <param name="from">From</param>
        /// <param name="to">To</param>
        /// <param name="attachments">Attachments</param>
        public int CreateTopic(string title, string message, string from, string to, IEnumerable <TopicAttachmentInfo> attachments)
        {
            // if to is not empty then this is a direct message
            // otherwise get the to users from followers
            if (string.IsNullOrWhiteSpace(to))
            {
                to = GetBroadcastUsers(from);
            }

            var users       = to + ";" + from; // topic visible to sender (from) as well
            var usersToCopy = ParseUsers.GetListUsersName(_usersService, users);

            using (var uofw = new FlowTasksUnitOfWork())
            {
                var topic = new Core.Topic {
                    Title = title, LastChanged = DateTime.Now
                };
                uofw.Topics.Insert(topic);

                CreateMessage(uofw, topic, true, message, from, to, attachments, usersToCopy);

                uofw.Commit();

                return(topic.TopicId);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Create Reply
        /// </summary>
        /// <param name="topicId">TopicId</param>
        /// <param name="message">Message</param>
        /// <param name="from">From</param>
        /// <param name="to">To</param>
        /// <param name="attachments">Attachments</param>
        public void CreateReply(int topicId, string message, string from, string to, IEnumerable <TopicAttachmentInfo> attachments)
        {
            using (var uofw = new FlowTasksUnitOfWork())
            {
                var topic        = uofw.Topics.First(t => t.TopicId == topicId);
                var topicMessage = uofw.TopicMessages.First(m => m.TopicId == topicId && m.IsTopic);

                if (!string.IsNullOrWhiteSpace(to))
                {
                    to += ";";
                }
                else
                {
                    to = string.Empty;
                }

                if (!to.Contains(topicMessage.To))
                {
                    to += topicMessage.To;
                }
                if (!to.Contains(topicMessage.From))
                {
                    to += ";" + topicMessage.From;
                }

                var usersToCopy = ParseUsers.GetListUsersName(_usersService, to);

                CreateMessage(uofw, topic, false, message, from, to, attachments, usersToCopy);
                topic.LastChanged = DateTime.Now;

                uofw.Commit();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Get Topics For User
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="topicId"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="title"></param>
        /// <param name="status"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="withReplies"></param>
        /// <returns>List of topics</returns>
        public IEnumerable <TopicInfo> GetTopicsForUser(string user, int topicId, DateTime start, DateTime end,
                                                        string title, string status, int pageIndex, int pageSize, bool withReplies)
        {
            var topicInfo = new List <TopicInfo>();

            using (var uofw = new FlowTasksUnitOfWork())
            {
                var userTopics = TopicsForUser(uofw, user, topicId, title, string.Empty, false);

                var skip         = pageIndex * pageSize;
                var topicsinPage = userTopics.OrderByDescending(tu => tu.TopicMessage.Topic.LastChanged).Skip(skip).Take(pageSize).ToList();

                var statusNewStr  = TopicStatusType.New.ToString();
                var statusReadStr = TopicStatusType.Read.ToString();
                var statusRead    = uofw.TopicStatuses.First(s => s.Status == statusReadStr);

                foreach (var tu in topicsinPage)
                {
                    var ti = CreateTopicInfo(tu, uofw, 20, end.AddDays(-1), end, status, withReplies);
                    topicInfo.Add(ti);

                    if (tu.TopicStatus.Status == statusNewStr)
                    {
                        tu.TopicStatus = statusRead;
                    }
                }

                uofw.Commit();
            }

            return(topicInfo);
        }
Esempio n. 6
0
        /// <summary>
        /// Give Back Task
        /// </summary>
        /// <param name="taskOid">Task Oid</param>
        public void GiveBackTask(Guid taskOid)
        {
            TaskDefinition tkd;

            using (var uofw = new FlowTasksUnitOfWork())
            {
                tkd = uofw.TaskDefinitions.First(t => t.TaskOid == taskOid, t => t.WorkflowDefinition);

                tkd.HandedOverStatus = HandOverStatus.None.ToString();

                var tku = uofw.TaskUsers.FirstOrDefault(u => u.TaskDefinitionId == tkd.TaskDefinitionId && u.User == tkd.AcceptedBy);
                if (tku != null)
                {
                    tku.InUse = false;
                }
                else
                {
                    var tkuh = uofw.TaskUserHandOvers.FirstOrDefault(u => u.TaskDefinitionId == tkd.TaskDefinitionId && u.User == tkd.AcceptedBy);
                    if (tkuh != null)
                    {
                        tkuh.InUse = false;
                    }
                }

                tkd.AcceptedBy = string.Empty;
                tkd.AcceptedOn = null;

                uofw.Commit();
            }

            _tracer.Trace(tkd.WorkflowDefinition.WorkflowOid, ActionTrace.TaskGaveBack, tkd.TaskCode,
                          string.Format(Properties.Resources.TK_GAVEBACK, tkd.TaskCode), TraceEventType.Activity);
        }
Esempio n. 7
0
        /// <summary>
        /// Update Workflow Parameters
        /// </summary>
        /// <param name="workflowOid">WorkflowOid</param>
        /// <param name="taskOid">TaskOid</param>
        /// <param name="properties">Properties</param>
        public void UpdateWorkflowParameters(Guid workflowOid, Guid taskOid, IEnumerable <PropertyInfo> properties)
        {
            using (var uofw = new FlowTasksUnitOfWork())
            {
                WorkflowDefinition wfd = null;
                if (workflowOid != Guid.Empty)
                {
                    wfd = uofw.WorkflowDefinitions.FirstOrDefault(w => w.WorkflowOid == workflowOid);
                }
                else if (taskOid != Guid.Empty)
                {
                    wfd = uofw.TaskDefinitions.Find(t => t.TaskOid == taskOid, t => t.WorkflowDefinition).Select(t => t.WorkflowDefinition).FirstOrDefault();
                }

                if (wfd != null)
                {
                    var parms         = uofw.WorkflowInParameters.Find(p => p.WorkflowDefinitionId == wfd.WorkflowDefinitionId, p => p.Property);
                    var propertyInfos = properties as IList <PropertyInfo> ?? properties.ToList();

                    foreach (var p in parms)
                    {
                        foreach (var newp in propertyInfos)
                        {
                            if (p.Property.Name == newp.Name)
                            {
                                p.Property.Value = newp.Value;
                            }
                        }
                    }

                    uofw.Commit();
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Trace
        /// </summary>
        /// <param name="workflowOid">Workflow Oid</param>
        /// <param name="action">Action</param>
        /// <param name="code">Code</param>
        /// <param name="result">Result</param>
        /// <param name="user">User</param>
        /// <param name="msg">Msg</param>
        /// <param name="type">Type</param>
        public void Trace(Guid workflowOid, ActionTrace action, string code, string result, string user, string msg, TraceEventType type)
        {
            using (var uofw = new FlowTasksUnitOfWork())
            {
                var wfd = uofw.WorkflowDefinitions.First(w => w.WorkflowOid == workflowOid);

                var eventType = type.ToString();
                var tre       = uofw.TraceEvents.First(e => e.Type == eventType);
                var t         = new WorkflowTrace
                {
                    Message            = msg.Substring(0, Math.Min(msg.Length, 500)),
                    TraceEvent         = tre,
                    User               = string.IsNullOrWhiteSpace(user) ? string.Empty : user,
                    When               = DateTime.Now,
                    WorkflowDefinition = wfd,
                    Action             = action.ToString(),
                    Code               = code,
                    Result             = result
                };

                uofw.WorkflowTraces.Insert(t);

                uofw.Commit();
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Complete Notification
 /// </summary>
 /// <param name="taskOid">Task Oid</param>
 public void CompleteNotification(Guid taskOid)
 {
     using (var uofw = new FlowTasksUnitOfWork())
     {
         var tkd = uofw.TaskDefinitions.First(t => t.TaskOid == taskOid, t => t.WorkflowDefinition);
         uofw.TaskDefinitions.Delete(tkd);
         uofw.Commit();
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Apply Holiday
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="type"></param>
        /// <param name="holiday">Holiday</param>
        /// <returns>holiday id</returns>
        public int ApplyHoliday(string user, int type, IEnumerable <string> holiday)
        {
            using (var uofw = new FlowTasksUnitOfWork())
            {
                var holidayList = holiday as IList <string> ?? holiday.ToList();
                var h           = new Core.Holiday {
                    Status = HolidayStatus.S.ToString(), HolidayTypeId = type, User = user, Year = GetYearFromDate(holidayList.FirstOrDefault()), Dates = String.Join(",", holidayList)
                };
                uofw.Holidays.Insert(h);

                uofw.Commit();

                return(h.HolidayId);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Create Task
        /// </summary>
        /// <param name="workflowOid">Workflow Oid</param>
        /// <param name="taskInfo">Task Info</param>
        /// <param name="properties">Properties</param>
        public void CreateTask(Guid workflowOid, TaskInfo taskInfo, IEnumerable <PropertyInfo> properties)
        {
            using (var uofw = new FlowTasksUnitOfWork())
            {
                WorkflowDefinition wfd = uofw.WorkflowDefinitions.First(d => d.WorkflowOid == workflowOid, d => d.WorkflowCode);

                // Check if there is a configuration that over writes initialization values
                ReadConfiguration(taskInfo, wfd.WorkflowCode);

                TaskDefinition tkd = new TaskDefinition
                {
                    DefaultResult      = taskInfo.DefaultResult,
                    UiCode             = taskInfo.UiCode,
                    ExpiryDate         = GetExpiryDatetime(taskInfo.ExpiresWhen, taskInfo.ExpiresIn),
                    TaskCode           = taskInfo.TaskCode,
                    TaskOid            = taskInfo.TaskOid,
                    WorkflowDefinition = wfd,
                    TaskCorrelationId  = taskInfo.TaskCorrelationId
                };

                SetParameters(uofw, wfd, tkd, properties);

                uofw.TaskDefinitions.Insert(tkd);

                // TODO: why do I need 2 commits?
                uofw.Commit();

                InitializePlaceHolders(uofw, tkd, taskInfo);
                InitializeUsers(uofw, tkd, taskInfo, wfd.Domain);

                uofw.Commit();
            }

            _tracer.Trace(workflowOid, ActionTrace.TaskCreated, taskInfo.TaskCode,
                          string.Format(Properties.Resources.TK_STARTED, taskInfo.TaskCode), TraceEventType.Activity);
        }
Esempio n. 12
0
        /// <summary>
        /// Hand Over Task To User
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="taskOid">Task Oid</param>
        public void HandOverTaskTo(string user, Guid taskOid)
        {
            using (var uofw = new FlowTasksUnitOfWork())
            {
                var tkd = uofw.TaskDefinitions.First(t => t.TaskOid == taskOid);

                var tku = uofw.TaskUserHandOvers.First(u => u.TaskDefinitionId == tkd.TaskDefinitionId && u.User == user);

                tkd.HandedOverStatus = GetNextStatus(tkd.HandedOverStatus);
                tkd.AcceptedBy       = string.Empty;
                tkd.AcceptedOn       = null;
                tku.InUse            = true;

                uofw.Commit();
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Remove Holiday
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="id">Id</param>
        public bool RemoveHoliday(string user, int id)
        {
            using (var uofw = new FlowTasksUnitOfWork())
            {
                var holiday = uofw.Holidays.Find(h => h.HolidayId == id).FirstOrDefault();
                if (holiday != null)
                {
                    uofw.Holidays.Delete(holiday);
                    uofw.Commit();

                    return(true);
                }
            }

            return(false);
        }
Esempio n. 14
0
        /// <summary>
        /// Get Replies For User
        /// </summary>
        /// <param name="topicId">TopicId</param>
        /// <param name="user">User</param>
        /// <param name="start">Start</param>
        /// <param name="end">End</param>
        /// <param name="showType"></param>
        /// <param name="hasOldReplies"></param>
        /// <returns>List of TopicMessageInfo</returns>
        public IEnumerable <TopicMessageInfo> GetRepliesForUser(int topicId, string user, DateTime start, DateTime end, RepliesShowType showType, out bool hasOldReplies)
        {
            const int recentReplies = 20;

            var replies = new List <TopicMessageInfo>();

            using (var uofw = new FlowTasksUnitOfWork())
            {
                //var userTopics = uofw.TopicUsers.Find(tu => !tu.TopicMessage.IsTopic && tu.TopicMessage.TopicId == topicId && tu.User == user
                //    && tu.TopicMessage.When >= start && tu.TopicMessage.When <= end, tu => tu.TopicMessage, tu => tu.TopicMessage.Topic, tu => tu.TopicStatus)
                //    .OrderByDescending(tu => tu.TopicMessageId);

                var userTopics = uofw.TopicUsers.Find(tu => !tu.TopicMessage.IsTopic && tu.TopicMessage.TopicId == topicId && tu.User == user, tu => tu.TopicMessage.Topic, tu => tu.TopicStatus)
                                 .OrderBy(tu => tu.TopicMessageId).ToList();

                var statusNewStr  = TopicStatusType.New.ToString();
                var statusReadStr = TopicStatusType.Read.ToString();
                var statusRead    = uofw.TopicStatuses.First(s => s.Status == statusReadStr);

                var countReplies = 0;
                var users        = new Dictionary <string, string>();
                foreach (var r in userTopics)
                {
                    if (showType == RepliesShowType.All || (showType == RepliesShowType.Recent && countReplies < recentReplies) ||
                        (showType == RepliesShowType.Old && countReplies >= recentReplies))
                    {
                        replies.Add(CreateMessageInfo(r, uofw, users));
                    }
                    if (r.TopicStatus.Status == statusNewStr)
                    {
                        r.TopicStatus = statusRead;
                    }
                    countReplies += 1;
                }
                uofw.Commit();

                hasOldReplies = countReplies > recentReplies;
            }

            return(replies);
        }
Esempio n. 15
0
        /// <summary>
        /// Create a workflow
        /// </summary>
        /// <param name="workflowOid">Workflow Oid</param>
        /// <param name="parentWorkflowOid">Parent workflow oid</param>
        /// <param name="workflowCode">Workflow Code</param>
        /// <param name="domain">Workflow domain</param>
        /// <param name="properties">Workflow list of properties</param>
        public void CreateWorkflow(Guid workflowOid, Guid parentWorkflowOid, string workflowCode, string domain, IEnumerable <PropertyInfo> properties)
        {
            using (var uofw = new FlowTasksUnitOfWork())
            {
                var wfc = uofw.WorkflowCodes.First(c => c.Code == workflowCode);

                var status = WorkflowStatusType.InProgress.ToString();
                var wfs    = uofw.WorkflowStatuses.First(s => s.Status == status);

                WorkflowDefinition parentWfd = null;
                if (parentWorkflowOid != Guid.Empty)
                {
                    parentWfd = uofw.WorkflowDefinitions.First(w => w.WorkflowOid == parentWorkflowOid);
                }

                if (string.IsNullOrWhiteSpace(domain))
                {
                    domain = Defaults.CommonWorkGroup;
                }

                var wfd = new WorkflowDefinition
                {
                    WorkflowOid              = workflowOid,
                    Domain                   = domain,
                    WorkflowCode             = wfc,
                    StartedOn                = DateTime.Now,
                    WorkflowStatus           = wfs,
                    WorkflowParentDefinition = parentWfd
                };
                uofw.WorkflowDefinitions.Insert(wfd);

                // Add "default" properties based on the specified domain
                AddProperties(uofw, domain, wfc, wfd, properties);

                uofw.Commit();
            }

            _tracer.Trace(workflowOid, ActionTrace.WorkflowCreated, workflowCode,
                          Properties.Resources.WF_STARTED, TraceEventType.Activity);
        }
Esempio n. 16
0
        /// <summary>
        /// Assign Task To User
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="taskOid">Task Oid</param>
        public void AssignTaskTo(string user, Guid taskOid)
        {
            TaskDefinition   tkd;
            TaskUserHandOver tkuh = null;

            using (var uofw = new FlowTasksUnitOfWork())
            {
                tkd = uofw.TaskDefinitions.First(t => t.TaskOid == taskOid, t => t.WorkflowDefinition);

                TaskUser tku = uofw.TaskUsers.FirstOrDefault(u => u.TaskDefinitionId == tkd.TaskDefinitionId && u.User == user);
                if (tku == null)
                {
                    tkuh = uofw.TaskUserHandOvers.First(u => u.TaskDefinitionId == tkd.TaskDefinitionId && u.User == user);
                }

                // If task already assigned to user don't do anything.
                if (!string.IsNullOrWhiteSpace(tkd.AcceptedBy) &&
                    tkd.AcceptedBy == (tku != null ? tku.User : tkuh.User))
                {
                    return;
                }

                tkd.AcceptedOn = DateTime.Now;
                tkd.AcceptedBy = (tku != null ? tku.User : tkuh.User);
                if (tku != null)
                {
                    tku.InUse = true;
                }
                else
                {
                    tkuh.InUse = true;
                }

                uofw.Commit();
            }

            _tracer.Trace(tkd.WorkflowDefinition.WorkflowOid, ActionTrace.TaskAssigned, tkd.TaskCode, string.Empty, tkd.AcceptedBy,
                          string.Format(Properties.Resources.TK_ASSIGNED, tkd.TaskCode, tkd.AcceptedBy), TraceEventType.Activity);
        }
Esempio n. 17
0
        /// <summary>
        /// Sketch Workflow
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="xamlxOid">XamlxOid</param>
        /// <param name="changedBy">ChangedBy</param>
        /// <param name="status">Status</param>
        public void SketchWorkflow(string name, Guid xamlxOid, string changedBy, SketchStatusType status)
        {
            var sketchStatusStr = status.ToString();

            using (var uofw = new FlowTasksUnitOfWork())
            {
                var sketchStatus = uofw.SketchStatuses.FirstOrDefault(ss => ss.Status == sketchStatusStr);

                var sc = uofw.SketchConfigurations.FirstOrDefault(s => s.Name == name);
                if (sc == null)
                {
                    sc = new SketchConfiguration {
                        Name = name, XamlxOid = xamlxOid, ChangedBy = changedBy, LastSavedOn = DateTime.Now
                    };
                    if (sketchStatus != null)
                    {
                        sc.SketchStatus = sketchStatus;
                    }

                    uofw.SketchConfigurations.Insert(sc);
                }
                else
                {
                    if (sketchStatus != null)
                    {
                        sc.SketchStatus = sketchStatus;
                    }
                    sc.LastSavedOn = DateTime.Now;
                    if (xamlxOid != Guid.Empty)
                    {
                        sc.XamlxOid = xamlxOid;
                    }
                    sc.ChangedBy = changedBy;
                }

                uofw.Commit();
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Complete Task
        /// </summary>
        /// <param name="taskOid">Task Oid</param>
        /// <param name="result">Result</param>
        /// <param name="user">User</param>
        public void CompleteTask(Guid taskOid, string result, string user)
        {
            using (var uofw = new FlowTasksUnitOfWork())
            {
                // Leave notifications
                if (IsTaskNotification(taskOid))
                {
                    return;
                }

                TaskDefinition tkd = uofw.TaskDefinitions.First(t => t.TaskOid == taskOid, t => t.WorkflowDefinition);

                var wfc = uofw.WorkflowDefinitions.First(c => c.WorkflowDefinitionId == tkd.WorkflowDefinitionId, c => c.WorkflowCode);

                var tkp = uofw.TaskInParameters.Find(tp => tp.TaskDefinition.TaskOid == taskOid, tp => tp.Property, tp => tp.TaskDefinition)
                          .Select(tp => tp.Property).ToList();

                var tkwfProp = uofw.WorkflowProperties.Find(p => p.WorkflowCode.Code == wfc.WorkflowCode.Code, p => p.Property)
                               .Select(p => p.Property).ToList();

                var tkwfInParam = uofw.WorkflowInParameters.Find(p => p.WorkflowDefinitionId == tkd.WorkflowDefinitionId, p => p.Property)
                                  .Select(p => p.Property).ToList();

                var tkwfOutParam = uofw.WorkflowOutParameters.Find(p => p.WorkflowDefinitionId == tkd.WorkflowDefinitionId, p => p.Property)
                                   .Select(p => p.Property).ToList();

                DeleteProperties(uofw, tkp, tkwfProp, tkwfInParam, tkwfOutParam);

                _tracer.Trace(tkd.WorkflowDefinition.WorkflowOid,
                              ActionTrace.TaskCompleted, tkd.TaskCode, result, user,
                              string.Format(Properties.Resources.TK_COMPLETED, tkd.TaskCode, result),
                              TraceEventType.Activity);

                uofw.TaskDefinitions.Delete(tkd);
                uofw.Commit();
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Delete workflow from the system
        /// </summary>
        /// <param name="workflowOid">Workflow oid</param>
        public void DeleteWorkflow(Guid workflowOid)
        {
            using (var uofw = new FlowTasksUnitOfWork())
            {
                var wfd = uofw.WorkflowDefinitions.FirstOrDefault(w => w.WorkflowOid == workflowOid);

                if (wfd == null)
                {
                    return;
                }

                // Delete all children first
                var wfdChilds = uofw.WorkflowDefinitions.Find(w => w.WorkflowParentDefinitionId == wfd.WorkflowDefinitionId);

                foreach (var w in wfdChilds)
                {
                    DeleteWorkflow(uofw, w);
                }

                DeleteWorkflow(uofw, wfd);

                uofw.Commit();
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Complete Workflow
        /// </summary>
        /// <param name="workflowOid">Workflow Oid</param>
        /// <param name="workflowStatusType">Workflow status</param>
        /// <param name="result">Result</param>
        /// <param name="message">Custom message</param>
        public void CompleteWorkflow(Guid workflowOid, WorkflowStatusType workflowStatusType, string result, string message)
        {
            WorkflowDefinition wfd;

            using (var uofw = new FlowTasksUnitOfWork())
            {
                wfd = uofw.WorkflowDefinitions.First(w => w.WorkflowOid == workflowOid, w => w.WorkflowStatus,
                                                     w => w.WorkflowCode);

                var status = workflowStatusType.ToString();
                var wfs    = uofw.WorkflowStatuses.First(s => s.Status == status);

                // Only workflow in progress
                if (wfd.WorkflowStatus.Status != WorkflowStatusType.InProgress.ToString())
                {
                    return;
                }

                // Only complete the children if status is terminated or aborted ie user intervention
                if (workflowStatusType != WorkflowStatusType.Completed)
                {
                    var wfdChilds = uofw.WorkflowDefinitions.Find(w => w.WorkflowParentDefinitionId == wfd.WorkflowDefinitionId);

                    foreach (var child in wfdChilds)
                    {
                        CompleteWorkflow(child.WorkflowOid, workflowStatusType, result, string.Empty);
                    }
                }

                var tkd = uofw.TaskDefinitions.Find(t => t.WorkflowDefinition.WorkflowOid == workflowOid);
                foreach (var t in tkd)
                {
                    _task.CompleteTask(t.TaskOid, Properties.Resources.TASK_TERMINATED, string.Empty);
                }

#if DELETE_IN_PARAMETERS
                /*
                 *  if you use this you will not been able to restart a wf and bring it to
                 *  the existing step
                 */
                var wfInParm = uofw.WorkflowInParameters.Find(wip => wip.WorkflowDefinitionId == wfd.WorkflowDefinitionId, p => p.Property)
                               .Select(wip => wip.Property).ToList();

                var wfProp = uofw.WorkflowProperties.Find(p => p.WorkflowCode.Code == wfd.WorkflowCode.Code, p => p.Property)
                             .Select(p => p.Property).ToList();

                var wfOutParam = uofw.WorkflowOutParameters.Find(p => p.WorkflowDefinitionId == wfd.WorkflowDefinitionId, p => p.Property)
                                 .Select(p => p.Property).ToList();

                // Delete all the property a part from the ones in :
                // WorkflowProperties and WorkflowOutParameters
                // I need those properties when I want to manualy restart
                // the workflow
                foreach (var p in wfInParm)
                {
                    if (!wfProp.Contains(p) && !wfOutParam.Contains(p))
                    {
                        uofw.Properties.Delete(p);
                    }
                }
#endif
                wfd.WorkflowStatus = wfs;
                wfd.CompletedOn    = DateTime.Now;

                uofw.Commit();
            }

            _tracer.Trace(workflowOid, ActionTrace.WorkflowCompleted, wfd.WorkflowCode.Code,
                          result, string.Empty, string.Format(Properties.Resources.WF_COMPLETED,
                                                              workflowStatusType.ToString() + (string.IsNullOrWhiteSpace(message) ? string.Empty : " - " + message)), TraceEventType.Activity);
        }
Esempio n. 21
0
 public void MyTestCleanup()
 {
     uow.Commit();
     uow.Dispose();
 }