Esempio n. 1
0
        private void SetStateStatus(ref ServiceObject so)
        {
            Method         meth     = so.Methods[0];
            BingMapsHelper bmHelper = new BingMapsHelper();

            BingResult SearchResult = new BingResult();

            try
            {
                SearchResult = bmHelper.SearchByCoordinates(so.Properties["SearchLatitude"].Value.ToString(), so.Properties["SearchLongitude"].Value.ToString(), NotNull(so.Properties["ConfidenceFilter"].Value), GetConfigPropertyValue("BingMapsKey"));

                so.Properties.InitResultTable();

                for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                {
                    Property prop = so.Properties[meth.ReturnProperties[c]];
                    prop = SetResultListValue(prop, SearchResult);
                }

                so.Properties.BindPropertiesToResultTable();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 2
0
        private void btnLoadJson_Click(object sender, EventArgs e)
        {
            if (true)
            {
                MessageBox.Show("Not yet implemented", "PastebinScraper", MessageBoxButtons.OK,
                                MessageBoxIcon.Asterisk);
                return;
            }

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.CheckFileExists  = true;
            ofd.Title            = "Select JSON Location";
            ofd.Filter           = "JSON Files|*.json|All Files|*.*";
            ofd.DefaultExt       = ".json";
            ofd.FilterIndex      = 0;
            ofd.InitialDirectory = Environment.CurrentDirectory + "/Exports/";
            ofd.RestoreDirectory = true;
            DialogResult dr = ofd.ShowDialog();

            if (dr == DialogResult.OK)
            {
                string p = ofd.FileName;

                object tempObj = JsonConvert.DeserializeObject(File.ReadAllText(p));

                Root tempRoot = (Root)tempObj;

                bingResult = RootToResult(tempRoot);
                DisplayResult();
            }
        }
Esempio n. 3
0
 internal void SetParam(byte v)
 {
     IsLedAlarm  = ((v & 1) == 1);
     IsBeepAlarm = ((v & 2) == 2);
     IsStatMode  = ((v & 4) == 4);
     Result      = (BingResult)((v & 0x18) >> 3);
 }
Esempio n. 4
0
        private void GetEntities(ref ServiceObject so)
        {
            Method         meth     = so.Methods[0];
            BingMapsHelper bmHelper = new BingMapsHelper();

            BingResult SearchResult = new BingResult();

            try
            {
                if (meth.Name.ToLower().Equals("generatemapfromcoordinates"))
                {
                    SearchResult = bmHelper.GenerateCoordinatesImage(so.Properties["SearchLatitude"].Value.ToString(), so.Properties["SearchLongitude"].Value.ToString(), int.Parse(NotNull(so.Properties["ImageZoom"].Value)), NotNull(so.Properties["MapStyle"].Value), int.Parse(NotNull(so.Properties["MapWidth"].Value)), int.Parse(NotNull(so.Properties["MapHeight"].Value)), NotNull(so.Properties["ImageFormat"].Value), NotNull(so.Properties["FileSystemLocation"].Value), GetConfigPropertyValue("BingMapsKey"));
                }
                else
                {
                    SearchResult = bmHelper.GenerateLocationImage(so.Properties["SearchLocation"].Value.ToString(), int.Parse(NotNull(so.Properties["ImageZoom"].Value)), NotNull(so.Properties["MapStyle"].Value), int.Parse(NotNull(so.Properties["MapWidth"].Value)), int.Parse(NotNull(so.Properties["MapHeight"].Value)), NotNull(so.Properties["ImageFormat"].Value), NotNull(so.Properties["FileSystemLocation"].Value), GetConfigPropertyValue("BingMapsKey"));
                }
                so.Properties.InitResultTable();

                for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                {
                    Property prop = so.Properties[meth.ReturnProperties[c]];
                    prop = SetResultListValue(prop, SearchResult);
                }

                so.Properties.BindPropertiesToResultTable();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 5
0
        public async Task GetBingDataAsync(string query)
        {
            try {
                Repository.SearchResults.Clear();
                Repository.RequestDates[query] = DateTime.Now;
                BingApi bing = new BingApi();
                _newsJSON = await bing.BingRequestNews(query);

                JObject        results     = JObject.Parse(_newsJSON);
                IList <JToken> bingResults = results["value"].Children().ToList();
                Repository.SearchResults.Clear();
                foreach (var item in bingResults)
                {
                    BingResult res = item.ToObject <BingResult>();
                    if (res.Image == null)
                    {
                        res.Image = new Image
                        {
                            ThumbNail = new ThumbNail()
                        };
                    }
                    Repository.SearchResults.Add(res);
                }
            }

            catch (Exception) { return; }
        }
        public BingResult BingSearch([FromBody] string searchText)
        {
            var        query      = HttpUtility.UrlEncode(searchText);
            BingResult bingResult = new BingResult();
            var        uri        = $"https://www.bing.com/search?q={query}";

            if (WebRequest.Create(uri) is HttpWebRequest request)
            {
                var response = request.GetResponse();
                using (var responseStream = response.GetResponseStream())
                    using (var streamReader = new StreamReader(responseStream ?? throw new InvalidOperationException(), Encoding.UTF8))
                    {
                        var          responseText            = streamReader.ReadToEnd();
                        string       stringThatKeepsYourHtml = responseText;
                        HtmlDocument doc = new HtmlDocument();
                        doc.LoadHtml(stringThatKeepsYourHtml);

                        var whatUrLookingFor      = doc.GetElementbyId("b_tween");
                        var whatUrLookingForValue = whatUrLookingFor.ChildNodes.FirstOrDefault(x => x.Attributes["class"].Value == "sb_count");
                        var value   = new String(whatUrLookingForValue.InnerHtml.Where(Char.IsDigit).ToArray());
                        var counter = int.Parse(value);
                        bingResult.Counter = counter;
                        return(bingResult);
                    }
            }
            bingResult.Counter = 0;
            return(bingResult);
        }
Esempio n. 7
0
            public ITermSearchService SetupService(HttpStatusCode code, BingResult result)
            {
                var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

                handlerMock
                .Protected()
                .Setup <Task <HttpResponseMessage> >(
                    "SendAsync",
                    ItExpr.IsAny <HttpRequestMessage>(),
                    ItExpr.IsAny <CancellationToken>()
                    )
                .ReturnsAsync(new HttpResponseMessage()
                {
                    Content    = new StringContent(JsonSerializer.Serialize(result)),
                    StatusCode = code,
                });

                var mockedHttpClient = new HttpClient(handlerMock.Object);

                var accessor = new Mock <IHttpClientAccessor>();

                accessor.SetupGet(m => m.Client).Returns(mockedHttpClient);

                var options = Options.Create(new BingConfig {
                    Key = "1234", Url = "http://bing.com/"
                });

                return(new BingTermSearchService(options, accessor.Object));
            }
Esempio n. 8
0
        private void PerformSearch()
        {
            if (string.IsNullOrEmpty(searchTerm))
            {
                MessageBox.Show("Please specify search term.");
                return;
            }

            Scraper scraper;

            if (pageRangeFrom != -1 && pageRangeTo != -1)
            {
                scraper = new Scraper(searchTerm, pageRangeFrom, pageRangeTo);
            }
            else if (startPage != -1)
            {
                scraper = new Scraper(searchTerm, startPage);
            }
            else
            {
                scraper = new Scraper(searchTerm);
            }

            scraper.Search();

            if (saveToJson)
            {
                if (!Directory.Exists(GetDirectoryFromFilename()))
                {
                    Directory.CreateDirectory(GetDirectoryFromFilename());
                }
                if (!File.Exists(jsonFilePath))
                {
                    File.Create(jsonFilePath).Close();
                }
                scraper.SaveToJson(jsonFilePath);
            }

            bingResult = scraper.BingResult;
            DisplayResult();
        }
Esempio n. 9
0
        private BingResult RootToResult(Root root)
        {
            int           rCount, fCount;
            List <Result> rList = new List <Result>();
            string        rUrl;

            rCount = root.SearchResultsCount;
            fCount = root.FetchedResultsCount;
            rUrl   = root.Url;


            foreach (SearchResult sr in root.SearchResults)
            {
                Result tmp = new Result(sr.Name, sr.Url);
                rList.Add(tmp);
            }

            BingResult bRes = new BingResult(rCount, fCount, rList, rUrl);

            return(bRes);
        }
        public BingResult BingSearchWithKey([FromBody] string searchText)
        {
            BingResult bingResult = new BingResult();
            string     accessKey  = "62d6fbbe656b4afba1ced6ff8eee8d7a";
            string     query      = searchText;
            var        uriBase    = "https://api.cognitive.microsoft.com/bing/v7.0/search";

            var uriQuery = uriBase + "?q=" + Uri.EscapeDataString(query);

            // Perform the Web request and get the response
            var request = WebRequest.Create(uriQuery);

            request.Headers["Ocp-Apim-Subscription-Key"] = accessKey;
            var    response = (HttpWebResponse)request.GetResponseAsync().Result;
            string json     = new StreamReader(response.GetResponseStream()).ReadToEnd();

            // Create result object for return
            var searchResult = new SearchResult()
            {
                JsonResult      = json,
                RelevantHeaders = new Dictionary <String, String>()
            };

            // Extract Bing HTTP headers
            //foreach (string header in response.Headers)
            //{
            //    if (header.StartsWith("BingAPIs-") || header.StartsWith("X-MSEdge-"))
            //        searchResult.RelevantHeaders[header] = response.Headers[header];
            //}
            var     jsonResult  = searchResult.JsonResult;
            dynamic dinamycdata = JsonConvert.DeserializeObject <JObject>(jsonResult);
            var     matches     = dinamycdata.webPages.totalEstimatedMatches.Value;

            bingResult.Counter = Convert.ToInt32(matches);
            bingResult.Query   = query;

            return(bingResult);
        }
Esempio n. 11
0
        private Property SetResultListValue(Property prop, BingResult SearchResult)
        {
            switch (prop.Name.ToLower())
            {
            case "locationname":
                prop.Value = SearchResult.LocationName;
                break;

            case "phonenumber":
                prop.Value = SearchResult.PhoneNumber;
                break;

            case "distance":
                prop.Value = SearchResult.Distance;
                break;

            case "addressline":
                prop.Value = SearchResult.AddressLine;
                break;

            case "postcode":
                prop.Value = SearchResult.Postcode;
                break;

            case "formatteaddress":
                prop.Value = SearchResult.FormattedAddress;
                break;

            case "latitude":
                prop.Value = SearchResult.Latitude;
                break;

            case "longitude":
                prop.Value = SearchResult.Longitude;
                break;

            case "imageuri":
                prop.Value = SearchResult.ImageURI;
                break;

            case "imagepath":
                prop.Value = SearchResult.ImagePath;
                break;

            case "imagebase64":
                prop.Value = SearchResult.ImageBase64;
                break;

            case "admindistrict":
                prop.Value = SearchResult.AdminDistrict;
                break;

            case "countryregion":
                prop.Value = SearchResult.CountryRegion;
                break;

            case "locality":
                prop.Value = SearchResult.Locality;
                break;

            case "postaltown":
                prop.Value = SearchResult.PostalTown;
                break;

            case "bestviewnelatitude":
                prop.Value = SearchResult.BestViewNELatitude;
                break;

            case "bestviewnelongitude":
                prop.Value = SearchResult.BestViewNELongitude;
                break;

            case "bestviewswlatitude":
                prop.Value = SearchResult.BestViewSWLatitude;
                break;

            case "bestviewswlongitude":
                prop.Value = SearchResult.BestViewSWLongitude;
                break;

            case "confidence":
                prop.Value = SearchResult.Confidence;
                break;

            case "website":
                prop.Value = SearchResult.WebSite;
                break;

            case "category":
                prop.Value = SearchResult.Category;
                break;
            }
            return(prop);
        }
        private void ChangeOwner(ref ServiceObject so)
        {
            Method meth = so.Methods[0];
            BingMapsHelper bmHelper = new BingMapsHelper();

            BingResult SearchResult = new BingResult();

            try
            {
                SearchResult = bmHelper.SearchByLocation(so.Properties["SearchLocation"].Value.ToString(), NotNull(so.Properties["ConfidenceFilter"].Value), GetConfigPropertyValue("BingMapsKey"));

                so.Properties.InitResultTable();

                for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                {
                    Property prop = so.Properties[meth.ReturnProperties[c]];
                    prop = SetResultListValue(prop, SearchResult);
                }

                so.Properties.BindPropertiesToResultTable();

            }
            catch (Exception ex)
            {
                throw;
            }
        }
 private Property SetResultListValue(Property prop, BingResult SearchResult)
 {
     switch (prop.Name.ToLower())
     {
         case "locationname":
             prop.Value = SearchResult.LocationName;
             break;
         case "phonenumber":
             prop.Value = SearchResult.PhoneNumber;
             break;
         case "distance":
             prop.Value = SearchResult.Distance;
             break;
         case "addressline":
             prop.Value = SearchResult.AddressLine; 
             break;
         case "postcode":
             prop.Value = SearchResult.Postcode;
             break;
         case "formatteaddress":
             prop.Value = SearchResult.FormattedAddress;
             break;
         case "latitude":
             prop.Value = SearchResult.Latitude;
             break;
         case "longitude":
             prop.Value = SearchResult.Longitude;
             break;
         case "imageuri":
             prop.Value = SearchResult.ImageURI;
             break;
         case "imagepath":
             prop.Value = SearchResult.ImagePath;
             break;
         case "imagebase64":
             prop.Value = SearchResult.ImageBase64;
             break;
         case "admindistrict":
             prop.Value = SearchResult.AdminDistrict;
             break;
         case "countryregion":
             prop.Value = SearchResult.CountryRegion;
             break;
         case "locality":
             prop.Value = SearchResult.Locality;
             break;
         case "postaltown":
             prop.Value = SearchResult.PostalTown;
             break;
         case "bestviewnelatitude":
             prop.Value = SearchResult.BestViewNELatitude;
             break;
         case "bestviewnelongitude":
             prop.Value = SearchResult.BestViewNELongitude;
             break;
         case "bestviewswlatitude":
             prop.Value = SearchResult.BestViewSWLatitude;
             break;
         case "bestviewswlongitude":
             prop.Value = SearchResult.BestViewSWLongitude;
             break;
         case "confidence":
             prop.Value = SearchResult.Confidence;
             break;
         case "website":
             prop.Value = SearchResult.WebSite;
             break;
         case "category":
             prop.Value = SearchResult.Category;
             break;
     }
     return prop;
 }
        private void GetEntities(ref ServiceObject so)
        {
            Method meth = so.Methods[0];
            BingMapsHelper bmHelper = new BingMapsHelper();

            BingResult SearchResult = new BingResult();

            try
            {

                if (meth.Name.ToLower().Equals("generatemapfromcoordinates"))
                {
                    SearchResult = bmHelper.GenerateCoordinatesImage(so.Properties["SearchLatitude"].Value.ToString(), so.Properties["SearchLongitude"].Value.ToString(), int.Parse(NotNull(so.Properties["ImageZoom"].Value)), NotNull(so.Properties["MapStyle"].Value), int.Parse(NotNull(so.Properties["MapWidth"].Value)), int.Parse(NotNull(so.Properties["MapHeight"].Value)), NotNull(so.Properties["ImageFormat"].Value), NotNull(so.Properties["FileSystemLocation"].Value), GetConfigPropertyValue("BingMapsKey"));
                }
                else
                {
                    SearchResult = bmHelper.GenerateLocationImage(so.Properties["SearchLocation"].Value.ToString(), int.Parse(NotNull(so.Properties["ImageZoom"].Value)), NotNull(so.Properties["MapStyle"].Value), int.Parse(NotNull(so.Properties["MapWidth"].Value)), int.Parse(NotNull(so.Properties["MapHeight"].Value)), NotNull(so.Properties["ImageFormat"].Value), NotNull(so.Properties["FileSystemLocation"].Value), GetConfigPropertyValue("BingMapsKey"));
                }
                so.Properties.InitResultTable();

                for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                {
                    Property prop = so.Properties[meth.ReturnProperties[c]];
                    prop = SetResultListValue(prop, SearchResult);
                }

                so.Properties.BindPropertiesToResultTable();

            }
            catch (Exception ex)
            {
                throw;
            }
        }