Beispiel #1
0
        public async Task <ActionResult> Search([FromQuery] SearchRequestParams requestToSearch)
        {
            var currentUserName = User.GetUserName();
            var user            = _uof.Users.GetByUsername(currentUserName);
            var userToWorkWith  = _mapper.Map <MemberDTO>(user);

            try
            {
                var crawledUrl = _crawlerService.Crawl(requestToSearch, userToWorkWith);
                if (requestToSearch.IsNeedToSave)
                {
                    user.InterestedUrls.Add(crawledUrl.Result);//TODO: optional saving url!
                    await _uof.Users.SaveAll();

                    crawledUrl.Result.InterestedUsers.Add(user);//TODO: optional saving url!
                    await _uof.Urls.SaveAll();
                }
                return(Ok());
                // return RedirectToActionPermanent(actionName: "GetCars", controllerName: "Cars", new { ExactUrl = crawledUrl.UrlToScrape });
            }
            catch (System.Exception)
            {
                throw;
            }
        }
        public async Task CrawlCars(SearchRequestParams requestToSearch)
        {
            var currentUserName = Context.User.GetUserName();
            var user            = _uof.Users.GetByUsername(currentUserName);
            var userToWorkWith  = _mapper.Map <MemberDTO>(user);

            try
            {
                await Clients.Caller.SendAsync("ReceiveCrawledCars", new List <CarDto>());

                var crawledUrl = await _crawlerService.Crawl(requestToSearch, userToWorkWith);

                if (requestToSearch.IsNeedToSave)
                {
                    user.InterestedUrls.Add(crawledUrl);//TODO: optional saving url!
                    await _uof.Users.SaveAll();

                    crawledUrl.InterestedUsers.Add(user);//TODO: optional saving url!
                    await _uof.Urls.SaveAll();
                }
                // await Clients.Caller.re("Crawled", )
                // return RedirectToActionPermanent(actionName: "GetCars", controllerName: "Cars", new { ExactUrl = crawledUrl.UrlToScrape });
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Beispiel #3
0
        public void SearchRequestWithAttendeesTest()
        {
            var sdate           = new DateTime(2017, 4, 7, 08, 0, 0);
            var edate           = new DateTime(2017, 4, 7, 18, 0, 0);
            var searchReqParams = new SearchRequestParams();

            searchReqParams.LocalEnd   = edate;
            searchReqParams.LocalStart = sdate;
            ZmailRequest.ApiRequest    = new SearchRequest(searchReqParams);
            var zResquest = ZmailDispatcher.SendRequest(ZmailRequest);

            //取出會議室的資訊
            var searchRes = zResquest.ApiResponse as SearchResponse;
            var appts     = searchRes?.Appointments;

            if (appts != null)
            {
                foreach (var appt in appts.OrderBy(a => a.StartTime))
                {
                    Console.WriteLine($"{appt.Name}:Start:{appt.StartTime}, 組織者:{appt.Organizer.DisplayName}, {appt.Organizer.Email}");
                    Console.WriteLine("與會人員 *** ");
                    ZmailRequest.ApiRequest = new GetMsgRequest(appt.InviteMessageId);
                    var msgRequest = ZmailDispatcher.SendRequest(ZmailRequest);
                    var msgResp    = msgRequest.ApiResponse as GetMsgResponse;
                    var attendees  = msgResp?.Attendees;
                    if (attendees != null)
                    {
                        foreach (var attendee in attendees)
                        {
                            Console.WriteLine($"  {attendee.DisplayName}, {attendee.Email}, {attendee.UserType}");
                        }
                    }
                }
            }
        }
        public void TestSpecialCaratersArrayJustOne()
        {
            //Arange
            var searchRequestParam = new SearchRequestParams();

            //for (int i = 32; i <= 165; i++)
            for (int i = 1; i <= 255; i++)
            {
                var text = ((char)i).ToString();
                searchRequestParam.SearchText = text;
                var geosearchService = new GeosearchService();
                try
                {
                    //Act;
                    var geoSearchAddressData = geosearchService.Request(searchRequestParam);
                    //Asset
                    var message = geoSearchAddressData.message;
                    if (message != "OK")
                    {
                        Console.WriteLine(string.Format("\"{0}\"={1}", (char)i, message));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(string.Format("\"{0}\"={1}", (char)i, e.Message));
                }
            }
        }
Beispiel #5
0
        private string RstUrlBuilder(SearchRequestParams requestToSearch)
        {
            string url = String.Empty;

            var model = _uof.Models.GetModelByName(requestToSearch.Model);
            var brand = model.CarBrand;

            url = $"https://rst.ua/ukr/oldcars/{brand.RstName}/{model.RstName}/";
            return(url);
        }
Beispiel #6
0
        private string RiaUrlBuilder(SearchRequestParams requestToSearch)
        {
            string url = String.Empty;

            var model = _uof.Models.GetModelByName(requestToSearch.Model);
            var brand = model.CarBrand;

            url = $"https://auto.ria.com/uk/legkovie/{brand.RiaName}/{model.RiaName}/";
            return(url);
        }
Beispiel #7
0
        public async Task <Url> Crawl(SearchRequestParams requestToSearch, MemberDTO user)
        {
            var userToWorkWith = _mapper.Map <User>(user);
            var url            = _uof.Urls.GetByLinkName($"{requestToSearch.Brand.ToLower()}/{requestToSearch.Model.ToLower()}");

            if (url == null)
            {
                url = new Url
                {
                    UrlToScrape     = $"{requestToSearch.Brand.ToLower()}/{requestToSearch.Model.ToLower()}",
                    InterestedUsers = new List <User>()
                };

                // url.InterestedUsers = new List<User> { userToWorkWith };

                await _uof.Urls.CreateAsync(url);

                if (!await _uof.Urls.SaveAll())
                {
                    throw new Exception("there are a problem with creating new url when crawl");
                }
            }
            // else
            // {
            //     if (!user.InterestedUrls.Any(x => x.UrlToScrape.ToLower() == url.UrlToScrape.ToLower()))
            //     {
            //         // url.InterestedUsers.Add(userToWorkWith);
            //         // await _uof.Urls.Update(url.Id, url);
            //         // if (!await _uof.Urls.SaveAll())
            //         //     throw new Exception("there are a problem with updating new url when crawl");
            //     }
            // }
            // try
            // {
            //     if (requestToSearch.IsNeedToSave)
            //     {
            //         userToWorkWith.InterestedUrls.Add(url);//TODO: optional saving url!
            //         url.InterestedUsers.Add(userToWorkWith);//TODO: optional saving url!
            //         // await _uof.Users.SaveAll();
            //     }
            // }
            // catch (System.Exception)
            // {
            //     throw;
            // }

            await RiaCrawl(requestToSearch, url);
            await RstCrawl(requestToSearch, url);

            // await _uof.Urls.SaveAll();
            return(url);
        }
Beispiel #8
0
        private async Task RstCrawl(SearchRequestParams requestToSearch, Url url)
        {
            var crawlerRST = new WheelsCrawler <CarSearchRstDto, Car>()
                             .AddRequest(new WheelsCrawlerRequest {
                Url = RstUrlBuilder(requestToSearch), Regex = @".*/oldcars/.+/[0-9]+\.html$", TimeOut = 5000
            })
                             .AddDownloader(new WheelsCrawlerDownloader {
                DownloderType = WheelsCrawlerDownloaderType.FromFile, DownloadPath = @"C:/Users/PC/source/repos/WheelsCrawler/htmls/RST/"
            })
                             .AddProcessor(new WheelsCrawlerProcessor <CarSearchRstDto, Car>(_uof.Cars)
            {
            })
                             .AddPipeline(new WheelsCrawlerPipeline <Car>(_uof.Cars)
            {
                Url = url
            });

            await crawlerRST.Crawle();
        }
Beispiel #9
0
        private async Task RiaCrawl(SearchRequestParams requestToSearch, Url url)
        {
            var crawlerRia = new WheelsCrawler <CarSearchRiaDto, Car>()
                             .AddRequest(new WheelsCrawlerRequest {
                Url = RiaUrlBuilder(requestToSearch), Regex = @"\?page=[0-9]+$", TimeOut = 5000
            })
                             .AddDownloader(new WheelsCrawlerDownloader {
                DownloderType = WheelsCrawlerDownloaderType.FromFile, DownloadPath = "C:/Users/PC/source/repos/WheelsCrawler/htmls/RIA/"
            })
                             .AddProcessor(new WheelsCrawlerProcessor <CarSearchRiaDto, Car>(_uof.Cars)
            {
            })
                             .AddPipeline(new WheelsCrawlerPipeline <Car>(_uof.Cars)
            {
                Url = url
            });

            await crawlerRia.Crawle();
        }
Beispiel #10
0
        public async Task GetCars(SearchRequestParams requestToSearch)
        {
            var httpContext = Context.GetHttpContext();
            // var url = httpContext.Request.Query["url"].ToString();
            // var groupName = GetGroupName(Context.User.GetUserName(), url);

            // await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
            // var client = Clients.Client(Context.ConnectionId);
            // var userParams = new UserParams { ExactUrl = $"{url}" };
            var userParams = requestToSearch;
            var cars       = await _carService.GetCars(userParams, Context.User.GetUserName());

            var pagedCars = await PagedList <Car> .CreateAsync(cars, userParams.PageNumber, userParams.PageSize);

            var carsToReturn = _mapper.Map <IEnumerable <CarDto> >(pagedCars);
            // httpContext.Response.AddPaginationHeader(pagedCars.CurrentPage, pagedCars.PageSize, pagedCars.TotalCount, pagedCars.TotalPages);
            // Response.AddPaginationHeader(pagedCars.CurrentPage, pagedCars.PageSize, pagedCars.TotalCount, pagedCars.TotalPages);

            await Clients.Caller.SendAsync("ReceiveCrawledCars", carsToReturn);
        }
Beispiel #11
0
        public GeoSearchAddressData Request(SearchRequestParams searchRequestParams)
        {
            try
            {
                Regex pattern    = new Regex("([\\\\#/])|(^[/&/./;])");
                var   searchText = searchRequestParams.SearchText;
                //Uri.EscapeDataString(searchRequestParams.SearchText.Replace('/', '_').Replace('\\', '_').Replace('\0', '_').Replace('.', '_').Replace(';', '_'));
                searchText = pattern.Replace(searchText, "_");
                //TODO move resource to file
                var url =
                    string.Format(
                        Interface.Properties.Settings.Default.Url,
                        searchText, searchRequestParams.Resources, searchRequestParams.ReturnLimit,
                        searchRequestParams.LoginName, searchRequestParams.Password,
                        searchRequestParams.EPSGCode);

                var webClient = new WebClient {
                    Encoding = Encoding.UTF8
                };

                System.Diagnostics.Debug.WriteLine("Url: " + url);

                var jsonContent = webClient.DownloadString(url);
                if (jsonContent.Equals("No workhorse available\r\nAll workhorses, including quarantined, are exhausted.\r\n"))
                {
                    throw new PlaceFinderException("Kan ikke søge på: '" + searchRequestParams.SearchText + "'");
                }
                var serializer = new DataContractJsonSerializer(typeof(GeoSearchAddressData));

                GeoSearchAddressData response;
                using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonContent)))
                {
                    response = (GeoSearchAddressData)serializer.ReadObject(ms);
                }
                return(response);
            }
            catch (WebException e)
            {
                throw new PlaceFinderException("Ikke muligt at få kontakt med Geosearch service", e);
            }
        }
Beispiel #12
0
        private List <GeoSearchAddress> GetAddressData(string inputParamSearch)
        {
            var retValue = new List <GeoSearchAddress>();

            if (!String.IsNullOrEmpty(inputParamSearch))
            {
                var searchRequestParams = new SearchRequestParams
                {
                    SearchText = inputParamSearch,
                    Resources  = searchRequestResources.GetResourceString
                };
                var response = _factory.GeosearchService.Request(searchRequestParams);

                if (response != null && response.data != null)
                {
                    return(response.data);
                }
            }

            return(retValue);
        }
Beispiel #13
0
        public void SearchOtherShareAppointmentsRequestTest()
        {
            //先取得他人的 Mountpoint
            var searchEmail         = "*****@*****.**";
            var getShareInfoRequest = new GetShareInfoRequest(searchEmail);

            ZmailRequest.ApiRequest = getShareInfoRequest;
            var zResquest = ZmailDispatcher.SendRequest(ZmailRequest);
            var resp      = zResquest.ApiResponse as GetShareInfoResponse;
            var mid       = resp.MountpointId;

            if (!string.IsNullOrWhiteSpace(mid))
            {
                var sdate           = new DateTime(2017, 5, 25, 08, 0, 0);
                var edate           = new DateTime(2017, 5, 25, 18, 0, 0);
                var searchReqParams = new SearchRequestParams(sdate, edate);
                //FolderId 10 預設是自已的行事曆
                searchReqParams.FolderId = mid;
                ZmailRequest.ApiRequest  = new SearchRequest(searchReqParams);
                zResquest = ZmailDispatcher.SendRequest(ZmailRequest);

                //取出會議室的資訊
                var searchRes = zResquest.ApiResponse as SearchResponse;
                var appts     = searchRes?.Appointments;
                if (appts != null)
                {
                    foreach (var appt in appts.OrderBy(a => a.StartTime))
                    {
                        //註:組織者有可能為 null
                        Console.WriteLine(
                            $"{appt.Name}:Start:{appt.StartTime}, 組織者:{appt.Organizer?.DisplayName}, {appt.Organizer?.Email}");
                    }
                }
            }
            else
            {
                Console.WriteLine($"尚未Mount {searchEmail} 行事曆");
            }
        }
Beispiel #14
0
        public GeoSearchAddressData Request(SearchRequestParams searchRequestParams)
        {
            try
            {
                Regex pattern    = new Regex("([\\\\#/])|(^[/&/./;])");
                var   searchText = searchRequestParams.SearchText;
                //Uri.EscapeDataString(searchRequestParams.SearchText.Replace('/', '_').Replace('\\', '_').Replace('\0', '_').Replace('.', '_').Replace(';', '_'));
                searchText = pattern.Replace(searchText, "_");
                //TODO move resource to file
                var url =
                    string.Format(
                        "https://kortforsyningen.kms.dk/Geosearch?type=json&search={0}&resources={1}&limit={2}&login={3}&password={4}&crs={5}",
                        searchText, searchRequestParams.Resources, searchRequestParams.ReturnLimit,
                        searchRequestParams.LoginName, searchRequestParams.Password,
                        searchRequestParams.EPSGCode);

                var webClient = new WebClient {
                    Encoding = Encoding.UTF8
                };
                var jsonContent = webClient.DownloadString(url);
                if (jsonContent.Equals("No workhorse available\r\nAll workhorses, including quarantined, are exhausted.\r\n"))
                {
                    throw new PlaceFinderException("Kan ikke søge på: '" + searchRequestParams.SearchText + "'");
                }
                var serializer = new DataContractJsonSerializer(typeof(GeoSearchAddressData));

                GeoSearchAddressData response;
                using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonContent)))
                {
                    response = (GeoSearchAddressData)serializer.ReadObject(ms);
                }
                return(response);
            }
            catch (WebException e)
            {
                throw new PlaceFinderException("Ikke muligt at få kontakt med Geosearch service", e);
            }
        }
Beispiel #15
0
        public void SearchRequestTest()
        {
            var sdate           = new DateTime(2017, 5, 25, 08, 0, 0);
            var edate           = new DateTime(2017, 5, 25, 18, 0, 0);
            var searchReqParams = new SearchRequestParams(sdate, edate);

            //FolderId 10 預設是自已的行事曆
            //searchReqParams.FolderId = "12654"; //501
            ZmailRequest.ApiRequest = new SearchRequest(searchReqParams);
            var zResquest = ZmailDispatcher.SendRequest(ZmailRequest);

            //取出會議室的資訊
            var searchRes = zResquest.ApiResponse as SearchResponse;
            var appts     = searchRes?.Appointments;

            if (appts != null)
            {
                foreach (var appt in appts.OrderBy(a => a.StartTime))
                {
                    Console.WriteLine($"{appt.Name}:Start:{appt.StartTime}, 組織者:{appt.Organizer?.DisplayName}, {appt.Organizer?.Email}");
                }
            }
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            //設定連接的Server
            InitDispatcher();

            //透過使用者帳密,取回Token
            var userId = "*****@*****.**";
            var pwd    = "your pwd";

            GetToken(userId, pwd);

            //_ZmailRequest.ApiRequest = new GetFolderRequest();
            //var zResquest = _ZmailDispatcher.SendRequest(_ZmailRequest);

            //get workinghours
            //var start = new DateTime(2017, 3, 28);
            //var end = new DateTime(2017, 3, 29);
            //var searchNames = "[email protected],[email protected]";
            //_ZmailRequest.ApiRequest = new GetWorkingHoursRequest(start, end, searchNames);
            //var zResquest = _ZmailDispatcher.SendRequest(_ZmailRequest);


            //get Free or Busy
            //var start = new DateTime(2017, 3, 28, 8, 0, 0);
            //var end = new DateTime(2017, 3, 29, 20, 0, 0);
            //var searchNames = "*****@*****.**";
            //_ZmailRequest.ApiRequest = new GetFreeBusyRequest(start, end, searchNames);
            //var zResquest = _ZmailDispatcher.SendRequest(_ZmailRequest);



            //取得會議室
            //var searchMeetingRooms = new SearchCalendarResourcesRequest("email,fullName");
            //searchMeetingRooms.ProcToXmlDocument = (conditionFilters) =>
            //{
            //    var condE = conditionFilters.OwnerDocument.CreateElement(AccountService.E_COND, AccountService.NAMESPACE_URI);
            //    condE.SetAttribute(AccountService.A_ATTR, AccountService.V_ATTR_TYPE);
            //    condE.SetAttribute(AccountService.A_OP, AccountService.A_OP_TYPE_EQ);
            //    condE.SetAttribute(AccountService.A_VALUE, AccountService.V_LOCATION);
            //    conditionFilters.AppendChild(condE);
            //};
            //_ZmailRequest.ApiRequest = searchMeetingRooms;
            //var zResquest = _ZmailDispatcher.SendRequest(_ZmailRequest);


            //訂會議
            //var app = new AppointmentRequestParams();
            //app.Subject = "到 一銀  Support";
            ////app.Body = @"這是Body
            ////行一
            ////行2
            ////行3
            ////            ";
            //app.StartDate = new DateTime(2017, 4, 7, 15, 30, 0);
            //app.EndDate = new DateTime(2017, 4, 7, 16, 30, 0);
            //app.Organizer = new Attendee { Email = "*****@*****.**", DisplayName = "Rainmaker Ho" };
            //app.Locations = new List<Attendee>()
            //{
            //    //new Attendee {Email ="*****@*****.**", DisplayName =  "協志會議室-舞蝶館"},
            //    //new Attendee {Email ="*****@*****.**", DisplayName =  "協志會議室-天空農場"},
            //};
            //app.Attendees = new List<Attendee>()
            //            {
            //               // new Attendee {Email = "*****@*****.**", DisplayName = "Alice Lai"}
            //            };

            //_ZmailRequest.ApiRequest = new CreateAppointmentRequest(app);
            //var zResquestx = _ZmailDispatcher.SendRequest(_ZmailRequest);


            //取得會議室的資訊
            var sdate           = new DateTime(2017, 4, 7, 08, 0, 0);
            var edate           = new DateTime(2017, 4, 7, 18, 0, 0);
            var searchReqParams = new SearchRequestParams();

            searchReqParams.LocalEnd   = edate;
            searchReqParams.LocalStart = sdate;
            _ZmailRequest.ApiRequest   = new SearchRequest(searchReqParams);
            var zResquest = _ZmailDispatcher.SendRequest(_ZmailRequest);

            //取出會議室的資訊
            var searchRes = zResquest.ApiResponse as SearchResponse;
            var appts     = searchRes.Appointments;

            foreach (var appt in appts)
            {
                Console.WriteLine($"{appt.Name}, OR:{appt.Organizer.DisplayName}, {appt.Organizer.Email}");
                _ZmailRequest.ApiRequest = new GetMsgRequest(appt.InviteMessageId);
                var msgRequest = _ZmailDispatcher.SendRequest(_ZmailRequest);
                var msgResp    = msgRequest.ApiResponse as GetMsgResponse;
                var attendees  = msgResp?.Attendees;
                if (attendees != null)
                {
                    foreach (var attendee in attendees)
                    {
                        Console.WriteLine($"  {attendee.DisplayName}, {attendee.Email}, {attendee.UserType}");
                    }
                }
            }
        }