//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDropUniquenessConstraintWhereConstraintRecordIsMissingAndIndexHasNoOwner() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDropUniquenessConstraintWhereConstraintRecordIsMissingAndIndexHasNoOwner() { // given using ( Transaction tx = Db.beginTx() ) { Db.schema().constraintFor(_label).assertPropertyIsUnique(_key).create(); tx.Success(); } // when intentionally breaking the schema by setting the backing index rule to unused RecordStorageEngine storageEngine = Db.DependencyResolver.resolveDependency( typeof( RecordStorageEngine ) ); SchemaStore schemaStore = storageEngine.TestAccessNeoStores().SchemaStore; SchemaRule constraintRule = single( filter( rule => rule is ConstraintRule, schemaStore.LoadAllSchemaRules() ) ); SetSchemaRecordNotInUse( schemaStore, constraintRule.Id ); SchemaRule indexRule = single( filter( rule => rule is StoreIndexDescriptor, schemaStore.LoadAllSchemaRules() ) ); SetOwnerNull( schemaStore, ( StoreIndexDescriptor ) indexRule ); // At this point the SchemaCache doesn't know about this change so we have to reload it storageEngine.LoadSchemaCache(); using ( Transaction tx = Db.beginTx() ) { // We don't use single() here, because it is okay for the schema cache reload to clean up after us. Db.schema().getConstraints(_label).forEach(ConstraintDefinition.drop); Db.schema().getIndexes(_label).forEach(IndexDefinition.drop); tx.Success(); } // then using ( Transaction ignore = Db.beginTx() ) { assertFalse( Db.schema().Constraints.GetEnumerator().hasNext() ); assertFalse( Db.schema().Indexes.GetEnumerator().hasNext() ); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDropUniquenessConstraintWithBackingIndexHavingNoOwner() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDropUniquenessConstraintWithBackingIndexHavingNoOwner() { // given using ( Transaction tx = Db.beginTx() ) { Db.schema().constraintFor(_label).assertPropertyIsUnique(_key).create(); tx.Success(); } // when intentionally breaking the schema by setting the backing index rule to unused RecordStorageEngine storageEngine = Db.DependencyResolver.resolveDependency( typeof( RecordStorageEngine ) ); SchemaStore schemaStore = storageEngine.TestAccessNeoStores().SchemaStore; SchemaRule indexRule = single( filter( rule => rule is StoreIndexDescriptor, schemaStore.LoadAllSchemaRules() ) ); SetOwnerNull( schemaStore, ( StoreIndexDescriptor ) indexRule ); // At this point the SchemaCache doesn't know about this change so we have to reload it storageEngine.LoadSchemaCache(); using ( Transaction tx = Db.beginTx() ) { single( Db.schema().getConstraints(_label).GetEnumerator() ).drop(); tx.Success(); } // then using ( Transaction ignore = Db.beginTx() ) { assertFalse( Db.schema().Constraints.GetEnumerator().hasNext() ); assertFalse( Db.schema().Indexes.GetEnumerator().hasNext() ); } }
private void SetSchemaRecordNotInUse( SchemaStore schemaStore, long id ) { DynamicRecord record = schemaStore.NewRecord(); record.Id = id; record.InUse = false; schemaStore.UpdateRecord( record ); }
public SchemaStore GetStore(DotNotation notation = null, IEnumerable <object> contracts = null) { BindingMetadataBuilder bindingBuilder = new BindingMetadataBuilder(); ReferenceMetadataBuilder referenceBuilder = new ReferenceMetadataBuilder(); TableMetadataBuilder tableBuilder = new TableMetadataBuilder(); SchemaStore store = new SchemaStore(notation ?? new DotNotation(), bindingBuilder, referenceBuilder, tableBuilder); if (contracts != null) { foreach (var contract in contracts) { if (contract is IRelationContractResolver relationResolver) { store.Use(relationResolver); } if (contract is IBindingContractResolver bindingResolver) { store.Use(bindingResolver); } if (contract is ITableContractResolver tableResolver) { store.Use(tableResolver); } } } return(store); }
static void Main(string[] args) { Options options; try { options = ValidateArguments(args); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); Usage(); return; } try { var esClient = new ElasticClient( new ConnectionSettings( new SingleNodeConnectionPool(new Uri(options.ElasticsearchUrl)), JsonNetSerializer.Default)); var config = new ApplicationConfiguration { ElasticsearchUrl = options.ElasticsearchUrl }; var datasetsStore = new DatasetStore(esClient, config); var schemaStore = new SchemaStore(esClient, config); var importer = new Importer(options, datasetsStore, schemaStore); importer.RunAsync().Wait(); } catch (Exception ex) { Console.Error.WriteLine("Error running import process: " + ex); } }
// POST api/values public bool Post(int id, [FromBody] SchemaStore value) { try { var ctx = new DataAccess.GraphKnowledgeEntities(); var schemaInfo = ctx.SchemaInformations.Add(new DataAccess.SchemaInformation { UserSchemaId = id, SchemaInfo = value.SchemaInfo, CreationDate = DateTime.UtcNow, ModifiedBy = value.ModifiedBy, Status = Constants.Active }); var schemaInfoChanges = ctx.SaveChanges(); var informations = ctx.SchemaInformations .Where(f => f.UserSchemaId == id && f.Status == Constants.Active && schemaInfo.Id != f.Id).ToList(); foreach (var information in informations) { information.Status = Constants.InActive; } ctx.SaveChanges(); //if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath($"~/Content/graph{DateTime.Now.ToString("yyyyMMdd")}.json"))) //{ // File.WriteAllText(System.Web.HttpContext.Current.Server.MapPath($"~/Content/graph{DateTime.Now.ToString("yyyyMMdd")}.json"), File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath("~/Content/graph.json"))); //} //File.WriteAllText(System.Web.HttpContext.Current.Server.MapPath("~/Content/graph.json"), value); return(true); } catch (Exception e) { } return(false); }
public QueryOptions GetQueryOptions(SchemaStore schemas = null) { return(new QueryOptions() { ConnectionFactory = () => new ProfilingConnection(new SqliteConnection("DATA SOURCE=testdb.db")), Schemas = schemas ?? this.Schemas, }); }
public QueryOptions GetQueryOptions(SchemaStore schemas = null) { return(new QueryOptions() { ConnectionFactory = () => new ProfilingConnection(new SqliteConnection(TestDbConnectionString)), Schemas = schemas ?? this.Schemas, }); }
public void Test_SchemaStore_DisallowsRecursion() { var store = new SchemaStore(new DotNotation(StringComparer.Ordinal), new RecursiveMetadataBuilder()); var schema = store.GetSchema(typeof(TupleModel)); schema.ShouldNotBeNull(); Should.Throw <MetadataBuilderException>(() => schema.Lookup <CustomMetadata>("Value")); }
private void SetOwnerNull( SchemaStore schemaStore, StoreIndexDescriptor rule ) { rule = rule.WithOwningConstraint( null ); IList<DynamicRecord> dynamicRecords = schemaStore.AllocateFrom( rule ); foreach ( DynamicRecord record in dynamicRecords ) { schemaStore.UpdateRecord( record ); } }
public void Test_Metadata_Invalid_Constract() { var customStore = new SchemaStore(new DotNotation()); customStore.Use(new InvalidContractResolver()); var schema = customStore.GetSchema(typeof(CustomModel)); Should.Throw <MetadataBuilderException>(() => schema.Lookup <IRelationMetadata>("List1")); }
public override bool VisitSchemaRuleCommand(SchemaRuleCommand command) { SchemaStore schemaStore = _neoStores.SchemaStore; foreach (DynamicRecord record in command.RecordsAfter) { Track(schemaStore, record); } return(false); }
public SchemaStore GetSchemas() { RelationMetadataBuilder relationBuilder = new RelationMetadataBuilder(); BindingMetadataBuilder bindingBuilder = new BindingMetadataBuilder(); ReferenceMetadataBuilder referenceBuilder = new ReferenceMetadataBuilder(); SchemaStore store = new SchemaStore(new DotNotation(), relationBuilder, bindingBuilder, referenceBuilder); bindingBuilder.Add(new SqliteContractResolver()); return(store); }
public void Test_MetadataBuilder_DisallowsRecursiveCalls() { SchemaStore store = new SchemaStore(new DotNotation(StringComparer.Ordinal)) { new RecursiveMetadataBuilder() }; ISchema schema = store.GetSchema(typeof(TupleModel)); schema.ShouldNotBeNull(); Should.Throw <MetadataBuilderException>(() => schema.GetMetadata <CustomMetadata>("Item.Value")); }
// PUT api/values/5 public string Put(int id, string mode, [FromBody] SchemaStore value) { try { var ctx = new DataAccess.GraphKnowledgeEntities(); if (mode?.ToLowerInvariant() == "undo") { var SchemaInformationFrom = ctx.SchemaInformations.Where(f => f.UserSchemaId == id && f.Status == Constants.Active) .OrderByDescending(p => p.CreationDate) .FirstOrDefault(); var SchemaInformationTo = ctx.SchemaInformations.Where(f => f.UserSchemaId == id && f.Status == Constants.InActive && f.Id < SchemaInformationFrom.Id) .OrderByDescending(p => p.CreationDate) .FirstOrDefault(); if (SchemaInformationFrom == null || SchemaInformationTo == null) { return("Data Missing"); } SchemaInformationFrom.Status = Constants.InActive; SchemaInformationTo.Status = Constants.Active; ctx.SaveChanges(); return(SchemaInformationTo.SchemaInfo); } else if (mode?.ToLowerInvariant() == "redo") { var SchemaInformationFrom = ctx.SchemaInformations.Where(f => f.UserSchemaId == id && f.Status == Constants.Active) .OrderByDescending(p => p.CreationDate) .FirstOrDefault(); var SchemaInformationTo = ctx.SchemaInformations.Where(f => f.UserSchemaId == id && f.Status == Constants.InActive && f.Id > SchemaInformationFrom.Id).OrderBy(p => p.CreationDate) .FirstOrDefault(); if (SchemaInformationFrom == null || SchemaInformationTo == null) { return("Data Missing"); } SchemaInformationFrom.Status = Constants.InActive; SchemaInformationTo.Status = Constants.Active; ctx.SaveChanges(); return(SchemaInformationTo.SchemaInfo); } } catch (Exception e) { return(e.Message); } return(string.Empty); }
public void Test_Metadata_WithInvalidListContract_Throws() { RelationMetadataBuilder builder = new RelationMetadataBuilder() { new InvalidContractResolver() }; SchemaStore customStore = new SchemaStore(new DotNotation()) { builder }; ISchema schema = customStore.GetSchema(typeof(CustomModel)); Should.Throw <MetadataBuilderException>(() => schema.GetMetadata <IRelationMetadata>("List1")); }
public StoresFixture() { var serviceProvider = new ServiceCollection() .AddEntityFrameworkInMemoryDatabase() .BuildServiceProvider(); var builder = new DbContextOptionsBuilder <ScimDbContext>(); builder.UseInMemoryDatabase() .UseInternalServiceProvider(serviceProvider) .ConfigureWarnings(warnings => warnings.Ignore(InMemoryEventId.TransactionIgnoredWarning)); var ctx = new ScimDbContext(builder.Options); ctx.EnsureSeedData(); SchemaStore = new SchemaStore(ctx, new Transformers()); }
/// <summary> /// Schema validator /// </summary> /// <param name="documentAsString">document to validate</param> public void Validate(string documentAsString) { this.logger.Trace("Schema validate xml document."); try { if (documentAsString == null) { throw new SchemaValidationInterceptionEmptyBodyException(); } XmlDataDocument xmlDoc = new XmlDataDocument(); xmlDoc.LoadXml(documentAsString); // ny udfording, find documentType via XmlReader eller ren string ? DocumentTypeConfig documentType = searcher.FindUniqueDocumentType(xmlDoc); if (string.IsNullOrEmpty(documentType.SchemaPath)) { // Empty schema path equal no schema exist. } else { SchemaStore schemaStore = new SchemaStore(); XmlSchemaSet XmlSchemaSet = schemaStore.GetCompiledXmlSchemaSet(documentType); SchemaValidator schemaValidator = new SchemaValidator(); ValidationEventHandler validationEventHandler = new ValidationEventHandler(ValidationCallBack); schemaValidator.SchemaValidateXmlDocument(documentAsString, XmlSchemaSet, validationEventHandler); } } catch (SchemaValidateDocumentFailedException ex) { this.logger.Debug("Schema validate xml document.", ex); throw ex; } catch (SchemaValidationFailedException ex) { this.logger.Debug("Schema validate xml document.", ex); throw ex; } catch (Exception ex) { this.logger.Error("Schema validate xml document.", ex); throw new SchemaValidateDocumentFailedException(ex); } this.logger.Trace("Schema validate xml document - Finish."); }
private void WriteSchemas(StreamWriter writer, SchemaStore schemaStore) { writer.WriteLine("schemas: "); foreach (Schema schema in schemaStore.Schemas.Values) { foreach (KeyValuePair <TDataExchangeFormat, string> pair in schema.Content) { writer.WriteLine(string.Concat(GetIndentString(1), "- ", GetSchemaKey(schema.Object, pair.Key), ": |")); List <string> lines = SerialisationUtils.SplitLines(pair.Value); foreach (string line in lines) { writer.WriteLine(string.Concat(GetIndentString(3), line)); } } } }
public void Test_Metadata_Custom_Contract() { var store = new SchemaStore(new DotNotation()); store.Use(new CustomContractResolver()); var schema1 = DatabaseHelper.Default.Store.GetSchema(typeof(CustomModel)); var schema2 = store.GetSchema(typeof(CustomModel)); var notFound = schema1.Lookup <IRelationMetadata>("Values.Item"); var found = schema2.Lookup <IRelationMetadata>("Values.Item"); notFound.ShouldBeNull(); found.ShouldNotBeNull(); found.Type.ShouldBe(typeof(int)); found.Annotations.OfType <CustomAttribute>().FirstOrDefault().ShouldNotBeNull(); }
public void Test_Notation_StringComparison() { var sensitive = new SchemaStore(new DotNotation(StringComparer.Ordinal)); var insensitive = new SchemaStore(new DotNotation()); var sensitive1 = sensitive.GetSchema(typeof(TupleModel)).Lookup <IRelationMetadata>("List.Item.Name"); var sensitive2 = sensitive.GetSchema(typeof(TupleModel)).Lookup <IRelationMetadata>("list.item.name"); var insensitive1 = insensitive.GetSchema(typeof(TupleModel)).Lookup <IRelationMetadata>("List.Item.Name"); var insensitive2 = insensitive.GetSchema(typeof(TupleModel)).Lookup <IRelationMetadata>("list.item.name"); sensitive1.ShouldNotBeNull(); sensitive2.ShouldBeNull(); insensitive1.ShouldNotBeNull(); insensitive2.ShouldNotBeNull(); }
internal TransactionRecordState(NeoStores neoStores, IntegrityValidator integrityValidator, RecordChangeSet recordChangeSet, long lastCommittedTxWhenTransactionStarted, ResourceLocker locks, RelationshipCreator relationshipCreator, RelationshipDeleter relationshipDeleter, PropertyCreator propertyCreator, PropertyDeleter propertyDeleter) { this._neoStores = neoStores; this._nodeStore = neoStores.NodeStore; this._relationshipStore = neoStores.RelationshipStore; this._propertyStore = neoStores.PropertyStore; this._relationshipGroupStore = neoStores.RelationshipGroupStore; this._metaDataStore = neoStores.MetaDataStore; this._schemaStore = neoStores.SchemaStore; this._integrityValidator = integrityValidator; this._recordChangeSet = recordChangeSet; this._lastCommittedTxWhenTransactionStarted = lastCommittedTxWhenTransactionStarted; this._locks = locks; this._relationshipCreator = relationshipCreator; this._relationshipDeleter = relationshipDeleter; this._propertyCreator = propertyCreator; this._propertyDeleter = propertyDeleter; }
public void Validate(XmlDocument document) { this.logger.Trace("Schema validate xml document."); try { if (document == null) { throw new SchemaValidationInterceptionEmptyBodyException(); } DocumentTypeConfig documentType = searcher.FindUniqueDocumentType(document); if (string.IsNullOrEmpty(documentType.SchemaPath)) { // Empty schema path equal no schema exist. } else { SchemaStore schemaStore = new SchemaStore(); XmlSchemaSet XmlSchemaSet = schemaStore.GetCompiledXmlSchemaSet(documentType); SchemaValidator schemaValidator = new SchemaValidator(); ValidationEventHandler validationEventHandler = new ValidationEventHandler(ValidationCallBack); schemaValidator.SchemaValidateXmlDocument(document, XmlSchemaSet, validationEventHandler); } } catch (SchemaValidateDocumentFailedException) { throw; } catch (SchemaValidationFailedException) { throw; } catch (Exception ex) { this.logger.Debug("Schema validate xml document.", ex); throw new SchemaValidateDocumentFailedException(ex); } this.logger.Trace("Schema validate xml document - Finish."); }
public void Test_Metadata_WithCustomListContract() { RelationMetadataBuilder builder = new RelationMetadataBuilder() { new CustomListContractResolver() }; SchemaStore customStore = new SchemaStore(new DotNotation()) { builder }; ISchema schema1 = DatabaseHelper.Default.Schemas.GetSchema(typeof(CustomModel)); ISchema schema2 = customStore.GetSchema(typeof(CustomModel)); IRelationMetadata notFound = schema1.GetMetadata <IRelationMetadata>("Values.Item"); IRelationMetadata found = schema2.GetMetadata <IRelationMetadata>("Values.Item"); notFound.ShouldBeNull(); found.ShouldNotBeNull(); found.Type.ShouldBe(typeof(int)); found.Annotations.OfType <CustomAttribute>().FirstOrDefault().ShouldNotBeNull(); }
public void Test_MetadataNotation_StringComparison() { SchemaStore sensitive = new SchemaStore(new DotNotation(StringComparer.Ordinal)) { new RelationMetadataBuilder() }; SchemaStore insensitive = new SchemaStore(new DotNotation()) { new RelationMetadataBuilder() }; IRelationMetadata sensitive1 = sensitive.GetSchema(typeof(TupleModel)).GetMetadata <IRelationMetadata>("List.Item.Name"); IRelationMetadata sensitive2 = sensitive.GetSchema(typeof(TupleModel)).GetMetadata <IRelationMetadata>("list.item.name"); IRelationMetadata insensitive1 = insensitive.GetSchema(typeof(TupleModel)).GetMetadata <IRelationMetadata>("List.Item.Name"); IRelationMetadata insensitive2 = insensitive.GetSchema(typeof(TupleModel)).GetMetadata <IRelationMetadata>("list.item.name"); sensitive1.ShouldNotBeNull(); sensitive2.ShouldBeNull(); insensitive1.ShouldNotBeNull(); insensitive2.ShouldNotBeNull(); }
private void Validate(string xmlDocumentPath, SchemaValidator validator, string schemaPath) { // Need the schema cache from the cacheConfiguration ConfigurationHandler.ConfigFilePath = "Resources/RaspConfiguration.Live.xml"; ConfigurationHandler.Reset(); XmlDocument document = new XmlDocument(); document.Load(xmlDocumentPath); DocumentTypeConfig documentType = _searcher.FindUniqueDocumentType(document); if (string.IsNullOrEmpty(documentType.SchemaPath)) { // Empty schema path equal no schema exist. } else { SchemaStore schemaStore = new SchemaStore(); XmlSchemaSet xmlSchemaSet = schemaStore.GetCompiledXmlSchemaSet(documentType); validator.SchemaValidateXmlDocument(document, xmlSchemaSet); } }
public SchemaStoreTests(ElasticsearchFixture fixture) { _fixture = fixture; _repo = new SchemaStore(fixture.Client, fixture.Configuration); _dummySchema = JObject.Parse("{foo : 'foo',bar : {baz : 'baz'}}"); }
public SchemaStoreSearchTests(SchemaStoreFixture fixture) { _repo = fixture.Store; }
public SchemaStoreFixture() : base() { Store = new SchemaStore(Client, Configuration); InitializeRepository().Wait(); }
public void Serialise(StreamWriter writer, ResourceNode tree, DocumentationHeaderSettings headerSettings, SchemaStore schemaStore, ExampleStore exampleStore) { WriteHeader(writer, headerSettings, schemaStore); WriteResources(writer, tree, headerSettings, schemaStore, exampleStore, -1); }
private void WriteSchemas(StreamWriter writer, SchemaStore schemaStore) { writer.WriteLine("schemas: "); foreach (Schema schema in schemaStore.Schemas.Values) { foreach (KeyValuePair<TDataExchangeFormat, string> pair in schema.Content) { writer.WriteLine(string.Concat(GetIndentString(1), "- ", GetSchemaKey(schema.Object, pair.Key), ": |")); List<string> lines = SerialisationUtils.SplitLines(pair.Value); foreach (string line in lines) { writer.WriteLine(string.Concat(GetIndentString(3), line)); } } } }
private void WriteResources(StreamWriter writer, ResourceNode node, DocumentationHeaderSettings headerSettings, SchemaStore schemaStore, ExampleStore exampleStore, int indent) { if (node.Parent != null) { string key = node.Key; if (node.Method == null) { key = string.Concat("/", key); } writer.WriteLine(string.Concat(GetIndentString(indent), key, ":")); if (node.Class != null && node.HasMethods()) { // top level resource RouteDocumentationAttribute attribute = node.Class.GetCustomAttributes<RouteDocumentationAttribute>().Where(a => a.Route != null && a.Route.EndsWith(node.GetRoute())).FirstOrDefault(); if (attribute != null) { if (attribute.DisplayName != null) { writer.WriteLine(string.Concat(GetIndentString(indent + 1), "displayName: ", attribute.DisplayName)); } if (attribute.Summary != null) { writer.WriteLine(string.Concat(GetIndentString(indent + 1), "description: ", attribute.Summary)); } } else { SerialisationLog.Warning(string.Concat("No route documentation for route '", node.GetRoute(), "' in ", node.Class.Name)); } } if (node.Method != null) { WriteMethod(writer, node, headerSettings, schemaStore, exampleStore, indent); } else if (node.Class != null) { NamedParameterDocumentationAttribute attribute = node.Class.GetCustomAttributes<NamedParameterDocumentationAttribute>() .Where(a => string.Concat("{", a.Name, "}").Equals(node.Key)).FirstOrDefault(); if (attribute != null) { writer.WriteLine(string.Concat(GetIndentString(indent + 1), "uriParameters:")); writer.WriteLine(string.Concat(GetIndentString(indent + 2), attribute.Name, ":")); if (attribute.DisplayName != null) { writer.WriteLine(string.Concat(GetIndentString(indent + 3), "displayName: ", attribute.DisplayName)); } if (attribute.Type != TNamedParameterType.NotSet) { writer.WriteLine(string.Concat(GetIndentString(indent + 3), "type: ", attribute.Type.ToString().ToLower())); } if (attribute.Description != null) { writer.WriteLine(string.Concat(GetIndentString(indent + 3), "description: ", attribute.Description)); } } } } foreach (ResourceNode child in node.Children.Values) { WriteResources(writer, child, headerSettings, schemaStore, exampleStore, indent + 1); } }
private void WriteMethod(StreamWriter writer, ResourceNode node, DocumentationHeaderSettings headerSettings, SchemaStore schemaStore, ExampleStore exampleStore, int indent) { MethodDocumentationAttribute attribute = node.Method.GetCustomAttributes<MethodDocumentationAttribute>().FirstOrDefault(); if (node.AllowsAnonymous()) { string securitySchemes = "null"; if (attribute != null && attribute.AllowMultipleSecuritySchemes) { securitySchemes = string.Concat(securitySchemes, ", oauth_2_0"); } writer.WriteLine(string.Concat(GetIndentString(indent + 1), "securedBy: [", securitySchemes, "]")); } if (attribute != null) { if (attribute.Summary != null) { writer.WriteLine(string.Concat(GetIndentString(indent + 1), "description: |")); writer.WriteLine(string.Concat(GetIndentString(indent + 2), attribute.Summary)); Example example = exampleStore.GetExample(node.Class, node.Method, ""); if (example != null) { writer.WriteLine(GetIndentString(indent + 2)); writer.WriteLine(string.Concat(GetIndentString(indent + 2), "For more information, go to ", headerSettings.RepositoryFilesURI, "/", example.DocFilename, "#", example.DocHeading)); } else if (attribute.RequestTypes != null) { SerialisationLog.Warning(string.Concat("No example to retrieve link to more information for ", node.Class.Name, ".", node.Method.Name)); } } else { SerialisationLog.Warning(string.Concat("No summary for ", node.Class.Name, ".", node.Method.Name)); } if (attribute.ResponseTypes != null && attribute.ResponseTypes.Any(r => r.GetProperties().Any(p => p.PropertyType == typeof(PageInfo)))) { writer.WriteLine(string.Concat(GetIndentString(indent + 1), "queryParameters: ")); foreach (KeyValuePair<string, Dictionary<string, string>> field in headerSettings.PagingFields) { writer.WriteLine(string.Concat(GetIndentString(indent + 2), field.Key, ":")); writer.WriteLine(string.Concat(GetIndentString(indent + 3), "displayName: ", field.Value["displayName"])); writer.WriteLine(string.Concat(GetIndentString(indent + 3), "description: ", field.Value["description"])); writer.WriteLine(string.Concat(GetIndentString(indent + 3), "type: ", field.Value["type"])); writer.WriteLine(string.Concat(GetIndentString(indent + 3), "required: ", field.Value["required"])); } } if (attribute.RequestTypes != null) { writer.WriteLine(string.Concat(GetIndentString(indent + 1), "body: ")); foreach (Type requestType in attribute.RequestTypes) { ContentTypeAttribute contentTypeAttribute = requestType.GetCustomAttributes<ContentTypeAttribute>().FirstOrDefault(); if (contentTypeAttribute == null) { SerialisationLog.Warning(string.Concat("No ContentTypeAttribute for ", requestType.FullName)); } if (attribute.RequestTypeNames != null) { foreach (string contentType in attribute.RequestTypeNames) { TDataExchangeFormat dataExchangeFormat = SerialisationUtils.GetDataExchangeFormatFromContentType(contentType); if (dataExchangeFormat != TDataExchangeFormat.None) { WriteBody(writer, exampleStore, node, dataExchangeFormat, contentType, TMessageType.Request, requestType, indent + 2); } else { SerialisationLog.Warning(string.Concat("No supported data exchange format for ", contentType)); } } } else { foreach (TDataExchangeFormat dataExchangeFormat in Enum.GetValues(typeof(TDataExchangeFormat))) { if (SerialisationUtils.IsStandardDataExchangeFormat(dataExchangeFormat)) { string contentType = GetContentType(contentTypeAttribute, dataExchangeFormat); WriteBody(writer, exampleStore, node, dataExchangeFormat, contentType, TMessageType.Request, requestType, indent + 2); } } } } } writer.WriteLine(string.Concat(GetIndentString(indent + 1), "responses:")); HttpStatusCode[] statusCodes = attribute.StatusCodes; if (node.Class.GetCustomAttributes<AuthorizeAttribute>().FirstOrDefault() != null) { statusCodes = statusCodes.Concat(new[] { HttpStatusCode.Unauthorized, HttpStatusCode.Forbidden }).ToArray(); } foreach (HttpStatusCode statusCode in statusCodes) { writer.WriteLine(string.Concat(GetIndentString(indent + 2), (int)statusCode, ":")); WriteDefaultDescription(writer, headerSettings, statusCode, indent + 3); if (SerialisationUtils.IsSuccessStatusCode(statusCode) && attribute.ResponseTypes != null) { writer.WriteLine(string.Concat(GetIndentString(indent + 3), "body:")); foreach (Type responseType in attribute.ResponseTypes) { ContentTypeAttribute contentTypeAttribute = responseType.GetCustomAttributes<ContentTypeAttribute>().FirstOrDefault(); if (contentTypeAttribute == null) { SerialisationLog.Warning(string.Concat("No ContentTypeAttribute for ", responseType.FullName)); } foreach (TDataExchangeFormat dataExchangeFormat in Enum.GetValues(typeof(TDataExchangeFormat))) { if (SerialisationUtils.IsStandardDataExchangeFormat(dataExchangeFormat)) { string contentType = GetContentType(contentTypeAttribute, dataExchangeFormat); WriteBody(writer, exampleStore, node, dataExchangeFormat, contentType, TMessageType.Response, responseType, indent + 4); } } } } } } else { SerialisationLog.Warning(string.Concat("No method-level documentation for ", node.Class.Name, ".", node.Method.Name)); } }
public void Serialise(StreamWriter writer, ResourceNode tree, DocumentationHeaderSettings headerSettings, SchemaStore schemaStore, ExampleStore exampleStore) { throw new NotSupportedException(); }
private void WriteHeader(StreamWriter writer, DocumentationHeaderSettings headerSettings, SchemaStore schemaStore) { writer.WriteLine("#%RAML 0.8"); writer.WriteLine("---"); writer.WriteLine(string.Concat("title: ", headerSettings.Title)); writer.WriteLine(string.Concat("version: ", headerSettings.Version)); writer.WriteLine(string.Concat("baseUri: ", headerSettings.BaseURI)); writer.WriteLine(string.Concat("mediaType: ", headerSettings.MediaType)); writer.WriteLine("securedBy: [oauth_2_0]"); WriteSecuritySchemes(writer, headerSettings); WriteIntroductionDocumentation(writer, headerSettings); WriteSchemas(writer, schemaStore); writer.WriteLine(); }