Ejemplo n.º 1
0
 public string Post(string url, HtmlForm form, string referer = null, bool isMultiPart = false)
 {
     return(Send(url, "POST", form, referer, isMultiPart));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates issue on Codeplex
        /// </summary>
        /// <param name="issue">Issue to create</param>
        /// <returns>Link to created issue.</returns>
        public string CreateIssue(Issue issue)
        {
            if (issue == null)
            {
                throw new ArgumentNullException("issue");
            }
            if (!IsSignedIn)
            {
                throw new Exception("Not signed in into codeplex.");
            }

            var createIssueUrl = string.Format(@"https://{0}.codeplex.com/WorkItem/Create", _projectName);

            var createIssuePage = _browser.Get(createIssueUrl);
            var form            = HtmlForm.GetForm(createIssuePage, "aspnetForm");
            var elements        = new List <HtmlElement>(form.Elements);

            form.Elements.Clear();

            var file = issue.FileToAttach;

            byte[] fileData = null;
            if (file != null)
            {
                using (var fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
                {
                    fileData = new byte[fs.Length];
                    fs.Read(fileData, 0, fileData.Length);
                }
            }
            form.Elements.Add(new HtmlElement("__RequestVerificationToken", elements.First(t => t.Name == "__RequestVerificationToken").Value));
            form.Elements.Add(new HtmlElement("searchsite", "Search all projects"));
            form.Elements.Add(new HtmlElement("WorkItem.Summary", issue.Summary));
            form.Elements.Add(new HtmlElement("Text", issue.Description));

            if (fileData != null)
            {
                form.Elements.Add(new HtmlElement("PostedFile_text", @"C:\fakepath\" + file.Name));
                form.Elements.Add(new HtmlElement("PostedFile", null)
                {
                    IsFile      = true,
                    File        = fileData,
                    ContentType = "application/octet-stream",
                    FileName    = file.Name
                });
            }
            else
            {
                form.Elements.Add(new HtmlElement("PostedFile_text", null));
                form.Elements.Add(new HtmlElement("PostedFile", null)
                {
                    IsFile = true,
                });
            }

            form.Elements.Add(new HtmlElement("SubscribeCheckBox", "true"));
            form.Elements.Add(new HtmlElement("EmailSubscriptionTypeList", "1"));
            form.Elements.Add(new HtmlElement("StopNotificationsCheckBox", "false"));
            form.Elements.Add(new HtmlElement("SelectedSubscriptionItem", "1"));
            form.Elements.Add(new HtmlElement("SelectedStatus", "Proposed"));
            form.Elements.Add(new HtmlElement("SelectedType", "Issue"));
            form.Elements.Add(new HtmlElement("SelectedPriority", "Low"));
            form.Elements.Add(new HtmlElement("WorkItem.PlannedForRelease", "Unassigned"));
            form.Elements.Add(new HtmlElement("WorkItem.AssignedTo", "Unassigned"));
            form.Elements.Add(new HtmlElement("SelectedComponent", "No Component Selected"));
            form.Elements.Add(new HtmlElement("WorkItem.Custom", null));

            var res = _browser.Post(createIssueUrl, form, createIssueUrl, true);
            // Check that issue was created
            string issueLink         = null;
            var    itemNumberSection = res.IndexOf(@">Item number:</td>", StringComparison.Ordinal);

            if (itemNumberSection >= 0)
            {
                var itemNumberStarts = res.IndexOf(">", itemNumberSection + @">Item number:</td>".Length + 1,
                                                   StringComparison.Ordinal);
                if (itemNumberStarts >= 0)
                {
                    var itemNumberEnds = res.IndexOf("</td>", itemNumberStarts + 1, StringComparison.Ordinal);
                    if (itemNumberEnds >= 0)
                    {
                        var itemNumber = res.Substring(itemNumberStarts + 1, itemNumberEnds - itemNumberStarts - 1);
                        int number;
                        if (Int32.TryParse(itemNumber, out number))
                        {
                            issueLink = string.Format("http://{0}.codeplex.com/workitem/{1}", _projectName, number);
                        }
                    }
                }
            }
            if (issueLink == null)
            {
                throw new Exception("Unable to post issue on Codeplex.");
            }
            return(issueLink);
        }
Ejemplo n.º 3
0
 public string Get(string url, HtmlForm form = null, string referer = null)
 {
     return(Send(url, "GET", form, referer));
 }