예제 #1
0
파일: AddCommand.cs 프로젝트: wertkh32/gg
 public override GGResult Execute(string userCommand, GGList ggList)
 {
     Debug.Assert(userCommand != null && !userCommand.Equals(string.Empty));
     Debug.Assert(ggList != null);
     this.SetGGList(ggList);
     userCommand = StripAddCommandFromUserCommand(userCommand).Trim();
     try
     {
         ThrowExceptionIfIsEmptyInput(userCommand);
         newGgItem = QuickParser.Parse(userCommand);
         ggList.AddGGItem(newGgItem);
         this.SetIsSuccessful(true);
         string successMsg = string.Format(MESSAGE_ADD_SUCCESS, newGgItem.GetDescription());
         Debug.WriteLine(successMsg, "info");
         result = CreateResultInstance(successMsg, GGResult.RESULT_TYPE.RESULT_ADD, ggList.IndexOfGGItem(newGgItem),newGgItem.GetTag());
     }
     catch (Exception e)
     {
         error = e.Message;
         string errorMsg = string.Format(MESSAGE_ERROR, error);
         Debug.WriteLine(errorMsg, "error");
         result = CreateResultInstance(errorMsg, GGResult.RESULT_TYPE.RESULT_INVALID);
     }
     return result;
 }
예제 #2
0
 /// <summary>
 /// Deletes an item from the ggList as specified by the user
 /// </summary>
 /// <param name="userCommand">The command issued by the user</param>
 /// <param name="ggList">The list of task items</param>
 public override GGResult Execute(string userCommand, GGList list)
 {
     Debug.Assert(userCommand != null && !userCommand.Equals(string.Empty));
     this.SetGGList(list);
     if (InvalidInput(userCommand))
     {
         string errorMsg = "Error: Please specify an item id to remove\n";
         Debug.WriteLine(errorMsg);
         return CreateErrorResultInstance(errorMsg);
     }
     int itemIndexToShow = GetItemIndexFromUserCommand(userCommand);
     itemIndex = itemIndexToShow - 1;
     if (IndexOutOfBounds(itemIndex))
     {
         string errorMsg = string.Format("Error: There is no list item of index {0}\n", itemIndexToShow);
         Debug.WriteLine(errorMsg);
         return CreateErrorResultInstance(errorMsg);
     }
     GGList ggList = this.GetGGList();
     removedGgItem = ggList.GetGGItemAt(itemIndex);
     ggList.RemoveGGItemAt(itemIndex);
     this.SetIsSuccessful(true);
     string successMsg = string.Format(MESSAGE_REMOVE_SUCCESS, removedGgItem.GetDescription());
     Debug.WriteLine(successMsg);
     result = new GGResult(string.Empty, successMsg, itemIndex, GGResult.RESULT_TYPE.RESULT_REMOVE, removedGgItem.GetTag()); //useless to return itemindex since item does not exist
     return result;
 }
예제 #3
0
        /// <summary>
        /// Parse a GGItem to CSV string
        /// </summary>
        /// <param name="ggItem"></param>
        /// <returns></returns>
        private string ToCSVString(GGItem ggItem)
        {
            string description = ggItem.GetDescription().Replace(Environment.NewLine, "[newline]");
            description = description.Replace(",", "[comma]");

            string tag = ggItem.GetTag().Replace(Environment.NewLine, "[newline]");
            tag = tag.Replace(",", "[comma]");
            CultureInfo usCulture = CultureInfo.CreateSpecificCulture("en-US");

            return description + ","
                   + ggItem.GetEndDate().ToString(usCulture) + ","
                   + tag + ","
                   + ggItem.GetLastModifiedTime().ToString() + ","
                   + ggItem.GetEventAbsoluteUrl() + ","
                   + ggItem.GetPath();
        }
예제 #4
0
파일: GGSync.cs 프로젝트: wertkh32/gg
        /// <summary>
        /// Add a local event to Google Calendar
        /// </summary>
        /// <param name="GGService">Google calendar service object</param>
        /// <param name="GGCalendar">GG calendar object</param>
        /// <param name="myGGItem">GGItem object to be added to GG calendar</param>
        /// <returns>Google event's ID</returns>
        private string AddGGEvent(CalendarService GGService, CalendarEntry GGCalendar, GGItem myGGItem)
        {
            // Create a event object
            EventEntry entry = new EventEntry();

            // Use description as event title (necessary)
            entry.Title.Text = myGGItem.GetDescription();
            // Use tag as event content (optional)
            entry.Content.Content = myGGItem.GetTag() + " | " + myGGItem.GetPath();

            // Set event start and end time
            if (myGGItem.GetEndDate().CompareTo(GGItem.DEFAULT_ENDDATE) != 0)
            {   // Specified endDate
                // Use endDate - 2hours as start time and endDate as end time
                When eventTime = new When(myGGItem.GetEndDate().AddHours(-2), myGGItem.GetEndDate());
                entry.Times.Add(eventTime);
            }
            else
            {   // Default endDate
                // Treat as tasks, set due date as 3 days later
                When eventTime = new When(DateTime.Today, DateTime.Today.AddDays(3));
                entry.Times.Add(eventTime);
            }

            // Log(entry.Updated.ToLongDateString());

            // Set email reminder: 15 minutes before end time
            Reminder GGReminder = new Reminder();
            GGReminder.Minutes = 15;
            GGReminder.Method = Reminder.ReminderMethod.email;
            entry.Reminders.Add(GGReminder);

            // Create the event on Google Calendar
            Uri postUri = new Uri("https://www.google.com/calendar/feeds/" + GGCalendar.Id.AbsoluteUri.Substring(63) + "/private/full");
            AtomEntry insertedEntry = GGService.Insert(postUri, entry);

            // Return the event's ID
            return insertedEntry.Id.AbsoluteUri;
        }