Пример #1
0
 public TimeEntry(DateTime startTime, DateTime endTime, int duration, Task relatedTask)
 {
     StartTime = startTime;
     EndTime = endTime;
     Duration = duration;
     RelatedTask = relatedTask;
     CreatedTime = DateTime.Now;
 }
Пример #2
0
 public TimeEntry(Task relatedTask)
 {
     // give the required fields default values
     StartTime = DateTime.Now;
     EndTime = DateTime.Now.AddSeconds(1);
     Duration = 1;
     RelatedTask = relatedTask;
     CreatedTime = DateTime.Now;
 }
Пример #3
0
        /// <summary>
        /// Updates or Inserts a task to SlimTimer
        /// If the task ID is null, an insert will be performed, otherwise an update
        /// </summary>
        /// <param name="task">Task to be updated/inserted</param>
        /// <returns>Task result from update/insert.  If an insert was performed, this will contain the new ID.
        /// A null result means an error was encountered</returns>
        public Task UpdateTask(Task task)
        {
            // verify the required fields have data so we don't get an error back from SlimTimer
            if (task == null || task.Name == null || task.Name.Length == 0)
            {
                throw new ArgumentNullException("Task.Name", "Task name must have a value");
            }

            if (!PrepareRequestCall())
                return null;

            // build the URL
            string url = GetBaseURL() + "/tasks";
            RequestType request = RequestType.Post;

            // if the task has an Id we are updating
            if (task.Id != null && task.Id.Length > 0)
            {
                url += "/" + task.Id;
                request = RequestType.Put;
            }
            url += GetURLParams();

            // create the XML data to pass to SlimTimer
            XmlDocument data = new XmlDocument();
            data.CreateXmlDeclaration("1.0", "UTF-8", "");
            XmlNode root = data.CreateNode(XmlNodeType.Element, "task", "");
            data.AppendChild(root);
            XmlNode n = data.CreateNode(XmlNodeType.Element, "name", "");
            n.InnerText = task.Name;
            root.AppendChild(n);

            if (task.Tags.Count > 0)
            {
                n = data.CreateNode(XmlNodeType.Element, "tags", "");
                foreach (string s in task.Tags)
                {
                    n.InnerText += s + ",";
                }
                n.InnerText = n.InnerText.TrimEnd(',');
                root.AppendChild(n);
            }
            if (task.ReporterEmails.Count > 0)
            {
                n = data.CreateNode(XmlNodeType.Element, "reporter_emails", "");
                foreach (string s in task.ReporterEmails)
                {
                    n.InnerText += s + ",";
                }
                n.InnerText = n.InnerText.TrimEnd(',');
                root.AppendChild(n);
            }
            if (task.CoworkerEmails.Count > 0)
            {
                n = data.CreateNode(XmlNodeType.Element, "coworker_emails", "");
                foreach (string s in task.CoworkerEmails)
                {
                    n.InnerText += s + ",";
                }
                n.InnerText = n.InnerText.TrimEnd(',');
                root.AppendChild(n);
            }
            if (task.CompletedOn != null)
            {
                n = data.CreateNode(XmlNodeType.Element, "completed_on", "");
                n.InnerText += Convert.ToDateTime(task.CompletedOn).ToString("s", CultureInfo.InvariantCulture);
                root.AppendChild(n);
            }

            string Response = GetHttpPage(new Uri(url), request, ContentType.Xml, data.InnerXml);
            Collection<Task> tasks = ParseTasks(Response);
            if (tasks.Count > 0)
                return tasks[0];

            _Error = "Unable to update/insert task";
            return null;
        }
Пример #4
0
        /// <summary>
        /// Parses an xml node to get a single Task
        /// </summary>
        /// <param name="n">XmlNode to parse</param>
        /// <returns>Task parsed from XML data in XmlNode</returns>
        private static Task ParseTask(XmlNode n)
        {
            Task t = new Task(GetNodeText(n, "name"));
            t.Id = GetNodeText(n, "id");
            //t.Hours = float.Parse(GetNodeText(n, "hours"));
            t.Hours = float.Parse(GetNodeText(n, "hours"), CultureInfo.InvariantCulture);
            t.Role = GetNodeText(n, "role");
            if (GetNodeText(n, "tags").Length > 0)
                t.Tags.AddRange(GetNodeText(n, "tags").Split(','));
            t.UpdatedTime = GetNodeText(n, "updated-at").Length > 0 ? DateTime.Parse(GetNodeText(n, "updated-at"), CultureInfo.InvariantCulture) : DateTime.MinValue;
            t.CreatedTime = GetNodeText(n, "created-at").Length > 0 ? DateTime.Parse(GetNodeText(n, "created-at"), CultureInfo.InvariantCulture) : DateTime.MinValue;
            t.CompletedOn = GetNodeText(n, "completed-on").Length > 0 ? DateTime.Parse(GetNodeText(n, "completed-on"), CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture) : null;

            return t;
        }
Пример #5
0
 public void setCurrentTask(Task task)
 {
     comboBoxProjects.SelectedItem = task;
 }