Exemple #1
0
        /// <summary>
        /// Gets a paged list of Tasks
        /// </summary>
        /// <param name="page">Zero based page index</param>
        /// <param name="per_page">Number of results per page</param>
        /// <param name="statusFilter">Only lists tasks that match this status filter</param>
        /// <param name="from_time">Lower bound of the time of the task</param>
        /// <param name="to_time">Upper bound of the time of the task</param>
        /// <returns>Tasks that meet the criteria</returns>
        public IList <Task> Tasks(int page = 0, int per_page = 30, StatusEnum statusFilter = StatusEnum.All, DateTime?from_time = null, DateTime?to_time = null)
        {
            StringBuilder queryParameters = new StringBuilder();

            if (page != 0)
            {
                queryParameters.AppendFormat("page={0}&", page);
            }

            if (per_page != 30)
            {
                queryParameters.AppendFormat("per_page={0}&", per_page);
            }

            if (!statusFilter.HasFlag(StatusEnum.All))
            {
                var statusQueryParams = Enum.GetNames(typeof(StatusEnum))
                                        .Where(status =>
                                               statusFilter.HasFlag((StatusEnum)Enum.Parse(typeof(StatusEnum), status)))
                                        .Select(status => status.ToLower())
                                        .Select(status => string.Format("{0}=1", status));

                var statusFilterQuery = string.Join("&", statusQueryParams);

                queryParameters.Append(statusFilterQuery);
            }

            if (from_time.HasValue)
            {
                queryParameters.AppendFormat("from_time={0}", (from_time.Value - new DateTime(1970, 1, 1)).Seconds);
            }

            if (to_time.HasValue)
            {
                queryParameters.AppendFormat("to_time={0}", (to_time.Value - new DateTime(1970, 1, 1)).Seconds);
            }

            var url = string.Format("{0}?{1}", TaskCore, queryParameters.ToString());

            var json = this.client.Get(url);
            var d    = JsonConvert.DeserializeObject <Dictionary <string, Task[]> >(json);

            Task[] tasks;
            if (d.TryGetValue("tasks", out tasks))
            {
                return(tasks);
            }

            return(new Task[0]);
        }
Exemple #2
0
        public void Equality_ValuesShouldMatch()
        {
            (t3 == t4).Should()
            .BeTrue();
            t3.Equals(t4)
            .Should()
            .BeTrue();
            t2.Equals(t4)
            .Should()
            .BeFalse();
            (t3 != t4).Should()
            .BeFalse();
            (t2 == t4).Should()
            .BeFalse();
            (t2 != t4).Should()
            .BeTrue();
            (t3 >= t4).Should()
            .BeTrue();
            (t2 <= t4).Should()
            .BeTrue();
            (t2 > t4).Should()
            .BeFalse();
            (t2 < t4).Should()
            .BeTrue();
            t.Equals(t5)
            .Should()
            .BeTrue();

            // ReSharper disable once SuspiciousTypeConversion.Global
            t5.Equals(t)
            .Should()
            .BeTrue();
            (t5 == t).Should()
            .BeTrue();
            t5.Should()
            .Be(t);
            t.Should()
            .Be(t5);

            t2 = StatusEnum.Error;
            t2.HasFlag(StatusEnum.Error)
            .Should()
            .BeFalse();
        }
Exemple #3
0
        /// <summary>
        /// Gets a paged list of Tasks
        /// </summary>
        /// <param name="page">Zero based page index</param>
        /// <param name="per_page">Number of results per page</param>
        /// <param name="statusFilter">Only lists tasks that match this status filter</param>
        /// <param name="from_time">Lower bound of the time of the task</param>
        /// <param name="to_time">Upper bound of the time of the task</param>
        /// <returns>Tasks that meet the criteria</returns>
        public IList<Task> Tasks(int page = 0, int per_page = 30, StatusEnum statusFilter = StatusEnum.All, DateTime? from_time = null, DateTime? to_time = null)
        {
            StringBuilder queryParameters = new StringBuilder();

            if (page != 0)
            {
                queryParameters.AppendFormat("page={0}&", page);
            }

            if (per_page != 30)
            {
                queryParameters.AppendFormat("per_page={0}&", per_page);
            }

            if (!statusFilter.HasFlag(StatusEnum.All))
            {
                var statusQueryParams = Enum.GetNames(typeof(StatusEnum))
                .Where(status =>
                    statusFilter.HasFlag((StatusEnum)Enum.Parse(typeof(StatusEnum), status)))
                    .Select(status => status.ToLower())
                    .Select(status => string.Format("{0}=1", status));

                var statusFilterQuery = string.Join("&", statusQueryParams);

                queryParameters.Append(statusFilterQuery);
            }

            if (from_time.HasValue)
            {
                queryParameters.AppendFormat("from_time={0}", (from_time.Value - new DateTime(1970, 1, 1)).Seconds);
            }

            if (to_time.HasValue)
            {
                queryParameters.AppendFormat("to_time={0}", (to_time.Value - new DateTime(1970, 1, 1)).Seconds);
            }

            var url = string.Format("{0}?{1}", TaskCore, queryParameters.ToString());

            var json = this.client.Get(url);
            var d = JsonConvert.DeserializeObject<Dictionary<string, Task[]>>(json);
            Task[] tasks;
            if (d.TryGetValue("tasks", out tasks))
            {
                return tasks;
            }

            return new Task[0];
        }