Ejemplo n.º 1
0
        void UpdateIndex(string fullPath, PendingRetrySource pendingRetrySource = null)
        {
            if (IsFile(fullPath))
            {
                var fileInfo = new FileInfo(fullPath);
                try
                {
                    Thread.Sleep(WaitMilliseconds); // Wait to let file finished write to disk

                    if (fileInfo.Exists)
                    {
                        var content  = FilesContentHelper.ReadAllText(fullPath);
                        var document = CodeIndexBuilder.GetDocumentFromSource(CodeSource.GetCodeSource(fileInfo, content));
                        CodeIndexBuilder.UpdateIndex(config.LuceneIndexForCode, GetNoneTokenizeFieldTerm(nameof(CodeSource.FilePath), fullPath), document);
                        WordsHintBuilder.UpdateWordsHint(config, WordSegmenter.GetWords(content), log);
                        pendingChanges++;
                    }
                }
                catch (IOException)
                {
                    AddFileChangesToRetrySouce(fullPath, WatcherChangeTypes.Changed, pendingRetrySource);
                }
                catch (Exception ex)
                {
                    log?.Error(ex.ToString());
                }
            }
        }
Ejemplo n.º 2
0
        void CreateNewIndex(string fullPath, PendingRetrySource pendingRetrySource = null)
        {
            if (IsFile(fullPath))
            {
                var fileInfo = new FileInfo(fullPath);
                try
                {
                    Thread.Sleep(WaitMilliseconds); // Wait to let file finished write to disk

                    if (fileInfo.Exists)
                    {
                        var content = FilesContentHelper.ReadAllText(fullPath);
                        CodeIndexBuilder.BuildIndex(config, false, false, false, new[] { CodeSource.GetCodeSource(fileInfo, content) });
                        WordsHintBuilder.UpdateWordsHint(config, WordSegmenter.GetWords(content), log);
                        pendingChanges++;
                    }
                }
                catch (IOException)
                {
                    AddFileChangesToRetrySouce(fullPath, WatcherChangeTypes.Created, pendingRetrySource);
                }
                catch (Exception ex)
                {
                    log?.Error(ex.ToString());
                }
            }
        }
Ejemplo n.º 3
0
        void AddFileChangesToRetrySouce(string fullPath, WatcherChangeTypes changesType, PendingRetrySource pendingRetrySource, string oldFullPath = null)
        {
            if (pendingRetrySource == null)
            {
                pendingRetrySource = new PendingRetrySource
                {
                    FilePath         = fullPath,
                    LastRetryUTCDate = DateTime.UtcNow,
                    ChangesType      = changesType,
                    OldPath          = oldFullPath
                };
            }
            else
            {
                pendingRetrySource.RetryTimes++;
                pendingRetrySource.LastRetryUTCDate = DateTime.UtcNow;
            }

            pendingRetryCodeSources.Enqueue(pendingRetrySource);
        }
Ejemplo n.º 4
0
        void FileRenamed(string oldFullPath, string fullPath, PendingRetrySource pendingRetrySource = null)
        {
            try
            {
                if (IsFile(fullPath))
                {
                    var fileInfo = new FileInfo(fullPath);

                    try
                    {
                        if (fileInfo.Exists)
                        {
                            var content  = FilesContentHelper.ReadAllText(fullPath);
                            var document = CodeIndexBuilder.GetDocumentFromSource(CodeSource.GetCodeSource(fileInfo, content));
                            CodeIndexBuilder.UpdateIndex(config.LuceneIndexForCode, GetNoneTokenizeFieldTerm(nameof(CodeSource.FilePath), oldFullPath), document);
                            pendingChanges++;
                        }
                    }
                    catch (IOException)
                    {
                        AddFileChangesToRetrySouce(fullPath, WatcherChangeTypes.Renamed, pendingRetrySource, oldFullPath);
                    }
                }
                else if (IsDirectory(fullPath))
                {
                    // Rebuild All Sub Directory Index File, rename the index path
                    var term = new PrefixQuery(GetNoneTokenizeFieldTerm(nameof(CodeSource.FilePath), oldFullPath));
                    var docs = CodeIndexSearcher.Search(config.LuceneIndexForCode, term, int.MaxValue);
                    foreach (var doc in docs)
                    {
                        CodeIndexBuilder.UpdateCodeFilePath(doc, oldFullPath, fullPath);
                        CodeIndexBuilder.UpdateIndex(config.LuceneIndexForCode, new Term(nameof(CodeSource.CodePK), doc.Get(nameof(CodeSource.CodePK))), doc);
                        pendingChanges++;
                    }
                }
            }
            catch (Exception ex)
            {
                log?.Error(ex.ToString());
            }
        }