Esempio n. 1
0
        private static void ConfigureConnector(IApplicationBuilder app, ConnectorService connectorService, AuthorizationService authorizationService)
        {
            app.Map("/Connectors", config =>
            {
                config.UseWebSockets(new WebSocketOptions
                {
                    KeepAliveInterval = TimeSpan.FromSeconds(30),
                    ReceiveBufferSize = 1024
                });

                config.Use(async(context, next) =>
                {
                    if (!context.WebSockets.IsWebSocketRequest)
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                        return;
                    }

                    try
                    {
                        var authorizationContext = authorizationService.AuthorizeConnector(context);

                        using (var webSocket = await context.WebSockets.AcceptWebSocketAsync().ConfigureAwait(false))
                        {
                            await connectorService.RunAsync(webSocket, authorizationContext, context.RequestAborted).ConfigureAwait(false);
                        }
                    }
                    catch (UnauthorizedAccessException)
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                    }
                });
            });
        }
Esempio n. 2
0
        public MainViewModel(PageService pageService,
                             DbContextLoader contextLoader,
                             ClientPipeHanlder pipeHanlder,
                             EventBus eventBus,
                             ConnectorService connectorService,
                             ValuteGetterService valuteGetter,
                             SplashScreenService splashScreenService,
                             SourceService sourceService,
                             Services.UpdateHandlerService handlerService, IConfiguration configuration)
        {
            this.pageService         = pageService;
            this.contextLoader       = contextLoader;
            this.pipeHanlder         = pipeHanlder;
            this.eventBus            = eventBus;
            this.updaterService      = connectorService;
            this.valuteGetter        = valuteGetter;
            this.splashScreenService = splashScreenService;
            this.sourceService       = sourceService;
            this.handlerService      = handlerService;
            this.configuration       = configuration;
            pageService.PageChanged += PageService_PageChanged;

            splashScreenService.OverlapScreen += SplashScreenService_OverlapScreen;
            splashScreenService.ShowPromtBtn  += SplashScreenService_ShowPromtBtn;
            splashScreenService.ClearScreen   += SplashScreenService_ClearScreen;


            Init();
        }
Esempio n. 3
0
 public ConnectorDetail Get(ConnectorCriteria connectorCriteria)
 {
     using (var uow = UnitOfWorkFactory.Create <NovelContext>())
     {
         var service = new ConnectorService(uow);
         var detail  = service.Get(connectorCriteria);
         return(detail);
     }
 }
Esempio n. 4
0
 public int AddConnector(ConnectorForm form)
 {
     using (var uow = UnitOfWorkFactory.Create <NovelContext>())
     {
         var service = new ConnectorService(uow);
         var id      = service.SaveChanges(form);
         return(id);
     }
 }
Esempio n. 5
0
 public HomeViewModel(PageService pageservice,
                      EventBus eventBus,
                      SplashScreenService splashScreen,
                      ConnectorService connectorService,
                      UserService userService,
                      SourceService sourceService) : base(pageservice)
 {
     this.eventBus       = eventBus;
     this.splashScreen   = splashScreen;
     this.updaterService = connectorService;
     this.userService    = userService;
     this.sourceService  = sourceService;
     Init();
 }
Esempio n. 6
0
        // ReSharper disable once UnusedMember.Global
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            AuthorizationService authorizationService,
            ConnectorService connectorService,
            StaticFilesService staticFilesService)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (env == null)
            {
                throw new ArgumentNullException(nameof(env));
            }
            if (authorizationService == null)
            {
                throw new ArgumentNullException(nameof(authorizationService));
            }
            if (connectorService == null)
            {
                throw new ArgumentNullException(nameof(connectorService));
            }
            if (staticFilesService == null)
            {
                throw new ArgumentNullException(nameof(staticFilesService));
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            ConfigureMvc(app);
            ConfigureSwagger(app);
            ConfigureConnector(app, connectorService, authorizationService);

            app.Run(async context =>
            {
                if (await staticFilesService.HandleRequestAsync(context))
                {
                    return;
                }

                await connectorService.ForwardHttpRequestAsync(context);
            });
        }
Esempio n. 7
0
        public int AddGroup(GroupForm form)
        {
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new GroupService(uow);
                var id      = service.SaveChanges(form);

                var connectorService = new ConnectorService(uow);

                if (form.Feeds != null || form.InlineEditProperty == form.PropertyName(m => m.Feeds))
                {
                    var feedService = new FeedService(uow);
                    foreach (var feed in form.Feeds)
                    {
                        feed.UrlHash         = feed.Url.GetIntHash();
                        feed.Status          = feed.Status == 0 ? R.FeedStatus.ACTIVE : feed.Status;
                        feed.LastSuccessDate = DateTime.Now.AddYears(-10);
                        var feedForm = new GenericForm <Feed>
                        {
                            ByUserID  = form.ByUserID,
                            DataModel = feed
                        };
                        var feedID = feedService.SaveChanges(feedForm);

                        // add to connector only if it a new feed
                        if (feed.ID == 0)
                        {
                            // connect series to feed
                            var connectorForm = new ConnectorForm()
                            {
                                ByUserID      = form.ByUserID,
                                ConnectorType = R.ConnectorType.GROUP_FEED,
                                SourceID      = id,
                                TargetID      = feedID
                            };
                            connectorService.SaveChanges(connectorForm);
                        }
                    }
                }

                if (form.Glossaries != null && form.InlineEditProperty == form.PropertyName(m => m.Glossaries))
                {
                    foreach (var glossary in form.Glossaries)
                    {
                        var glossaryService = new GlossaryService(uow);
                        var glossaryForm    = new GlossaryForm();
                        new PropertyMapper <Glossary, GlossaryForm>(glossary, glossaryForm).Map();
                        glossaryForm.ByUserID = form.ByUserID;

                        var glossaryID = glossaryService.SaveChanges(glossaryForm);

                        // connect group to glossary
                        var connectorForm = new ConnectorForm()
                        {
                            ByUserID      = form.ByUserID,
                            ConnectorType = R.ConnectorType.GROUP_GLOSSARY,
                            SourceID      = id,
                            TargetID      = glossaryID
                        };
                        connectorService.SaveChanges(connectorForm);
                    }
                }
                return(id);
            }
        }
Esempio n. 8
0
        public int AddSeries(SeriesForm form)
        {
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new SeriesService(uow);
                var id      = service.SaveChanges(form);

                var connectorService = new ConnectorService(uow);

                if (form.Categories != null || form.InlineEditProperty == form.PropertyName(m => m.Categories))
                {
                    form.Categories = form.Categories ?? new List <int>();
                    var connectorForm = new GenericForm <Connector>
                    {
                        ByUserID  = form.ByUserID,
                        DataModel = new Connector {
                            ConnectorType = R.ConnectorType.SERIES_TAGCATEGORY, SourceID = id
                        }
                    };
                    connectorService.Connect(connectorForm, form.Categories);
                }
                if (form.Genres != null || form.InlineEditProperty == form.PropertyName(m => m.Genres))
                {
                    form.Genres = form.Genres ?? new List <int>();
                    var connectorForm = new GenericForm <Connector>
                    {
                        ByUserID  = form.ByUserID,
                        DataModel = new Connector {
                            ConnectorType = R.ConnectorType.SERIES_TAGGENRE, SourceID = id
                        }
                    };
                    connectorService.Connect(connectorForm, form.Genres);
                }
                if (form.Contains != null || form.InlineEditProperty == form.PropertyName(m => m.Contains))
                {
                    form.Contains = form.Contains ?? new List <int>();
                    var connectorForm = new GenericForm <Connector>
                    {
                        ByUserID  = form.ByUserID,
                        DataModel = new Connector {
                            ConnectorType = R.ConnectorType.SERIES_TAGCONTAIN, SourceID = id
                        }
                    };
                    connectorService.Connect(connectorForm, form.Contains);
                }

                if (form.Feeds != null || form.InlineEditProperty == form.PropertyName(m => m.Feeds))
                {
                    var feedService = new FeedService(uow);
                    foreach (var feed in form.Feeds)
                    {
                        feed.UrlHash         = feed.Url.GetIntHash();
                        feed.Status          = feed.Status == 0 ? R.FeedStatus.ACTIVE : feed.Status;
                        feed.LastSuccessDate = feed.LastSuccessDate == DateTime.MinValue ? DateTime.Now : feed.LastSuccessDate;
                        var feedForm = new GenericForm <Feed>
                        {
                            ByUserID  = form.ByUserID,
                            DataModel = feed
                        };
                        var feedID = feedService.SaveChanges(feedForm);

                        // add to connector only if it a new feed
                        if (feed.ID == 0)
                        {
                            // connect series to feed
                            var connectorForm = new ConnectorForm()
                            {
                                ByUserID      = form.ByUserID,
                                ConnectorType = R.ConnectorType.SERIES_FEED,
                                SourceID      = id,
                                TargetID      = feedID
                            };
                            connectorService.SaveChanges(connectorForm);
                        }
                    }
                }
                if (form.Groups != null || form.InlineEditProperty == form.PropertyName(m => m.Groups))
                {
                    foreach (var group in form.Groups)
                    {
                        // connect series to feed
                        var connectorForm = new ConnectorForm()
                        {
                            ByUserID      = form.ByUserID,
                            ConnectorType = R.ConnectorType.SERIES_GROUP,
                            SourceID      = id,
                            TargetID      = group.ID
                        };
                        connectorService.SaveChanges(connectorForm);
                    }
                }
                if (form.Authors != null || form.InlineEditProperty == form.PropertyName(m => m.Authors))
                {
                    foreach (var author in form.Authors)
                    {
                        // connect series to feed
                        var connectorForm = new ConnectorForm()
                        {
                            ByUserID      = form.ByUserID,
                            ConnectorType = R.ConnectorType.SERIES_AUTHOR,
                            SourceID      = id,
                            TargetID      = author.ID
                        };
                        connectorService.SaveChanges(connectorForm);
                    }
                }
                if (form.Akas != null || form.InlineEditProperty == form.PropertyName(m => m.Akas))
                {
                    var akaService = new AkaService(uow);
                    foreach (var aka in form.Akas)
                    {
                        var akaForm = new AkaForm
                        {
                            ByUserID    = form.ByUserID,
                            SourceID    = form.ID,
                            SourceTable = R.SourceTable.SERIES
                        };
                        new PropertyMapper <Aka, AkaForm>(aka, akaForm).Map();
                        var akaID = akaService.SaveChanges(akaForm);
                    }
                }

                return(id);
            }
        }
Esempio n. 9
0
 public FunctionsController(ConnectorService connectorService, AuthorizationService authorizationService)
 {
     _connectorService     = connectorService ?? throw new ArgumentNullException(nameof(connectorService));
     _authorizationService = authorizationService ?? throw new ArgumentNullException(nameof(authorizationService));
 }