Пример #1
0
        static async Task <BrokeredMessage> GenerateBrokeredMessageWithBlobKeyPropertyAsync(
            Stream stream,
            IOrchestrationServiceBlobStore orchestrationServiceBlobStore,
            OrchestrationInstance instance,
            ServiceBusMessageSettings messageSettings,
            DateTime messageFireTime,
            string compressionType)
        {
            if (stream.Length > messageSettings.MessageMaxSizeInBytes)
            {
                throw new ArgumentException(
                          $"The serialized message size {stream.Length} is larger than the supported external storage blob size {messageSettings.MessageMaxSizeInBytes}.",
                          "stream");
            }

            if (orchestrationServiceBlobStore == null)
            {
                throw new ArgumentException(
                          "Please provide an implementation of IOrchestrationServiceBlobStore for external storage.",
                          "orchestrationServiceBlobStore");
            }

            // save the compressed stream using external storage when it is larger
            // than the supported message size limit.
            // the stream is stored using the generated key, which is saved in the message property.
            string blobKey = orchestrationServiceBlobStore.BuildMessageBlobKey(instance, messageFireTime);

            TraceHelper.TraceInstance(
                TraceEventType.Information,
                "GenerateBrokeredMessageWithBlobKeyProperty-SaveToBlob",
                instance,
                () => $"Saving the message stream in blob storage using key {blobKey}.");
            await orchestrationServiceBlobStore.SaveStreamAsync(blobKey, stream);

            BrokeredMessage brokeredMessage = new BrokeredMessage();

            brokeredMessage.Properties[ServiceBusConstants.MessageBlobKey]             = blobKey;
            brokeredMessage.Properties[FrameworkConstants.CompressionTypePropertyName] = compressionType;

            return(brokeredMessage);
        }
        async static Task <Stream> CreateStreamForExternalStorageAsync(
            bool shouldCompress,
            IOrchestrationServiceBlobStore orchestrationServiceBlobStore,
            string sessionId,
            DataConverter dataConverter,
            Stream compressedState)
        {
            if (orchestrationServiceBlobStore == null)
            {
                throw new OrchestrationException(
                          "The compressed session is larger than supported. " +
                          "Please provide an implementation of IOrchestrationServiceBlobStore for external storage.");
            }

            // create a new orchestration session state with the external blob key
            string key = orchestrationServiceBlobStore.BuildSessionBlobKey(sessionId);

            TraceHelper.TraceSession(
                TraceEventType.Information,
                "RuntimeStateStreamConverter-SaveSessionToStorage",
                sessionId,
                $"Saving the serialized stream in external storage with key {key}.");

            // save the compressedState stream externally as a blob
            await orchestrationServiceBlobStore.SaveStreamAsync(key, compressedState);

            // create an OrchestrationSessionState instance to hold the blob key,
            // and then serialize the instance as a sream for the session state
            OrchestrationSessionState orchestrationSessionState = new OrchestrationSessionState(key);
            string serializedStateExternal = dataConverter.Serialize(orchestrationSessionState);

            long   streamSize;
            Stream compressedStateForSession = Utils.WriteStringToStream(
                serializedStateExternal,
                shouldCompress,
                out streamSize);

            return(compressedStateForSession);
        }