protected override void Dispose(bool disposing) { if (isDisposed) { return; } if (disposing) { if (fsDir != null) { fsDir.Close(); } } fsDir = null; isDisposed = true; }
public virtual void TestFSDirectoryDifferentLockFactory() { System.IO.FileInfo indexDirName = _TestUtil.GetTempDir("index.TestLockFactory5"); LockFactory lf = new SingleInstanceLockFactory(); FSDirectory fs1 = FSDirectory.GetDirectory(indexDirName, lf); // Different lock factory instance should hit IOException: try { FSDirectory.GetDirectory(indexDirName, new SingleInstanceLockFactory()); Assert.Fail("Should have hit an IOException because LockFactory instances differ"); } catch (System.IO.IOException e) { } FSDirectory fs2 = null; // Same lock factory instance should not: try { fs2 = FSDirectory.GetDirectory(indexDirName, lf); } catch (System.IO.IOException e) { System.Console.Out.WriteLine(e.StackTrace); Assert.Fail("Should not have hit an IOException because LockFactory instances are the same"); } fs1.Close(); if (fs2 != null) { fs2.Close(); } // Cleanup _TestUtil.RmDir(indexDirName); }
private void LukeInit(OpenIndex openIndexDlg) { indexPath = openIndexDlg.Path; _readOnly = openIndexDlg.ReadOnlyIndex; bool force = openIndexDlg.UnlockIndex; FSDirectory newDir = FSDirectory.Open(new DirectoryInfo(indexPath)); if (indexPath == String.Empty || !IndexReader.IndexExists(newDir)) { ErrorMessage(resources.GetString("InvalidPath")); return; } if (dir != null) { try { if (indexReader != null) indexReader.Close(); } catch (Exception) { }; try { dir.Close(); } catch (Exception) { }; } try { dir = newDir; p.AddToMruList(indexPath); if (IndexWriter.IsLocked(dir)) { if (_readOnly) { ShowStatus(resources.GetString("IndexLockedRo")); dir.Close(); return; } if (force) { IndexWriter.Unlock(dir); } else { ShowStatus(resources.GetString("IndexLocked")); dir.Close(); return; } } // files tab tabFiles.ShowFiles(dir); indexReader = IndexReader.Open(dir, true); menuItemCompound.Checked = p.UseCompound; // plugins tab pluginsTabPage.LoadPlugins(); // overview tab InitOverview(); searchTabPage.UpdateListSearch(indexFields); ShowStatus(resources.GetString("IndexOpened")); } catch (Exception e) { ErrorMessage(e.Message); } }