Esempio n. 1
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            _options           = options;
            _connectionFactory = options.ConnectionFactory();

            _logger = options.Logger();

            Schema = new DocumentSchema(_options, _connectionFactory, _logger);


            _serializer = options.Serializer();

            var cleaner = new DocumentCleaner(_connectionFactory, Schema.As <DocumentSchema>());

            Advanced = new AdvancedOptions(cleaner, options, _serializer, Schema);

            Diagnostics = new Diagnostics(Schema);


            CreateDatabaseObjects();

            Transform = new DocumentTransforms(this);

            options.InitialData.Each(x => x.Populate(this));
        }
        public void resolve_storage_for_event_type()
        {
            var schema = new DocumentSchema(new StoreOptions(), new ConnectionSource(), new DevelopmentSchemaCreation(new ConnectionSource(), new NulloMartenLogger()));

            schema.StorageFor(typeof(RaceStarted)).ShouldBeOfType <EventMapping <RaceStarted> >()
            .DocumentType.ShouldBe(typeof(RaceStarted));
        }
Esempio n. 3
0
 public void SetType(DocumentSchema schema)
 {
     //string type, string format
     var type = schema.Type;
     var format = schema.Format;
     switch (type, format)
     {
        public void resolve_a_document_mapping_for_an_event_type()
        {
            var schema = new DocumentSchema(new StoreOptions(), null, null);

            schema.MappingFor(typeof(RaceStarted)).ShouldBeOfType <EventMapping <RaceStarted> >()
            .DocumentType.ShouldBe(typeof(RaceStarted));
        }
Esempio n. 5
0
        private void CreateDocSchema()
        {
            if (this.schemaCollection == null)
            {
                throw new ArgumentNullException("schemaCollection");
            }
            string docType = this.DocType;

            if (docType == null)
            {
                throw new ApplicationException("DocumentSpec does not contain a doctype.");
            }
            string[] strArray = docType.Split(new char[] { '#' });
            if (strArray.Length == 1)
            {
                this.documentSchema = new DocumentSchema(this.schemaCollection, "", new XmlQualifiedName(strArray[0]));
            }
            else
            {
                if (strArray.Length != 2)
                {
                    throw new ApplicationException(string.Format(CultureInfo.CurrentCulture, "Invalid doctype format: {0}", new object[] { docType }));
                }
                this.documentSchema = new DocumentSchema(this.schemaCollection, strArray[0], new XmlQualifiedName(strArray[1], strArray[0]));
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            _options = options;
            _runner  = new CommandRunner(options.ConnectionFactory());

            var creation = options.AutoCreateSchemaObjects
                ? (IDocumentSchemaCreation) new DevelopmentSchemaCreation(_runner)
                : new ProductionSchemaCreation();

            Schema = new DocumentSchema(_options, _runner, creation);

            Schema.Alter(options.Schema);

            _serializer = options.Serializer();

            var cleaner = new DocumentCleaner(_runner, Schema);

            Advanced = new AdvancedOptions(cleaner, options);

            Diagnostics = new Diagnostics(Schema, new MartenQueryExecutor(_runner, Schema, _serializer, _parser, new NulloIdentityMap(_serializer)));


            if (options.RequestCounterThreshold.HasThreshold)
            {
                _runnerForSession = () => new RequestCounter(_runner, options.RequestCounterThreshold);
            }
            else
            {
                _runnerForSession = () => _runner;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            _options           = options;
            _connectionFactory = options.ConnectionFactory();
            _runner            = new ManagedConnection(_connectionFactory, CommandRunnerMode.ReadOnly);

            _logger = options.Logger();

            var creation = options.AutoCreateSchemaObjects
                ? (IDocumentSchemaCreation) new DevelopmentSchemaCreation(_connectionFactory, _logger)
                : new ProductionSchemaCreation();

            Schema = new DocumentSchema(_options, _connectionFactory, creation);

            Schema.Alter(options.Schema);

            _serializer = options.Serializer();

            var cleaner = new DocumentCleaner(_connectionFactory, Schema);

            Advanced = new AdvancedOptions(cleaner, options);

            Diagnostics = new Diagnostics(Schema, new MartenQueryExecutor(_runner, Schema, _serializer, _parser, new NulloIdentityMap(_serializer)));

            EventStore = new EventStoreAdmin(_connectionFactory, _options, creation, _serializer);
        }
Esempio n. 8
0
        public void resolve_storage_for_event_type()
        {
            var schema = new DocumentSchema(new StoreOptions(), null, null);

            schema.StorageFor(typeof(RaceStarted)).ShouldBeOfType <EventMapping>()
            .DocumentType.ShouldBe(typeof(RaceStarted));
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            options.CreatePatching();

            _options           = options;
            _connectionFactory = options.ConnectionFactory();

            _logger = options.Logger();

            Schema = new DocumentSchema(_options, _connectionFactory, _logger);

            _serializer = options.Serializer();

            var cleaner = new DocumentCleaner(_connectionFactory, Schema.As <DocumentSchema>());

            Advanced = new AdvancedOptions(cleaner, options, _serializer, Schema);

            Diagnostics = new Diagnostics(Schema);


            CreateDatabaseObjects();

            Transform = new DocumentTransforms(this, _connectionFactory);

            options.InitialData.Each(x => x.Populate(this));


            if (options.AutoCreateSchemaObjects != AutoCreate.None)
            {
                Schema.As <DocumentSchema>().RebuildSystemFunctions();
            }
        }
Esempio n. 10
0
 private BaseOutputClass CreateDefinition(string name, DocumentSchema schema)
 {
     if (schema.Ref != null)
     {
         var refName = schema.Ref.Remove("#/components/schemas/".Length);
         var @class  = new OutputClass()
         {
             Name = refName
         };
         return(@class);
     }
     if (schema.Enum != null)
     {
         //create enum
         var @enum = new OutputEnum()
         {
             Name = name
         };
         @enum.SetType(schema);
         @enum.Types = schema.Enum;
         return(@enum);
     }
     else
     {
         //create class
         var @class = new OutputClass()
         {
             Name = name
         };
         @class.SetType(schema);
         return(@class);
     }
 }
        public void TestSchemaFragmentsIterator()
        {
            // arrange
            var            counter  = new UidPropertyCounter();
            var            iterator = new SchemaFragmentsIterator(counter);
            DocumentSchema schema;

            using (var sr = new StreamReader("TestData/schemas/rest.mixed.schema.json"))
            {
                schema = DocumentSchema.Load(sr, "rest.mixed");
            }
            var yamlStream = new YamlStream();

            using (var sr = new StreamReader("TestData/inputs/Suppressions.yml"))
            {
                yamlStream.Load(sr);
            }

            // act
            iterator.Traverse(yamlStream.Documents[0].RootNode, new Dictionary <string, MarkdownFragment>(), schema);

            // assert
            Assert.Single(counter.ExistingUids);
            Assert.Equal("management.azure.com.advisor.suppressions", counter.ExistingUids[0]);
            Assert.Single(counter.ExistingMarkdownProperties);
            Assert.Equal("definitions[name=\"Application 1\"]/properties[name=\"id\"]/description", counter.ExistingMarkdownProperties[0]);
            Assert.Equal(6, counter.MissingMarkdownProperties.Count);
        }
Esempio n. 12
0
        private IEnumerable <IDocumentProcessor> LoadSchemaDrivenDocumentProcessors(DocumentBuildParameters parameter)
        {
            using (var resource = parameter?.TemplateManager?.CreateTemplateResource())
            {
                if (resource == null || resource.IsEmpty)
                {
                    yield break;
                }

                foreach (var pair in resource.GetResourceStreams(@"^schemas/.*\.schema\.json"))
                {
                    var fileName = Path.GetFileName(pair.Key);
                    using (new LoggerFileScope(fileName))
                    {
                        using (var stream = pair.Value)
                        {
                            using (var sr = new StreamReader(stream))
                            {
                                var schema = DocumentSchema.Load(sr, fileName.Remove(fileName.Length - ".schema.json".Length));
                                var sdp    = new SchemaDrivenDocumentProcessor(schema, new CompositionContainer(CompositionContainer.DefaultContainer));
                                Logger.LogVerbose($"\t{sdp.Name} with build steps ({string.Join(", ", from bs in sdp.BuildSteps orderby bs.BuildOrder select bs.Name)})");
                                yield return(sdp);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 13
0
        public MartenRegistryTests()
        {
            var storeOptions = new StoreOptions();

            storeOptions.Schema.Include <TestRegistry>();

            theSchema = new DocumentSchema(storeOptions, new ConnectionSource(), new NulloMartenLogger());
        }
Esempio n. 14
0
 public void cannot_use_a_doc_type_with_no_id()
 {
     Exception <InvalidDocumentException> .ShouldBeThrownBy(() =>
     {
         var schema = new DocumentSchema(new StoreOptions(), null, null);
         schema.MappingFor(typeof(BadDoc)).ShouldBeNull();
     });
 }
        public void should_get_foreign_key_from_attribute()
        {
            var schema = new DocumentSchema(new StoreOptions(), null, null);

            schema.MappingFor(typeof(Issue))
            .As <DocumentMapping>()
            .ForeignKeys
            .ShouldContain(x => x.ColumnName == "user_id");
        }
Esempio n. 16
0
        private List <IDocumentProcessor> LoadSchemaDrivenDocumentProcessors(DocumentBuildParameters parameter)
        {
            using (new LoggerPhaseScope(nameof(LoadSchemaDrivenDocumentProcessors)))
            {
                var result = new List <IDocumentProcessor>();

                SchemaValidateService.RegisterLicense(parameter.SchemaLicense);
                using (var resource = parameter?.TemplateManager?.CreateTemplateResource())
                {
                    if (resource == null || resource.IsEmpty)
                    {
                        return(result);
                    }

                    var markdigMarkdownService = CreateMarkdigMarkdownService(parameter);
                    foreach (var pair in resource.GetResourceStreams(@"^schemas/.*\.schema\.json"))
                    {
                        var fileName = Path.GetFileName(pair.Key);
                        using (new LoggerFileScope(fileName))
                        {
                            using (var stream = pair.Value)
                            {
                                using (var sr = new StreamReader(stream))
                                {
                                    DocumentSchema schema;
                                    try
                                    {
                                        schema = DocumentSchema.Load(sr, fileName.Remove(fileName.Length - ".schema.json".Length));
                                    }
                                    catch (Exception e)
                                    {
                                        Logger.LogError(e.Message);
                                        throw;
                                    }
                                    var sdp = new SchemaDrivenDocumentProcessor(
                                        schema,
                                        new CompositionContainer(CompositionContainer.DefaultContainer),
                                        markdigMarkdownService,
                                        new FolderRedirectionManager(parameter.OverwriteFragmentsRedirectionRules));
                                    Logger.LogVerbose($"\t{sdp.Name} with build steps ({string.Join(", ", from bs in sdp.BuildSteps orderby bs.BuildOrder select bs.Name)})");
                                    result.Add(sdp);
                                }
                            }
                        }
                    }
                }

                if (result.Count > 0)
                {
                    Logger.LogInfo($"{result.Count} schema driven document processor plug-in(s) loaded.");
                    Processors = Processors.Union(result);
                }
                return(result);
            }
        }
Esempio n. 17
0
        public void can_override_with_MartenRegistry()
        {
            var storeOptions = new StoreOptions();

            storeOptions.Schema.For <Organization>().Searchable(x => x.Time2, pgType: "timestamp");

            var schema = new DocumentSchema(storeOptions, null, new NulloMartenLogger());

            schema.MappingFor(typeof(Organization)).As <DocumentMapping>().DuplicatedFields.Single(x => x.MemberName == "Time2")
            .PgType.ShouldBe("timestamp");
        }
Esempio n. 18
0
        public void can_override_with_MartenRegistry()
        {
            var registry = new MartenRegistry();

            registry.For <Organization>().Searchable(x => x.Time2, pgType: "timestamp");

            var schema = new DocumentSchema(new StoreOptions(), null, null);

            schema.Alter(registry);

            schema.MappingFor(typeof(Organization)).DuplicatedFields.Single(x => x.MemberName == "Time2")
            .PgType.ShouldBe("timestamp");
        }
Esempio n. 19
0
        private static Dictionary <string, DocumentSchema> LoadSchemas(string schemaFolderPath)
        {
            var schemas = new Dictionary <string, DocumentSchema>();

            foreach (var schemaFile in Directory.EnumerateFiles(schemaFolderPath, "*.schema.json"))
            {
                using var sr = new StreamReader(schemaFile);
                var schema = DocumentSchema.Load(sr, schemaFile.Remove(schemaFile.Length - ".schema.json".Length));
                schemas.Add(schema.Title, schema);
            }

            return(schemas);
        }
        public when_deriving_the_table_definition_from_the_database_schema_Tests()
        {
            ConnectionSource.CleanBasicDocuments();
            _schema = _container.GetInstance <DocumentSchema>();

            theMapping = _schema.MappingFor(typeof(User)).As <DocumentMapping>();
            theMapping.DuplicateField("UserName");


            _storage = _schema.StorageFor(typeof(User));

            theDerivedTable = _schema.TableSchema(theMapping.TableName);
        }
        public void should_get_foreign_key_from_registry()
        {
            var storeOptions = new StoreOptions();

            storeOptions.Schema.For <Issue>().ForeignKey <User>(i => i.OtherUserId);

            var schema = new DocumentSchema(storeOptions, null, null);

            schema.MappingFor(typeof(Issue))
            .As <DocumentMapping>()
            .ForeignKeys
            .ShouldContain(x => x.ColumnName == "other_user_id");
        }
Esempio n. 22
0
        public object Process(object raw, DocumentSchema schema, IProcessContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.Model == null)
            {
                throw new ArgumentNullException(nameof(context) + "." + nameof(context.Model));
            }

            return(InterpretCore(raw, schema, string.Empty, context));
        }
Esempio n. 23
0
        public static BaseOutputClass GetClassDefinition(DocumentSchema schema, List <BaseOutputClass> baseOutputClasses = null)
        {
            if (schema.Ref != null)
            {
                var refName = schema.Ref.Substring("#/components/schemas/".Length);

                if (baseOutputClasses != null)
                {
                    var item = baseOutputClasses.FirstOrDefault(p => p.Name == refName);

                    if (item != null)
                    {
                        if (item is OutputEnum)
                        {
                            var @enum = new OutputEnum()
                            {
                                Name = refName
                            };
                            return(@enum);
                        }
                    }
                }
                var @class = new OutputClass()
                {
                    Name = refName
                };
                return(@class);
            }
            if (schema.Enum != null)
            {
                //create enum
                var @enum = new OutputEnum()
                {
                };
                @enum.SetType(schema);
                @enum.Types = schema.Enum;
                return(@enum);
            }
            else
            {
                //create class
                var @class = new OutputClass()
                {
                };
                @class.SetType(schema);
                return(@class);
            }
        }
Esempio n. 24
0
 internal BaseOutputClass CreateDefinitionWithDeep(DocumentSchema schema, List <BaseOutputClass> list)
 {
     if (schema.Enum != null)
     {
         return(ClassFactory.GetClassDefinition(schema));
     }
     else
     {
         //create class
         var @class = new OutputClass()
         {
         };
         @class.SetType(schema);
         @class.SetProperties(this, list, schema);
         @class.SetInnerClass(this, list, schema);
         return(@class);
     }
 }
Esempio n. 25
0
        public void builds_schema_objects_on_the_fly_as_needed()
        {
            _schema.StorageFor(typeof(User)).ShouldNotBeNull();
            _schema.StorageFor(typeof(Issue)).ShouldNotBeNull();
            _schema.StorageFor(typeof(Company)).ShouldNotBeNull();

            var schema = new DocumentSchema(new ConnectionSource(), new DevelopmentSchemaCreation(new ConnectionSource()));
            var tables = schema.SchemaTableNames();

            tables.ShouldContain(DocumentMapping.TableNameFor(typeof(User)).ToLower());
            tables.ShouldContain(DocumentMapping.TableNameFor(typeof(Issue)).ToLower());
            tables.ShouldContain(DocumentMapping.TableNameFor(typeof(Company)).ToLower());

            var functions = schema.SchemaFunctionNames();

            functions.ShouldContain(DocumentMapping.UpsertNameFor(typeof(User)).ToLower());
            functions.ShouldContain(DocumentMapping.UpsertNameFor(typeof(Issue)).ToLower());
            functions.ShouldContain(DocumentMapping.UpsertNameFor(typeof(Company)).ToLower());
        }
Esempio n. 26
0
        /// <summary>
        /// Creates a new DocumentStore with the supplied StoreOptions
        /// </summary>
        /// <param name="options"></param>
        public DocumentStore(StoreOptions options)
        {
            _options           = options;
            _connectionFactory = options.ConnectionFactory();

            _logger = options.Logger();

            Schema = new DocumentSchema(_options, _connectionFactory, _logger);


            _serializer = options.Serializer();

            var cleaner = new DocumentCleaner(_connectionFactory, Schema.As <DocumentSchema>());

            Advanced = new AdvancedOptions(cleaner, options, _serializer, Schema);

            Diagnostics = new Diagnostics(Schema);

            EventStore = new EventStoreAdmin(Schema, _connectionFactory, _options, _serializer);

            CreateDatabaseObjects();
        }
Esempio n. 27
0
        public void SetProperties(ClassFactory factory, List <BaseOutputClass> list, DocumentSchema schema)
        {
            if (schema.Properties != null && schema.Properties.Count > 0)
            {
                Properties = new List <ClassProperty>();
                foreach (var property in schema.Properties)
                {
                    var propertyValue = property.Value;
                    var @ref          = propertyValue.Ref;

                    var innerEntity = @ref != null?
                                      list.First(p => p.ReferenceName == @ref) : factory.CreateDefinitionWithDeep(property.Value, list);

                    Properties.Add(new ClassProperty()
                    {
                        IsNullable = !schema.Required.Contains(property.Key),
                        Name       = property.Key,
                        Class      = innerEntity
                    });
                }
            }
        }
Esempio n. 28
0
        internal void SetInnerClass(ClassFactory factory, List <BaseOutputClass> list, DocumentSchema schema)
        {
            if (IsDictionary)
            {
                var @ref        = schema.AdditionalProperties.Ref;
                var innerEntity = @ref != null?
                                  list.First(p => p.ReferenceName == @ref) : factory.CreateDefinitionWithDeep(schema.AdditionalProperties, list);

                InnerClass = innerEntity;
                return;
            }
            if (Type == ClassTypeEnum.Array)
            {
                var @ref        = schema.Items.Ref;
                var innerEntity = @ref != null?
                                  list.First(p => p.ReferenceName == @ref) : factory.CreateDefinitionWithDeep(schema.Items, list);

                InnerClass = innerEntity;
            }
        }
Esempio n. 29
0
        public void resolve_storage_for_stream_type()
        {
            var schema = new DocumentSchema(new StoreOptions(), null, null);

            schema.StorageFor(typeof(Stream <Race>)).ShouldBeOfType <AggregateStorage <Race> >();
        }
Esempio n. 30
0
        public MartenRegistryTests()
        {
            theSchema = Container.For <DevelopmentModeRegistry>().GetInstance <DocumentSchema>();

            theSchema.Alter <TestRegistry>();
        }