Exemplo n.º 1
0
        public string PutRevisionFile(string name, long?size, RavenJObject metadata)
        {
            string revisionFile = null;

            fileSystem.Storage.Batch(accessor =>
            {
                FileVersioningConfiguration versioningConfiguration;
                if (TryGetVersioningConfiguration(name, metadata, accessor, out versioningConfiguration) == false)
                {
                    return;
                }

                using (fileSystem.DisableAllTriggersForCurrentThread())
                {
                    var copyHeaders = new RavenJObject(metadata);
                    copyHeaders[VersioningUtil.RavenFileRevisionStatus] = RavenJToken.FromObject("Historical");
                    copyHeaders[Constants.RavenReadOnly] = true;
                    copyHeaders.Remove(VersioningUtil.RavenFileRevision);
                    object parentRevision;
                    metadata.__ExternalState.TryGetValue("Parent-Revision", out parentRevision);
                    if (parentRevision != null)
                    {
                        copyHeaders[VersioningUtil.RavenFileParentRevision] = name + "/revisions/" + parentRevision;
                    }

                    object value;
                    metadata.__ExternalState.TryGetValue("Next-Revision", out value);

                    revisionFile = name + "/revisions/" + value;
                    accessor.PutFile(revisionFile, size, copyHeaders);
                }
            });

            return(revisionFile);
        }
Exemplo n.º 2
0
        private void Prepare()
        {
            fs.Storage.Batch(accessor =>
            {
                // remove previous SyncResult
                fs.Synchronizations.DeleteSynchronizationReport(fileName, accessor);

                using (fs.DisableAllTriggersForCurrentThread())
                {
                    // remove previous .downloading file
                    fs.Files.IndicateFileToDelete(RavenFileNameHelper.DownloadingFileName(fileName), null);
                }
            });
        }
Exemplo n.º 3
0
        protected StorageStream(RavenFileSystem fileSystem, ITransactionalStorage storage, string fileName, RavenJObject metadata, StorageStreamAccess storageStreamAccess)
        {
            this.fileSystem = fileSystem;
            this.storage    = storage;

            StorageStreamAccess = storageStreamAccess;
            Name = fileName;

            switch (storageStreamAccess)
            {
            case StorageStreamAccess.Read:
                storage.Batch(accessor => fileHeader = accessor.ReadFile(fileName));
                if (fileHeader.TotalSize == null)
                {
                    throw new FileNotFoundException("File is not uploaded yet");
                }
                Metadata = fileHeader.Metadata;
                Seek(0, SeekOrigin.Begin);
                break;

            case StorageStreamAccess.CreateAndWrite:

                if (this.fileSystem == null)
                {
                    throw new ArgumentNullException("fileSystem");
                }

                storage.Batch(accessor =>
                {
                    using (fileSystem.DisableAllTriggersForCurrentThread())
                    {
                        fileSystem.Files.IndicateFileToDelete(fileName, null);
                    }

                    var putResult = accessor.PutFile(fileName, null, metadata);
                    fileSystem.Search.Index(fileName, metadata, putResult.Etag);
                });
                Metadata = metadata;
                break;

            default:
                throw new ArgumentOutOfRangeException("storageStreamAccess", storageStreamAccess, "Unknown value");
            }
        }
Exemplo n.º 4
0
        protected StorageStream(RavenFileSystem fileSystem, ITransactionalStorage storage, string fileName, RavenJObject metadata, StorageStreamAccess storageStreamAccess)
        {
            this.fileSystem = fileSystem;
            this.storage = storage;

            StorageStreamAccess = storageStreamAccess;
            Name = fileName;

            switch (storageStreamAccess)
            {
                case StorageStreamAccess.Read:
                    storage.Batch(accessor => fileHeader = accessor.ReadFile(fileName));
                    if (fileHeader.TotalSize == null)
                    {
                        throw new FileNotFoundException("File is not uploaded yet");
                    }
                    Metadata = fileHeader.Metadata;
                    Seek(0, SeekOrigin.Begin);
                    break;
                case StorageStreamAccess.CreateAndWrite:

                    if (this.fileSystem == null)
                        throw new ArgumentNullException("fileSystem");

                    storage.Batch(accessor =>
                    {
                        using (fileSystem.DisableAllTriggersForCurrentThread())
                        {
                            fileSystem.Files.IndicateFileToDelete(fileName, null);
                        }

                        var putResult = accessor.PutFile(fileName, null, metadata);
                        fileSystem.Search.Index(fileName, metadata, putResult.Etag);
                    });
                    Metadata = metadata;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("storageStreamAccess", storageStreamAccess, "Unknown value");
            }
        }