/// <summary> /// Default constructor. All parameters populated via dependency injection /// </summary> /// <param name="labelFindQueue">Search request queue. See <see cref="SearchHub"/> for further information.</param> /// <param name="index">netMIH index for lookups</param> /// <param name="hubContext">SearchHub context for sending responses/results.</param> /// <param name="options">Configurable options</param> public SearchService(IBackgroundTaskQueue <Tuple <string, int, string> > labelFindQueue, netMIH.Index index, IHubContext <SearchHub> hubContext, IOptions <SearchServiceOptions> options) { _labelFindQueue = labelFindQueue; _index = index; _hubContext = hubContext; _options = options; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <PDQWrapper>(new PDQWrapper(Configuration["PDQ:Binary"])); services.AddSignalR(); var i = new netMIH.Index(); foreach (var f in Directory.EnumerateFiles("hashes", "*.PDQ")) { var newHashes = File.ReadAllLines(f); for (var counter = 0; counter < newHashes.Length; counter++) { newHashes[counter] = newHashes[counter].ToLower().Trim(); } Console.WriteLine($"Loading {newHashes.Length} hashes from {f}"); i.Update(newHashes, Path.GetFileName(f).Replace(".PDQ", "")); } i.Train(); Console.WriteLine($"Index reports {i.Count()} unique entries"); services.AddSingleton <netMIH.Index>(i); services.Configure <HashServiceOptions>(Configuration.GetSection("HashService")); services.AddSingleton <IBackgroundTaskQueue <Tuple <byte[], string, string> >, BackgroundQueue <Tuple <byte[], string, string> > >(); services.AddHostedService <HashService>(); services.Configure <SearchServiceOptions>(Configuration.GetSection("SearchService")); services.AddSingleton <IBackgroundTaskQueue <Tuple <string, int, string> >, BackgroundQueue <Tuple <string, int, string> > >(); services.AddHostedService <SearchService>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddSwaggerGen(c => { c.EnableAnnotations(); c.SwaggerDoc("v1", new Info { Title = "netPDQContainer", Version = "v1", License = new License() { Name = "MIT", Url = "https://github.com/AiLECS/netPDQContainer/blob/master/licence" }, Contact = new Contact() { Email = "*****@*****.**", Name = "Janis Dalins", Url = "https://github.com/AiLECS/netPDQContainer" }, Description = "A .NET core based API exposing the PDQ perceptual hashing algorithm by @facebook (\"PDQ as a service\")" }); c.IncludeXmlComments(Path.Combine(System.AppContext.BaseDirectory, "netPDQContainer.xml")); #region XMLDocumentationWorkaround // workaround for limitations regarding publication of XML comments from nuget dependencies within Swagger doc. if (Directory.Exists(System.AppContext.BaseDirectory + "documentation")) { foreach (var commentFile in Directory.EnumerateFiles(System.AppContext.BaseDirectory + "documentation")) { c.IncludeXmlComments(commentFile); } } #endregion }); }
/// <summary> /// Default constructor. All parameters passed via dependency injection. /// </summary> /// <param name="hashRequestQueue">Queue for incoming requests. <see cref="SearchHub"/> for further details. </param> /// <param name="index">netMIH index for lookups (populated at startup)</param> /// <param name="hubContext">Context for SearchHub (<see cref="SearchHub"/></param> /// <param name="wrapper">PDQ wrapper</param> /// <param name="options">Configurable options</param> public HashService(IBackgroundTaskQueue <Tuple <byte[], string, string> > hashRequestQueue, netMIH.Index index, IHubContext <SearchHub> hubContext, PDQWrapper wrapper, IOptions <HashServiceOptions> options) { _hashRequestQueue = hashRequestQueue; _hubContext = hubContext; _wrapper = wrapper; _options = options; }