/// <summary> /// Initialize LogSearcher with optional directory path, where cache database will be stored. /// </summary> /// <param name="dirPath">Absolute directory path, default null will use CodeBase</param> /// <param name="wipeExistingDb">Clears any existing database at dirPath location</param> /// <exception cref="InvalidOperationException">LogSearcher was already initialized</exception> /// <exception cref="Exception">There was an error while trying to initialize</exception> /// <returns></returns> public static void Initialize(string dirPath = null, bool wipeExistingDb = false) { if (isInitialized) throw new InvalidOperationException("LogSearcher already initialized"); try { Logger.LogInfo("Initializing API", THIS); LogSearchMan = new LogSearchManager(); LogSearchMan.CreateCacheDB(dirPath, wipeExistingDb); //wipeExistingDb); //exc here stop the init and allow recovery LogSearchMan.Initialize(); LogSearchMan.UpdateCache(); //ensure updates before first search SearcherUI = new FormLogSearcher(LogSearchMan); SearcherUI.WindowState = System.Windows.Forms.FormWindowState.Minimized; SearcherUI.Show(); //need to create window handle SearcherUI.Hide(); SearcherUI.StartUpdateLoop(); Logger.LogInfo("Init completed", THIS); isInitialized = true; _tcs.SetResult(true); } catch (Exception _e) { Logger.LogError("API init error", THIS, _e); throw; } }
/// <summary> /// This will rebuild entire log cache /// </summary> /// <param name="control">calling Control or any of it's inheritors</param> /// <param name="internalCall">will not do any BeginInvoke callbacks</param> /// <returns></returns> internal bool ForceRecache(FormLogSearcher control, bool internalCall) { var forceRecacheTask = new Task<LogSearchData>(x => { var ctrl = (FormLogSearcher)x; if (!internalCall) isForceRecaching = true; if (!internalCall) ForceRecachingOwner = ctrl; SearchDB.ClearDB(); SearchersDict.Clear(); Initialize(); return null; }, (object)control); EnqueueNewSearchTask(forceRecacheTask); return true; }