示例#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 void BuildTest()
        {
            var a = $"select * from {Sql.Tables.WorkItems} " +
                    $"and {Sql.Fields.WorkItemType} = '{WorkItemTypes.Task}' " +
                    $"and {Sql.IsCurrentIteractionCondition}" +
                    $"and {Sql.AssignedToMeCondition} " +
                    $"and {Sql.Fields.State} <> {WorkItemStates.Closed}";


            var builder = new WiqlBuilder()
                          .WithItemTypes("and", "=", WorkItemTypes.Task)
                          .CurrentIteration()
                          .AssignedTo()
                          .WithStates("and", "<>", WorkItemStates.Closed)
                          .ToString();


            Assert.AreEqual(a, builder);
        }
示例#5
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());
        }
示例#6
0
        /// <param name="url">Строка подключения к TFS</param>
        /// <param name="owner">От какого имени действуем</param>
        public TfsApi(string url, string owner = null)
        {
            Project = new TfsTeamProjectCollection(new Uri(url));

            Trace.WriteLine($"{nameof(TfsApi)}.ctor: Connected to " + Project.Name);

            _itemStore         = Project.GetService <WorkItemStore>();
            _linking           = Project.GetService <ILinking>();
            _versionControl    = Project.GetService <VersionControlServer>();
            _managementService = Project.GetService <IIdentityManagementService2>();
            _teamService       = Project.GetService <TfsTeamService>();


            Name = owner ?? _itemStore.UserDisplayName;

            Trace.WriteLine($"{nameof(TfsApi)}.ctor: Acting from {Name}");

            _myItemsQuerry = new WiqlBuilder()
                             .AssignedTo()
                             .WithStates("and", "<>", "and", WorkItemStates.Closed, WorkItemStates.Removed)
                             .ToString();
        }
示例#7
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);
        }