Пример #1
0
 private static void RenderProperties(TextWriter writer, WorkItem item)
 {
     foreach (var keyValue in item.Properties)
     {
         writer.Write(",\"{0}\":\"{1}\"", Encode(keyValue.Key), Encode(keyValue.Value));
     }
 }
Пример #2
0
        public void CreateWorkItem(WorkItem newWorkItem)
        {
            var creator = new WorkItemCreator(WorkflowRepository, TimeSource);

            var timeStamp = TimeSource.GetTime();
            creator.CreateWorkItem(newWorkItem.UpdateTimestamp(timeStamp).UpdateLastMoved(timeStamp));
        }
Пример #3
0
        private static string GenerateWorkItemClass(WorkItem item)
        {
            var classes = new List<string> {"workitem"};
            classes.AddRange(item.Classes);

            return classes.Join(' ');
        }
        public void Init()
        {
            _tx = new TransactionScope(TransactionScopeOption.Required);

            _repository = new AdoWorkItemRepository(_connectionString);

            _wi = WorkItem.New("1", "/path/subpath");
        }
        public void DeleteWorkItem(WorkItem workItem)
        {
            var request = (HttpWebRequest)WebRequest.Create(_site + workItem.Path + "/" + workItem.Id);
            request.ContentType = "text/csv";
            request.Method = "delete";

            ((IDisposable)request.GetResponse()).Dispose();
        }
 public void CreateWorkItem(WorkItem newWorkItem)
 {
     using(WorkflowRepository.BeginTransaction())
     {
         Create(newWorkItem);
         WorkflowRepository.CommitTransaction();
     }
 }
 public void CreateWorkItem(WorkItem workItem)
 {
     using(var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         Create(connection,workItem);
     }
 }
Пример #8
0
 private static string GetAge(WorkItem workItem)
 {
     if(workItem.Properties.ContainsKey(_ageKey))
     {
         return workItem.Properties[_ageKey];
     }
     return null;
 }
Пример #9
0
 public void MoveWorkItem(WorkItem workItem, WorkStep toStep)
 {
     using(WorkflowRepository.BeginTransaction())
     {
         Move(workItem, toStep);
         WorkflowRepository.CommitTransaction();
     }
 }
Пример #10
0
        private static void AdjustStatus(SqlConnection connection, WorkItem workItem, string query)
        {
            var cmd = new SqlCommand(query, connection);

            cmd.Parameters.Add(new SqlParameter("@Id", workItem.Id));
            cmd.Parameters.Add(new SqlParameter("@Path", workItem.Path));

            cmd.ExecuteNonQuery();
        }
Пример #11
0
 private static WorkItem ParseClasses(XmlNode workItemNode, WorkItem workItem)
 {
     var workItemClasses = SelectNodeValueOrDefault(workItemNode,"@classes",null);
     if(!String.IsNullOrEmpty(workItemClasses))
     {
         workItem = workItem.UpdateClasses(workItemClasses.Split(' '));
     }
     return workItem;
 }
Пример #12
0
 private static WorkItem ParseOrdinal(XmlNode workItemNode, WorkItem workItem)
 {
     var ordinal = SelectNodeValueOrDefault(workItemNode, "@ordinal", null);
     if(!String.IsNullOrEmpty(ordinal))
     {
         workItem = workItem.UpdateOrdinal(XmlConvert.ToInt32(ordinal));
     }
     return workItem;
 }
Пример #13
0
 private static WorkItem ParseTimestamp(XmlNode workItemNode, WorkItem workItem)
 {
     var lastUpdatedValue = SelectNodeValueOrDefault(workItemNode, "@timestamp", null);
     if(!String.IsNullOrEmpty(lastUpdatedValue))
     {
         var lastUpdated = XmlConvert.ToDateTime(lastUpdatedValue, XmlDateTimeSerializationMode.RoundtripKind);
         workItem = workItem.UpdateTimestamp(lastUpdated);
     }
     return workItem;
 }
        public void CreateWorkItem(WorkItem workItem)
        {
            if (_workItems.ContainsKey(workItem.Id))
            {
                throw new ArgumentException("Work item already exists: " + workItem.Id);
            }

            _innerRepository.CreateWorkItem(workItem);
            _workItems.Add(workItem.Id, workItem);
        }
        public void CleanUpIfInExpandStep(WorkItem workItemToMove)
        {
            WorkStep expandStep;
            if (WorkflowRepository.IsInExpandStep(workItemToMove, out expandStep))
            {
                var transientStepPath = ExpandedWorkStep.GetTransientPath(expandStep, workItemToMove);
                var transientStep = WorkflowRepository.GetWorkStep(transientStepPath);

                WorkflowRepository.DeleteWorkStepsRecursively(transientStep);
            }
        }
 private void ThrowInvalidOperationExceptionIfParentIsParallelLocked(WorkItem workItem)
 {
     if (workItem.Parent != null)
     {
         var parent = WorkflowRepository.GetWorkItem(workItem.Parent.Id);
         if (parent.Status == WorkItemStatus.ParallelLocked)
         {
             throw new InvalidOperationException("Cannot delete workitem which is child of paralleled workitem");
         }
     }
 }
        public static bool IsChildOfExpandedWorkItem(this IReadableWorkflowRepository workflowRepository, WorkItem item)
        {
            if (item.Parent == null)
            {
                return false;
            }

            var parent = workflowRepository.GetWorkItem(item.Parent.Id);
            var workStep = workflowRepository.GetWorkStep(parent.Path);

            return workStep.Type == WorkStepType.Expand;
        }
Пример #18
0
        private static void LogCreate(WorkItem workItem)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                Log(connection, workItem.Timestamp, "create", workItem, null);

                const string createStatus =
                    "insert into WS_WorkflowStatus (WS_Id,WS_Path) VALUES (@Id,@Path)";

                AdjustStatus(connection, workItem, createStatus);
            }
        }
        public static bool IsChildOfParallelledWorkItem(this IReadableWorkflowRepository repository, WorkItem workItem, out WorkItem parent)
        {
            if (workItem.Parent != null)
            {
                parent = repository.GetWorkItem(workItem.Parent.Id);
                if (parent.Status == WorkItemStatus.ParallelLocked)
                {
                    return true;
                }
            }

            parent = null;
            return false;
        }
        public IEnumerable<WorkItem> SplitForParallelism(WorkItem workItem, WorkStep parallelRootStep)
        {
            var childWorkItems = new List<WorkItem>();

            foreach (var subStep in _workflowRepository.GetChildWorkSteps(parallelRootStep.Path))
            {
                var childId = GetParallelId(workItem.Id, parallelRootStep, subStep);
                var childWorkItem = workItem.CreateChildItem(childId,WorkItemParentType.Parallelled).AddClass(subStep.WorkItemClass);

                childWorkItems.Add(childWorkItem);
            }

            return childWorkItems;
        }
Пример #21
0
        private static WorkItem GetAgeUpdateWorkItem(WorkItem workItem)
        {
            var now = DateTime.Now;

            var lastMoved = workItem.LastMoved.HasValue ? workItem.LastMoved.Value : now;
            string age;

            if (lastMoved.AddDays(35) < now)
            {
                age = "dead";
            }
            else if (lastMoved.AddDays(20) < now)
            {
                age = "old";
            }
            else if (lastMoved.AddDays(13) < now)
            {
                age = "senior";
            }
            else if (lastMoved.AddDays(8) < now)
            {
                age = "middleaged";
            }
            else if (lastMoved.AddDays(5) < now)
            {
                age = "young";
            }
            else if (lastMoved.AddDays(3) < now)
            {
                age = "adolescent";
            }
            else if (lastMoved.AddDays(2) < now)
            {
                age = "child";
            }
            else if (lastMoved.AddDays(1) < now)
            {
                age = "baby";
            }
            else
            {
                age = "newborn";
            }

            return WorkItem.New(workItem.Id,workItem.Path).UpdateProperty(_ageKey, age);
        }
Пример #22
0
        private static void Log(SqlConnection connection, DateTime? timestamp, string type, WorkItem workItem,
                                object fromPath)
        {
            const string insertLog =
                "insert into WL_WorkflowLog" +
                " (WL_Type,WL_Timestamp,WL_Id,WL_Path,WL_FromPath)" +
                " values (@Type,@Timestamp,@Id,@Path,@FromPath)";

            var cmd = new SqlCommand(insertLog, connection);

            cmd.Parameters.Add(new SqlParameter("@Type", type));
            cmd.Parameters.Add(new SqlParameter("@Timestamp", timestamp.HasValue ? timestamp.Value : DateTime.Now));
            cmd.Parameters.Add(new SqlParameter("@Id", workItem.Id));
            cmd.Parameters.Add(new SqlParameter("@Path", workItem.Path));
            cmd.Parameters.Add(new SqlParameter("@FromPath", fromPath ?? DBNull.Value));

            cmd.ExecuteNonQuery();
        }
        private void DeleteWorkItemRecursively(WorkItem workItem)
        {
            var expandedChildWorkItems = WorkflowRepository.GetChildWorkItems(workItem.AsParent(WorkItemParentType.Expanded));
            var parallelChildWorkItems = WorkflowRepository.GetChildWorkItems(workItem.AsParent(WorkItemParentType.Parallelled));

            var childWorkItems = expandedChildWorkItems.Concat(parallelChildWorkItems);

            if (childWorkItems.Count() > 0)
            {
                foreach (var childWorkItem in childWorkItems)
                {
                    DeleteWorkItemRecursively(childWorkItem);
                }
            }

            WorkflowRepository.DeleteWorkItem(workItem.Id);
            CleanUpIfInExpandStep(workItem);
        }
Пример #24
0
        private static void RenderProperties(XmlWriter writer, WorkItem workItem)
        {
            writer.WriteStartElement("Properties");

            foreach (var keyValue in workItem.Properties)
            {
                writer.WriteStartElement("Property");

                writer.WriteStartAttribute("name");
                writer.WriteValue(keyValue.Key);
                writer.WriteEndAttribute();

                writer.WriteValue(keyValue.Value);

                writer.WriteEndElement(); //Property
            }

            writer.WriteEndElement(); //Properties
        }
        private void Create(WorkItem newWorkItem)
        {
            var leafStep = WorkflowRepository.GetLeafStep(newWorkItem.Path);

            if (leafStep.Type != WorkStepType.Begin)
            {
                throw new InvalidOperationException("Can only create work items in begin step");
            }

            var classes = WorkflowRepository.GetWorkItemClasses(leafStep);

            newWorkItem = newWorkItem.MoveTo(leafStep,_timeSource.GetTime()).UpdateClasses(classes);

            WorkStep transientStep;
            if (WorkflowRepository.IsWithinTransientStep(leafStep, out transientStep))
            {
                var parentItem = GetTransientParentWorkItem(transientStep);
                WorkflowRepository.UpdateWorkItem(parentItem.UpdateStatus(WorkItemStatus.ExpandLocked));

                newWorkItem = newWorkItem.MoveTo(leafStep,_timeSource.GetTime()).UpdateParent(parentItem,WorkItemParentType.Expanded);

                foreach (var workItemClass in newWorkItem.Classes)
                {
                    foreach (var rootClass in WorkItemClass.FindRootClasses(workItemClass))
                    {
                        newWorkItem = newWorkItem.AddClass(rootClass);
                    }
                }
            }
            else if (WorkflowRepository.IsWithinExpandStep(leafStep))
            {
                throw new InvalidOperationException("Cannot create item directly under expand step");
            }

            if (!newWorkItem.Ordinal.HasValue)
            {
                newWorkItem = newWorkItem.UpdateOrdinal(WorkflowRepository.GetNextOrdinal(newWorkItem));
            }

            WorkflowRepository.CreateWorkItem(newWorkItem);
        }
Пример #26
0
        public void UpdateWorkItem(WorkItem changedWorkItem)
        {
            var currentWorkItem = GetWorkItemOrThrow(changedWorkItem.Id);

            ThrowIfConflictingTimestamp(currentWorkItem, changedWorkItem);

            currentWorkItem =
                currentWorkItem.UpdatePropertiesAndOrdinalFrom(changedWorkItem).UpdateTimestamp(TimeSource.GetTime());

            var leafStep = WorkflowRepository.GetLeafStep(changedWorkItem.Path);

            if (changedWorkItem.Path == currentWorkItem.Path || currentWorkItem.Path == leafStep.Path)
            {
                WorkflowRepository.UpdateWorkItem(currentWorkItem);
            }
            else
            {
                var mover = new WorkItemMover(WorkflowRepository,TimeSource);
                mover.MoveWorkItem(currentWorkItem, leafStep);
            }
        }
Пример #27
0
 private static void ThrowIfConflictingTimestamp(WorkItem currentWorkItem, WorkItem changedWorkItem)
 {
     if (changedWorkItem.Timestamp.HasValue && changedWorkItem.Timestamp.Value != currentWorkItem.Timestamp.Value)
     {
         throw new InvalidOperationException("Conflicting timestamps");
     }
 }
        public void UpdateWorkItem(WorkItem workItem)
        {
            _innerRepository.UpdateWorkItem(workItem);

            _workItems[workItem.Id] = workItem;
        }
 public void UpdateWorkItem(WorkItem workItem)
 {
     _workItems[workItem.Id] = workItem;
 }
Пример #30
0
        private static void RenderWorkItem(XmlWriter writer, WorkItem item)
        {
            writer.WriteStartElement("WorkItem");

            writer.WriteStartAttribute("id");
            writer.WriteValue(item.Id);
            writer.WriteEndAttribute();

            if(item.Ordinal.HasValue)
            {
                RenderAttribute(writer, "ordinal", XmlConvert.ToString(item.Ordinal.Value));
            }

            if(item.Timestamp.HasValue)
            {
                RenderAttribute(writer, "timestamp", XmlConvert.ToString(item.Timestamp.Value, XmlDateTimeSerializationMode.RoundtripKind));
            }

            if (item.LastMoved.HasValue)
            {
                RenderAttribute(writer, "lastmoved", XmlConvert.ToString(item.LastMoved.Value, XmlDateTimeSerializationMode.RoundtripKind));
            }

            writer.WriteStartAttribute("classes");
            writer.WriteValue(item.Classes.Join(' '));
            writer.WriteEndAttribute();

            RenderProperties(writer, item);

            writer.WriteEndElement(); //WorkItem
        }