Exemplo n.º 1
0
        public static void RegisterStorageServices(this IAbstractDependencyInjector di, IHostingEnvironment env)
        {
            // Configure service types.
            di.AddPerThread <ILocalStorage>(provider => {
                var config     = provider.Resolve <IConfiguration>();
                var mlpath     = config["MediaStorage:Local:MediaLibraryPath"];
                var tempMlPath = config["MediaStorage:Local:TempLibraryPath"];

                if (mlpath.StartsWith("~"))
                {
                    mlpath = env.ContentRootPath + mlpath.Substring(1);
                }
                if (tempMlPath.StartsWith("~"))
                {
                    tempMlPath = env.ContentRootPath + tempMlPath.Substring(1);
                }
                return(new LocalStorage(mlpath));
            });

            di.AddPerThread <IStorage>(provider => {
                var config = provider.Resolve <IConfiguration>();
                return(GoogleDriveStorageFactory.Create(
                           config["MediaStorage:GoogleDrive:AppName"],
                           config["MediaStorage:GoogleDrive:ClientId"],
                           config["MediaStorage:GoogleDrive:ClientSecret"]));
            });
        }
Exemplo n.º 2
0
        public static void RegisterStorageServices(this IAbstractDependencyInjector di, IHostingEnvironment env)
        {
            // Configure service types.
            di.AddSingletone <IOuth2CodeSynchronizer, InProcessOuth2CodeSynchronizer>();

            di.AddPerThread <ILocalStorage>(provider => {
                var config     = provider.Resolve <IConfiguration>();
                var mlpath     = config["MediaStorage:Local:MediaLibraryPath"];
                var tempMlPath = config["MediaStorage:Local:TempLibraryPath"];

                if (mlpath.StartsWith("~"))
                {
                    mlpath = env.ContentRootPath + mlpath.Substring(1);
                }
                if (tempMlPath.StartsWith("~"))
                {
                    tempMlPath = env.ContentRootPath + tempMlPath.Substring(1);
                }
                return(new LocalStorage(mlpath));
            });

            di.AddPerThread <IStorage>(provider => {
                var config        = provider.Resolve <IConfiguration>();
                var accessToken   = config["MediaStorage:GoogleDrive:AccessToken"];
                var refreshoken   = config["MediaStorage:GoogleDrive:RefreshToken"];
                var appName       = config["MediaStorage:GoogleDrive:AppName"];
                var clientId      = config["MediaStorage:GoogleDrive:ClientId"];
                var clientSecret  = config["MediaStorage:GoogleDrive:ClientSecret"];
                string folderPath = config.GetValue <string>("MediaStorage:GoogleDrive:DataStoreFolder", string.Empty);
                bool isFullPath   = config.GetValue <bool>("DataStoreFolderIsFullPath", true);

                if (string.IsNullOrEmpty(accessToken))
                {
                    var gdriveStorage = GoogleDriveStorageFactory.Create(appName, clientId, clientSecret);
                    if (!string.IsNullOrEmpty(folderPath))
                    {
                        gdriveStorage.DataStoreFolder = folderPath;
                        gdriveStorage.IsFullPath      = isFullPath;
                    }

                    //gdriveStorage.AuthorizeRedirectUrl = config.GetValue<string>("MediaStorage:GoogleDrive:CodeReceiverUrl", string.Empty);
                    return(gdriveStorage);
                }
                else
                {
                    var gdriveStorage = GoogleDriveStorageFactory.CreateUsingAccessToken(appName, clientId, clientSecret, accessToken, refreshoken);
                    if (!string.IsNullOrEmpty(folderPath))
                    {
                        gdriveStorage.DataStoreFolder = folderPath;
                        gdriveStorage.IsFullPath      = isFullPath;
                    }
                    return(gdriveStorage);
                }
            });
        }
Exemplo n.º 3
0
 public static void RegisterCoreServices(this IAbstractDependencyInjector di)
 {
     // Configure service types.
     di.AddPerThread <IMediaLibraryService, MediaLibraryService>();
     di.AddPerThread <IMediaStreamingService, MediaStreamingService>();
     di.AddPerThread <IMediaUploadService, MediaUploadService>();
     di.AddPerThread <IImageResourceService, ImageResourceService>();
     di.AddPerThread <IStreamingUserService, StreamingUserService>();
     di.AddPerThread <IStreamingUserSessionService, StreamingUserSessionService>();
     di.AddPerThread <IStreamingUserCacheService, StreamingUserCacheService>();
 }
Exemplo n.º 4
0
        static void RegisterServices(IAbstractDependencyInjector di)
        {
            // Microsoft.Extensions.Configuration.IConfigurationRoot
            // Microsoft.Extensions.Configuration.IConfiguration
            //var ss = typeof(Configuration).Name;

            // Add services here.
            di.AddSingletone(Configuration);
            //di.AddPerThread<IMediaDataContext, MediaDataContext>();
            di.AddPerThread <itest, test>();

            di.Build();
        }
Exemplo n.º 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication("MyAuth")
            .AddScheme <MyAuthSchemeOptions, MyAuthenticationHandler>("MyAuth", options => {
                var authSettings = _di.Resolve <IOptions <AuthSettings> >().Value;
                options.Scheme   = "MyAuth";
                options.AccessTokenKeyHeaderName  = authSettings.AccessTokenHeaderName;
                options.SessionInfoContextKeyName = authSettings.SessionInfoContextKeyName;
                options.Expiration = new TimeSpan((authSettings.ExpirationInMin - authSettings.ExpirationInMin % 60) / 60,
                                                  authSettings.ExpirationInMin % 60, 0);
            });

            services.AddMvc();
            services.AddMemoryCache();

            // Configure settings.
            services.AddOptions();
            services.Configure <GoogleDriveSettings>(_configuration.GetSection("MediaStorage:GoogleDrive"));
            services.Configure <LocalDriveSettings>(_configuration.GetSection("MediaStorage:Local"));
            services.Configure <AuthSettings>(_configuration.GetSection("Auth"));

            // Configure dependency abstructor.
            _di = services.UseMicrosoftDI(_serviceProvider);
            _di.AddSingletone(_configuration);
            _di.AddSingletone(_di);
            _di.AddPerThread <AuthenticationHandler <MyAuthSchemeOptions>, MyAuthenticationHandler>();

            // Start registering services.
            _di.RegisterStorageServices(_hostingEnvironment);
            _di.RegisterMediaDataContextServices();
            _di.RegisterStreamingDataContextServices();
            _di.RegisterCoreServices();
            // End registering services.

            return(_di.Build());
        }
Exemplo n.º 6
0
 public static void RegisterStreamingDataContextServices(this IAbstractDependencyInjector di)
 {
     // Configure service types.
     di.AddPerThread <IStreamingDataContext, StreamingDataContext>();
 }