Example #1
0
        public LiveStreamPayload(ILiveStreamService liveStreamService, ICloudStorage cloudStorage)
        {
            _liveStreamService = liveStreamService;
            _cloudStorage      = cloudStorage;

            Name = nameof(Models.LiveStream);

            Id("audioId", x => x.Id);
            Field(x => x.Name);
            Field(x => x.WebsiteUrl, nullable: true);
            Field(x => x.Likes);
            Field(x => x.Dislikes);
            Field(x => x.Country);
            Field <StringGraphType>("coverImageUrl", "The cover image url", resolve: GetCoverImageUrl);
            Field <DateGraphType>("dateAdded", "The date the user added the live stream");
            Field <ListGraphType <GenrePayload> >("genres", "The genre the live stream belongs to", resolve: c => c.Source.AudioGenres.Select(x => x.Genre));
            Field <ListGraphType <RatingPayload> >("ratings", "The ratings that have been applied by users to this live stream");
            Field <ListGraphType <StreamDataPayload> >("streamDatas");
            Connection <CommentPayload>()
            .Name("comments")
            .Description("The top level comments for the live stream")
            .Resolve(c =>
            {
                var comments = c.Source.Comments.Where(x => x.IsTopLevelComment);

                return(ConnectionUtils.ToConnection(comments, c));
            });

            Interface <AudioInterface>();
        }
        public SaveLiveStreamPayload(ILiveStreamService liveService, ITagService tagService, ICloudStorage cloudStorage)
        {
            _liveStreamService = liveService;
            _tagService        = tagService;
            _cloudStorage      = cloudStorage;

            Name = nameof(SaveLiveStreamPayload);

            Field <NonNullGraphType <LiveStreamPayload> >("liveStream");
        }
Example #3
0
        public static async Task <IWebHost> SeedData(this IWebHost webHost)
        {
            using (var scope = webHost.Services.GetService <IServiceScopeFactory>().CreateScope())
            {
                using (var context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>())
                {
                    _env               = scope.ServiceProvider.GetRequiredService <IHostingEnvironment>();
                    _configuration     = scope.ServiceProvider.GetRequiredService <IConfiguration>();
                    _cloudStorage      = scope.ServiceProvider.GetRequiredService <ICloudStorage>();
                    _audioService      = scope.ServiceProvider.GetRequiredService <IAudioService <Audio> >();
                    _uploadService     = scope.ServiceProvider.GetRequiredService <IUploadService>();
                    _genreService      = scope.ServiceProvider.GetRequiredService <IGenreService>();
                    _liveStreamService = scope.ServiceProvider.GetRequiredService <ILiveStreamService>();
                    _dirble            = scope.ServiceProvider.GetRequiredService <IDirble>();

                    context.Database.Migrate();

                    var musicGenres = MusicGenres.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true).OfType <DictionaryEntry>().ToArray();
                    var otherGenres = OtherGenres.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true).OfType <DictionaryEntry>().ToArray();

                    await SeedImages();

                    //  await SeedGenres(context);
                    //  await SeedLiveStreams();
                    SeedQuotes(context);

                    _genreService.UpdateCoverImages();

                    LuceneSearch.AddOrUpdateLuceneIndex(_audioService.GetAudios());

                    context.SaveChanges();
                }
            }

            return(webHost);
        }
 public DirbleController(IDirble dirble, ILiveStreamService liveStreamService)
 {
     _dirble            = dirble;
     _liveStreamService = liveStreamService;
 }
Example #5
0
        public AppQuery(ILiveStreamService liveStreamService, IValidationProvider validationProvider,
                        IGenreService genreService, ILoggerFactory loggerFactory, IQuoteService quoteService,
                        SignInManager <ApplicationUser> signInManager, UserManager <ApplicationUser> userManager)
        {
            var logger = loggerFactory.CreateLogger <AppQuery>();

            Field <QuotePayload>()
            .Name("quote")
            .Resolve(c => quoteService.GetRandomQuote());

            Connection <LiveStreamPayload>()
            .Name("liveStreams")
            .Argument <StringGraphType>("genre", "The genre that the live stream belongs to")
            .Argument <StringGraphType>("searchQuery", "The search query to filter the liveStreams against")
            .Argument <FilterInput>("filter", "The filters to apply to the live streams")
            .Resolve(c =>
            {
                var genre       = c.GetArgument <string>("genre");
                var searchQuery = c.GetArgument <string>("searchQuery");
                var filter      = c.GetArgument <Filter.Filter>("filter");
                var offset      = ConnectionUtils.OffsetOrDefault(c.After, 0);
                var page        = ((offset + 1) / c.First.Value) + 2;

                if (filter.Newest)
                {
                    var liveStreams = liveStreamService.GetLiveStreams(c.First.Value * page, genre, searchQuery);

                    return(ConnectionUtils.ToConnection(liveStreams, c));
                }

                return(liveStreamService.GetPopularLiveStreams(page, genre, searchQuery)
                       .ContinueWith(x => ConnectionUtils.ToConnection(x.Result, c)));
            });

            Field <ListGraphType <GenrePayload> >("genres",
                                                  resolve: c => genreService.GetGenres());

            Field <AccountPayload>()
            .Name("user")
            .Resolve(c => c.UserContext.As <Context>().CurrentUser);

            Field <ExternalLoginCallbackPayload>()
            .Name("externalLoginCallback")
            .ResolveAsync(async c =>
            {
                var info = await signInManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    validationProvider.AddError("_error", "Could not get external login information");

                    return(null);
                }

                // Sign in the user with this external login provider if the user already has a login.
                var result           = await signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, true);
                ApplicationUser user = null;

                if (result.Succeeded)
                {
                    user = await signInManager.UserManager.FindByLoginAsync(info.LoginProvider, info.ProviderKey);

                    logger.LogInformation(5, $"User logged in with {info.LoginProvider} provider.");
                }
                var userName = info.Principal.FindFirstValue(ClaimTypes.Name);

                // If the user does not have an account, then ask the user to create an account.
                return(new
                {
                    user,
                    loginProvider = info.LoginProvider,
                    userName
                });
            });


            Field <BooleanGraphType>()
            .Name("confirmEmail")
            .Argument <NonNullGraphType <StringGraphType> >("userId", "The id of the user")
            .Argument <NonNullGraphType <StringGraphType> >("token", "The unique code to verify the email")
            .ResolveAsync(async c =>
            {
                var userId = c.GetArgument <string>("userId");
                var token  = c.GetArgument <string>("token");

                var user = await userManager.FindByIdAsync(userId);

                if (user == null)
                {
                    validationProvider.AddError("_error", "No user could be found");

                    return(null);
                }
                var result = await userManager.ConfirmEmailAsync(user, token);

                if (!result.Succeeded)
                {
                    validationProvider.AddError("_error", "Could not confirm your email. Please try again.");
                }

                return(null);
            });

            Field <ListGraphType <LoginProvidersPayload> >()
            .Name("loginProviders")
            .ResolveAsync(async c =>
            {
                var providers = await signInManager.GetExternalAuthenticationSchemesAsync();

                return(providers);
            });
        }