[AutomaticRetry(Attempts = BackgroundJobsConstants.NumberOfRetries)] //configure hangfire to retry on failure
        public void CreateIndex(CreateIndexRequest model, PerformContext context)
        {
            string cachedManagementInformation;

            if (m_MemoryCache.TryGetValue <string>(CacheKeys.ManagementInformationKey, out cachedManagementInformation))
            {
                m_Manager.ManagementInformationPath = cachedManagementInformation;
            }

            var indexId = m_Manager.CreateIndex(model.SourcePath, model.FileExtensions);

            if (context != null)
            {
                m_MemoryCache.Set(context.BackgroundJob.Id, indexId);
            }
            else
            {
                m_Logger.Debug($"hangfire.io didn't inject PerformContext instance, didn't save indexId into memory cache ");
            }
        }
示例#2
0
        internal static void ShowCreateNewIndexMenu(ICodeSearcherManager manager, ITextBasedUserInterface tui, IMenuNavigator nav)
        {
            string answer;
            // Source path
            string sourcePath = null;

            do
            {
                tui.WriteLine("Please enter Path with Sources to Index:");
                answer = tui.ReadLine();
                if (Directory.Exists(answer))
                {
                    sourcePath = answer;
                    tui.WriteLine($"Path with files to Index: {sourcePath}");
                    break;
                }
                tui.WriteLine("Path do not exist!");
            } while (tui.ShouldLoop());

            // file extensions
            var extensions = new List <String>();

            tui.WriteLine("Please select file extension to index (form .ext1,.ext2)");
            tui.WriteLine("Leave empty to use (.cs,.xml,.csproj) ");
            answer = tui.ReadLine();
            if (string.IsNullOrWhiteSpace(answer))
            {
                extensions.Add(".cs");
                extensions.Add(".xml");
                extensions.Add(".csproj");
            }
            else
            {
                foreach (var extension in answer.Split(new[] { ',' }))
                {
                    extensions.Add(extension);
                }
            }

            tui.WriteLine("Looking for files with extensions: ");
            extensions.ForEach((ext) => tui.WriteLine($"File Extension: {ext}"));

            if (!string.IsNullOrWhiteSpace(sourcePath) && extensions.Count > 0)
            {
                var id = manager.CreateIndex(sourcePath, extensions);
                tui.WriteLine($"New Index created with ID: {id}");
                do
                {
                    tui.WriteLine("[1] Search in new created index");
                    tui.WriteLine("[2] Back to main menu");
                    tui.WriteLine("Please choose: ");
                    answer = tui.ReadLine();
                    if (int.TryParse(answer, out int selection))
                    {
                        if (1.Equals(selection))
                        {
                            var selectedIndex = manager.GetIndexById(id);
                            nav.GoToSelectedIndexMenu(manager, selectedIndex, tui);
                        }
                        else if (2.Equals(selection))
                        {
                            nav.GoToMainMenu(tui);
                        }
                    }
                } while (tui.ShouldLoop());
            }
        }