コード例 #1
0
ファイル: Startup.cs プロジェクト: arobert2/StreamNet
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
            var connectionString = OptionsFactory.GetConnectionString().DefaultConnection;

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             //Configuration.GetConnectionString("DefaultConnection")));
                                                             connectionString));

            services.AddIdentity <AppIdentityUser, IdentityRole <Guid> >()
            .AddDefaultTokenProviders()
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.AddSingleton <StreamCache>();
            services.AddTransient(typeof(FileStoreOptions), fso => new OptionsFactory().GetOptions <FileStoreOptions>());
            services.AddTransient(typeof(VideoRepositoryOptions), vro => new OptionsFactory().GetOptions <VideoRepositoryOptions>());

            services.AddMvc(o => o.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: arobert2/StreamNet
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            ConnectionString connectionString = OptionsFactory.GetConnectionString();

            services.AddControllers();
            services.AddDbContext <ApplicationDbContext>(options =>
            {
                options.UseSqlServer(
                    connectionString.DefaultConnection,
                    b => b.MigrationsAssembly("StreamNet.Server.CMS"));
            });
        }
コード例 #3
0
ファイル: ContentScanner.cs プロジェクト: arobert2/StreamNet
        public static void Main(string[] args)
        {
            _connectionString = OptionsFactory.GetConnectionString();                   //Get connection string options
            _fileStoreOptions = OptionsFactory.GetFileStoreOptions();                   //Get file store options
            _dbContext        = new ApplicationDbContext(                               //Create database context
                new DbContextOptionsBuilder <ApplicationDbContext>()
                .UseSqlServer(_connectionString.DefaultConnection).Options);

            //Fill default picture data
            using (FileStream fs = new FileStream("NoPicture.png", FileMode.Open, FileAccess.Read))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    fs.CopyTo(ms);
                    _defaultImagedata = ms.ToArray();
                }
            }

            bool error = false;                                                         //If an error was thrown.

            InitializeFileSystem();                                                     //Make folders if they don't exist.
            var filenames = Directory.GetFiles(_fileStoreOptions.DumpPath);

            if (filenames.Length == 0)
            {
                System.Diagnostics.Debug.WriteLine("No new files to add.");
                return;
            }
            foreach (var fp in filenames)          //Create DB entries and copy files to correct locations.
            {
                try
                {
                    CopyFileToMediaLibrary(fp);
                }
                catch (UnsupportedFileException ex)                                     //If unsupported type move to rejected path.
                {
                    var adminMessage = CreateAdminMessage(string.Format("Failed to add {0} to database. File type {1} incompatible.", ex.FileName, ex.MediaType), ErrorStatus.error);
                    _dbContext.AdminMessages.Add(adminMessage);
                    //Rejected path
                    string rejectpath = Path.Combine(_fileStoreOptions.RejectedPath, Path.GetFileName(fp));
                    //Move rejected file
                    File.Move(fp, rejectpath);
                    error = true;
                    continue;
                }
                catch (Exception ex)                                                     //Halt program if other error.
                {
                    var adminMessage = CreateAdminMessage(string.Format("ContentScanner failed with the following error: {0}", ex.Message), ErrorStatus.error);
                    _dbContext.AdminMessages.Add(adminMessage);
                    error = true;
                    throw ex;
                }
            }
            if (error)
            {
                System.Diagnostics.Debug.WriteLine("Process ended with errors.");       //Report program ended with errors.
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Process ended successfully.");      //Report program ended without errors.
            }
        }