Exemplo n.º 1
0
        public List<dynamic> GetKanban(RallySlackMapping map)
        {
            RallyRestApi restApi = _pool.GetApi(map.UserName, map.Password);
            var queryType = "Iteration";
            var query = new Query(string.Format("(StartDate <= {0})", DateTime.Now.ToString("o")));
            var requestFields = new List<string>() { "Name", "StartDate", "Project", "EndDate" };
            QueryResult queryResult = GetRallyItemByQuery( map, requestFields, query,queryType);

            string iterationName;

            if (queryResult.Results.Any())
            {
                //var iter = queryResult.Results.Select(e => new Iteration(e)).Where(r => r.StartDate <= DateTime.Now).OrderByDescending(r => r.StartDate).First();
                var iter =
                    queryResult.Results.Select(
                        e =>
                            new
                            {
                                Name = e["Name"],
                                StartDate = e["StartDate"] == null ? DateTime.MinValue : DateTime.Parse(e["StartDate"]),
                                EndDate = e["EndDate"] == null ? DateTime.MaxValue : DateTime.Parse(e["EndDate"])
                            }).OrderByDescending(p=>p.StartDate).First();
                iterationName = iter.Name;

            }
            else
            {
                return null;
            }

            //User stories
            queryType = "hierarchicalrequirement";
            query = new Query("Iteration.Name", Query.Operator.Equals, iterationName);
            requestFields = new List<string>()
            {
                "Name",
                "ObjectID",
                "FormattedID",
                "Description",
                "Blocked",
                "BlockedReason",
                "Owner"
            };
            requestFields.Add(map.KanbanSortColumn);
            var result0 = GetRallyItemByQuery( map, requestFields, query, queryType);

            //Defects
            queryType = "defect";
            var result1 = GetRallyItemByQuery(map, requestFields, query, queryType);
            var result = result0.Results.ToList();
            result.AddRange(result1.Results);
            return result;
        }
Exemplo n.º 2
0
 public QueryResult GetRallyItemById(RallySlackMapping map, string formattedId)
 {
     var queryType = "hierarchicalrequirement";
     if (formattedId.StartsWith("de", StringComparison.InvariantCultureIgnoreCase))
     {
         queryType = "defect";
     }
     var query = new Query("FormattedID", Query.Operator.Equals, formattedId);
     var requestFields = new List<string>() { "Name", "Description", "FormattedID" };
     return GetRallyItemByQuery( map, requestFields, query,queryType);
 }
Exemplo n.º 3
0
        private static Request BuildRequest(string type)
        {
            var todayDate = DateTime.Today.ToString("yyyy-MM-dd");
              var q = new Query("Iteration.StartDate", Query.Operator.LessThanOrEqualTo, todayDate)
            .And(new Query("Iteration.EndDate", Query.Operator.GreaterThanOrEqualTo, todayDate)
            .And(new Query("Release.Name", Query.Operator.Equals, "ST 15.5")));

              var fetchValues = new List<string>() { "Name", "Description", "FormattedID" };
              var defectRequest = new Request(type);
              defectRequest.Fetch = fetchValues;
              defectRequest.Query = q;
              return defectRequest;
        }
Exemplo n.º 4
0
 public QueryResult GetRallyItemByQuery(RallySlackMapping map, List<string> requestFields, Query query, string artifectName ="")
 {
     var api = _pool.GetApi(map.UserName, map.Password);
     if (api == null)
     {
         throw new AuthenticationException("Cannot verify rally login");
     }
     Request request;
     if (string.IsNullOrEmpty(artifectName))
     {
         request = new Request();
     }
     else
     {
         request = new Request(artifectName);
     }
     request.Project = "/project/" + map.ProjectId;
     request.Workspace = "/workspace/" + map.WorkspaceId;
     //request.Fetch = new List<string>() { "Name", "Description", "FormattedID" };
     request.Fetch = requestFields;
     request.Query = query;
     QueryResult queryResult = api.Query(request);
     return queryResult;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Join the specified query to this query
 /// using the OR operator.
 /// </summary>
 /// <param name="q">The query to be joined</param>
 /// <returns>The joined query</returns>
 public Query Or(Query q)
 {
     return Join(this, q, ClauseOperator.Or);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Join the specified query to this query
 /// using the AND operator.
 /// </summary>
 /// <param name="q">The query to be joined</param>
 /// <returns>The joined query</returns>
 public Query And(Query q)
 {
     return Join(this, q, ClauseOperator.And);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Join the two specified queries with the specified operator
 /// </summary>
 /// <param name="a">The first query to be joined</param>
 /// <param name="b">The second query to be joined</param>
 /// <param name="op">The operator</param>
 /// <returns>The joined query</returns>
 protected Query Join(Query a, Query b, ClauseOperator op)
 {
     return new Query(string.Format("({0} {1} {2})", a.QueryClause, op.ToString().ToUpper(), b.QueryClause));
 }
Exemplo n.º 8
0
        List<ChangedArtifact> LoadChanges(DateTime fromTime, DateTime toTime, CancellationToken ct)
        {
            var toS = toTime.ToString("yyyy-MM-ddTHH:mm:ss");
            var fromS = fromTime.ToString("yyyy-MM-ddTHH:mm:ss");

            var client = new RallyRestApi(Settings.Default.RallyUser, Settings.Default.RallyPassword, cancellationToken: ct);

            if (_currentUser == null)
            {
                backgroundOperation.SetProgress("Get current user ...");
                if (string.IsNullOrWhiteSpace(textBoxUser.Text) || textBoxUser.Tag != null)
                {
                    _currentUser = client.GetCurrentUser();
                }
                else
                {
                    var query = new Query("(UserName = "******")");
                    var resp = client.Query(new Request("user") { Query = query });
                    _currentUser = resp.Results.First();
                }
            }

            // retrieve revisions
            var requestRevs = new Request("revision");
            requestRevs.Limit = Int32.MaxValue;
            requestRevs.Fetch = new List<string> { "Description", "RevisionHistory", "CreationDate" };
            requestRevs.Query = new Query("User", Query.Operator.Equals, _currentUser["UserName"])
                .And(new Query("CreationDate", Query.Operator.GreaterThanOrEqualTo, fromS))
                .And(new Query("CreationDate", Query.Operator.LessThanOrEqualTo, toS))
            ;

            backgroundOperation.SetProgress("Load revisions ...");

            var resultRevs = client.Query(requestRevs);

            var revHists = resultRevs.Results.Cast<DynamicJsonObject>()
                .GroupBy(r => (string)r["RevisionHistory"]["_refObjectUUID"])
                .ToDictionary(g => g.Key, g => g.Select(r => (DynamicJsonObject)r).ToList())
            ;

            // check cancellation
            ct.ThrowIfCancellationRequested();

            // query artifacts
            var requestArtifacts = new Request("artifact");
            requestArtifacts.Limit = Int32.MaxValue;
            requestArtifacts.Fetch = new List<string> { "FormattedID", "Name", "RevisionHistory", "LastUpdateDate", "Requirement", "WorkProduct", "ObjectID", "Owner", "Project" };
            requestArtifacts.Query = new Query("LastUpdateDate", Query.Operator.GreaterThanOrEqualTo, fromS)
                .And(new Query("LastUpdateDate", Query.Operator.LessThanOrEqualTo, toS))
            ;

            var artUuid2Revs = new Dictionary<string, List<DynamicJsonObject>>();
            var artUuid2Art = new Dictionary<string, DynamicJsonObject>();

            backgroundOperation.SetProgress("Load artifacts ...");

            var resultArts = client.Query(requestArtifacts);

            foreach (var art in resultArts.Results)
            {
                // can't inject in Query ....
                var type = (string)art["_type"];
                if (type != "Task" && type != "Defect")
                    continue;

                var histUuid = (string)art["RevisionHistory"]["_refObjectUUID"];
                if (!revHists.ContainsKey(histUuid))
                    continue;

                List<DynamicJsonObject> artifactRevs;
                if (!artUuid2Revs.TryGetValue((string)art["_refObjectUUID"], out artifactRevs))
                {
                    artifactRevs = new List<DynamicJsonObject>();
                    artUuid2Revs[(string)art["_refObjectUUID"]] = artifactRevs;
                }

                artifactRevs.AddRange(revHists[histUuid]);
                artUuid2Art[(string)art["_refObjectUUID"]] = art;
            }

            foreach (var group in artUuid2Art.GroupBy(kvp => new Artifact(kvp.Value).Type).ToArray())
            {
                ct.ThrowIfCancellationRequested();

                backgroundOperation.SetProgress(string.Format("Loading group of '{0}' ...", group.Key));

                var allIds = group.Select(a => new Artifact(a.Value).ObjectID.ToString(CultureInfo.InvariantCulture)).ToArray();
                var query = allIds
                    .Skip(1)
                    .Aggregate(new Query("ObjectId", Query.Operator.Equals, allIds.First()), (current, id) => current.Or(new Query("ObjectId", Query.Operator.Equals, id)))
                ;

                var r = new Request(group.First().Value["_type"]);
                r.Limit = Int32.MaxValue;
                r.Query = query;
                var qr = client.Query(r);

                foreach (var result in qr.Results)
                {
                    if (result["_type"] == "Task")
                    {
                        artUuid2Art[result["_refObjectUUID"]]["Estimate"] = (double)result["Estimate"];
                        artUuid2Art[result["_refObjectUUID"]]["ToDo"] = (double)result["ToDo"];
                        artUuid2Art[result["_refObjectUUID"]]["State"] = (string)result["State"];
                    }
                    else if (result["_type"] == "Defect")
                    {
                        //var additionalInfo = client.GetByReference(art.Reference);

                        //artUuid2Art[kvp.Key]["Estimate"] = additionalInfo["Estimate"];
                        //artUuid2Art["ToDo"] = additionalInfo["ToDo"];
                    }
                }
            }

            var changes = artUuid2Revs
                .Select(kvp => new ChangedArtifact { Artifact = artUuid2Art[kvp.Key], Revisions = kvp.Value, WorkItem = new Artifact(artUuid2Art[kvp.Key]) })
                .ToList()
            ;

            UpdateCache(changes);

            return changes;
        }
Exemplo n.º 9
0
        // load issues list
        List<Artifact> LoadArtifacts(CancellationToken ct)
        {
            var artifacts = new List<DynamicJsonObject>();

            var restApi = new RallyRestApi(Settings.Default.RallyUser, Settings.Default.RallyPassword
                //, proxy: new WebProxy("localhost:8888", false)
                , cancellationToken: ct
            );

            var query = new Query(Settings.Default.RallyQuery);

            {
                backgroundRefreshOperation.SetProgress("Loading defects  ...");

                var request = new Request("defect");
                request.Limit = Int32.MaxValue;
                request.Fetch = new List<string> { "FormattedID", "Requirement", "Name", "Project", "ObjectID", "Iteration", "EndDate", "StartDate" };
                request.Order = "Iteration";
                request.Query = query;

                // perfrom query
                var response = restApi.Query(request);
                artifacts.AddRange(response.Results.Select(a => (DynamicJsonObject)a));
            }

            ct.ThrowIfCancellationRequested();

            {
                backgroundRefreshOperation.SetProgress("Loading tasks ...");

                var request = new Request("task");
                request.Limit = Int32.MaxValue;
                request.Fetch = new List<string> { "FormattedID", "WorkProduct", "Name", "Project", "ObjectID", "Iteration", "EndDate", "StartDate" };
                request.Order = "Iteration";
                request.Query = query;

                // perfrom query
                var response = restApi.Query(request);
                artifacts.AddRange(response.Results.Select(a => (DynamicJsonObject)a));
            }

            // update cache
            UpdateCache(artifacts);

            var list = artifacts
                .Select(w => new Artifact(w))
                .ToList()
            ;

            // move defect tasks immediately after defects
            for (var i = 0; i < list.Count; i++)
            {
                if(list[i].Parent.Type == ArtifactType.Defect)
                {
                    // find defect in list
                    var parentIndex = list.FindIndex(a => a.ObjectID == list[i].Parent.ObjectID);

                    // if parent found and parent is not direct preceder
                    if (parentIndex != -1 && parentIndex != (i - 1))
                    {
                        var task = list[i];
                        list.RemoveAt(i);
                        list.Insert(parentIndex + 1, task);
                    }
                }
            }

            return list;
        }