コード例 #1
0
ファイル: BookmarkFormatter.cs プロジェクト: NHxD/NHxD
 private Formatter GetBookmarkFormatter(SearchArg searchArg)
 {
     return(new Formatter(new ITokenReplacer[]
     {
         new SearchTokenReplacer(searchArg, TagsModel)
     }, TokenModifiers));
 }
コード例 #2
0
        // FIXME

        /*
         * private void LibraryModel_Poll(object sender, LibraryModel.LibraryEventArgs e)
         * {
         *      LibraryModel.LibraryEvent fileSystemEvent = e.LibraryEvent;
         *
         *      if (fileSystemEvent.EventType == LibraryModel.LibraryEventType.Rename)
         *      {
         *              FileSystemWatcher_Renamed(libraryModel.FileSystemWatcher, fileSystemEvent.EventData as RenamedEventArgs);
         *      }
         *      else if (fileSystemEvent.EventType == LibraryModel.LibraryEventType.Create)
         *      {
         *              FileSystemWatcher_Created(libraryModel.FileSystemWatcher, fileSystemEvent.EventData as FileSystemEventArgs);
         *      }
         *      else if (fileSystemEvent.EventType == LibraryModel.LibraryEventType.Delete)
         *      {
         *              FileSystemWatcher_Deleted(libraryModel.FileSystemWatcher, fileSystemEvent.EventData as FileSystemEventArgs);
         *      }
         * }
         *
         * private void FileSystemWatcher_Renamed(object sender, RenamedEventArgs e)
         * {
         *      // TODO
         * }
         *
         * // FIXME: I think this doesn't work anymore.
         * private void FileSystemWatcher_Created(object sender, FileSystemEventArgs e)
         * {
         *      int galleryId = ExtractGalleryIdFromFileName(e.Name);
         *
         *      if (galleryId == -1)
         *      {
         *              return;
         *      }
         *
         *      Metadata metadata = GetGalleryMetadata(galleryId, PathFormatter, SearchResultCache);
         *
         *      if (metadata == null)
         *      {
         *              return;
         *      }
         *
         *      HtmlDocument document = webBrowser.Document;
         *
         *      if (document == null)
         *      {
         *              return;
         *      }
         *
         *      HtmlElementCollection bodies = document.GetElementsByTagName("BODY");
         *
         *      if (bodies == null || bodies.Count == 0)
         *      {
         *              return;
         *      }
         *
         *      HtmlElement script = document.CreateElement("SCRIPT");
         *      script.SetAttribute("text", string.Format(CultureInfo.InvariantCulture, "searchResult.result.push({0}); ++searchResult.per_page", JsonConvert.SerializeObject(metadata)));
         *
         *      bodies[0].AppendChild(script);
         *
         *      webBrowser.Document.InvokeScript("__onGalleryAdded", new object[] { JsonConvert.SerializeObject(metadata) });
         *
         *      // TODO: need to inject this html as well...
         *      HtmlElement searchResultContainer = document.GetElementById("search-result-container");
         *
         *      string result = LibraryCovergridItemTemplate.GetText(metadata);
         *
         *      searchResultContainer.InnerHtml = searchResultContainer.InnerHtml + result;
         * }
         *
         * private void FileSystemWatcher_Deleted(object sender, FileSystemEventArgs e)
         * {
         *      int galleryId = ExtractGalleryIdFromFileName(e.Name);
         *
         *      if (galleryId == -1)
         *      {
         *              return;
         *      }
         *
         *      //Metadata metadata = GetGalleryMetadata(galleryId, PathFormatter);
         *
         *      webBrowser.Document.InvokeScript("__onGalleryRemoved", new object[] { galleryId });
         * }
         */

        public void Search()
        {
            SearchArg searchArg = new SearchArg(LibraryModel.PageIndex, true);

            webBrowser.Tag          = searchArg;
            webBrowser.DocumentText = LibraryPreloadTemplate.GetFormattedText(searchArg);
        }
コード例 #3
0
ファイル: SearchHandler.cs プロジェクト: Klein69/NHxD
        public void RunSearch(SearchArg searchArg, bool activateGalleryTab)
        {
            if (activateGalleryTab)
            {
                MainViewTabControl.SelectTab(GalleryBrowserViewTabPage);
            }

            currentSearchArg = searchArg;

            GalleryModel.SearchArg = searchArg;
        }
コード例 #4
0
        private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            SearchArg searchArg = webBrowser.Tag as SearchArg;

            if (searchArg != null)
            {
                GalleryWebBrowser_PreloadDocumentCompleted(sender, e);
            }
            else
            {
                GalleryWebBrowser_SearchDocumentCompleted(sender, e);
            }
        }
コード例 #5
0
 public SearchDoArg(SearchArg searchArg
                    , TagsModel tagsModel
                    , SearchHandler searchHandler
                    , GallerySortType sortType
                    , SortOrder sortOrder
                    , MetadataKeywordLists metadataKeywordLists)
 {
     SearchArg            = searchArg;
     TagsModel            = tagsModel;
     SearchHandler        = searchHandler;
     SortType             = sortType;
     SortOrder            = sortOrder;
     MetadataKeywordLists = metadataKeywordLists;
 }
コード例 #6
0
 public LibraryLoadRunArg(IPathFormatter pathFormatter, ISearchResultCache searchResultCache, SearchArg searchArg, int numItemsPerPage, string libraryPath
                          , GallerySortType sortType, LibrarySortType globalSortType
                          , SortOrder sortOrder, SortOrder globalSortOrder)
 {
     PathFormatter     = pathFormatter;
     SearchResultCache = searchResultCache;
     SearchArg         = searchArg;
     NumItemsPerPage   = numItemsPerPage;
     LibraryPath       = libraryPath;
     SortType          = sortType;
     GlobalSortType    = globalSortType;
     SortOrder         = sortOrder;
     GlobalSortOrder   = globalSortOrder;
 }
コード例 #7
0
        private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            SearchArg         searchArg         = webBrowser.Tag as SearchArg;
            SearchProgressArg searchProgressArg = webBrowser.Tag as SearchProgressArg;

            if (searchArg != null)
            {
                WebBrowser_PreloadDocumentCompleted(sender, e);
            }
            else if (searchProgressArg != null)
            {
                WebBrowser_LibraryDocumentCompleted(sender, e);
            }
        }
コード例 #8
0
        private void GalleryWebBrowser_PreloadDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            SearchArg searchArg = webBrowser.Tag as SearchArg;

            if (searchArg == null)
            {
                return;
            }

            if (listBackgroundWorker.IsBusy)
            {
                return;
            }

            SearchDoArg searchDoArg = new SearchDoArg(searchArg, TagsModel, SearchHandler, GalleryBrowserSettings.SortType, GalleryBrowserSettings.SortOrder, MetadataKeywordLists);

            listBackgroundWorker.RunWorkerAsync(searchDoArg);
        }
コード例 #9
0
        private void WebBrowser_PreloadDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            SearchArg searchArg = webBrowser.Tag as SearchArg;

            if (searchArg == null)
            {
                return;
            }

            if (backgroundWorker.IsBusy)
            {
                return;
            }

            LibraryLoadRunArg runArg = new LibraryLoadRunArg(PathFormatter, SearchResultCache, searchArg, LibraryBrowserSettings.NumResultsPerPage, LibraryModel.FileSystemWatcher.Path, LibraryBrowserSettings.SortType, LibraryBrowserSettings.GlobalSortType, LibraryBrowserSettings.SortOrder, LibraryBrowserSettings.GlobalSortOrder);

            backgroundWorker.RunWorkerAsync(runArg);
        }
コード例 #10
0
ファイル: SearchHandler.cs プロジェクト: Klein69/NHxD
 public void RunSearch(SearchArg searchArg)
 {
     RunSearch(searchArg, true);
 }
コード例 #11
0
 public SearchResultArg(SearchArg searchArg, SearchResult searchResult)
 {
     SearchArg    = searchArg;
     SearchResult = searchResult;
 }
コード例 #12
0
 public SearchErrorArg(SearchArg searchArg, int pageIndex, string error)
 {
     SearchArg = searchArg;
     PageIndex = pageIndex;
     Error     = error;
 }
コード例 #13
0
        private static void ListBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;
            SearchDoArg      searchDoArg      = e.Argument as SearchDoArg;

            if (searchDoArg == null)
            {
                return;
            }

            SearchArg         searchArg         = searchDoArg.SearchArg;
            SearchProgressArg searchProgressArg = null;
            int          currentPage            = searchArg.PageIndex;
            SearchResult searchResult           = null;

            /*
             * bool loadAll = false;   // TODO: read this from settings.Download.LoadAll
             *
             * do
             * {
             */
            try
            {
                if (searchArg.Target == SearchTarget.Query)
                {
                    searchResult = searchDoArg.SearchHandler.Search(searchArg.Query, currentPage);
                }
                else if (searchArg.Target == SearchTarget.Tagged)
                {
                    searchResult = searchDoArg.SearchHandler.TaggedSearch(searchArg.TagId, currentPage);
                }
                else if (searchArg.Target == SearchTarget.Recent)
                {
                    searchResult = searchDoArg.SearchHandler.RecentSearch(currentPage);
                }

                if (searchResult == null)
                {
                    e.Cancel = true;
                    return;
                }

                searchDoArg.TagsModel.CollectTags(searchResult);

                searchProgressArg = new SearchProgressArg(searchArg, searchResult, currentPage, searchDoArg.MetadataKeywordLists, searchDoArg.SortType, searchDoArg.SortOrder);

                backgroundWorker.ReportProgress(searchResult.NumPages > 0 ? (int)(currentPage / (float)searchResult.NumPages * 100) : 100, searchProgressArg);
            }
            catch (Exception ex)
            {
                SearchErrorArg errorArg = new SearchErrorArg(searchArg, currentPage, (ex.InnerException != null) ? string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", ex.Message, Environment.NewLine, ex.InnerException.Message) : ex.Message);

                backgroundWorker.ReportProgress(0, errorArg);
            }

            /*
             * } while (loadAll
             *      && searchResult != null
             *      && ++currentPage < searchResult.NumPages);
             */

            if (searchResult != null &&
                searchResult.Result != null)
            {
                /*if (searchDoArg.SortType != GallerySortType.None)
                 * {
                 *      searchResult = OrderByMetadata(searchResult, searchDoArg.SortType, searchDoArg.SortOrder);
                 * }*/

                e.Result = new SearchResultArg(searchArg, searchResult);
            }
        }