Ejemplo n.º 1
0
        private static WorkHoursInCalendar DeserializeObject(Stream streamToReadFrom)
        {
            WorkHoursInCalendar workHoursInCalendar = new WorkHoursInCalendar();
            XmlSerializer       xmlSerializer       = VersionedXmlTypeFactory.GetXmlSerializer(workHoursInCalendar.GetType());

            return((WorkHoursInCalendar)xmlSerializer.Deserialize(streamToReadFrom));
        }
Ejemplo n.º 2
0
        public static StorageWorkingHours LoadFrom(MailboxSession session, StoreId folderId)
        {
            WorkHoursInCalendar fromCalendar = WorkHoursInCalendar.GetFromCalendar(session, folderId);

            if (fromCalendar == null || fromCalendar.WorkHoursVersion1 == null)
            {
                return(null);
            }
            if (fromCalendar.WorkHoursVersion1.TimeSlot == null)
            {
                throw new WorkingHoursXmlMalformedException(ServerStrings.NullWorkHours);
            }
            ExTimeZone exTimeZone = null;

            try
            {
                if (!string.IsNullOrEmpty(fromCalendar.WorkHoursVersion1.TimeZone.Name))
                {
                    if (ExTimeZoneEnumerator.Instance.TryGetTimeZoneByName(fromCalendar.WorkHoursVersion1.TimeZone.Name, out exTimeZone))
                    {
                        WorkHoursTimeZone workHoursTimeZone = fromCalendar.WorkHoursVersion1.TimeZone;
                        if (!workHoursTimeZone.IsSameTimeZoneInfo(TimeZoneHelper.RegTimeZoneInfoFromExTimeZone(exTimeZone)))
                        {
                            exTimeZone = null;
                        }
                    }
                    else
                    {
                        exTimeZone = null;
                    }
                }
                if (exTimeZone == null)
                {
                    exTimeZone = TimeZoneHelper.CreateCustomExTimeZoneFromRegTimeZoneInfo(fromCalendar.WorkHoursVersion1.TimeZone.TimeZoneInfo, "tzone://Microsoft/Custom", "Customized Time Zone");
                }
            }
            catch (InvalidTimeZoneException ex)
            {
                throw new WorkingHoursXmlMalformedException(ServerStrings.MalformedTimeZoneWorkingHours(session.MailboxOwner.MailboxInfo.DisplayName, ex.ToString()), ex);
            }
            return(new StorageWorkingHours(exTimeZone, fromCalendar.WorkHoursVersion1.WorkDays, fromCalendar.WorkHoursVersion1.TimeSlot.StartTimeInMinutes, fromCalendar.WorkHoursVersion1.TimeSlot.EndTimeInMinutes));
        }
Ejemplo n.º 3
0
        internal static WorkHoursInCalendar GetFromCalendar(MailboxSession session, StoreId folderId)
        {
            WorkHoursInCalendar workHoursInCalendar = null;

            try
            {
                UserConfigurationManager userConfigurationManager = session.UserConfigurationManager;
                using (IReadableUserConfiguration readOnlyFolderConfiguration = userConfigurationManager.GetReadOnlyFolderConfiguration("WorkHours", UserConfigurationTypes.XML, folderId))
                {
                    if (readOnlyFolderConfiguration == null)
                    {
                        ExTraceGlobals.WorkHoursTracer.TraceDebug <string>(-1L, "{0}: Work hours configuration item was not found", session.MailboxOwner.MailboxInfo.DisplayName);
                    }
                    else
                    {
                        using (Stream xmlStream = readOnlyFolderConfiguration.GetXmlStream())
                        {
                            workHoursInCalendar = WorkHoursInCalendar.DeserializeObject(xmlStream);
                            if (workHoursInCalendar == null)
                            {
                                ExTraceGlobals.WorkHoursTracer.TraceDebug <string>(-1L, "{0}: Work hours configuration item was found, but no content was found", session.MailboxOwner.MailboxInfo.DisplayName);
                            }
                        }
                    }
                }
            }
            catch (ObjectNotFoundException arg)
            {
                ExTraceGlobals.WorkHoursTracer.TraceError <string, ObjectNotFoundException>(-1L, "{0}: Could not retrieve working hours. Exception information is {1}", session.MailboxOwner.MailboxInfo.DisplayName, arg);
            }
            catch (InvalidOperationException ex)
            {
                ExTraceGlobals.WorkHoursTracer.TraceError <string, InvalidOperationException>(-1L, "{0}: Malformed working hours XML in mailbox. Exception information is {1}", session.MailboxOwner.MailboxInfo.DisplayName, ex);
                throw new WorkingHoursXmlMalformedException(ServerStrings.MalformedWorkingHours(session.MailboxOwner.MailboxInfo.DisplayName, ex.ToString()), ex);
            }
            catch (XmlException ex2)
            {
                ExTraceGlobals.WorkHoursTracer.TraceError <string, XmlException>(-1L, "{0}: Hit an XmlException deserializing working hours XML in mailbox. Exception information is {1}", session.MailboxOwner.MailboxInfo.DisplayName, ex2);
                throw new WorkingHoursXmlMalformedException(ServerStrings.MalformedWorkingHours(session.MailboxOwner.MailboxInfo.DisplayName, ex2.ToString()), ex2);
            }
            return(workHoursInCalendar);
        }
Ejemplo n.º 4
0
 internal void SaveToCalendar(MailboxSession session, StoreId folderId)
 {
     try
     {
         using (UserConfiguration orCreateWorkingHourConfiguration = WorkHoursInCalendar.GetOrCreateWorkingHourConfiguration(session, folderId))
         {
             using (Stream xmlStream = orCreateWorkingHourConfiguration.GetXmlStream())
             {
                 xmlStream.SetLength(0L);
                 this.SerializeObject(xmlStream);
                 orCreateWorkingHourConfiguration.Save();
             }
         }
     }
     catch (InvalidOperationException ex)
     {
         ExTraceGlobals.WorkHoursTracer.TraceError <string, InvalidOperationException>((long)this.GetHashCode(), "{0}: Could not save work hours configuration item to mailbox. Exception information is {1}.", session.MailboxOwner.MailboxInfo.DisplayName, ex);
         throw new WorkingHoursXmlMalformedException(ServerStrings.SaveConfigurationItem(session.MailboxOwner.MailboxInfo.DisplayName, ex.ToString()));
     }
 }
Ejemplo n.º 5
0
 public static bool RemoveWorkingHoursFrom(MailboxSession session, StoreId folderId)
 {
     return(WorkHoursInCalendar.DeleteFromCalendar(session, folderId));
 }
Ejemplo n.º 6
0
        public void SaveTo(MailboxSession session, StoreId folderId)
        {
            WorkHoursInCalendar workHoursInCalendar = WorkHoursInCalendar.Create(this.timeZone, (int)this.daysOfWeek, this.startTimeInMinutes, this.endTimeInMinutes);

            workHoursInCalendar.SaveToCalendar(session, folderId);
        }