/// <summary>
        /// Gets s single story for a project
        /// </summary>
        /// <param name="user">The user to get the ApiToken from</param>
        /// <param name="projectId">The id of the project to get stories for</param>
        /// <param name="storyId">The id of the story to get</param>
        /// <returns>the stories for the project</returns>
        public static PivotalStory FetchStory(PivotalUser user, int projectId, string storyId)
        {
            string       url    = String.Format("{0}/projects/{1}/story/{2}?token={3}", PivotalService.BaseUrl, projectId.ToString(), storyId, user.ApiToken);
            XmlDocument  xmlDoc = PivotalService.GetData(url);
            PivotalStory story  = SerializationHelper.DeserializeFromXmlDocument <PivotalStory>(xmlDoc);

            return(story);
        }
        /// <summary>
        /// Deletes a story from Pivotal
        /// </summary>
        /// <param name="user">The user to get the ApiToken from</param>
        /// <param name="projectId">The project id</param>
        /// <param name="story">The story id</param>
        /// <returns>The story that was deleted</returns>
        public static PivotalStory DeleteStory(PivotalUser user, string projectId, PivotalStory story)
        {
            string      url      = String.Format("{0}/projects/{1}/story/{2}?token={3}", PivotalService.BaseUrl, projectId, story.Id, user.ApiToken);
            XmlDocument xml      = SerializationHelper.SerializeToXmlDocument <PivotalStory>(story);
            string      storyXml = PivotalService.CleanXmlForSubmission(xml, "//story", ExcludeNodesOnSubmit, true);
            XmlDocument response = PivotalService.SubmitData(url, storyXml, ServiceMethod.DELETE);

            return(story);
        }
        /// <summary>
        /// Updates the story with new values
        /// </summary>
        /// <remarks>Uses reflection to iterate properties, so does carry some overhead in terms of performance</remarks>
        /// <param name="user">The user to get the ApiToken from</param>
        /// <returns>The updated story instance</returns>
        public PivotalStory UpdateStory(PivotalUser user)
        {
            PivotalStory updatedStory = PivotalStory.UpdateStory(user, ProjectId.GetValueOrDefault().ToString(), this);

            System.Reflection.PropertyInfo[] properties = this.GetType().GetProperties();
            foreach (System.Reflection.PropertyInfo p in properties)
            {
                p.SetValue(this, p.GetValue(updatedStory, null), null);
            }
            return(this);
        }
        /// <summary>
        /// Updates the task with new values
        /// </summary>
        /// <remarks>Uses reflection to iterate properties, so does carry some overhead in terms of performance</remarks>
        /// <param name="user">The user to get the ApiToken from</param>
        /// <param name="story">The story the task belongs to</param>
        /// <returns>The updated task instance</returns>
        public PivotalTask UpdateTask(PivotalUser user, PivotalStory story)
        {
            PivotalTask updatedTask = PivotalTask.UpdateTask(user, story.ProjectId.GetValueOrDefault(), story.Id.GetValueOrDefault(), this);

            System.Reflection.PropertyInfo[] properties = this.GetType().GetProperties();
            foreach (System.Reflection.PropertyInfo p in properties)
            {
                p.SetValue(this, p.GetValue(updatedTask, null), null);
            }
            return(this);
        }
 /// <summary>
 /// Fetches current stories from Pivotal and optionally reloads the cache and uses the cache
 /// </summary>
 /// <param name="user">The user to get the ApiToken from</param>
 /// <param name="options">Options for caching</param>
 /// <returns>stories for the project</returns>
 public IList <PivotalStory> FetchStories(PivotalUser user, PivotalFetchOptions options)
 {
     if (options.RefreshCache)
     {
         _storyCache = (List <PivotalStory>)PivotalStory.FetchStories(user, Id.GetValueOrDefault());
     }
     if (options.UseCachedItems)
     {
         return(_storyCache);
     }
     return(PivotalStory.FetchStories(user, Id.GetValueOrDefault()));
 }
 /// <summary>
 /// Fetches current releases from Pivotal and optionally reloads the cache and uses the cache
 /// </summary>
 /// <remarks>The cache is updated with all stories, not just releases, so this can be more intensive than intended.</remarks>
 /// <param name="user">The user to get the ApiToken from</param>
 /// <param name="options">Options for caching</param>
 /// <returns>releases for the project</returns>
 public IList <PivotalStory> FetchReleases(PivotalUser user, PivotalFetchOptions options)
 {
     if (options.RefreshCache)
     {
         _storyCache = (List <PivotalStory>)PivotalStory.FetchStories(user, Id.GetValueOrDefault());
     }
     if (options.UseCachedItems)
     {
         return(_storyCache.Where(x => x.StoryType == PivotalStoryType.release).ToList());
     }
     return(PivotalStory.FetchStories(user, Id.GetValueOrDefault(), PivotalFilterHelper.BuildStoryTypeFilter(PivotalStoryType.release, "")));
 }
        /// <summary>
        /// Adds a story to Pivotal
        /// </summary>
        /// <param name="user">The user to get the ApiToken from</param>
        /// <param name="projectId">The id of the project</param>
        /// <param name="story">The story to add</param>
        /// <param name="saveTasks">Controls whether any tasks associated with the story should also be saved.</param>
        /// <returns>The created story</returns>
        public static PivotalStory AddStory(PivotalUser user, int projectId, PivotalStory story, bool saveTasks)
        {
            string       url        = String.Format("{0}/projects/{1}/stories?token={2}", PivotalService.BaseUrl, projectId.ToString(), user.ApiToken);
            XmlDocument  xml        = SerializationHelper.SerializeToXmlDocument <PivotalStory>(story);
            string       storyXml   = PivotalService.CleanXmlForSubmission(xml, "//story", ExcludeNodesOnSubmit, true);
            XmlDocument  response   = PivotalService.SubmitData(url, storyXml, ServiceMethod.POST);
            PivotalStory savedStory = SerializationHelper.DeserializeFromXmlDocument <PivotalStory>(response);

            if (saveTasks)
            {
                foreach (PivotalTask task in story.Tasks)
                {
                    if (task.TaskId.HasValue)
                    {
                        PivotalTask.UpdateTask(user, projectId, savedStory.Id.GetValueOrDefault(), task);
                    }
                    else
                    {
                        PivotalTask.AddTask(user, projectId, savedStory.Id.GetValueOrDefault(), task);
                    }
                }
            }
            return(savedStory);
        }
 /// <summary>
 /// Adds a story to Pivotal
 /// </summary>
 /// <param name="user">The user to get the ApiToken from</param>
 /// <param name="story">The story to add</param>
 /// <param name="saveTasks">Controls whether any tasks associated with the story should also be saved.</param>
 /// <returns>The created story</returns>
 public PivotalStory AddStory(PivotalUser user, PivotalStory story, bool saveTasks)
 {
   return PivotalStory.AddStory(user, this.Id.GetValueOrDefault(), story, saveTasks);
 }
 /// <summary>
 /// Updates a story without requiring a reference
 /// </summary>
 /// <param name="user">The user to get the ApiToken from</param>
 /// <param name="projectId">The project id</param>
 /// <param name="story">The story id</param>
 /// <returns>The updated story instance</returns>
 public static PivotalStory UpdateStory(PivotalUser user, string projectId, PivotalStory story)
 {
     string url = String.Format("{0}/projects/{1}/stories/{2}?token={3}", PivotalService.BaseUrl, projectId, story.Id, user.ApiToken);
       XmlDocument xml = SerializationHelper.SerializeToXmlDocument<PivotalStory>(story);
       string storyXml = PivotalService.CleanXmlForSubmission(xml, "//story", ExcludeNodesOnSubmit, true);
       XmlDocument response = PivotalService.SubmitData(url, storyXml, ServiceMethod.PUT);
       return SerializationHelper.DeserializeFromXmlDocument<PivotalStory>(response);
 }
 /// <summary>
 /// Adds a story to Pivotal
 /// </summary>
 /// <param name="user">The user to get the ApiToken from</param>
 /// <param name="projectId">The id of the project</param>
 /// <param name="story">The story to add</param>
 /// <param name="saveTasks">Controls whether any tasks associated with the story should also be saved.</param>
 /// <returns>The created story</returns>
 public static PivotalStory AddStory(PivotalUser user, int projectId, PivotalStory story, bool saveTasks)
 {
     string url = String.Format("{0}/projects/{1}/stories?token={2}", PivotalService.BaseUrl, projectId.ToString(), user.ApiToken);
       XmlDocument xml = SerializationHelper.SerializeToXmlDocument<PivotalStory>(story);
       string storyXml = PivotalService.CleanXmlForSubmission(xml, "//story", ExcludeNodesOnSubmit, true);
       XmlDocument response = PivotalService.SubmitData(url, storyXml, ServiceMethod.POST);
       PivotalStory savedStory = SerializationHelper.DeserializeFromXmlDocument<PivotalStory>(response);
       if (saveTasks)
       {
     foreach (PivotalTask task in story.Tasks)
     {
       if (task.TaskId.HasValue)
       {
     PivotalTask.UpdateTask(user, projectId, savedStory.Id.GetValueOrDefault(), task);
       }
       else
       {
     PivotalTask.AddTask(user, projectId, savedStory.Id.GetValueOrDefault(), task);
       }
     }
       }
       return savedStory;
 }
 /// <summary>
 /// Adds a story to Pivotal
 /// </summary>
 /// <param name="user">The user to get the ApiToken from</param>
 /// <param name="projectId">The id of the project</param>
 /// <param name="story">The story to add</param>
 /// <returns>The created story</returns>
 public static PivotalStory AddStory(PivotalUser user, int projectId, PivotalStory story)
 {
     return AddStory(user, projectId, story, false);
 }
        public PivotalExcelImportInfo ImportInfo(string filePath)
        {
            string genericLabels = String.Empty;

            FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
            IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
            DataSet ds = excelReader.AsDataSet();
            var dt = ds.Tables[0];
            excelReader.Close();

            var headerRow = 0;
            var totalRow = 0;

            for (var r = 0; r < dt.Rows.Count; r++)
            {
                var txt = dt.Rows[r][0];

                if (String.IsNullOrEmpty(genericLabels) && txt != null && txt.ToString().ToUpperInvariant() == this.genericLabelText)
                {
                    genericLabels = (dt.Rows[r][1] != null) ? dt.Rows[r][1].ToString() : String.Empty;
                }

                if (txt != null && txt.ToString().ToUpperInvariant() == this.headerRowText)
                {
                    headerRow = r;
                    continue;
                }
                if (txt != null && txt.ToString().ToUpperInvariant() == this.totalRowText)
                {
                    totalRow = r;
                    break;
                }

            }

            //-- import into list
            var stories = new List<PivotalStory>();
            for (int r = (headerRow + 1); r <= (totalRow - 1); r++)
            {
                var row = (DataRow)dt.Rows[r];

                // TODO - put in Enum
                var colName = 1;
                var colDesc = 2;
                var colEstimateHours = 3;
                var colEstimatePts = 4;
                var colRemaining = 5;
                var colRequestor = 6;
                var colOwner = 7;
                var colLabels = 8;

                //-- TODO - Check for nothing!
                if (String.IsNullOrEmpty(String.Concat(row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString())))
                    continue;

                var story = new PivotalStory();
                story.Name = row[colName].ToString();
                story.Description = row[colDesc].ToString();
                story.Estimate = (row[colEstimatePts] != null && !string.IsNullOrEmpty(row[colEstimatePts].ToString())) ? int.Parse(row[colEstimatePts].ToString()) : 0;
                story.Requestor = row[colRequestor].ToString();
                story.Owner = row[colOwner].ToString();
                var labels = row[colLabels].ToString();
                if (!String.IsNullOrEmpty(labels))
                {
                    story.LabelValues = labels.Split(',').Select(s => s.Trim()).ToList();
                }

                stories.Add(story);

            }

            return new PivotalExcelImportInfo(stories, genericLabels);
        }
Exemplo n.º 13
0
 public void LoadTasks(PivotalStory story)
 {
     story.LoadTasks(_user);
 }
Exemplo n.º 14
0
 public void LoadNotes(PivotalStory story)
 {
     story.LoadNotes(_user);
 }
 /// <summary>
 /// Updates the task with new values
 /// </summary>
 /// <remarks>Uses reflection to iterate properties, so does carry some overhead in terms of performance</remarks>
 /// <param name="user">The user to get the ApiToken from</param>
 /// <param name="story">The story the task belongs to</param>
 /// <returns>The updated task instance</returns>
 public PivotalTask UpdateTask(PivotalUser user, PivotalStory story)
 {
   PivotalTask updatedTask = PivotalTask.UpdateTask(user, story.ProjectId.GetValueOrDefault(), story.Id.GetValueOrDefault(), this);
   System.Reflection.PropertyInfo[] properties = this.GetType().GetProperties();
   foreach (System.Reflection.PropertyInfo p in properties)
   {
     p.SetValue(this, p.GetValue(updatedTask, null), null);
   }
   return this;
 }
 /// <summary>
 /// Fetches current stories from Pivotal
 /// </summary>
 /// <param name="user">The user to get the ApiToken from</param>
 /// <returns>stories for the project</returns>
 public IList <PivotalStory> FetchStories(PivotalUser user)
 {
     return(PivotalStory.FetchStories(user, Id.GetValueOrDefault()));
 }
 /// <summary>
 /// Adds a story to Pivotal
 /// </summary>
 /// <param name="user">The user to get the ApiToken from</param>
 /// <param name="projectId">The id of the project</param>
 /// <param name="story">The story to add</param>
 /// <returns>The created story</returns>
 public static PivotalStory AddStory(PivotalUser user, int projectId, PivotalStory story)
 {
     return(AddStory(user, projectId, story, false));
 }
 /// <summary>
 /// Adds a story to Pivotal
 /// </summary>
 /// <param name="user">The user to get the ApiToken from</param>
 /// <param name="story">The story to add</param>
 /// <param name="saveTasks">Controls whether any tasks associated with the story should also be saved.</param>
 /// <returns>The created story</returns>
 public PivotalStory AddStory(PivotalUser user, PivotalStory story, bool saveTasks)
 {
     return(PivotalStory.AddStory(user, this.Id.GetValueOrDefault(), story, saveTasks));
 }
 /// <summary>
 /// Fetches current releases from Pivotal
 /// </summary>
 /// <param name="user">The user to get the ApiToken from</param>
 /// <returns>releases for the project</returns>
 public IList <PivotalStory> FetchReleases(PivotalUser user)
 {
     return(PivotalStory.FetchStories(user, Id.GetValueOrDefault(), PivotalFilterHelper.BuildStoryTypeFilter(PivotalStoryType.release, "")));
 }
Exemplo n.º 20
0
        /// <summary>
        ///  Not yet used
        /// </summary>
        /// <param name="stories"></param>
        /// <param name="projectId"></param>
        /// <returns></returns>
        public IEnumerable<PivotalStory> SaveStories(List<PivotalStory> stories, int? projectId)
        {
            var proj = this.Projects().Where(x => x.Id == projectId).FirstOrDefault();
            if (proj != null)
            {
                foreach (var story in stories)
                {
                    var st = new PivotalStory(PivotalStoryType.feature, story.Name, story.Description);
                    st.Estimate = story.Estimate;
                    st.Owner = story.Owner;
                    st.Requestor = story.Requestor;
                    st.Labels = story.Labels;

                    proj.AddStory(this.membershipService.CurrentUser(), st, false);
                }
            }
            // TODO! Return a helpful object
            return Enumerable.Empty<PivotalStory>();
        }
Exemplo n.º 21
0
        public ActionResult Publish(List<PivotalStory> stories, int? projectId)
        {
            //pivotalService.SaveStories(stories, projectId);
            // TODO! Update and use pivotalService method
            var proj = pivotalService.Projects().Where(x => x.Id == projectId).FirstOrDefault();
            if (proj != null)
            {
                foreach (var story in stories)
                {
                    var st = new PivotalStory(PivotalStoryType.feature, story.Name, story.Description);
                    st.Estimate = story.Estimate;
                    st.Owner = story.Owner;
                    st.Requestor = story.Requestor;
                    st.Labels = story.Labels;

                    proj.AddStory(membershipService.CurrentUser(), st, false);
                }
            }

            //var result = new JsonResult();
            return Json( new { ProjectId = projectId });
        }