コード例 #1
0
        internal static IWriteOperation <BsonDocument> CreateEncryptedDropCollectionOperationIfConfigured(
            CollectionNamespace collectionNamespace,
            BsonDocument encryptedFields,
            MessageEncoderSettings messageEncoderSettings,
            Action <DropCollectionOperation> configureDropCollectionConfigurator)
        {
            var mainOperation = new DropCollectionOperation(collectionNamespace, messageEncoderSettings)
            {
                EncryptedFields = encryptedFields
            };

            configureDropCollectionConfigurator?.Invoke(mainOperation);

            if (encryptedFields != null)
            {
                return(new CompositeWriteOperation <BsonDocument>(
                           (CreateInnerDropOperation(EncryptedCollectionHelper.GetAdditionalCollectionName(encryptedFields, collectionNamespace, HelperCollectionForEncryption.Esc)), IsMainOperation: false),
                           (CreateInnerDropOperation(EncryptedCollectionHelper.GetAdditionalCollectionName(encryptedFields, collectionNamespace, HelperCollectionForEncryption.Ecc)), IsMainOperation: false),
                           (CreateInnerDropOperation(EncryptedCollectionHelper.GetAdditionalCollectionName(encryptedFields, collectionNamespace, HelperCollectionForEncryption.Ecos)), IsMainOperation: false),
                           (mainOperation, IsMainOperation: true)));
            }
            else
            {
                return(mainOperation);
            }

            DropCollectionOperation CreateInnerDropOperation(string collectionName)
            => new DropCollectionOperation(new CollectionNamespace(collectionNamespace.DatabaseNamespace.DatabaseName, collectionName), messageEncoderSettings);
        }
コード例 #2
0
        internal static IWriteOperation <BsonDocument> CreateEncryptedCreateCollectionOperationIfConfigured(
            CollectionNamespace collectionNamespace,
            BsonDocument encryptedFields,
            MessageEncoderSettings messageEncoderSettings,
            Action <CreateCollectionOperation> createCollectionOperationConfigurator)
        {
            var mainOperation = new CreateCollectionOperation(
                collectionNamespace,
                messageEncoderSettings)
            {
                EncryptedFields = encryptedFields
            };

            createCollectionOperationConfigurator?.Invoke(mainOperation);

            if (encryptedFields != null)
            {
                return(new CompositeWriteOperation <BsonDocument>(
                           (CreateInnerCollectionOperation(EncryptedCollectionHelper.GetAdditionalCollectionName(encryptedFields, collectionNamespace, HelperCollectionForEncryption.Esc)), IsMainOperation: false),
                           (CreateInnerCollectionOperation(EncryptedCollectionHelper.GetAdditionalCollectionName(encryptedFields, collectionNamespace, HelperCollectionForEncryption.Ecc)), IsMainOperation: false),
                           (CreateInnerCollectionOperation(EncryptedCollectionHelper.GetAdditionalCollectionName(encryptedFields, collectionNamespace, HelperCollectionForEncryption.Ecos)), IsMainOperation: false),
                           (mainOperation, IsMainOperation: true),
                           (new CreateIndexesOperation(collectionNamespace, new[] { new CreateIndexRequest(EncryptedCollectionHelper.AdditionalCreateIndexDocument) }, messageEncoderSettings), IsMainOperation: false)));
            }
            else
            {
                return(mainOperation);
            }

            CreateCollectionOperation CreateInnerCollectionOperation(string collectionName)
            => new CreateCollectionOperation(new CollectionNamespace(collectionNamespace.DatabaseNamespace.DatabaseName, collectionName), messageEncoderSettings)
            {
                ClusteredIndex = new BsonDocument {
                    { "key", new BsonDocument("_id", 1) }, { "unique", true }
                }
            };
        }