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);*/ }
public void AddOrUpdateSpyAccountJobs(IAddOrUpdateAccountJobs model) { var currentModel = model as AddOrUpdateAccountModel; if (currentModel == null) { return; } var accountViewModel = currentModel.Account; RecurringJob.AddOrUpdate(string.Format(RefreshCookiesPattern, accountViewModel.Login), () => RefreshCookiesJob.Run(new RunJobModel { ForSpy = true, Account = accountViewModel }), Cron.Daily); if (AccountIsWorking(accountViewModel)) { //for add or update spy only account RecurringJob.AddOrUpdate(string.Format(AnalyzeFriendsPattern, accountViewModel.Login), () => AnalyzeFriendsJob.Run(accountViewModel), Cron.Minutely); } }
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); }