public void TypesControllerGetTest() { var topic = CreateContext(); var Logic = CreateLogic(); var Controller = new TypesController(Logic); var Type = new TypeEntity { Id = Guid.NewGuid(), Name = "First Type", Topic = topic, TopicId = topic.Id }; Logic.Create(Type); var Result = Controller.Get(Type.Id); var CreatedResult = Result as OkObjectResult; var Model = CreatedResult.Value as TypeDTO; Assert.AreEqual(Type.Name, Model.Name); }
public IActionResult Update(TypeEntity entity) { if (!this.ValidAccess()) { return(this.RedirectToAction("AccessDenied", "Users")); } try { if (this.ModelState.IsValid) { this.service.Update(entity); return(this.RedirectToAction("Index")); } } catch (Exception e) { this.ModelState.AddModelError(string.Empty, e.Message); } return(this.View(entity)); }
public void RegisterTypeEntity(TypeEntity typeEntity) { if (typeEntity.Definition.Type == ObjectType.Object) { RegisterTypeClassEntity(typeEntity); } else if (typeEntity.Definition.Type == ObjectType.String && typeEntity.Definition.EnumValues is not null) { RegisterEnumEntity(typeEntity); } else if (typeEntity.Definition.Type == ObjectType.String && !string.IsNullOrEmpty(typeEntity.Definition.StringFormat)) { RegisterStringFormatClassEntity(typeEntity); } else if (typeEntity.Definition.Type == ObjectType.Array && typeEntity.Definition.ArrayItems is not null) { RegisterArrayClassEntity(typeEntity); } else if (typeEntity.Definition.TypeChoices is not null) { RegisterMultitypeClassEntity(typeEntity); } }
public IEnumerable <TypeEntity> ConvertTypes(Dictionary <string, string> parserModel) { XmlDocument xml = new XmlDocument(); xml.Load(parserModel["FilePath"]); XmlElement root = xml.DocumentElement; List <TypeEntity> types = new List <TypeEntity>(); /* Types Import */ XmlNodeList nodes = root.SelectNodes("Type"); foreach (XmlNode node in nodes) { TypeEntity importedType = new TypeEntity(); importedType.Name = node["Name"].InnerText; importedType.Id = Guid.Parse(node["InternalId"].InnerText); importedType.TopicId = Guid.Parse(node["TopicId"].InnerText);; types.Add(importedType); } return(types); }
private void RegisterTypeClassEntity(TypeEntity typeEntity) { var classEntity = entitiesContext.Classes.RegisterClass(ClassEntityType.TypeClass, typeEntity.FormattedName, typeEntity.NamespaceEntity); classEntity.TypeDefinition = typeEntity.Definition; classEntity.Description = typeEntity.Definition.Description; classEntity.BaseClassName = registrationOptions.ObjectTypeClassBaseClassName; var typeFunctions = new List <FunctionDefinition>(); var typeProperties = new List <KeyValuePair <string, PropertyDefinition> >(); if (typeEntity.Definition.ObjectFunctions is not null) { typeFunctions.AddRange(typeEntity.Definition.ObjectFunctions); } if (typeEntity.Definition.ObjectProperties is not null) { typeProperties.AddRange(typeEntity.Definition.ObjectProperties); } foreach (var typeExtension in typeEntity.Extensions) { if (typeExtension.ObjectFunctions is not null) { typeFunctions.AddRange(typeExtension.ObjectFunctions); } if (typeExtension.ObjectProperties is not null) { typeProperties.AddRange(typeExtension.ObjectProperties); } } AddFunctionsToClassEntity(typeFunctions, classEntity); AddPropertiesToClassEntity(typeProperties, classEntity); }
/// <summary> /// Create a type entry without setting its parent info. /// </summary> private TypeEntity createTypeCore(string name, bool isSealed, bool defaultCtor, bool prepare, Action <TypeEntity> extraInit = null) { if (_DefinedTypes.ContainsKey(name)) { Error(CompilerMessages.TypeDefined, name); } var te = new TypeEntity(this) { Name = name, IsSealed = isSealed, }; _DefinedTypes.Add(name, te); if (extraInit != null) { extraInit(te); } if (prepare) { te.PrepareSelf(); } else { UnpreparedTypes.Add(te); } if (defaultCtor) { te.CreateConstructor(null, prepare); } return(te); }
protected TypeContentsBase(TypeEntity type) { ContainerType = type; }
public Entity() { Type = TypeEntity.UNKNOWN; }
public Entity(TypeEntity type, long id) { Type = type; ID = id; }
public static TypeEntity ToTypeEntity(this Type type) { return(TypeEntity.ToTypeEntityFunc(type)); }
public static Type ToType(this TypeEntity type) { return(TypeEntity.ToTypeFunc(type)); }
public static Dictionary <uint, TypeEntity> Load(NpgsqlConnection connection) { var dataTable = connection.GetSchema("DataTypes"); var mapper = EntityMapper.GetTableMapper <TypeEntity>(dataTable); var dataReader = dataTable.CreateDataReader(); var types = new Dictionary <uint, TypeEntity>(); var systemCollectionsAssembly = typeof(System.Collections.BitArray).Assembly; var systemNetAssembly = typeof(IPAddress).Assembly; var systemNetNetworkInformationAssembly = typeof(PhysicalAddress).Assembly; var npgsqlAssembly = typeof(NpgsqlBox).Assembly; var newtonsoftJsonLinqAssembly = typeof(JObject).Assembly; while (dataReader.Read()) { var type = new TypeEntity(); foreach (var columnName in mapper.ColumnMaps.Keys) { var value = dataReader[columnName]; if (value is DBNull) { continue; } mapper.ColumnMaps[columnName].Set(type, value); } if ((type.TypeName == "OID" || type.TypeName == "xid" || type.TypeName == "cid" || type.TypeName == "tid") && string.IsNullOrEmpty(type.DataType)) { type.DataType = "System.UInt32"; type.IsUnsigned = true; } if (type.DataType == "String") { type.DataType = "System.String"; } else if (type.DataType == "System.Text.Json.JsonDocument") { type.DataType = "Newtonsoft.Json.Linq.JObject"; } else if (type.DataType == "System.Text.Json.JsonDocument[]") { type.DataType = "Newtonsoft.Json.Linq.JArray"; } if (!string.IsNullOrEmpty(type.DataType)) { type.Type = Type.GetType(type.DataType); if (type.Type == null) { if (type.DataType.Contains("NpgsqlRange")) { var match = Regex.Match(type.DataType, @"\[[^\.]+\.([A-Za-z0-9]+)"); type.DataType = $"NpgsqlRange<{match.Groups[1].Value}>"; type.Type = npgsqlAssembly.GetType(type.DataType); type.Using = "NpgsqlTypes"; } else if (type.DataType.StartsWith("Npgsql")) { type.Type = npgsqlAssembly.GetType(type.DataType); type.Using = "NpgsqlTypes"; } else if (type.DataType.StartsWith("System.Collections")) { type.Type = systemCollectionsAssembly.GetType(type.DataType); type.Using = "System.Collections"; } else if (type.DataType.StartsWith("System.Net.NetworkInformation")) { type.Type = systemNetNetworkInformationAssembly.GetType(type.DataType); type.Using = "System.Net.NetworkInformation"; } else if (type.DataType.StartsWith("System.Net")) { type.Type = systemNetAssembly.GetType(type.DataType); type.Using = "System.Net"; } else if (type.DataType.StartsWith("Newtonsoft.Json.Linq")) { type.Type = newtonsoftJsonLinqAssembly.GetType(type.DataType); type.Using = "Newtonsoft.Json.Linq"; } } } types[type.OID] = type; } return(types); }
public void Update(TypeEntity entity) { _repository.Update(entity); }
public void Delete(TypeEntity entity) { _repository.Delete(entity); }
private static IEnumerable <FunctionDefinition> GetEventFunctionDefinitions(EventDefinition eventDefinition, TypeEntity baseEventTypeEntity, string functionName, bool useBaseFunctionDescription) { var eventFunctionDefinitions = new List <FunctionDefinition>(); var baseEventFunction = baseEventTypeEntity.Definition?.ObjectFunctions?.SingleOrDefault(functionDefinition => functionDefinition.Name == functionName); if (baseEventFunction is null) { throw new InvalidOperationException($"Failed to locate '{functionName}' function in type entity '{baseEventTypeEntity.NamespaceQualifiedId}'."); } var baseEventFunctionParameter = baseEventFunction.FunctionParameters?.SingleOrDefault(); if (baseEventFunctionParameter is null) { throw new InvalidOperationException($"'{functionName}' function should have one parameter."); } var functionParameters = new List <ParameterDefinition>(); var functionParameter = SerializationHelper.DeserializeTo <ParameterDefinition>(eventDefinition); functionParameter.Name = baseEventFunctionParameter.Name; if (useBaseFunctionDescription) { functionParameter.Description = baseEventFunctionParameter.Description; } functionParameters.Add(functionParameter); var clonedEventFunction = SerializationHelper.DeserializeTo <FunctionDefinition>(baseEventFunction); clonedEventFunction.FunctionParameters = functionParameters.ToArray(); eventFunctionDefinitions.Add(clonedEventFunction); if (eventDefinition.ExtraParameters is not null) { functionParameters.AddRange(eventDefinition.ExtraParameters); var extraParameterEventFunction = SerializationHelper.DeserializeTo <FunctionDefinition>(baseEventFunction); extraParameterEventFunction.FunctionParameters = functionParameters.ToArray(); eventFunctionDefinitions.Add(extraParameterEventFunction); } return(eventFunctionDefinitions); }