private void OnQueryDriverChanged (Queryable queryable, IQueryableChangeData change_data) { bool is_indexing = QueryDriver.IsIndexing; if (is_indexing && crawl_status == IndexingStatus.NotRunning) SendIndexingStatusResponse (IndexingStatus.Running); else if (! is_indexing && crawl_status == IndexingStatus.Running) SendIndexingStatusResponse (IndexingStatus.NotRunning); }
// Instantiates and loads a StaticQueryable from an index directory internal static Queryable LoadStaticQueryable(DirectoryInfo index_dir, QueryDomain query_domain) { StaticQueryable static_queryable = null; if (!index_dir.Exists) { return(null); } try { static_queryable = new StaticQueryable(index_dir.Name, index_dir.FullName, true); } catch (InvalidOperationException) { Logger.Log.Warn("Unable to create read-only index (likely due to index version mismatch): {0}", index_dir.FullName); return(null); } catch (Exception e) { Logger.Log.Error(e, "Caught exception while instantiating static queryable: {0}", index_dir.Name); return(null); } if (static_queryable == null) { return(null); } // Load StaticIndex.xml from index_dir.FullName/config string config_file_path = Path.Combine(index_dir.FullName, "StaticIndex.xml"); Config static_index_config; try { static_index_config = Conf.LoadFrom(config_file_path); if (static_index_config == null) { Log.Error("Unable to read config from {0}", config_file_path); return(null); } } catch (Exception e) { Log.Error(e, "Caught exception while reading config from {0}", config_file_path); return(null); } string source = static_index_config.GetOption("Source", null); if (source == null) { Log.Error("Invalid config file: {0}", config_file_path); return(null); } QueryableFlavor flavor = new QueryableFlavor(); flavor.Name = source; flavor.Domain = query_domain; Queryable queryable = new Queryable(flavor, static_queryable); return(queryable); }
// A method to fire the ChangedEvent event. static public void QueryableChanged(IQueryable iqueryable, IQueryableChangeData change_data) { if (ChangedEvent != null) { Queryable queryable = iqueryable_to_queryable [iqueryable] as Queryable; ChangedEvent(queryable, change_data); } }
private static ResponseMessage AddRemovableIndex(string path, string mnt_dir) { DirectoryInfo index_dir = new DirectoryInfo(StringFu.SanitizePath(path)); if (!index_dir.Exists) { ErrorResponse msg; msg = new ErrorResponse(); msg.ErrorMessage = "Adding removable index failed"; msg.Details = String.Format("'{0}' does not exist.", path); return(msg); } // Allow late loading of mount dir ? mnt_dir = StringFu.SanitizePath(mnt_dir); if (!Directory.Exists(mnt_dir)) { ErrorResponse msg; msg = new ErrorResponse(); msg.ErrorMessage = "Adding removable index failed"; msg.Details = String.Format("Mount directory '{0}' does not exist.", mnt_dir); return(msg); } if (removable_queryables.ContainsKey(path)) { ErrorResponse msg; msg = new ErrorResponse(); msg.ErrorMessage = "Adding removable index failed"; msg.Details = String.Format("'{0}' already added.", path); return(msg); } Queryable removable_queryable = null; try { iqueryable_lock.AcquireWriterLock(System.Threading.Timeout.Infinite); removable_queryable = StaticQueryable.LoadRemovableQueryable(index_dir, mnt_dir); } finally { iqueryable_lock.ReleaseWriterLock(); } if (removable_queryable == null) { return(new ErrorResponse("Adding removable index failed")); } iqueryable_to_queryable [removable_queryable.IQueryable] = removable_queryable; removable_queryables [path] = removable_queryable; RemovableIndexResponse resp = new RemovableIndexResponse(); resp.Source = removable_queryable.Name; Log.Info("Adding removable index '{0}' from {1}", resp.Source, path); return(resp); }
public QueryClosure(Queryable queryable, Query query, QueryResult result, IQueryableChangeData change_data) { this.queryable = queryable; this.query = query; this.result = result; this.change_data = change_data; }
private void OnQueryDriverChanged(Queryable queryable, IQueryableChangeData change_data) { bool is_indexing = QueryDriver.IsIndexing; if (is_indexing && crawl_status == IndexingStatus.NotRunning) { SendIndexingStatusResponse(IndexingStatus.Running); } else if (!is_indexing && crawl_status == IndexingStatus.Running) { SendIndexingStatusResponse(IndexingStatus.NotRunning); } }
private static ResponseMessage RemoveRemovableIndex(string path, string mnt_dir) { if (!removable_queryables.ContainsKey(path)) { ErrorResponse msg; msg = new ErrorResponse(); msg.ErrorMessage = "Removing removable-index failed"; msg.Details = String.Format("'{0}' was not added.", path); return(msg); } Queryable removable_queryable = removable_queryables [path]; // Assert if (removable_queryable == null || !(removable_queryable.IQueryable is StaticQueryable)) { ErrorResponse msg = new ErrorResponse("Removing removable-index failed"); return(msg); } StaticQueryable static_queryable = (StaticQueryable)removable_queryable.IQueryable; if (static_queryable.RemovableMountDir != mnt_dir) { ErrorResponse msg; msg = new ErrorResponse(); msg.ErrorMessage = "Removing removable-index failed"; msg.Details = String.Format("No index mounted at {0}.", mnt_dir); return(msg); } static_queryable.Close(); removable_queryables.Remove(path); try { iqueryable_lock.AcquireWriterLock(System.Threading.Timeout.Infinite); iqueryable_to_queryable [removable_queryable.IQueryable] = null; iqueryable_to_queryable.Remove(removable_queryable.IQueryable); } finally { iqueryable_lock.ReleaseWriterLock(); } RemovableIndexResponse resp = new RemovableIndexResponse(); resp.Source = removable_queryable.Name; Log.Info("Removed removable-index '{0}' at {1}", removable_queryable.Name, path); return(resp); }
static public void DoOneQuery(Queryable queryable, Query query, QueryResult result, IQueryableChangeData change_data) { try { if (queryable.AcceptQuery(query)) { QueryClosure qc = new QueryClosure(queryable, query, result, change_data); result.AttachWorker(qc); } } catch (Exception ex) { Logger.Log.Warn(ex, "Caught exception calling DoOneQuery on '{0}'", queryable.Name); } }
internal static Queryable LoadRemovableQueryable(DirectoryInfo index_dir, string mnt_dir) { Queryable queryable = LoadStaticQueryable(index_dir, QueryDomain.Local); if (queryable == null) { return(null); } StaticQueryable static_queryable; static_queryable = (StaticQueryable)queryable.IQueryable; static_queryable.mount_dir = mnt_dir; return(queryable); }
// (1) register themselves in AssemblyInfo.cs:IQueryableTypes and // (2) has a QueryableFlavor attribute attached // assemble a Queryable object and stick it into our list of queryables. static void ScanAssemblyForQueryables(Assembly assembly) { int count = 0; foreach (Type type in ReflectionFu.GetTypesFromAssemblyAttribute(assembly, typeof(IQueryableTypesAttribute))) { foreach (QueryableFlavor flavor in ReflectionFu.ScanTypeForAttribute(type, typeof(QueryableFlavor))) { if (!UseQueryable(flavor.Name)) { continue; } if (flavor.RequireInotify && !Inotify.Enabled) { Logger.Log.Warn("Can't start backend '{0}' without inotify", flavor.Name); continue; } if (flavor.RequireExtendedAttributes && !ExtendedAttribute.Supported) { Logger.Log.Warn("Can't start backend '{0}' without extended attributes", flavor.Name); continue; } IQueryable iq = null; try { iq = Activator.CreateInstance(type) as IQueryable; } catch (Exception e) { Logger.Log.Error(e, "Caught exception while instantiating {0} backend", flavor.Name); } if (iq != null) { Queryable q = new Queryable(flavor, iq); iqueryable_to_queryable [iq] = q; ++count; break; } } } Logger.Log.Debug("Found {0} backends in {1}", count, assembly.Location); }
// Instantiates and loads a StaticQueryable from an index directory internal static Queryable LoadStaticQueryable (DirectoryInfo index_dir, QueryDomain query_domain) { StaticQueryable static_queryable = null; if (!index_dir.Exists) return null; try { static_queryable = new StaticQueryable (index_dir.Name, index_dir.FullName, true); } catch (InvalidOperationException) { Logger.Log.Warn ("Unable to create read-only index (likely due to index version mismatch): {0}", index_dir.FullName); return null; } catch (Exception e) { Logger.Log.Error (e, "Caught exception while instantiating static queryable: {0}", index_dir.Name); return null; } if (static_queryable == null) return null; // Load StaticIndex.xml from index_dir.FullName/config string config_file_path = Path.Combine (index_dir.FullName, "StaticIndex.xml"); Config static_index_config; try { static_index_config = Conf.LoadFrom (config_file_path); if (static_index_config == null) { Log.Error ("Unable to read config from {0}", config_file_path); return null; } } catch (Exception e) { Log.Error (e, "Caught exception while reading config from {0}", config_file_path); return null; } string source = static_index_config.GetOption ("Source", null); if (source == null) { Log.Error ("Invalid config file: {0}", config_file_path); return null; } QueryableFlavor flavor = new QueryableFlavor (); flavor.Name = source; flavor.Domain = query_domain; Queryable queryable = new Queryable (flavor, static_queryable); return queryable; }
static public void DoOneQuery (Queryable queryable, Query query, QueryResult result, IQueryableChangeData change_data) { try { if (queryable.AcceptQuery (query)) { QueryClosure qc = new QueryClosure (queryable, query, result, change_data); result.AttachWorker (qc); } } catch (Exception ex) { Logger.Log.Warn (ex, "Caught exception calling DoOneQuery on '{0}'", queryable.Name); } }
public QueryClosure (Queryable queryable, Query query, QueryResult result, IQueryableChangeData change_data) { this.queryable = queryable; this.query = query; this.result = result; this.change_data = change_data; }
// (1) register themselves in AssemblyInfo.cs:IQueryableTypes and // (2) has a QueryableFlavor attribute attached // assemble a Queryable object and stick it into our list of queryables. static void ScanAssemblyForQueryables (Assembly assembly) { int count = 0; foreach (Type type in ReflectionFu.GetTypesFromAssemblyAttribute (assembly, typeof (IQueryableTypesAttribute))) { foreach (QueryableFlavor flavor in ReflectionFu.ScanTypeForAttribute (type, typeof (QueryableFlavor))) { if (! UseQueryable (flavor.Name)) continue; if (flavor.RequireInotify && ! Inotify.Enabled) { Logger.Log.Warn ("Can't start backend '{0}' without inotify", flavor.Name); continue; } if (flavor.RequireExtendedAttributes && ! ExtendedAttribute.Supported) { Logger.Log.Warn ("Can't start backend '{0}' without extended attributes", flavor.Name); continue; } IQueryable iq = null; try { iq = Activator.CreateInstance (type) as IQueryable; } catch (Exception e) { Logger.Log.Error (e, "Caught exception while instantiating {0} backend", flavor.Name); } if (iq != null) { Queryable q = new Queryable (flavor, iq); iqueryable_to_queryable [iq] = q; ++count; break; } } } Logger.Log.Debug ("Found {0} backends in {1}", count, assembly.Location); }
private void OnQueryDriverChanged (Queryable queryable, IQueryableChangeData change_data) { if (this.result != null) QueryDriver.DoOneQuery (queryable, this.query, this.result, change_data); }