Exemplo n.º 1
0
        public IRequestRepo Create()
        {
            string TwoFaHandler(string login, bool isAutoRelogin)
            {
                Logger.Info($"Waiting 2FA code for {login}");
                var code = _settings.TwoFaHandler?.Get(login, isAutoRelogin);

                Logger.Info($"Got 2FA code for {login}");
                return(code);
            }

            IRequestRepo repo = _settings.Protocol switch
            {
                Protocol.YadWeb => new YadWebRequestRepo(_settings.Proxy, _credentials),
                Protocol.WebM1Bin => new WebBinRequestRepo(_settings.Proxy, _credentials, TwoFaHandler),
                Protocol.WebV2 => new WebV2RequestRepo(_settings.Proxy, _credentials, TwoFaHandler),
                _ => throw new Exception("Unknown protocol")
            };

            if (!string.IsNullOrWhiteSpace(_settings.UserAgent))
            {
                repo.HttpSettings.UserAgent = _settings.UserAgent;
            }

            return(repo);
        }
    }
Exemplo n.º 2
0
        public async Task Invoke(HttpContext context, IRequestRepo requestRepo, IAuxUserAgentService userAgentService)
        {
            //getting user agent from header
            StringValues user_agent = "";

            context.Request.Headers.TryGetValue("User-Agent", out user_agent);


            //waiting for user agent
            // var result = await userAgentService.ParseUserAgentData(user_agent.ToString());

            //saving request(request+useragentdata) data to dbcontext
            requestRepo.Add(new Request
            {
                Source      = context.Connection.RemoteIpAddress.ToString() + ":" + context.Connection.RemotePort.ToString(),
                Destination = context.Request.Path.ToString(),
                Method      = context.Request.Method,
                //UserAgent = result,
            });

            //save changes to db
            await requestRepo.SaveChangesAsync();

            //calling next to go to next middleware
            await _next(context);
        }
 public HomeController(ILogger <HomeController> logger, IBookRepo bookR,
                       IReportRepo reportR, IReviewRepo reviewR, IRequestRepo requestR)
 {
     _logger     = logger;
     bookRepo    = bookR;
     reportRepo  = reportR;
     reviewRepo  = reviewR;
     requestRepo = requestR;
 }
Exemplo n.º 4
0
 public RequestController(
     IRequestRepo requestRepo,
     ILinkService <RequestDto, RequestResourceParameters> linkService,
     IMapper mapper)
 {
     _requestRepo = requestRepo;
     _mapper      = mapper;
     _linkService = linkService;
 }
Exemplo n.º 5
0
        public ShardManager(IRequestRepo repo)
        {
            var httpsettings = repo.HttpSettings;

            _metaServer = new Cached <ServerRequestResult>(_ =>
            {
                Logger.Debug("Requesting new meta server");
                var server = new MobMetaServerRequest(httpsettings).MakeRequestAsync().Result;
                return(server);
            },
                                                           _ => TimeSpan.FromSeconds(MetaServerExpiresSec));

            BannedShards = new Cached <List <ShardInfo> >(_ => new List <ShardInfo>(),
                                                          _ => TimeSpan.FromMinutes(2));

            //CachedShards = new Cached<Dictionary<ShardType, ShardInfo>>(old => new ShardInfoRequest(httpsettings, auth).MakeRequestAsync().Result.ToShardInfo(),
            //    value => TimeSpan.FromSeconds(ShardsExpiresInSec));

            CachedShards = new Cached <Dictionary <ShardType, ShardInfo> >(_ => repo.GetShardInfo1(),
                                                                           _ => TimeSpan.FromSeconds(ShardsExpiresInSec));

            DownloadServersPending = new Pending <Cached <ServerRequestResult> >(8,
                                                                                 () => new Cached <ServerRequestResult>(_ =>
            {
                var server = new GetServerRequest(httpsettings).MakeRequestAsync().Result;
                Logger.Debug($"Download server changed to {server.Url}");
                return(server);
            },
                                                                                                                        _ => TimeSpan.FromSeconds(DownloadServerExpiresSec)
                                                                                                                        ));

            UploadServer = new Cached <ShardInfo>(_ =>
            {
                var server = new GetUploadServerRequest(httpsettings).MakeRequestAsync().Result;
                Logger.Debug($"Upload server changed to {server.Url}");
                return(new ShardInfo {
                    Count = 0, Type = ShardType.Upload, Url = server.Url
                });
            },
                                                  _ => TimeSpan.FromSeconds(ShardsExpiresInSec));


            WeblinkDownloadServersPending = new Pending <Cached <ServerRequestResult> >(8,
                                                                                        () => new Cached <ServerRequestResult>(_ =>
            {
                var data      = new WeblinkGetServerRequest(httpsettings).MakeRequestAsync().Result;
                var serverUrl = data.Body.WeblinkGet[0].Url;
                Logger.Debug($"weblink Download server changed to {serverUrl}");
                var res = new ServerRequestResult {
                    Url = serverUrl
                };
                return(res);
            },
                                                                                                                               _ => TimeSpan.FromSeconds(DownloadServerExpiresSec)
                                                                                                                               ));
        }
Exemplo n.º 6
0
        public UnpublishRequest(IRequestRepo repo, HttpCommonSettings settings, IAuth auth, string publicLink)
            : base(settings, auth)
        {
            _publicLink = publicLink;

            if (repo.PublicBaseUrlDefault.Length > 0 &&
                _publicLink.StartsWith(repo.PublicBaseUrlDefault, StringComparison.InvariantCultureIgnoreCase))
            {
                _publicLink = _publicLink.Remove(0, repo.PublicBaseUrlDefault.Length);
            }
        }
 public ReviewController(ApplicationDbContext context, UserManager <AppUser> userMgr,
                         IBookRepo bookR, IReportRepo reportR,
                         IReviewRepo reviewR, IRequestRepo requestR)
 {
     _context    = context;
     userManager = userMgr;
     bookRepo    = bookR;
     reportRepo  = reportR;
     reviewRepo  = reviewR;
     requestRepo = requestR;
 }
Exemplo n.º 8
0
 public AccountController(UserManager <AppUser> userMgr, SignInManager <AppUser> signinMgr,
                          RoleManager <IdentityRole> roleMgr, IBookRepo bookR, IReportRepo reportR,
                          IReviewRepo reviewR, IRequestRepo requestR)
 {
     userManager   = userMgr;
     signInManager = signinMgr;
     roleManager   = roleMgr;
     bookRepo      = bookR;
     reportRepo    = reportR;
     reviewRepo    = reviewR;
     requestRepo   = requestR;
 }
Exemplo n.º 9
0
        public void TestCheckForOwnerName()
        {
            //Arrange
            repo = new FakeRequestRepo();
            SeedRequestData();
            foreach (Request r in requests)
            {
                repo.AddRequest(r);
            }

            //Act
            bool stiles = repo.CheckForOwnerName("Stiles");
            bool robin  = repo.CheckForOwnerName("robinhood");

            //Assert
            Assert.True(stiles);
            Assert.False(robin);
        }
Exemplo n.º 10
0
        public void TestAddRequest()
        {
            //Arrange
            repo = new FakeRequestRepo();
            SeedData();
            Request request = new Request()
            {
                Requester = users[0].UserName,
                Owner     = users[1].UserName,
                BookTitle = books[0].Title,
                Duration  = "1 week"
            };

            //Act
            repo.AddRequest(request);

            //Assert
            Assert.Single(repo.Requests);
            Assert.Equal("Stiles", repo.Requests.ElementAt(0).Owner);
            Assert.Equal("The Lightning Thief", repo.Requests.ElementAt(0).BookTitle);
        }
Exemplo n.º 11
0
        public ShardManager(HttpCommonSettings httpsettings, IAuth auth, IRequestRepo repo)
        {
            _metaServer = new Cached <Requests.WebBin.MobMetaServerRequest.Result>(old =>
            {
                Logger.Debug("Requesting new meta server");
                var server = new Requests.WebBin.MobMetaServerRequest(httpsettings).MakeRequestAsync().Result;
                return(server);
            },
                                                                                   value => TimeSpan.FromSeconds(MetaServerExpiresSec));

            BannedShards = new Cached <List <ShardInfo> >(old => new List <ShardInfo>(),
                                                          value => TimeSpan.FromMinutes(2));

            //CachedShards = new Cached<Dictionary<ShardType, ShardInfo>>(old => new ShardInfoRequest(httpsettings, auth).MakeRequestAsync().Result.ToShardInfo(),
            //    value => TimeSpan.FromSeconds(ShardsExpiresInSec));

            CachedShards = new Cached <Dictionary <ShardType, ShardInfo> >(old => repo.GetShardInfo1(),
                                                                           value => TimeSpan.FromSeconds(ShardsExpiresInSec));

            DownloadServersPending = new Pending <Cached <Requests.WebBin.ServerRequest.Result> >(8,
                                                                                                  () => new Cached <Requests.WebBin.ServerRequest.Result>(old =>
            {
                var server = new Requests.WebBin.GetServerRequest(httpsettings).MakeRequestAsync().Result;
                Logger.Debug($"Download server changed to {server.Url}");
                return(server);
            },
                                                                                                                                                          value => TimeSpan.FromSeconds(DownloadServerExpiresSec)
                                                                                                                                                          ));

            WeblinkDownloadServersPending = new Pending <Cached <Requests.WebBin.ServerRequest.Result> >(8,
                                                                                                         () => new Cached <Requests.WebBin.ServerRequest.Result>(old =>
            {
                var server = new Requests.WebBin.WeblinkGetServerRequest(httpsettings).MakeRequestAsync().Result;
                Logger.Debug($"weblink Download server changed to {server.Url}");
                return(server);
            },
                                                                                                                                                                 value => TimeSpan.FromSeconds(DownloadServerExpiresSec)
                                                                                                                                                                 ));
        }
Exemplo n.º 12
0
 public RequestController(IRequestRepo repo)
 {
     _repo = repo;
 }
Exemplo n.º 13
0
 public DownloadRequest(IRequestRepo repo, File file, long instart, long inend, IAuth authent, HttpCommonSettings settings, Cached <Dictionary <ShardType, ShardInfo> > shards)
 {
     _repo   = repo;
     Request = CreateRequest(authent, settings.Proxy, file, instart, inend, settings.UserAgent, shards);
 }
Exemplo n.º 14
0
 public RequestsController(IRequestRepo repository, IMapper mapper, IRequestService service)
 {
     _repository = repository;
     _mapper     = mapper;
     _service    = service;
 }
Exemplo n.º 15
0
 public Handler(IPublishEndpoint publishEndpoint, IRequestRepo consumerRepo)
 {
     this.publishEndpoint = publishEndpoint;
     this.consumerRepo    = consumerRepo;
 }
Exemplo n.º 16
0
 public RequestService()
 {
     this.Repository = new RequestRepo();
 }
Exemplo n.º 17
0
 public HomeController(IOfferRepo offerRepo, ICategoryRepo categoryRepo, IRequestRepo requestRepo)
 {
     this.offerRepo    = offerRepo;
     this.categoryRepo = categoryRepo;
     this.requestRepo  = requestRepo;
 }
Exemplo n.º 18
0
 public Handler(IRequestRepo repo)
 {
     this.repo = repo;
 }
Exemplo n.º 19
0
 public OrderRepo(IRequestRepo requestRepo) : base()
 {
     RequestRepo = requestRepo;
 }
Exemplo n.º 20
0
 public RequestService(IRequestRepo requestRepo, IMapper mapper, IBookRepo bookRepo)
 {
     this.requestRepo = requestRepo;
     this.mapper      = mapper;
     this.bookRepo    = bookRepo;
 }
Exemplo n.º 21
0
 public RequestStatusUpdatedConsumer(IRequestRepo repo)
 {
     this.repo = repo;
 }
Exemplo n.º 22
0
 public RequestService(IRequestRepo Repository)
 {
     this.Repository = Repository;
 }
Exemplo n.º 23
0
 public RequestsController(IRequestRepo repository, IMapper mapper)
 {
     _repository = repository;
     _mapper     = mapper;
 }