Beispiel #1
0
        protected StorageStream(ITransactionalStorage transactionalStorage, string fileName,
                                StorageStreamAccess storageStreamAccess,
                                RavenJObject metadata, IndexStorage indexStorage, StorageOperationsTask operations)
        {
            TransactionalStorage = transactionalStorage;
            StorageStreamAccess  = storageStreamAccess;
            Name = fileName;

            switch (storageStreamAccess)
            {
            case StorageStreamAccess.Read:
                TransactionalStorage.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:
                TransactionalStorage.Batch(accessor =>
                {
                    operations.IndicateFileToDelete(fileName);
                    accessor.PutFile(fileName, null, metadata);
                    indexStorage.Index(fileName, metadata);
                });
                Metadata = metadata;
                break;

            default:
                throw new ArgumentOutOfRangeException("storageStreamAccess", storageStreamAccess, "Unknown value");
            }
        }
Beispiel #2
0
        public void Create(string fileName, ConflictItem conflict)
        {
            RavenJObject metadata = null;

            storage.Batch(
                accessor =>
            {
                metadata = accessor.GetFile(fileName, 0, 0).Metadata;
                accessor.SetConfig(RavenFileNameHelper.ConflictConfigNameForFile(fileName), JsonExtensions.ToJObject(conflict));
                metadata[SynchronizationConstants.RavenSynchronizationConflict] = true;
                accessor.UpdateFileMetadata(fileName, metadata);
            });

            if (metadata != null)
            {
                index.Index(fileName, metadata);
            }
        }
Beispiel #3
0
        public void RenameFile(RenameFileOperation operation)
        {
            var configName = RavenFileNameHelper.RenameOperationConfigNameForFile(operation.Name);

            notificationPublisher.Publish(new FileChangeNotification
            {
                File   = FilePathTools.Cannoicalise(operation.Name),
                Action = FileChangeAction.Renaming
            });

            storage.Batch(accessor =>
            {
                var previousRenameTombstone = accessor.ReadFile(operation.Rename);

                if (previousRenameTombstone != null &&
                    previousRenameTombstone.Metadata[SynchronizationConstants.RavenDeleteMarker] != null)
                {
                    // if there is a tombstone delete it
                    accessor.Delete(previousRenameTombstone.FullPath);
                }

                accessor.RenameFile(operation.Name, operation.Rename, true);
                accessor.UpdateFileMetadata(operation.Rename, operation.MetadataAfterOperation);

                // copy renaming file metadata and set special markers
                var tombstoneMetadata = new RavenJObject(operation.MetadataAfterOperation).WithRenameMarkers(operation.Rename);

                accessor.PutFile(operation.Name, 0, tombstoneMetadata, true); // put rename tombstone

                accessor.DeleteConfig(configName);

                search.Delete(operation.Name);
                search.Index(operation.Rename, operation.MetadataAfterOperation);
            });

            notificationPublisher.Publish(new ConfigurationChangeNotification {
                Name = configName, Action = ConfigurationChangeAction.Set
            });
            notificationPublisher.Publish(new FileChangeNotification
            {
                File   = FilePathTools.Cannoicalise(operation.Rename),
                Action = FileChangeAction.Renamed
            });
        }