public static List <YoutubeVideoItem> GetVideos(List <string> videoIds) { List <YoutubeVideoItem> videos = new List <YoutubeVideoItem>(); HttpCacheProvider cacheProvider = new HttpCacheProvider(); // Todo: Return result object with status message and result try { var youTube = GetYouTubeService(); //Build up request var videoRequest = youTube.PlaylistItems.List("snippet,contentDetails, statistics"); videoRequest.MaxResults = _noPerPage; //3 per page foreach (var videoId in videoIds) { var cacheItem = cacheProvider.GetItem <YoutubeVideoItem>(videoId); if (cacheItem != null) { videos.Add(cacheItem); continue; } //Perform request VideoListResponse videoResponse = GetVideo(videoId); if (videoResponse == null && !videoResponse.Items.Any()) { continue; } var videoItem = new YoutubeVideoItem() { Title = videoResponse.Items.FirstOrDefault().Snippet.Title, Id = videoResponse.Items.FirstOrDefault().Id, PublishDate = videoResponse.Items.FirstOrDefault().Snippet.PublishedAt, Image = videoResponse.Items.FirstOrDefault().Snippet.Thumbnails.High.Url, Url = string.Format("https://www.youtube.com/embed/{0}?rel=0", videoResponse.Items.FirstOrDefault().Id), ExternalUrl = string.Format("https://www.youtube.com/watch?v={0}", videoResponse.Items.FirstOrDefault().Id), WatchCount = videoResponse.Items.FirstOrDefault().Statistics.ViewCount.ToString() }; videos.Add(videoItem); cacheProvider.InsertItem <YoutubeVideoItem>(videoId, videoItem, TimeSpan.FromHours(1)); } } catch (Exception ex) { // Todo: Implement error handling } //Return the list of videos we find return(videos); }
private static void InitializePlatform(IUnityContainer container, string connectionStringName) { #region Setup database using (var db = new SecurityDbContext(connectionStringName)) { new IdentityDatabaseInitializer().InitializeDatabase(db); } using (var context = new PlatformRepository(connectionStringName, new AuditableInterceptor(), new EntityPrimaryKeyGeneratorInterceptor())) { new PlatformDatabaseInitializer().InitializeDatabase(context); } // Create Hangfire tables new SqlServerStorage(connectionStringName); #endregion Func <IPlatformRepository> platformRepositoryFactory = () => new PlatformRepository(connectionStringName, new AuditableInterceptor(), new EntityPrimaryKeyGeneratorInterceptor()); container.RegisterType <IPlatformRepository>(new InjectionFactory(c => platformRepositoryFactory())); container.RegisterInstance <Func <IPlatformRepository> >(platformRepositoryFactory); var moduleCatalog = container.Resolve <IModuleCatalog>(); var manifestProvider = container.Resolve <IModuleManifestProvider>(); #region Caching var cacheProvider = new HttpCacheProvider(); var cacheSettings = new[] { new CacheSettings(CacheGroups.Settings, TimeSpan.FromDays(1)), new CacheSettings(CacheGroups.Security, TimeSpan.FromMinutes(1)), }; var cacheManager = new CacheManager(cacheProvider, cacheSettings); container.RegisterInstance <CacheManager>(cacheManager); #endregion #region Settings var platformSettings = new[] { new ModuleManifest { Settings = new[] { new ModuleSettingsGroup { Name = "Platform|Notifications|SendGrid", Settings = new [] { new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SendGrid.UserName", ValueType = ModuleSetting.TypeString, Title = "SendGrid UserName", Description = "Your SendGrid account username" }, new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SendGrid.Secret", ValueType = ModuleSetting.TypeString, Title = "SendGrid Password", Description = "Your SendGrid account password" } } }, new ModuleSettingsGroup { Name = "Platform|Notifications|SendingJob", Settings = new [] { new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SendingJob.TakeCount", ValueType = ModuleSetting.TypeInteger, Title = "Job Take Count", Description = "Take count for sending job" } } } } } }; var settingsManager = new SettingsManager(manifestProvider, platformRepositoryFactory, cacheManager, platformSettings); container.RegisterInstance <ISettingsManager>(settingsManager); #endregion #region Dynamic Properties container.RegisterType <IDynamicPropertyService, DynamicPropertyService>(); #endregion #region Notifications var hubSignalR = GlobalHost.ConnectionManager.GetHubContext <ClientPushHub>(); var notifier = new InMemoryNotifierImpl(hubSignalR); container.RegisterInstance <INotifier>(notifier); var resolver = new LiquidNotificationTemplateResolver(); var notificationTemplateService = new NotificationTemplateServiceImpl(platformRepositoryFactory); var notificationManager = new NotificationManager(resolver, platformRepositoryFactory, notificationTemplateService); var emailNotificationSendingGateway = new DefaultEmailNotificationSendingGateway(settingsManager); var defaultSmsNotificationSendingGateway = new DefaultSmsNotificationSendingGateway(); container.RegisterInstance <INotificationTemplateService>(notificationTemplateService); container.RegisterInstance <INotificationManager>(notificationManager); container.RegisterInstance <INotificationTemplateResolver>(resolver); container.RegisterInstance <IEmailNotificationSendingGateway>(emailNotificationSendingGateway); container.RegisterInstance <ISmsNotificationSendingGateway>(defaultSmsNotificationSendingGateway); //notificationManager.RegisterNotificationType( // () => new RegistrationSmsNotification(defaultSmsNotificationSendingGateway) // { // DisplayName = "Registration notification", // Description = "This notification sends by sms to client when he finish registration", // ObjectId = "Platform", // NotificationTemplate = new NotificationTemplate // { // Body = @"Dear {{ context.first_name }} {{ context.last_name }}, you has registered on our site. Your login - {{ context.login }} Your login - {{ context.password }}", // Subject = @"", // NotificationTypeId = "RegistrationSmsNotification", // ObjectId = "Platform" // } // } //); #endregion #region Assets var assetsConnection = ConfigurationManager.ConnectionStrings["AssetsConnectionString"]; if (assetsConnection != null) { var properties = assetsConnection.ConnectionString.ToDictionary(";", "="); var provider = properties["provider"]; var assetsConnectionString = properties.ToString(";", "=", "provider"); if (string.Equals(provider, FileSystemBlobProvider.ProviderName, StringComparison.OrdinalIgnoreCase)) { var fileSystemBlobProvider = new FileSystemBlobProvider(assetsConnectionString); container.RegisterInstance <IBlobStorageProvider>(fileSystemBlobProvider); container.RegisterInstance <IBlobUrlResolver>(fileSystemBlobProvider); } else if (string.Equals(provider, AzureBlobProvider.ProviderName, StringComparison.OrdinalIgnoreCase)) { var azureBlobProvider = new AzureBlobProvider(assetsConnectionString); container.RegisterInstance <IBlobStorageProvider>(azureBlobProvider); container.RegisterInstance <IBlobUrlResolver>(azureBlobProvider); } } #endregion #region Packaging var sourcePath = HostingEnvironment.MapPath("~/App_Data/SourcePackages"); var packagesPath = HostingEnvironment.MapPath("~/App_Data/InstalledPackages"); var packageService = new ZipPackageService(moduleCatalog, manifestProvider, packagesPath, sourcePath); container.RegisterInstance <IPackageService>(packageService); container.RegisterType <ModulesController>(new InjectionConstructor(packageService, sourcePath)); #endregion #region ChangeLogging var changeLogService = new ChangeLogService(platformRepositoryFactory); container.RegisterInstance <IChangeLogService>(changeLogService); #endregion #region Security var permissionService = new PermissionService(platformRepositoryFactory, manifestProvider, cacheManager); container.RegisterInstance <IPermissionService>(permissionService); container.RegisterType <IRoleManagementService, RoleManagementService>(new ContainerControlledLifetimeManager()); var apiAccountProvider = new ApiAccountProvider(platformRepositoryFactory, cacheManager); container.RegisterInstance <IApiAccountProvider>(apiAccountProvider); container.RegisterType <IClaimsIdentityProvider, ApplicationClaimsIdentityProvider>(new ContainerControlledLifetimeManager()); container.RegisterType <ApplicationSignInManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Get <ApplicationSignInManager>())); container.RegisterType <ApplicationUserManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>())); container.RegisterType <IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication)); container.RegisterType <ISecurityService, SecurityService>(); #endregion #region ExportImport container.RegisterType <IPlatformExportImportManager, PlatformExportImportManager>(); #endregion }
private static void InitializePlatform(IAppBuilder app, IUnityContainer container, string connectionStringName) { #region Setup database using (var db = new SecurityDbContext(connectionStringName)) { new IdentityDatabaseInitializer().InitializeDatabase(db); } using (var context = new PlatformRepository(connectionStringName, new AuditableInterceptor(), new EntityPrimaryKeyGeneratorInterceptor())) { new PlatformDatabaseInitializer().InitializeDatabase(context); } // Create Hangfire tables new SqlServerStorage(connectionStringName); #endregion Func <IPlatformRepository> platformRepositoryFactory = () => new PlatformRepository(connectionStringName, new AuditableInterceptor(), new EntityPrimaryKeyGeneratorInterceptor()); container.RegisterType <IPlatformRepository>(new InjectionFactory(c => platformRepositoryFactory())); container.RegisterInstance(platformRepositoryFactory); var moduleCatalog = container.Resolve <IModuleCatalog>(); var manifestProvider = container.Resolve <IModuleManifestProvider>(); #region Caching var cacheProvider = new HttpCacheProvider(); var cacheSettings = new[] { new CacheSettings(CacheGroups.Settings, TimeSpan.FromDays(1)), new CacheSettings(CacheGroups.Security, TimeSpan.FromMinutes(1)), }; var cacheManager = new CacheManager(cacheProvider, cacheSettings); container.RegisterInstance(cacheManager); #endregion #region Settings var platformSettings = new[] { new ModuleManifest { Settings = new[] { new ModuleSettingsGroup { Name = "Platform|Notifications|SendGrid", Settings = new [] { new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SendGrid.UserName", ValueType = ModuleSetting.TypeString, Title = "SendGrid UserName", Description = "Your SendGrid account username" }, new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SendGrid.Secret", ValueType = ModuleSetting.TypeString, Title = "SendGrid Password", Description = "Your SendGrid account password" } } }, new ModuleSettingsGroup { Name = "Platform|Notifications|SendingJob", Settings = new [] { new ModuleSetting { Name = "VirtoCommerce.Platform.Notifications.SendingJob.TakeCount", ValueType = ModuleSetting.TypeInteger, Title = "Job Take Count", Description = "Take count for sending job" } } }, new ModuleSettingsGroup { Name = "Platform|Security", Settings = new [] { new ModuleSetting { Name = "VirtoCommerce.Platform.Security.AccountTypes", ValueType = ModuleSetting.TypeString, Title = "Account types", Description = "Dictionary for possible account types", IsArray = true, ArrayValues = Enum.GetNames(typeof(AccountType)), DefaultValue = AccountType.Manager.ToString() } } } } } }; var settingsManager = new SettingsManager(manifestProvider, platformRepositoryFactory, cacheManager, platformSettings); container.RegisterInstance <ISettingsManager>(settingsManager); #endregion #region Dynamic Properties container.RegisterType <IDynamicPropertyService, DynamicPropertyService>(); #endregion #region Notifications var hubSignalR = GlobalHost.ConnectionManager.GetHubContext <ClientPushHub>(); var notifier = new InMemoryPushNotificationManager(hubSignalR); container.RegisterInstance <IPushNotificationManager>(notifier); var resolver = new LiquidNotificationTemplateResolver(); var notificationTemplateService = new NotificationTemplateServiceImpl(platformRepositoryFactory); var notificationManager = new NotificationManager(resolver, platformRepositoryFactory, notificationTemplateService); var emailNotificationSendingGateway = new DefaultEmailNotificationSendingGateway(settingsManager); var defaultSmsNotificationSendingGateway = new DefaultSmsNotificationSendingGateway(); container.RegisterInstance <INotificationTemplateService>(notificationTemplateService); container.RegisterInstance <INotificationManager>(notificationManager); container.RegisterInstance <INotificationTemplateResolver>(resolver); container.RegisterInstance <IEmailNotificationSendingGateway>(emailNotificationSendingGateway); container.RegisterInstance <ISmsNotificationSendingGateway>(defaultSmsNotificationSendingGateway); #endregion #region Assets var assetsConnection = ConfigurationManager.ConnectionStrings["AssetsConnectionString"]; if (assetsConnection != null) { var properties = assetsConnection.ConnectionString.ToDictionary(";", "="); var provider = properties["provider"]; var assetsConnectionString = properties.ToString(";", "=", "provider"); if (string.Equals(provider, FileSystemBlobProvider.ProviderName, StringComparison.OrdinalIgnoreCase)) { var fileSystemBlobProvider = new FileSystemBlobProvider(assetsConnectionString); container.RegisterInstance <IBlobStorageProvider>(fileSystemBlobProvider); container.RegisterInstance <IBlobUrlResolver>(fileSystemBlobProvider); } else if (string.Equals(provider, AzureBlobProvider.ProviderName, StringComparison.OrdinalIgnoreCase)) { var azureBlobProvider = new AzureBlobProvider(assetsConnectionString); container.RegisterInstance <IBlobStorageProvider>(azureBlobProvider); container.RegisterInstance <IBlobUrlResolver>(azureBlobProvider); } } #endregion #region Packaging var packagesPath = HostingEnvironment.MapPath(VirtualRoot + "/App_Data/InstalledPackages"); var packageService = new ZipPackageService(moduleCatalog, manifestProvider, packagesPath); container.RegisterInstance <IPackageService>(packageService); var uploadsPath = HostingEnvironment.MapPath(VirtualRoot + "/App_Data/Uploads"); container.RegisterType <ModulesController>(new InjectionConstructor(packageService, uploadsPath, notifier)); #endregion #region ChangeLogging var changeLogService = new ChangeLogService(platformRepositoryFactory); container.RegisterInstance <IChangeLogService>(changeLogService); #endregion #region Security container.RegisterInstance <IPermissionScopeService>(new PermissionScopeService()); container.RegisterType <IRoleManagementService, RoleManagementService>(new ContainerControlledLifetimeManager()); var apiAccountProvider = new ApiAccountProvider(platformRepositoryFactory, cacheManager); container.RegisterInstance <IApiAccountProvider>(apiAccountProvider); container.RegisterType <IClaimsIdentityProvider, ApplicationClaimsIdentityProvider>(new ContainerControlledLifetimeManager()); container.RegisterInstance(app.GetDataProtectionProvider()); container.RegisterType <SecurityDbContext>(new InjectionConstructor(connectionStringName)); container.RegisterType <IUserStore <ApplicationUser>, ApplicationUserStore>(); container.RegisterType <IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication)); container.RegisterType <ApplicationUserManager>(); container.RegisterType <ApplicationSignInManager>(); var nonEditableUsers = ConfigurationManager.AppSettings.GetValue("VirtoCommerce:NonEditableUsers", string.Empty); container.RegisterInstance <ISecurityOptions>(new SecurityOptions(nonEditableUsers)); container.RegisterType <ISecurityService, SecurityService>(); #endregion #region ExportImport container.RegisterType <IPlatformExportImportManager, PlatformExportImportManager>(); #endregion }
public static List <YoutubeVideoItem> GetLastestVideosForPlayLists(List <string> playListIds) { List <YoutubeVideoItem> videos = new List <YoutubeVideoItem>(); HttpCacheProvider cacheProvider = new HttpCacheProvider(); var youTube = GetYouTubeService(); //Build up request var videoRequest = youTube.PlaylistItems.List("snippet,contentDetails"); videoRequest.MaxResults = _noPerPage; //3 per page foreach (var playlistId in playListIds) { var cacheItem = cacheProvider.GetItem <YoutubeVideoItem>(playlistId); if (cacheItem != null) { videos.Add(cacheItem); continue; } videoRequest.PlaylistId = playlistId; //Get videos for playlist only //Perform request var videoResponse = videoRequest.Execute(); var currentPlayList = videoResponse.Items.FirstOrDefault(); if (currentPlayList == null) { continue; } int y = 1; while (currentPlayList != null && currentPlayList.Snippet.Title == "Private video") { if (y > videoResponse.Items.Count()) { break; } currentPlayList = videoResponse.Items.ElementAt(y); y++; } Tuple <string, DateTime?> extraInfo = GetExtraInfo(currentPlayList.ContentDetails.VideoId); if (extraInfo == null) { continue; } var videoItem = new YoutubeVideoItem() { Title = currentPlayList.Snippet.Title, Id = currentPlayList.ContentDetails.VideoId, PublishDate = extraInfo.Item2, Image = currentPlayList.Snippet.Thumbnails != null ? currentPlayList.Snippet.Thumbnails.Maxres != null ? currentPlayList.Snippet.Thumbnails.Maxres.Url : currentPlayList.Snippet.Thumbnails.Standard?.Url : string.Empty, Url = string.Format("https://www.youtube.com/embed/{0}?rel=0", currentPlayList.ContentDetails.VideoId), ExternalUrl = string.Format("https://www.youtube.com/watch?v={0}", currentPlayList.ContentDetails.VideoId), WatchCount = extraInfo.Item1 }; videos.Add(videoItem); cacheProvider.InsertItem <YoutubeVideoItem>(playlistId, videoItem, TimeSpan.FromHours(1)); } //Return the list of videos we find return(videos); }
public CacheController(ILog ilog, IMemoryCache memoryCache, IConfiguration configuration) : base(ilog) { this.cacheProvider = CacheProvider.GetInstance(memoryCache, configuration, ilog); this.httpCacheProvider = cacheProvider.HttpCache; this.redisCacheProvider = cacheProvider.RedisCache; }