Пример #1
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();
        }
Пример #2
0
        /// <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;
        }