示例#1
0
        private string GetGitText()
        {
            WebReader reader  = new WebReader();
            var       gitText = reader.ReadText_FromURL(GitReleasesURL, maxTries: 50);

            return(gitText);
        }
示例#2
0
    /*---------------------------------------------------------
    * Method: findCoords
    *
    * Purpose: Finds the averaged coordinates of a city
    *          using the .csv file containing coordinates
    *          for various zip codes.
    *
    * Parameters:
    *   city - a string containing the name of the city
    *   statecode - the 2-letter abbreviation for the state
    *
    * Returns: A Location object.
    *          Returns '-1, -1' as coords if the city
    *          is not found.
    *--------------------------------------------------------*/
    public static Location findCoords(string city, string statecode)
    {
        double latSum  = 0.0;
        double longSum = 0.0;
        int    count   = 0;

        // read through the .csv file
        // and sum the coordinates where the
        // city and statenames match
        string    url    = "http://theochem.mercer.edu/csc330/data/zip_codes_states.csv";
        WebReader reader = new WebReader(url);
        string    line   = reader.getLine();

        while (line != null)
        {
            string[] columns = line.Split(',');
            if (columns[3].Contains(city) && columns[4].Contains(statecode))
            {
                try {
                    latSum  += Double.Parse(columns[1]);
                    longSum += Double.Parse(columns[2]);
                    count++;
                } catch (FormatException) {}
            }
            line = reader.getLine();
        }

        if (count == 0)
        {
            return(new Location(-1.0, -1.0, city, statecode));
        }
        return(new Location((latSum / count), (longSum / count), city, statecode));
    }
示例#3
0
        private static void PerformVersionCheck()
        {
            string content = new WebReader().Read(UPDATES_URL);

            if (!string.IsNullOrWhiteSpace(content))
            {
                var regex = new Regex(@"\d+\.\d+\.\d+");
                var lines = new List <string>();
                foreach (Match match in regex.Matches(content))
                {
                    lines.Add(match.Value);
                }

                var versions = lines
                               .OrderByDescending(VersionToNumber)
                               .ToArray();
                string topVersion = versions.FirstOrDefault();

                long actualVersion = VersionToNumber(Assembly.GetExecutingAssembly().GetName().Version.ToString(3));
                if (actualVersion < VersionToNumber(topVersion))
                {
                    _logger.Value.Debug($"There is newer version: {topVersion}");
                    Messenger.Default.Send(new ApplicationUpdateMessage($"{Strings.UpdateAvailable}: {topVersion}", string.Empty));
                }
                else
                {
                    _logger.Value.Debug("Up-to-date");
                }
            }
        }
        public override async Task <bool> BeforeOk()
        {
            /*
             * This is a chance to verify the data. If user didn't enter the correct values, return false
             * Once this function returns true, OnOk will be called.
             * */

            try
            {
                IsRefreshing = true;
                try
                {
                    await WebReader.GetItemsAsync(Url);

                    return(true);
                }
                finally
                {
                    IsRefreshing = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
        }
        internal string GetJsonFromYouTube()
        {
            if (!CanGetPlaylistFromJSON())
            {
                return(null);
            }

            var parameters = new Dictionary <string, string>
            {
                //Store API Key
                ["key"] = APIKey,
                //Store the Playlisy ID
                ["playlistId"] = playListID,
                //Get only the info in this part
                ["part"] = "snippet",
                //get on the info in this feild for this part
                //["fields"] = "pageInfo, items/snippet(title)", //removed this to get more info. Leaving for reference
                //Max number of video you can pull
                ["maxResults"] = videoListSize.ToString()
            };

            //Create full URL with API key
            var fullUrl = MakeUrlWithQuery(parameters);

            WebReader webReader = new WebReader();
            string    json      = null;

            json = webReader.ReadText_FromURL(fullUrl);
            return(json);
        }
示例#6
0
        /// <summary>
        /// Get the text from the GitApiReleasesUrl
        /// </summary>
        /// <returns>The text on the page from the url</returns>
        private string GetGitApiText()
        {
            WebReader reader = new WebReader();

            AquiredGitApiText = reader.ReadText_FromURL(GitApiReleasesURL);
            return(AquiredGitApiText);
        }
示例#7
0
        public void GetItemsTest()
        {
            var sampleUrl = "https://raw.githubusercontent.com/manictime/samplewebtagsource/master/ManicTime.TagSource.SampleWeb/SampleTags.txt";
            var tags      = WebReader.GetItemsAsync(sampleUrl).Result;

            Assert.AreEqual(5, tags.Length);
            CollectionAssert.AreEqual(new [] { "client 1", "project 1", "Activity 1" }, tags[0].Tags);
            Assert.AreEqual("Activity 1 notes", tags[0].Notes);
        }
示例#8
0
        public void TestReader_Fail_InvalidUrl()
        {
            var reader = new WebReader("conveyancing software", 100, "www.111");

            try
            {
                reader.Read();
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Incorrect site URL", ((HttpResponseException)ex).Response.ReasonPhrase);
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            DataReader dataReader = new DataReader();

            IDataRequest fileReq = new FileReader("SomeFile.txt");
            IDataRequest webReq  = new WebReader("https://www.google.com/");

            Console.WriteLine(dataReader.ReadData(fileReq));

            Console.ReadKey();
            Console.Clear();

            Console.WriteLine(dataReader.ReadData(webReq));
        }
        public void FileRecorder_tests()
        {
            using (var recorder = Recorders.FileRecorder(@"C:\Users\Patrik\Documents\recorded_calls.dat"))
            {
                var realReader = new WebReader();
                var fakeReader = A.Fake <WebReader>(x => x.Wrapping(realReader).RecordedBy(recorder));

                for (int i = 0; i < 30; i++)
                {
                    fakeReader.Download(new Uri("http://www.sembo.se/"));
                }

                Console.WriteLine(fakeReader.Download(new Uri("http://www.sembo.se/")));
            }
        }
        public void FileRecorder_tests()
        {
            using (var recorder = Recorders.FileRecorder(@"C:\Users\Patrik\Documents\recorded_calls.dat"))
            {
                var realReader = new WebReader();
                var fakeReader = A.Fake<WebReader>(x => x.Wrapping(realReader).RecordedBy(recorder));

                for (int i = 0; i < 30; i++)
                {
                    fakeReader.Download(new Uri("http://www.sembo.se/"));
                }

                Console.WriteLine(fakeReader.Download(new Uri("http://www.sembo.se/")));
            }
        }
        protected override void Update()
        {
            /*
             *
             * Add your implementation of what happens on update.
             *
             * This is the main function of the plugin, it is responsible to get tags from your service
             *
             * After you get your tags from the service call TagSourceCache.Update
             *
             */

            TagSourceItem[] items = WebReader.GetItemsAsync(_settings.Url).Result;

            TagSourceCache.Update(InstanceId, items, null, true);
        }
        private decimal ReadStockPrice(Stock stock)
        {
            try
            {
                string priceString = String.Empty;
                priceString = WebReader.ReadFromWeb(stock.URL, stock.XPath, stock.CssSelector);
                priceString = Utility.CleanCurrencyString(priceString);

                decimal priceDecimal = Utility.GetDecimalFromString(priceString, stock.IsScrapedPriceInPence);
                if (stock.Currency != CurrencyType.GBP)
                {
                    priceDecimal = currencyConverter.ConvertCurrency(priceDecimal, stock.Currency, CurrencyType.GBP);
                }
                return(priceDecimal);
            }
            catch (Exception e)
            {
                DailyPortfolioTotalFunction.Logger.Write(e.Message + "\n" + e.StackTrace);
                return(-1);
            }
        }
示例#14
0
    /*---------------------------------------------------------
    * Method: findNearestAirport
    *
    * Purpose: Finds the nearest usable airport to some location
    *
    * Returns: Location of the nearest usable airport
    *--------------------------------------------------------*/
    public static Airport findNearestAirport(Location target)
    {
        Location l      = new Location(-1, -1, target.city, target.state);
        Airport  result = new Airport("", l, false);

        result.position.city  = target.city;
        result.position.state = target.state;

        double mindist = 5000;

        WebReader reader = new WebReader("http://theochem.mercer.edu/csc330/data/airports.csv");
        String    line   = reader.getLine();

        while (line != null)
        {
            Regex regex = new Regex("\".*?\"");
            line = regex.Replace(line, m => m.Value.Replace(',', ' '));
            line = line.Replace("\"", "");
            String[] columns = line.Split(',');

            if (columns[2].Contains("airport"))
            {
                double lat = Double.Parse(columns[4]);
                double lon = Double.Parse(columns[5]);

                double dist = getDistance(target.latitude, target.longitude, lat, lon);
                if (dist < mindist)
                {
                    mindist = dist;
                    result.position.latitude  = lat;
                    result.position.longitude = lon;
                    result.name = columns[3];
                }
            }

            line = reader.getLine();
        }

        return(result);
    }
示例#15
0
 private void NavigateToNavigationPoint(NavigationPoint navigationPoint)
 {
     WebReader.Load("epub://handler/" + navigationPoint.File.Path + '#' + navigationPoint.ElementId);
 }
示例#16
0
        public Product(string sku, string mfg, string name, string desc, string price, string hdd, string ram, string proc, string pweight, string pdisplay, string gpu, string imageurl)
        {
            WebReader wr = new WebReader();

            SKU          = sku;
            Manufacturer = mfg;
            Description  = desc;
            HDDCap       = hdd;
            RAM          = ram;
            Processor    = proc;
            Weight       = pweight;
            Display      = pdisplay;
            GPU          = gpu;
            double.TryParse(price, out priceout);
            Price       = priceout;
            Name        = name;
            Category    = "";
            ImageUrl    = imageurl;
            SubCategory = "";
            //    imageUrl = new Uri(imageurl, UriKind.RelativeOrAbsolute);


            if (Processor != "")
            {
                if (Name.Contains("Surface"))
                {
                    Category = "Surface";

                    if (Name.Contains("Pro"))
                    {
                        SubCategory = "Surface Pro";
                    }
                }
                else
                {
                    Category = "PC";

                    Processor = wr.GetContentBetweenStrings(Processor, "I", "z");
                    Processor = Processor.Insert(0, "I");
                    Processor = Processor.Insert(Processor.Length, "z");
                    if (GPU.Contains("AMD") || GPU.Contains("NVIDIA"))
                    {
                        if (!Name.Contains("Desktop"))
                        {
                            SubCategory = "Gaming Laptop";
                        }
                        else
                        {
                            SubCategory = "Gaming Desktop";
                        }
                    }
                    else
                    {
                        if (!Name.Contains("Desktop"))
                        {
                            SubCategory = "Laptop";
                        }
                        else
                        {
                            SubCategory = "Desktop";
                        }
                    }

                    Display = wr.GetContentBetweenStrings(Display, "1", ")");
                    Display = Display.Insert(0, "1");
                    Display = Display.Insert(Display.Length, ")");
                    if (SubCategory == "Desktop")
                    {
                        Display = "";
                    }
                }
            }
            if (Manufacturer == "MAROO" || Manufacturer == "KATE SPADE" || Manufacturer == "Jack Spade" || Manufacturer == "HEX" || Manufacturer == "Tumi" || Manufacturer == "UAG" || Manufacturer == "Brenthaven" ||
                Manufacturer == "Maroo")
            {
                Category = "Case";

                if (Name.Contains("Pro"))
                {
                    SubCategory = "Surface Pro Case";
                }
                if (Name.Contains("Book"))
                {
                    SubCategory = "Surface Book Case";
                }
            }
            if (Name.Contains("Xbox") || Description.Contains("Xbox"))
            {
                Category = "Xbox";

                if (Price == 0)
                {
                    SubCategory = "Xbox Software";
                    Price       = wr.GetRandomNumber(1, 5) * 9.99;
                }
                if (Price > 200)
                {
                    SubCategory = "Xbox Hardware";
                }
                else
                {
                    SubCategory = "Xbox Accessory";
                }
            }
            if (Name.Contains("Fitbit"))
            {
                Category    = "Fitness";
                SubCategory = "Wearable";
            }
            if (Name.Contains("Roku"))
            {
                Category    = "Misc";
                SubCategory = "Streaming Hardware";
            }
            if ((name.Contains("Consumer") || Name.Contains("Commercial")))
            {
                Category = "Warranty";
                if (Name.Contains("Complete"))
                {
                    SubCategory = "Microsoft Complete";
                }
                else
                {
                    SubCategory = "Performance Guard";
                }
            }
            else if (Category == "")
            {
                Category = "Accessory";

                if ((Name.Contains("Surface") || Description.Contains("Surface")))
                {
                    SubCategory = "Surface Accessory";
                }
                if (Name.Contains("Cable"))
                {
                    SubCategory = "Cable";
                }
                else if (Name.Contains("Mouse") || Name.Contains("Keyboard") || Name.Contains("Hard Drive") || Name.Contains("USB") || Name.Contains("Bluetooth") || Name.Contains("Adpater") || Name.Contains("SSD") || Name.Contains("Memory") || Name.Contains("Headset") || Name.Contains("Monitor"))
                {
                    ;
                }
                {
                    SubCategory = "PC Accessory";
                }
            }
            //if (ImageUrl != "")
            //{
            //    try
            //    {
            //        ImageURI = new Uri(ImageUrl);
            //    }
            //    catch (Exception)
            //    {

            //        return;
            //    }

            //}
        }