コード例 #1
0
        private IRule CheckTasksAreapath(AreaPathParameter name)
        {
            var builder = new WiqlBuilder()
                          .AssignedTo()
                          .WithItemTypes("and", "=", WorkItemTypes.Task)
                          .WithStates("and", "<>", "and", WorkItemStates.Closed, WorkItemStates.Removed);

            var result = new Rule
            {
                Title     = Resource.AS_Rule_AreaCondition_Title,
                Operation = RuleOperation.SameCount,
                Source    = builder.ToString(),
                Condition = builder.WithAreaPath("and", $"{name?.AreaPath}").ToString()
            };

            return(result);
        }
コード例 #2
0
        private IRule AllTasksIsCurrentIteration()
        {
            var builder = new WiqlBuilder()
                          .AssignedTo()
                          .WithItemTypes("and", "=", WorkItemTypes.Task)
                          .WithStates("and", "<>", "and", WorkItemStates.Closed, WorkItemStates.Removed);

            var result = new Rule
            {
                Title     = Resource.AS_Rule_CurrentIteration_Title,
                Operation = RuleOperation.SameCount,
                Source    = builder.ToString(),
                Condition = builder.CurrentIteration().ToString()
            };

            return(result);
        }
コード例 #3
0
        public Dictionary <int, WorkItem> FindById(IEnumerable <int> ids)
        {
            if (ids.IsNullOrEmpty())
            {
                return(new Dictionary <int, WorkItem>());
            }

            var builder = new WiqlBuilder();

            foreach (var id in ids.Distinct())
            {
                builder = builder.WithNumber("or", id);
            }

            var items = QueryItems(builder.ToString());

            return(items.ToDictionary(x => x.Id));
        }
コード例 #4
0
        public IList <WorkItem> Search(string text, params string[] allowedTypes)
        {
            var quarry = new WiqlBuilder()
                         .ContainsInFields("where",
                                           text,
                                           Sql.Fields.History,
                                           Sql.Fields.Title,
                                           Sql.Fields.Description);

            // Ищу только указанные типы
            if (!allowedTypes.IsNullOrEmpty())
            {
                quarry.WithItemTypes("and", "=", allowedTypes);
            }

            var items = _itemStore.Query(quarry.ToString());

            Trace.WriteLine($"{nameof(TfsApi)}.{nameof(Search)}: Tfs.Search: Founded {items.Count} items");

            return(items.OfType <WorkItem>().ToList());
        }
コード例 #5
0
        public List <KeyValuePair <Revision, int> > GetWriteoffs(DateTime from, DateTime to)
        {
            var result = new List <KeyValuePair <Revision, int> >();

            // Рабочие элементы в TFS находятся по дате
            // Т.к. TFS некорректно отрабатывает с ">=",
            // работаем с ">". Для этого нужно исключить переданный день
            from = from.AddDays(-1).Date;
            to   = to.AddDays(1).Date;

            if (from >= to)
            {
                throw new Exception($"{nameof(from)} should be earlier than {nameof(to)}");
            }

            var query = new WiqlBuilder()
                        .AssignedTo()
                        .WithItemTypes("and", "=", WorkItemTypes.Task)
                        .EverChangedBy("and")
                        .ChangedDate("and", from, ">")
                        .ChangedDate("and", to, "<");

            var tasks = _itemStore.Query(query.ToString());

            foreach (WorkItem task in tasks)
            {
                var revisions = task
                                .Revisions
                                .OfType <Revision>()
                                .Where(x => x.Fields[WorkItems.Fields.Complited]?.Value != null &&
                                       x.Fields[WorkItems.Fields.ChangedBy]?.Value != null &&
                                       x.Fields[CoreField.ChangedDate].Value is DateTime)
                                .ToList();

                double previouse = 0;

                foreach (var revision in revisions)
                {
                    // Был ли в этот момент таск на мне
                    var assignedToMe = revision.Fields[CoreField.AssignedTo]?.Value is string assigned &&
                                       string.Equals(Name, assigned);

                    // Был ли таск изменен мной
                    var changedByMe = revision.Fields[WorkItems.Fields.ChangedBy]?.Value is string owner &&
                                      string.Equals(Name, owner);

                    var correctTime = revision.Fields[CoreField.ChangedDate].Value is DateTime time &&
                                      from < time.Date &&
                                      time.Date < to;

                    var completed = (double)revision.Fields[WorkItems.Fields.Complited].Value;

                    // Списанное время
                    var delta = (int)(completed - previouse);

                    previouse = completed;

                    if (delta < 1)
                    {
                        continue;
                    }

                    if (!correctTime)
                    {
                        continue;
                    }

                    if (!changedByMe)
                    {
                        Trace.WriteLine(
                            $"{revision.Fields[WorkItems.Fields.ChangedBy]?.Value} is changed completed work for you");
                        continue;
                    }

                    if (!assignedToMe)
                    {
                        Trace.WriteLine(
                            $"{nameof(TfsApi)}.{nameof(GetWriteoffs)}: {revision.Fields[CoreField.AssignedTo]?.Value} took your task");
                        continue;
                    }

                    result.Add(new KeyValuePair <Revision, int>(revision, delta));
                }
            }

            return(result);
        }