예제 #1
0
파일: Site.cs 프로젝트: bg0jr/Maui
 public Site( Site site, params TransformAction[] rules )
 {
     Name = rules.ApplyTo<string>( () => site.Name );
     Navigation = rules.ApplyTo<Navigation>( () => site.Navigation );
     Format = rules.ApplyTo<IFormat>( () => site.Format );
     Content = rules.ApplyTo<DataContent>( () => site.Content );
 }
예제 #2
0
        public ParameterizedDatumLocator( string datum, Site site )
        {
            Datum = datum;
            Site = site;

            Name = string.Format( "{0}: {1}", datum, site.Name );
            Parameters = new Dictionary<string, string>();
        }
예제 #3
0
        public void TupleProperty()
        {
            var site = new Site( "Ariva",
                   new Navigation( DocumentType.Html, string.Empty ),
                   new SeparatorSeriesFormat( "Ariava.Prices" )
                       {
                           Anchor = Anchor.ForRow( new StringContainsLocator( 0, ">>${TableIndex}<<" ) )
                       },
                   new DataContent( "Euro" ) );

            var fetchPolicy = new LookupPolicy();
            fetchPolicy.Lut[ "${TableIndex}" ] = "0";

            var format = (SeparatorSeriesFormat)fetchPolicy.GetFormat( site );

            Assert.That( ( (StringContainsLocator)format.Anchor.Row ).Pattern, Is.EqualTo( ">>0<<" ) );
        }
예제 #4
0
 /// <summary>
 /// Returns the navigation object of the given site object 
 /// without any modification.
 /// <seealso cref="IFetchPolicy.GetNavigation"/>
 /// </summary>
 public virtual Navigation GetNavigation( Site site )
 {
     return site.Navigation;
 }
예제 #5
0
 /// <summary>
 /// Returns the form object of the given site object 
 /// without any modification.
 /// <seealso cref="IFetchPolicy.GetFormat"/>
 /// </summary>
 public virtual IFormat GetFormat( Site site )
 {
     return site.Format;
 }
예제 #6
0
파일: LookupPolicy.cs 프로젝트: bg0jr/Maui
        public IFormat GetFormat( Site site )
        {
            var newFormat = site.Format.Clone();

            // XXX: find a better way!!
            //      go for transformation rules
            foreach ( var pi in newFormat.GetType().GetProperties() )
            {
                if ( !pi.CanWrite )
                {
                    continue;
                }

                if ( pi.PropertyType == typeof( string ) )
                {
                    pi.SetValue( newFormat, LookupInternal( (string)pi.GetValue( newFormat, null ) ), null );
                }
                else if ( pi.PropertyType == typeof( Anchor ) )
                {
                    // xxx: hack to get string replacement in anchors running
                    var anchor = (Anchor)pi.GetValue( newFormat, null );
                    if ( anchor != null )
                    {
                        var colLocator = anchor.Column;
                        var rowLocator = anchor.Row;
                        var locator = colLocator as StringContainsLocator;
                        if ( locator != null )
                        {
                            colLocator = new StringContainsLocator( locator.SeriesToScan, LookupInternal( locator.Pattern ) );
                        }
                        locator = rowLocator as StringContainsLocator;
                        if ( locator != null )
                        {
                            rowLocator = new StringContainsLocator( locator.SeriesToScan, LookupInternal( locator.Pattern ) );
                        }
                        pi.SetValue( newFormat, Anchor.ForCell( rowLocator, colLocator ), null );
                    }
                }
                else if ( pi.PropertyType.HasInterface( typeof( IEnumerable ) ) )
                {
                    var list = new List<object>();
                    bool changed = false;
                    foreach ( var obj in (IEnumerable)pi.GetValue( newFormat, null ) )
                    {
                        if ( obj.GetType() == typeof( string ) )
                        {
                            list.Add( LookupInternal( (string)obj ) );
                            changed = true;
                        }
                        else
                        {
                            list.Add( obj );
                        }
                    }

                    if ( changed )
                    {
                        if ( pi.PropertyType.IsArray )
                        {
                            throw new NotSupportedException( "Unable to handle properties of type System.Array" );
                        }

                        // XXX: the trick is how to find the proper instance
                        //      or how to find the proper constructor
                        var newObj = Activator.CreateInstance( pi.PropertyType, list.ToArray() );
                        pi.SetValue( newFormat, newObj, null );
                    }
                }
            }

            return newFormat;
        }
예제 #7
0
파일: LookupPolicy.cs 프로젝트: bg0jr/Maui
 public Navigation GetNavigation( Site site )
 {
     return new Navigation( site.Navigation,
         Let.Member( () => site.Navigation.Uris ).Become( Update( site.Navigation.Uris ) ) );
 }