示例#1
0
        public FileService(IEntityRepository repository, ISecurityService securityService, IDatabaseService dbService)
        {
            _repository      = repository;
            _securityService = securityService;
            _dbService       = dbService;

            FileServiceConfigurationSection config = ConfigurationManager.GetSection("fileService") as FileServiceConfigurationSection;

            _tempPath   = config.TemporaryStoragePath;
            _permPath   = config.PermanentStoragePath;
            _bufferSize = config.BufferSize;
            _allowed    = new string[config.AllowedExtensions.Count];
            for (int i = 0; i < config.AllowedExtensions.Count; i++)
            {
                _allowed[i] = config.AllowedExtensions[i].Value;
            }
        }
示例#2
0
        void IModule.Initialize()
        {
            FileServiceConfigurationSection config = ConfigurationManager.GetSection("fileService") as FileServiceConfigurationSection;

            //if (!Directory.Exists(config.TemporaryStoragePath))
            //    Directory.CreateDirectory(config.TemporaryStoragePath);
            try
            {
                if (!Directory.Exists(config.PermanentStoragePath))
                {
                    Directory.CreateDirectory(config.PermanentStoragePath);
                }

                using (var dbContext = _dbService.GetDatabaseContext(true))
                {
                    SqlCommand cmd = new SqlCommand("UPDATE [User] SET [DiskUsageLimit]=@limit where [DiskUsageLimit] is null", dbContext.Connection);
                    cmd.Parameters.AddWithValue("@limit", 25 * 1024 * 1024);
                    cmd.ExecuteNonQuery();
                    dbContext.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Could not create file directory for permanent file storage.", ex);
            }
            try
            {
                string test = "test";
                System.IO.File.WriteAllText(Path.Combine(config.PermanentStoragePath, "test.txt"), test);
                System.IO.File.Delete(Path.Combine(config.PermanentStoragePath, "test.txt"));
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("The application cannot write into the permanent file storage directory: {0}", config.PermanentStoragePath), ex);
            }
        }