Example #1
0
        private void AppendFreeBusyEntry(
            DateTime startUtc,
            DateTime endUtc,
            string subject,
            string location,
            string organizer,
            BusyStatus busyStatus,
            StringBuilder result)
        {
            DateTime startLocal = OlsonUtil.ConvertFromUTC(startUtc, Request.TimeZone);
            DateTime endLocal   = OlsonUtil.ConvertFromUTC(endUtc, Request.TimeZone);
            int      status     = ConversionsUtil.ConvertBusyStatusToGoogleResponse(busyStatus);

            ConversionsUtil.EscapeNonAlphaNumeric(subject, escapedSubject);
            ConversionsUtil.EscapeNonAlphaNumeric(location, escapedLocation);
            ConversionsUtil.EscapeNonAlphaNumeric(organizer, escapedOrganizer);

            result.AppendFormat("['{0}','{1}','{2}','{3}','{4}',{5}]",
                                escapedSubject,
                                DateUtil.FormatDateTimeForGoogle(startLocal),
                                DateUtil.FormatDateTimeForGoogle(endLocal),
                                escapedLocation,
                                escapedOrganizer,
                                status);
        }
Example #2
0
        private void CreateAppointment(
            IntervalTree <Appointment> result,
            ExchangeUser user,
            OlsonTimeZone srcTimeZone,
            EventEntry googleAppsEvent)
        {
            Appointment appt = new Appointment();

            if (googleAppsEvent.Times != null && googleAppsEvent.Times.Count > 0)
            {
                When eventTime = googleAppsEvent.Times[0];
                appt.StartDate = DateTime.SpecifyKind(eventTime.StartTime.ToUniversalTime(), DateTimeKind.Unspecified);
                appt.EndDate   = DateTime.SpecifyKind(eventTime.EndTime.ToUniversalTime(), DateTimeKind.Unspecified);

                log.DebugFormat("Create - [{0}] {1}", appt.Range, appt.Range.Start.Kind);

                appt.AllDayEvent = googleAppsEvent.Times[0].AllDay;
            }

            if (ConfigCache.SyncAppointmentDetails &&
                googleAppsEvent.Locations != null &&
                googleAppsEvent.Locations.Count > 0)
            {
                appt.Location = googleAppsEvent.Locations[0].ValueString ?? string.Empty;
            }
            else
            {
                appt.Location = String.Empty;
            }

            string subject = ConfigCache.PlaceHolderMessage;

            if (ConfigCache.SyncAppointmentDetails)
            {
                subject += ": " + ConversionsUtil.SafeGetText(googleAppsEvent.Title);
                if (subject.Length > 255)
                {
                    subject = subject.Remove(255);
                }
            }

            appt.Subject = subject;

            if (ConfigCache.SyncAppointmentDetails)
            {
                appt.Body = ConversionsUtil.SafeGetContent(googleAppsEvent.Content);
            }

            appt.MeetingStatus = ConversionsUtil.ConvertGoogleEventStatus(googleAppsEvent.Status);

            appt.BusyStatus = ConversionsUtil.GetUserStatusForEvent(user, googleAppsEvent);

            appt.Created      = DateUtil.NowUtc;
            appt.InstanceType = InstanceType.Single;
            AssignOwnership(appt);
            result.Insert(appt.Range, appt);
        }
        private static void ConvertEventToFreeBusy(
            ExchangeUser user,
            EventEntry googleAppsEvent,
            DateTimeRange coveredRange,
            List <DateTimeRange> busyTimes,
            List <DateTimeRange> tentativeTimes)
        {
            DateTime   startDate    = DateTime.MinValue;
            DateTime   endDate      = DateTime.MinValue;
            DateTime   utcStartDate = DateTime.MinValue;
            DateTime   utcEndDate   = DateTime.MinValue;
            BusyStatus userStatus   = BusyStatus.Free;

            userStatus = ConversionsUtil.GetUserStatusForEvent(user, googleAppsEvent);

            // If the user is free, do not put this meeting in the free busy
            if (userStatus == BusyStatus.Free)
            {
                return;
            }

            startDate    = googleAppsEvent.Times[0].StartTime;
            utcStartDate = DateTime.SpecifyKind(startDate.ToUniversalTime(),
                                                DateTimeKind.Unspecified);
            endDate    = googleAppsEvent.Times[0].EndTime;
            utcEndDate = DateTime.SpecifyKind(endDate.ToUniversalTime(),
                                              DateTimeKind.Unspecified);

            if (utcStartDate < coveredRange.Start)
            {
                coveredRange.Start = utcStartDate;
            }

            if (utcEndDate > coveredRange.End)
            {
                coveredRange.End = utcEndDate;
            }

            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Read GData FB event {0} - {1}", startDate, endDate);
                _log.DebugFormat("Write FB event {0} - {1} in UTC", utcStartDate, utcEndDate);
                _log.DebugFormat("The FB status is {0}", userStatus.ToString());
            }

            if (userStatus == BusyStatus.Tentative)
            {
                tentativeTimes.Add(new DateTimeRange(utcStartDate, utcEndDate));
            }
            else
            {
                Debug.Assert(userStatus == BusyStatus.Busy);
                busyTimes.Add(new DateTimeRange(utcStartDate, utcEndDate));
            }
        }
Example #4
0
        /// <summary>
        /// Generate the response for the request
        /// </summary>
        /// <returns>The response</returns>
        public string GenerateResponse()
        {
            StringBuilder escapedError = new StringBuilder(errorMessage.Length);

            ConversionsUtil.EscapeNonAlphaNumeric(errorMessage, escapedError);

            // GCal expects errors in the following format:
            // [VERSION NUMBER, MESSAGE ID, ERROR ID, ERROR STRING]
            return(string.Format(
                       "['{0}','{1}','{2}','{3}']",
                       versionId,
                       messageId,
                       errorId,
                       escapedError));
        }
Example #5
0
        private List <Appointment> ParseAppointmentResultSetXml(XmlDocument doc)
        {
            List <Appointment> result = new List <Appointment>();
            XPathNavigator     nav    = doc.CreateNavigator();
            bool active = nav.MoveToFirstChild();

            XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);

            ns.AddNamespace("dav", "DAV:");
            ns.AddNamespace("cal", "urn:schemas:calendar:");
            ns.AddNamespace("mail", "urn:schemas:mailheader:");
            ns.AddNamespace("f", "http://schemas.microsoft.com/mapi/proptag/");
            ns.AddNamespace("g", "http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/");
            ns.AddNamespace("h", "http://schemas.microsoft.com/mapi/id/{00062002-0000-0000-C000-000000000046}/");

            XmlNodeList nodes = doc.SelectNodes("//dav:response", ns);

            foreach (XmlNode node in nodes)
            {
                Appointment appt = new Appointment();

                appt.HRef = node.SelectSingleNode("dav:href", ns).InnerXml;
                XmlNode prop = node.SelectSingleNode("dav:propstat[1]/dav:prop", ns);

                appt.AllDayEvent =
                    GetPropertyAsBool(prop, "cal:alldayevent", ns);

                appt.Body =
                    GetPropertyAsXML(prop, "f:x1000001e", ns);

                appt.BusyStatus = ConversionsUtil.ParseBusyStatus(
                    GetPropertyAsString(prop, "cal:busystatus", appt.BusyStatus.ToString(), ns));

                appt.Comment =
                    GetPropertyAsString(prop, "dav:comment", ns);

                appt.Created =
                    GetPropertyAsDateTime(prop, "dav:creationdate", ns);

                appt.StartDate =
                    GetPropertyAsDateTime(prop, "cal:dtstart", ns);

                appt.EndDate =
                    GetPropertyAsDateTime(prop, "cal:dtend", ns);

                appt.InstanceType = (InstanceType)Enum.Parse(
                    typeof(InstanceType),
                    GetPropertyAsString(prop, "cal:instancetype", appt.InstanceType.ToString(), ns),
                    true);

                appt.IsPrivate =
                    GetPropertyAsBool(prop, "g:x8506", ns);

                appt.Location =
                    GetPropertyAsString(prop, "cal:location", ns);

                appt.MeetingStatus = (MeetingStatus)Enum.Parse(
                    typeof(MeetingStatus),
                    GetPropertyAsString(prop, "cal:meetingstatus", appt.MeetingStatus.ToString(), ns),
                    true);

                appt.Organizer =
                    GetPropertyAsString(prop, "cal:organizer", ns);

                appt.ResponseStatus = (ResponseStatus)GetPropertyAsInt(prop, "h:x8218", (int)appt.ResponseStatus, ns);

                appt.Subject =
                    GetPropertyAsString(prop, "mail:subject", ns);

                result.Add(appt);
            }

            return(result);
        }