/// <summary>
        ///     Creates the or update wiki page asynchronous.
        /// </summary>
        /// <param name="redmineManager">The redmine manager.</param>
        /// <param name="projectId">The project identifier.</param>
        /// <param name="pageName">Name of the page.</param>
        /// <param name="wikiPage">The wiki page.</param>
        /// <returns></returns>
        public static async Task <WikiPage> CreateOrUpdateWikiPageAsync(this RedmineManager redmineManager, string projectId, string pageName, WikiPage wikiPage)
        {
            var uri  = UrlHelper.GetWikiCreateOrUpdaterUrl(redmineManager, projectId, pageName);
            var data = RedmineSerializer.Serialize(wikiPage, redmineManager.MimeFormat);

            return(await WebApiAsyncHelper.ExecuteUpload <WikiPage>(redmineManager, uri, HttpVerbs.PUT, data, "CreateOrUpdateWikiPageAsync"));
        }
Beispiel #2
0
        public async Task <T> Put <T>(Uri uri, T data, MimeType mimeType) where T : class, new()
        {
            SetupCredentials();
            httpClient.AddImpersonationHeaderIfSet(ImpersonateUser);

            var serializedData = RedmineSerializer.Serialize(data, mimeType);

            serializedData = sanitizeRegex.Replace(serializedData, "\r\n");
            var requestContent = new StringContent(serializedData, Encoding.UTF8, $"{APPLICATION}/{UrlBuilder.mimeTypes[mimeType]}");

            using (var responseMessage = await httpClient.PutAsync(uri.ToString(), requestContent).ConfigureAwait(false))
            {
                var tc = new TaskCompletionSource <T>();
                if (responseMessage.IsSuccessStatusCode)
                {
                    var responseContent = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);

                    tc.SetResult(string.IsNullOrWhiteSpace(responseContent)
                        ? data
                        : RedmineSerializer.Deserialize <T>(responseContent, mimeType));
                }
                else
                {
                    tc.SetException(await responseMessage.CreateExceptionAsync(mimeType).ConfigureAwait(false));
                }
                return(await tc.Task);
            }
        }
Beispiel #3
0
        /// <summary>
        ///     Creates a new Redmine object.
        /// </summary>
        /// <typeparam name="T">The type of object to create.</typeparam>
        /// <param name="obj">The object to create.</param>
        /// <param name="ownerId">The owner identifier.</param>
        /// <returns></returns>
        /// <exception cref="RedmineException"></exception>
        /// <remarks>
        ///     When trying to create an object with invalid or missing attribute parameters, you will get a 422 Unprocessable
        ///     Entity response. That means that the object could not be created.
        /// </remarks>
        /// <code>
        ///   <example>
        ///         var project = new Project();
        ///         project.Name = "test";
        ///         project.Identifier = "the project identifier";
        ///         project.Description = "the project description";
        ///         redmineManager.CreateObject(project);
        ///     </example>
        /// </code>
        public T CreateObject <T>(T obj, string ownerId) where T : class, new()
        {
            var url  = UrlHelper.GetCreateUrl <T>(this, ownerId);
            var data = RedmineSerializer.Serialize(obj, MimeFormat);

            return(WebApiHelper.ExecuteUpload <T>(this, url, HttpVerbs.POST, data, "CreateObject"));
        }
        /// <summary>
        ///     Creates a new Redmine object. This method does not block the calling thread.
        /// </summary>
        /// <typeparam name="T">The type of object to create.</typeparam>
        /// <param name="redmineManager">The redmine manager.</param>
        /// <param name="obj">The object to create.</param>
        /// <param name="ownerId">The owner identifier.</param>
        /// <returns></returns>
        public static async Task <T> CreateObjectAsync <T>(this RedmineManager redmineManager, T obj, string ownerId)
            where T : class, new()
        {
            var uri  = UrlHelper.GetCreateUrl <T>(redmineManager, ownerId);
            var data = RedmineSerializer.Serialize(obj, redmineManager.MimeFormat);

            return(await WebApiAsyncHelper.ExecuteUpload <T>(redmineManager, uri, HttpVerbs.POST, data, "CreateObjectAsync"));
        }
Beispiel #5
0
        /// <summary>
        ///     Updates a Redmine object.
        /// </summary>
        /// <typeparam name="T">The type of object to be update.</typeparam>
        /// <param name="id">The id of the object to be update.</param>
        /// <param name="obj">The object to be update.</param>
        /// <param name="projectId">The project identifier.</param>
        /// <exception cref="RedmineException"></exception>
        /// <remarks>
        ///     When trying to update an object with invalid or missing attribute parameters, you will get a
        ///     422(RedmineException) Unprocessable Entity response. That means that the object could not be updated.
        /// </remarks>
        /// <code></code>
        public void UpdateObject <T>(string id, T obj, string projectId) where T : class, new()
        {
            var url  = UrlHelper.GetUploadUrl(this, id, obj, projectId);
            var data = RedmineSerializer.Serialize(obj, MimeFormat);

            data = Regex.Replace(data, @"\r\n|\r|\n", "\r\n");
            WebApiHelper.ExecuteUpload(this, url, HttpVerbs.PUT, data, "UpdateObject");
        }
        /// <summary>
        ///     Updates the object asynchronous.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="redmineManager">The redmine manager.</param>
        /// <param name="id">The identifier.</param>
        /// <param name="obj">The object.</param>
        /// <param name="projectId">The project identifier.</param>
        /// <returns></returns>
        public static async Task UpdateObjectAsync <T>(this RedmineManager redmineManager, string id, T obj, string projectId = null)
            where T : class, new()
        {
            var uri  = UrlHelper.GetUploadUrl(redmineManager, id, obj, projectId);
            var data = RedmineSerializer.Serialize(obj, redmineManager.MimeFormat);

            data = Regex.Replace(data, @"\r\n|\r|\n", "\r\n");

            await WebApiAsyncHelper.ExecuteUpload <T>(redmineManager, uri, HttpVerbs.PUT, data, "UpdateObjectAsync");
        }
Beispiel #7
0
        /// <summary>
        ///     Updates the attachment.
        /// </summary>
        /// <param name="issueId">The issue identifier.</param>
        /// <param name="attachment">The attachment.</param>
        public void UpdateAttachment(int issueId, Attachment attachment)
        {
            var address     = UrlHelper.GetAttachmentUpdateUrl(this, issueId);
            var attachments = new Attachments {
                { attachment.Id, attachment }
            };
            var data = RedmineSerializer.Serialize(attachments, MimeFormat);

            WebApiHelper.ExecuteUpload(this, address, HttpVerbs.PATCH, data, "UpdateAttachment");
        }
Beispiel #8
0
        /// <summary>
        ///     Creates or updates a wiki page.
        /// </summary>
        /// <param name="projectId">The project id or identifier.</param>
        /// <param name="pageName">The wiki page name.</param>
        /// <param name="wikiPage">The wiki page to create or update.</param>
        /// <returns></returns>
        public WikiPage CreateOrUpdateWikiPage(string projectId, string pageName, WikiPage wikiPage)
        {
            var result = RedmineSerializer.Serialize(wikiPage, MimeFormat);

            if (string.IsNullOrEmpty(result))
            {
                return(null);
            }

            var url = UrlHelper.GetWikiCreateOrUpdaterUrl(this, projectId, pageName);

            return(WebApiHelper.ExecuteUpload <WikiPage>(this, url, HttpVerbs.PUT, result, "CreateOrUpdateWikiPage"));
        }
Beispiel #9
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 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);
        }
Beispiel #11
0
        public async Task <T> Post <T>(Uri uri, T data, MimeType mimeType) where T : class, new()
        {
            SetupCredentials();
            httpClient.AddImpersonationHeaderIfSet(ImpersonateUser);

            var content = new StringContent(RedmineSerializer.Serialize(data, mimeType), Encoding.UTF8,
                                            $"{APPLICATION}/{UrlBuilder.mimeTypes[mimeType]}");

            using (var responseMessage = await httpClient.PostAsync(uri.ToString(), content).ConfigureAwait(false))
            {
                var tc = await responseMessage.CreateTaskCompletionSource <T>(mimeType).ConfigureAwait(false);

                return(await tc.Task);
            }
        }
Beispiel #12
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);
        }
Beispiel #13
0
        public static Task <T> CreateObjectAsync <T>(this RedmineManager redmineManager, T obj, string ownerId) where T : class, new()
        {
            Task <T> task = delegate
            {
                var url  = UrlHelper.GetCreateUrl <T>(redmineManager, ownerId);
                var data = RedmineSerializer.Serialize(obj, redmineManager.MimeFormat);

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

            return(task);
        }
        public static Task <T> CreateObjectAsync <T>(this RedmineManager redmineManager, T obj, string ownerId) where T : class, new()
        {
            var task = Task.Factory.StartNew(() =>
            {
                var url  = UrlHelper.GetCreateUrl <T>(redmineManager, ownerId);
                var data = RedmineSerializer.Serialize(obj, redmineManager.MimeFormat);

                using (var wc = redmineManager.CreateWebClient(null))
                {
                    var response = wc.UploadString(url, RedmineManager.POST, data);
                    return(RedmineSerializer.Deserialize <T>(response, redmineManager.MimeFormat));
                }
            }, TaskCreationOptions.LongRunning);

            return(task);
        }
        public static Task <WikiPage> CreateOrUpdateWikiPageAsync(this RedmineManager redmineManager, string projectId, string pageName, WikiPage wikiPage)
        {
            var task = Task.Factory.StartNew(() =>
            {
                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));
                }
            }, TaskCreationOptions.LongRunning);

            return(task);
        }
        public static async Task UpdateObjectAsync <T>(this RedmineManager redmineManager, string id, T obj, string projectId = null) where T : class, new()
        {
            var url = UrlHelper.GetUploadUrl(redmineManager, id, obj, projectId);

            using (var wc = redmineManager.CreateWebClient(null))
            {
                var data = RedmineSerializer.Serialize(obj, redmineManager.MimeFormat);
                try
                {
                    await wc.UploadStringTaskAsync(url, RedmineManager.PUT, data).ConfigureAwait(false);
                }
                catch (WebException wex)
                {
                    wex.HandleWebException("UpdateObjectAsync", redmineManager.MimeFormat);
                }
            }
        }
Beispiel #17
0
        public void ShouldSerializeFileXml()
        {
            const string expected = @"<file><token>21.01a1d7b1c2ffcbbc9ecf14debeec27d8</token><version_id>2</version_id><filename>foo-1.0-src.tar.tgz</filename><description>Foo App source code</description></file>";

            var file = new File
            {
                Token   = "21.01a1d7b1c2ffcbbc9ecf14debeec27d8",
                Version = new IdentifiableName {
                    Id = 2
                },
                Filename    = "foo-1.0-src.tar.tgz",
                Description = "Foo App source code"
            };

            var actual = RedmineSerializer.Serialize(file, Net.Api.MimeType.Xml);

            Assert.True(actual.Equals(expected), "File type serialization failed.");
        }
        ///  <summary>
        ///  Creates a new Redmine object. This method does not block the calling thread.
        ///  </summary>
        ///  <typeparam name="T">The type of object to create.</typeparam>
        /// <param name="redmineManager"></param>
        /// <param name="obj">The object to create.</param>
        /// <param name="ownerId"></param>
        ///  <returns></returns>
        public static async Task <T> CreateObjectAsync <T>(this RedmineManager redmineManager, T obj, string ownerId) where T : class, new()
        {
            var url  = UrlHelper.GetCreateUrl <T>(redmineManager, ownerId);
            var data = RedmineSerializer.Serialize(obj, redmineManager.MimeFormat);

            using (var wc = redmineManager.CreateWebClient(null))
            {
                string response = null;
                try
                {
                    response = await wc.UploadStringTaskAsync(url, RedmineManager.POST, data).ConfigureAwait(false);
                }
                catch (WebException wex)
                {
                    wex.HandleWebException("CreateObjectAsync", redmineManager.MimeFormat);
                }
                return(RedmineSerializer.Deserialize <T>(response, redmineManager.MimeFormat));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="redmineManager"></param>
        /// <param name="projectId"></param>
        /// <param name="pageName"></param>
        /// <param name="wikiPage"></param>
        /// <returns></returns>
        public static async Task <WikiPage> CreateOrUpdateWikiPageAsync(this RedmineManager redmineManager, string projectId, string pageName, WikiPage wikiPage)
        {
            var uri  = UrlHelper.GetWikiCreateOrUpdaterUrl(redmineManager, projectId, pageName);
            var data = RedmineSerializer.Serialize(wikiPage, redmineManager.MimeFormat);

            using (var wc = redmineManager.CreateWebClient(null))
            {
                try
                {
                    var response = await wc.UploadStringTaskAsync(uri, RedmineManager.PUT, data).ConfigureAwait(false);

                    return(RedmineSerializer.Deserialize <WikiPage>(response, redmineManager.MimeFormat));
                }
                catch (WebException wex)
                {
                    wex.HandleWebException("CreateOrUpdateWikiPageAsync", redmineManager.MimeFormat);
                }
                return(null);
            }
        }