Exemplo n.º 1
0
 private double GetNumber(string key, double fallback)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, new object[]
     {
         "ExecutionPolicySettings.GetNumber Key:",
         key,
         "Fallback:",
         fallback
     });
     if (this.settingsMap.ContainsKey(key))
     {
         Recorder.Trace(2L, TraceType.InfoTrace, "ExecutionPolicySettings.GetNumber Found Setting Key:", key);
         double num;
         if (double.TryParse(this.settingsMap[key].Value, out num))
         {
             if (num == -1.0)
             {
                 num = 4294967295.0;
             }
             Recorder.Trace(2L, TraceType.InfoTrace, new object[]
             {
                 "ExecutionPolicySettings.GetNumber Found Setting Key:",
                 key,
                 "Value:",
                 num
             });
             return(num);
         }
     }
     return(fallback);
 }
Exemplo n.º 2
0
 private bool GetBool(string key, bool fallback)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, new object[]
     {
         "ExecutionPolicySettings.GetBool Key:",
         key,
         "Fallback:",
         fallback
     });
     if (this.settingsMap.ContainsKey(key))
     {
         Recorder.Trace(2L, TraceType.InfoTrace, "ExecutionPolicySettings.GetBool Found Setting Key:", key);
         bool flag;
         if (bool.TryParse(this.settingsMap[key].Value, out flag))
         {
             Recorder.Trace(2L, TraceType.InfoTrace, new object[]
             {
                 "ExecutionPolicySettings.GetBool Found Setting Key:",
                 key,
                 "Value:",
                 flag
             });
             return(flag);
         }
     }
     return(fallback);
 }
Exemplo n.º 3
0
        public virtual IThrottlingPolicy GetThrottlingPolicy(ISearchPolicy policy)
        {
            Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetThrottlingPolicy");
            DiscoveryTenantBudgetKey discoveryTenantBudgetKey = new DiscoveryTenantBudgetKey(policy.RecipientSession.SessionSettings.CurrentOrganizationId, BudgetType.PowerShell);

            return(discoveryTenantBudgetKey.Lookup());
        }
Exemplo n.º 4
0
 public Executor(ISearchPolicy policy, Type taskType)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "Executor.ctor Task:", taskType);
     this.defaultTimeout     = policy.ExecutionSettings.SearchTimeout;
     this.Policy             = policy;
     this.TaskType           = taskType;
     this.ExecutesInParallel = this.Policy.ExecutionSettings.DiscoveryExecutesInParallel;
     this.useRealThreads     = this.useRealThreads;
 }
Exemplo n.º 5
0
 public virtual void EnqueueNext(object item)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "Executor.Chain Item:", item);
     if (this.ChainedExecutor != null)
     {
         this.ChainedExecutor.Enqueue(item);
         return;
     }
     this.Context.Output = item;
 }
Exemplo n.º 6
0
 public virtual ISourceConverter GetSourceConverter(ISearchPolicy policy, SourceType sourceFrom)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetSourceConverter SourceType:", sourceFrom);
     if (sourceFrom == SourceType.PublicFolder || sourceFrom == SourceType.AllPublicFolders)
     {
         return(new PublicFolderSourceConverter());
     }
     Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetSourceConverter No Converter SourceType:", sourceFrom);
     return(null);
 }
Exemplo n.º 7
0
 protected virtual void SignalComplete()
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "Executor.SignalComplete");
     this.queue.CompleteAdding();
     if (!this.IsSynchronous)
     {
         this.EnsureThreads();
     }
     this.AttemptComplete();
 }
Exemplo n.º 8
0
 protected virtual void CreateThread()
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "Executor.CreateThreads Real:", this.useRealThreads);
     if (this.useRealThreads)
     {
         new Thread(new ParameterizedThreadStart(this.RunThread))
         {
             Name = string.Format("DiscoveryExecutionThread: {0}", this.TaskType)
         }.Start();
         return;
     }
     ThreadPool.QueueUserWorkItem(new WaitCallback(this.RunThread));
 }
Exemplo n.º 9
0
 public virtual ISearchResultProvider GetSearchResultProvider(ISearchPolicy policy, SearchType searchType)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetSearchResultProvider");
     if (searchType == SearchType.NonIndexedItemPreview || searchType == SearchType.NonIndexedItemStatistics)
     {
         return(new LocalNonIndexedResultProvider());
     }
     if (policy.ExecutionSettings.DiscoveryUseFastSearch && searchType == SearchType.Preview)
     {
         return(new FastLocalSearchResultsProvider());
     }
     return(new LocalSearchResultsProvider());
 }
Exemplo n.º 10
0
        public virtual void Fail(Exception ex)
        {
            Recorder.Trace(2L, TraceType.WarningTrace, "Executor.Fail Error:", ex);
            this.Context.Failures.Add(ex);
            Recorder.Record record = this.Policy.Recorder.Start(this.TaskType.Name, TraceType.ErrorTrace, true);
            SearchException ex2    = ex as SearchException;

            if (ex2 != null)
            {
                record.Attributes["FailError"]  = ex2.Error.ToString();
                record.Attributes["FailSource"] = ex2.Source;
            }
            record.Attributes["EX"] = ex.ToString();
            this.Policy.Recorder.End(record);
        }
Exemplo n.º 11
0
 protected virtual void RunTask(object item)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, new object[]
     {
         "Executor.RunTask Item:",
         item,
         "IsCancelled:",
         this.IsCancelled
     });
     if (!this.IsCancelled)
     {
         ITask task = null;
         try
         {
             long timestamp = this.Policy.Recorder.Timestamp;
             task       = (Activator.CreateInstance(this.TaskType) as ITask);
             task.State = new SearchTaskContext
             {
                 TaskContext = this.TaskContext,
                 Executor    = this,
                 Item        = item
             };
             task.Execute(this.defaultQueueDelay, this.defaultTimeout);
             task.Complete(this.defaultQueueDelay, this.defaultTimeout);
             long num = this.Policy.Recorder.Timestamp - timestamp;
             Interlocked.Increment(ref this.itemCount);
             Interlocked.Add(ref this.totalDuration, num);
             IList list = item as IList;
             int   num2 = 1;
             if (list != null)
             {
                 num2 = list.Count;
             }
             this.batchDurations.Add(new Tuple <long, long, long>(timestamp, num, (long)num2));
         }
         catch (SearchException ex)
         {
             if (task != null)
             {
                 task.Cancel();
             }
             this.Cancel(ex);
             Recorder.Trace(2L, TraceType.ErrorTrace, "Executor.RunTask Failed Error:", ex);
         }
     }
 }
Exemplo n.º 12
0
            private List <T> GetEnumList <T>(string key) where T : struct, IConvertible
            {
                Recorder.Trace(2L, TraceType.InfoTrace, "ExecutionPolicySettings.GetList Key:", key);
                if (!typeof(T).IsEnum)
                {
                    throw new ArgumentException("Specified type is not an enum");
                }
                List <T> list = new List <T>();

                if (this.settingsMap.ContainsKey(key))
                {
                    string value = this.settingsMap[key].Value;
                    Recorder.Trace(2L, TraceType.InfoTrace, new object[]
                    {
                        "ExecutionPolicySettings.GetList Setting Key:",
                        key,
                        "Value:",
                        (value == null) ? string.Empty : value
                    });
                    if (!string.IsNullOrWhiteSpace(value))
                    {
                        string[] array = value.Split(new char[]
                        {
                            ','
                        });
                        foreach (string text in array)
                        {
                            T item;
                            if (Enum.TryParse <T>(text, true, out item))
                            {
                                list.Add(item);
                            }
                            else
                            {
                                Recorder.Trace(2L, TraceType.InfoTrace, "ExecutionPolicySettings.GetList invalid enum value:", text);
                            }
                        }
                    }
                    else
                    {
                        Recorder.Trace(2L, TraceType.InfoTrace, "ExecutionPolicySettings.GetList Setting key not found:", key);
                    }
                }
                return(list);
            }
Exemplo n.º 13
0
        public virtual VariantConfigurationSnapshot GetVariantConfigurationSnapshot(ISearchPolicy policy)
        {
            Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetVariantConfigurationSnapshot");
            VariantConfigurationSnapshot variantConfigurationSnapshot = null;

            if (policy.RunspaceConfiguration != null && policy.RunspaceConfiguration.ExecutingUser != null)
            {
                Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetVariantConfigurationSnapshot Loading User Snapshpt");
                ADUser user = new ADUser(policy.RecipientSession, policy.RunspaceConfiguration.ExecutingUser.propertyBag);
                variantConfigurationSnapshot = VariantConfiguration.GetSnapshot(user.GetContext(null), null, null);
            }
            if (variantConfigurationSnapshot == null)
            {
                Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetVariantConfigurationSnapshot User Snapshot Failed, Loading Global Snapshot");
                variantConfigurationSnapshot = VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null);
            }
            return(variantConfigurationSnapshot);
        }
Exemplo n.º 14
0
 protected virtual void AttemptComplete()
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "Executor.AttemptComplete");
     if ((this.queue.IsCompleted && this.current < 0) || this.IsCancelled)
     {
         Recorder.Trace(2L, TraceType.InfoTrace, "Executor.AttemptComplete Started");
         if (this.currentRecord != null)
         {
             this.currentRecord.Attributes["COUNT"]        = this.itemCount;
             this.currentRecord.Attributes["WORKDURATION"] = this.totalDuration;
             this.Policy.Recorder.End(this.currentRecord);
             if (this.batchDurations.Count > 0)
             {
                 string          description = string.Format("{0}Batches", this.currentRecord.Description);
                 Recorder.Record record      = this.Policy.Recorder.Start(description, TraceType.InfoTrace, false);
                 int             num         = 0;
                 foreach (Tuple <long, long, long> tuple in this.batchDurations)
                 {
                     record.Attributes[string.Format("BATCH{0}START", num)]    = tuple.Item1;
                     record.Attributes[string.Format("BATCH{0}DURATION", num)] = tuple.Item2;
                     record.Attributes[string.Format("BATCH{0}COUNT", num)]    = tuple.Item3;
                     num++;
                 }
                 this.Policy.Recorder.End(record);
             }
         }
         if (this.ChainedExecutor != null)
         {
             Recorder.Trace(2L, TraceType.InfoTrace, "Executor.AttemptComplete SignalNext");
             this.ChainedExecutor.SignalComplete();
         }
         else
         {
             Recorder.Trace(2L, TraceType.InfoTrace, "Executor.AttemptComplete SignalRoot");
             if (this.Context != null && !this.Context.IsDisposed && this.Context.WaitHandle != null && !this.Context.WaitHandle.SafeWaitHandle.IsClosed)
             {
                 this.Context.WaitHandle.Set();
             }
         }
         Recorder.Trace(2L, TraceType.InfoTrace, "Executor.AttemptComplete Completed");
     }
 }
Exemplo n.º 15
0
        public virtual object Process(object item)
        {
            Recorder.Trace(2L, TraceType.InfoTrace, "Executor.Process Item:", item);
            this.EnsureContext();
            object output;

            using (this.Context)
            {
                if (this.Context.Input != null || !this.IsEnqueable || this.Context.Output != null)
                {
                    Recorder.Trace(2L, TraceType.ErrorTrace, new object[]
                    {
                        "Executor.Process Invalid State  Input:",
                        this.Context.Input,
                        "Enqueuable:",
                        this.IsEnqueable,
                        "Output:",
                        this.Context.Output
                    });
                    throw new InvalidOperationException();
                }
                this.Context.Input = item;
                this.Enqueue(item);
                this.SignalComplete();
                bool flag = this.Context.WaitHandle.WaitOne(this.Policy.ExecutionSettings.SearchTimeout);
                if (this.Context.FatalException != null)
                {
                    Recorder.Trace(2L, TraceType.ErrorTrace, "Executor.Process Failed Error:", this.Context.FatalException);
                    throw new SearchException(this.Context.FatalException);
                }
                if (!flag)
                {
                    Recorder.Trace(2L, TraceType.ErrorTrace, "Executor.Process TimedOut");
                    Exception ex = new SearchException(KnownError.ErrorSearchTimedOut);
                    this.Cancel(ex);
                    throw ex;
                }
                Recorder.Trace(2L, TraceType.InfoTrace, "Executor.Process Completed Output:", this.Context.Output);
                output = this.Context.Output;
            }
            return(output);
        }
Exemplo n.º 16
0
        public virtual void Cancel(Exception ex)
        {
            Recorder.Trace(2L, TraceType.ErrorTrace, "Executor.Cancel Called Error:", ex);
            if (!this.IsCancelled)
            {
                Recorder.Trace(2L, TraceType.ErrorTrace, "Executor.Cancel First Cancel Error:", ex);
                this.Context.FatalException = ex;
                this.Context.CancellationTokenSource.Cancel(false);
                this.AttemptComplete();
            }
            Recorder.Record record = this.Policy.Recorder.Start(this.TaskType.Name, TraceType.FatalTrace, true);
            SearchException ex2    = ex as SearchException;

            if (ex2 != null)
            {
                record.Attributes["CancelError"]  = ex2.Error.ToString();
                record.Attributes["CancelSource"] = ex2.Source;
            }
            record.Attributes["EX"] = ex.ToString();
            this.Policy.Recorder.End(record);
        }
Exemplo n.º 17
0
            private bool LookupRegBool(string name, out bool boolValue)
            {
                boolValue = false;
                bool result;

                try
                {
                    using (RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32))
                    {
                        using (RegistryKey registryKey2 = registryKey.OpenSubKey("SOFTWARE\\Microsoft\\ExchangeServer\\v15\\eDiscovery"))
                        {
                            if (registryKey2 != null)
                            {
                                string text = registryKey2.GetValue(name) as string;
                                bool   flag;
                                if (text == null || !bool.TryParse(text, out flag))
                                {
                                    result = false;
                                }
                                else
                                {
                                    boolValue = flag;
                                    result    = true;
                                }
                            }
                            else
                            {
                                Recorder.Trace(2L, TraceType.InfoTrace, "SearchPolicySettings.LookupRegBool: Registry not found for constants");
                                result = false;
                            }
                        }
                    }
                }
                catch (Exception arg)
                {
                    Recorder.Trace(2L, TraceType.InfoTrace, string.Format("SearchPolicySettings.LookupRegBool: Failed to load registry data. Details: {0}", arg));
                    result = false;
                }
                return(result);
            }
Exemplo n.º 18
0
 protected virtual void Enqueue(object item)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, new object[]
     {
         "Executor.Enqueue Item:",
         item,
         "Enqueable:",
         this.IsEnqueable,
         "Sync:",
         this.IsSynchronous
     });
     this.EnsureRecorder();
     if (this.IsEnqueable)
     {
         if (this.IsSynchronous)
         {
             this.RunThread(item);
             return;
         }
         this.queue.Add(item);
         this.EnsureThreads();
     }
 }
Exemplo n.º 19
0
 protected override void Enqueue(object item)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "BatchedExecutor.Enqueue Item:", item);
     if (item != null)
     {
         string text = this.BatchKeyFactory(item);
         if (text != null)
         {
             lock (this.updateLock)
             {
                 List <object> list;
                 if (this.items.ContainsKey(text))
                 {
                     list = this.items[text];
                 }
                 else
                 {
                     list             = new List <object>();
                     this.items[text] = list;
                 }
                 list.Add(item);
                 if ((long)list.Count >= (long)((ulong)this.BatchSize))
                 {
                     this.EnqueueBatch(text);
                 }
                 return;
             }
         }
         Recorder.Trace(2L, TraceType.WarningTrace, new object[]
         {
             "BatchedExecutor.Enqueue Null Key Task:",
             base.TaskType,
             "Item:",
             item
         });
     }
 }
Exemplo n.º 20
0
        protected virtual void EnsureThreads()
        {
            Recorder.Trace(2L, TraceType.InfoTrace, "Executor.EnsureThreads");
            if ((!this.ExecutesInParallel && !this.queue.IsAddingCompleted) || this.IsSynchronous)
            {
                return;
            }
            uint num  = Math.Min((uint)this.queue.Count, (uint)((ulong)this.threads - (ulong)((long)this.current)));
            uint num2 = 0U;

            while ((long)this.current < (long)((ulong)this.threads) && num2 < num)
            {
                int num3 = Interlocked.Increment(ref this.current);
                if ((long)num3 < (long)((ulong)this.threads))
                {
                    this.CreateThread();
                }
                else
                {
                    Interlocked.Decrement(ref this.current);
                }
                num2 += 1U;
            }
        }
Exemplo n.º 21
0
 public virtual IConfigurationSession GetConfigurationSession(ISearchPolicy policy)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetConfigurationSession");
     return(DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, policy.RecipientSession.SessionSettings, 222, "GetConfigurationSession", "f:\\15.00.1497\\sources\\dev\\EDiscovery\\src\\MailboxSearch\\WebService\\Infrastructure\\SearchFactory.cs"));
 }
Exemplo n.º 22
0
 public virtual IExchangeProxy GetProxy(ISearchPolicy policy, FanoutParameters parameter)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetProxy");
     return(new ExchangeProxy(policy, parameter));
 }
Exemplo n.º 23
0
 public virtual ISearchConfigurationProvider GetSearchConfigurationProvider(ISearchPolicy policy)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetSearchConfigurationProvider");
     return(new ArbitrationSearchConfigurationProvider());
 }
Exemplo n.º 24
0
 public virtual IServerProvider GetServerProvider(ISearchPolicy policy)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetServerProvider");
     return(new AutoDiscoveryServerProvider());
 }
Exemplo n.º 25
0
 public virtual IDirectoryProvider GetDirectoryProvider(ISearchPolicy policy)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetDirectoryProvider");
     return(new ActiveDirectoryProvider());
 }
Exemplo n.º 26
0
 public virtual ISearchPolicy GetSearchPolicy(IRecipientSession recipientSession, CallerInfo callerInfo, ExchangeRunspaceConfiguration runspaceConfiguration, IBudget budget = null)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "SearchFactory.GetSearchPolicy");
     return(new SearchPolicy(recipientSession, callerInfo, runspaceConfiguration, budget));
 }
Exemplo n.º 27
0
 public BatchedExecutor(ISearchPolicy policy, Type taskType) : base(policy, taskType)
 {
     Recorder.Trace(2L, TraceType.InfoTrace, "BatchedExecutor.ctor Task:", taskType);
     this.BatchSize       = policy.ExecutionSettings.DiscoveryMaxAllowedExecutorItems;
     this.BatchKeyFactory = BatchedExecutor.BatchByCount;
 }
Exemplo n.º 28
0
 protected virtual void RunThread(object state)
 {
     try
     {
         Recorder.Trace(2L, TraceType.InfoTrace, new object[]
         {
             "Executor.RunThread State:",
             state,
             "Synchronous:",
             this.IsSynchronous,
             "Current:",
             this.current
         });
         GrayException.MapAndReportGrayExceptions(delegate()
         {
             try
             {
                 if (this.IsSynchronous)
                 {
                     Interlocked.Increment(ref this.current);
                     this.RunTask(state);
                 }
                 else
                 {
                     foreach (object item in this.queue.GetConsumingEnumerable())
                     {
                         this.RunTask(item);
                     }
                 }
             }
             catch (OperationCanceledException)
             {
                 Recorder.Trace(2L, TraceType.WarningTrace, "Executor.RunThread OperationCancelled");
             }
             catch (SearchException ex2)
             {
                 Recorder.Trace(2L, TraceType.ErrorTrace, "Executor.RunThread Search Error:", ex2);
                 this.Cancel(ex2);
             }
         });
     }
     catch (GrayException ex)
     {
         Recorder.Trace(2L, TraceType.ErrorTrace, "Executor.RunThread Gray Error:", ex);
         this.Cancel(ex);
     }
     finally
     {
         Interlocked.Decrement(ref this.current);
         Recorder.Trace(2L, TraceType.InfoTrace, new object[]
         {
             "Executor.RunThread Completed Current:",
             this.current,
             "Cancelled:",
             this.IsCancelled
         });
         if (!this.IsCancelled)
         {
             this.AttemptComplete();
         }
     }
 }