示例#1
0
        public async Task <string> GetVariableAsync(string name, IContext context, CancellationToken cancellationToken)
        {
            try
            {
                var resourceCommandResult = await ExecuteGetResourceCommandAsync(name, cancellationToken);

                if (resourceCommandResult.Status != CommandStatus.Success)
                {
                    _logger.Warning("Variable {VariableName} from {ResourceName} not found", name, _resourceName);
                    return(null);
                }

                if (!resourceCommandResult.Resource.GetMediaType().IsJson)
                {
                    return(resourceCommandResult.Resource.ToString());
                }

                return(_documentSerializer.Serialize(resourceCommandResult.Resource));
            }
            catch (LimeException ex) when(ex.Reason.Code == ReasonCodes.COMMAND_RESOURCE_NOT_FOUND)
            {
                _logger.Warning(ex, "An exception occurred while obtaining variable {VariableName} from {ResourceName}", name, _resourceName);
                return(null);
            }
        }
示例#2
0
        public async Task <bool> ValidateInputAsync(Message envelope, CancellationToken cancellationToken)
        {
            // Gets the settings from the previous input
            var settingsJson = await _sessionManager.GetVariableAsync(envelope.From, INPUT_SETTINGS_KEY, cancellationToken);

            if (settingsJson == null)
            {
                return(true);
            }

            var inputSettings = JsonConvert.DeserializeObject <InputSettings>(settingsJson, Application.SerializerSettings);

            if (ValidateRule(envelope.Content, inputSettings.Validation))
            {
                // Save the value in the session
                var variableValue = _documentSerializer.Serialize(envelope.Content);
                await _sessionManager.AddVariableAsync(envelope.From, inputSettings.Validation.VariableName, variableValue, cancellationToken);

                return(true);
            }

            // Send a validation error message and resend the previous label
            await _sender.SendMessageAsync(inputSettings.Validation.Error ?? "An validation error has occurred", envelope.From, cancellationToken);

            await Task.Delay(250, cancellationToken);

            await _sender.SendMessageAsync(inputSettings.Label.ToDocument(), envelope.From, cancellationToken);

            return(false);
        }
        public static BsonDocument ToMongoCommit(this CommitAttempt commit, LongCheckpoint checkpoint, IDocumentSerializer serializer)
        {
            int streamRevision                = commit.StreamRevision - (commit.Events.Count - 1);
            int streamRevisionStart           = streamRevision;
            IEnumerable <BsonDocument> events = commit
                                                .Events
                                                .Select(e =>
                                                        new BsonDocument
            {
                { MongoCommitFields.StreamRevision, streamRevision++ },
                { MongoCommitFields.Payload, new BsonDocumentWrapper(serializer.Serialize(e)) }
            });

            return(new BsonDocument
            {
                { MongoCommitFields.CheckpointNumber, checkpoint.LongValue },
                { MongoCommitFields.CommitId, commit.CommitId },
                { MongoCommitFields.CommitStamp, commit.CommitStamp },
                { MongoCommitFields.Headers, Mangle(commit.Headers) },
                { MongoCommitFields.Events, new BsonArray(events) },
                { MongoCommitFields.Dispatched, false },
                { MongoCommitFields.StreamRevisionFrom, streamRevisionStart },
                { MongoCommitFields.StreamRevisionTo, streamRevision - 1 },
                { MongoCommitFields.BucketId, commit.BucketId },
                { MongoCommitFields.StreamId, commit.StreamId },
                { MongoCommitFields.CommitSequence, commit.CommitSequence }
            });
        }
示例#4
0
        public bool Convert(string sourceFileName, string targetFileName)
        {
            string input;

            var documentStorage = GetDocumentStorageForFileName(sourceFileName);

            try
            {
                input = documentStorage.GetData(sourceFileName);
            }
            catch (FileNotFoundException)
            {
                return(false);
            }

            var doc           = inputParser.Parse(input);
            var serializedDoc = documentSerializer.Serialize(doc);

            try
            {
                documentStorage.Persist(serializedDoc, targetFileName);
            }
            catch (AccessViolationException)
            {
                return(false);
            }

            return(true);
        }
示例#5
0
        public bool Convert(string sourceFileName, string targetFileName)
        {
            string input;

            var inputRetriever = GetInputRetrieverForFileName(sourceFileName);

            try
            {
                input = inputRetriever.GetData(sourceFileName);
            }
            catch (FileNotFoundException)
            {
                return false;
            }

            var doc = inputParser.Parse(input);
            var serializedDoc = documentSerializer.Serialize(doc);

            try
            {
                var documentPersister = GetDocumentPersisterForFileName(targetFileName);
                documentPersister.Persist(serializedDoc, targetFileName);
            }
            catch (AccessViolationException)
            {
                return false;
            }

            return true;
        }
示例#6
0
        public async Task <string> GetVariableAsync(string name, IContext context, CancellationToken cancellationToken)
        {
            try
            {
                // We are sending the command directly here because the BucketExtension requires us to known the type.
                var bucketCommandResult = await _sender.ProcessCommandAsync(
                    new Command()
                {
                    Uri    = new LimeUri($"/buckets/{Uri.EscapeDataString(name)}"),
                    Method = CommandMethod.Get,
                },
                    cancellationToken);

                if (bucketCommandResult.Status != CommandStatus.Success)
                {
                    return(null);
                }
                if (!bucketCommandResult.Resource.GetMediaType().IsJson)
                {
                    return(bucketCommandResult.Resource.ToString());
                }
                return(_documentSerializer.Serialize(bucketCommandResult.Resource));
            }
            catch (LimeException ex) when(ex.Reason.Code == ReasonCodes.COMMAND_RESOURCE_NOT_FOUND)
            {
                return(null);
            }
        }
        public bool ConvertFormat(string sourceFileName, string targetFileName)
        {
            string input;

            try
            {
                var inputRetriever = InputRetriever.ForFileName(sourceFileName);
                input = inputRetriever.GetData(sourceFileName);
            }
            catch (FileNotFoundException)
            {
                return(false);
            }

            var doc           = _inputParser.ParseInput(input);
            var serializedDoc = _documentSerializer.Serialize(doc);

            try
            {
                var documentPersister = DocumentPersister.ForFileName(targetFileName);
                documentPersister.PersistDocument(serializedDoc, targetFileName);
            }
            catch (AccessViolationException)
            {
                return(false);
            }

            return(true);
        }
示例#8
0
        public static BsonDocument ToMongoCommit(this Commit commit, IDocumentSerializer serializer)
        {
            int streamRevision = commit.StreamRevision - (commit.Events.Count - 1);
            IEnumerable <BsonDocument> events = commit
                                                .Events
                                                .Select(e =>
                                                        new BsonDocument
            {
                { "StreamRevision", streamRevision++ },
                { "Payload", new BsonDocumentWrapper(typeof(EventMessage), serializer.Serialize(e)) }
            });

            return(new BsonDocument
            {
                { MongoFields.Id, new BsonDocument
                  {
                      { MongoFields.BucketId, commit.BucketId },
                      { MongoFields.StreamId, commit.StreamId },
                      { MongoFields.CommitSequence, commit.CommitSequence }
                  } },
                { MongoFields.CommitId, commit.CommitId },
                { MongoFields.CommitStamp, commit.CommitStamp },
                { MongoFields.Headers, BsonDocumentWrapper.Create(commit.Headers) },
                { MongoFields.Events, new BsonArray(events) },
                { MongoFields.Dispatched, false }
            });
        }
        private async Task <string> GetAnalyzedContentAsync(LazyInput input)
        {
            var analyzedContent = await input.AnalyzedContent;

            return(analyzedContent != default(AnalysisResponse)
                ? _documentSerializer.Serialize(analyzedContent)
                : default);
        private async Task <string> GetIntentVariableAsync(LazyInput input, string intentProperty)
        {
            var intent = await input.GetIntentAsync();

            if (intent == null)
            {
                return(null);
            }

            switch (intentProperty)
            {
            case "id":
                return(intent.Id);

            case "name":
                return(intent.Name);

            case "score":
                return(intent.Score?.ToString(CultureInfo.InvariantCulture));

            case "answer":
                var document = intent.Answer?.Value;
                if (document == null)
                {
                    return(null);
                }
                return(_documentSerializer.Serialize(document));
            }

            return(null);
        }
示例#11
0
        private FlowDocument CloneDocument(FlowDocument flowDocument)
        {
            MathDocument mathDocument             = _serializer.Serialize(flowDocument);
            FlowDocument deserializedFlowDocument = _serializer.Deserialize(mathDocument);

            return(deserializedFlowDocument);
        }
示例#12
0
 public static BsonDocument ToMongoSnapshot(this Snapshot snapshot, IDocumentSerializer serializer)
 {
     return new BsonDocument
     {
         { "_id", new BsonDocument { { "StreamId", snapshot.StreamId }, { "StreamRevision", snapshot.StreamRevision } } },
         { "Payload", BsonDocumentWrapper.Create(serializer.Serialize(snapshot.Payload)) }
     };
 }
示例#13
0
        private async Task SaveInternal()
        {
            var content = _serializer.Serialize(Data);
            await _storage.Write(_ref, content);

            _onSave?.Invoke(this);
            _onSave = null; // intended for single use.
        }
示例#14
0
 public static RavenSnapshot ToRavenSnapshot(this Snapshot snapshot, IDocumentSerializer serializer)
 {
     return new RavenSnapshot
     {
         StreamId = snapshot.StreamId,
         StreamRevision = snapshot.StreamRevision,
         Payload = serializer.Serialize(snapshot.Payload)
     };
 }
        /// <summary>
        /// turn Scenario into a JSON object.  - save
        /// </summary>
        /// <param name="scenario"></param>
        /// <param name="targetFileName"></param>
        /// <returns></returns>
        public bool ConvertFormat(Scene scenario, string targetlocation, string targetFileName)
        {
            var             x = _documentSerializer.Serialize(scenario);
            DocumentStorage documentStorage = new JsonStorage();

            documentStorage.PersistDocument(x, targetlocation, targetFileName);

            return(true);
        }
 public static RavenSnapshot ToRavenSnapshot(this Snapshot snapshot, IDocumentSerializer serializer)
 {
     return(new RavenSnapshot
     {
         StreamId = snapshot.StreamId,
         StreamRevision = snapshot.StreamRevision,
         Payload = serializer.Serialize(snapshot.Payload)
     });
 }
示例#17
0
        private void SaveConcrete(object obj)
        {
            if (obj is Document)
            {
                _session.Save(obj);
            }
            else if (obj is IIndex)
            {
                _session.Save(obj);
            }
            else
            {
                var doc = new Document();

                // convert the custom object to a storable document
                _serializer.Serialize(obj, ref doc);

                // if the object is not new, reload to get the old map
                int id;
                if (_documents.TryGetValue(obj, out id))
                {
                    var oldDoc = _session.Get <Document>(id);
                    var oldObj = _serializer.Deserialize(oldDoc);

                    // do nothing if the document hasn't been modified
                    if (oldDoc.Content != doc.Content)
                    {
                        oldDoc.Content = doc.Content;

                        MapDeleted(oldDoc, oldObj);

                        // update document
                        MapNew(oldDoc, obj);
                    }
                }
                else
                {
                    // new document
                    _session.Save(doc);

                    var accessor = _store.GetIdAccessor(obj.GetType(), "Id");

                    // if the object has an Id property, set it back
                    var ident = accessor.Get(obj);
                    if (ident != null)
                    {
                        accessor.Set(obj, doc.Id);
                    }

                    // track the newly created object
                    TrackObject(obj, doc);

                    MapNew(doc, obj);
                }
            }
        }
示例#18
0
        public void Persist(string documentName, TDocument document)
        {
            var                blobAddressUri  = documentName;
            CloudBlobClient    blobStorageType = Account.CreateCloudBlobClient();
            CloudBlobContainer container       = blobStorageType.GetContainerReference(DocumentsContainerName);
            CloudBlockBlob     blobReference   = container.GetBlockBlobReference(blobAddressUri);

            AdjustBlobAttribute(blobReference);
            blobReference.UploadFromStream(_documentSerializer.Serialize(document));
        }
示例#19
0
        public Task Persist(string documentName, TDocument document)
        {
            var blobAddressUri  = documentName;
            var blobStorageType = Account.CreateCloudBlobClient();
            var container       = blobStorageType.GetContainerReference(DocumentsContainerName);
            var blobReference   = container.GetBlockBlobReference(blobAddressUri);

            AdjustBlobAttributes(blobReference);
            return(blobReference.UploadFromStreamAsync(documentSerializer.Serialize(document)));
        }
示例#20
0
 public static BsonDocument ToMongoSnapshot(this Snapshot snapshot, IDocumentSerializer serializer)
 {
     return(new BsonDocument
     {
         { "_id", new BsonDocument {
               { "StreamId", snapshot.StreamId }, { "StreamRevision", snapshot.StreamRevision }
           } },
         { "Payload", BsonDocumentWrapper.Create(serializer.Serialize(snapshot.Payload)) }
     });
 }
示例#21
0
        public LazyInput(
            Message message,
            Identity userIdentity,
            BuilderConfiguration builderConfiguration,
            IDocumentSerializer documentSerializer,
            IEnvelopeSerializer envelopeSerializer,
            IArtificialIntelligenceExtension artificialIntelligenceExtension,
            CancellationToken cancellationToken)
        {
            Message = message ?? throw new ArgumentNullException(nameof(message));
            _builderConfiguration  = builderConfiguration ?? throw new ArgumentNullException(nameof(builderConfiguration));
            _lazySerializedContent = new Lazy <string>(() => documentSerializer.Serialize(Content));
            _analyzable            = new Lazy <bool>(() =>
            {
                string result = null;
                Message?.Metadata?.TryGetValue("builder.analyzable", out result);
                return(result?.ToLower() == "true");
            });
            _lazyAnalyzedContent = new Lazy <Task <AnalysisResponse> >(async() =>
            {
                // Only analyze the input if the type is plain text or analyzable metadata is true.
                if (!_analyzable.Value && Content.GetMediaType() != PlainText.MediaType)
                {
                    return(null);
                }

                try
                {
                    return(await artificialIntelligenceExtension.AnalyzeAsync(
                               new AnalysisRequest
                    {
                        Text = _lazySerializedContent.Value,
                        Extras = new Dictionary <string, string>
                        {
                            ["MessageId"] = Message.Id,
                            ["UserIdentity"] = userIdentity.ToString()
                        }
                    },
                               cancellationToken));
                }
                catch (LimeException)
                {
                    return(null);
                }
            });
            _lazySerializedMessage = new Lazy <string>(() =>
            {
                if (Message != null)
                {
                    return(envelopeSerializer.Serialize(Message));
                }

                return(null);
            });
        }
示例#22
0
 public static RavenSnapshot ToRavenSnapshot(this Snapshot snapshot, string partition, IDocumentSerializer serializer)
 {
     return(new RavenSnapshot
     {
         Id = ToRavenSnapshotId(snapshot, partition),
         Partition = partition,
         StreamId = snapshot.StreamId,
         StreamRevision = snapshot.StreamRevision,
         Payload = serializer.Serialize(snapshot.Payload)
     });
 }
示例#23
0
		public static RavenSnapshot ToRavenSnapshot(this Snapshot snapshot, string partition, IDocumentSerializer serializer)
		{
		    return new RavenSnapshot
			{
                Id = ToRavenSnapshotId(snapshot, partition),
                Partition = partition,
				StreamId = snapshot.StreamId,
				StreamRevision = snapshot.StreamRevision,
				Payload = serializer.Serialize(snapshot.Payload)
			};
		}
示例#24
0
 public static DocumentSnapshot ToDocumentSnapshot(this ISnapshot snapshot, IDocumentSerializer serializer)
 {
     return(new DocumentSnapshot
     {
         Id = ToDocumentSnapshotId(snapshot),
         BucketId = snapshot.BucketId,
         StreamId = snapshot.StreamId,
         StreamRevision = snapshot.StreamRevision,
         Payload = serializer.Serialize(snapshot.Payload)
     });
 }
示例#25
0
 public static BsonDocument ToMongoSnapshot(this Snapshot snapshot, IDocumentSerializer serializer)
 {
     return(new BsonDocument
     {
         { MongoFields.Id, new BsonDocument
           {
               { MongoFields.BucketId, snapshot.BucketId },
               { MongoFields.StreamId, snapshot.StreamId },
               { MongoFields.StreamRevision, snapshot.StreamRevision }
           } },
         { MongoFields.Payload, BsonDocumentWrapper.Create(serializer.Serialize(snapshot.Payload)) }
     });
 }
示例#26
0
 public static BsonDocument ToMongoCommit(this Commit commit, IDocumentSerializer serializer)
 {
     var streamRevision = commit.StreamRevision - (commit.Events.Count - 1);
     var events = commit.Events.Select(e => new BsonDocument { { "StreamRevision", streamRevision++ }, { "Payload", new BsonDocumentWrapper(typeof(EventMessage), serializer.Serialize(e)) } });
     return new BsonDocument
     {
         { "_id", new BsonDocument { { "StreamId", commit.StreamId }, { "CommitSequence", commit.CommitSequence } } },
         { "CommitId", commit.CommitId },
         { "CommitStamp", commit.CommitStamp },
         { "Headers", BsonDocumentWrapper.Create(commit.Headers) },
         { "Events", BsonArray.Create(events) },
         { "Dispatched", false }
     };
 }
示例#27
0
        protected override HttpResponse GetEnvelopeResponse(Message envelope, HttpRequest request)
        {
            if (envelope.Content != null)
            {
                var body        = _serializer.Serialize(envelope.Content);
                var contentType = envelope.Content.GetMediaType();
                var bodyStream  = new MemoryStream(Encoding.UTF8.GetBytes(body));

                return(new HttpResponse(request.CorrelatorId, HttpStatusCode.OK, contentType: contentType, bodyStream: bodyStream));
            }
            else
            {
                return(new HttpResponse(request.CorrelatorId, HttpStatusCode.NotFound));
            }
        }
 public static RavenCommit ToRavenCommit(this Commit commit, IDocumentSerializer serializer)
 {
     return(new RavenCommit
     {
         Id = ToRavenCommitId(commit),
         StreamId = commit.StreamId,
         CommitSequence = commit.CommitSequence,
         StartingStreamRevision = commit.StreamRevision - (commit.Events.Count - 1),
         StreamRevision = commit.StreamRevision,
         CommitId = commit.CommitId,
         CommitStamp = commit.CommitStamp,
         Headers = commit.Headers,
         Payload = serializer.Serialize(commit.Events)
     });
 }
示例#29
0
 public static RavenCommit ToRavenCommit(this Commit commit, IDocumentSerializer serializer)
 {
     return new RavenCommit
     {
         Id = ToRavenCommitId(commit),
         StreamId = commit.StreamId,
         CommitSequence = commit.CommitSequence,
         StartingStreamRevision = commit.StreamRevision - (commit.Events.Count - 1),
         StreamRevision = commit.StreamRevision,
         CommitId = commit.CommitId,
         CommitStamp = commit.CommitStamp,
         Headers = commit.Headers,
         Payload = serializer.Serialize(commit.Events)
     };
 }
示例#30
0
 public static RavenCommit ToRavenCommit(this CommitAttempt commit, IDocumentSerializer serializer)
 {
     return new RavenCommit
     {
         Id = ToRavenCommitId(commit),
         BucketId = commit.BucketId,
         StreamId = commit.StreamId,
         CommitSequence = commit.CommitSequence,
         StartingStreamRevision = commit.StreamRevision - (commit.Events.Count - 1),
         StreamRevision = commit.StreamRevision,
         CommitId = commit.CommitId,
         CommitStamp = commit.CommitStamp,
         Headers = commit.Headers.ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
         Payload = serializer.Serialize(commit.Events)
     };
 }
示例#31
0
 public static DocumentCommit ToDocumentCommit(this CommitAttempt commit, IDocumentSerializer serializer)
 {
     return(new DocumentCommit
     {
         Id = ToDocumentCommitId(commit),
         BucketId = commit.BucketId,
         StreamId = commit.StreamId,
         CommitSequence = commit.CommitSequence,
         StartingStreamRevision = commit.StreamRevision - (commit.Events.Count - 1),
         StreamRevision = commit.StreamRevision,
         CommitId = commit.CommitId,
         CommitStamp = commit.CommitStamp,
         Headers = commit.Headers.ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
         Payload = (IList <EventMessage>)serializer.Serialize(commit.Events)
     });
 }
        protected override string GetProperty(Contact item, string propertyName)
        {
            if (propertyName.StartsWith(CONTACT_EXTRAS_VARIABLE_PREFIX, StringComparison.OrdinalIgnoreCase))
            {
                var extraVariableName = propertyName.Remove(0, CONTACT_EXTRAS_VARIABLE_PREFIX.Length);
                if (item.Extras != null && item.Extras.TryGetValue(extraVariableName, out var extraVariableValue))
                {
                    return(extraVariableValue);
                }
                return(null);
            }
            else if (propertyName.Equals(CONTACT_SERIALIZED_PROPERTY, StringComparison.OrdinalIgnoreCase))
            {
                return(_documentSerializer.Serialize(item));
            }

            return(base.GetProperty(item, propertyName));
        }
示例#33
0
        public LazyInput(
            Document content,
            IDictionary <string, string> flowConfiguration,
            IDocumentSerializer documentSerializer,
            IEnvelopeSerializer envelopeSerializer,
            IArtificialIntelligenceExtension artificialIntelligenceExtension,
            CancellationToken cancellationToken)
        {
            _flowConfiguration     = flowConfiguration;
            Content                = content;
            _lazySerializedContent = new Lazy <string>(() => documentSerializer.Serialize(content));
            _lazyAnalyzedContent   = new Lazy <Task <AnalysisResponse> >(async() =>
            {
                // Only analyze the input if the type is plain text.
                if (Content.GetMediaType() != PlainText.MediaType)
                {
                    return(null);
                }

                try
                {
                    return(await artificialIntelligenceExtension.AnalyzeAsync(
                               new AnalysisRequest
                    {
                        Text = _lazySerializedContent.Value
                    },
                               cancellationToken));
                }
                catch (LimeException)
                {
                    return(null);
                }
            });
            _lazySerializedMessage = new Lazy <string>(() =>
            {
                var message = EnvelopeReceiverContext <Message> .Envelope;
                if (message != null)
                {
                    return(envelopeSerializer.Serialize(message));
                }

                return(null);
            });
        }
示例#34
0
        public LazyInput(
            Message message,
            BuilderConfiguration builderConfiguration,
            IDocumentSerializer documentSerializer,
            IEnvelopeSerializer envelopeSerializer,
            IArtificialIntelligenceExtension artificialIntelligenceExtension,
            CancellationToken cancellationToken)
        {
            Message = message ?? throw new ArgumentNullException(nameof(message));
            _builderConfiguration  = builderConfiguration ?? throw new ArgumentNullException(nameof(builderConfiguration));
            _lazySerializedContent = new Lazy <string>(() => documentSerializer.Serialize(Content));
            _lazyAnalyzedContent   = new Lazy <Task <AnalysisResponse> >(async() =>
            {
                // Only analyze the input if the type is plain text.
                if (Content.GetMediaType() != PlainText.MediaType)
                {
                    return(null);
                }

                try
                {
                    return(await artificialIntelligenceExtension.AnalyzeAsync(
                               new AnalysisRequest
                    {
                        Text = _lazySerializedContent.Value
                    },
                               cancellationToken));
                }
                catch (LimeException)
                {
                    return(null);
                }
            });
            _lazySerializedMessage = new Lazy <string>(() =>
            {
                if (Message != null)
                {
                    return(envelopeSerializer.Serialize(Message));
                }

                return(null);
            });
        }
示例#35
0
        protected override async Task ExecuteAsync(ProcessCommandOptions options, IEstablishedChannel channel, CancellationToken cancellationToken)
        {
            if (options.ExpectedResource != null && options.Method != CommandMethod.Get)
            {
                throw new Exception("The expected resource option can only be used with 'get' method");
            }

            var resource = _documentSerializer.Deserialize(options.JoinedResource, options.Type);

            using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(options.Timeout)))
                using (var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, cancellationToken))
                {
                    var responseCommand = await channel.ProcessCommandAsync(
                        new Command(options.Id ?? EnvelopeId.NewId())
                    {
                        From     = options.From,
                        To       = options.To,
                        Method   = options.Method,
                        Uri      = new LimeUri(options.Uri),
                        Resource = resource
                    },
                        cancellationToken);

                    if (responseCommand.Status != options.ExpectedStatus)
                    {
                        throw new Exception($"Unexpected response status '{responseCommand.Status}' ({responseCommand.Reason?.ToString()})");
                    }

                    if (options.ExpectedResource != null)
                    {
                        var expectedResourceRegex = new Regex(options.ExpectedResource);
                        var responseResource      = _documentSerializer.Serialize(responseCommand.Resource);

                        if (!expectedResourceRegex.IsMatch(responseResource))
                        {
                            throw new Exception($"Unexpected response resource: {responseResource}");
                        }
                    }
                }
        }
示例#36
0
        public async Task <string> GetVariableAsync(string name, IContext context, CancellationToken cancellationToken)
        {
            try
            {
                var resourceCommandResult = await ExecuteGetResourceCommandAsync(name, cancellationToken);

                if (resourceCommandResult.Status != CommandStatus.Success)
                {
                    return(null);
                }

                if (!resourceCommandResult.Resource.GetMediaType().IsJson)
                {
                    return(resourceCommandResult.Resource.ToString());
                }

                return(_documentSerializer.Serialize(resourceCommandResult.Resource));
            }
            catch (LimeException ex) when(ex.Reason.Code == ReasonCodes.COMMAND_RESOURCE_NOT_FOUND)
            {
                return(null);
            }
        }