Exemplo n.º 1
0
 private static CosmosTrigger MakeScript(TriggerProperties props) =>
 new CosmosTrigger
 {
     Id        = props.Id,
     Body      = props.Body,
     ETag      = props.ETag,
     Operation = props.TriggerOperation,
     Type      = props.TriggerType
 };
 internal Task <TriggerResponse> CreateTriggerResponseAsync(Task <ResponseMessage> cosmosResponseMessageTask)
 {
     return(this.ProcessMessageAsync(cosmosResponseMessageTask, (cosmosResponseMessage) =>
     {
         TriggerProperties triggerProperties = this.ToObjectInternal <TriggerProperties>(cosmosResponseMessage, this.propertiesSerializer);
         return new TriggerResponse(
             cosmosResponseMessage.StatusCode,
             cosmosResponseMessage.Headers,
             triggerProperties);
     }));
 }
Exemplo n.º 3
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Trigger")
        {
            GameObject        eventTrigger = other.gameObject;
            TriggerProperties triggerProps = eventTrigger.GetComponent <TriggerProperties> ();

            if (!triggerProps.IsDestroyed())
            {
                triggerProps.ActivateTrigger();
                string message = triggerProps.GetMessage();
                if (message != "")
                {
                    gameCanvas.GetComponent <Journal> ().AddMessage(message);
                }
            }
            if (triggerProps.IsPuzzleTrigger())
            {
                triggerProps.isPuzzleTrigger = false;
                puzzleManager.StartPuzzle(triggerProps.GetPuzzle());
            }
        }
    }
Exemplo n.º 4
0
        public void ValidateResponseFactoryJsonSerializer()
        {
            ResponseMessage databaseResponse  = this.CreateResponse();
            ResponseMessage containerResponse = this.CreateResponse();
            ResponseMessage storedProcedureExecuteResponse = this.CreateResponse();
            ResponseMessage storedProcedureResponse        = this.CreateResponse();
            ResponseMessage triggerResponse = this.CreateResponse();
            ResponseMessage udfResponse     = this.CreateResponse();
            ResponseMessage itemResponse    = this.CreateResponse();


            Mock <CosmosSerializer>       mockUserJsonSerializer = new Mock <CosmosSerializer>();
            CosmosSerializerCore          serializerCore         = new CosmosSerializerCore(mockUserJsonSerializer.Object);
            CosmosResponseFactoryInternal cosmosResponseFactory  = new CosmosResponseFactoryCore(
                serializerCore);

            // Test the user specified response
            mockUserJsonSerializer.Setup(x => x.FromStream <ToDoActivity>(itemResponse.Content)).Callback <Stream>(input => input.Dispose()).Returns(new ToDoActivity());
            mockUserJsonSerializer.Setup(x => x.FromStream <ToDoActivity>(storedProcedureExecuteResponse.Content)).Callback <Stream>(input => input.Dispose()).Returns(new ToDoActivity());

            // Verify all the user types use the user specified version
            cosmosResponseFactory.CreateItemResponse <ToDoActivity>(itemResponse);
            cosmosResponseFactory.CreateStoredProcedureExecuteResponse <ToDoActivity>(storedProcedureExecuteResponse);

            // Throw if the setups were not called
            mockUserJsonSerializer.VerifyAll();

            // Test read feed scenario
            ResponseMessage readFeedResponse = this.CreateReadFeedResponse();

            mockUserJsonSerializer.Setup(x => x.FromStream <ToDoActivity[]>(It.IsAny <Stream>()))
            .Callback <Stream>(input => input.Dispose())
            .Returns(new ToDoActivity[] { new ToDoActivity() });
            FeedResponse <ToDoActivity> feedResponse = cosmosResponseFactory.CreateItemFeedResponse <ToDoActivity>(readFeedResponse);

            foreach (ToDoActivity toDoActivity in feedResponse)
            {
                Assert.IsNotNull(toDoActivity);
            }

            mockUserJsonSerializer.VerifyAll();

            ResponseMessage             changeFeedResponseMessage = this.CreateChangeFeedNotModifiedResponse();
            FeedResponse <ToDoActivity> changeFeedResponse        = cosmosResponseFactory.CreateItemFeedResponse <ToDoActivity>(changeFeedResponseMessage);

            Assert.AreEqual(HttpStatusCode.NotModified, changeFeedResponse.StatusCode);
            Assert.IsFalse(changeFeedResponse.Resource.Any());

            ResponseMessage queryResponse = this.CreateReadFeedResponse();

            mockUserJsonSerializer.Setup(x => x.FromStream <ToDoActivity[]>(It.IsAny <Stream>())).Callback <Stream>(input => input.Dispose()).Returns(new ToDoActivity[] { new ToDoActivity() });
            FeedResponse <ToDoActivity> queryFeedResponse = cosmosResponseFactory.CreateItemFeedResponse <ToDoActivity>(queryResponse);

            foreach (ToDoActivity toDoActivity in queryFeedResponse)
            {
                Assert.IsNotNull(toDoActivity);
            }

            mockUserJsonSerializer.VerifyAll();

            // Test the system specified response
            ContainerProperties containerSettings = new ContainerProperties("mockId", "/pk");
            DatabaseProperties  databaseSettings  = new DatabaseProperties()
            {
                Id = "mock"
            };

            StoredProcedureProperties cosmosStoredProcedureSettings = new StoredProcedureProperties()
            {
                Id = "mock"
            };

            TriggerProperties cosmosTriggerSettings = new TriggerProperties()
            {
                Id = "mock"
            };

            UserDefinedFunctionProperties cosmosUserDefinedFunctionSettings = new UserDefinedFunctionProperties()
            {
                Id = "mock"
            };

            Mock <Container> mockContainer = new Mock <Container>();
            Mock <Database>  mockDatabase  = new Mock <Database>();

            // Verify all the system types that should always use default
            cosmosResponseFactory.CreateContainerResponse(mockContainer.Object, containerResponse);
            cosmosResponseFactory.CreateDatabaseResponse(mockDatabase.Object, databaseResponse);
            cosmosResponseFactory.CreateStoredProcedureResponse(storedProcedureResponse);
            cosmosResponseFactory.CreateTriggerResponse(triggerResponse);
            cosmosResponseFactory.CreateUserDefinedFunctionResponse(udfResponse);
        }
Exemplo n.º 5
0
 public FullNameRule() : base()
 {
     TriggerProperties.Add(nameof(IPersonBase.Title));
     TriggerProperties.Add(nameof(IPersonBase.ShortName));
 }
Exemplo n.º 6
0
        public async Task InitializeAsync()
        {
            using var cosmosClient = new CosmosClient(LocalSettings.ConnectionString);

            var databaseResponse = await cosmosClient
                                   .CreateDatabaseIfNotExistsAsync(LocalSettings.DatabaseName)
                                   .ConfigureAwait(false);

            var testDatabase = databaseResponse.Database;

            var container = await testDatabase
                            .CreateContainerIfNotExistsAsync("catalog", "/partitionKey")
                            .ConfigureAwait(false);

            await container.Container
            .UpsertItemAsync(new CosmosSequenceNumber(int.MaxValue))
            .ConfigureAwait(false);

            await testDatabase
            .CreateContainerIfNotExistsAsync("cabinet", "/partitionKey")
            .ConfigureAwait(false);

            await testDatabase
            .CreateContainerIfNotExistsAsync("idempotency", "/partitionKey")
            .ConfigureAwait(false);

            await testDatabase
            .CreateContainerIfNotExistsAsync("actor", "/partitionKey")
            .ConfigureAwait(false);

            var bundlesResponse = await testDatabase
                                  .CreateContainerIfNotExistsAsync("bundle", "/recipient")
                                  .ConfigureAwait(false);

            var singleBundleViolationTrigger = new TriggerProperties
            {
                Id = "EnsureSingleUnacknowledgedBundle",
                TriggerOperation = TriggerOperation.Create,
                TriggerType      = TriggerType.Post,
                Body             = @"
function trigger() {

    var context = getContext();
    var container = context.getCollection();
    var response = context.getResponse();
    var createdItem = response.getBody();

    // Query for checking if there are other unacknowledged bundles for market operator.
    var filterQuery = `
    SELECT * FROM bundle b
    WHERE b.recipient = '${createdItem.recipient}' AND
          b.dequeued = false AND (
          b.origin = '${createdItem.origin}' OR
         ((b.origin = 'MarketRoles' OR b.origin = 'Charges') AND '${createdItem.origin}' = 'MeteringPoints') OR
         ((b.origin = 'Charges' OR b.origin = 'MeteringPoints') AND '${createdItem.origin}' = 'MarketRoles') OR
         ((b.origin = 'MarketRoles' OR b.origin = 'MeteringPoints') AND '${createdItem.origin}' = 'Charges'))`;

    var accept = container.queryDocuments(container.getSelfLink(), filterQuery, function(err, items, options)
    {
        if (err) throw err;
        if (items.length !== 0) throw 'SingleBundleViolation';
    });

    if (!accept) throw 'queryDocuments in trigger failed.';
}"
            };

            var bundles = bundlesResponse.Container;
            var scripts = bundles.Scripts;

            try
            {
                await scripts.DeleteTriggerAsync(singleBundleViolationTrigger.Id).ConfigureAwait(false);
            }
            catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                // Trigger not there, ignore.
            }

            await scripts.CreateTriggerAsync(singleBundleViolationTrigger).ConfigureAwait(false);
        }
Exemplo n.º 7
0
 public ShortNameRule() : base()
 {
     TriggerProperties.Add(nameof(ISimpleValidateObject.FirstName));
     TriggerProperties.Add(nameof(ISimpleValidateObject.LastName));
 }
Exemplo n.º 8
0
 public FullNameAsyncRule() : base()
 {
     TriggerProperties.Add(nameof(IPersonBase.FirstName));
     TriggerProperties.Add(nameof(IPersonBase.ShortName));
 }
Exemplo n.º 9
0
 public ShortNameDependencyRule(IDisposableDependency dd) : base()
 {
     TriggerProperties.Add(nameof(IPersonBase.FirstName));
     TriggerProperties.Add(nameof(IPersonBase.LastName));
     DisposableDependency = dd;
 }
Exemplo n.º 10
0
 public AsyncRuleBase(IEnumerable <IRegisteredProperty> triggerProperties) : this()
 {
     TriggerProperties.AddRange(triggerProperties.Select(t => t.Name));
 }
Exemplo n.º 11
0
 public AsyncRuleBase(IEnumerable <string> triggerProperties) : this()
 {
     TriggerProperties.AddRange(triggerProperties);
 }