예제 #1
0
        static void TestInstanceStatistics()
        {
            var avito = new Avito();
            var task  = new TaskInstanceStatisticsCache
            {
                InstanceId = new Guid("8BB27650-462E-497E-B9A5-044AA1C66FAD"),
                Url        = "https://www.avito.ru/podolsk/telefony/iphone_6s_64gb_seryy_kosmos_1259355638",
            };

            FirefoxHelper.ExecuteWithVisual(browser =>
            {
                browser.Navigate().GoToUrl("https://www.avito.ru/moskva/bytovaya_elektronika");
                var stat = avito.GetInstanceStatistics(browser, task);
                if (stat != null)
                {
                    var instance   = BulletinInstanceHelper.Get(task.InstanceId);
                    instance.Views = stat.Value;
                    BulletinInstanceHelper.Save(instance);
                }
            }, null, 100);
        }
예제 #2
0
        public void Execute(TaskCache task)
        {
            DCT.Execute(c =>
            {
                ConsoleHelper.SendMessage($"Task {UID}.{task.Command} started");
                switch (task.Command)
                {
                    case "CollectMessages":
                        executeCommand<TaskMessageCollectorCache>(task, (a, b) =>
                        {
                            var messages = CollectMessages(a, b);
                            if (messages.Any())
                            {
                                var access = AccessHelper.GetAccess(b.AccessId);
                                access.LastMessage = messages.Max(q => q.PublicationDate);
                                AccessHelper.Save(access);
                                MessageServiceHelper.Save(messages);
                            }
                        }, true, true);
                        break;
                    case "Registration":
                        registration(task);
                        break;
                    case "AccessCheck":
                        checkAccess(task);
                        break;
                    case "ActivateAccess":
                        executeCommand<TaskAccessCheckCache>(task, ActivateBulletins, false);
                        break;
                    case "ActivateInstance":
                        executeCommand<TaskInstanceActivationCache>(task, (a, b) => 
                        {
                            if(b.Url == null)
                            {
                                ConsoleHelper.SendMessage("ActivateInstance => URL is Empty");
                                return;
                            }
                            ActivateBulletin(a, b);
                            var instance = BulletinInstanceHelper.Get(b.InstanceId);
                            instance.ActivationDate = DateTime.Now;
                            BulletinInstanceHelper.Save(instance);
                        }, hasProxy: true, withImage: true);
                        break;
                    case "InstancePublication":
                        executeCommand<TaskInstancePublicationCache>(task, (a, b) =>
                        {
                            var url = InstancePublication(a, b);
                            if (!string.IsNullOrWhiteSpace(url))
                            {
                                var instance = BulletinInstanceHelper.Get(b.InstanceId);
                                instance.Url = url;
                                BulletinInstanceHelper.Save(instance);
                            }
#if RELEASE
                        }, hasProxy: true, withImage: true);
#endif
#if DEBUG_REMOTE || DEBUG

                        }, hasProxy: true, withImage: true);
#endif

                        break;