Exemplo n.º 1
0
        private static void OnThumbnailStepProcessed(ThumbnailCompilerContext context, AssetItem assetItem, string thumbnailStorageUrl, BuildStepEventArgs buildStepEventArgs)
        {
            // returns immediately if the user has not subscribe to the event
            if (!context.ShouldNotifyThumbnailBuilt)
            {
                return;
            }

            // TODO: the way to get last build step (which should be thumbnail, not its dependencies) should be done differently, at the compiler level
            // (we need to generate two build step that can be accessed directly, one for dependency and one for thumbnail)
            var lastBuildStep = buildStepEventArgs.Step is ListBuildStep ? ((ListBuildStep)buildStepEventArgs.Step).Steps.LastOrDefault() ?? buildStepEventArgs.Step : buildStepEventArgs.Step;

            // Retrieving build result
            var result = ThumbnailBuildResult.Failed;

            if (lastBuildStep.Succeeded)
            {
                result = ThumbnailBuildResult.Succeeded;
            }
            else if (lastBuildStep.Status == ResultStatus.Cancelled)
            {
                result = ThumbnailBuildResult.Cancelled;
            }

            // TODO: Display error logo if anything else went wrong?

            var changed = lastBuildStep.Status != ResultStatus.NotTriggeredWasSuccessful;

            // Open the image data stream if the build succeeded
            Stream   thumbnailStream = null;
            ObjectId thumbnailHash   = ObjectId.Empty;

            if (lastBuildStep.Succeeded)
            {
                thumbnailStream = MicrothreadLocalDatabases.DatabaseFileProvider.OpenStream(thumbnailStorageUrl, VirtualFileMode.Open, VirtualFileAccess.Read);
                thumbnailHash   = MicrothreadLocalDatabases.DatabaseFileProvider.ContentIndexMap[thumbnailStorageUrl];
            }

            try
            {
                context.NotifyThumbnailBuilt(assetItem, result, changed, thumbnailStream, thumbnailHash);
            }
            finally
            {
                // Close the image data stream if opened
                if (thumbnailStream != null)
                {
                    thumbnailStream.Dispose();
                }
            }
        }