Ejemplo n.º 1
0
        public static IProperty<Issue> GetPropertyByField(TracIssue.IssueField field)
        {
            var index = (int) field;

            if (index < 0 || index >= Properties.Count)
                throw new ArgumentOutOfRangeException("field", field, null);

            return Properties[index];
        }
Ejemplo n.º 2
0
        public Action DownloadIssues(string project, int start, bool includeClosedIssues,
            Func<IEnumerable<Issue>, bool> onData,
            Action<DownloadProgressChangedEventArgs> onProgress,
            Action<bool, Exception> onCompleted)
        {
            Debug.Assert(project != null);
            Debug.Assert(onData != null);

            var client = new WebClient();
            client.Headers.Add("Content-Type", "application/json");

            client.UploadStringCompleted += (sender, args) =>
            {
                if (args.Cancelled || args.Error != null)
                {
                    if (onCompleted != null)
                        onCompleted(args.Cancelled, args.Error);

                    return;
                }

                JsonData data = JsonMapper.ToObject(args.Result);
                if (data["error"] != null)
                {
                    if (onCompleted != null)
                        onCompleted(false, new Exception((string)data["error"]["message"]));

                    return;
                }
                else if (data["result"] != null && data["result"].Count > 0)
                {
                    var client2 = new WebClient();
                    client2.Headers.Add("Content-Type", "application/json");
                    var jsonRPCQuery = new JsonWriter();
                    jsonRPCQuery.WriteObjectStart();
                    jsonRPCQuery.WritePropertyName("method");
                    jsonRPCQuery.Write("system.multicall");
                    jsonRPCQuery.WritePropertyName("params");
                    jsonRPCQuery.WriteArrayStart();
                    for (int i = 0; i < data["result"].Count - 1; i++)
                    {
                        jsonRPCQuery.WriteObjectStart();
                        jsonRPCQuery.WritePropertyName("method");
                        jsonRPCQuery.Write("ticket.get");
                        jsonRPCQuery.WritePropertyName("params");
                        jsonRPCQuery.WriteArrayStart();
                        jsonRPCQuery.Write((int)data["result"][i]);
                        jsonRPCQuery.WriteArrayEnd();
                        jsonRPCQuery.WriteObjectEnd();
                    }

                    client2.UploadStringCompleted += (sender2, args2) =>
                    {
                        if (args2.Cancelled || args2.Error != null)
                        {
                            return;
                        }

                        int lastObjectStart = 0;
                        int count = 0;
                        bool inQuote = false;
                        bool lastWasBackslash = false;
                        for (int n = 1; n < args2.Result.Length; n++)
                        {
                            if (inQuote)
                            {
                                if (args2.Result[n] == '"' && !lastWasBackslash)
                                {
                                    inQuote = false;
                                }
                                else if (args2.Result[n] == '\\')
                                {
                                    lastWasBackslash = !lastWasBackslash;
                                }
                                else
                                {
                                    lastWasBackslash = false;
                                }
                            }
                            else
                            {
                                if (args2.Result[n] == '"')
                                {
                                    inQuote = true;
                                }
                                else if (args2.Result[n] == '}')
                                {
                                    --count;
                                    if (count == 0)
                                    {
                                        n++;
                                        JsonData issueData = JsonMapper.ToObject(args2.Result.Substring(lastObjectStart, n - lastObjectStart));
                                        TracIssue[] issues = new TracIssue[1];
                                        issues[0] = new TracIssue();
                                        issues[0].Id = (int)issueData["result"][0];
                                        if (issueData["result"][3].ToString().Contains("milestone"))
                                        {
                                            issues[0].Milestone = (string)issueData["result"][3]["milestone"];
                                        }
                                        issues[0].Owner = (string)issueData["result"][3]["owner"];
                                        issues[0].Type = (string)issueData["result"][3]["type"];
                                        issues[0].Priority = (string)issueData["result"][3]["priority"];
                                        issues[0].Status = (string)issueData["result"][3]["status"];
                                        issues[0].Summary = (string)issueData["result"][3]["summary"];
                                        onData(issues);
                                    }
                                }
                                else if (args2.Result[n] == '{')
                                {
                                    if (count == 0)
                                    {
                                        lastObjectStart = n;
                                    }
                                    ++count;
                                }
                            }
                        }

                        if (onCompleted != null)
                            onCompleted(false, null);
                    };

                    jsonRPCQuery.WriteArrayEnd();
                    jsonRPCQuery.WriteObjectEnd();
                    client2.UploadStringAsync(this.RPCUrl(), jsonRPCQuery.ToString());

                    if (onProgress != null)
                        client.DownloadProgressChanged += (sender2, args2) => onProgress(args2);
                }
            };

            if (onProgress != null)
                client.DownloadProgressChanged += (sender, args) => onProgress(args);

            var jsonRPCQueryTicktes = new JsonWriter();
            jsonRPCQueryTicktes.WriteObjectStart();
            jsonRPCQueryTicktes.WritePropertyName("method");
            jsonRPCQueryTicktes.Write("ticket.query");
            jsonRPCQueryTicktes.WritePropertyName("qstr");
            jsonRPCQueryTicktes.Write("status!=closed");
            jsonRPCQueryTicktes.WriteObjectEnd();

            client.UploadStringAsync(this.RPCUrl(), jsonRPCQueryTicktes.ToString());

            return client.CancelAsync;
        }