コード例 #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");
			}
		}
コード例 #2
0
ファイル: AsyncFilesSession.cs プロジェクト: GorelH/ravendb
        public async Task<FileHeader> LoadFileAsync(string filename)
        {
            if (string.IsNullOrWhiteSpace(filename))
                throw new ArgumentNullException("filename", "The filename cannot be null, empty or whitespace.");

			FileHeader existingEntity;
            if (entitiesByKey.TryGetValue(filename, out existingEntity))
            {
                // Check if the file is not currently been scheduled for deletion or known to be non-existent.
                if (!this.IsDeleted(filename))
                    return existingEntity;
                else
                    return null;
            }

            IncrementRequestCount();            

            // Check if the file exists on the server.
            var metadata = await Commands.GetMetadataForAsync(filename);
            if (metadata == null)
                return null;

            var fileHeader = new FileHeader(filename, metadata);
            AddToCache(filename, fileHeader);

            return fileHeader;
        }
コード例 #3
0
        public UpdateMetadataOperation(InMemoryFilesSessionOperations sessionOperations, FileHeader fileHeader, RavenJObject metadata)
        {
            if (fileHeader != null && string.IsNullOrWhiteSpace(fileHeader.FullPath))
                throw new ArgumentNullException("fileHeader", "The file cannot be null or have an empty or whitespace name.");

            this.sessionOperations = sessionOperations;

            this.FileHeader = fileHeader;
            this.Filename = fileHeader.FullPath;
            this.Metadata = metadata;
        }
コード例 #4
0
        public UpdateMetadataOperation(InMemoryFilesSessionOperations sessionOperations, FileHeader fileHeader, RavenJObject metadata, Etag etag)
        {
            if (fileHeader == null || string.IsNullOrWhiteSpace(fileHeader.FullPath))
                throw new ArgumentNullException("fileHeader", "The file cannot be null or have an empty or whitespace name!");

            this.sessionOperations = sessionOperations;

            FileHeader = fileHeader;
            FileName = fileHeader.FullPath;
            Metadata = metadata;
            Etag = etag;
        }
コード例 #5
0
ファイル: SerializationTests.cs プロジェクト: GorelH/ravendb
        public void ConflictNotificationSerialization()
        {
			var metadata = new RavenJObject { { Constants.LastModified, "2014-07-07T12:00:00.0000000" }, { Constants.FileSystem.RavenFsSize, "128" } };
            var fileHeader = new FileHeader("test1.file", metadata);
            var notification = new ConflictNotification() { FileName = "test1.file", SourceServerUrl = "http://destination", RemoteFileHeader = fileHeader, Status = ConflictStatus.Detected};

            var serializedValue = JsonExtensions.ToJObject(notification);

            var jr = new RavenJTokenReader(serializedValue);
            var deserializedValue = JsonExtensions.CreateDefaultJsonSerializer().Deserialize<ConflictNotification>(jr);

            Assert.NotNull(deserializedValue);
        }
コード例 #6
0
ファイル: SerializationTests.cs プロジェクト: GorelH/ravendb
        public void FileHeaderSerialization()
        {
			var metadata = new RavenJObject { { Constants.LastModified, "2014-07-07T12:00:00.0000000" }, { Constants.FileSystem.RavenFsSize, "128" } };
            var fileHeader = new FileHeader("test1.file", metadata);

            var serializedValue = JsonExtensions.ToJObject(fileHeader);

            var jr = new RavenJTokenReader(serializedValue);
            var deserializedValue = JsonExtensions.CreateDefaultJsonSerializer().Deserialize<FileHeader>(jr);

            Assert.NotNull(deserializedValue);
            Assert.Equal(fileHeader.Name, deserializedValue.Name);
            Assert.Equal(fileHeader.LastModified, deserializedValue.LastModified);
        }
コード例 #7
0
        public bool Filter(FileHeader file, Guid destinationId, IEnumerable<FileHeader> candidatesToSynchronization)
		{
			// prevent synchronization back to source
			if (file.Metadata.Value<Guid>(SynchronizationConstants.RavenSynchronizationSource) == destinationId)
				return false;

            if (file.FullPath.EndsWith(RavenFileNameHelper.DownloadingFileSuffix))
				return false;

            if (file.FullPath.EndsWith(RavenFileNameHelper.DeletingFileSuffix))
				return false;

			if (file.IsFileBeingUploadedOrUploadHasBeenBroken())
				return false;

            if (ExistsRenameTombstone(file.FullPath, candidatesToSynchronization))
				return false;

			return true;
		}
コード例 #8
0
ファイル: StorageStream.cs プロジェクト: j2jensen/ravendb
        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");
            }
        }
コード例 #9
0
        public bool EntityChanged(FileHeader fileHeader)
        {
            if (fileHeader == null)
                return true;

            return RavenJToken.DeepEquals(fileHeader.Metadata, fileHeader.OriginalMetadata, null) == false;
        }
コード例 #10
0
        private FileHeader GetSmallest(FileHeader[][] applyAsync, int[] indexes, int[] originalIndexes)
        {
            FileHeader smallest = null;
            var smallestIndex = -1;
            for (var i = 0; i < applyAsync.Length; i++)
            {

                var pos = indexes[i] - originalIndexes[i];
                if (pos >= applyAsync[i].Length)
                    continue;

                var current = applyAsync[i][pos];
                if (smallest == null ||
                    string.Compare(current.FullPath, smallest.FullPath, StringComparison.OrdinalIgnoreCase) < 0)
                {
                    smallest = current;
                    smallestIndex = i;
                }
            }

            if (smallestIndex != -1)
                indexes[smallestIndex]++;

            return smallest;
        }
コード例 #11
0
        public void AddToCache(string filename, FileHeader fileHeader)
        {
            if (!entitiesByKey.ContainsKey(filename))
                entitiesByKey.Add(filename, fileHeader);
            else
                entitiesByKey[filename] = fileHeader;

            if (this.IsDeleted(filename))
                knownMissingIds.Remove(filename);
        }
コード例 #12
0
        internal bool TryGetFromCache(string filename, out FileHeader fileHeader)
        {
            fileHeader = null;

            if (entitiesByKey.ContainsKey(filename))
                fileHeader = entitiesByKey[filename];

            return fileHeader != null;
        }
コード例 #13
0
        public void RegisterFileDeletion(FileHeader file, Etag etag = null)
        {
			RegisterFileDeletion(file.FullPath, etag);
        }
コード例 #14
0
 public void RegisterRename(FileHeader sourceFile, string destinationFile, Etag etag = null)
 {
     RegisterRename(sourceFile.FullPath, destinationFile, etag);
 }
コード例 #15
0
 protected bool Equals(FileHeader other)
 {
     return(string.Equals(FullPath, other.FullPath) && TotalSize == other.TotalSize && UploadedSize == other.UploadedSize && Metadata.Equals(other.Metadata));
 }
コード例 #16
0
 public void AfterChange(FileHeader instance, RavenJObject metadata)
 {
     AfterCount++;
 }
コード例 #17
0
 public async Task PutFile(FileHeader file, Stream data, long dataSize)
 {
     await filesystem.Files.PutAsync(file.FullPath, null, file.Metadata, () => new CompletedTask<Stream>(data), new FileActions.PutOperationOptions
     {
         ContentLength = dataSize
     });
 }
コード例 #18
0
 public void ConflictResolved(FileHeader header)
 {
     ResolvedCount++;
 }
コード例 #19
0
 public bool BeforeChange(FileHeader instance, RavenJObject metadata, RavenJObject original)
 {
     BeforeCount++;
     return metadata.Value<string>("ETag") == original.Value<string>("ETag");
 }
コード例 #20
0
        public void RegisterUpload(FileHeader file, Stream stream, Etag etag = null)
        {
            if (deletedEntities.Contains(file.FullPath))
                throw new InvalidOperationException("The file '" + file.FullPath + "' was already marked for deletion in this session, we do not allow delete and upload on the same session");

            var operation = new UploadFileOperation(this, file.FullPath, stream.Length, stream.CopyTo, file.Metadata, etag);

            IncrementRequestCount();

            registeredOperations.Enqueue(operation);   
        }
コード例 #21
0
	    public IEnumerable<FileHeader> GetFilesStartingWith(string namePrefix, int start, int take)
	    {
			Api.JetSetCurrentIndex(session, Files, "by_name");

			Api.MakeKey(session, Files, namePrefix, Encoding.Unicode, MakeKeyGrbit.NewKey);
			if (Api.TrySeek(session, Files, SeekGrbit.SeekGE) == false)
			{
				yield break;
			}

			Api.MakeKey(session, Files, namePrefix, Encoding.Unicode, MakeKeyGrbit.NewKey | MakeKeyGrbit.PartialColumnEndLimit);
			try
			{
				Api.JetMove(session, Files, start, MoveGrbit.MoveKeyNE);
			}
			catch (EsentNoCurrentRecordException)
			{
				yield break;
			}

			if (Api.TrySetIndexRange(session, Files, SetIndexRangeGrbit.RangeInclusive | SetIndexRangeGrbit.RangeUpperLimit))
			{
				var fetchedCount = 0;

				do
				{
					var file = new FileHeader(Api.RetrieveColumnAsString(session, Files, tableColumnsCache.FilesColumns["name"], Encoding.Unicode), RetrieveMetadata())
					             {
						             TotalSize = GetTotalSize(), 
									 UploadedSize = BitConverter.ToInt64(Api.RetrieveColumn(session, Files, tableColumnsCache.FilesColumns["uploaded_size"]), 0),
					             };

					if (file.FullPath.StartsWith(namePrefix) == false)
						continue;

					fetchedCount++;

					yield return file;
				}
				while (Api.TryMoveNext(session, Files) && fetchedCount < take);
			}
	    }
コード例 #22
0
        private int CompareFileInfos(FileHeader current, FileHeader smallest, string[] sortFields)
        {
            if (sortFields == null || sortFields.Length == 0)
            {
                return string.Compare(current.FullPath, smallest.FullPath, StringComparison.OrdinalIgnoreCase);
            }
            foreach (var sortField in sortFields)
            {
                var field = sortField;
                var multiplay = 1; //for asending decending
                if (sortField.StartsWith("-"))
                {
                    field = sortField.TrimStart(new[] { '-' });
                    multiplay = -1;
                }

                if (field.Equals("__size", StringComparison.OrdinalIgnoreCase))
                {
                    var currentItem = current.TotalSize;
                    var smallestItem = smallest.TotalSize;

                    if (currentItem == null && smallestItem == null)
                        continue;

                    if (currentItem == null)
                        return 1 * multiplay;

                    if (smallestItem == null)
                        return -1 * multiplay;


                    var compare = (long)(currentItem - smallestItem);
                    if (compare != 0)
                        return Math.Sign(compare) * multiplay;
                }
                else
                {
                    var currentItem = current.Metadata.Value<string>(field);
                    var smallestItem = smallest.Metadata.Value<string>(field);
                    
                    var compare = string.Compare(currentItem, smallestItem, StringComparison.OrdinalIgnoreCase);
                    if (compare != 0)
                        return compare * multiplay;
                }
            }

            return 0;
        }
コード例 #23
0
 public void RegisterUpload(FileHeader file, long size, Action<Stream> write, Etag etag = null)
 {
     RegisterUploadInternal(file.FullPath, size, write, file.Metadata, etag);
 }
コード例 #24
0
        public void RegisterUpload(FileHeader file, long size, Action<Stream> write, Etag etag = null)
        {
            var operation = new UploadFileOperation(this, file.FullPath, size, write, file.Metadata, etag);

            IncrementRequestCount();

            registeredOperations.Enqueue(operation);     
        }
コード例 #25
0
 public bool BeforeChange(FileHeader instance, RavenJObject metadata, RavenJObject original)
 {
     BeforeCount++;
     return true;
 }
コード例 #26
0
 public Task<Stream> DownloadFile(FileHeader file)
 {
     var name = file.FullPath;
     var readingStream = StorageStream.Reading(filesystem.Storage, name);
     return new CompletedTask<Stream>(readingStream);
 }
コード例 #27
0
        public void RegisterFileDeletion(FileHeader file, Etag etag = null)
        {
			deletedEntities.Add(file.Directory);

			var operation = new DeleteFileOperation(this, file.Directory, etag);

            IncrementRequestCount();

            registeredOperations.Enqueue(operation); 
        }
コード例 #28
0
ファイル: AsyncFilesSession.cs プロジェクト: GorelH/ravendb
        public Task<Stream> DownloadAsync(FileHeader fileHeader, Reference<RavenJObject> metadata = null)
        {
            if (fileHeader == null || string.IsNullOrWhiteSpace(fileHeader.FullPath))
                throw new ArgumentNullException("fileHeader", "The file header cannot be null, and must have a filename.");

            return this.DownloadAsync(fileHeader.FullPath, metadata);
        }
コード例 #29
0
 public void RegisterRename(FileHeader sourceFile, string destinationFile)
 {
     RegisterRename(sourceFile.Directory, destinationFile);
 }
コード例 #30
0
ファイル: FileHeader.cs プロジェクト: GorelH/ravendb
 protected bool Equals(FileHeader other)
 {
     return string.Equals(FullPath, other.FullPath) && TotalSize == other.TotalSize && UploadedSize == other.UploadedSize && Metadata.Equals(other.Metadata);
 }
コード例 #31
0
        public void RegisterUpload(FileHeader file, Stream stream, Etag etag = null)
        {
			RegisterUploadInternal(file.FullPath, stream.Length, stream.CopyTo, file.Metadata, etag);
        }