public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            //ensure name is set
            _name = name;

            //We need to check if we actually can initialize, if not then don't continue
            if (CanInitialize() == false)
            {
                return;
            }

            base.Initialize(name, config);

            if (config != null && config["useTempStorage"] != null)
            {
                //Use the temp storage directory which will store the index in the local/codegen folder, this is useful
                // for websites that are running from a remove file server and file IO latency becomes an issue
                var attemptUseTempStorage = config["useTempStorage"].TryConvertTo <LocalStorageType>();
                if (attemptUseTempStorage)
                {
                    var indexSet       = IndexSets.Instance.Sets[IndexSetName];
                    var configuredPath = indexSet.IndexPath;
                    var codegenPath    = HttpRuntime.CodegenDir;
                    _localTempPath    = Path.Combine(codegenPath, configuredPath.TrimStart('~', '/').Replace("/", "\\"));
                    _localStorageType = attemptUseTempStorage.Result;
                }
            }
        }
        public void Initialize(NameValueCollection config, string configuredPath, FSDirectory baseLuceneDirectory, Analyzer analyzer, LocalStorageType localStorageType)
        {
            var codegenPath = HttpRuntime.CodegenDir;

            TempPath = Path.Combine(codegenPath, configuredPath.TrimStart('~', '/').Replace("/", "\\"));

            switch (localStorageType)
            {
                case LocalStorageType.Sync:
                    var success = InitializeLocalIndexAndDirectory(baseLuceneDirectory, analyzer, configuredPath);

                    //create the custom lucene directory which will keep the main and temp FS's in sync
                    LuceneDirectory = LocalTempStorageDirectoryTracker.Current.GetDirectory(
                        new DirectoryInfo(TempPath),
                        baseLuceneDirectory,
                        //flag to disable the mirrored folder if not successful
                        (int)success >= 100);

                    //If the master index simply doesn't exist, we don't continue to try to open anything since there will
                    // actually be nothing there.
                    if (success == InitializeDirectoryFlags.SuccessNoIndexExists)
                    {
                        return;
                    }

                    //Try to open the reader, this will fail if the index is corrupt and we'll need to handle that
                    var result = DelegateExtensions.RetryUntilSuccessOrMaxAttempts(i =>
                    {
                        try
                        {
                            using (IndexReader.Open(
                                LuceneDirectory,
                                DeletePolicyTracker.Current.GetPolicy(LuceneDirectory),
                                true))
                            {
                            }

                            return Attempt.Succeed(true);
                        }
                        catch (Exception ex)
                        {
                            LogHelper.WarnWithException<LocalTempStorageIndexer>(
                                string.Format("Could not open an index reader, local temp storage index is empty or corrupt... retrying... {0}", configuredPath),
                                ex);
                        }
                        return Attempt.Fail(false);
                    }, 5, TimeSpan.FromSeconds(1));

                    if (result.Success == false)
                    {
                        LogHelper.Warn<LocalTempStorageIndexer>(
                                string.Format("Could not open an index reader, local temp storage index is empty or corrupt... attempting to clear index files in local temp storage, will operate from main storage only {0}", configuredPath));

                        ClearFilesInPath(TempPath);

                        //create the custom lucene directory which will keep the main and temp FS's in sync
                        LuceneDirectory = LocalTempStorageDirectoryTracker.Current.GetDirectory(
                            new DirectoryInfo(TempPath),
                            baseLuceneDirectory,
                            //Disable mirrored index, we're kind of screwed here only use master index
                            true);
                    }

                    break;
                case LocalStorageType.LocalOnly:
                    if (System.IO.Directory.Exists(TempPath) == false)
                    {
                        System.IO.Directory.CreateDirectory(TempPath);
                    }
                    LuceneDirectory = DirectoryTracker.Current.GetDirectory(new DirectoryInfo(TempPath));
                    break;
                default:
                    throw new ArgumentOutOfRangeException("localStorageType");
            }
        }
        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            //ensure name is set
            _name = name;

            //We need to check if we actually can initialize, if not then don't continue
            if (CanInitialize() == false)
            {
                return;
            }

            base.Initialize(name, config);

            //NOTES: useTempStorage is obsolete, tempStorageDirectory is obsolete, both have been superceded by Examine Core's IDirectoryFactory
            //       tempStorageDirectory never actually got finished in Umbraco Core but accidentally got shipped (it's only enabled on the searcher
            //       and not the indexer). So this whole block is just legacy

            //detect if a dir factory has been specified, if so then useTempStorage will not be used (deprecated)
            if (config != null && config["directoryFactory"] == null && config["useTempStorage"] != null)
            {
                //Use the temp storage directory which will store the index in the local/codegen folder, this is useful
                // for websites that are running from a remove file server and file IO latency becomes an issue
                var attemptUseTempStorage = config["useTempStorage"].TryConvertTo <LocalStorageType>();
                if (attemptUseTempStorage)
                {
                    //this is the default
                    ILocalStorageDirectory localStorageDir = new CodeGenLocalStorageDirectory();
                    if (config["tempStorageDirectory"] != null)
                    {
                        //try to get the type
                        var dirType = BuildManager.GetType(config["tempStorageDirectory"], false);
                        if (dirType != null)
                        {
                            try
                            {
                                localStorageDir = (ILocalStorageDirectory)Activator.CreateInstance(dirType);
                            }
                            catch (Exception ex)
                            {
                                LogHelper.Error <UmbracoExamineSearcher>(
                                    string.Format("Could not create a temp storage location of type {0}, reverting to use the " + typeof(CodeGenLocalStorageDirectory).FullName, dirType),
                                    ex);
                            }
                        }
                    }
                    var indexSet       = IndexSets.Instance.Sets[IndexSetName];
                    var configuredPath = indexSet.IndexPath;
                    var tempPath       = localStorageDir.GetLocalStorageDirectory(config, configuredPath);
                    if (tempPath == null)
                    {
                        throw new InvalidOperationException("Could not resolve a temp location from the " + localStorageDir.GetType() + " specified");
                    }
                    _localTempPath    = tempPath.FullName;
                    _localStorageType = attemptUseTempStorage.Result;
                }
            }
        }
        public void Initialize(NameValueCollection config, string configuredPath, FSDirectory baseLuceneDirectory, Analyzer analyzer, LocalStorageType localStorageType)
        {
            var codegenPath = HttpRuntime.CodegenDir;

            TempPath = Path.Combine(codegenPath, configuredPath.TrimStart('~', '/').Replace("/", "\\"));

            switch (localStorageType)
            {
            case LocalStorageType.Sync:
                var success = InitializeLocalIndexAndDirectory(baseLuceneDirectory, analyzer, configuredPath);

                //create the custom lucene directory which will keep the main and temp FS's in sync
                LuceneDirectory = LocalTempStorageDirectoryTracker.Current.GetDirectory(
                    new DirectoryInfo(TempPath),
                    baseLuceneDirectory,
                    //flag to disable the mirrored folder if not successful
                    (int)success >= 100);

                //If the master index simply doesn't exist, we don't continue to try to open anything since there will
                // actually be nothing there.
                if (success == InitializeDirectoryFlags.SuccessNoIndexExists)
                {
                    return;
                }

                //Try to open the reader, this will fail if the index is corrupt and we'll need to handle that
                var result = DelegateExtensions.RetryUntilSuccessOrMaxAttempts(i =>
                {
                    try
                    {
                        using (IndexReader.Open(
                                   LuceneDirectory,
                                   DeletePolicyTracker.Current.GetPolicy(LuceneDirectory),
                                   true))
                        {
                        }

                        return(Attempt.Succeed(true));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.WarnWithException <LocalTempStorageIndexer>(
                            string.Format("Could not open an index reader, local temp storage index is empty or corrupt... retrying... {0}", configuredPath),
                            ex);
                    }
                    return(Attempt.Fail(false));
                }, 5, TimeSpan.FromSeconds(1));

                if (result.Success == false)
                {
                    LogHelper.Warn <LocalTempStorageIndexer>(
                        string.Format("Could not open an index reader, local temp storage index is empty or corrupt... attempting to clear index files in local temp storage, will operate from main storage only {0}", configuredPath));

                    ClearFilesInPath(TempPath);

                    //create the custom lucene directory which will keep the main and temp FS's in sync
                    LuceneDirectory = LocalTempStorageDirectoryTracker.Current.GetDirectory(
                        new DirectoryInfo(TempPath),
                        baseLuceneDirectory,
                        //Disable mirrored index, we're kind of screwed here only use master index
                        true);
                }

                break;

            case LocalStorageType.LocalOnly:
                if (System.IO.Directory.Exists(TempPath) == false)
                {
                    System.IO.Directory.CreateDirectory(TempPath);
                }
                LuceneDirectory = DirectoryTracker.Current.GetDirectory(new DirectoryInfo(TempPath));
                break;

            default:
                throw new ArgumentOutOfRangeException("localStorageType");
            }
        }
        public void Initialize(NameValueCollection config, string configuredPath, FSDirectory baseLuceneDirectory, Analyzer analyzer, LocalStorageType localStorageType)
        {
            //this is the default
            ILocalStorageDirectory localStorageDir = new CodeGenLocalStorageDirectory();

            if (config["tempStorageDirectory"] != null)
            {
                //try to get the type
                var dirType = BuildManager.GetType(config["tempStorageDirectory"], false);
                if (dirType != null)
                {
                    try
                    {
                        localStorageDir = (ILocalStorageDirectory)Activator.CreateInstance(dirType);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error <LocalTempStorageIndexer>(
                            string.Format("Could not create a temp storage location of type {0}, reverting to use the " + typeof(CodeGenLocalStorageDirectory).FullName, dirType),
                            ex);
                    }
                }
            }

            var tempPath = localStorageDir.GetLocalStorageDirectory(config, configuredPath);

            if (tempPath == null)
            {
                throw new InvalidOperationException("Could not resolve a temp location from the " + localStorageDir.GetType() + " specified");
            }
            TempPath = tempPath.FullName;

            switch (localStorageType)
            {
            case LocalStorageType.Sync:
                var success = InitializeLocalIndexAndDirectory(baseLuceneDirectory, analyzer, configuredPath);

                //create the custom lucene directory which will keep the main and temp FS's in sync
                LuceneDirectory = LocalTempStorageDirectoryTracker.Current.GetDirectory(
                    new DirectoryInfo(TempPath),
                    baseLuceneDirectory,
                    //flag to disable the mirrored folder if not successful
                    (int)success >= 100);

                //If the master index simply doesn't exist, we don't continue to try to open anything since there will
                // actually be nothing there.
                if (success == InitializeDirectoryFlags.SuccessNoIndexExists)
                {
                    return;
                }

                //Try to open the reader, this will fail if the index is corrupt and we'll need to handle that
                var result = DelegateExtensions.RetryUntilSuccessOrMaxAttempts(i =>
                {
                    try
                    {
                        using (IndexReader.Open(
                                   LuceneDirectory,
                                   DeletePolicyTracker.Current.GetPolicy(LuceneDirectory),
                                   true))
                        {
                        }

                        return(Attempt.Succeed(true));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.WarnWithException <LocalTempStorageIndexer>(
                            string.Format("Could not open an index reader, local temp storage index is empty or corrupt... retrying... {0}", configuredPath),
                            ex);
                    }
                    return(Attempt.Fail(false));
                }, 5, TimeSpan.FromSeconds(1));

                if (result.Success == false)
                {
                    LogHelper.Warn <LocalTempStorageIndexer>(
                        string.Format("Could not open an index reader, local temp storage index is empty or corrupt... attempting to clear index files in local temp storage, will operate from main storage only {0}", configuredPath));

                    ClearFilesInPath(TempPath);

                    //create the custom lucene directory which will keep the main and temp FS's in sync
                    LuceneDirectory = LocalTempStorageDirectoryTracker.Current.GetDirectory(
                        new DirectoryInfo(TempPath),
                        baseLuceneDirectory,
                        //Disable mirrored index, we're kind of screwed here only use master index
                        true);
                }

                break;

            case LocalStorageType.LocalOnly:
                if (Directory.Exists(TempPath) == false)
                {
                    Directory.CreateDirectory(TempPath);
                }
                LuceneDirectory = DirectoryTracker.Current.GetDirectory(new DirectoryInfo(TempPath));
                break;

            default:
                throw new ArgumentOutOfRangeException("localStorageType");
            }
        }