internal static bool SameNameExists(string name, DiscoverySearchDataProvider e15DataProvider, MailboxDataProvider e14DataProvider) { return(e15DataProvider.Find <MailboxDiscoverySearch>(name) != null || Utils.GetE14SearchObjectByName(name, e14DataProvider) != null); }
public void ApplyConfiguration(ISearchPolicy policy, ref SearchMailboxesInputs inputs) { Recorder.Trace(5L, TraceType.InfoTrace, "ArbitrationSearchConfigurationProvider.ApplyConfiguration Inputs:", inputs); if (inputs.Sources != null && inputs.Sources.Count > 0 && inputs.Sources[0].SourceType == SourceType.SavedSearchId) { inputs.SearchConfigurationId = inputs.Sources[0].ReferenceId; inputs.Sources.RemoveAt(0); Recorder.Trace(5L, TraceType.InfoTrace, "ArbitrationSearchConfigurationProvider.ApplyConfiguration Found In Sources SearchId:", inputs.SearchConfigurationId); } if (!string.IsNullOrWhiteSpace(inputs.SearchConfigurationId)) { Recorder.Trace(5L, TraceType.InfoTrace, "ArbitrationSearchConfigurationProvider.ApplyConfiguration Found SearchId:", inputs.SearchConfigurationId); IDiscoverySearchDataProvider discoverySearchDataProvider = new DiscoverySearchDataProvider(policy.RecipientSession.SessionSettings.CurrentOrganizationId); MailboxDiscoverySearch mailboxDiscoverySearch = discoverySearchDataProvider.Find <MailboxDiscoverySearch>(inputs.SearchConfigurationId); if (mailboxDiscoverySearch == null) { Recorder.Trace(5L, TraceType.ErrorTrace, "ArbitrationSearchConfigurationProvider.ApplyConfiguration Invalid SearchId:", inputs.SearchConfigurationId); throw new SearchException(KnownError.ErrorInvalidSearchId); } inputs.SearchQuery = mailboxDiscoverySearch.CalculatedQuery; inputs.Language = mailboxDiscoverySearch.Language; Recorder.Trace(5L, TraceType.InfoTrace, new object[] { "ArbitrationSearchConfigurationProvider.ApplyConfiguration Query:", inputs.SearchQuery, "Language:", inputs.Language }); if (inputs.Sources == null || inputs.Sources.Count == 0) { Recorder.Trace(5L, TraceType.InfoTrace, "ArbitrationSearchConfigurationProvider.ApplyConfiguration No Sources"); inputs.Sources = new List <SearchSource>(); if (mailboxDiscoverySearch.Sources != null && mailboxDiscoverySearch.Sources.Count > 0) { Recorder.Trace(5L, TraceType.InfoTrace, "ArbitrationSearchConfigurationProvider.ApplyConfiguration Mailboxes:", mailboxDiscoverySearch.Sources.Count); using (MultiValuedProperty <string> .Enumerator enumerator = mailboxDiscoverySearch.Sources.GetEnumerator()) { while (enumerator.MoveNext()) { string referenceId = enumerator.Current; inputs.Sources.Add(new SearchSource { ReferenceId = referenceId, SourceLocation = SourceLocation.All, SourceType = SourceType.AutoDetect }); } goto IL_234; } } if (mailboxDiscoverySearch.Version == SearchObjectVersion.Original || mailboxDiscoverySearch.AllSourceMailboxes) { Recorder.Trace(5L, TraceType.InfoTrace, "ArbitrationSearchConfigurationProvider.ApplyConfiguration AllMailboxes"); inputs.Sources.Add(new SearchSource { SourceLocation = SourceLocation.All, SourceType = SourceType.AllMailboxes }); } IL_234: if (mailboxDiscoverySearch.PublicFolderSources != null && mailboxDiscoverySearch.PublicFolderSources.Count > 0) { Recorder.Trace(5L, TraceType.InfoTrace, "ArbitrationSearchConfigurationProvider.ApplyConfiguration PublicFoiders:", mailboxDiscoverySearch.PublicFolderSources.Count); using (MultiValuedProperty <string> .Enumerator enumerator2 = mailboxDiscoverySearch.PublicFolderSources.GetEnumerator()) { while (enumerator2.MoveNext()) { string referenceId2 = enumerator2.Current; inputs.Sources.Add(new SearchSource { ReferenceId = referenceId2, SourceLocation = SourceLocation.All, SourceType = SourceType.PublicFolder }); } return; } } if (mailboxDiscoverySearch.AllPublicFolderSources) { Recorder.Trace(5L, TraceType.InfoTrace, "ArbitrationSearchConfigurationProvider.ApplyConfiguration AllPublicFoiders"); inputs.Sources.Add(new SearchSource { SourceLocation = SourceLocation.PrimaryOnly, SourceType = SourceType.AllPublicFolders }); } } } }
internal static MailboxDiscoverySearch UpgradeLegacySearchObject(SearchObject searchObject, MailboxDataProvider e14DataProvider, DiscoverySearchDataProvider e15DataProvider, Task.TaskErrorLoggingDelegate writeErrorDelegate, Action <LocalizedString> writeWarningDelegate) { MailboxDiscoverySearch mailboxDiscoverySearch = new MailboxDiscoverySearch(); if (e15DataProvider.Find <MailboxDiscoverySearch>(searchObject.Name) != null) { mailboxDiscoverySearch.Name = searchObject.Name + Guid.NewGuid().ToString(); } else { mailboxDiscoverySearch.Name = searchObject.Name; } mailboxDiscoverySearch.Senders = searchObject.Senders; mailboxDiscoverySearch.CreatedBy = searchObject.CreatedByEx; mailboxDiscoverySearch.Description = Strings.UpgradedSearchObjectDescription; mailboxDiscoverySearch.EndDate = searchObject.EndDate; mailboxDiscoverySearch.StartDate = searchObject.StartDate; mailboxDiscoverySearch.ExcludeDuplicateMessages = searchObject.ExcludeDuplicateMessages; mailboxDiscoverySearch.StatisticsOnly = searchObject.EstimateOnly; mailboxDiscoverySearch.IncludeUnsearchableItems = searchObject.IncludeUnsearchableItems; mailboxDiscoverySearch.IncludeKeywordStatistics = searchObject.IncludeKeywordStatistics; mailboxDiscoverySearch.Language = searchObject.Language.ToString(); mailboxDiscoverySearch.LogLevel = searchObject.LogLevel; mailboxDiscoverySearch.ManagedBy = searchObject.ManagedBy; mailboxDiscoverySearch.MessageTypes = searchObject.MessageTypes; mailboxDiscoverySearch.Query = Utils.ConvertAqsToKql(searchObject.SearchQuery, searchObject.Language); mailboxDiscoverySearch.Recipients = searchObject.Recipients; mailboxDiscoverySearch.StatusMailRecipients = searchObject.StatusMailRecipients; mailboxDiscoverySearch.ManagedByOrganization = e15DataProvider.OrganizationId.ToString(); mailboxDiscoverySearch.LegacySearchObjectIdentity = searchObject.Identity.ToString(); if (searchObject.SourceMailboxes != null && searchObject.SourceMailboxes.Count > 0) { MultiValuedProperty <string> multiValuedProperty = new MultiValuedProperty <string>(); Result <ADRawEntry>[] first = e14DataProvider.RecipientSession.ReadMultiple(searchObject.SourceMailboxes.ToArray(), new PropertyDefinition[] { ADRecipientSchema.DisplayName, ADRecipientSchema.LegacyExchangeDN, ADObjectSchema.ExchangeVersion }); foreach (ADRawEntry adrawEntry in from x in first select x.Data) { if (adrawEntry != null) { if (((ExchangeObjectVersion)adrawEntry[ADObjectSchema.ExchangeVersion]).IsOlderThan(ExchangeObjectVersion.Exchange2012)) { writeErrorDelegate(new MailboxSearchTaskException(Strings.SourceMailboxMustBeE15OrLater((string)adrawEntry[ADRecipientSchema.DisplayName])), ErrorCategory.InvalidArgument, null); } else { multiValuedProperty.Add((string)adrawEntry[ADRecipientSchema.LegacyExchangeDN]); } } } if (multiValuedProperty.Count > 0) { mailboxDiscoverySearch.Sources = multiValuedProperty; } } ADUser aduser = null; if (searchObject.TargetMailbox != null) { aduser = (ADUser)e14DataProvider.RecipientSession.Read(searchObject.TargetMailbox); if (aduser != null) { mailboxDiscoverySearch.Target = aduser.LegacyExchangeDN; } } e15DataProvider.CreateOrUpdate <MailboxDiscoverySearch>(mailboxDiscoverySearch); Exception ex = null; try { if (searchObject.SearchStatus != null) { if (!string.IsNullOrEmpty(searchObject.SearchStatus.ResultsPath) && aduser != null) { string serverFqdn = ExchangePrincipal.FromADUser(e14DataProvider.RecipientSession.SessionSettings, aduser, RemotingOptions.AllowCrossSite).MailboxInfo.Location.ServerFqdn; if (!string.IsNullOrEmpty(serverFqdn)) { goto IL_395; } Utils.< > c__DisplayClassc CS$ < > 8__locals1 = new Utils.< > c__DisplayClassc(); CS$ < > 8__locals1.searchId = new SearchId(e14DataProvider.ADUser.Id.DistinguishedName, e14DataProvider.ADUser.Id.ObjectGuid, searchObject.Id.Guid.ToString()); using (MailboxSearchClient client = new MailboxSearchClient(serverFqdn)) { Utils.RpcCallWithRetry(delegate() { client.Remove(CS$ < > 8__locals1.searchId, true); }); goto IL_395; } } e14DataProvider.Delete(searchObject.SearchStatus); } IL_395: e14DataProvider.Delete(searchObject); } catch (RpcConnectionException ex2) { ex = ex2; } catch (RpcException ex3) { ex = ex3; } catch (StoragePermanentException ex4) { ex = ex4; } catch (StorageTransientException ex5) { ex = ex5; } if (ex != null) { writeWarningDelegate(Strings.FailedToDeleteE14SearchObjectWhenUpgrade(searchObject.Name, ex.Message)); } return(e15DataProvider.FindByAlternativeId <MailboxDiscoverySearch>(searchObject.Name)); }