Пример #1
0
        public void ShouldTakeAuthorizationAsAgrument()
        {
            var sut = new HttpEngine();

            sut.Authorization = authorization;
            var ff = sut.GetHttpResponseAsync(url).Result;
        }
Пример #2
0
        public async Task <bool> GetEmailReminderStatus()
        {
            try
            {
                HttpEngine httpRequest = new HttpEngine();
                string     result      = await httpRequest.GetAsync("http://api.sellmoe.com/get_user_info?key=" + key + "&hash=" + new Random().Next());

                JObject json = JObject.Parse(result);
                ErrorProcessor(json);

                int status = (int)json["data"]["email"];
                if (status == 1)
                {
                    emailReminderStatus = true;
                }
                else
                {
                    emailReminderStatus = false;
                }
                return(true);
            }
            catch
            {
                throw;
            }
        }
Пример #3
0
        public async Task <bool> SetEmailReminderStatus(bool status)
        {
            try
            {
                HttpEngine httpRequest = new HttpEngine();
                string     enable;
                if (status)
                {
                    enable = "1";
                }
                else
                {
                    enable = "0";
                }
                string result = await httpRequest.GetAsync("http://api.sellmoe.com/email_reminder_set?key=" + key + "&enable=" + enable + "&hash=" + new Random().Next());

                JObject json = JObject.Parse(result);
                ErrorProcessor(json);
                emailReminderStatus = status;
                return(true);
            }
            catch
            {
                throw;
            }
        }
Пример #4
0
        void WhereMatsuya(string content)
        {
            var setMatsuyaReg = new Regex(RegexStringSet.MatsuyaPattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            var m             = setMatsuyaReg.Match(content);

            var req = new PlacesTextSearchRequest();

            req.Language = Language.Japanese;
            req.Key      = "AIzaSyDOFjkWnVMBNklD5RjTQX2T9XfwsAzHI2k";
            req.Query    = "松屋 " + m.Groups[2];

            var httpEngine = new HttpEngine <PlacesTextSearchRequest, PlacesTextSearchResponse>();
            var res        = httpEngine.Query(req).Results.Take(3);

            if (res.Count() == 0)
            {
                this.client.PostStatus("みつからなかったよ", Visibility.Public);
            }
            else
            {
                var tootText = "調べてみたら";
                foreach (var r in res)
                {
                    tootText += r.Name + "、";
                }
                tootText  = tootText.Substring(0, tootText.Length - 1);
                tootText += "がみつかったよ";
                this.client.PostStatus(tootText, Visibility.Public);
            }
        }
Пример #5
0
        public PlacesNearbySearchResponse NearbySearchTest()
        {
            //Arrange
            var response = new PlacesNearbySearchResponse();
            var request  = new PlacesNearBySearchRequest
            {
                Key      = "AIzaSyB_4x15ATP7Br_fRJpb215UGhsL519cwPA",
                Location = new Location()
                {
                    Latitude = 45.8057017, Longitude = 15.9205017
                },
                Radius = 1000
            };

            HttpEngine <PlacesNearBySearchRequest, PlacesNearbySearchResponse> httpResponse
                = new HttpEngine <PlacesNearBySearchRequest, PlacesNearbySearchResponse>();

            // Act
            response = httpResponse.Query(request);

            // Assert
            Assert.IsNotNull(response);


            return(response);
        }
Пример #6
0
        public PlacesNearbySearchResponse NearbySearch(double lat, double lgn)
        {
            var response = new PlacesNearbySearchResponse();

            try
            {
                var AppKey = new ConfigurationBuilder().AddJsonFile("application.default.json").Build().GetSection("AppSettings")["ApiKey"];

                var request = new PlacesNearBySearchRequest
                {
                    Key      = AppKey.ToString(),//this.ApiKey,
                    Location = new Location()
                    {
                        Latitude = lat, Longitude = lgn
                    },
                    Radius = 1000
                };

                HttpEngine <PlacesNearBySearchRequest, PlacesNearbySearchResponse> httpResponse
                    = new HttpEngine <PlacesNearBySearchRequest, PlacesNearbySearchResponse>();

                response = httpResponse.Query(request);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Exception during geting places data: " +
                                ex.ToString());
            }
            return(response);
        }
Пример #7
0
        public void ShouldHaveGetHttpResponseMethod()
        {
            var        sut        = new HttpEngine();
            MethodInfo methodInfo = sut.GetType().GetMethod("GetHttpResponseAsync");

            Assert.IsNotNull(methodInfo);
        }
Пример #8
0
 /// <summary>
 ///  Render the webpage icon onto the give specified engine.
 /// </summary>
 /// <param name='serverFolder'>
 /// The root of the server folder that contains the custom favoicon.
 /// </param>
 /// <param name='engine'>
 ///  The given specified engine.
 /// </param>
 /// <param name='stream'>
 /// The stream to write the content to.
 /// </param>
 public void RenderIcon(string serverFolder, HttpEngine engine, Stream stream)
 {
     this.Load(serverFolder);
     using (BinaryWriter bw = new BinaryWriter(stream)) {
         bw.Write(this.data);
     }
 }
Пример #9
0
        public static void Main(string[] args)
        {
            HttpEngine engine = HttpEngine.Initialize();

            httpEngine = engine;
            System.Console.WriteLine("Init ok");
            Start();
        }
Пример #10
0
        public async void Search()
        {
            ProgressBar.Text           = "搜索中...";
            ProgressBar.IsVisible      = true;
            SearchBox.IsEnabled        = false;
            LongListSelector.IsEnabled = false;
            try
            {
                HttpEngine httpRequest = new HttpEngine();
                string     result      = await httpRequest.GetAsync("http://mediaso.xmp.kankan.xunlei.com/search.php?keyword=" + SearchBox.Text + "&hash=" + new Random().Next());

                App.ViewModel.SearchResultItems.Clear();
                string name_flag_begin  = "sname=\"";
                string name_flag_end    = "\",";
                string id_flag_begin    = "imovieid=";
                string id_flag_end      = ",";
                string type_flag_begin  = "Typedesc=\"";
                string type_flag_end    = "\",";
                int    name_index_begin = result.IndexOf(name_flag_begin);
                while (name_index_begin != -1)
                {
                    // name
                    int    name_index_end = result.IndexOf(name_flag_end, name_index_begin);
                    string name           = result.Substring(name_index_begin + name_flag_begin.Length, name_index_end - name_index_begin - name_flag_begin.Length);
                    // id
                    int    id_index_begin = result.IndexOf(id_flag_begin, name_index_end);
                    int    id_index_end   = result.IndexOf(id_flag_end, id_index_begin);
                    string id             = result.Substring(id_index_begin + id_flag_begin.Length, id_index_end - id_index_begin - id_flag_begin.Length);
                    // type
                    int    type_index_begin = result.IndexOf(type_flag_begin, id_index_end);
                    string type             = "";
                    if (type_index_begin != -1)
                    {
                        int type_index_end = result.IndexOf(type_flag_end, type_index_begin);
                        type = result.Substring(type_index_begin + type_flag_begin.Length, type_index_end - type_index_begin - type_flag_begin.Length);
                    }
                    if (type != "电影")
                    {
                        App.ViewModel.SearchResultItems.Add(new ViewModels.SearchResultModel()
                        {
                            Name = name, ID = id, Type = type
                        });
                    }
                    name_index_begin = result.IndexOf(name_flag_begin, id_index_end);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "错误", MessageBoxButton.OK);
            }
            finally
            {
                SearchBox.IsEnabled        = true;
                LongListSelector.IsEnabled = true;
                ProgressBar.IsVisible      = false;
                ProgressBar.Text           = "";
            }
        }
Пример #11
0
        public void ShouldPassAutorizationAsHeader()
        {
            var sut = new HttpEngine();

            sut.Authorization = authorization;
            var dic = (Dictionary <string, object>)sut.GetHttpResponseAsync("http://headers.jsontest.com/").Result;

            Assert.IsNotNull(dic["User-Agent"]);
        }
Пример #12
0
        public void ShouldRetunDictionaryWithValues()
        {
            var sut = new HttpEngine();

            sut.Authorization = authorization;
            var dic = sut.GetHttpResponseAsync(url).Result;

            Assert.IsTrue(dic.Keys.Count > 0);
        }
Пример #13
0
        // 最近更新 图片加载
        private async void Image_Loaded_1(object sender, RoutedEventArgs e)
        {
            try
            {
                var image = sender as Image;
                var item  = image.DataContext as ViewModels.ScheduleModel;

                BitmapImage bitmap = new BitmapImage();
                using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    string filePath = "/Cache/" + item.aid + "_1.jpg";
                    if (isf.FileExists(filePath))
                    {
                        using (IsolatedStorageFileStream stream = isf.OpenFile(filePath, FileMode.Open))
                        {
                            bitmap.SetSource(stream);
                        }
                    }
                    else
                    {
                        HttpEngine httpRequest = new HttpEngine();
                        Stream     stream      = await httpRequest.GetAsyncForData("http://images.movie.xunlei.com/submovie_img/" + item.aid[0] + item.aid[1] + "/" + item.aid + "/1_1_115x70.jpg");

                        bitmap.SetSource(stream);
                        if (!isf.DirectoryExists("/Cache"))
                        {
                            isf.CreateDirectory("/Cache");
                        }
                        using (IsolatedStorageFileStream writeStream = isf.OpenFile(filePath, FileMode.Create))
                        {
                            WriteableBitmap wb = new WriteableBitmap(bitmap);
                            wb.SaveJpeg(writeStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                            writeStream.Close();
                        }
                    }
                }

                image.Source = bitmap;

                Storyboard storyboard = new Storyboard();

                DoubleAnimation animation = new DoubleAnimation();
                animation.From     = 0;
                animation.To       = 1;
                animation.Duration = new Duration(TimeSpan.FromMilliseconds(500));

                Storyboard.SetTarget(animation, image);
                Storyboard.SetTargetProperty(animation, new PropertyPath(Image.OpacityProperty));

                storyboard.Children.Add(animation);
                storyboard.Begin();
            }
            catch
            {
                // do nothing
            }
        }
Пример #14
0
 /// <summary>
 ///  Render the webpage onto the give specified engine.
 /// </summary>
 /// <param name='serverFolder'>
 /// The root of the folder of the web server.
 /// </param>
 /// <param name='engine'>
 ///  The given specified engine.
 /// </param>
 /// <param name='writer'>
 /// The html writer to write content to.
 /// </param>
 public virtual void Render(string serverFolder, HttpEngine engine, Html32TextWriter writer)
 {
     this.Load(serverFolder);
     if (this.pieces != null)
     {
         foreach (IWebPagePiece piece in this.Pieces)
         {
             piece.Render(serverFolder, engine, writer);
         }
     }
 }
Пример #15
0
 private string GetLatestVesrionFrormRemote(string url)
 {
     try
     {
         var httpEngine = new HttpEngine();
         return(httpEngine.GetResponseStringAsync(httpEngine.GetHttpResponseAsync(url).Result[DownloadUrl].ToString()).Result);
     }
     catch (WebException ex)
     {
         throw ex;
     }
 }
Пример #16
0
        private async Task <int> GetHttpData()
        {
            HttpEngine he     = new HttpEngine();
            var        stream = await he.Get(AcFunAPI.GetHomeDataUrl());

            if (stream != null)
            {
                var str = new System.IO.StreamReader(stream.AsStreamForRead()).ReadToEnd();
                ParseData(str);
            }
            return(0);
        }
Пример #17
0
        public async Task <AXFContent> GetSingleData(string id, string key)
        {
            HttpEngine he     = new HttpEngine();
            var        stream = await he.Get(AcFunAPI.GetRegionUrlById(id));

            if (stream != null)
            {
                var str = new System.IO.StreamReader(stream.AsStreamForRead()).ReadToEnd();
                ParseSingleData(str);
            }
            return(DataOfDic[key]);
        }
Пример #18
0
        public async Task <bool> GetSubscriptionList()
        {
            try
            {
                HttpEngine httpRequest = new HttpEngine();
                string     result      = await httpRequest.GetAsync("http://api.sellmoe.com/get_user_info?key=" + key + "&sb=Ricter&hash=" + new Random().Next());

                JObject json = JObject.Parse(result);
                ErrorProcessor(json);

                subscriptionList.Clear();
                updateNumber = 0;
                JArray subscription = json["data"]["subscription"] as JArray;
                foreach (JObject item in subscription)
                {
                    Anime anime = new Anime();
                    anime.aid       = (string)item["id"];
                    anime.name      = (string)item["name"];
                    anime.status    = ((int)item["isover"]).ToString();
                    anime.epi       = ((int)item["episode"]).ToString();
                    anime.read      = ((int)item["watch"]).ToString();
                    anime.highlight = ((int)item["isread"]).ToString();
                    subscriptionList.Add(anime);

                    if (anime.highlight != "0")
                    {
                        updateNumber++;
                    }
                }

                subscriptionList.Sort((Anime a, Anime b) =>
                {
                    if (a.highlight != "0" && b.highlight == "0")
                    {
                        return(-1);
                    }
                    return(0);
                });


                for (int i = 0; i < subscriptionList.Count; ++i)
                {
                    subscriptionList[i].num = i + 1;
                }

                return(true);
            }
            catch
            {
                throw;
            }
        }
Пример #19
0
        public void ShouldDeleteFilesOldestFiles()
        {
            var fileContent = "Testing File";

            File.WriteAllText(_logFile, fileContent);
            var file    = Path.Combine(@"0012345", Guid.NewGuid().ToString());
            var fullUrl = ConfigurationManager.AppSettings["BlobContainerBaseUri"] + "/" + file;

            _fileSystem.CopyFile(_logFile, file);
            var responseText = new HttpEngine().GetResponseStringAsync(fullUrl).Result;

            Assert.IsTrue(responseText.Equals(fileContent));
        }
Пример #20
0
 public void Listen()
 {
     this.listener = new TcpListener(IPAddress.Loopback, this.port);
     this.listener.Start();
     while (true)
     {
         TcpClient  s      = listener.AcceptTcpClient();
         HttpEngine pr     = new HttpEngine(s, this);
         Thread     thread = new Thread(new ThreadStart(pr.Process));
         thread.Start();
         Thread.Sleep(1);
     }
 }
Пример #21
0
        /// <summary>
        /// Render the webpage onto the give specified engine.
        /// </summary>
        /// <param name="serverFolder">The root of the folder of the web server.</param>
        /// <param name="engine">The given specified engine.</param>
        /// <param name="writer">The html writer to write content to.</param>
        public override void Render(string serverFolder, HttpEngine engine, Html32TextWriter writer)
        {
            string landingName = this.LandingName;

            writer.AddAttribute(HtmlTextWriterAttribute.Id, landingName);
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.RenderEndTag();
            if (this.QueryPage != null)
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Script);
                writer.WriteLine("genericAjax (\"{0}\", \"{1}\");", this.QueryPage.Href, landingName);
                writer.RenderEndTag();
            }
        }
Пример #22
0
        public async Task <bool> ChangePsw(string oldPsw, string newPsw)
        {
            try
            {
                HttpEngine httpRequest = new HttpEngine();
                string     result      = await httpRequest.GetAsync("http://api.sellmoe.com/changepw?key=" + key + "&oldpw=" + oldPsw + "&newpw=" + newPsw + "&hash=" + new Random().Next());

                JObject json = JObject.Parse(result);
                ErrorProcessor(json);
                return(true);
            }
            catch
            {
                throw;
            }
        }
Пример #23
0
        private async Task <List <Suggest> > GetSuggest(string key)
        {
            try
            {
                HttpEngine engine = new HttpEngine();
                var        str    = await engine.GetString("http://search.app.acfun.cn/suggest?q=" + key);

                var suggests = JsonConvert.DeserializeObject <RespData <List <Suggest> > >(str);
                return(suggests.Data);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("[AcFunVideo][SearchPage.GetSuggest]" + ex.Message);
                return(null);
            }
        }
Пример #24
0
        public async Task <bool> DelHighlight(string aid)
        {
            try
            {
                HttpEngine httpRequest = new HttpEngine();
                string     result      = await httpRequest.GetAsync("http://api.sellmoe.com/highlight?key=" + key + "&aid=" + aid + "&method=del&hash=" + new Random().Next());

                JObject json = JObject.Parse(result);
                ErrorProcessor(json);
                return(true);
            }
            catch
            {
                throw;
            }
        }
Пример #25
0
        public async Task <bool> SetReadEpi(string aid, string epi)
        {
            try
            {
                HttpEngine httpRequest = new HttpEngine();
                string     result      = await httpRequest.GetAsync("http://api.sellmoe.com/epiedit?key=" + key + "&aid=" + aid + "&epi=" + epi + "&hash=" + new Random().Next());

                JObject json = JObject.Parse(result);
                ErrorProcessor(json);
                return(true);
            }
            catch
            {
                throw;
            }
        }
Пример #26
0
        public void UpdateApp(IEnumerable <string> exludeFiles)
        {
            var httpEngine = new HttpEngine();
            var arr        = (object[])httpEngine.GetHttpResponseObjectAsync(_appUpdateDetail.Source).Result;

            foreach (var file in arr)
            {
                var dic       = file as Dictionary <string, object>;
                var foundFile = exludeFiles.FirstOrDefault(x => x.Equals(dic["name"].ToString(), StringComparison.OrdinalIgnoreCase));

                if (string.IsNullOrEmpty(foundFile))
                {
                    httpEngine.DownLoadFileAsync(dic[DownloadUrl].ToString(), Path.Combine(_appUpdateDetail.Destination, dic["name"].ToString()));
                }
            }
        }
Пример #27
0
        public async Task <bool> Register(string username, string password)
        {
            try
            {
                HttpEngine httpRequest = new HttpEngine();
                string     result      = await httpRequest.PostAsync("http://api.sellmoe.com/reg?hash=" + new Random().Next(), "u=" + username + "&p=" + password);

                JObject json = JObject.Parse(result);
                ErrorProcessor(json);
                key = (string)json["data"]["key"];
                return(true);
            }
            catch
            {
                throw;
            }
        }
Пример #28
0
 /// <summary>
 ///  Render the webpage onto the give specified engine.
 /// </summary>
 /// <param name='serverFolder'>
 ///  The root of the folder of the web server.
 /// </param>
 /// <param name='engine'>
 ///  The given specified engine.
 /// </param>
 /// <param name='writer'>
 ///  The html writer to write content to.
 /// </param>
 public override void Render(string serverFolder, HttpEngine engine, Html32TextWriter writer)
 {
     this.Load(serverFolder);
     foreach (HtmlAttribute ha in this.node.Attributes)
     {
         writer.AddAttribute(ha.Name, ha.Value);
     }
     writer.RenderBeginTag(this.node.Name);
     if (this.pieces != null)
     {
         foreach (IWebPagePiece piece in this.pieces)
         {
             piece.Render(serverFolder, engine, writer);
         }
     }
     writer.RenderEndTag();
 }
Пример #29
0
        private async void Test()
        {
            //Encode("sdj", "zx26mfbsuebv72ja");
            //Encode("44616713980388605ab4d_030020010057150762B6552D9B7D2F302AAB41-D431-EDEE-DF77-5A4E5E993D74_8466", "zx26mfbsuebv72ja");
            var md5str = Utils.GetMD5String("GET:/common/partner/play:1462284491:78554907b127c3853f8e956243dc74c4");
            var url    = "http://acfun.api.mobile.youku.com/common/partner/play?_t_=1462284491&e=md5&_s_=" + md5str
                         + "&point=1&id=CMzQwMTA3Mg==&format=1,5,6,7,8&language=guoyu&did=a721b02c70aa0c2784afa3a39b9356b6&ctype=87&audiolang=1&pid=528a34396e9040f3";
            HttpEngine he   = new HttpEngine();
            var        data = await he.Get(url);

            var reader = new StreamReader(data.AsStreamForRead());
            var str    = reader.ReadToEnd();
            var obj    = Newtonsoft.Json.Linq.JObject.Parse(str);
            var keystr = obj["data"].ToString();
            var destr  = Decode(keystr, Aeskey);

            //http://k.youku.com/player/getFlvPath/sid/44616713980388605ab4d_00/st/mp4/fileid/030020010057150762B6552D9B7D2F302AAB41-D431-EDEE-DF77-5A4E5E993D74/?K=8aae87b234a1cb02282b5e1a&hd=1&myp=0&ts=1519.867&ypp=0&ep=C55ccxIEzL9JF0%2FF5gjcoEbkDHaOmE%2FI6YrmN90c%2FieiMqDvcFpZvjPJK9ojN%2BP0ZzFvykhvKduhPiCXpaaWGpUPQos0wjsPI%2BH6PVV%2FwXCORi1awYC9q1DYqq7W&ctype=86&ev=1&token=8466&oip=3550665720
        }
Пример #30
0
        private async void GetHotKey()
        {
            try
            {
                HttpEngine engine = new HttpEngine();
                var        str    = await engine.GetString("http://api.aixifan.com/hotwords");

                var keys  = JsonConvert.DeserializeObject <RespData <List <Hotword> > >(str);
                var items = keys.Data.Select(x => new Suggest()
                {
                    Name = x.Value
                }).ToList();
                SuggestBox.ItemsSource          = items;
                SuggestBox.IsSuggestionListOpen = true;
            }
            catch (Exception)
            {
            }
        }