예제 #1
0
        private async Task Initialize()
        {
            var endpoint = GetEndpoint("configuration");
            var config   = await HttpRequestHelper.Get <Configuration>(endpoint);

            this.configurationTcs.SetResult(config);
        }
예제 #2
0
        public void GetWebFormWithHttpRequestHelper()
        {
            Uri    requestUri   = NormalizeUri("default.aspx");
            string responseText = HttpRequestHelper.Get(requestUri, null, null);

            Assert.IsTrue(responseText.IndexOf("This is the default document of the TestWebApp") > 0);
        }
예제 #3
0
        static void Main(string[] args)
        {
            var result1 = HttpRequestHelper.Get <JObject>("http://192.168.1.3:8123/Token/GetTest", "", AppConfig.SignKey, true);

            Console.WriteLine(JsonConvert.SerializeObject(result1));
            Console.ReadLine();
        }
예제 #4
0
        public Task Execute(IJobExecutionContext context)
        {
            var data = JsonSerializerHelper.Deserialize <Data.Models.TaskScheduling>(context.JobDetail.JobDataMap.GetString("data"));

            Log4Net.InfoLog("run job:" + data.Id);
            DateTime runTime     = context.FireTimeUtc.LocalDateTime;
            DateTime?nextRunTime = null;

            if (context.NextFireTimeUtc != null)
            {
                nextRunTime = context.NextFireTimeUtc.Value.LocalDateTime;
            }
            string result = "";

            try
            {
                result = httpRequest.Get(data.Api, null);
            }
            catch (Exception ex)
            {
                Log4Net.ErrorLog(ex);
                result = ex.Message;
            }
            try
            {
                schedulingHistory.InsertHistoryAndUpdateScheduling(data.Id, data.Name, runTime, nextRunTime, result);
            }
            catch (Exception ex)
            {
                Log4Net.ErrorLog(ex);
            }
            return(Task.Delay(0));
        }
예제 #5
0
        public void InstallPlugin(string name, string version = null)
        {
            var plugins = GetAllPlugins();
            var plugin  = plugins.FirstOrDefault(p =>
            {
                var formattedName = p.name.ToLower().Replace("plugin", "");
                return(formattedName == name.ToLower());
            });

            if (plugin == null)
            {
                _consoleWriter.Write($"Unknown Plugin {name}");
                return;
            }
            var versions = HttpRequestHelper.Get <GitTreeRoot>($"https://api.github.com/repos/dhemken97/plugins/git/trees/{plugin.sha}").tree;

            version = version ?? versions.OrderBy(v => v).Last().path;
            var tree = versions.FirstOrDefault(t => t.path == version);

            if (tree == null)
            {
                _consoleWriter.Write($"Unknown Version {version}");
                return;
            }

            name = plugin.name.ToLower().Replace("plugin", "");

            TaskSpinner.RunTaskWithSpinner(_consoleWriter, $"Installing {name} Plugin...", () => { DownloadAndInstall(tree, plugin); });
        }
        public void GetContentTest()
        {
            var ipAddressProviderUrl = @"http://www.baidu.com";

            var response = HttpRequestHelper.Get(ipAddressProviderUrl, "GBK");

            Assert.NotNull(response);
        }
예제 #7
0
        private string GetPageContent()
        {
            var headers = HttpRequestHelper.GetDefaultHeaders("UTF-8");

            headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");

            return(HttpRequestHelper.Get(REGISTER_PAGE_URL, GetHttpCookies(), headers));
        }
예제 #8
0
        public async Task <SeasonInfo> LoadDetails(int id, int seasonNumber)
        {
            var endpoint = GetEndpoint($"tv/{id}/season/{seasonNumber}");
            var response = await HttpRequestHelper.Get <TMDbSeasonInfo>(endpoint);

            var config = await configurationTcs.Task;

            config.ImagesConfiguration.UpdateUrls(response, 200, 200);
            return(Mapper.Map <SeasonInfo>(response));
        }
예제 #9
0
        public async Task <SeriesInfo> LoadDetails(int id)
        {
            var endpoint = GetEndpoint($"tv/{id}");
            var response = await HttpRequestHelper.Get <TMDbSeriesInfo>(endpoint);

            var config = await configurationTcs.Task;

            config.ImagesConfiguration.UpdateUrls(response, 200, this.device.Display.Width, 200);
            return(Mapper.Map <SeriesInfo>(response));
        }
예제 #10
0
        public async Task <IEnumerable <SeriesInfo> > Search(string query)
        {
            var endpoint = GetEndpoint("search/tv", $"query={query}");
            var response = await HttpRequestHelper.Get <TMDbCollection <TMDbSeriesInfo> >(endpoint);

            var config = await configurationTcs.Task;

            foreach (var info in response.Items)
            {
                config.ImagesConfiguration.UpdateUrls(info, 200, this.device.Display.Width, 200);
            }

            return(response.Items.Select(Mapper.Map <SeriesInfo>));
        }
예제 #11
0
        private void DownloadAndInstall(Tree tree, GitObject plugin)
        {
            var name        = plugin.name.ToLower().Replace("plugin", "");
            var url         = tree.url;
            var folder      = HttpRequestHelper.Get <GitTreeRoot>(url);
            var fileDetails = HttpRequestHelper.Get <GitTreeRoot>(folder.tree.FirstOrDefault().url);
            var file        = HttpRequestHelper.Get <GitFile>(fileDetails.url);
            var bytes       = Convert.FromBase64String(file.content);

            File.WriteAllBytes($"{Configuration.BaseDirectory}/Plugins/{plugin.name}.dll", bytes);
            Configuration.Reload();
            var isSuccess = Configuration.Domains.Any(a => a.FriendlyName.Contains(plugin.name));
            var message   = isSuccess ? "Success" : "Failed";

            _consoleWriter.Write($"\rInstalling {name} Plugin...{message}\r\n");
        }
예제 #12
0
        public void TestEvents()
        {
            Fixture f        = new Fixture();
            bool    started  = false;
            bool    stopped  = false;
            bool    begin    = false;
            bool    complete = false;

            f.ServerStarted   += ((sender, args) => { started = true; });
            f.RequestBegin    += ((sender, args) => { begin = true; });
            f.RequestComplete += ((sender, args) => { complete = true; });
            f.ServerStopped   += ((sender, args) => { stopped = true; });

            //Thread t = new Thread(() =>
            //                          {
            //                              f.StartServer(@"..\..\..\CassiniDev.FixtureExamples.TestWeb",
            //                                            IPAddress.Loopback,
            //                                            Fixture.GetPort(8080, 9000, IPAddress.Loopback), "/",
            //                                            "localhost", false, 0, 0);

            //                              HttpRequestHelper.Get(new Uri(f.RootUrl), null, null);
            //                              f.StopServer();
            //                              while (!stopped)
            //                              {
            //                                  Thread.Sleep(0);
            //                              }
            //                          });

            //t.Start();
            //t.Join(50000);

            f.StartServer(@"..\..\..\CassiniDev.FixtureExamples.TestWeb",
                          IPAddress.Loopback,
                          Fixture.GetPort(8080, 9000, IPAddress.Loopback), "/",
                          "localhost", false, 0, 0);

            HttpRequestHelper.Get(new Uri(f.RootUrl), null, null);
            f.StopServer();

            Assert.IsTrue(started, "server started event not fired");

            Assert.IsTrue(begin, "request begin event not fired");
            Assert.IsTrue(complete, "request complete event not fired");
            Assert.IsTrue(stopped, "server stopped event not fired");
        }
예제 #13
0
        public void GetWebFormWithHttpRequestHelperAndParseWithMSHTML()
        {
            Uri requestUri = NormalizeUri("default.aspx");

            string responseText = HttpRequestHelper.Get(requestUri, null, null);

            Assert.IsTrue(responseText.IndexOf("This is the default document of the TestWebApp") > 0);
            using (HttpRequestHelper browser = new HttpRequestHelper())
            {
                // parse the html in internet explorer
                IHTMLDocument2 doc = browser.ParseHtml(responseText);
                // get the resultant html
                string content = doc.body.outerHTML;
                Assert.IsTrue(content.IndexOf("This is the default document of the TestWebApp") > 0);
                IHTMLElement form = browser.FindElementByID("form1");
                Assert.IsNotNull(form);
            }
        }
예제 #14
0
        public void GetWebFormWithHttpRequestHelperWithCookies()
        {
            CookieContainer cookies    = new CookieContainer();
            Uri             requestUri = NormalizeUri("TestWebFormCookies1.aspx");

            HttpRequestHelper.Get(requestUri, null, cookies);
            CookieCollection mycookies = cookies.GetCookies(requestUri);
            Cookie           cookie    = mycookies["Cooookie"];

            Assert.IsNotNull(cookie);
            Assert.AreEqual("TestWebFormCookies1", cookie.Value);
            requestUri = NormalizeUri("TestWebFormCookies2.aspx");
            HttpRequestHelper.Get(requestUri, null, cookies);
            mycookies = cookies.GetCookies(requestUri);
            cookie    = mycookies["Cooookie"];
            Assert.IsNotNull(cookie);
            Assert.AreEqual("TestWebFormCookies2", cookie.Value);
        }
예제 #15
0
        public void GetHtmlWithHttpRequestHelperAndParseWithMSHTMLAndVerifyJavascriptExecution()
        {
            Uri jsUri = NormalizeUri("TestJavascript.htm");

            string responseText = HttpRequestHelper.Get(jsUri, null, null);

            using (HttpRequestHelper browser = new HttpRequestHelper())
            {
                // parse the html in internet explorer
                IHTMLDocument2 doc = browser.ParseHtml(responseText);

                // get the resultant html
                string content = doc.body.outerHTML;

                Assert.IsTrue(content.IndexOf("HEY IM IN A SCRIPT") > 0, "inline script document.write not executed");
                Assert.IsTrue(content.IndexOf("this is some text from javascript") == -1,
                              "if failed then event driven script document.appendChile executed!");
            }
        }
예제 #16
0
        public List <Proxy> FetchForeignProxy()
        {
            var proxies = new List <Proxy>();
            int count   = 0;

            while (count < 5)
            {
                count++;
                try
                {
                    var proxyHtml = HttpRequestHelper.Get(CommonAppSetting.Instatance.ForeignProxyProvider,
                                                          null,
                                                          GetHeaders());
                    var doc = new HtmlDocument();
                    doc.LoadHtml(proxyHtml);

                    foreach (var tr in doc.DocumentNode.SelectNodes("//tr"))
                    {
                        var tds = tr.ChildNodes.Where(item => item.NodeType != HtmlNodeType.Text).ToArray();

                        var host = tds[0].InnerText.RemoveWhiteSpace();
                        if (Regex.IsMatch(host, IP_ADDRESS_PATTERN))
                        {
                            proxies.Add(new Proxy
                            {
                                Host    = host,
                                Port    = tds[1].InnerText.RemoveWhiteSpace(),
                                Area    = "国外",
                                Address = tds[3].InnerText.Trim()
                            });
                        }
                    }
                    return(proxies);
                }
                catch (Exception)
                {
                }
                Thread.Sleep(1000);
            }
            return(proxies);
        }
예제 #17
0
        public void GetWebFormWithHttpRequestHelperWithCookies()
        {
            // pass the same instance of CookieContainer to each request
            // cookies (session id, membership cache etc) are read from and written to
            CookieContainer cookies = new CookieContainer();

            // page that sets a cookie on the response
            Uri requestUri = NormalizeUri("TestWebFormCookies1.aspx");

            // pass the cookie container with the requestUri
            HttpRequestHelper.Get(requestUri, null, cookies);

            // get the cookies for this path from the container
            CookieCollection mycookies = cookies.GetCookies(requestUri);

            // find our cookie and test it
            Cookie cookie = mycookies["Cooookie"];

            Assert.IsNotNull(cookie);
            Assert.AreEqual("TestWebFormCookies1", cookie.Value);

            // page that reads cookie from request and ensures is present and
            // has expected value then writes it back out to the response with
            // a different value.
            requestUri = NormalizeUri("TestWebFormCookies2.aspx");

            // just pass the same CookieContainer
            HttpRequestHelper.Get(requestUri, null, cookies);

            //....
            mycookies = cookies.GetCookies(requestUri);
            cookie    = mycookies["Cooookie"];
            Assert.IsNotNull(cookie);

            // bingo!
            Assert.AreEqual("TestWebFormCookies2", cookie.Value);

            // now you can maintain state across requests
        }
예제 #18
0
        public string GetLocalIpInfo()
        {
            try
            {
                var homePageContent = HttpRequestHelper.Get(IP_ADDRESS_PROVIDER_URL, "GBK");
                var doc             = new HtmlDocument();
                doc.LoadHtml(homePageContent);

                var ipFrame       = doc.DocumentNode.SelectNodes("//iframe").First();
                var ipAddressPage = ipFrame.GetAttributeValue("src", string.Empty);

                var ipContent = HttpRequestHelper.Get(ipAddressPage, encodingStr: "GBK");
                doc.LoadHtml(ipContent);

                var ipInfo = doc.DocumentNode.SelectNodes("//center").First().InnerText;

                return(ipInfo);
            }
            catch (Exception)
            {
                return(CANNOT_LOCATE_YOUR_IP);
            }
        }
예제 #19
0
        public void TestTimeOutWithRequest()
        {
            Fixture f       = new Fixture();
            bool    stopped = false;

            f.ServerStopped += ((sender, args) => { stopped = true; });
            Thread t = new Thread(() =>
            {
                f.StartServer(@"..\..\..\CassiniDev.FixtureExamples.TestWeb",
                              IPAddress.Loopback,
                              Fixture.GetPort(8080, 9000, IPAddress.Loopback), "/",
                              "localhost", false, 0, 5000);

                HttpRequestHelper.Get(new Uri(f.RootUrl), null, null);
                while (!stopped)
                {
                    Thread.Sleep(0);
                }
            });

            t.Start();
            t.Join(50000);
            Assert.IsTrue(stopped, "server stopped event not fired");
        }
예제 #20
0
 public string Get(string cultureName, string key)
 {
     return(HttpRequestHelper.Get <string>(serviceEndpoint, string.Format("api/cultures?culturename={0}&key={1}", cultureName, key)));
 }
예제 #21
0
 private List <GitObject> GetAllPlugins()
 {
     return(HttpRequestHelper.Get <GitObject[]>("https://api.github.com/repos/dhemken97/plugins/contents/")
            .ToList());
 }