Exemple #1
0
        public long AddOrUpdateAccount(AccountDraftViewModel model, IBackgroundJobService backgroundJobService)
        {
            var userAgentId = new GetRandomUserAgentQueryHandler(new DataBaseContext()).Handle(new GetRandomUserAgentQuery());

            if (userAgentId == null)
            {
                return(0);
            }

            var accountId = new AddOrUpdateAccountCommandHandler(new DataBaseContext()).Handle(new AddOrUpdateAccountCommand
            {
                Id            = model.Id,
                Name          = model.Name,
                PageUrl       = model.PageUrl,
                FacebookId    = model.FacebookId,
                Password      = model.Password,
                Login         = model.Login,
                Proxy         = model.Proxy,
                ProxyLogin    = model.ProxyLogin,
                ProxyPassword = model.ProxyPassword,
                UserAgentId   = userAgentId.Id
            });

            new CookieService().RefreshCookies(new AccountViewModel
            {
                Id            = accountId,
                Login         = model.Login,
                Password      = model.Password,
                Proxy         = model.Proxy,
                ProxyLogin    = model.ProxyLogin,
                ProxyPassword = model.ProxyPassword,
                UserAgentId   = model.UserAgentId
            },
                                               false,
                                               backgroundJobService);


            var account = new GetAccountByIdQueryHandler(new DataBaseContext()).Handle(new GetAccountByIdQuery
            {
                UserId = accountId
            });

            if (model.Id == null || model.PageUrl == null || model.FacebookId == 0)
            {
                long   accountFacebookId = 0;
                string homePageUrl       = null;

                if (account.Cookie != null)
                {
                    accountFacebookId = _proxyManager.GetAccountFacebookId(account.Cookie.CookieString);
                    homePageUrl       = _accountManager.CreateHomePageUrl(accountFacebookId);
                }

                new AddOrUpdateAccountCommandHandler(new DataBaseContext()).Handle(new AddOrUpdateAccountCommand
                {
                    Id            = account.Id,
                    Name          = model.Name,
                    PageUrl       = homePageUrl,
                    FacebookId    = accountFacebookId,
                    Password      = model.Password,
                    Login         = model.Login,
                    Proxy         = model.Proxy,
                    ProxyLogin    = model.ProxyLogin,
                    ProxyPassword = model.ProxyPassword
                });

                return(accountId);
            }

            var modelForJob = new AddOrUpdateAccountModel
            {
                Account = new AccountViewModel
                {
                    Id                        = accountId,
                    PageUrl                   = account.PageUrl,
                    Login                     = account.Login,
                    Password                  = account.Password,
                    FacebookId                = account.FacebookId,
                    Proxy                     = account.Proxy,
                    ProxyLogin                = account.ProxyLogin,
                    ProxyPassword             = account.ProxyPassword,
                    Cookie                    = account.Cookie.CookieString,
                    Name                      = model.Name,
                    GroupSettingsId           = account.GroupSettingsId,
                    AuthorizationDataIsFailed = account.AuthorizationDataIsFailed,
                    ProxyDataIsFailed         = account.ProxyDataIsFailed,
                    ConformationDataIsFailed  = account.ConformationIsFailed,
                    IsDeleted                 = account.IsDeleted,
                    UserAgentId               = account.UserAgentId
                }
            };

            _jobService.AddOrUpdateAccountJobs(modelForJob);

            return(accountId);
        }
Exemple #2
0
        public void AddOrUpdateSpyAccount(SpyAccountViewModel model, IBackgroundJobService backgroundJobService)
        {
            var accountId = new AddOrUpdateSpyAccountCommandHandler(new DataBaseContext()).Handle(new AddOrUpdateSpyAccountCommand
            {
                Id            = model.Id,
                Name          = model.Name,
                PageUrl       = model.PageUrl,
                FacebookId    = model.FacebookId,
                Password      = model.Password,
                Login         = model.Login,
                Proxy         = model.Proxy,
                ProxyLogin    = model.ProxyLogin,
                ProxyPassword = model.ProxyPassword
            });

            new CookieService().RefreshCookies(new AccountViewModel
            {
                Id            = accountId,
                Login         = model.Login,
                Password      = model.Password,
                Proxy         = model.Proxy,
                ProxyLogin    = model.ProxyLogin,
                ProxyPassword = model.ProxyPassword,
            },
                                               true,
                                               backgroundJobService);

            var account = new GetSpyAccountByIdQueryHandler(new DataBaseContext()).Handle(new GetSpyAccountByIdQuery
            {
                UserId = accountId
            });

            if (model.PageUrl == null || model.FacebookId == 0)
            {
                var accountFacebookId = _proxyManager.GetAccountFacebookId(account.Cookie.CookieString);
                var homePageUrl       = _accountManager.CreateHomePageUrl(accountFacebookId);

                new AddOrUpdateSpyAccountCommandHandler(new DataBaseContext()).Handle(new AddOrUpdateSpyAccountCommand
                {
                    Id            = account.Id,
                    Name          = model.Name,
                    PageUrl       = homePageUrl,
                    FacebookId    = accountFacebookId,
                    Password      = model.Password,
                    Login         = model.Login,
                    Proxy         = model.Proxy,
                    ProxyLogin    = model.ProxyLogin,
                    ProxyPassword = model.ProxyPassword
                });

                account = new GetSpyAccountByIdQueryHandler(new DataBaseContext()).Handle(new GetSpyAccountByIdQuery
                {
                    UserId = accountId
                });
            }

            var jobModel = new AddOrUpdateAccountModel
            {
                Account = new AccountViewModel
                {
                    Id            = accountId,
                    Name          = model.Name,
                    PageUrl       = model.PageUrl,
                    FacebookId    = account.FacebookId,
                    Password      = model.Password,
                    Login         = model.Login,
                    Proxy         = model.Proxy,
                    ProxyLogin    = model.ProxyLogin,
                    ProxyPassword = model.ProxyPassword,
                    Cookie        = account.Cookie.CookieString
                }
            };

            _jobService.AddOrUpdateSpyAccountJobs(jobModel);
        }