示例#1
0
        public List<Story> ReadAllStories(string area, string filePath)
        {
            var doc = new XmlDocument();
            doc.Load(filePath);

            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable);
            namespaceManager.AddNamespace("m", "urn:schemas-microsoft-com:office:spreadsheet");
            namespaceManager.AddNamespace("ss", "urn:schemas-microsoft-com:office:spreadsheet");

            var x = doc.SelectSingleNode("//m:Table", namespaceManager);
            List<Story> list = new List<Story>();
            foreach (XmlElement row in doc.SelectNodes("//m:Table/m:Row", namespaceManager))
            {
                string[] data = new string[8];
                int index = 0;
                foreach (XmlElement cell in row.ChildNodes)
                {
                    if (cell.Attributes["Index", "urn:schemas-microsoft-com:office:spreadsheet"] != null)
                    {
                        index =
                            int.Parse(cell.Attributes["Index", "urn:schemas-microsoft-com:office:spreadsheet"].InnerText)-1;
                    }
                    data[index] = cell.InnerText;
                    index++;
                }

                var story = new Story();
                story.Title = string.Format("{0} - {1} {2}", area, System.Security.SecurityElement.Escape(data[0]), System.Security.SecurityElement.Escape(data[1]));
                StringBuilder stringBuilder = new StringBuilder(data[2] + data[3]);
                if (!string.IsNullOrWhiteSpace(data[5]))
                    stringBuilder.AppendFormat("<P> \n </P><BR/><P>\nAcceptance Criteria: \n{0}</P>", System.Security.SecurityElement.Escape(data[5]));
                if (!string.IsNullOrWhiteSpace(data[4]))
                    stringBuilder.AppendFormat("<P> \n </P><BR/><P>\nAssumptions: \n{0}</P>", System.Security.SecurityElement.Escape(data[4]));
                if (!string.IsNullOrWhiteSpace(data[6]))
                    stringBuilder.AppendFormat("<P> \n </P><BR/><P>\nQuestions: \n{0}</P>", System.Security.SecurityElement.Escape(data[6]));
                story.Description = stringBuilder.ToString();
                if (!string.IsNullOrWhiteSpace(data[7]))
                    story.Estimate = int.Parse(data[7]);
                list.Add(story);
            }

            return list;
        }
示例#2
0
        public void Execute(Story story)
        {
            string createStoryRequest = string.Format(@"
            <Asset>
            <Attribute name=""Name"" act=""set"">{0}</Attribute>
            <Attribute name=""Estimate"" act=""set"">{1}</Attribute>
            <Attribute name=""Description"" act=""set"">{2}</Attribute>
            <Relation name=""Scope"" act=""set"">
            <Asset idref=""Scope:2636"" />
            </Relation>
            </Asset>", story.Title, story.Estimate, story.Description);

            WebRequest request =
                WebRequest.Create(string.Format("http://{0}/VersionOne/rest-1.v1/Data/Story",
                                                HostName));
            request.Method = "POST";
            request.ContentType = "text/xml; charset=utf-8";
            SetBasicAuthHeader(request, "Tom Peplow", "password1");
            byte[] content = Encoding.UTF8.GetBytes(createStoryRequest);
            request.ContentLength = content.Length;

            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(content, 0, content.Length);
                requestStream.Close();
            }
            using (var response = request.GetResponse())
            {
                Console.WriteLine(((HttpWebResponse) response).StatusDescription);
                using (Stream responseStream = response.GetResponseStream())
                {
                    using (var reader = new StreamReader(responseStream))
                    {
                        Console.WriteLine(reader.ReadToEnd());
                        reader.Close();
                    }
                    responseStream.Close();
                }
                response.Close();
            }
        }