public Type GetMixinType(string modelName) { FlatType entityType = index.GetType(modelName); // First try to directly lookup type as a library type Type mixinType = GetType($"I{modelName}"); if (mixinType != null) { return(mixinType); } List <FlatType> requiredMixins = entityType.RequiredMixin().ToList(); if (requiredMixins.Count != 1) { throw new InvalidOperationException($"Cannot find single mixin for: {entityType}"); } FlatType requiredMixin = requiredMixins.First(); mixinType = GetType($"I{requiredMixin.Name}"); if (mixinType == null) { throw new InvalidOperationException($"Mixin type: I{requiredMixin.Name} does not exist."); } return(mixinType); }
public Type GetClass(string modelName) { if (cache.TryGetValue(modelName, out Type classType)) { return(classType); } FlatType entityType = index.GetType(modelName); Type mixinType = GetMixinType(modelName); TypeBuilder classBuilder = moduleBuilder.DefineType( modelName, TypeAttributes.Class | TypeAttributes.Public, typeof(object), new[] { mixinType } ); List <(FlatProperty, FieldInfo)> backingFields = new List <(FlatProperty, FieldInfo)>(); // Override ModelName to this model's name. /*{ * (MethodInfo methodInfo, MethodBuilder methodBuilder) = OverrideMethod(classBuilder, mixinType, "get_ModelName"); * ILGenerator? ilGenerator = methodBuilder.GetILGenerator(); * if (ilGenerator == null) { * throw new InvalidOperationException($"{mixinType.Name} could not create ILGenerator."); * } * ilGenerator.EmitValue(modelName); * ilGenerator.Emit(OpCodes.Ret); * classBuilder.DefineMethodOverride(methodBuilder, methodInfo); * }*/ (string, string)[] baseProps =
public ActionResult Create([Bind(Include = "Id,Name,Value")] FlatType flatType) { if (ModelState.IsValid) { m_repo.SaveFlatType(flatType); return(RedirectToAction("Index")); } return(View(flatType)); }
/// <summary> /// Получение из XML /// </summary> /// <param name="arg"></param> /// <returns></returns> public static DbFlatType Get(FlatType arg) { return(new DbFlatType() { FltypeId = arg.FltypeId, Name = arg.Name, ShortName = arg.ShortName }); }
public void ShouldMapFlatProperties() { var flat = new FlatType { FooBarName = "hi" }; var unflat = new UnflatType(); unflat.InjectFrom<UnflatLoopInjection>(flat); Assert.AreEqual(flat.FooBarName, unflat.Foo.Bar.Name); }
public Flat(string _unitId, int _price, int _surface, int _bathroomCount, int _bedroomCount, bool _maidsroom, Availability _availability, FlatType _flatType) { unitId = _unitId; price = _price; surface = _surface; bathroomCount = _bathroomCount; bedroomCount = _bedroomCount; maidsroom = _maidsroom; availability = _availability; fType = _flatType; }
public Flat(Flat flat) { unitId = flat.unitId; price = flat.price; surface = flat.surface; bathroomCount = flat.bathroomCount; bedroomCount = flat.bedroomCount; maidsroom = flat.maidsroom; availability = flat.availability; fType = flat.fType; }
private IMapEntity CreateInstance(Entity entity) { Type entityType = lookup.GetClass(entity.modelName); var mapEntity = (IMapEntity)Activator.CreateInstance(entityType); if (mapEntity == null) { throw new InvalidOperationException($"Unable to create instance of: {entity.modelName}"); } var setPropertyValue = new List <(string, object)>(); foreach (var property in entity.property) { // Not setting any values if (property.set.Count == 0) { continue; } FlatType modelType = index.GetType(entity.modelName); FlatProperty modelProperty = modelType.GetProperty(property.name); object value; if (modelProperty.Type.StartsWith("Assoc")) { value = FlatProperty.ParseAssocType(modelProperty.Type, property.set.Select(set => (set.index, set.value))); } else { value = FlatProperty.ParseType(modelProperty.Type, property.set[0].value); } setPropertyValue.Add((property.name, value)); } setPropertyValue.Add(("EntityId", entity.id)); setPropertyValue.Add(("EntityName", entity.name)); foreach ((string name, object value) in setPropertyValue) { MethodInfo setter = entityType.GetMethod($"set_{name}"); if (setter == null) { throw new InvalidOperationException($"No function set_{name} on {entity.modelName}"); } setter.Invoke(mapEntity, new[] { value }); } return(mapEntity); }
public void ShouldMapFlatProperties() { var flat = new FlatType { FooBarName = "hi" }; var unflat = new UnflatType(); unflat.InjectFrom <UnflatLoopInjection>(flat); Assert.AreEqual(flat.FooBarName, unflat.Foo.Bar.Name); }
public ActionResult Edit([Bind(Include = "Id,Name,Value")] FlatType flatType) { if (flatType == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (ModelState.IsValid) { m_repo.SaveFlatType(flatType); return(RedirectToAction("Index")); } return(View(flatType)); }
// GET: Admin/FlatTypes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FlatType flatType = m_repo.GetFlatType(id.Value); if (flatType == null) { return(HttpNotFound()); } return(View(flatType)); }
private string ConvertFlatType(FlatType flatType) { switch (flatType) { case FlatType.Brick: return("cihlova"); case FlatType.Panel: return("panelova"); default: throw new NotImplementedException($"Flat type {flatType.ToString()} is not supported"); } }
private void PopulateFlatType() { DataTable dt = new DataTable(); dt = FlatTypeBL.GetFlatTypeDetails(m_iCCId); FlatType.DataSource = CommFun.AddAllToDataTable(dt); FlatType.PopulateColumns(); FlatType.DisplayMember = "TypeName"; FlatType.ValueMember = "FlatTypeId"; FlatType.Columns["FlatTypeId"].Visible = false; FlatType.ShowFooter = false; FlatType.ShowHeader = false; cboFlatType.EditValue = -1; }
public ActionResult Retire(int?id) { if (!id.HasValue) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FlatType flatType = m_repo.GetFlatType(id.Value); if (flatType == null) { return(HttpNotFound()); } flatType.Retired = !flatType.Retired; m_repo.SaveFlatType(flatType); return(RedirectToAction("Index")); }
public int AddFlatType(FlatType model) { using (REMSDBEntities context = new REMSDBEntities()) { try { context.FlatTypes.Add(model); int i = context.SaveChanges(); return(i); } catch (Exception ex) { Helper hp = new Helper(); hp.LogException(ex); return(0); } } }
public int EditFlatType(FlatType model) { using (REMSDBEntities context = new REMSDBEntities()) { try { context.FlatTypes.Add(model); context.Entry(model).State = EntityState.Modified; int i = context.SaveChanges(); return(i); } catch (Exception ex) { Helper hp = new Helper(); hp.LogException(ex); return(0); } } }
// Start is called before the first frame update void Start() { //mendapatkan level generator komponen dari parent levelGenerator = transform.parent.GetComponent <LevelGenerator>(); //setup mesh filter var filter = GetComponent <MeshFilter>(); mesh = filter.mesh; mesh.Clear(); //reset x dan y position dari vertices xPos = 0; yBefore = 0; //merandomize tipe mesh int RandomizeType = Random.Range(1, 3); //jika bukan di awal generasi dan hasil dari random itu = 2 if (levelGenerator.MeshObjects.Count > 2 && RandomizeType == 2 && levelGenerator.MeshObjects[levelGenerator.MeshObjects.Count - 2].meshType != MeshType.Flat) { meshType = MeshType.Flat; transform.position = new Vector3(transform.position.x, transform.position.y - 1f, transform.position.z); int RandomType = Random.Range(1, 3); flatType = RandomType == 1 ? FlatType.WaterFall : FlatType.PhotoSpot; } else { meshType = MeshType.StreamDown; } //Buat Mesh for (int i = 0; i < 5; i++) { GeneratePoint(); } GenerateMesh(); GenerateObstacle(); }
public string GenerateClass(string @namespace, FlatType type) { List <string> mixinTypes = type.RequiredMixin() .Select(mixin => mixin.Name) .ToList(); var builder = new StringBuilder(); builder.AppendLine($"namespace Maple2.File.Flat.{@namespace} {{"); List <string> mixinInterfaces = mixinTypes.Select(mixin => $"I{mixin}").ToList(); if (mixinInterfaces.Count > 0) { builder.AppendLine($"\tpublic class {type.Name} : {string.Join(",", mixinInterfaces)} {{"); } else { builder.AppendLine($"\tpublic class {type.Name} : IMapEntity {{"); } builder.AppendLine($"\t\tstring ModelName => \"{type.Name}\";"); foreach (FlatProperty property in type.GetProperties()) { string typeStr = NormalizeType(property.Value.GetType().ToString()); string typeValue = property.ValueCodeString(); builder.AppendLine($"\t\tpublic {typeStr} {property.Name} {{ get; set; }} = {typeValue};"); } foreach (FlatProperty property in type.GetInheritedProperties()) { string typeStr = NormalizeType(property.Value.GetType().ToString()); string typeValue = property.ValueCodeString(); builder.AppendLine($"\t\t{typeStr} {property.Name} {{ get; set; }} = {typeValue};"); } builder.AppendLine("\t}"); // class builder.AppendLine("}"); // namespace return(builder.ToString()); }
public static List <Flat> Initialize(List <double> listSquares1, FlatType type1, List <double> listSquares2, FlatType type2) { var list = new List <Flat>(); var i = 1; foreach (var elem in listSquares1) { list.Add(new Flat { Id = i, Fine = 0, InputSquare = elem, CastSquare = elem, BalconySquare = Constraints.SquareBalcony, Type = type1 }); i++; } foreach (var elem in listSquares2) { list.Add(new Flat { Id = i, Fine = 0, InputSquare = elem, CastSquare = elem, BalconySquare = Constraints.SquareBalcony, Type = type2 }); i++; } return(list); }
private static void FlatIndexExplorer() { using var reader = new M2dReader(EXPORTED_PATH); var index = new FlatTypeIndex(reader); Console.WriteLine("Index is ready!"); while (true) { string[] input = (Console.ReadLine() ?? string.Empty).Split(" ", 2); switch (input[0]) { case "quit": return; case "type": case "prop": case "properties": if (input.Length < 2) { Console.WriteLine("Invalid input."); } else { string name = input[1]; FlatType type = index.GetType(name); if (type == null) { Console.WriteLine($"Invalid type: {name}"); continue; } Console.WriteLine(type); foreach (FlatProperty prop in type.GetProperties()) { Console.WriteLine($"{prop.Type,22}{prop.Name,30}: {prop.ValueString()}"); } Console.WriteLine("----------------------Inherited------------------------"); foreach (FlatProperty prop in type.GetInheritedProperties()) { Console.WriteLine($"{prop.Type,22}{prop.Name,30}: {prop.ValueString()}"); } } break; case "sub": case "children": if (input.Length < 2) { Console.WriteLine("Invalid input."); } else { string name = input[1]; FlatType type = index.GetType(name); if (type == null) { Console.WriteLine($"Invalid type: {name}"); continue; } Console.WriteLine(type); foreach (FlatType subType in index.GetSubTypes(name)) { Console.WriteLine($"{subType.Name,30} : {string.Join(',', subType.Mixin.Select(sub => sub.Name))}"); } } break; case "ls": try { bool recursive = input.Contains("-r"); string path = input.FirstOrDefault(arg => arg != "ls" && arg != "-r"); Console.WriteLine(string.Join(", ", index.Hierarchy.List(path, recursive).Select(type => type.Name))); } catch (DirectoryNotFoundException e) { Console.WriteLine(e.Message); } break; case "lsdir": try { string path = input.FirstOrDefault(arg => arg != "lsdir"); Console.WriteLine(string.Join(", ", index.Hierarchy.ListDirectories(path))); } catch (DirectoryNotFoundException e) { Console.WriteLine(e.Message); } break; default: Console.WriteLine($"Unknown command: {string.Join(' ', input)}"); break; } } }
public string GenerateInterface(string @namespace, FlatType type) { List <string> mixinTypes = type.RequiredMixin() .Select(mixin => mixin.Name) .ToList(); var inheritedProperties = new Dictionary <string, object>(); foreach (string mixinType in mixinTypes) { foreach (FlatProperty property in index.GetType(mixinType).GetAllProperties()) { if (inheritedProperties.ContainsKey(property.Name)) { inheritedProperties[property.Name] = null; } else { inheritedProperties.Add(property.Name, property.Value); } } } var builder = new StringBuilder(); builder.AppendLine($"namespace Maple2.File.Flat.{@namespace} {{"); List <string> mixinInterfaces = mixinTypes.Select(mixin => $"I{mixin}").ToList(); if (mixinInterfaces.Count > 0) { builder.AppendLine($"\tpublic interface I{type.Name} : {string.Join(",", mixinInterfaces)} {{"); } else { builder.AppendLine($"\tpublic interface I{type.Name} : IMapEntity {{"); } builder.AppendLine($"\t\tstring ModelName => \"{type.Name}\";"); foreach (FlatProperty property in type.GetProperties()) { // Inherited properties don't need to be declared on interface if (inheritedProperties.TryGetValue(property.Name, out object propertyValue)) { if (propertyValue != null) { if (Equals(propertyValue, property.Value)) { continue; } // Since the dictionaries are always empty, just doing count comparison to shortcut if (propertyValue is IDictionary dict1 && property.Value is IDictionary dict2 && dict1.Count == dict2.Count) { continue; } } } string typeStr = NormalizeType(property.Value.GetType().ToString()); string typeValue = property.ValueCodeString(); builder.AppendLine($"\t\t{typeStr} {property.Name} => {typeValue};"); } builder.AppendLine("\t}"); // class builder.AppendLine("}"); // namespace return(builder.ToString()); }
public bool ScanProject(Document document) { bool result = true; this.document = document; this.Flats.Clear(); FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document); RoomFilter roomFilter = new RoomFilter(); filteredElementCollector.WherePasses(roomFilter); using (IEnumerator <Element> enumerator = filteredElementCollector.GetEnumerator()) { while (enumerator.MoveNext()) { Room room = (Room)enumerator.Current; Parameter parameter = room.get_Parameter(new Guid(Converter.FlatNumber )); Parameter parameter2 = room.get_Parameter(new Guid(Converter.SectionNumber )); if (parameter.HasValue) { string flatNumber = parameter.AsString(); string text = parameter2.HasValue ? parameter2.AsString() : ""; if (!this.Sections.Contains(text)) { this.Sections.Add(text); } Flat flat = this.GetFlatBySectionAndFlatNumber(text, flatNumber); if (flat == null) { Parameter parameter3 = room.get_Parameter(new Guid(Converter.FlatInd)); string flatIndex = parameter3.HasValue ? parameter3.AsString() : ""; Parameter parameter4 = room.get_Parameter(new Guid(Converter.FlatTypeIndex)); FlatType type = (FlatType)parameter4.AsInteger(); flat = new Flat(document, flatNumber, text); flat.FlatIndex = flatIndex; flat.Type = type; this.Flats.Add(flat); } flat.AddRoom(room); } } } using (Transaction transaction = new Transaction(document)) { transaction.Start("Update flats"); foreach (Flat current in this.Flats) { if (current.FlatIndex == String.Empty && current.FlatNumber == String.Empty && current.SectionNumber == String.Empty) { continue; } current.FlatCalculate(); } transaction.Commit(); } //if (filteredElementCollector.Count<Element>() == 0) //{ // this.FlatsRefreshed(this, new FlatsRefreshedEventArg // { // Document = document, // UpdatedFlats = this.Flats // }); //} return(result); }