internal static Stream GetBinaryStream(int nodeId, int versionId, int propertyTypeId) { BinaryCacheEntity binaryCacheEntity = null; if (TransactionScope.IsActive) { binaryCacheEntity = DataProvider.Current.LoadBinaryCacheEntity(versionId, propertyTypeId); return(new SnStream(binaryCacheEntity.Context, binaryCacheEntity.RawData)); } // Try to load cached binary entity var cacheKey = BinaryCacheEntity.GetCacheKey(versionId, propertyTypeId); binaryCacheEntity = (BinaryCacheEntity)DistributedApplication.Cache.Get(cacheKey); if (binaryCacheEntity == null) { // Not in cache, load it from the database binaryCacheEntity = DataProvider.Current.LoadBinaryCacheEntity(versionId, propertyTypeId); // insert the binary cache entity into the // cache only if we know the node id if (binaryCacheEntity != null && nodeId != 0) { if (!RepositoryEnvironment.WorkingMode.Populating) { var head = NodeHead.Get(nodeId); DistributedApplication.Cache.Insert(cacheKey, binaryCacheEntity, CacheDependencyFactory.CreateBinaryDataDependency(nodeId, head.Path, head.NodeTypeId)); } } } // Not found even in the database if (binaryCacheEntity == null) { return(null); } if (binaryCacheEntity.Length == -1) { return(null); } return(new SnStream(binaryCacheEntity.Context, binaryCacheEntity.RawData)); }
internal static Stream GetBinaryStream2(int nodeId, int versionId, int propertyTypeId) { FileStreamData fileStreamData = null; if (TransactionScope.IsActive) { // Aktív tranzakció hekk var bce = DataProvider.Current.LoadBinaryCacheEntity(versionId, propertyTypeId, out fileStreamData); //If we received the necessary information for serving file stream, use that. If filestream data //is null, we MUST NOT use SqlFileStream here, because the data is in the database. if (bce.UseFileStream && fileStreamData != null) { return(new ContentRepository.Storage.Data.SqlFileStream(bce.Length, bce.BinaryPropertyId, fileStreamData)); } return(bce.RawData == null ? new RepositoryStream(bce.Length, bce.BinaryPropertyId) : new RepositoryStream(bce.BinaryPropertyId, bce.Length, bce.RawData)); } // Try to load cached binary entity var cacheKey = BinaryCacheEntity.GetCacheKey(versionId, propertyTypeId); var binaryCacheEntity = (BinaryCacheEntity)DistributedApplication.Cache.Get(cacheKey); if (binaryCacheEntity == null) { //Not in cache, load it from the database binaryCacheEntity = DataProvider.Current.LoadBinaryCacheEntity(versionId, propertyTypeId, out fileStreamData); //insert the binary cache entity into the //cache only if we know the node id if (binaryCacheEntity != null && nodeId != 0) { if (!RepositoryConfiguration.WorkingMode.Populating) { DistributedApplication.Cache.Insert(cacheKey, binaryCacheEntity, new NodeIdDependency(nodeId)); } } } //Not found even in the database if (binaryCacheEntity == null) { return(null); } if (binaryCacheEntity.Length == -1) { return(null); } //We can use SqlFilestream to load the binary from the filesystem. //Transaction is handled inside the SqlFileStream. if (binaryCacheEntity.UseFileStream) { return(new ContentRepository.Storage.Data.SqlFileStream(binaryCacheEntity.Length, binaryCacheEntity.BinaryPropertyId)); } var stream = binaryCacheEntity.RawData == null ? new RepositoryStream(binaryCacheEntity.Length, binaryCacheEntity.BinaryPropertyId) : new RepositoryStream(binaryCacheEntity.BinaryPropertyId, binaryCacheEntity.Length, binaryCacheEntity.RawData); return(stream); }