public void Save(SaveMode saveMode) { EnumValidator.ThrowIfInvalid <SaveMode>(saveMode); if (!this.IsLoaded) { throw new InvalidOperationException("The Master Category List is not loaded and thus cannot be saved"); } this.FlushCategoryUsageLog(); if (!this.IsDirty()) { return; } this.propertyBag[MasterCategoryListSchema.LastSavedTime] = ExDateTime.GetNow(ExTimeZone.UtcTimeZone); using (UserConfiguration folderConfiguration = this.session.UserConfigurationManager.GetFolderConfiguration("CategoryList", UserConfigurationTypes.XML, this.session.GetDefaultFolderId(DefaultFolderType.Calendar))) { MasterCategoryList masterCategoryList; using (Stream xmlStream = folderConfiguration.GetXmlStream()) { masterCategoryList = ((!this.configurationItemId.Equals(folderConfiguration.VersionedId)) ? this.MergeCopies(saveMode, folderConfiguration, xmlStream) : this); xmlStream.Position = 0L; using (Stream stream = new MemoryStream((int)xmlStream.Length)) { masterCategoryList.SaveToStream(saveMode, stream, xmlStream); if (stream.Length > 524288L) { throw new StoragePermanentException(ServerStrings.ExMclIsTooBig(stream.Length, 524288L)); } stream.Position = 0L; xmlStream.Position = 0L; xmlStream.SetLength(0L); Util.StreamHandler.CopyStreamData(stream, xmlStream); } } folderConfiguration.Save(); this.MovePersistentContent(masterCategoryList); this.originalMcl = this.Clone(); this.configurationItemId = folderConfiguration.VersionedId; this.loadedWithProblems = false; this.propertyBag.ClearChangeInfo(); this.isListModified = false; } }
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())); } }