Esempio n. 1
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>parses an xml node to create a Recurrence object</summary> 
        /// <param name="node">Recurrence node</param>
        /// <returns> the created Recurrence object</returns>
        //////////////////////////////////////////////////////////////////////
        public static Recurrence ParseRecurrence(XmlNode node)
        {
            Tracing.TraceCall();
            Recurrence recurrence = null;
            Tracing.Assert(node != null, "node should not be null");
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            object localname = node.LocalName;
            if (localname.Equals(GDataParserNameTable.XmlRecurrenceElement))
            {
                recurrence = new Recurrence();
                recurrence.Value = node.InnerText.Trim();
            }

            return recurrence;
        }
Esempio n. 2
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>Parses an xml node to create a Reminder object.</summary> 
        /// <param name="node">the node to parse node</param>
        /// <param name="parser">the xml parser to use if we need to dive deeper</param>
        /// <returns>the created Reminder object</returns>
        //////////////////////////////////////////////////////////////////////
        public IExtensionElementFactory CreateInstance(XmlNode node, AtomFeedParser parser)
        {
            Tracing.TraceCall();
            if (node != null)
            {
                object localname = node.LocalName;
                if (!localname.Equals(this.XmlName) ||
                    !node.NamespaceURI.Equals(this.XmlNameSpace))
                {
                    return null;
                }
            }

            Recurrence recurrence = new Recurrence();

            if (node != null)
            {
                recurrence.Value = node.InnerText.Trim();
            }

            return recurrence;
        }
        /// <summary>
        /// Helper method to create either single-instance or recurring events.
        /// For simplicity, some values that might normally be passed as parameters
        /// (such as author name, email, etc.) are hard-coded.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        /// <param name="entryTitle">Title of the event to create.</param>
        /// <param name="recurData">Recurrence value for the event, or null for
        ///                         single-instance events.</param>
        /// <returns>The newly-created EventEntry on the calendar.</returns>
        static EventEntry CreateEvent(CalendarService service, String entryTitle,
                                     String recurData)
        {
            EventEntry entry = new EventEntry();

            // Set the title and content of the entry.
            entry.Title.Text = entryTitle;
            entry.Content.Content = "Meet for a quick lesson.";

            // Set a location for the event.
            Where eventLocation = new Where();
            eventLocation.ValueString = "South Tennis Courts";
            entry.Locations.Add(eventLocation);

            // If a recurrence was requested, add it.  Otherwise, set the
            // time (the current date and time) and duration (30 minutes)
            // of the event.
            if (recurData == null) {
                When eventTime = new When();
                eventTime.StartTime = DateTime.Now;
                eventTime.EndTime = eventTime.StartTime.AddMinutes(30);
                entry.Times.Add(eventTime);
            } else {
                Recurrence recurrence = new Recurrence();
                recurrence.Value = recurData;
                entry.Recurrence = recurrence;
            }

            // Send the request and receive the response:
            Uri postUri = new Uri(feedUri);
            AtomEntry insertedEntry = service.Insert(postUri, entry);

            return (EventEntry)insertedEntry;
        }
Esempio n. 4
0
        // TODO: dynamically generate study time based on credit hours of each class
        private void generateBtn_Click(object sender, EventArgs e)
        {
            timeSlots.Clear();

            String report = "";

            if (username == "" || password == "" || calendarUrl == "")
            {
                MessageBox.Show("Please add Google login and password information.");
            }
            else
            {
                foreach (ClassGroupBox g in groupBoxList)
                {
                    firstDayOfClass = assignClassStartDay(g.getDays()[0], startOfSemester);

                    String recursionString = "DTSTART;TZID=US/Eastern:" + startOfSemester.Year
                        + startOfSemester.Month.ToString("00") + firstDayOfClass.ToString()
                        + "T" + g.getStartHour() + g.getStartMin()
                        + "00" + "\r\nDTEND;TZID=US/Eastern:" + startOfSemester.Year
                        + startOfSemester.Month.ToString("00") + startOfSemester.Day.ToString("00")
                        + "T" + g.getEndHour() + g.getEndMin() + "00"
                        + "\r\n" + "RRULE:FREQ=WEEKLY;BYDAY=" + buildDayString(g.getDays()) + ";UNTIL="
                        + endOfSemester.Year + endOfSemester.Month.ToString("00")
                        + endOfSemester.Day.ToString("00") + "\r\n";

                    Recurrence recurrence = new Recurrence();
                    recurrence.Value = recursionString;
                    Console.Out.WriteLine(recursionString);

                    CalendarService service = new CalendarService("ggco-purdueScheduler-0.01");
                    Uri postUri = new Uri("https://www.google.com/calendar/feeds/" + calendarUrl + "/private/full");

                    service.setUserCredentials(username, password);
                    EventEntry calendarEntry = new EventEntry();
                    calendarEntry.Title.Text = g.getCourseName();
                    calendarEntry.Recurrence = recurrence;

                    report += buildDayReport(g);

                    try
                    {
                        AtomEntry insertedEntry = service.Insert(postUri, calendarEntry);
                        resultLbl.Text = "SUCCESS";
                        resultLbl.ForeColor = Color.White;
                        resultLbl.BackColor = Color.Green;
                    }
                    catch
                    {
                        resultLbl.Text = "FAILURE";
                        resultLbl.ForeColor = Color.White;
                        resultLbl.BackColor = Color.Red;
                    }

                    //// BASELINE - used to ensure no overlap in a given day
                    //DateTime start = new DateTime(DateTime.Now.Year, DateTime.Now.Month,
                    //    DateTime.Now.Day, int.Parse(g.getStartHour()), int.Parse(g.getStartMin()), 0);
                    //DateTime end = new DateTime(DateTime.Now.Year, DateTime.Now.Month,
                    //    DateTime.Now.Day, int.Parse(g.getEndHour()), int.Parse(g.getEndMin()), 0);

                    //if (groupBoxList.Count == 0)
                    //{
                    //    timeSlots.Add(new TimeSlot(start, end));
                    //}
                    //else
                    //{
                    //    foreach (TimeSlot t in timeSlots)
                    //    {
                    //        if (start <= t.getStartTime() && end > t.getStartTime())
                    //        {
                    //            MessageBox.Show("Classes overlap - one ends after another starts.");
                    //        }
                    //        else if (start >= t.getStartTime() && start < t.getEndTime())
                    //        {
                    //            MessageBox.Show("Classes overlap - one starts before another ends.");
                    //        }
                    //        else
                    //        {
                    //            MessageBox.Show("No errors");
                    //        }
                    //    }
                    //    timeSlots.Add(new TimeSlot(start, end));
                    //}
                }
            }
            reportRichTxt.Text = report;
        }
        /// <summary>
        /// Merges the recurrence.
        /// </summary>
        /// <param name="outlookCalendarItem">The outlook calendar item.</param>
        /// <param name="recurrence">The recurrence.</param>
        /// <returns>True if Change.</returns>
        public static bool MergeRecurrence(this AppointmentItem outlookCalendarItem, Recurrence recurrence)
        {
            if (recurrence != null && !string.IsNullOrWhiteSpace(recurrence.Value))
            {
                var result = false;
                var outlookRecurrencePattern = outlookCalendarItem.GetRecurrencePattern();
                var googleRecurrencePattern = RecurrenceSerializer.Deserialize(recurrence.Value);

                try { result |= outlookCalendarItem.ApplyProperty(r => r.AllDayEvent, googleRecurrencePattern.AllDayEvent); } catch (TargetInvocationException) { }
                result |= outlookRecurrencePattern.ApplyProperty(r => r.RecurrenceType, googleRecurrencePattern.RecurrenceType);
                result |= outlookRecurrencePattern.ApplyProperty(r => r.PatternStartDate, googleRecurrencePattern.StartPattern.HasValue ? googleRecurrencePattern.StartPattern.Value.Date : DateTime.Today);
                if (googleRecurrencePattern.EndPattern.HasValue)
                    result |= outlookRecurrencePattern.ApplyProperty(r => r.PatternEndDate, googleRecurrencePattern.EndPattern.Value.Date);
                else
                    result |= outlookRecurrencePattern.ApplyProperty(r => r.NoEndDate, true);

                result |= outlookRecurrencePattern.ApplyProperty(r => r.DayOfMonth, googleRecurrencePattern.DayOfMonth);
                result |= outlookRecurrencePattern.ApplyProperty(r => r.DayOfWeekMask, googleRecurrencePattern.DayOfWeek);
                result |= outlookRecurrencePattern.ApplyProperty(r => r.MonthOfYear, googleRecurrencePattern.MonthOfYear);

                if (outlookRecurrencePattern.StartTime.TimeOfDay.Ticks != googleRecurrencePattern.StartTime.TimeOfDay.Ticks)
                    result |= outlookRecurrencePattern.ApplyProperty(r => r.StartTime, googleRecurrencePattern.StartTime);

                if (outlookRecurrencePattern.EndTime.TimeOfDay.Ticks != googleRecurrencePattern.EndTime.TimeOfDay.Ticks)
                    result |= outlookRecurrencePattern.ApplyProperty(r => r.EndTime, googleRecurrencePattern.EndTime);

                if (googleRecurrencePattern.Count.HasValue)
                    result |= outlookRecurrencePattern.ApplyProperty(r => r.Occurrences, googleRecurrencePattern.Count.Value);

                if (googleRecurrencePattern.Interval.HasValue)
                    result |= outlookRecurrencePattern.ApplyProperty(r => r.Interval, googleRecurrencePattern.Interval.Value);

                return result;
            }

            if (outlookCalendarItem.RecurrenceState == OlRecurrenceState.olApptNotRecurring)
            {
                outlookCalendarItem.ClearRecurrencePattern();
                return true;
            }

            return false;
        }