public void Run(IRunJobModel runModel)
        {
            var account = runModel.Account;
            var forSpy  = runModel.ForSpy;
            var friend  = runModel.Friend;

            if (account.GroupSettingsId == null)
            {
                return;
            }

            if (!new FunctionPermissionManager().HasPermissions(FunctionName.InviteToGroups, (long)account.GroupSettingsId))
            {
                return;
            }

            var settings = new GroupService(new NoticeService()).GetSettings((long)account.GroupSettingsId);
            var inviteTheNewGroupLaunchTime = new TimeSpan(settings.RetryTimeInviteTheGroupsHour, settings.RetryTimeInviteTheGroupsMin, settings.RetryTimeInviteTheGroupsSec);

            var model = new CreateBackgroundJobModel
            {
                Account          = account,
                FunctionName     = FunctionName.InviteToGroups,
                LaunchTime       = inviteTheNewGroupLaunchTime,
                CheckPermissions = true,
                IsForSpy         = forSpy
            };

            new JobStateService().DeleteJobState(new JobStateViewModel
            {
                AccountId    = account.Id,
                FunctionName = FunctionName.InviteToGroups,
                FriendId     = friend.Id,
                IsForSpy     = forSpy
            });

            var jobIsSuccessfullyCreated = new BackgroundJobService().CreateBackgroundJob(model);

            if (!jobIsSuccessfullyCreated)
            {
                return;
            }

            new JobQueueService().AddToQueue(new JobQueueViewModel
            {
                AccountId    = account.Id,
                FunctionName = FunctionName.InviteToGroups,
                FriendId     = friend.Id,
                IsForSpy     = forSpy
            });
        }
Beispiel #2
0
        public void Run(IRunJobModel runModel)
        {
            var account = runModel.Account;
            var friend  = runModel.Friend;
            var forSpy  = runModel.ForSpy;

            if (account.GroupSettingsId == null)
            {
                return;
            }

            var settings = new GroupService(new NoticeService()).GetSettings((long)account.GroupSettingsId);
            var winkFriendsLaunchTime = new TimeSpan(settings.RetryTimeForWinkFriendsHour, settings.RetryTimeForWinkFriendsMin, settings.RetryTimeForWinkFriendsSec);

            var model = new CreateBackgroundJobModel
            {
                Account          = account,
                FunctionName     = FunctionName.Wink,
                LaunchTime       = winkFriendsLaunchTime,
                CheckPermissions = true,
                IsForSpy         = forSpy
            };

            new JobStateService().DeleteJobState(new JobStateViewModel
            {
                AccountId    = account.Id,
                FunctionName = FunctionName.Wink,
                IsForSpy     = forSpy
            });

            var jobIsSuccessfullyCreated = new BackgroundJobService().CreateBackgroundJob(model);

            if (!jobIsSuccessfullyCreated)
            {
                return;
            }

            new JobQueueService().AddToQueue(new JobQueueViewModel
            {
                AccountId    = account.Id,
                FunctionName = FunctionName.Wink,
                IsForSpy     = forSpy
            });
        }
Beispiel #3
0
        public void SaveGroupFunctions(long groupId, List <long> funtions, IBackgroundJobService backgroundJobService)
        {
            var functionsIdForRun = new List <FunctionName>();

            var oldFuntions =
                new GetGroupFunctionsByGroupIdQueryHandler(new DataBaseContext()).Handle(new GetGroupFunctionsByGroupIdQuery
            {
                GroupId = groupId
            });

            new SaveGroupFunctionsCommandHandler(new DataBaseContext()).Handle(new SaveGroupFunctionsCommand
            {
                GroupId   = groupId,
                Functions = funtions
            });

            var newFunctions =
                new GetGroupFunctionsByGroupIdQueryHandler(new DataBaseContext()).Handle(new GetGroupFunctionsByGroupIdQuery
            {
                GroupId = groupId
            });

            foreach (var funtion in newFunctions)
            {
                if (oldFuntions.Any(data => data.FunctionId == funtion.FunctionId))
                {
                    continue;
                }

                if (oldFuntions.All(data => data.FunctionId != funtion.FunctionId))
                {
                    functionsIdForRun.Add(funtion.FunctionName);
                }
            }
            var accounts =
                new GetAccountsByGroupSettingsIdQueryHandler(new DataBaseContext()).Handle(new GetAccountsByGroupSettingsIdQuery
            {
                GroupSettingsId = groupId
            });

            var accountsViewModel = accounts.Select(model => new AccountViewModel
            {
                Id                        = model.Id,
                PageUrl                   = model.PageUrl,
                Login                     = model.Login,
                Password                  = model.Password,
                FacebookId                = model.FacebookId,
                Proxy                     = model.Proxy,
                ProxyLogin                = model.ProxyLogin,
                ProxyPassword             = model.ProxyPassword,
                Cookie                    = model.Cookie.CookieString,
                Name                      = model.Name,
                GroupSettingsId           = model.GroupSettingsId,
                AuthorizationDataIsFailed = model.AuthorizationDataIsFailed,
                ProxyDataIsFailed         = model.ProxyDataIsFailed,
                IsDeleted                 = model.IsDeleted,
                UserAgentId               = model.UserAgentId
            }).ToList();

            foreach (var accountModel in accountsViewModel)
            {
                //удаляем выключенные задачи
                foreach (var oldFuntion in oldFuntions)
                {
                    if (newFunctions.All(data => data.FunctionId != oldFuntion.FunctionId))
                    {
                        var stateList = _jobStateService.GetStatesByAccountAndFunctionName(new JobStateViewModel
                        {
                            AccountId    = accountModel.Id,
                            FunctionName = oldFuntion.FunctionName,
                            IsForSpy     = false
                        });

                        foreach (var state in stateList)
                        {
                            _jobStateService.DeleteJobState(state);

                            backgroundJobService.RemoveBackgroundJobById(state.JobId);
                        }
                    }
                }
                foreach (var function in functionsIdForRun)
                {
                    var delayTime = _settingsManager.GetTimeSpanByFunctionName(function, groupId);

                    var model = new CreateBackgroundJobModel
                    {
                        Account          = accountModel,
                        CheckPermissions = true,
                        FunctionName     = function,
                        LaunchTime       = delayTime
                    };

                    backgroundJobService.CreateBackgroundJob(model);
                }
            }
        }