private void toolStripComboBoxPath_TextChanged(object sender, EventArgs e) { //update status if (toolStripComboBoxPath.Text == "" || !System.IO.File.Exists(toolStripComboBoxPath.Text)) { toolStripStatusLabelFile.Text = "Status: Waiting for a Microsoft® Project file to load."; Application.DoEvents(); } //check for valid file name if (!System.IO.File.Exists(toolStripComboBoxPath.Text)) { //otherwise bounce and let the user keep typing return; } toolStripStatusLabelFile.Text = "Status: Opening file \"" + this.toolStripComboBoxPath.Text + "\". Please stand by..."; Application.DoEvents(); //since the file name is valid, let's "try" to open the Microsoft® Project file ProjectFile projectFile = null; try { projectFile = this.readProjectFile(this.toolStripComboBoxPath.Text); } catch (Exception ex) { toolStripStatusLabelFile.Text = "Error: The file specified is not a valid Microsoft® Project file. " + ex.Message; Application.DoEvents(); //bounce and let the user try again return; } System.Diagnostics.Debug.WriteLine("Step 1: Opened Microsoft® Project file \"" + this.toolStripComboBoxPath.Text + "\"."); toolStripStatusLabelFile.Text = "Status: Opened Microsoft® Project file \"" + this.toolStripComboBoxPath.Text + "\". Getting tasks..."; Application.DoEvents(); //get task list from open Project file Task[] tasks = this.getAllProjectTasks(projectFile); System.Diagnostics.Debug.WriteLine("Step 2: Returned " + tasks.Length + " tasks."); toolStripStatusLabelFile.Text = "Status: Opened Microsoft® Project file \"" + this.toolStripComboBoxPath.Text + "\" and gathered " + tasks.Length + " task candidates. Preparing checklist..."; Application.DoEvents(); //erase the last list, if any listViewTasks.Items.Clear(); foreach (Task task in tasks) { //storage DateTime startDate = DateTime.MinValue; DateTime finishDate = DateTime.MinValue; //write these down java.util.Date taskStart = task.Start; java.util.Date taskFinish = task.Finish; //now split them up string[] taskStartComponents = new string[] { }; if (taskStart != null) { taskStartComponents = taskStart.toString().Split(new char[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries); } string[] taskFinishComponents = new string[] { }; if (taskFinish != null) { taskFinishComponents = taskFinish.toString().Split(new char[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries); } //now convert them from Java to .Net and tell Google®'s When what's up if (taskStart != null) { startDate = DateTime.ParseExact( taskStartComponents[7] + " " + //year taskStartComponents[1] + " " + //month taskStartComponents[2], "yyyy MMM dd", System.Globalization.CultureInfo.InvariantCulture ); } if (taskFinish != null) { finishDate = DateTime.ParseExact( taskFinishComponents[7] + " " + //year taskFinishComponents[1] + " " + //month taskFinishComponents[2], "yyyy MMM dd", System.Globalization.CultureInfo.InvariantCulture ); } string name = task.Name; //debug: print each task found to the stderr System.Diagnostics.Debug.Write(" >> Task by name \"" + name + "\""); if (taskStart != null && taskFinish != null) { System.Diagnostics.Debug.WriteLine(" starting on \"" + startDate.ToString("MMMM dd, yyyy") + "\" and ending on \"" + finishDate.ToString("MMMM dd, yyyy") + "\"."); } else if (taskStart != null) { System.Diagnostics.Debug.WriteLine(" starting on \"" + startDate.ToString("MMMM dd, yyyy") + "\"."); } else if (taskFinish != null) { System.Diagnostics.Debug.WriteLine(" ending on \"" + finishDate.ToString("MMMM dd, yyyy") + "\"."); } else { System.Diagnostics.Debug.WriteLine("."); } //in order to be considered data for the production app, //it must contain a start date and a task name if (name != null && name.Trim().Length > 0 && taskStart != null) { //it must contain some valid data, so let's enroll it into our list //first generate a ListViewItem and fill it up ListViewItem item = new ListViewItem(); item.Text = task.Name.Trim(); item.SubItems.Add(startDate.ToString("yyyy-MM-dd (MMMM dd, yyyy)")); if (taskFinish != null) { item.SubItems.Add(finishDate.ToString("yyyy-MM-dd (MMMM dd, yyyy)")); } //mark this tag with the Task object, we'll cast it back out later from the checked items list item.Tag = task; //check the item, by default we'd want all the events migrated item.Checked = true; //now add this to the list this.listViewTasks.Items.Add(item); } } // Set the ListViewItemSorter property to a new ListViewItemComparer object. this.listViewTasks.ListViewItemSorter = new ListViewItemComparer(1); // Call the sort method to manually sort. listViewTasks.Sort(); toolStripStatusLabelFile.Text = "Status: Located " + this.listViewTasks.Items.Count + " validated tasks in Microsoft® Project file \"" + this.toolStripComboBoxPath.Text + "\"."; Application.DoEvents(); }
/// <summary> /// Translates a Microsoft® Project task into a Google® Data API CalendarEntry for Google® Calendar. /// </summary> /// <param name="task">Microsoft® Project task instance.</param> /// <returns>A new EventEntry from Google® Data API.</returns> protected Event translateProjectTaskToCalendarEntry(Task task) { //create EventEntry for Google® API Event eventEntry = new Event(); //assign title to EventEntry from Microsoft® Project Task name eventEntry.Summary = task.Name; eventEntry.Description = task.Name; // Set a location for the event. eventEntry.Location = "Microsoft® Project"; //create When object for Google® API DateTime startTime = DateTime.MinValue; DateTime endTime = DateTime.MinValue; //write these down java.util.Date taskStart = task.Start; java.util.Date taskFinish = task.Finish; //now split them up string[] taskStartComponents = new string[] { }; if (taskStart != null) { taskStartComponents = taskStart.toString().Split(new char[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries); } string[] taskFinishComponents = new string[] { }; if (taskFinish != null) { taskFinishComponents = taskFinish.toString().Split(new char[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries); } //now convert them from Java to .Net and tell Google®'s When what's up if (taskStart != null) { startTime = DateTime.ParseExact( taskStartComponents[7] + " " + //year taskStartComponents[1] + " " + //month taskStartComponents[2], "yyyy MMM dd", System.Globalization.CultureInfo.InvariantCulture ); } if (taskFinish != null) { endTime = DateTime.ParseExact( taskFinishComponents[7] + " " + //year taskFinishComponents[1] + " " + //month taskFinishComponents[2], "yyyy MMM dd", System.Globalization.CultureInfo.InvariantCulture ); } //add the When to the event entry if (startTime != DateTime.MinValue) { eventEntry.Start = new EventDateTime() { DateTime = startTime } } ; if (endTime != DateTime.MinValue) { eventEntry.End = new EventDateTime() { DateTime = endTime } } ; //return the EventEntry return(eventEntry); } } }