예제 #1
0
        public ZanmaiWikiSearchProvider(ZanmaiWikiSearchProviderOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.InitializationTask = Task.Run(async() =>
            {
                try
                {
                    using (var fs = new FileStream(options.IndexFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        var programs = await ZanmaiWikiSearchDataHelper.DeserializeProgramsAsync(fs)
                                       .ToArrayAsync()
                                       .ConfigureAwait(false);

                        this.Programs.AddRange(programs);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Failed to load search index.");
                    Debug.WriteLine(ex);
                }
            });
        }
        public async Task CreateIndexAsync(
            Stream outputStream,
            CancellationToken cancellationToken)
        {
            var programs = await this.RetrieveSongEntries(cancellationToken)
                           .ToArrayAsync()
                           .ConfigureAwait(false);

            await ZanmaiWikiSearchDataHelper.SerializeProgramsAsync(
                outputStream,
                programs,
                cancellationToken)
            .ConfigureAwait(false);
        }