/* ----------------------------------------------------------------------------------------------- */ public Stream GetBinaryStream(int nodeId, int versionId, int propertyTypeId) { // Try to load cached binary entity var cacheKey = BinaryCacheEntity.GetCacheKey(versionId, propertyTypeId); var binaryCacheEntity = (BinaryCacheEntity)Cache.Get(cacheKey); if (binaryCacheEntity == null) { //TODO: [DIBLOB] get the storage service through the constructor later // Not in cache, load it from the database binaryCacheEntity = Providers.Instance.BlobStorage.LoadBinaryCacheEntityAsync(versionId, propertyTypeId, CancellationToken.None) .GetAwaiter().GetResult(); // 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); Cache.Insert(cacheKey, binaryCacheEntity, CacheDependencyFactory.CreateBinaryDataDependency(nodeId, head.Path, head.NodeTypeId)); } } } // Not found even in the database if (binaryCacheEntity == null || binaryCacheEntity.Length == -1) { return(null); } return(new SnStream(binaryCacheEntity.Context, Providers.Instance.BlobStorage, binaryCacheEntity.RawData)); }
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)); }