Exemple #1
0
        /// <summary>
        /// 判断车型配置是否和数据库中的LoaderCode表中配置重复
        /// 重复弹出重复的配置表对应条目
        /// 不重复弹出null值,注意:还有一种读不到数据的情况,事后要考虑!
        /// </summary>
        private LoaderCode JudgeLoaderCodeRepeat(LoaderCode newLoaderCode, JudgePara judgePara)
        {
            LoaderCode tempLoaderCode;
            object     tempObject = null;
            string     tempString = null, tempLCstr = null;

            if (judgePara == JudgePara.useWholeCode)
            {
                tempLCstr = newLoaderCode.wholeCode;
            }
            if (judgePara == JudgePara.usewholeConfigration)
            {
                tempLCstr = newLoaderCode.wholeConfigration;
            }
            LoaderCodeService loaderCodeService = new LoaderCodeService();

            loaderCodeIdRecord  = (int)loaderCodeService.GetLoaderCodeCount();
            loaderCodeIdRecord += 100;
            for (int id = 100; id < loaderCodeIdRecord; id++)
            {
                if (null == (tempObject = loaderCodeService.GetLoaderCodeDataById(id, (string)paraLCStr[(int)judgePara])))
                {
                    break;
                }
                tempString = tempObject.ToString();
                if (String.Compare(tempString, tempLCstr) == 0)
                {
                    tempLoaderCode = loaderCodeService.ReaderLoaderCodeById(id);
                    return(tempLoaderCode);
                }
            }
            return(null);
        }
        /// <summary>
        /// 向数据库LoaderCode表插入一条数据条目
        /// </summary>
        /// <param name="loaderCode"></param>
        /// <returns></returns>
        public int AddLoaderCode(LoaderCode loaderCode)
        {
            string sql = "insert into LoaderCode(wholeCode,wholeConfigration)";

            sql += $"values('{loaderCode.wholeCode}','{loaderCode.wholeConfigration}')";

            return(SQLHelper.Update(sql));
        }
Exemple #3
0
        /// <summary>
        /// 插入数据到数据表LoaderCode中,返回受影响的行数
        /// </summary>
        /// <param name="loaderConfigBase"></param>
        /// <returns></returns>
        private int InsertLoaderCode(LoaderCode loaderCode)
        {
            LoaderCodeService loaderCodeService = new LoaderCodeService();

            if ((loaderCode == null) || (loaderCode.wholeCode.Contains("*")))
            {
                return(0);
            }
            return(loaderCodeService.AddLoaderCode(loaderCode));
        }
Exemple #4
0
        /// <summary>
        /// 生成输入的车型配置对应的编码
        /// 并封装到LoaderCode类
        /// 默认enterLoaderConfig输入是有效的,不少不多,但是允许每项输入错别字,有效性交由UI控制。
        /// </summary>
        /// <param name="loaderConfigBase"></param>
        /// <returns></returns>
        private LoaderCode CreateCode(string enterLoaderConfig, out LoaderCode reLoaderCode)
        {
            object baseSingleResult = null;

            string[] tmpArray;
            string[] loaderConfigArray = enterLoaderConfig.Split('/');
            string   code = null;
            int      id = 1, col = 0;//col = 0,
            bool     judgeFlag = false;

            reLoaderCode = null;
            LoaderCodeService loaderCodeService = new LoaderCodeService();
            LoaderCode        loaderCode        = new LoaderCode();

            loaderCode.wholeConfigration = enterLoaderConfig;
            for (col = 0; col < paramNumStr.Length; col++)
            //foreach (string itemLoaderConfig in loaderConfigArray)
            {
                if (paramNumStr[col] == "optional")
                {
                    if ((reLoaderCode = JudgeLoaderCodeRepeat(loaderCode, JudgePara.usewholeConfigration)) == null)
                    {
                        int tmpNum = JudgeLoaderCodeRepeat(code);
                        if (tmpNum < 10)
                        {
                            code += 0;
                        }
                        code += tmpNum;
                        break;
                    }
                    return(null);
                }
                while ((baseSingleResult = loaderCodeService.GetLoaderConfigrationBaseSingle(paramNumStr[col], id++)) != null)
                {
                    tmpArray = baseSingleResult.ToString().Split(':');

                    if ((id < 16) && (String.Compare(tmpArray[0], loaderConfigArray[col]) == 0))
                    {
                        code      = String.Concat(code, tmpArray[1]);
                        judgeFlag = true;
                        break;
                    }
                }
                id = 1;
                if (judgeFlag == false)
                {
                    code = String.Concat(code, "*");
                }
                judgeFlag = false;
            }
            loaderCode.wholeCode = code;
            return(loaderCode);
        }
        /// <summary>
        /// 返回ID对应LoaderCode表中条目
        /// </summary>
        /// <param name="loaderCodeId"></param>
        /// <returns></returns>
        public LoaderCode ReaderLoaderCodeById(int loaderCodeId)
        {
            string        sql        = $"select LoaderCodeId,wholeCode,wholeConfigration from LoaderCode where LoaderCodeId = {loaderCodeId}";
            LoaderCode    loaderCode = new LoaderCode();
            SqlDataReader reader     = SQLHelper.GetReader(sql);

            while (reader.Read())
            {
                loaderCode.LoaderCodeId      = (int)reader["LoaderCodeId"];
                loaderCode.wholeCode         = reader["wholeCode"].ToString();
                loaderCode.wholeConfigration = reader["wholeConfigration"].ToString();
            }
            return(loaderCode);
        }
        private void tbConfigEnter_TextChanged(object sender, EventArgs e)
        {
            //this.lbProductCode.Text = this.tbConfigEnter.Text;
            string loaderConfigUI = this.tbConfigEnter.Text;

            if (loaderConfigUI.Contains("\r\n"))
            {
                loaderConfigUI = loaderConfigUI.Replace("\r\n", "");
                if (CheckEffective(loaderConfigUI) == true)
                {
                    LoaderCode loaderCode = null, reCodeLoaderCode = null, reConfigLoaderCode = null;

                    LoaderCodeManager loaderCodeManager = new LoaderCodeManager();
                    loaderCode = loaderCodeManager.CreateLoaderCode(loaderConfigUI, out reCodeLoaderCode, out reConfigLoaderCode);
                    if (reCodeLoaderCode == null && reConfigLoaderCode == null)
                    {
                        this.lbProductCode.Text = loaderCode.wholeCode;
                    }
                    else
                    {
                        if (reConfigLoaderCode != null)
                        {
                            this.lbProductCode.Text  = reConfigLoaderCode.wholeCode;
                            this.lbProductCode.Text += "\r\n";
                            this.lbProductCode.Text += reConfigLoaderCode.wholeConfigration;
                            MessageBox.Show("配置重复!");
                        }
                        if (reCodeLoaderCode != null)
                        {
                            this.lbProductCode.Text  = reCodeLoaderCode.wholeCode;
                            this.lbProductCode.Text += "\r\n";
                            this.lbProductCode.Text += reCodeLoaderCode.wholeConfigration;
                            MessageBox.Show("编码重复!");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("输入出错,请重新输入!");
                }
                loaderConfigUI.Remove(0, loaderConfigUI.Length);
                this.tbConfigEnter.Text = null;
            }
        }
Exemple #7
0
        /// <summary>
        /// 生成编码,有重复保存到reLoaderCode
        /// </summary>
        /// <param name="enterLoaderConfig"></param>
        /// <param name="reLoaderCode"></param>
        /// <returns></returns>
        public LoaderCode CreateLoaderCode(string enterLoaderConfig, out LoaderCode reCodeLoaderCode, out LoaderCode reConfigLoaderCode)
        {
            LoaderCode loaderCode = null;

            reCodeLoaderCode   = null;
            reConfigLoaderCode = null;
            //【1】判断车型配置wholeConfigration,已有车型不做处理
            //【2】若数据库中没有此类车型,而后根据LoaderConfigrationBase类和数据库LoaderConfigrationBase表对比,
            //     生成编码LoaderCode:wholeCode
            //【3】并把LoaderConfigrationBase中的配置生成到LoaderCode:wholeConfigration
            //【4】将生成的LoaderCode加入数据库中的LoaderCode表
            if ((loaderCode = CreateCode(enterLoaderConfig, out reConfigLoaderCode)) != null)
            {
                if ((reCodeLoaderCode = JudgeLoaderCodeRepeat(loaderCode, JudgePara.useWholeCode)) == null)
                {
                    int temp = InsertLoaderCode(loaderCode);
                }
            }
            return(loaderCode);
        }
Exemple #8
0
        private static void Write(
            List <EnumData> enums,
            List <FunctionData> functions,
            List <CallbackData> callbacks,
            List <StructData> structs)
        {
            string[] license = File.ReadAllLines(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "License.txt"));

            StringBuilder sb = new StringBuilder(1024);

            foreach (var line in license)
            {
                sb.Append("// ");
                sb.AppendLine(line);
            }

            sb.AppendLine();

            sb.AppendLine("using System;");
            sb.AppendLine("using System.IO;");
            sb.AppendLine("using System.Reflection;");
            sb.AppendLine("using System.Runtime.InteropServices;");
            sb.AppendLine("using System.Security;");

            sb.AppendLine();
            sb.AppendLine("namespace GLFWDotNet");
            sb.AppendLine("{");
            sb.AppendLine("\tpublic static class GLFW");
            sb.AppendLine("\t{");

            foreach (var @enum in enums)
            {
                string name  = @enum.Name;
                string value = @enum.Value;

                sb.AppendLine($"\t\tpublic const int {name} = {value};");
            }

            sb.AppendLine();

            foreach (var @struct in structs.Where(x => !x.IsOpaque))
            {
                sb.AppendLine($"\t\tpublic struct {GetType(@struct.Name, structs)}");
                sb.AppendLine("\t\t{");

                foreach (var member in @struct.Members)
                {
                    var type = GetParamType(member.Type, ParamModifier.None, structs);
                    sb.AppendLine($"\t\t\tpublic {type} {member.Name};");
                }

                sb.AppendLine("\t\t}");

                sb.AppendLine();
            }

            foreach (var callback in callbacks)
            {
                string parameters = string.Join(", ", callback.Params.Select(x => GetParamType(x.Type, x.Modifier, structs) + " " + GetParamName(x.Name)));

                sb.AppendLine("\t\t[UnmanagedFunctionPointer(CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]");
                sb.AppendLine($"\t\tpublic delegate {GetReturnType(callback.ReturnType, structs)} {callback.Name}({parameters});");

                sb.AppendLine();
            }

            sb.AppendLine("\t\tprivate static class Delegates");
            sb.AppendLine("\t\t{");

            foreach (var function in functions)
            {
                string parameters = string.Join(", ", function.Params.Select(x => GetParamType(x.Type, x.Modifier, structs) + " " + GetParamName(x.Name)));

                if (function.CommentOut)
                {
                    sb.AppendLine("/*");
                }

                sb.AppendLine("\t\t\t[UnmanagedFunctionPointer(CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]");
                sb.AppendLine($"\t\t\tpublic delegate {GetReturnType(function.ReturnType, structs)} {function.Name}({parameters});");

                if (function.CommentOut)
                {
                    sb.AppendLine("*/");
                }

                sb.AppendLine();
            }

            sb.AppendLine("\t\t}");
            sb.AppendLine();

            foreach (var function in functions)
            {
                if (function.CommentOut)
                {
                    sb.Append("// ");
                }

                sb.AppendLine($"\t\tprivate static Delegates.{function.Name} _{function.Name};");
                sb.AppendLine();
            }

            sb.Append("\t\t");

            var glfwInit = functions.Single(x => x.Name == "glfwInit");

            var loaderCode = LoaderCode
                             .Replace("/// glfwInit.Summary ///", FormatDocs(glfwInit.BriefDescription, "\t\t").TrimStart())
                             .Replace("/// glfwInit.Remarks ///", FormatDocs(glfwInit.Description, "\t\t").TrimStart())
                             .Replace("/// glfwInit.Returns ///", FormatDocs(glfwInit.ReturnDescription, "\t\t").TrimStart());

            sb.AppendLine(loaderCode.Trim());
            sb.AppendLine();

            sb.AppendLine("\t\tprivate static void LoadFunctions(Func<string, IntPtr> getProcAddress)");
            sb.AppendLine("\t\t{");

            foreach (var function in functions)
            {
                if (function.CommentOut)
                {
                    sb.Append("// ");
                }

                sb.AppendLine($"\t\t\t_{function.Name} = (Delegates.{function.Name})Marshal.GetDelegateForFunctionPointer(getProcAddress(\"{function.Name}\"), typeof(Delegates.{function.Name}));");
            }

            sb.AppendLine("\t\t}");
            sb.AppendLine();

            foreach (var function in functions.Where(x => x.Name != "glfwInit"))
            {
                sb.AppendLine("\t\t/// <summary>");
                sb.AppendLine(FormatDocs(function.BriefDescription, "\t\t"));
                sb.AppendLine("\t\t/// </summary>");
                sb.AppendLine("\t\t/// <remarks>");
                sb.AppendLine(FormatDocs(function.Description, "\t\t"));
                sb.AppendLine("\t\t/// </remarks>");

                foreach (var param in function.Params)
                {
                    sb.AppendLine($"\t\t/// <param name=\"{param.Name}\">");
                    sb.AppendLine(FormatDocs(param.Description, "\t\t"));
                    sb.AppendLine("\t\t/// </param>");
                }

                if (!string.IsNullOrEmpty(function.ReturnDescription))
                {
                    sb.AppendLine("\t\t/// <returns>");
                    sb.AppendLine(FormatDocs(function.ReturnDescription, "\t\t"));
                    sb.AppendLine("\t\t/// </returns>");
                }

                if (function.CommentOut)
                {
                    sb.AppendLine("/*");
                }

                if (!Methods.ContainsKey(function.Name))
                {
                    string parameters       = string.Join(", ", function.Params.Select(x => GetParamType(x.Type, x.Modifier, structs) + " " + GetParamName(x.Name)));
                    string parametersInvoke = string.Join(", ", function.Params.Select(x => PrependModifier(GetParamName(x.Name), x.Modifier)));
                    string returnType       = GetReturnType(function.ReturnType, structs);

                    sb.AppendLine($"\t\tpublic static {returnType} {function.Name}({parameters})");
                    sb.AppendLine("\t\t{");

                    sb.Append("\t\t\t");

                    if (returnType != "void")
                    {
                        sb.Append("return ");
                    }

                    sb.AppendLine($"_{function.Name}({parametersInvoke});");

                    sb.AppendLine("\t\t}");

                    if (function.CommentOut)
                    {
                        sb.AppendLine("*/");
                    }
                }
                else
                {
                    sb.AppendLine("\t\t" + Methods[function.Name].Trim());
                }

                sb.AppendLine();
            }

            sb.AppendLine("\t}");
            sb.AppendLine("}");

            File.WriteAllText(@"..\..\..\..\src\GLFWDotNet\GLFW.cs", sb.ToString());
        }