コード例 #1
0
ファイル: Site.cs プロジェクト: bg0jr/Maui
 public Site( string name, Navigation navi, IFormat format, DataContent content )
 {
     Name = name;
     Navigation = navi;
     Format = format;
     Content = content;
 }
コード例 #2
0
ファイル: Navigation.cs プロジェクト: bg0jr/Maui
        public Navigation( Navigation navi, params TransformAction[] rules )
        {
            DocumentType = rules.ApplyTo<DocumentType>( () => navi.DocumentType );
            Uris = rules.ApplyTo<IArray<NavigatorUrl>>( () => navi.Uris );

            UrisHashCode = CreateUrisHashCode();
        }
コード例 #3
0
ファイル: LocatorValidationResult.cs プロジェクト: bg0jr/Maui
 public LocatorValidationResult( DataTable result, ParameterizedDatumLocator datumLocator, Navigation modifiedNavigation, string documentLocation, IFormat modifiedFormat )
 {
     Result = result;
     DatumLocator = datumLocator;
     Navigation = modifiedNavigation ?? Navigation.Empty;
     DocumentLocation = documentLocation;
     Format = modifiedFormat;
 }
コード例 #4
0
ファイル: Navigator.cs プロジェクト: bg0jr/Maui
        public Uri Navigate( Navigation navigation )
        {
            var uri = TryNavigateWithWildcards( navigation );
            if ( uri != null )
            {
                return uri;
            }

            return NavigateToFinalSite( navigation.Uris );
        }
コード例 #5
0
ファイル: TestBase.cs プロジェクト: bg0jr/Maui
        protected IHtmlDocument LoadDocument( string name )
        {
            string file = Path.Combine( TestDataRoot, "Recognition", "Html" );
            file = Path.Combine( file, name );

            var navi = new Navigation( DocumentType.Html, new NavigatorUrl( UriType.Request, file ) );
            var doc = (HtmlDocumentHandle)myBrowser.GetDocument( navi );

            return doc.Content;
        }
コード例 #6
0
ファイル: DocumentBrowser.cs プロジェクト: bg0jr/Maui
        public IDocument GetDocument( Navigation navi )
        {
            var uri = myNavigator.Navigate( navi );

            myLogger.Info( "Url from navigator: {0}", uri );

            var documentLoader = DocumentLoaderFactory.Create( navi.DocumentType );
            var doc = documentLoader.Load( uri );

            return doc;
        }
コード例 #7
0
ファイル: CachingNavigator.cs プロジェクト: bg0jr/Maui
        public Uri Navigate( Navigation navigation )
        {
            var uri = myCache.TryGet( navigation );
            if ( uri == null )
            {
                uri = myNavigator.Navigate( navigation );
                uri = myCache.Add( navigation, uri );
            }

            return uri;
        }
コード例 #8
0
ファイル: DocumentCache.cs プロジェクト: bg0jr/Maui
        /// <summary>
        /// Adds the document specified by the given URL and the given navigation as key to the cache
        /// </summary>
        internal Uri Add( Navigation key, Uri document )
        {
            var entry = CreateCacheEntry( key, document );

            ShrinkCacheIfRequired( entry );

            myIndex.Add( entry );

            myIndex.Store( myIndexFile );

            return entry.Uri;
        }
コード例 #9
0
ファイル: LegacyDocumentBrowser.cs プロジェクト: bg0jr/Maui
        public IDocument GetDocument( Navigation navi )
        {
            var doc = TryNavigateWithWildcards( navi );
            if ( doc != null )
            {
                return doc;
            }

            if ( navi.DocumentType == DocumentType.Html )
            {
                return new HtmlDocumentHandle( LoadDocument( navi.Uris ) );
            }
            else if ( navi.DocumentType == DocumentType.Text )
            {
                return new TextDocument( DownloadFile( navi.Uris ) );
            }

            throw new NotSupportedException( "DocumentType: " + navi.DocumentType );
        }
コード例 #10
0
ファイル: DocumentCache.cs プロジェクト: bg0jr/Maui
        internal Uri TryGet( Navigation key )
        {
            var entry = myIndex.TryGet( key.UrisHashCode );
            if ( entry == null )
            {
                return null;
            }

            if ( entry.IsExpired )
            {
                // found but live time of entry expired
                myIndex.Remove( key.UrisHashCode );
                return null;
            }

            // found and live time of entry not expired
            myLogger.Info( "DocumentCache CacheHit for {0}", key );

            return entry.Uri;
        }
コード例 #11
0
ファイル: DocumentCache.cs プロジェクト: bg0jr/Maui
        private CacheEntryBase CreateCacheEntry( Navigation key, Uri document )
        {
            var expirationTime = DateTime.Now.Add( Settings.MaxEntryLiveTime );

            if ( document.IsFile )
            {
                return new CacheEntryBase( key.UrisHashCode, expirationTime, document );
            }
            else
            {
                var cacheFile = Path.Combine( myCacheFolder, key.UrisHashCode + ".dat" );
                WebUtil.DownloadTo( document, cacheFile );

                return new ValueCacheEntry( key.UrisHashCode, expirationTime, new Uri( cacheFile ) );
            }
        }
コード例 #12
0
ファイル: Navigator.cs プロジェクト: bg0jr/Maui
        private Uri TryNavigateWithWildcards( Navigation navi )
        {
            if ( navi.Uris.Count != 1 )
            {
                // we can only handle single urls
                return null;
            }

            var url = navi.Uris[ 0 ];
            Uri uri = new Uri( url.UrlString );
            if ( !uri.IsFile && !uri.IsUnc )
            {
                // we cannot handle e.g. http now
                return null;
            }

            // currently we only handle "/xyz/*/file.txt"
            int pos = url.UrlString.IndexOf( "/*/" );
            if ( pos <= 0 )
            {
                // no pattern found
                return null;
            }

            string root = url.UrlString.Substring( 0, pos );
            string file = url.UrlString.Substring( pos + 3 );
            string[] dirs = Directory.GetDirectories( root, "*" );

            // now try everything with "or"
            // first path which returns s.th. wins
            foreach ( string dir in dirs )
            {
                string tmpUri = Path.Combine( dir, file );
                if ( !File.Exists( tmpUri ) )
                {
                    continue;
                }

                return new Uri( tmpUri );
            }

            // so in this case we got a pattern navigation url but we were not able
            // to navigate to that url --> throw an exception
            throw new Exception( "Failed to navigate to the document" );
        }