private string GetObjectMessageClass <T>(Guid guid) where T : IConfigurable, new() { SearchObjectBase searchObjectBase = ((default(T) == null) ? Activator.CreateInstance <T>() : default(T)) as SearchObjectBase; if (searchObjectBase == null) { throw new ArgumentException(string.Format("Invalid type: {0}, only SearchObject or SearchStatus are supported!", typeof(T).Name)); } SearchObjectId searchObjectId = new SearchObjectId(this.MailboxOwnerId, searchObjectBase.ObjectType, guid); return("IPM.Configuration." + searchObjectId.ConfigurationName); }
public void Delete(SearchObjectBase deletedObject) { this.CheckDisposed("Delete"); if (deletedObject == null || deletedObject.Id == null) { throw new ArgumentNullException("deletedObject"); } OperationResult operationResult = this.MailboxSession.UserConfigurationManager.DeleteFolderConfigurations(this.MailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox), new string[] { deletedObject.Id.ConfigurationName }); if (operationResult != OperationResult.Succeeded) { MailboxDataStore.Tracer.TraceError <SearchObjectBase, IExchangePrincipal>((long)this.GetHashCode(), "Deleting object {0} from discovery mailbox {1} failed!", deletedObject, this.MailboxSession.MailboxOwner); } }
internal void Delete(SearchObjectBase instance) { if (instance == null) { throw new ArgumentNullException("instance"); } MailboxDataProvider.Tracer.TraceDebug <SearchObjectId>((long)this.GetHashCode(), "Deleting search object {0}", instance.Id); if (instance.ObjectState == ObjectState.Deleted) { throw new InvalidOperationException("The object has already been deleted"); } using (MailboxDataStore mailboxDataStore = this.OpenMailboxStore()) { mailboxDataStore.Delete(instance); } instance.MarkAsDeleted(); }
private void Save(SearchObjectBase instance) { if (instance == null) { throw new ArgumentNullException("instance"); } MailboxDataProvider.Tracer.TraceDebug <SearchObjectId>((long)this.GetHashCode(), "Saving search object {0}", instance.Id); if (instance.ObjectState == ObjectState.Deleted) { throw new InvalidOperationException("Calling Save() on a deleted object is not permitted. Delete() should be used instead."); } if (instance.ObjectState == ObjectState.Unchanged) { return; } bool flag = false; if (instance.ObjectState == ObjectState.New && (instance.Id == null || instance.Id.IsEmpty)) { instance.SetId(base.ADUser.Id, Guid.NewGuid()); flag = true; } ValidationError[] array = instance.Validate(); if (array.Length > 0) { throw new DataValidationException(array[0]); } using (MailboxDataStore mailboxDataStore = this.OpenMailboxStore()) { if (flag) { while (mailboxDataStore.Exists(instance.Id)) { instance.SetId(base.ADUser.Id, Guid.NewGuid()); } } instance.OnSaving(); mailboxDataStore.Save(instance); } instance.ResetChangeTracking(true); this.LogSaveEvent(instance); }
private void LogSaveEvent(SearchObjectBase obj) { SearchEventLogger.PropertyLogData propertyLogData = new SearchEventLogger.PropertyLogData(); if (base.ADUser.OrganizationId != null && base.ADUser.OrganizationId.ConfigurationUnit != null) { propertyLogData.AddOrganization(base.ADUser.OrganizationId.ConfigurationUnit.ToString()); } switch (obj.ObjectType) { case ObjectType.SearchObject: break; case ObjectType.SearchStatus: { SearchStatus searchStatus = (SearchStatus)obj; propertyLogData.AddSearchStatus(searchStatus); SearchEventLogger.Instance.LogSearchStatusSavedEvent(propertyLogData); if (searchStatus.Errors == null) { return; } using (MultiValuedProperty <string> .Enumerator enumerator = searchStatus.Errors.GetEnumerator()) { while (enumerator.MoveNext()) { string errorMsg = enumerator.Current; SearchEventLogger.Instance.LogSearchErrorEvent(obj.Id.ToString(), errorMsg); } return; } break; } default: return; } propertyLogData.AddSearchObject((SearchObject)obj); SearchEventLogger.Instance.LogSearchObjectSavedEvent(propertyLogData); }
public void Save(SearchObjectBase savedObject) { this.CheckDisposed("Save"); if (savedObject == null) { throw new ArgumentNullException("savedObject"); } using (UserConfiguration userConfiguration = this.OpenFaiMessage(savedObject.Id.ConfigurationName, true)) { bool flag = savedObject.IsChanged(SearchObjectBaseSchema.Name); using (Stream stream = userConfiguration.GetStream()) { savedObject.ResetChangeTracking(true); IFormatter formatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); formatter.Serialize(stream, savedObject); MailboxDataStore.Tracer.TraceDebug <SearchObjectBase, IExchangePrincipal>((long)this.GetHashCode(), "Saved {0} from discovery mailbox {1}.", savedObject, this.MailboxSession.MailboxOwner); } ConflictResolutionResult conflictResolutionResult = userConfiguration.Save(SaveMode.ResolveConflicts); if (conflictResolutionResult.SaveStatus == SaveResult.IrresolvableConflict) { throw new SaveConflictException(ServerStrings.ErrorSavingSearchObject(savedObject.Id.ToString()), conflictResolutionResult); } if (flag) { using (ConfigurationItem configurationItem = (ConfigurationItem)Item.Bind(this.MailboxSession, userConfiguration.Id, new PropertyDefinition[] { ItemSchema.Subject })) { configurationItem.OpenAsReadWrite(); configurationItem.Subject = savedObject.Name; configurationItem.Save(SaveMode.FailOnAnyConflict); } } } }
public IConfigurable Read <T>(SearchObjectId identity) where T : IConfigurable, new() { this.CheckDisposed("Read"); if (identity == null) { throw new ArgumentNullException("identity"); } SearchObjectBase searchObjectBase = ((default(T) == null) ? Activator.CreateInstance <T>() : default(T)) as SearchObjectBase; if (searchObjectBase == null || searchObjectBase.ObjectType != identity.ObjectType) { return(null); } IConfigurable result; using (UserConfiguration userConfiguration = this.OpenFaiMessage(identity.ConfigurationName, false)) { if (userConfiguration == null) { result = null; } else { using (Stream stream = userConfiguration.GetStream()) { T t = default(T); try { IFormatter formatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); t = (T)((object)formatter.Deserialize(stream)); } catch (InvalidOperationException ex) { MailboxDataStore.Tracer.TraceError <InvalidOperationException, SearchObjectId>((long)this.GetHashCode(), "SerializationException: {0} for search {1}!", ex, identity); throw new CorruptDataException(ServerStrings.StoreDataInvalid(identity.ToString()), ex); } catch (SerializationException ex2) { MailboxDataStore.Tracer.TraceError <SerializationException, SearchObjectId>((long)this.GetHashCode(), "SerializationException: {0} for search {1}!", ex2, identity); throw new CorruptDataException(ServerStrings.StoreDataInvalid(identity.ToString()), ex2); } if (t == null || t.Identity == null || !t.Identity.Equals(identity)) { MailboxDataStore.Tracer.TraceError <SearchObjectId, IExchangePrincipal>((long)this.GetHashCode(), "Reading {0} from discovery mailbox {1} failed with null object or incorrect identity!", identity, this.MailboxSession.MailboxOwner); throw new CorruptDataException(ServerStrings.StoreDataInvalid(identity.ToString())); } (t as SearchObjectBase).Id.MailboxOwnerId = this.MailboxOwnerId; MailboxDataStore.Tracer.TraceDebug <T, IExchangePrincipal>((long)this.GetHashCode(), "Read {0} from discovery mailbox {1}.", t, this.MailboxSession.MailboxOwner); ValidationError[] array = (t as ConfigurableObject).ValidateRead(); if (array.Length > 0) { throw new DataValidationException(array[0]); } if (t.GetType() == typeof(SearchObject)) { this.CacheSearchStatus(t as SearchObject); } result = t; } } } return(result); }