コード例 #1
0
ファイル: JobService.cs プロジェクト: DoctorSoft/fbkBot
        public void AddOrUpdateAccountJobs(IAddOrUpdateAccountJobs model)
        {
            var currentModel = model as AddOrUpdateAccountModel;

            if (currentModel == null)
            {
                return;
            }

            var accountViewModel = currentModel.Account;
            var runModel         = new RunJobModel
            {
                Account = accountViewModel
            };

            RecurringJob.AddOrUpdate(string.Format(CheckFriendsConditionsToRemovePattern, accountViewModel.Login), () => CheckFriendsAtTheEndTimeConditionsJob.Run(runModel), "*/30 * * * *");
            RecurringJob.AddOrUpdate(string.Format(RefreshCookiesPattern, accountViewModel.Login), () => RefreshCookiesJob.Run(runModel), Cron.Daily);

            /*RecurringJob.AddOrUpdate(string.Format(InviteTheNewGroupPattern, accountViewModel.Login), () => InviteTheNewGroupJob.Run(accountViewModel), Cron.Hourly);
             * RecurringJob.AddOrUpdate(string.Format(RefreshCookiesPattern, accountViewModel.Login), () => RefreshCookiesJob.Run(accountViewModel), Cron.Hourly);
             * RecurringJob.AddOrUpdate(string.Format(UnreadMessagesPattern, accountViewModel.Login), () => SendMessageToUnreadJob.Run(accountViewModel), Cron.Minutely);
             * RecurringJob.AddOrUpdate(string.Format(UnansweredMessagesPattern, accountViewModel.Login), () => SendMessageToUnansweredJob.Run(accountViewModel), Cron.Minutely);
             * RecurringJob.AddOrUpdate(string.Format(NewFriendMessagesPattern, accountViewModel.Login), () => SendMessageToNewFriendsJob.Run(accountViewModel), Cron.Minutely);
             * RecurringJob.AddOrUpdate(string.Format(RefreshFriendsPattern, accountViewModel.Login), () => RefreshFriendsJob.Run(accountViewModel), Cron.Minutely);
             * RecurringJob.AddOrUpdate(string.Format(AddNewFriendsPattern, accountViewModel.Login), () => GetNewFriendsAndRecommendedJob.Run(accountViewModel), Cron.Minutely);
             * RecurringJob.AddOrUpdate(string.Format(ConfirmFriendshipPattern, accountViewModel.Login), () => ConfirmFriendshipJob.Run(accountViewModel), Cron.Minutely);
             * RecurringJob.AddOrUpdate(string.Format(SendRequestFriendshipPattern, accountViewModel.Login), () => SendRequestFriendshipJob.Run(accountViewModel), Cron.Minutely);
             * RecurringJob.AddOrUpdate(string.Format(RunnerPattern, accountViewModel.Login), () => RunnerJob.Run(accountViewModel), Cron.Minutely);*/
        }
コード例 #2
0
        public static void Run(RunJobModel runModel)
        {
            var account = runModel.Account;
            var forSpy  = runModel.ForSpy;


            if (account.GroupSettingsId == null)
            {
                return;
            }
            if (new AccountManager().GetAccountById(account.Id) == null)
            {
                new JobService().RemoveAccountJobs(new RemoveAccountJobsModel
                {
                    AccountId = account.Id,
                    IsForSpy  = forSpy,
                    Login     = account.Login
                });

                return;
            }

            if (!new AccountManager().HasAWorkingAccount(account.Id))
            {
                return;
            }

            new JobQueueService().AddToQueue(new JobQueueViewModel
            {
                AccountId    = account.Id,
                FunctionName = FunctionName.CheckFriendsAtTheEndTimeConditions,
                IsForSpy     = forSpy
            });
        }
コード例 #3
0
        protected virtual void CheckAccount(RunJobModel runModel)
        {
            var    account      = runModel.Account;
            var    forSpy       = runModel.ForSpy;
            object accountModel = null;

            if (!forSpy)
            {
                accountModel = new AccountManager().GetAccountById(account.Id);
            }
            else
            {
                accountModel = new SpyAccountManager().GetSpyAccountById(account.Id);
            }


            if (accountModel == null)
            {
                new JobService().RemoveAccountJobs(new RemoveAccountJobsModel
                {
                    AccountId = account.Id,
                    Login     = account.Login,
                    IsForSpy  = forSpy
                });
            }
        }
コード例 #4
0
        public bool CreateBackgroundJob(ICreateBackgroundJob model)
        {
            var currentModel = model as CreateBackgroundJobModel;

            if (currentModel == null)
            {
                return(false);
            }

            var account          = currentModel.Account;
            var isForSpy         = currentModel.IsForSpy;
            var friend           = currentModel.Friend;
            var checkPermissions = currentModel.CheckPermissions;
            var functionName     = currentModel.FunctionName;
            var launchTime       = currentModel.LaunchTime;

            var jobStateModel = new JobStateViewModel
            {
                AccountId    = account.Id,
                FriendId     = null,
                FunctionName = functionName,
                IsForSpy     = isForSpy
            };

            if (_requaredFunctions.All(groupFunction => groupFunction != functionName) && checkPermissions)
            {
                if (!FunctionHasPermisions(functionName, account))
                {
                    return(false);
                }
            }

            if (!TimeIsSet(launchTime))
            {
                return(false);
            }

            if (JobIsRun(jobStateModel))
            {
                return(false);
            }

            var runModel = new RunJobModel
            {
                Account = account,
                ForSpy  = isForSpy,
                Friend  = friend
            };
            var runJobFunctionService = new RunJobFunctionService();
            var jobId = BackgroundJob.Schedule(() => runJobFunctionService.RunService(functionName, runModel),
                                               launchTime);

            jobStateModel.JobId = jobId;

            AddJobState(jobStateModel);


            return(true);
        }
コード例 #5
0
        public static void Run(RunJobModel runModel)
        {
            var account = runModel.Account;
            var forSpy  = runModel.ForSpy;

            new JobQueueService().AddToQueue(new JobQueueViewModel
            {
                AccountId    = account.Id,
                FunctionName = FunctionName.RefreshCookies,
                IsForSpy     = forSpy
            });
        }
コード例 #6
0
        public async Task <IActionResult> RunJob(Guid workerId, [FromBody] RunJobModel runJobModel)
        {
            try
            {
                _telemetryClient.TrackEvent(TelemetryEvents.SchedulingJob, new Dictionary <string, string>
                {
                    { nameof(workerId), workerId.ToString() },
                    { nameof(runJobModel.JobName), runJobModel.JobName },
                    { nameof(runJobModel.JobPayload), runJobModel.JobPayload },
                });

                await _serverService.RunJob(workerId, runJobModel.JobName, runJobModel.JobPayload);

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }
コード例 #7
0
        public string RunService(FunctionName functionName, RunJobModel model)
        {
            RunJobContext context;

            switch (functionName)
            {
            case FunctionName.SendMessageToNewFriends:
            {
                context = new RunJobContext(new SendMessageToNewFriendsJob());
                break;
            }

            case FunctionName.SendMessageToUnanswered:
            {
                context = new RunJobContext(new SendMessageToUnansweredJob());
                break;
            }

            case FunctionName.SendMessageToUnread:
            {
                context = new RunJobContext(new SendMessageToUnreadJob());
                break;
            }

            case FunctionName.RefreshFriends:
            {
                context = new RunJobContext(new RefreshFriendsJob());
                break;
            }

            case FunctionName.GetNewFriendsAndRecommended:
            {
                context = new RunJobContext(new GetNewFriendsAndRecommendedJob());
                break;
            }

            case FunctionName.ConfirmFriendship:
            {
                context = new RunJobContext(new ConfirmFriendshipJob());
                break;
            }

            case FunctionName.SendRequestFriendship:
            {
                context = new RunJobContext(new SendRequestFriendshipJob());
                break;
            }    /*
                  * case FunctionName.RefreshCookies:
                  * {
                  * context = new RunJobContext(new RefreshCookies());
                  * break;
                  * }*/

            case FunctionName.JoinTheNewGroupsAndPages:
            {
                context = new RunJobContext(new JoinTheNewGroupsAndPagesJob());
                break;
            }

            case FunctionName.InviteToGroups:
            {
                context = new RunJobContext(new InviteTheNewGroupJob());
                break;
            }

            case FunctionName.InviteToPages:
            {
                context = new RunJobContext(new InviteTheNewPageJob());
                break;
            }

            case FunctionName.RemoveFromFriends:
            {
                context = new RunJobContext(new RemoveFromFriendsJob());
                break;
            }

            case FunctionName.Wink:
            {
                context = new RunJobContext(new WinkFriendsJob());
                break;
            }    /*
                  * case FunctionName.AnalyzeFriends:
                  * {
                  * context = new RunJobContext(new AnalyzeFriendsJob());
                  * break;
                  * }*/

            case FunctionName.WinkFriendFriends:
            {
                context = new RunJobContext(new WinkFriendsFriendsJob());
                break;
            }    /*
                  * case FunctionName.CheckFriendsAtTheEndTimeConditions:
                  * {
                  * context = new RunJobContext(new C());
                  * break;
                  * }*/

            case FunctionName.WinkBack:
            {
                context = new RunJobContext(new WinkFriendsJob());
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException("functionName");
            }
            }

            context.Execute(model);

            return(functionName.ToString());
        }
コード例 #8
0
        public bool CreateBackgroundJob(ICreateBackgroundJob model)
        {
            var currentModel = model as CreateBackgroundJobModel;

            if (currentModel == null)
            {
                return(false);
            }

            var account          = currentModel.Account;
            var isForSpy         = currentModel.IsForSpy;
            var friend           = currentModel.Friend;
            var checkPermissions = currentModel.CheckPermissions;
            var functionName     = currentModel.FunctionName;
            var launchTime       = currentModel.LaunchTime;

            var jobStateModel = new JobStateViewModel
            {
                AccountId    = account.Id,
                FriendId     = null,
                FunctionName = functionName,
                IsForSpy     = isForSpy
            };

            if (checkPermissions)
            {
                if (!FunctionHasPermisions(functionName, account))
                {
                    return(false);
                }
            }
            if (!TimeIsSet(launchTime))
            {
                return(false);
            }

            if (JobIsRun(jobStateModel))
            {
                return(false);
            }

            var runModel = new RunJobModel
            {
                Account = account,
                ForSpy  = isForSpy,
                Friend  = friend
            };

            string jobId = null;

            switch (functionName)
            {
            case FunctionName.SendMessageToNewFriends:
            {
                jobId = BackgroundJob.Schedule(() => SendMessageToNewFriendsJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.SendMessageToUnanswered:
            {
                jobId = BackgroundJob.Schedule(() => SendMessageToUnansweredJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.SendMessageToUnread:
            {
                jobId = BackgroundJob.Schedule(() => SendMessageToUnreadJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.RefreshFriends:
            {
                jobId = BackgroundJob.Schedule(() => RefreshFriendsJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.GetNewFriendsAndRecommended:
            {
                jobId = BackgroundJob.Schedule(() => GetNewFriendsAndRecommendedJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.ConfirmFriendship:
            {
                jobId = BackgroundJob.Schedule(() => ConfirmFriendshipJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.SendRequestFriendship:
            {
                jobId = BackgroundJob.Schedule(() => SendRequestFriendshipJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.AnalyzeFriends:
            {
                jobId = BackgroundJob.Schedule(() => SendRequestFriendshipJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.RefreshCookies:
            {
                jobId = BackgroundJob.Schedule(() => RefreshCookiesJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.JoinTheNewGroupsAndPages:
            {
                if (account.GroupSettingsId == null)
                {
                    break;
                }
                var newGroups = new GroupService(new NoticeService()).GetNewSettings(account.Id, (long)account.GroupSettingsId);

                if (newGroups == null || newGroups.Count == 0)
                {
                    break;
                }

                jobId = BackgroundJob.Schedule(() => JoinTheNewGroupsAndPagesJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.InviteToGroups:
            {
                jobId = BackgroundJob.Schedule(() => InviteTheNewGroupJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.InviteToPages:
            {
                jobId = BackgroundJob.Schedule(() => InviteTheNewPageJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.RemoveFromFriends:
            {
                jobId = BackgroundJob.Schedule(() => RemoveFromFriendsJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.Wink:
            {
                jobId = BackgroundJob.Schedule(() => WinkFriendsJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.WinkFriendFriends:
            {
                jobId = BackgroundJob.Schedule(() => WinkFriendsFriendsJob.Run(runModel), launchTime);
                break;
            }

            case FunctionName.WinkBack:
            {
                jobId = BackgroundJob.Schedule(() => WinkBackJob.Run(runModel), launchTime);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException("functionName");
            }

            jobStateModel.JobId = jobId;

            AddJobState(jobStateModel);

            return(true);
        }