示例#1
0
        public NavigatorUrl( UriType uriType, string url, Formular form )
        {
            uriType.Require( x => uriType != UriType.None );

            UrlType = uriType;
            UrlString = url;
            Formular = form;
        }
示例#2
0
文件: HtmlForm.cs 项目: bg0jr/Maui
        public Uri CreateSubmitUrl( Formular formular )
        {
            var builder = new UriBuilder();
            builder.Scheme = FormElement.Document.Url.Scheme;
            builder.Host = FormElement.Document.Url.Host;
            builder.Port = FormElement.Document.Url.Port;
            builder.Path = FormElement.GetAttribute( "action" );
            builder.Query = string.Join( "&", BuildParameters( formular ) );

            return builder.Uri;
        }
示例#3
0
        public void CreateSubmitUrl_FilledFormular()
        {
            var doc = LoadDocument( "ariva.historicalprices.DE0008404005.html" );
            var form = doc.GetFormByName( "histcsv" );

            var formular = new Formular( "histcsv",
                Tuple.Create( "boerse_id", "1" ),
                Tuple.Create( "min_time", "1.1.1980" ),
                Tuple.Create( "max_time", "3.3.2012" )
                );

            var submitUrl = form.CreateSubmitUrl( formular );

            Assert.That( submitUrl.ToString(), Is.EqualTo( "file:///quote/historic/historic.csv%3Fsecu=292&boerse_id=1&clean_split=1&clean_payout=0&clean_bezug=0&min_time=1.1.1980&max_time=3.3.2012&trenner=;" ) );
        }
示例#4
0
文件: HtmlForm.cs 项目: bg0jr/Maui
        //<form action="/quote/historic/historic.csv" method="get" name="histcsv" style="margin:0px">
        //  <input type="hidden" name="secu" value="292">
        //  <input type="hidden" name="boerse_id" value="6">
        //  <input type="hidden" name="clean_split" value="1">
        //  <input type="hidden" name="clean_payout" value="0">
        //  <input type="hidden" name="clean_bezug" value="0"> <ul> <li><div class="fleft" style="width:45px">von:</div>
        //  <input name="min_time" value="25.2.2011" style="width:65px"></li> <li><div class="fleft" style="width:45px">bis:</div>
        //  <input name="max_time" value="25.2.2012" style="width:65px"></li> <li><div class="fleft" style="width:85px">Trennzeichen:</div>
        //  <input name="trenner" value=";" style="width:25px"></li> </ul> <div align="right" style="padding: 3px 3px 4px">
        //  <input name="go" value="Download" type="submit" style="font-size:12px;"></div> <div class="clearfloat"></div>
        //</form>
        private string[] BuildParameters( Formular formular )
        {
            var parameters = new Dictionary<string, string>();

            var inputElements = FormElement.GetInnerElements()
                .Where( child => child.TagName.EqualsI( "input" ) )
                .Where( child => child.GetAttribute( "type" ) != "submit" );
            foreach ( var input in inputElements )
            {
                parameters[ input.GetAttribute( "name" ) ] = input.GetAttribute( "value" );
            }

            foreach ( var param in formular.Parameters )
            {
                parameters[ param.Key ] = param.Value;
            }

            var urlPairs = parameters
                 .Select( entry => string.Format( "{0}={1}", HttpUtility.UrlEncode( entry.Key ), HttpUtility.UrlEncode( entry.Value ) ) )
                 .ToArray();

            return urlPairs;
        }
示例#5
0
 public NavigatorUrl( Formular form )
     : this(UriType.SubmitFormular, string.Empty, form)
 {
 }
示例#6
0
 public static NavigatorUrl SubmitFormular( Formular form )
 {
     return new NavigatorUrl( form );
 }
示例#7
0
文件: Navigator.cs 项目: bg0jr/Maui
        /// <summary>
        /// 1. Get the document
        /// 2. find the formular specified by formular.Name (currently only Html supported)
        /// 3. fill the formular from the document with the additional/overwrite parameters
        /// 3. submit the formular
        /// </summary>
        private Uri SubmitFormular( Uri url, Formular formular )
        {
            using ( var loader = new WinFormHtmlDocumentLoader() )
            {
                var document = loader.LoadHtmlDocument( url );
                var htmlForm = new Html.WinForms.HtmlDocumentAdapter( document ).GetFormByName( formular.Name );
                if ( htmlForm == null )
                {
                    return null;
                }

                var formSubmitUrl = htmlForm.CreateSubmitUrl( formular );

                return SendRequest( formSubmitUrl );
            }
        }
示例#8
0
        private Formular TransformFormular( Formular originalFormular )
        {
            if ( originalFormular == null )
            {
                return null;
            }

            var transformedForm = new Formular( originalFormular.Name );
            foreach ( var origParam in originalFormular.Parameters )
            {
                transformedForm.Parameters[ origParam.Key ] = LookupInternal( origParam.Value );
            }

            return transformedForm;
        }