/// <summary>
        /// Add a single file upload task to the upload queue
        /// </summary>
        /// <param name="name">The name of the uploaded file, you need to keep the file after the format suffix name</param>
        /// <param name="file">File stream of uploaded files</param>
        /// <param name="options">Target endpoint setting item</param>
        /// <param name="immediate">Whether to join the priority queue</param>
        /// <returns>Upload receipt of file results</returns>
        public async Task <DeliverStatus> Dispatch(string name, Stream file, FastDfsEndPointOptions options, bool immediate = false)
        {
            var envelope = new Envelope {
                FileName = name, Options = options, Cargo = file
            };

            Envelopes.Enqueue(envelope, immediate);
            return(await Task.Run(() => envelope.Status.Value));
        }
        private FastDfsEndPointOptions InitOptions(Action <FastDfsEndPointOptions> action)
        {
            if (action == null)
            {
                return(DefaultOptionManagement.DefaultOption);
            }

            var option = new FastDfsEndPointOptions
            {
                EndPoint             = DefaultOptionManagement.DefaultOption.EndPoint,
                FilePath             = DefaultOptionManagement.DefaultOption.FilePath,
                Output               = DefaultOptionManagement.DefaultOption.Output,
                Scene                = DefaultOptionManagement.DefaultOption.Scene,
                AuthoritionComponent = DefaultOptionManagement.DefaultOption.AuthoritionComponent
            };

            action.Invoke(option);

            return(option);
        }
        /// <summary>
        /// Add upload tasks to the task queue in batches
        /// </summary>
        /// <param name="files">File name-stream key-value structure set, you can directly use the implementation type of <see cref="IDictionary{String, Stream}"/></param>
        /// <param name="options">Target endpoint setting item</param>
        /// <param name="immediate">Whether to join the priority queue</param>
        /// <returns>Collection of upload file result receipts</returns>
        public async Task <DeliverStatusCollection> Dispatch(ICollection <KeyValuePair <string, Stream> > files, FastDfsEndPointOptions options, bool immediate = false)
        {
            List <Envelope> EnvelopeGroup = new List <Envelope>(files.Count);

            foreach (var item in files)
            {
                var envelope = new Envelope {
                    FileName = item.Key, Options = options, Cargo = item.Value
                };
                EnvelopeGroup.Add(envelope);
                Envelopes.Enqueue(envelope, immediate);
            }
            return(await Task.Run(() => new DeliverStatusCollection(EnvelopeGroup.Select(a => a.Status.Value).ToList())));
        }
        /// <summary>
        /// Create a context to send a file request
        /// </summary>
        /// <param name="name">The name of the uploaded file, you need to keep the file after the format suffix name</param>
        /// <param name="file">File stream of uploaded files</param>
        /// <param name="options">Target endpoint setting item</param>
        /// <returns></returns>
        private MultipartFormDataContent GenerateHttpContent(string name, Stream file, FastDfsEndPointOptions options)
        {
            var Content = new MultipartFormDataContent {
                { new StringContent(options.Output.StringValue()), "output" },
                { new StringContent(options.FilePath ?? string.Empty), "path" },
                { new StringContent(options.Scene ?? string.Empty), "scene" },
            };

            //If an authentication component exists, set the authentication field from the authentication component in the context
            if (options.AuthoritionComponent != null)
            {
                options.AuthoritionComponent.AuthorizeFormSetting(Content, iAuthoritionTokenService.GetToken(options.AuthoritionComponent));
            }

            Content.Add(new StreamContent(file), "file", name);

            return(Content);
        }
Beispiel #5
0
 public static IGoogleAuthBuilder UseGoogleAuthServer(this FastDfsEndPointOptions option) => new GoogleAuthBuilder(option);
Beispiel #6
0
 public static IOIDCAuthBuilder UseOIDCAuthServer(this FastDfsEndPointOptions option, Uri uri) => new OIDCAuthBuilder(option).SetUrl(uri);