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); }
public bool CheckExist(JobStateViewModel jobState) { return(new JobStateIsExistQueryHandler(new DataBaseContext()).Handle(new JobStateIsExistQuery { AccountId = jobState.AccountId, FunctionName = jobState.FunctionName, IsForSpy = jobState.IsForSpy, FriendId = jobState.FriendId })); }
public void AddJobState(JobStateViewModel jobState) { new AddJobStateCommandHandler().Handle(new AddJobStateCommand { AccountId = jobState.AccountId, FunctionName = jobState.FunctionName, IsForSpy = jobState.IsForSpy, FriendId = jobState.FriendId, JobId = jobState.JobId }); }
public List <string> DeleteJobState(JobStateViewModel jobState) { var jobIdList = new DeleteJobStateCommandHandler().Handle(new DeleteJobStateCommand { AccountId = jobState.AccountId, FunctionName = jobState.FunctionName, IsForSpy = jobState.IsForSpy, FriendId = jobState.FriendId }); return(jobIdList); }
public List <JobStateViewModel> GetStatesByAccountAndFunctionName(JobStateViewModel jobState) { var result = new GetStatesByModelCommandHandler().Handle(new GetStatesByModelCommand { AccountId = jobState.AccountId, FunctionName = jobState.FunctionName, IsForSpy = jobState.IsForSpy }); return(result.Select(model => new JobStateViewModel { AccountId = model.AccountId, JobId = model.JobId, FunctionName = model.FunctionName, IsForSpy = model.IsForSpy, FriendId = model.FriendId }).ToList()); }
private void AddJobState(JobStateViewModel model) { _jobStateService.AddJobState(model); }
private bool JobIsRun(JobStateViewModel model) { return(_jobStateService.CheckExist(model)); }
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); }