コード例 #1
0
ファイル: LocalTextScope.cs プロジェクト: tgckpg/wenku10
        private async void ProcessVols()
        {
            StringResources stx = new StringResources( "LoadingMessage" );
            string LoadText = stx.Str( "ProgressIndicator_Message" );

            IEnumerable<string> BookIds = Shared.Storage.ListDirs( FileLinks.ROOT_LOCAL_VOL );
            string[] favs = new BookStorage().GetIdList();

            List<LocalBook> Items = new List<LocalBook>();
            foreach ( string Id in BookIds )
            {
                Loading = LoadText + ": " + Id;
                LocalBook LB = await LocalBook.CreateAsync( Id );
                if ( LB.ProcessSuccess )
                {
                    Items.Add( LB );
                    LB.IsFav = favs.Contains( Id );
                }
            }

            Action<string, SpiderBook> ProcessSpider = ( Id, LB ) =>
             {
                 Loading = LoadText + ": " + Id;
                 if ( LB.aid != Id )
                 {
                     try
                     {
                         Logger.Log( ID, "Fixing misplaced spider book" );
                         Shared.Storage.MoveDir( FileLinks.ROOT_SPIDER_VOL + Id, LB.MetaLocation );
                     }
                     catch ( Exception ex )
                     {
                         Logger.Log( ID
                             , string.Format(
                                 "Unable to move script: {0} => {1}, {2} "
                                 , Id, LB.aid, ex.Message )
                                 , LogType.WARNING );
                     }
                 }

                 if ( LB.ProcessSuccess || LB.CanProcess )
                 {
                     Items.Add( LB );
                     LB.IsFav = favs.Contains( Id );
                 }
                 else
                 {
                     try
                     {
                         Logger.Log( ID, "Removing invalid script: " + Id, LogType.INFO );
                         Shared.Storage.RemoveDir( LB.MetaRoot );
                     }
                     catch ( Exception ex )
                     {
                         Logger.Log( ID, "Cannot remove invalid script: " + ex.Message, LogType.WARNING );
                     }
                 }
             };

            BookIds = Shared.Storage.ListDirs( FileLinks.ROOT_SPIDER_VOL );
            foreach ( string Id in BookIds )
            {
                if ( Id[ 0 ] == ZONE_PFX )
                {
                    IEnumerable<string> ZoneItems = Shared.Storage.ListDirs( FileLinks.ROOT_SPIDER_VOL + Id + "/" );
                    foreach ( string SId in ZoneItems )
                    {
                        /**
                         * This code is a mess. I'll explain a bit more in here
                         *   First, the location of the Book.MetaLocation for ZoneItems
                         *   can only be retrived from BookInstruction
                         *   However ZoneId and Id are assinged by Spider on the fly,
                         *   restoring this information is a bit tricky
                         */

                        // Create BookIntstruction just to retrieve the correct id pattern
                        BookInstruction BInst = new BookInstruction( Id, SId );

                        /**
                         * After 2 hours of investigations...
                         * Welp, just outsmarted by myself, The CreateAsyncSpide works because:
                         *   Inside the TestProcessed method, the BookInstruction are created
                         *   using BoockInstruction( Id, Setings ) overload
                         *   the provided id is "this.aid" here BUT the full id is restored again
                         *   in InitProcMan() method
                         *   Fortunately, ssid will be set correctly inside the ReadInfo method
                         */
                        ProcessSpider( BInst.Id, await SpiderBook.CreateAsyncSpider( BInst.Id ) );
                    }
                }
                else
                {
                    ProcessSpider( Id, await SpiderBook.CreateAsyncSpider( Id ) );
                }
            }

            if ( 0 < Items.Count ) SearchSet = Items;
            Loading = null;
        }
コード例 #2
0
ファイル: LocalTextScope.cs プロジェクト: tgckpg/wenku10
        protected override IEnumerable<ActiveItem> Filter( IEnumerable<ActiveItem> Items )
        {
            if ( Items != null && FavOnly )
            {
                string[] ids = new BookStorage().GetIdList();
                Items = Items.Where( x => ids.Contains( ( x as LocalBook ).aid ) );
            }

            return base.Filter( Items );
        }