Example #1
0
 private static void ExtractCosmosCommandProperties(CosmosDbFunctionDefinition functionDefinition)
 {
     functionDefinition.CommandProperties = functionDefinition
                                            .CommandType
                                            .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                                            .Where(x => x.GetCustomAttribute <SecurityPropertyAttribute>() == null &&
                                                   x.SetMethod != null)
                                            .Select(x =>
     {
         string cosmosPropertyName = x.Name;
         JsonPropertyAttribute jsonPropertyAttribute = x.GetCustomAttribute <JsonPropertyAttribute>();
         if (jsonPropertyAttribute != null)
         {
             cosmosPropertyName = jsonPropertyAttribute.PropertyName;
         }
         return(new CosmosDbCommandProperty
         {
             Name = x.Name,
             CosmosPropertyName = cosmosPropertyName,
             TypeName = x.PropertyType.EvaluateType(),
             Type = x.PropertyType
         });
     })
                                            .ToArray();
 }
Example #2
0
 public CosmosDbFunctionOptionBuilder(
     ConnectionStringSettingNames connectionStringSettingNames,
     ICosmosDbFunctionBuilder underlyingBuilder,
     CosmosDbFunctionDefinition functionDefinition)
 {
     _connectionStringSettingNames = connectionStringSettingNames;
     _underlyingBuilder            = underlyingBuilder;
     _functionDefinition           = functionDefinition;
 }
Example #3
0
        private void CompleteCosmosDbFunctionDefinition(CosmosDbFunctionDefinition cosmosDbFunctionDefinition)
        {
            Type documentCommandType      = typeof(ICosmosDbDocumentCommand);
            Type documentBatchCommandType = typeof(ICosmosDbDocumentBatchCommand);

            ExtractCosmosCommandProperties(cosmosDbFunctionDefinition);

            cosmosDbFunctionDefinition.IsDocumentCommand      = documentCommandType.IsAssignableFrom(cosmosDbFunctionDefinition.CommandType);
            cosmosDbFunctionDefinition.IsDocumentBatchCommand = documentBatchCommandType.IsAssignableFrom(cosmosDbFunctionDefinition.CommandType);
            if (cosmosDbFunctionDefinition.IsDocumentCommand && cosmosDbFunctionDefinition.IsDocumentBatchCommand)
            {
                throw new ConfigurationException(
                          $"Command {cosmosDbFunctionDefinition.CommandType.Name} implements both ICosmosDbDocumentCommand and ICosmosDbDocumentBatchCommand - it can only implement one of these interfaces");
            }
        }
Example #4
0
        public ICosmosDbFunctionOptionBuilder <TCommand> ChangeFeedFunction <TCommand, TCosmosDbErrorHandler>(
            string collectionName,
            string databaseName,
            string leaseCollectionName            = "leases",
            string leaseDatabaseName              = null,
            bool createLeaseCollectionIfNotExists = false,
            bool startFromBeginning            = false,
            bool convertToPascalCase           = false,
            string leaseCollectionPrefix       = null,
            int?maxItemsPerInvocation          = null,
            int?feedPollDelay                  = null,
            int?leaseAcquireInterval           = null,
            int?leaseExpirationInterval        = null,
            int?leaseRenewInterval             = null,
            int?checkpointFrequency            = null,
            int?leasesCollectionThroughput     = null,
            bool trackRemainingWork            = false,
            string remainingWorkCronExpression = "*/5 * * * * *"
            ) where TCommand : ICommand where TCosmosDbErrorHandler : ICosmosDbErrorHandler
        {
            CosmosDbFunctionDefinition definition = new CosmosDbFunctionDefinition(typeof(TCommand))
            {
                ConnectionStringName             = _connectionStringName,
                CollectionName                   = collectionName,
                DatabaseName                     = databaseName,
                LeaseConnectionStringName        = _leaseConnectionStringName,
                LeaseCollectionName              = leaseCollectionName,
                LeaseDatabaseName                = leaseDatabaseName ?? databaseName,
                CreateLeaseCollectionIfNotExists = createLeaseCollectionIfNotExists,
                ConvertToPascalCase              = convertToPascalCase,
                StartFromBeginning               = startFromBeginning,
                LeaseCollectionPrefix            = leaseCollectionPrefix,
                MaxItemsPerInvocation            = maxItemsPerInvocation,
                FeedPollDelay                    = feedPollDelay,
                LeaseAcquireInterval             = leaseAcquireInterval,
                LeaseExpirationInterval          = leaseExpirationInterval,
                LeaseRenewInterval               = leaseRenewInterval,
                CheckpointFrequency              = checkpointFrequency,
                LeasesCollectionThroughput       = leasesCollectionThroughput,
                ErrorHandlerType                 = typeof(TCosmosDbErrorHandler),
                ErrorHandlerTypeName             = typeof(TCosmosDbErrorHandler).EvaluateType(),
                TrackRemainingWork               = trackRemainingWork,
                RemainingWorkCronExpression      = remainingWorkCronExpression
            };

            _functionDefinitions.Add(definition);
            return(new CosmosDbFunctionOptionBuilder <TCommand>(_connectionStringSettingNames, this, definition));
        }
Example #5
0
        public ICosmosDbFunctionOptionBuilder ChangeFeedFunction <TCommand>(
            string collectionName,
            string databaseName,
            string leaseCollectionName            = "leases",
            string leaseDatabaseName              = null,
            bool createLeaseCollectionIfNotExists = false,
            bool startFromBeginning        = false,
            bool convertToPascalCase       = true,
            string leaseCollectionPrefix   = null,
            int?maxItemsPerInvocation      = null,
            int?feedPollDelay              = null,
            int?leaseAcquireInterval       = null,
            int?leaseExpirationInterval    = null,
            int?leaseRenewInterval         = null,
            int?checkpointFrequency        = null,
            int?leasesCollectionThroughput = null
            ) where TCommand : ICommand
        {
            CosmosDbFunctionDefinition definition = new CosmosDbFunctionDefinition(typeof(TCommand))
            {
                ConnectionStringName             = _connectionStringName,
                CollectionName                   = collectionName,
                DatabaseName                     = databaseName,
                LeaseConnectionStringName        = _leaseConnectionStringName,
                LeaseCollectionName              = leaseCollectionName,
                LeaseDatabaseName                = leaseDatabaseName ?? databaseName,
                CreateLeaseCollectionIfNotExists = createLeaseCollectionIfNotExists,
                ConvertToPascalCase              = convertToPascalCase,
                StartFromBeginning               = startFromBeginning,
                LeaseCollectionPrefix            = leaseCollectionPrefix,
                MaxItemsPerInvocation            = maxItemsPerInvocation,
                FeedPollDelay                    = feedPollDelay,
                LeaseAcquireInterval             = leaseAcquireInterval,
                LeaseExpirationInterval          = leaseExpirationInterval,
                LeaseRenewInterval               = leaseRenewInterval,
                CheckpointFrequency              = checkpointFrequency,
                LeasesCollectionThroughput       = leasesCollectionThroughput
            };

            _functionDefinitions.Add(definition);
            return(new CosmosDbFunctionOptionBuilder(this, definition));
        }
 public CosmosDbFunctionOptionBuilder(ICosmosDbFunctionBuilder underlyingBuilder,
                                      CosmosDbFunctionDefinition functionDefinition)
 {
     _underlyingBuilder  = underlyingBuilder;
     _functionDefinition = functionDefinition;
 }