Exemplo n.º 1
0
        private async Task GetMovieInfoAsync(IMovieBuilder builder, Uri uri)
        {
            var html = await WebHttp.GetHtmlDocument(uri);

            var coverImage = html.DocumentNode.SelectSingleNode("//div[@class='single_port']/img")
                             .ThrowExceptionIfCoverImageNotExists()
                             .GetAttributeValue("src", null);
            var descriptionInput = HttpUtility.HtmlDecode(html.DocumentNode.SelectSingleNode("//div[@class='single_entry']")
                                                          .ThrowExceptionIfMovieInfoNotExists().InnerText);
            var movieInfo = builder.MovieInfo;

            using (var sr = new StringReader(descriptionInput))
            {
                for (int i = 0; i < 3; i++)
                {
                    sr.ReadLine();
                }
                movieInfo.Description = sr.ReadToEnd();
            }

            var regexInput = HttpUtility.HtmlDecode(html.DocumentNode.SelectSingleNode("//div[@class='single_date_box']")
                                                    .ThrowExceptionIfMovieInfoNotExists().InnerText);
            var match = MovieInfoRegex.Match(regexInput);

            if (match.Success)
            {
                movieInfo.LoadGenresFrom(match.Groups[1].Value);
            }

            foreach (var video in html.DocumentNode.SelectNodes("//div[@class='block-container']/center/div/iframe")
                     .ThrowExceptionIfNotExists("Unable to find the movie root"))
            {
                builder.Enqueue(this, HtmlHelpers.GetEmbededUri(video));
            }
        }
        /// <summary>
        ///
        /// </summary>
        private async Task WriteViewToFileAsync(ResultExecutingContext context)
        {
            try {
                var html = await RenderToStringAsync(context);

                if (string.IsNullOrWhiteSpace(html))
                {
                    return;
                }
                var path      = WebHttp.GetPhysicalPath(string.IsNullOrWhiteSpace(Path) ? GetPath(context) : Path);
                var directory = System.IO.Path.GetDirectoryName(path);
                if (string.IsNullOrWhiteSpace(directory))
                {
                    return;
                }
                if (Directory.Exists(directory) == false)
                {
                    Directory.CreateDirectory(directory);
                }
                System.IO.File.WriteAllText(path, html);
            }
            catch (Exception ex) {
                ex.Log(Log.GetLog().Caption(""));
            }
        }
Exemplo n.º 3
0
        public async Task <MovieStream> GetStreamSetAsync()
        {
            var request = WebHttp.CreateRequest(uri);

            request.CookieContainer = new System.Net.CookieContainer();
            var response = await WebHttp.GetWebResponse(request);

            var streamInfo = new MovieStream();

            streamInfo.Cookies = request.CookieContainer.GetCookies(uri);

            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                var match = VideoRegex.Match(sr.ReadToEnd());
                if (!match.Success)
                {
                    throw new InvalidDOMStructureException("Unable to find the video source uri");
                }
                streamInfo.VideoStreams.Add(new VideoStream {
                    AVStream = match.Groups[1].Value
                });
            }

            return(streamInfo);
        }
        private async Task Build(IMovieBuilder builder, Uri uri)
        {
            var html = await WebHttp.GetHtmlDocument(uri);

            var entryContent = html.DocumentNode.SelectSingleNode("//div[@class='entry entry-content']")
                               .ThrowExceptionIfNotExists("Unable to find the movie details element");
            var img        = entryContent.SelectSingleNode("a[@class='entry-thumb']/img").ThrowExceptionIfNotExists("Movie thumbnail element");
            var categories = entryContent.SelectNodes("a[@rel='category tag']/text()")
                             .ThrowExceptionIfNotExists("Unable to find the categories element")
                             .Select(li => HttpUtility.HtmlDecode(li.InnerText));

            var movieInfo = builder.MovieInfo;

            movieInfo.LoadGenresFrom(categories);
            movieInfo.CoverImage = new Uri(img.GetAttributeValue("src", null));

            var description = entryContent.SelectSingleNode("p").ThrowExceptionIfNotExists("Unable to find description element");

            movieInfo.Description = HttpUtility.HtmlDecode(description.InnerText);

            foreach (var entry in html.DocumentNode.SelectNodes("//div[@class='entry-embed']/iframe")
                     .ThrowExceptionIfNotExists("Unable to find the movie streams"))
            {
                builder.Enqueue(this, HtmlHelpers.GetEmbededUri(entry));
            }
        }
        public async Task <MovieStream> GetStreamSetAsync()
        {
            var html = await WebHttp.GetHtmlDocument(uri);

            var flashEmbedded = html.GetElementbyId("flash_video_obj");

            if (flashEmbedded == null)
            {
                flashEmbedded = html.DocumentNode.SelectSingleNode("//embed[@type='application/x-shockwave-flash']")
                                .ThrowExceptionIfNotExists("Not found the flash embedded element!");
            }

            var query = HttpUtility.ParseQueryString(HttpUtility.HtmlDecode(flashEmbedded.GetAttributeValue("flashvars", null)));

            var streamSet = new MovieStream();

            foreach (var kvp in SupportedVideos)
            {
                string movieUrl = HttpUtility.UrlDecode(query.Get(kvp.Key));
                if (!string.IsNullOrEmpty(movieUrl))
                {
                    streamSet.VideoStreams.Add(new VideoStream {
                        AVStream = movieUrl, Resolution = kvp.Value
                    });
                }
            }

            if (streamSet.VideoStreams.Count == 0)
            {
                throw new ArgumentException("Unable to determine any valid video stream");
            }
            return(streamSet);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 退废票
        /// </summary>
        /// <param name="refundArgs"></param>
        /// <returns></returns>
        public RefundTicketResult BounceOrAnnulTicket(RefundArgs refundArgs)
        {
            string submitStr = string.Empty;

            if (refundArgs.RefundType == 0)
            {
                submitStr = RefundTicket(refundArgs);
            }
            else
            {
                submitStr = AnnulTicket(refundArgs);
            }
            WebHttp http         = new WebHttp();
            var     result       = http.SendRequest(submitStr, MethodType.GET, Encoding.UTF8, 60);
            var     returnResult = new RefundTicketResult {
                Result = false, Descript = string.Empty
            };

            if (result == null)
            {
                return(returnResult);
            }
            returnResult.Result   = result.Data.Contains("提交成功");
            returnResult.Descript = result.Data;
            return(returnResult);
        }
Exemplo n.º 7
0
        public List <RateModel> GetHtml()
        {
            string url    = "http://fx.cmbchina.com/hq/";
            var    http   = new WebHttp();
            var    html   = http.WebReq(url);
            var    result = new List <RateModel>();

            var reg    = new Regex("<div id=\"realRateInfo\">\\s+?<table [^*]+?</table>");
            var regVal = reg.Match(html).Value;

            var trReg   = new Regex("<tr[^*]+?</tr>");
            var resList = trReg.Matches(regVal);

            for (int i = 0; i < resList.Count; i++)
            {
                var tds = new Regex("<td[^*]+?>(?<val>[^*]+?)</td>").Matches(resList[i].Value);

                result.Add(new RateModel()
                {
                    Name    = tds[0].Groups["val"].Value.Trim(),
                    SpotVal = tds[6].Groups["val"].Value.Trim()
                });
            }
            return(result);
        }
Exemplo n.º 8
0
 public CFDNS(ICFConfig config, ILogger logger)
 {
     _config      = config;
     _logger      = logger;
     _webHttp     = new WebHttp(_config.CF_API);
     jsonSettings = new JsonSerializerSettings {
         NullValueHandling = NullValueHandling.Ignore,
         Formatting        = Formatting.Indented
     };
 }
        private static async Task ParseMovieInfoAsync(IMovieBuilder builder, Uri uri)
        {
            var html = await WebHttp.GetHtmlDocument(uri);

            var movieRootElement = html.DocumentNode.SelectSingleNode("//div[@class='filmcontent']/div[@class='filmalti']")
                                   .ThrowExceptionIfNotExists("Unable to find the movie root element");

            var imgElement          = movieRootElement.SelectSingleNode("div[@class='filmaltiimg']/img").ThrowExceptionIfNotExists("Unable to find the 'img' tag element");
            var movieDetailsElement = movieRootElement.SelectSingleNode("div[@class='filmaltiaciklama']")
                                      .ThrowExceptionIfNotExists("Unable to find the movie details element");
            var categories = movieDetailsElement.SelectNodes("p[1]/a/text()")
                             .ThrowExceptionIfNotExists("Unable to find the categories elements")
                             .Select(li => HttpUtility.HtmlDecode(li.InnerText));

            var movieInfo = new MovieInfo(new BasicMovieInfo(imgElement.GetAttributeValue("alt", null), uri));

            movieInfo.CoverImage = new Uri(imgElement.GetAttributeValue("src", null));

            var description = movieDetailsElement.SelectSingleNode("//p[last()]").ThrowExceptionIfNotExists("Unable to find the movie description element").InnerText;
            int idx         = description.IndexOf(':');

            if (idx > 0)
            {
                movieInfo.Description = HttpUtility.HtmlDecode(description.Substring(idx + 1).Trim());
            }

            foreach (var embeddedMovies in html.DocumentNode.SelectNodes("//object[@type='application/x-shockwave-flash']/param[@name='flashvars']"))
            {
                var query = HttpUtility.ParseQueryString(HttpUtility.HtmlDecode(embeddedMovies.GetAttributeValue("value", null)));

                string captionFile = query.Get("captions.file");
                var    avstream    = HttpUtility.UrlDecode(query.Get("streamer"));

                if (string.IsNullOrEmpty(captionFile) || string.IsNullOrEmpty(avstream))
                {
                    continue;
                }

                var streamSet = new MovieStream();
                streamSet.Captions.Add(new Caption
                {
                    Language = "Romanian",
                    Address  = captionFile
                });

                streamSet.VideoStreams.Add(new VideoStream {
                    AVStream = avstream
                });
                movieInfo.Streams.Add(streamSet);
            }
        }
            protected override async Task <ICollection <BasicMovieInfo> > ParseFirstPage()
            {
                var html = await WebHttp.GetHtmlDocument(new Uri(string.Format(PageFormat, 1)));

                var pages = html.DocumentNode.SelectSingleNode("//div[@class='wp-pagenavi']/span/text()")
                            .ThrowExceptionIfNotExists("Unable to find the page number section");
                var match = SharedRegex.EnglishPageMatchRegex.Match(pages.InnerText);

                if (match.Success)
                {
                    SetTotalPages(int.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture));
                }

                return(BratuMarianMovieProvider.ParsePage(html));
            }
        /// <summary>
        ///
        /// </summary>
        public async Task <string> SaveAsync()
        {
            var fileControl  = WebHttp.GetFile();
            var path         = _generator.Generate(fileControl.FileName);
            var physicalPath = WebHttp.GetWebRootPath(path);
            var directory    = Path.GetDirectoryName(physicalPath);

            if (string.IsNullOrEmpty(directory))
            {
                throw new Warning("Erro");
            }
            if (Directory.Exists(directory) == false)
            {
                Directory.CreateDirectory(directory);
            }
            using (var stream = new FileStream(physicalPath, FileMode.Create)) {
                await fileControl.CopyToAsync(stream);
            }
            return(path);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the hotel around hotel list by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        private static List <Models.HotelAroundHotel> GetHotelAroundHotelListById(string id)
        {
            List <Models.HotelAroundHotel> data = null;

            Models.HotelAroundHotel               temp    = null;
            Provider.Configs.IUnionConfig         fig     = Provider.Configs.ConfigManager.GetConfigProvider();
            Provider.DataUrl.UnionDataUrlProvider dataUrl = null;
            dataUrl = new Provider.DataUrl.Default.HotelAroundDefaultProvider(fig);
            dataUrl.UrlParas.Add("hid", id);
            var     url = dataUrl.GetUrl();
            WebHttp req = new WebHttp();

            try
            {
                var dataStr = req.WebRequest(HttpMethod.GET, url.ToString(), "");
                if (string.IsNullOrEmpty(req.Message) && !string.IsNullOrEmpty(dataStr))
                {
                    data = new List <Models.HotelAroundHotel>();
                    var jarray = Newtonsoft.Json.Linq.JArray.Parse(dataStr);
                    foreach (var item in jarray)
                    {
                        temp           = new Models.HotelAroundHotel();
                        temp.chaping   = item["chaping"] == null ? -1 : int.Parse(item["chaping"].ToString());
                        temp.haoping   = item["haoping"] == null ? -1 : int.Parse(item["haoping"].ToString());
                        temp.hotelname = item["hotelname"] == null ? string.Empty : item["hotelname"].ToString();
                        temp.id        = item["id"] == null ? -1 : long.Parse(item["id"].ToString());
                        temp.juli      = item["juli"] == null ? string.Empty : item["juli"].ToString();
                        temp.lowprice  = item["lowprice"] == null ? 0.0 : double.Parse(item["lowprice"].ToString());
                        temp.xingji    = item["xingji"] == null ? 0 : int.Parse(item["xingji"].ToString());
                        temp.zhongping = item["xingji"] == null ? 0 : int.Parse(item["xingji"].ToString());
                        data.Add(temp);
                    }
                }
            }
            catch (Exception ex)
            { }
            return(data);
        }
Exemplo n.º 13
0
        public List <WebSource> GetWebExternalInfo(List <WebSource> webSources, int webDelayTime)
        {
            WebHttp _webHttp = new WebHttp();
            int     i        = 0;

            //status
            foreach (var sourceItem in webSources)
            {
                i++;
                sourceItem.Sequence         = "W" + i;
                sourceItem.ConnectionStatus = (_webHttp.GetStatus(sourceItem.Url, webDelayTime));

                if (sourceItem.ConnectionStatus.Equals("200"))
                {
                    sourceItem.StatusColor = Color.LightGreen;
                }
                else
                {
                    sourceItem.StatusColor = Color.Red;
                }
            }
            return(webSources);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Gets the hotel around hotel list by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        private static List<Models.HotelAroundHotel> GetHotelAroundHotelListById(string id)
        {
            List<Models.HotelAroundHotel> data = null;
            Models.HotelAroundHotel temp = null;
            Provider.Configs.IUnionConfig fig = Provider.Configs.ConfigManager.GetConfigProvider();
            Provider.DataUrl.UnionDataUrlProvider dataUrl = null;
            dataUrl = new Provider.DataUrl.Default.HotelAroundDefaultProvider(fig);
            dataUrl.UrlParas.Add("hid", id);
            var url = dataUrl.GetUrl();
            WebHttp req = new WebHttp();
            try
            {
                var dataStr = req.WebRequest(HttpMethod.GET, url.ToString(), "");
                if (string.IsNullOrEmpty(req.Message) && !string.IsNullOrEmpty(dataStr))
                {

                    data = new List<Models.HotelAroundHotel>();
                    var jarray = Newtonsoft.Json.Linq.JArray.Parse(dataStr);
                    foreach (var item in jarray)
                    {
                        temp = new Models.HotelAroundHotel();
                        temp.chaping = item["chaping"] == null ? -1 : int.Parse(item["chaping"].ToString());
                        temp.haoping = item["haoping"] == null ? -1 : int.Parse(item["haoping"].ToString());
                        temp.hotelname = item["hotelname"] == null ? string.Empty : item["hotelname"].ToString();
                        temp.id = item["id"] == null ? -1 : long.Parse(item["id"].ToString());
                        temp.juli = item["juli"] == null ? string.Empty : item["juli"].ToString();
                        temp.lowprice = item["lowprice"] == null ? 0.0 : double.Parse(item["lowprice"].ToString());
                        temp.xingji = item["xingji"] == null ? 0 : int.Parse(item["xingji"].ToString());
                        temp.zhongping = item["xingji"] == null ? 0 : int.Parse(item["xingji"].ToString());
                        data.Add(temp);
                    }
                }
            }
            catch (Exception ex)
            { }
            return data;
        }
            protected override async Task <ICollection <BasicMovieInfo> > ParseFirstPage()
            {
                var html = await WebHttp.GetHtmlDocument(new Uri(string.Format(PageUriFormat, CurrentPage)));

                var movies = GetTopMovies(html);

                foreach (var movie in GetPaggedMovies(html))
                {
                    movies.Add(movie);
                }

                var pagesElement = html.DocumentNode.SelectSingleNode("//div[@class='wp-pagenavi']/span")
                                   .ThrowExceptionIfNotExists("Unable to find the pages number element");

                var pagesMatch = SharedRegex.EnglishPageMatchRegex.Match(pagesElement.InnerText);

                if (!pagesMatch.Success)
                {
                    throw new ArgumentException("Unable to determine the pages count from text '" + pagesElement.InnerText + "'");
                }

                SetTotalPages(int.Parse(pagesMatch.Groups[2].Value));
                return(movies);
            }
Exemplo n.º 16
0
            protected override async Task <ICollection <BasicMovieInfo> > ParsePage(int page)
            {
                var html = await WebHttp.GetHtmlDocument(new Uri(string.Format(PageFormat, CurrentPage)));

                return(DivXOnlineMovieProvider.ParsePage(html));
            }
            protected override async Task <ICollection <BasicMovieInfo> > ParsePage(int page)
            {
                var html = await WebHttp.GetHtmlDocument(new Uri(string.Format(PageUriFormat, CurrentPage)));

                return(GetPaggedMovies(html));
            }
Exemplo n.º 18
0
        public async Task <MovieStream> GetStreamSetAsync()
        {
            var response = await WebHttp.GetWebResponse(uri);

            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                var content = await reader.ReadToEndAsync();

                int startIndex = content.IndexOf(SearchPattern, StringComparison.CurrentCultureIgnoreCase);
                if (startIndex < 0)
                {
                    throw new InvalidDOMStructureException("Unable to find the start point of the escaped flash");
                }

                startIndex += SearchPattern.Length;

                var endIndex = content.IndexOf('\"', startIndex);
                if (endIndex < 0)
                {
                    throw new InvalidDOMStructureException("Unable to find the end point of the escaped flash");
                }

                var flashContent = Utilities.EscapeJavaScript(content.Substring(startIndex, endIndex - startIndex));

                startIndex = flashContent.IndexOf('{');
                if (startIndex < 0)
                {
                    throw new InvalidDOMStructureException("Unable to find the start character for the Json data");
                }
                endIndex = flashContent.LastIndexOf('}');
                if (endIndex < 0)
                {
                    throw new InvalidDOMStructureException("Unable to find the end character for the Json data");
                }

                var json           = Newtonsoft.Json.Linq.JObject.Parse(flashContent.Substring(startIndex, endIndex - startIndex + 1));
                var movieStreamSet = new MovieStream();

                JToken token;
                if (json.TryGetValue("provider", out token) && !token.ToString().Equals("http", StringComparison.CurrentCultureIgnoreCase))
                {
                    logger.Warning(string.Format("An non HTTP provider was found: {0}", token.ToString()));
                }

                if (!json.TryGetValue(((string)token) + ".startparam", out token))
                {
                    logger.Warning("Unable to find a valid value for the http.startparam");
                }

                if (!json.TryGetValue("file", out token))
                {
                    throw new InvalidDOMStructureException("Unable to find the 'file' value in the JSON data");
                }

                movieStreamSet.VideoStreams.Add(new VideoStream
                {
                    AVStream = CreateUri((string)token).ToString(),
                });

                if (json.TryGetValue("tracks", out token))
                {
                    foreach (var jcaption in token.OfType <JObject>())
                    {
                        var caption = new Caption
                        {
                            Language = (string)jcaption["label"],
                            Address  = CreateUri((string)jcaption["file"]).ToString()
                        };
                        movieStreamSet.Captions.Add(caption);
                    }
                }

                return(movieStreamSet);
            }
        }