/// <summary>
 /// Executes the download file.
 /// </summary>
 /// <param name="redmineManager">The redmine manager.</param>
 /// <param name="address">The address.</param>
 /// <returns></returns>
 public static async Task <byte[]> ExecuteDownloadFile(RedmineManager redmineManager, string address)
 {
     using (var wc = redmineManager.CreateWebClient(null, true))
     {
         return(await wc.DownloadDataTaskAsync(address).ConfigureAwait(false));
     }
 }
        /// <summary>
        /// Executes the download paginated list.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="redmineManager">The redmine manager.</param>
        /// <param name="address">The address.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public static async Task <PagedResults <T> > ExecuteDownloadPaginatedList <T>(RedmineManager redmineManager, string address,
                                                                                      NameValueCollection parameters = null) where T : class, new()
        {
            using (var wc = redmineManager.CreateWebClient(parameters))
            {
                var response = await wc.DownloadStringTaskAsync(address).ConfigureAwait(false);

                return(redmineManager.Serializer.DeserializeToPagedResults <T>(response));
            }
        }
        /// <summary>
        /// Executes the upload file.
        /// </summary>
        /// <param name="redmineManager">The redmine manager.</param>
        /// <param name="address">The address.</param>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public static async Task <Upload> ExecuteUploadFile(RedmineManager redmineManager, string address, byte[] data)
        {
            using (var wc = redmineManager.CreateWebClient(null, true))
            {
                var response = await wc.UploadDataTaskAsync(address, data).ConfigureAwait(false);

                var responseString = Encoding.ASCII.GetString(response);
                return(redmineManager.Serializer.Deserialize <Upload>(responseString));
            }
        }
Esempio n. 4
0
        public static Task DeleteWikiPageAsync(this RedmineManager redmineManager, string projectId, string pageName)
        {
            var uri = UrlHelper.GetDeleteWikirUrl(redmineManager, projectId, pageName);

            return(delegate
            {
                using (var wc = redmineManager.CreateWebClient(null))
                {
                    wc.UploadString(uri, RedmineManager.DELETE, string.Empty);
                }
            });
        }
Esempio n. 5
0
 /// <summary>
 /// Executes the upload.
 /// </summary>
 /// <param name="redmineManager">The redmine manager.</param>
 /// <param name="address">The address.</param>
 /// <param name="actionType">Type of the action.</param>
 /// <param name="data">The data.</param>
 /// <param name="parameters">The parameters</param>
 public static void ExecuteUpload(RedmineManager redmineManager, string address, string actionType, string data,
                                  NameValueCollection parameters = null)
 {
     using (var wc = redmineManager.CreateWebClient(parameters))
     {
         if (actionType == HttpVerbs.POST || actionType == HttpVerbs.DELETE || actionType == HttpVerbs.PUT ||
             actionType == HttpVerbs.PATCH)
         {
             wc.UploadString(address, actionType, data);
         }
     }
 }
        public static Task DeleteWikiPageAsync(this RedmineManager redmineManager, string projectId, string pageName)
        {
            var uri = UrlHelper.GetDeleteWikirUrl(redmineManager, projectId, pageName);

            return(Task.Factory.StartNew(() =>
            {
                using (var wc = redmineManager.CreateWebClient(null))
                {
                    wc.UploadString(uri, RedmineManager.DELETE, string.Empty);
                }
            }, TaskCreationOptions.LongRunning));
        }
Esempio n. 7
0
 /// <summary>
 /// Executes the upload.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="redmineManager">The redmine manager.</param>
 /// <param name="address">The address.</param>
 /// <param name="actionType">Type of the action.</param>
 /// <param name="data">The data.</param>
 /// <returns></returns>
 public static T ExecuteUpload <T>(RedmineManager redmineManager, string address, string actionType, string data)
     where T : class, new()
 {
     using (var wc = redmineManager.CreateWebClient(null))
     {
         if (actionType == HttpVerbs.POST || actionType == HttpVerbs.DELETE || actionType == HttpVerbs.PUT ||
             actionType == HttpVerbs.PATCH)
         {
             var response = wc.UploadString(address, actionType, data);
             return(redmineManager.Serializer.Deserialize <T>(response));
         }
         return(default);
Esempio n. 8
0
        /// <summary>
        /// Executes the download.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="redmineManager">The redmine manager.</param>
        /// <param name="address">The address.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public static T ExecuteDownload <T>(RedmineManager redmineManager, string address,
                                            NameValueCollection parameters = null)
            where T : class, new()
        {
            using (var wc = redmineManager.CreateWebClient(parameters))
            {
                var response = wc.DownloadString(address);
                if (!string.IsNullOrEmpty(response))
                {
                    return(redmineManager.Serializer.Deserialize <T>(response));
                }

                return(default);
        /// <summary>
        /// Executes the upload.
        /// </summary>
        /// <param name="redmineManager">The redmine manager.</param>
        /// <param name="address">The address.</param>
        /// <param name="actionType">Type of the action.</param>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public static async Task <string> ExecuteUpload(RedmineManager redmineManager, string address, string actionType, string data)
        {
            using (var wc = redmineManager.CreateWebClient(null))
            {
                if (actionType == HttpVerbs.POST || actionType == HttpVerbs.DELETE || actionType == HttpVerbs.PUT ||
                    actionType == HttpVerbs.PATCH)
                {
                    return(await wc.UploadStringTaskAsync(address, actionType, data).ConfigureAwait(false));
                }
            }

            return(null);
        }
        public static Task RemoveWatcherFromIssueAsync(this RedmineManager redmineManager, int issueId, int userId)
        {
            var task = Task.Factory.StartNew(() =>
            {
                var uri = UrlHelper.GetRemoveWatcherUrl(redmineManager, issueId, userId);
                using (var wc = redmineManager.CreateWebClient(null))
                {
                    wc.UploadString(uri, RedmineManager.DELETE, string.Empty);
                }
            }, TaskCreationOptions.LongRunning);

            return(task);
        }
Esempio n. 11
0
        public static Task RemoveWatcherFromIssueAsync(this RedmineManager redmineManager, int issueId, int userId)
        {
            Task task = delegate
            {
                var uri = UrlHelper.GetRemoveWatcherUrl(redmineManager, issueId, userId);
                using (var wc = redmineManager.CreateWebClient(null))
                {
                    wc.UploadString(uri, RedmineManager.DELETE, string.Empty);
                }
            };

            return(task);
        }
Esempio n. 12
0
        //public static Task<List<T>> GetObjectsAsync<T>(this RedmineManager redmineManager, NameValueCollection parameters) where T : class, new()
        //{
        //    Task<List<T>> task = delegate
        //    {
        //        int totalCount = 0, pageSize;
        //        List<T> resultList = null;
        //        if (parameters == null) parameters = new NameValueCollection();
        //        int offset = 0;
        //        int.TryParse(parameters[RedmineKeys.LIMIT], out pageSize);
        //        if (pageSize == default(int))
        //        {
        //            pageSize = redmineManager.PageSize > 0 ? redmineManager.PageSize : 25;
        //            parameters.Set(RedmineKeys.LIMIT, pageSize.ToString(CultureInfo.InvariantCulture));
        //        }
        //        do
        //        {
        //            parameters.Set(RedmineKeys.OFFSET, offset.ToString(CultureInfo.InvariantCulture));
        //            var requestTask = redmineManager.GetPaginatedObjectsAsync<T>(parameters).ContinueWith(t =>
        //            {
        //                if (t.Result != null)
        //                {
        //                    if (resultList == null)
        //                    {
        //                        resultList = t.Result.Objects;
        //                        totalCount = t.Result.TotalCount;
        //                    }
        //                    else
        //                        resultList.AddRange(t.Result.Objects);
        //                }
        //                offset += pageSize;
        //            });
        //            requestTask.Wait(TimeSpan.FromMilliseconds(5000));
        //        } while (offset < totalCount);
        //        return resultList;
        //    });
        //    return task;
        //}

        public static Task UpdateObjectAsync <T>(this RedmineManager redmineManager, string id, T obj, string projectId = null) where T : class, new()
        {
            Task task = delegate
            {
                var url = UrlHelper.GetUploadUrl(redmineManager, id, obj, projectId);
                using (var wc = redmineManager.CreateWebClient(null))
                {
                    var data = RedmineSerializer.Serialize(obj, redmineManager.MimeFormat);
                    wc.UploadString(url, RedmineManager.PUT, data);
                }
            };

            return(task);
        }
        public static Task <User> GetCurrentUserAsync(this RedmineManager redmineManager, NameValueCollection parameters = null)
        {
            var task = Task.Factory.StartNew(() =>
            {
                var uri = UrlHelper.GetCurrentUserUrl(redmineManager);

                using (var wc = redmineManager.CreateWebClient(parameters))
                {
                    return(wc.DownloadString(uri));
                }
            });

            return(task.ContinueWith(t => RedmineSerializer.Deserialize <User>(t.Result, redmineManager.MimeFormat)));
        }
Esempio n. 14
0
        public static Task <List <WikiPage> > GetAllWikiPagesAsync(this RedmineManager redmineManager, NameValueCollection parameters, string projectId)
        {
            Task <List <WikiPage> > task = delegate
            {
                var uri = UrlHelper.GetWikisUrl(redmineManager, projectId);
                using (var wc = redmineManager.CreateWebClient(parameters))
                {
                    var response = wc.DownloadString(uri);
                    return(RedmineSerializer.Deserialize <List <WikiPage> >(response, redmineManager.MimeFormat));
                }
            };

            return(task);
        }
        public static Task <PaginatedObjects <WikiPage> > GetAllWikiPagesAsync(this RedmineManager redmineManager, NameValueCollection parameters, string projectId)
        {
            var task = Task.Factory.StartNew(() =>
            {
                var uri = UrlHelper.GetWikisUrl(redmineManager, projectId);
                using (var wc = redmineManager.CreateWebClient(parameters))
                {
                    var response = wc.DownloadString(uri);
                    return(RedmineSerializer.DeserializeList <WikiPage>(response, redmineManager.MimeFormat));
                }
            }, TaskCreationOptions.LongRunning);

            return(task);
        }
        public static Task <byte[]> DownloadFileAsync(this RedmineManager redmineManager, string address)
        {
            var task = Task.Factory.StartNew(() =>
            {
                using (var wc = redmineManager.CreateWebClient(null))
                {
                    wc.Headers.Add(HttpRequestHeader.Accept, "application/octet-stream");
                    var response = wc.DownloadData(address);
                    return(response);
                }
            }, TaskCreationOptions.LongRunning);

            return(task);
        }
Esempio n. 17
0
        public static Task <User> GetCurrentUserAsync(this RedmineManager redmineManager, NameValueCollection parameters = null)
        {
            Task <User> task = delegate
            {
                using (var wc = redmineManager.CreateWebClient(parameters))
                {
                    var uri      = UrlHelper.GetCurrentUserUrl(redmineManager);
                    var response = wc.DownloadString(new Uri(uri));
                    return(RedmineSerializer.Deserialize <User>(response, redmineManager.MimeFormat));
                }
            };

            return(task);
        }
        public static Task UpdateObjectAsync <T>(this RedmineManager redmineManager, string id, T obj, string projectId = null) where T : class, new()
        {
            var task = Task.Factory.StartNew(() =>
            {
                var url = UrlHelper.GetUploadUrl(redmineManager, id, obj, projectId);
                using (var wc = redmineManager.CreateWebClient(null))
                {
                    var data = RedmineSerializer.Serialize(obj, redmineManager.MimeFormat);
                    wc.UploadString(url, RedmineManager.PUT, data);
                }
            }, TaskCreationOptions.LongRunning);

            return(task);
        }
        public static Task DeleteObjectAsync <T>(this RedmineManager redmineManager, string id, NameValueCollection parameters) where T : class, new()
        {
            var task = Task.Factory.StartNew(() =>
            {
                var uri = UrlHelper.GetDeleteUrl <T>(redmineManager, id);

                using (var wc = redmineManager.CreateWebClient(parameters))
                {
                    wc.UploadString(uri, RedmineManager.DELETE, string.Empty);
                }
            }, TaskCreationOptions.LongRunning);

            return(task);
        }
Esempio n. 20
0
        public static Task <byte[]> DownloadFileAsync(this RedmineManager redmineManager, string address)
        {
            Task <byte[]> task = delegate
            {
                using (var wc = redmineManager.CreateWebClient(null))
                {
                    wc.Headers.Add(HttpRequestHeader.Accept, "application/octet-stream");
                    var response = wc.DownloadData(address);
                    return(response);
                }
            };

            return(task);
        }
Esempio n. 21
0
        public static Task DeleteObjectAsync <T>(this RedmineManager redmineManager, string id, NameValueCollection parameters) where T : class, new()
        {
            Task task = delegate
            {
                var uri = UrlHelper.GetDeleteUrl <T>(redmineManager, id);

                using (var wc = redmineManager.CreateWebClient(parameters))
                {
                    wc.UploadString(uri, RedmineManager.DELETE, string.Empty);
                }
            };

            return(task);
        }
Esempio n. 22
0
        public static Task <PaginatedObjects <T> > GetPaginatedObjectsAsync <T>(this RedmineManager redmineManager, NameValueCollection parameters) where T : class, new()
        {
            Task <PaginatedObjects <T> > task = delegate
            {
                var url = UrlHelper.GetListUrl <T>(redmineManager, parameters);
                using (var wc = redmineManager.CreateWebClient(parameters))
                {
                    var response = wc.DownloadString(url);
                    return(RedmineSerializer.Deserialize <PaginatedObjects <T> >(response, redmineManager.MimeFormat));
                }
            };

            return(task);
        }
        public static Task <PaginatedObjects <T> > GetPaginatedObjectsAsync <T>(this RedmineManager redmineManager, NameValueCollection parameters) where T : class, new()
        {
            var task = Task.Factory.StartNew(() =>
            {
                var url = UrlHelper.GetListUrl <T>(redmineManager, parameters);
                using (var wc = redmineManager.CreateWebClient(parameters))
                {
                    var response = wc.DownloadString(url);
                    return(RedmineSerializer.DeserializeList <T>(response, redmineManager.MimeFormat));
                }
            }, TaskCreationOptions.LongRunning);

            return(task);
        }
Esempio n. 24
0
        public static Task <WikiPage> GetWikiPageAsync(this RedmineManager redmineManager, string projectId, NameValueCollection parameters, string pageName, uint version = 0)
        {
            Task <WikiPage> task = delegate
            {
                var uri = UrlHelper.GetWikiPageUrl(redmineManager, projectId, parameters, pageName, version);
                using (var wc = redmineManager.CreateWebClient(parameters))
                {
                    var response = wc.DownloadString(uri);
                    return(RedmineSerializer.Deserialize <WikiPage>(response, redmineManager.MimeFormat));
                }
            };

            return(task);
        }
Esempio n. 25
0
 /// <summary>
 /// Executes the download file.
 /// </summary>
 /// <param name="redmineManager">The redmine manager.</param>
 /// <param name="address">The address.</param>
 /// <param name="methodName">Name of the method.</param>
 /// <returns></returns>
 public static byte[] ExecuteDownloadFile(RedmineManager redmineManager, string address, string methodName)
 {
     using (RedmineWebClient wc = redmineManager.CreateWebClient(null, true))
     {
         try
         {
             return(wc.DownloadData(address));
         }
         catch (System.Net.WebException webException)
         {
             webException.HandleWebException(methodName, redmineManager.MimeFormat);
         }
         return(null);
     }
 }
 /// <summary>
 /// Executes the download file.
 /// </summary>
 /// <param name="redmineManager">The redmine manager.</param>
 /// <param name="address">The address.</param>
 /// <param name="methodName">Name of the method.</param>
 /// <returns></returns>
 public static async Task <byte[]> ExecuteDownloadFile(RedmineManager redmineManager, string address, string methodName)
 {
     using (var wc = redmineManager.CreateWebClient(null, true))
     {
         try
         {
             return(await wc.DownloadDataTaskAsync(address));
         }
         catch (WebException webException)
         {
             webException.HandleWebException(methodName, redmineManager.MimeFormat);
         }
         return(null);
     }
 }
Esempio n. 27
0
 /// <summary>
 /// Executes the download file.
 /// </summary>
 /// <param name="redmineManager">The redmine manager.</param>
 /// <param name="address">The address.</param>
 /// <returns></returns>
 public static byte[] ExecuteDownloadFile(RedmineManager redmineManager, string address)
 {
     using (var wc = redmineManager.CreateWebClient(null, true))
     {
         try
         {
             return(wc.DownloadData(address));
         }
         catch (WebException webException)
         {
             webException.HandleWebException(redmineManager.Serializer);
         }
         return(null);
     }
 }
Esempio n. 28
0
 /// <summary>
 /// Executes the download file.
 /// </summary>
 /// <param name="redmineManager">The redmine manager.</param>
 /// <param name="address">The address.</param>
 /// <returns></returns>
 public static async Task <byte[]> ExecuteDownloadFile(RedmineManager redmineManager, string address)
 {
     using (var wc = redmineManager.CreateWebClient(null, true))
     {
         try
         {
             return(await wc.DownloadDataTaskAsync(address).ConfigureAwait(false));
         }
         catch (WebException webException)
         {
             webException.HandleWebException(redmineManager.Serializer);
         }
         return(null);
     }
 }
Esempio n. 29
0
        public static Task <Upload> UploadFileAsync(this RedmineManager redmineManager, byte[] data)
        {
            Task <Upload> task = delegate
            {
                var uri = UrlHelper.GetUploadFileUrl(redmineManager);
                using (var wc = redmineManager.CreateWebClient(null))
                {
                    var response = wc.UploadData(uri, RedmineManager.POST, data);

                    var responseString = Encoding.ASCII.GetString(response);
                    return(RedmineSerializer.Deserialize <Upload>(responseString, redmineManager.MimeFormat));
                }
            };

            return(task);
        }
Esempio n. 30
0
        public static Task <WikiPage> CreateOrUpdateWikiPageAsync(this RedmineManager redmineManager, string projectId, string pageName, WikiPage wikiPage)
        {
            Task <WikiPage> task = delegate
            {
                var uri  = UrlHelper.GetWikiCreateOrUpdaterUrl(redmineManager, projectId, pageName);
                var data = RedmineSerializer.Serialize(wikiPage, redmineManager.MimeFormat);

                using (var wc = redmineManager.CreateWebClient(null))
                {
                    var response = wc.UploadString(uri, RedmineManager.PUT, data);
                    return(RedmineSerializer.Deserialize <WikiPage>(response, redmineManager.MimeFormat));
                }
            };

            return(task);
        }