예제 #1
0
        private SerpModuleRequestStats FindRequestPosition(SerpModuleRequest request, IRuntimeModule <string, List <SerpWebPage> > dataProvider, string targetPage)
        {
            var requestStats = new SerpModuleRequestStats();

            Context.LogInform(Context.Localizer[$"Analysis position of '{request.Text}' request..."]);

            var result = RuntimeTask.Run(this.Context, dataProvider, request.Text);

            if (result.IsSuccessfully)
            {
                var target = result.Data.Where(page => page.Url.Contains(targetPage.ToLower())).SingleOrDefault();
                if (target != null)
                {
                    requestStats.Request       = request;
                    requestStats.Position      = target.Position;
                    requestStats.DetectionTime = DateTime.Now;

                    Context.LogInform(Context.Localizer[$"Request '{request.Text}' found. Position : {target.Position}"]);
                }
                else
                {
                    Context.LogInform(Context.Localizer[$"Request '{request.Text}' not found"]);
                }

                Context.LogInform(Context.Localizer[$"Analysis position of '{request.Text}' request was completed"]);
            }

            throw new UserException(this.Context.Localizer[RuntimeTask.RuntimeException, dataProvider.Name]);
        }
예제 #2
0
        private List <SerpModuleRequestStats> Analyze()
        {
            List <SerpModuleRequestStats> stats = new List <SerpModuleRequestStats>();

            if (Configuration.DataProvider == null)
            {
                throw new UserException("Data provider not specified");
            }
            var registry = this.Context.Provider.GetService <IProjectModuleRegistry>();

            var module = registry.OpenModule(Context, Configuration.DataProvider.Code, Configuration.DataProvider.Id);

            var dataProvider = module as IRuntimeModule <string, List <SerpWebPage> >;

            if (dataProvider == null)
            {
                throw new UserException("Data provider is incorrected");
            }

            foreach (var request in Configuration.Requests)
            {
                var iteration = 0;

                SerpModuleRequestStats requestResult = null;

                do
                {
                    iteration++;
                    if (iteration > 1)
                    {
                        Context.LogInform(Context.Localizer[$"The attemp {iteration} to get position of '{request.Text}'"]);
                    }

                    try
                    {
                        requestResult = FindRequestPosition(request, dataProvider, Configuration.Url);
                    }
                    catch (UserException exc)
                    {
                    }
                } while (iteration <= Configuration.RequestAttempt);


                stats.Add(requestResult ?? new SerpModuleRequestStats()
                {
                    Position = -1, DetectionTime = DateTime.Now, Request = request, Details = Context.Localizer[$"An error occured during getting of position the request. See log"]
                });
            }

            return(stats);
        }