public UnifiedAggregateOnDatabaseOperation Build(string targetDatabaseId, BsonDocument arguments) { var database = _entityMap.GetDatabase(targetDatabaseId); AggregateOptions options = null; PipelineDefinition <NoPipelineInput, BsonDocument> pipeline = null; foreach (var argument in arguments) { switch (argument.Name) { case "allowDiskUse": options ??= new AggregateOptions(); options.AllowDiskUse = argument.Value.AsBoolean; break; case "pipeline": var stages = argument.Value.AsBsonArray.Cast <BsonDocument>(); pipeline = new BsonDocumentStagePipelineDefinition <NoPipelineInput, BsonDocument>(stages); break; default: throw new FormatException($"Invalid AggregateOperation argument name: '{argument.Name}'."); } } return(new UnifiedAggregateOnDatabaseOperation(database, pipeline, options)); }
public UnifiedCreateCollectionOperation Build(string targetDatabaseId, BsonDocument arguments) { var database = _entityMap.GetDatabase(targetDatabaseId); string collectionName = null; IClientSessionHandle session = null; foreach (var argument in arguments) { switch (argument.Name) { case "collection": collectionName = argument.Value.AsString; break; case "session": var sessionId = argument.Value.AsString; session = _entityMap.GetSession(sessionId); break; default: throw new FormatException($"Invalid CreateCollectionOperation argument name: '{argument.Name}'."); } } return(new UnifiedCreateCollectionOperation(session, database, collectionName)); }
public UnifiedListCollectionsOperation Build(string targetDatabaseId, BsonDocument arguments) { var database = _entityMap.GetDatabase(targetDatabaseId); var listCollectionsOptions = new ListCollectionsOptions(); IClientSessionHandle session = null; if (arguments != null) { foreach (var argument in arguments) { switch (argument.Name) { case "filter": listCollectionsOptions.Filter = argument.Value.AsBsonDocument; break; case "batchSize": listCollectionsOptions.BatchSize = argument.Value.ToInt32(); break; case "session": session = _entityMap.GetSession(argument.Value.AsString); break; default: throw new FormatException($"Invalid AssertIndexNotExistsOperation argument name: '{argument.Name}'."); } } } return(new UnifiedListCollectionsOperation(database, listCollectionsOptions, session)); }
public UnifiedRunCommandOperation Build(string targetDatabaseId, BsonDocument arguments) { var database = _entityMap.GetDatabase(targetDatabaseId); string commandName = null; BsonDocument command = null; IClientSessionHandle session = null; foreach (var argument in arguments) { switch (argument.Name) { case "commandName": commandName = argument.Value.AsString; break; case "command": command = argument.Value.AsBsonDocument; break; case "session": session = _entityMap.GetSession(argument.Value.AsString); break; default: throw new FormatException($"Invalid RunCommandOperation argument name: '{argument.Name}'."); } } return(new UnifiedRunCommandOperation(database, commandName, command, session)); }
public UnifiedCreateChangeStreamOnDatabaseOperation Build(string targetClientId, BsonDocument arguments) { var database = _entityMap.GetDatabase(targetClientId); ChangeStreamOptions options = null; BsonDocumentStagePipelineDefinition <ChangeStreamDocument <BsonDocument>, ChangeStreamDocument <BsonDocument> > pipeline = null; foreach (var argument in arguments) { switch (argument.Name) { case "batchSize": options = options ?? new ChangeStreamOptions(); options.BatchSize = argument.Value.AsInt32; break; case "pipeline": var stages = argument.Value.AsBsonArray.Cast <BsonDocument>(); pipeline = new BsonDocumentStagePipelineDefinition <ChangeStreamDocument <BsonDocument>, ChangeStreamDocument <BsonDocument> >(stages); break; default: throw new FormatException($"Invalid CreateChangeStreamOperation argument name: '{argument.Name}'."); } } return(new UnifiedCreateChangeStreamOnDatabaseOperation(database, pipeline, options)); }
public UnifiedCreateCollectionOperation Build(string targetDatabaseId, BsonDocument arguments) { var database = _entityMap.GetDatabase(targetDatabaseId); string collectionName = null; CreateCollectionOptions createCollectionOptions = null; IClientSessionHandle session = null; foreach (var argument in arguments) { switch (argument.Name) { case "collection": collectionName = argument.Value.AsString; break; case "expireAfterSeconds": createCollectionOptions ??= new CreateCollectionOptions(); createCollectionOptions.ExpireAfter = TimeSpan.FromSeconds(argument.Value.ToInt64()); break; case "session": var sessionId = argument.Value.AsString; session = _entityMap.GetSession(sessionId); break; case "timeseries": var timeseries = argument.Value.AsBsonDocument; var timeField = timeseries["timeField"].AsString; var metaField = timeseries.TryGetValue("metaField", out var metaFieldValue) ? metaFieldValue.AsString : null; TimeSeriesGranularity?granularity = null; if (timeseries.TryGetValue("granularity", out var granularityValue)) { granularity = (TimeSeriesGranularity)Enum.Parse(typeof(TimeSeriesGranularity), granularityValue.AsString, true); } createCollectionOptions ??= new CreateCollectionOptions(); createCollectionOptions.TimeSeriesOptions = new TimeSeriesOptions(timeField, metaField, granularity); break; default: throw new FormatException($"Invalid CreateCollectionOperation argument name: '{argument.Name}'."); } } return(new UnifiedCreateCollectionOperation(session, database, collectionName, createCollectionOptions)); }
public UnifiedDropCollectionOperation Build(string targetDatabaseId, BsonDocument arguments) { var database = _entityMap.GetDatabase(targetDatabaseId); string collectionName = null; foreach (var argument in arguments) { switch (argument.Name) { case "collection": collectionName = argument.Value.AsString; break; default: throw new FormatException($"Invalid DropCollectionOperation argument name: '{argument.Name}'."); } } return(new UnifiedDropCollectionOperation(database, collectionName)); }
public IUnifiedEntityTestOperation Build(string targetDatabaseId, BsonDocument arguments) { var database = _entityMap.GetDatabase(targetDatabaseId); string name = null; string viewOn = null; PipelineDefinition <BsonDocument, BsonDocument> pipeline = null; IClientSessionHandle session = null; TimeSpan? expireAfter = null; TimeSeriesOptions timeSeriesOptions = null; ClusteredIndexOptions <BsonDocument> clusteredIndex = null; foreach (var argument in arguments) { switch (argument.Name) { case "clusteredIndex": var clusteredIndexSpecification = argument.Value.AsBsonDocument; clusteredIndex = new ClusteredIndexOptions <BsonDocument> { Key = clusteredIndexSpecification["key"].AsBsonDocument, Unique = clusteredIndexSpecification["unique"].AsBoolean, Name = clusteredIndexSpecification["name"].AsString }; break; case "collection": name = argument.Value.AsString; break; case "expireAfterSeconds": expireAfter = TimeSpan.FromSeconds(argument.Value.ToInt64()); break; case "pipeline": pipeline = new EmptyPipelineDefinition <BsonDocument>(); foreach (var stage in argument.Value.AsBsonArray) { pipeline = pipeline.AppendStage <BsonDocument, BsonDocument, BsonDocument>(stage.AsBsonDocument); } break; case "session": var sessionId = argument.Value.AsString; session = _entityMap.GetSession(sessionId); break; case "timeseries": var timeseries = argument.Value.AsBsonDocument; var timeField = timeseries["timeField"].AsString; var metaField = timeseries.TryGetValue("metaField", out var metaFieldValue) ? metaFieldValue.AsString : null; TimeSeriesGranularity?granularity = null; if (timeseries.TryGetValue("granularity", out var granularityValue)) { granularity = (TimeSeriesGranularity)Enum.Parse(typeof(TimeSeriesGranularity), granularityValue.AsString, true); } timeSeriesOptions = new TimeSeriesOptions(timeField, metaField, granularity); break; case "viewOn": viewOn = argument.Value.AsString; break; default: throw new FormatException($"Invalid CreateCollectionOperation argument name: '{argument.Name}'."); } } if (viewOn == null && pipeline == null) { var options = new CreateCollectionOptions <BsonDocument> { ExpireAfter = expireAfter, TimeSeriesOptions = timeSeriesOptions, ClusteredIndex = clusteredIndex }; return(new UnifiedCreateCollectionOperation(session, database, name, options)); } if (viewOn != null && expireAfter == null && timeSeriesOptions == null && clusteredIndex == null) { var options = new CreateViewOptions <BsonDocument>(); return(new UnifiedCreateViewOperation(session, database, name, viewOn, pipeline, options)); } var invalidArguments = string.Join(",", arguments.Elements.Select(x => x.Name)); throw new InvalidOperationException($"Invalid combination of CreateCollectionOperation arguments: {invalidArguments}"); }
public IUnifiedEntityTestOperation BuildDatabaseOperation(string targetCollectionId, BsonDocument arguments) { var database = _entityMap.GetDatabase(targetCollectionId); return(Build(database, collection: null, arguments)); }