Пример #1
0
        public bool LoadPrivateData()
        {
            string[] args = Environment.GetCommandLineArgs();
            foreach (var arg in args.Select(a => a.ToLower()))
            {
                if (arg.StartsWith("projectid=")) ProjectId = Convert.ToInt32(arg.Replace("projectid=", ""));
                if (arg.StartsWith("storyid=")) StoryId = Convert.ToInt32(arg.Replace("storyid=", ""));
            }
            if (ProjectId == 0 || StoryId == 0)
            {
                MessageBox.Show("ProjectId and StoryId are both required.");
                return false;
            }

            // Load the config
            Config config = new Config();
            try
            {
                config = PivotalUtils.GetConfig(baseDir + configFileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }

            // Get the password if it is not set
            if (string.IsNullOrEmpty(config.Password))
            {
                if (PasswordBox("Password Required", "PivotalTracker Password:"******"GrindstonPivotalLink unable to run without password.");
                        return false;
                    }
                }
                else
                {
                    MessageBox.Show("GrindstonPivotalLink unable to run without password.");
                    return false;
                }
            }

            try
            {
                token = PivotalUtils.GetPivotalTrackerUserToken(config.Email, config.Password);
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to retrieve user token.");
                return false;
            }

            // Get story node and populate private story object
            XmlNode storyNode = new XmlDocument();
            try
            {
                storyNode = PivotalUtils.GetStoryNode(token, ProjectId, StoryId);
                story = PivotalUtils.GetStoryFromStoryNode(storyNode);
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to retireve story data from PivotalTracker.");
                return false;
            }

            // Get comments from story node and build private comments string
            try
            {
                var listComments = PivotalUtils.GetCommentsFromStoryNode(storyNode);
                var sbComments = new StringBuilder();
                if (listComments.Count > 0)
                {
                    foreach (var comment in listComments)
                    {
                        sbComments.AppendLine(string.Concat(comment.timestamp.ToShortTimeString(), " - ", comment.author));
                        sbComments.AppendLine(comment.text);
                        sbComments.AppendLine();
                    }
                }
                else
                {
                    sbComments.AppendLine("No comments found.");
                }
                comments = sbComments.ToString();
            }
            catch (Exception)
            {
                comments = "Unable to retrieve story comments from PivotalTracker.";
            }

            // Set the form tasks
            try
            {
                tasks = PivotalUtils.GetStoryTasks(token, ProjectId, StoryId);
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to retrieve story tasks from PivotalTracker.");
                return false;
            }

            // Set up the story owner
            try
            {
                var authenticityToken = string.Empty;
                var sessionCookie = PivotalUtils.GetPivotalTrackerSessionCookie(config.Email, config.Password, out authenticityToken);
                owners = PivotalUtils.GetUserIds(ref sessionCookie);
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to retrieve potential story owners from PivotalTracker.");
                return false;
            }

            return true;
        }
 public static XmlElement CreateTaskElement(XmlDocument xmlDoc, string projectName, Story story, string batchFilePath)
 {
     var element = xmlDoc.CreateElement("task");
     element.SetAttribute("name", story.name);
     if (story.dateTimeCompleted != DateTime.MinValue)
         element.SetAttribute("complete", story.dateTimeCompleted.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.ffK"));
     element.SetAttribute("dueAlerted", "False");
     element.SetAttribute("estimateAlerted", "False");
     var customValue = xmlDoc.CreateElement("customValue");
     customValue.SetAttribute("name", "id");
     customValue.SetAttribute("value", story.id.ToString());
     element.AppendChild(customValue);
     customValue = xmlDoc.CreateElement("customValue");
     customValue.SetAttribute("name", "Type");
     customValue.SetAttribute("value", story.type);
     element.AppendChild(customValue);
     customValue = xmlDoc.CreateElement("customValue");
     customValue.SetAttribute("name", "Url");
     customValue.SetAttribute("value", story.url);
     element.AppendChild(customValue);
     customValue = xmlDoc.CreateElement("customValue");
     customValue.SetAttribute("name", "Update");
     customValue.SetAttribute("value", batchFilePath);
     element.AppendChild(customValue);
     customValue = xmlDoc.CreateElement("customValue");
     customValue.SetAttribute("name", "State");
     customValue.SetAttribute("value", story.state);
     element.AppendChild(customValue);
     customValue = xmlDoc.CreateElement("customValue");
     customValue.SetAttribute("name", "Status");
     customValue.SetAttribute("value", story.status);
     element.AppendChild(customValue);
     customValue = xmlDoc.CreateElement("customValue");
     customValue.SetAttribute("name", "Project");
     customValue.SetAttribute("value", projectName);
     element.AppendChild(customValue);
     customValue = xmlDoc.CreateElement("customValue");
     customValue.SetAttribute("name", "Labels");
     customValue.SetAttribute("value", story.labels);
     element.AppendChild(customValue);
     customValue = xmlDoc.CreateElement("customValue");
     customValue.SetAttribute("name", "Owner");
     customValue.SetAttribute("value", story.owner);
     element.AppendChild(customValue);
     customValue = xmlDoc.CreateElement("customValue");
     customValue.SetAttribute("name", "Filter");
     customValue.SetAttribute("value", story.filter);
     element.AppendChild(customValue);
     customValue = xmlDoc.CreateElement("customValue");
     customValue.SetAttribute("name", "Order");
     customValue.SetAttribute("value", story.order.ToString());
     element.AppendChild(customValue);
     return element;
 }