private ScrapingResult ScrapingTaskOperation(SearchCriteria sc, int pageNo, LIScraper scraper)
        {
            bool           morerecords = false;
            ScrapingResult res         = new ScrapingResult();

            res.UserProfiles        = scraper.StartUserProfilesScraping(sc, pageNo, out morerecords);
            res.AreThereMoreRecords = morerecords;

            //var res = new ScrapingResult();
            //res.AreThereMoreRecords = false;
            //res.UserProfiles = new List<LIUserData>() { new LIUserData() { ConnectionDegree = "2nd", CurrentWorkingTitle = "jobee", ProfileTitle = "imran" } };
            //Thread.Sleep(10000);


            return(res);
        }
        private void btnDirectMessageRequest_Click(object sender, EventArgs e)
        {
            try
            {
                if (liImportUserProfiles == null || liImportUserProfiles.Count <= 0)
                {
                    MessageBox.Show("No User Profiles found  for this action", "No Profiles", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                var selectedUserProfiles = liImportUserProfiles.Where(s => s.IsSelected).ToList();

                if (selectedUserProfiles == null || selectedUserProfiles.Count <= 0)
                {
                    MessageBox.Show("No User Profiles Selected for this action", "No Profiles", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                busyTab = 2;

                ShowBusyForm_Tab2(true);
                var data = Mapper.Map <List <LIUserData>, List <LIUserDirectMessageReport> >(selectedUserProfiles);


                settings = SraperSettingsManager.GetSettings();
                var scraper = new LIScraper(settings);

                var done = scraper.StartDirectMessageFlow(data);

                scraper.ShutdownScraper();
                busyTab = 0;
                ShowBusyForm_Tab2(false);


                UpdateStatus("Generating Report File");
                string f = CSVFileManager.WriteDirectMessageReport(settings.DirMsgReportPath, data);

                MessageBox.Show($"Successfully Sent Direct Messages to selected UserProfiles. A report has also been generated {f} ", "Direct Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error Creating Direct Message Schedule Data File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                busyTab = 0;
                ShowBusyForm_Tab2(false);
            }
        }
示例#3
0
        private void CloseScraper()
        {
            try
            {
                if (connScraper != null)
                {
                    connScraper.ShutdownScraper();
                }

                connScraper    = null;
                settings       = null;
                searchCriteria = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Scraper Shutdown Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#4
0
        private async void btnSearchLinkedIn_Click(object sender, EventArgs e)
        {
            try
            {
                busyTab = 1;

                settings = SraperSettingsManager.GetSettings();

                if (string.IsNullOrWhiteSpace(settings.LIUserName) || string.IsNullOrWhiteSpace(settings.LIPassword))
                {
                    throw new Exception("LinkedIn UserName or Password cannot be blank");
                }

                searchCriteria         = new SearchCriteria();
                searchCriteria.Keyword = this.txtKeyword.Text;
                searchCriteria.City    = this.txtCity.Text;
                searchCriteria.State   = this.cmbState.Text;
                searchCriteria.Company = this.txtCompany.Text;

                this.dgvLinkedInResult.Rows.Clear();
                this.rtbConnectLog.Clear();

                liUserProfiles = new List <LIUserData>();
                dgvLinkedInScrapingResultSource            = new BindingSource();
                dgvLinkedInScrapingResultSource.DataSource = liUserProfiles;
                dgvLinkedInResult.DataSource = dgvLinkedInScrapingResultSource;

                this.grpConnectNow.Enabled      = false;
                this.grpConnectSchedule.Enabled = false;

                connScraper = new LIScraper(settings);
                pageNo      = 1;

                ScrapeLinkedIn(connScraper, searchCriteria, pageNo);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Scraping Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                busyTab = 0;
            }
        }
示例#5
0
        private async void ScrapeLinkedIn(LIScraper scraper, SearchCriteria searchCriteria, int pageNo)
        {
            try
            {
                isScrapingNow = true;
                //  this.dgvLinkedInResult.Columns.Clear();
                busyTab = 1;

                ShowBusyForm_Tab1(true);
                ScraperRunner runner = new ScraperRunner();

                var result = await runner.StartScraping(searchCriteria, pageNo, scraper);

                ShowBusyForm_Tab1(false);


                this.grpSearch.Enabled       = false;
                this.btnDoneScraping.Enabled = true;

                this.btnLoadMore.Enabled = result.AreThereMoreRecords;
                this.btnLoadMore.Enabled = result.AreThereMoreRecords;

                liUserProfiles.AddRange(result.UserProfiles);
                dgvLinkedInScrapingResultSource.ResetBindings(false);


                isScrapingNow = false;
                MessageBox.Show("LinkedIn Scraping Result", "Scraping Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                busyTab = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Scraping Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ShowBusyForm_Tab1(false);
                busyTab = 0;
            }
        }
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Console()
                         .WriteTo.File("logs\\LIConnectScheduleAppLogs.txt", rollingInterval: RollingInterval.Day)
                         .CreateLogger();


            Logger.DebugMessaged += Logger_DebugMessaged;
            Logger.ErrorMessaged += Logger_ErrorMessaged;

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <LIUserData, LIUserConnectRequestReport>().ReverseMap();
                cfg.CreateMap <LIUserData, LIUserDirectMessageReport>().ReverseMap();
            });

            Log.Debug("Readig Command line arguments...");
            int argNumber = 0;

            try
            {
                if (args.Length > 0)
                {
                    //argNumber = 1;//
                    argNumber = Convert.ToInt32(args[0]);
                    Log.Debug($"Command is {argNumber}");
                    string err = "";

                    switch (argNumber)
                    {
                    case 1:
                    {
                        Log.Debug("Performing Connection Request Workflow...");
                        var data = CSVFileManager.ReadConnectionRequestSchedulerData(out err);
                        if (data.Count > 0)
                        {
                            var settings = SraperSettingsManager.GetSettings();
                            var scraper  = new LIScraper(settings);

                            var done = scraper.StartConnectRequestFlow(data);
                            scraper.ShutdownScraper();

                            Log.Debug("Generating Report File");
                            string f = CSVFileManager.WriteConnectionRequestReport(settings.ConnReportPath, data);
                            Log.Debug($"Report File Generated {f}");
                        }
                        else
                        {
                            Log.Debug("No Connection Request Scheduling data...");
                            if (!string.IsNullOrWhiteSpace(err))
                            {
                                Log.Error(err);
                            }
                        }
                    }
                    break;

                    case 2:
                    {
                        Log.Debug("Performing Direct Message Workflow...");
                        var data = CSVFileManager.ReadDirectMessageSchedulerData(out err);
                        if (data.Count > 0)
                        {
                            var settings = SraperSettingsManager.GetSettings();
                            var scraper  = new LIScraper(settings);

                            var done = scraper.StartDirectMessageFlow(data);
                            scraper.ShutdownScraper();


                            Log.Debug("Generating Report File");
                            string f = CSVFileManager.WriteDirectMessageReport(settings.DirMsgReportPath, data);
                            Log.Debug($"Report File Generated {f}");
                        }
                        else
                        {
                            Log.Debug("No Direct Message Scheduling data...");
                            if (!string.IsNullOrWhiteSpace(err))
                            {
                                Log.Error(err);
                            }
                        }
                    }
                    break;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, $"Error while running scheduler Task - {argNumber}");
            }


            Log.Debug("All Done , Exiting...");

            return;

            //TestLinkedinScraping();
        }
 private Task <ScrapingResult> StartScraingTask(SearchCriteria sc, int pageNo, LIScraper scraper)
 {
     return(Task.Run <ScrapingResult>(() => ScrapingTaskOperation(sc, pageNo, scraper)));
 }
        public async Task <ScrapingResult> StartScraping(SearchCriteria sc, int pageNo, LIScraper scraper)
        {
            ScrapingResult result = await StartScraingTask(sc, pageNo, scraper);

            return(result);
        }