コード例 #1
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="storage">The main file storage</param>
 /// <param name="basePath">The base path</param>
 /// <param name="baseUrl">The base url</param>
 /// <param name="naming">How uploaded media files should be named</param>
 public FileStorageSession(FileStorage storage, string basePath, string baseUrl, FileStorageNaming naming)
 {
     _storage  = storage;
     _basePath = basePath;
     _baseUrl  = baseUrl;
     _naming   = naming;
 }
コード例 #2
0
    /// <summary>
    /// Adds the FileStorage module if simple startup is used.
    /// </summary>
    /// <param name="serviceBuilder">The service builder</param>
    /// <param name="basePath">The optional base path for where uploaded media is stored.null Default is wwwroot/uploads/</param>
    /// <param name="baseUrl">The optional base url for accessing uploaded media. Default is ~/uploads/</param>
    /// <param name="naming">How uploaded media files should be named</param>
    /// <param name="scope">The optional service scope. Default is singleton</param>
    /// <returns>The updated builder</returns>
    public static PiranhaServiceBuilder UseFileStorage(
        this PiranhaServiceBuilder serviceBuilder,
        string basePath          = null,
        string baseUrl           = null,
        FileStorageNaming naming = FileStorageNaming.UniqueFileNames,
        ServiceLifetime scope    = ServiceLifetime.Singleton)
    {
        serviceBuilder.Services.AddPiranhaFileStorage(basePath, baseUrl, naming, scope);

        return(serviceBuilder);
    }
コード例 #3
0
    /// <summary>
    /// Adds the services for the local FileStorage service.
    /// </summary>
    /// <param name="services">The current service collection</param>
    /// <param name="basePath">The optional base path for where uploaded media is stored.null Default is wwwroot/uploads/</param>
    /// <param name="baseUrl">The optional base url for accessing uploaded media. Default is ~/uploads/</param>
    /// <param name="naming">How uploaded media files should be named</param>
    /// <param name="scope">The optional service scope. Default is singleton</param>
    /// <returns>The service collection</returns>
    public static IServiceCollection AddPiranhaFileStorage(
        this IServiceCollection services,
        string basePath          = null,
        string baseUrl           = null,
        FileStorageNaming naming = FileStorageNaming.UniqueFileNames,
        ServiceLifetime scope    = ServiceLifetime.Singleton)
    {
        App.Modules.Register <FileStorageModule>();

        services.Add(new ServiceDescriptor(typeof(IStorage), sp => new FileStorage(basePath, baseUrl, naming), scope));

        return(services);
    }
コード例 #4
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="basePath">The optional base path</param>
        /// <param name="baseUrl">The optional base url</param>
        /// <param name="naming">How uploaded media files should be named</param>
        public FileStorage(
            string basePath          = null,
            string baseUrl           = null,
            FileStorageNaming naming = FileStorageNaming.UniqueFileNames)
        {
            if (!string.IsNullOrEmpty(basePath))
            {
                _basePath = basePath;
            }
            if (!string.IsNullOrEmpty(baseUrl))
            {
                _baseUrl = baseUrl;
            }

            if (!Directory.Exists(_basePath))
            {
                Directory.CreateDirectory(_basePath);
            }

            _naming = naming;
        }