Beispiel #1
0
        private string BuildModel(string name, Func <NpgsqlConnection, IEnumerable <PgReturns> > func)
        {
            if (Models.ContainsKey(name))
            {
                return(name);
            }
            string getType(PgReturns returnModel)
            {
                if (TryGetReturnMapping(returnModel, out var result))
                {
                    if (returnModel.Array)
                    {
                        return($"{result}[]");
                    }
                    if (result != "string" && returnModel.Nullable)
                    {
                        var key = $"{name}.{returnModel.Name.ToUpperCamelCase()}";
                        if (settings.RoutinesModelPropertyTypes.TryGetValue(key, out var value))
                        {
                            return(value);
                        }
                        return($"{result}?");
                    }
                    return(result);
                }
                throw new ArgumentException($"Could not find mapping \"{returnModel.DataType}\" for result type of routine  \"{this.Name}\"");
            }

            var model        = new StringBuilder();
            var modelContent = new StringBuilder();

            if (!settings.UseRecords)
            {
                model.AppendLine($"{I1}public class {name}");
                model.AppendLine($"{I1}{{");
                foreach (var item in func(connection))
                {
                    modelContent.AppendLine($"{I2}public {getType(item)} {item.Name.ToUpperCamelCase()} {{ get; set; }}");
                }
                model.Append(modelContent);
                model.AppendLine($"{I1}}}");
            }
            else
            {
                model.Append($"{I1}public record {name}(");
                modelContent.Append(string.Join(", ", func(connection).Select(item => $"{getType(item)} {item.Name.ToUpperCamelCase()}")));
                model.Append(modelContent);
                model.AppendLine($");");
            }
            foreach (var(key, value) in ModelContent)
            {
                if (value.Equals(modelContent))
                {
                    return(key);
                }
            }
            Models.Add(name, model);
            ModelContent.Add(name, modelContent);
            return(name);
        }
Beispiel #2
0
        /// <summary>Adds model of given type and name to the symbol tables.</summary>
        /// <param name="modelType">Type of the model parameters.</param>
        /// <param name="name">Name of the model.</param>
        /// <param name="model">If this function returns true, contains the found model, otherwise null.</param>
        public void AddModel(Type modelType, object model, string name)
        {
            if (!Models.ContainsKey(modelType))
            {
                Models[modelType] = new Dictionary <string, object>();
            }

            Models[modelType].Add(name, model);
        }
Beispiel #3
0
 public static Model LoadModel(string modelPath, string name)
 {
     if (!Models.ContainsKey(name))
     {
         Console.WriteLine("Loading model: " + name);
         Models[name] = new Model(modelPath);
         Console.WriteLine("Model Loaded!");
     }
     return(Models[name]);
 }
Beispiel #4
0
 public override void CloseModelForName(string ModelName)
 {
     if (Models.ContainsKey(ModelName))
     {
         Models[ModelName].Close();
         Models.Remove(ModelName);
         base.CloseModel(ModelName);
     }
     else
     {
         LoggerHelper.Error("This Model Already Close:" + ModelName);
     }
 }
Beispiel #5
0
        public T FindInstanceForCode(uint configCode)
        {
            T baseInstance = default(T);

            if (Models.ContainsKey(configCode))
            {
                baseInstance = Models[configCode];
            }
            else
            {
                baseInstance = Models[DefaultCode];
            }
            return(baseInstance);
        }
Beispiel #6
0
        public T ConfigureModel(T baseInstance, uint configCode)
        {
            T modelInstance = baseInstance;

            if (modelInstance != null)
            {
                Models [configCode] = modelInstance;
            }
            else if (Models.ContainsKey(configCode))
            {
                modelInstance = Models [configCode];
            }
            return(modelInstance);
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public ODataRoutingOptions AddModel(string name, IEdmModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (Models.ContainsKey(name))
            {
                throw new Exception($"Contains the same name for the model: {name}");
            }

            Models[name] = model;
            return(this);
        }
Beispiel #8
0
        public override void CloseModel <C>()
        {
            string ModelName = typeof(C).Name;

            if (Models.ContainsKey(ModelName))
            {
                Models[ModelName].Close();
                Models.Remove(ModelName);
                base.CloseModel(ModelName);
            }
            else
            {
                LoggerHelper.Error("This Model Already Close:" + typeof(C).Name);
            }
        }
Beispiel #9
0
        public T InstanceFromModels(Assembly configAssembly, uint configCode)
        {
            T modelInstance = default(T);

            if (!Models.ContainsKey(configCode))
            {
                T baseInstance = EmptyInstanceForCode(configAssembly, configCode);

                modelInstance = ConfigureModel(baseInstance, configCode);
            }
            else
            {
                modelInstance = FindInstanceForCode(configCode);
            }
            return(modelInstance);
        }
Beispiel #10
0
 public override void StartModelForName(string nameSpace, string ModelName, ModelLoadBackCall <ManagerContorBase> BackCall = null, params object[] _Agr)
 {
     if (!Models.ContainsKey(ModelName))
     {
         Models[ModelName]           = Assembly.GetExecutingAssembly().CreateInstance(nameSpace + "." + ModelName, true, System.Reflection.BindingFlags.Default, null, null, null, null) as ManagerContorBase;
         Models[ModelName].ModelName = ModelName;
         base.StartModel(ModelName, Models[ModelName]);
         Models[ModelName].Load <ManagerContorBase>((model) => {
             StartCoroutine(ModelStart <ManagerContorBase>(model, BackCall, _Agr));
         }, _Agr);
     }
     else
     {
         LoggerHelper.Error("This Model Already Load:" + ModelName);
     }
 }
Beispiel #11
0
        private bool ResolveId <TValue, TForeign>(ForeignKeyFieldDefinition <TModel, TValue, TForeign> def)
            where TValue : struct, IComparable <TValue>
        {
            if (def.GetModelsByCode == null ||
                CodeResolutionQueue == null ||
                !CodeResolutionQueue.ContainsKey(def.FieldIndex))
            {
                return(true);
            }

            var queueOfField = CodeResolutionQueue[def.FieldIndex]; // 対象の列に対応するIdマッピング待ちモデル
            var codeKeys     = def.GetModelsByCode(queueOfField.Keys.ToArray());

            def.ForeignModels = codeKeys.Values.ToList();
            bool result = true;

            foreach (var queueByCode in queueOfField) // <code, List<lineNo>>
            {
                var code = queueByCode.Key;
                if (codeKeys.ContainsKey(code))   // DB有無チェック
                {
                    var foreign = codeKeys[code]; // コードに対応するキー
                    foreach (var lineNo in queueByCode.Value.Where(l => Models.ContainsKey(l)))
                    {
                        def.SetValue(Models[lineNo], def.GetForeignKey(foreign));
                    }
                }
                else
                {
                    foreach (var lineNo in queueByCode.Value)
                    {
                        Reports.Add(new WorkingReport
                        {
                            LineNo    = lineNo,
                            FieldNo   = def.FieldIndex,
                            FieldName = def.FieldName,
                            Value     = code,
                            Message   = $"存在しないため、インポートできません。",
                        });
                        result = false;
                    }
                }
            }

            return(result);
        }
Beispiel #12
0
        public override void StartModel <C>(ModelLoadBackCall <C> BackCall = null, params object[] _Agr)
        {
            string ModelName = typeof(C).Name;

            if (!Models.ContainsKey(ModelName))
            {
                Models[ModelName]           = new C();
                Models[ModelName].ModelName = ModelName;
                base.StartModel(ModelName, Models[ModelName]);
                Models[ModelName].Load <C>((model) => {
                    StartCoroutine(ModelStart <C>(model, BackCall, _Agr));
                }, _Agr);
            }
            else
            {
                LoggerHelper.Error("This Model Already Load:" + typeof(C).Name);
            }
        }
Beispiel #13
0
 /// <summary>
 /// Tests if an object is contained with the given id
 /// </summary>
 /// <param name="id">The id to test</param>
 /// <returns>true if contained, else false</returns>
 public static bool Contains(int id)
 {
     return(Models.ContainsKey(id));
 }
Beispiel #14
0
        /// <summary>
        /// Baut ein Terrain-Modell
        /// </summary>
        /// <param name="name">Name des Modells</param>
        /// <param name="heightmap">Height Map Textur</param>
        /// <param name="texture">Textur der Oberfläche</param>
        /// <param name="width">Breite</param>
        /// <param name="height">Höhe</param>
        /// <param name="depth">Tiefe</param>
        /// <param name="texRepeatX">Texturwiederholung Breite</param>
        /// <param name="texRepeatZ">Texturwiederholung Tiefe</param>
        /// <param name="isFile">false, wenn die Texturen Teil der EXE sind (Eingebettete Ressource)</param>
        public static void BuildTerrainModel(string name, string heightmap, string texture, float width, float height, float depth, float texRepeatX = 1, float texRepeatZ = 1, bool isFile = true)
        {
            if (Models.ContainsKey(name))
            {
                throw new Exception("There already is a model with that name. Please choose a different name.");
            }
            GeoModel terrainModel = new GeoModel();

            terrainModel.Name    = name;
            terrainModel.Meshes  = new Dictionary <string, GeoMesh>();
            terrainModel.IsValid = true;

            GeoMeshHitbox meshHitBox = new GeoMeshHitbox(0 + width / 2, 0 + height / 2, 0 + depth / 2, 0 - width / 2, 0 - height / 2, 0 - depth / 2);

            meshHitBox.Model = terrainModel;
            meshHitBox.Name  = name;

            terrainModel.MeshHitboxes = new List <GeoMeshHitbox>();
            terrainModel.MeshHitboxes.Add(meshHitBox);

            GeoTerrain t           = new GeoTerrain();
            GeoMesh    terrainMesh = t.BuildTerrain(new Vector3(0, 0, 0), heightmap, width, height, depth, texRepeatX, texRepeatZ, isFile);

            terrainMesh.Terrain = t;
            GeoMaterial mat = new GeoMaterial();

            mat.BlendMode     = OpenTK.Graphics.OpenGL4.BlendingFactor.OneMinusSrcAlpha;
            mat.ColorDiffuse  = new Vector4(1, 1, 1, 1);
            mat.ColorEmissive = new Vector4(0, 0, 0, 0);
            mat.Name          = name + "-Material";
            mat.SpecularArea  = 512;
            mat.SpecularPower = 0;

            GeoTexture texDiffuse = new GeoTexture(name + "-TextureDiffuse");

            texDiffuse.Filename    = texture;
            texDiffuse.Type        = GeoTexture.TexType.Diffuse;
            texDiffuse.UVMapIndex  = 0;
            texDiffuse.UVTransform = new Vector2(texRepeatX, texRepeatZ);

            bool dictFound = CustomTextures.TryGetValue(CurrentWorld, out Dictionary <string, int> texDict);

            if (dictFound && texDict.ContainsKey(texture))
            {
                texDiffuse.OpenGLID = texDict[texture];
            }
            else
            {
                texDiffuse.OpenGLID = isFile ? HelperTexture.LoadTextureForModelExternal(texture) : HelperTexture.LoadTextureForModelInternal(texture);
                if (dictFound)
                {
                    texDict.Add(texture, texDiffuse.OpenGLID);
                }
            }
            mat.TextureDiffuse = texDiffuse;


            terrainMesh.Material = mat;
            terrainModel.Meshes.Add("Terrain", terrainMesh);
            KWEngine.Models.Add(name, terrainModel);
        }
Beispiel #15
0
        /// <summary>
        /// Baut ein Terrain-Modell
        /// </summary>
        /// <param name="name">Name des Modells</param>
        /// <param name="heightmap">Height Map Textur</param>
        /// <param name="texture">Textur der Oberfläche</param>
        /// <param name="width">Breite</param>
        /// <param name="height">Höhe</param>
        /// <param name="depth">Tiefe</param>
        /// <param name="texRepeatX">Texturwiederholung Breite</param>
        /// <param name="texRepeatZ">Texturwiederholung Tiefe</param>
        /// <param name="isFile">false, wenn die Texturen Teil der EXE sind (Eingebettete Ressource)</param>
        public static void BuildTerrainModel(string name, string heightmap, string texture, float width, float height, float depth, float texRepeatX = 1, float texRepeatZ = 1, bool isFile = true)
        {
            if (Models.ContainsKey(name))
            {
                HelperGeneral.ShowErrorAndQuit("KWEngine::BuildTerrainModel()", "There already is a model with that name. Please choose a different name.");
                return;
            }
            GeoModel terrainModel = new GeoModel();

            terrainModel.Name    = name;
            terrainModel.Meshes  = new Dictionary <string, GeoMesh>();
            terrainModel.IsValid = true;

            GeoMeshHitbox meshHitBox = new GeoMeshHitbox(0 + width / 2, 0 + height / 2, 0 + depth / 2, 0 - width / 2, 0 - height / 2, 0 - depth / 2, null);

            meshHitBox.Model = terrainModel;
            meshHitBox.Name  = name;

            terrainModel.MeshHitboxes = new List <GeoMeshHitbox>();
            terrainModel.MeshHitboxes.Add(meshHitBox);

            GeoTerrain t           = new GeoTerrain();
            GeoMesh    terrainMesh = t.BuildTerrain2(new Vector3(0, 0, 0), heightmap, width, height, depth, texRepeatX, texRepeatZ, isFile);

            terrainMesh.Terrain = t;
            GeoMaterial mat = new GeoMaterial();

            mat.BlendMode     = BlendingFactor.OneMinusSrcAlpha;
            mat.ColorAlbedo   = new Vector4(1, 1, 1, 1);
            mat.ColorEmissive = new Vector4(0, 0, 0, 0);
            mat.Opacity       = 1;
            mat.Metalness     = 0;
            mat.Roughness     = 1;

            GeoTexture texDiffuse = new GeoTexture();

            texDiffuse.Filename    = texture;
            texDiffuse.Type        = TextureType.Albedo;
            texDiffuse.UVMapIndex  = 0;
            texDiffuse.UVTransform = new Vector2(texRepeatX, texRepeatZ);

            bool dictFound = CustomTextures.TryGetValue(CurrentWorld, out Dictionary <string, int> texDict);

            if (dictFound && texDict.ContainsKey(texture))
            {
                texDiffuse.OpenGLID = texDict[texture];
            }
            else
            {
                int texId = isFile ? HelperTexture.LoadTextureForModelExternal(texture) : HelperTexture.LoadTextureForModelInternal(texture);
                texDiffuse.OpenGLID = texId > 0 ? texId : KWEngine.TextureDefault;

                if (dictFound && texId > 0)
                {
                    texDict.Add(texture, texDiffuse.OpenGLID);
                }
            }
            mat.TextureAlbedo = texDiffuse;


            terrainMesh.Material = mat;
            terrainModel.Meshes.Add("Terrain", terrainMesh);
            KWEngine.Models.Add(name, terrainModel);
        }