Пример #1
0
        /// <summary>
        /// Updates the specified file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="stream">The binary stream.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken" /> used to propagate notifications that the operation should be canceled.</param>
        /// <returns></returns>
        public async Task UpdateAsync(File file, Stream stream, CancellationToken cancellationToken)
        {
            // use file guid instead name
            var queryOptions = new FileQueryOptions()
            {
                Type = file.Type
            };

            queryOptions.DocumentIds.Add(file.DocumentId);
            var filesToRemove = await FileStore.FindAsync(queryOptions, cancellationToken);

            foreach (var fileToRemove in filesToRemove)
            {
                BinaryProvider.Delete(fileToRemove.Reference);
            }

            await FileStore.UpdateAsync(file, cancellationToken);

            var reference = BinaryProvider.InitUpload(file.Id.ToString(CultureInfo.CurrentCulture));
            await FileStore.InitAsync(file.Id, BinaryProvider.AssemblyQualifiedName, reference, cancellationToken);

            await BinaryProvider.FinalizeUploadAsync(reference, stream, cancellationToken);

            await FileStore.FinalizeAsync(file.Id, cancellationToken);
        }
Пример #2
0
        /// <summary>
        /// Adds the specified file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="stream">The binary stream.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken" /> used to propagate notifications that the operation should be canceled.</param>
        /// <returns></returns>
        public async Task <long> CreateAsync(File file, Stream stream, CancellationToken cancellationToken)
        {
            // use file guid instead name
            var id = await FileStore.CreateAsync(file, cancellationToken);

            var reference = BinaryProvider.InitUpload(id.ToString(CultureInfo.CurrentCulture));
            await FileStore.InitAsync(id, BinaryProvider.AssemblyQualifiedName, reference, cancellationToken);

            await BinaryProvider.FinalizeUploadAsync(reference, stream, cancellationToken);

            await FileStore.FinalizeAsync(id, cancellationToken);

            return(id);
        }