コード例 #1
0
        public XmlDocument LoadHtmlPageAsXmlByGet(string uri, ProxySettingsDTO proxySettings)
        {
            if (!uri.Contains("pilot.php"))
            {
                throw new NotSupportedException("Attempting to load HTML by GET from an unexpected URL");
            }

            var xDoc = new XmlDocument();

            xDoc.Load("../../Data/GET-pilot-php20150915-144004.xml");
            return(xDoc);
        }
コード例 #2
0
        public XmlDocument LoadHtmlPageAsXmlByPost(string uri, string postData, ProxySettingsDTO proxySettings)
        {
            if (uri.Contains("pilot.php"))
            {
                var xDoc = new XmlDocument();
                xDoc.Load("../../Data/POST-pilot-php20150915-144024.xml");
                return(xDoc);
            }
            if (uri.Contains("players.php"))
            {
                var xDoc = new XmlDocument();
                xDoc.Load("../../Data/POST-players-php20150915-144016.xml");
                return(xDoc);
            }

            throw new NotSupportedException("Attempting to load HTML by GET from an unexpected URL");
        }
コード例 #3
0
        private void BuildTourMap(ProxySettingsDTO proxySettings, string scoresURL)
        {
            var xDoc = _loader.LoadHtmlPageAsXmlByGet(scoresURL, proxySettings);

            var xformer = new XSLT2Transformer(xDoc, new XmlTextReader(@"TourListTransform.xslt"));
            var transformedTourListDoc = xformer.DoTransform();

            foreach (XmlNode xNode in transformedTourListDoc.SelectNodes("/AHTourList/AHTourNode"))
            {
                _definitions.AddTourToMap(new TourNode(xNode));
            }

            if (!_definitions.IsTourDefinitionsComplete())
            {
                throw new ApplicationException("Failed to build Tour Map!");
            }
        }
コード例 #4
0
        /// <summary>
        /// Calls the HTCPilotStatsSvc to load all the current tour definitions.
        /// </summary>
        public void LoadTourDefinitions(Form parent)
        {
            _proxySettings = ProxySettingsDTO.GetProxySettings();

            var waitDlg = new WaitDialog
            {
                MdiParent     = parent,
                UseWaitCursor = true
            };

            waitDlg.Show();
            waitDlg.Update();

            if (Registry.AreTourDefinitionsInitialised() == false)
            {
                var scoresUrl = ConfigurationManager.AppSettings["scoresURL"];
                Registry.TourDefinitions = HTCTourDefinitionsSvc.GetTourDefinitions(scoresUrl, ProxySettingsDTO.GetProxySettings());
            }

            waitDlg.Hide();
        }
コード例 #5
0
        public NetConnectionSelectorForm()
        {
            InitializeComponent();

            _proxySettings = ProxySettingsDTO.GetProxySettings();
        }
コード例 #6
0
 public TourDefinitions LoadTourDefinitions(ProxySettingsDTO proxySettings, string scoresUrl, string statsUrl)
 {
     BuildTourMap(proxySettings, scoresUrl);
     return(_definitions);
 }
コード例 #7
0
        public AcesHighPilotStats GetPilotStats(string pilotId, TourNode tour, string statsUrl, ProxySettingsDTO proxySettings)
        {
            if (tour == null)
            {
                throw new ArgumentException("tour of type TourNode must be set!");
            }
            if (pilotId == null)
            {
                throw new ArgumentException("pilotId of type string must be set!");
            }
            if (proxySettings == null)
            {
                throw new ArgumentException("proxySettings of type ProxySettingsDTO must be set!");
            }

            var postData = string.Format("playername={1}&selectTour={0}&action=1&Submit=Get+Stats", tour.TourSelectArg,
                                         pilotId);

            var statsPageDoc = _loader.LoadHtmlPageAsXmlByPost(statsUrl, postData, proxySettings);

            var xsltDocReader = new XmlTextReader("PilotStatsTransform.xslt");
            var transformer   = new XSLT2Transformer(statsPageDoc, xsltDocReader);
            var result        = transformer.DoTransform();

            // Deserialise the XmlDocument to a in-memory object.
            var stats = result.DeserialiseFromXmlDoc <AcesHighPilotStats>();

            // And fill in the rest of the details ourselves.
            stats.GameId      = pilotId.ToUpperFirstChar();
            stats.TourId      = tour.TourId.ToString();
            stats.TourType    = tour.TourType;
            stats.TourDetails = tour.BuildTourDetailsTag();

            return(stats);
        }
コード例 #8
0
        /// <summary>
        ///     Load a single AcesHighPilotScore objects from HTC web server for a give pilot, tour, and tour type.
        /// </summary>
        /// <param name="pilotId">Pilot in-game handle to retrieve score of.</param>
        /// <param name="tour">The tour</param>
        /// <param name="proxySettings">DTO object detailing how we should connect to the internet.</param>
        /// <param name="scoresUrl"></param>
        /// <returns>The score for the nominated pilot/tour/tour-type combination.</returns>
        public AcesHighPilotScore GetPilotScore(string pilotId, TourNode tour, string scoresUrl, ProxySettingsDTO proxySettings)
        {
            if (tour == null)
            {
                throw new ArgumentNullException("tour of type TourNode must be set!");
            }
            if (pilotId == null)
            {
                throw new ArgumentNullException("pilotId of type string must be set!");
            }
            if (scoresUrl == null)
            {
                throw new ArgumentNullException("scoresUrl of type string must be set!");
            }
            if (proxySettings == null)
            {
                throw new ArgumentNullException("proxySettings of type ProxySettingsDTO must be set!");
            }

            // Grab the web page and turn it into true XML.
            var postData = "playername=" + pilotId + "&selectTour=" + tour.TourSelectArg + "&action=1&Submit=Get+Scores";
            var doc      = _loader.LoadHtmlPageAsXmlByPost(scoresUrl, postData, proxySettings);

            // XSLT 2.0 parse the Xml score page and transform to our public format.
            var xsltDocReader = new XmlTextReader("PilotScoreTransform.xslt");
            var xformer       = new XSLT2Transformer(doc, xsltDocReader);
            var result        = xformer.DoTransform(); // may throw Saxon.Api.DynamicError when cant convert

            // Deserialise the XmlDocument to a in-memory object.
            var score = result.DeserialiseFromXmlDoc <AcesHighPilotScore>();

            // And fill in the rest of the details ourselves.
            score.GameId      = pilotId.ToUpperFirstChar();
            score.TourId      = tour.TourId.ToString();
            score.TourDetails = tour.BuildTourDetailsTag();
            score.TourType    = tour.TourType;

            // Yah! all done.
            return(score);
        }
コード例 #9
0
        private XmlDocument LoadHtmlPageAsXmlInternal(string postData, string uri, string httpMethod, ProxySettingsDTO proxySettings)
        {
            // Prepare web request...
            var webrequest = (HttpWebRequest)WebRequest.Create(uri);

            // Deal with proxy details if any.
            if (proxySettings.Option == ProxySettingsDTO.ProxyOption.Custom)
            {
                var proxy = new WebProxy(proxySettings.ProxyHost, proxySettings.ProxyPort);
                webrequest.Proxy = proxy;
            }
            webrequest.Method = httpMethod;

            if (string.Equals(httpMethod, "POST", StringComparison.OrdinalIgnoreCase))
            {
                var encoding = new ASCIIEncoding();
                var data     = encoding.GetBytes(postData);

                webrequest.ContentType   = "application/x-www-form-urlencoded";
                webrequest.ContentLength = data.Length;

                using (var newStream = webrequest.GetRequestStream())
                {
                    newStream.Write(data, 0, data.Length);
                }
            }


            var webresponse      = (HttpWebResponse)webrequest.GetResponse();
            var enc              = Encoding.GetEncoding(1252);
            var loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);
            var buffer           = loResponseStream.ReadToEnd();

            loResponseStream.Close();
            webresponse.Close();

            var stringReader = new StringReader(buffer);

            // Use the cool sgml reader to 'interpret' the HTML as XML :) very nice!
            var sgmlReader = new SgmlReader
            {
                DocType     = "HTML",
                InputStream = stringReader
            };
            var doc = new XmlDocument();

            doc.Load(sgmlReader);

            //var split = uri.Split('/');
            //var name = httpMethod + "-" + split[split.Length - 1].Replace('.', '-') + DateTime.Now.ToString("yyyyMMdd-HHmmss") + ".xml";

            //doc.Save(name);

            return(doc);
        }
コード例 #10
0
 public XmlDocument LoadHtmlPageAsXmlByPost(string uri, string postData, ProxySettingsDTO proxySettings)
 {
     return(LoadHtmlPageAsXmlInternal(postData, uri, "POST", proxySettings));
 }
コード例 #11
0
 public XmlDocument LoadHtmlPageAsXmlByGet(string uri, ProxySettingsDTO proxySettings)
 {
     return(LoadHtmlPageAsXmlInternal(string.Empty, uri, "GET", proxySettings));
 }