コード例 #1
0
        /*
         * public override IPropertyDialog PreparePropertyDialog()
         * {
         *  var dialog = new ElementPropertyDialog(2, ElementPropertyDialog.INST_ATCH);
         *  dialog.ShowLine3("EVENT:", IDValue);
         *  dialog.ShowLine5("FUNC:");
         *  dialog.ValueString5 = FuncName;
         *  return dialog;
         * }
         */
        public override void AcceptNewValues(IList <string> valueStrings, Device contextDevice)
        {
            var  oldvaluestring1 = IDValue.ValueString;
            var  oldvaluestring2 = FuncName;
            bool check1          = ValueParser.CheckValueString(valueStrings[0], new Regex[] {
                ValueParser.VerifyIntKHValueRegex
            });
            bool check2 = true;

            if (check1)
            {
                IDValue = ValueParser.ParseWordValue(valueStrings[0], contextDevice);
                int id = int.Parse(IDValue.GetValue());
                if (id < 0 || id > 7)
                {
                    throw new ValueParseException("ID超出范围(0-7)");
                }
            }
            if (check1 && check2)
            {
                FuncName = valueStrings[2];
                InstructionCommentManager.ModifyValue(this, oldvaluestring1, IDValue.ValueString);
                InstructionCommentManager.ModifyValue(this, oldvaluestring2, FuncName);
                //ValueCommentManager.UpdateComment(InputValue, valueStrings[1]);
                ValueCommentManager.UpdateComment(IDValue, valueStrings[1]);
            }
            else if (!check2)
            {
                throw new ValueParseException(String.Format("找不到函数{0:s}", valueStrings[2]));
            }
            else if (!check1)
            {
                throw new ValueParseException("EVENT格式非法!");
            }
        }
コード例 #2
0
        /*
         * public override IPropertyDialog PreparePropertyDialog()
         * {
         *  var dialog = new ElementPropertyDialog(1);
         *  //dialog.ShowLine3("FUNC:", FuncName);
         *  dialog.ShowLine4("EVENT:", IDValue);
         *  return dialog;
         * }
         */
        public override void AcceptNewValues(IList <string> valueStrings, Device contextDevice)
        {
            var  oldvaluestring1 = IDValue.ValueString;
            bool check1          = ValueParser.CheckValueString(valueStrings[2], new Regex[] {
                ValueParser.VerifyIntKHValueRegex
            });

            if (check1)
            {
                IDValue = ValueParser.ParseWordValue(valueStrings[2], contextDevice);
                int id = int.Parse(IDValue.GetValue());
                if (id < 0 || id > 7)
                {
                    throw new ValueParseException("EV超出范围(0-7)");
                }
            }
            else
            {
                throw new ValueParseException("EV格式非法!");
            }
        }
コード例 #3
0
ファイル: ExcelTool.cs プロジェクト: firefishes/ShipDock
        /// <summary>
        /// 读取表数据,生成对应的数组
        /// </summary>
        /// <param name="filePath">excel文件全路径</param>
        /// <returns>Item数组</returns>
        public static void CreateItemArrayWithExcel(string filePath, out string relativeName, ref string log)
        {
            InitExeclDefs();
            log += filePath + "开始解析... \r\n";

            DataRowCollection collect = ReadExcel(filePath, out int rowSize, out int colSize);//获得表数据
            ExeclDefination   defination = Setting.classDefine;
            int    col = defination.column, row = defination.row;
            string className = collect[row][col].ToString();//类名

            defination = Setting.generateFileName;
            col        = defination.column;
            row        = defination.row;
            string fileName = collect[row][col].ToString();//生成的配置文件名

            fileName = string.IsNullOrEmpty(fileName) ? className : fileName;

            defination = Setting.classType;
            col        = defination.column;
            row        = defination.row;
            string classType = collect[row][col].ToString();//类模板的类别

            defination = Setting.IDFieldName;
            col        = defination.column;
            row        = defination.row;
            string IDName = collect[row][col].ToString();//id字段的名称

            defination = Setting.dataStart;
            int dataStartRow = defination.row;
            int dataStartCol = defination.column;

            Debug.Log(rowSize);

            string cellData;

            for (int i = dataStartRow; i < rowSize; i++)
            {
                cellData = collect[i][dataStartCol].ToString();
                if (string.IsNullOrEmpty(cellData))
                {
                    rowSize = i;//找到数据起始列为空的一行,作为数据最终行
                    Debug.Log(rowSize);
                    break;
                }
                else
                {
                }
            }

            StringBuilder sb = new StringBuilder();

            int typeRow  = Setting.dataType.row;     //类型名所在行
            int keyRow   = Setting.keyFieldDef.row;  //字段名所在行
            int notesRow = Setting.noteFieldDef.row; //注释所在行

            DataRow rowData    = collect[typeRow];
            object  colData    = rowData[dataStartCol];
            object  IDTypeCell = collect[typeRow][dataStartCol];

            string            typeValue = GetCSharpForTypeValueCode(IDTypeCell.ToString());
            ClassTemplateInfo info      = new ClassTemplateInfo
            {
                sb           = sb,
                collect      = collect,
                className    = className,
                notesRow     = notesRow,
                dataStartCol = dataStartCol,
                typeValue    = typeValue,
                IDName       = IDName,
            };

            switch (classType)
            {
            case "mapper":
                TranslateConfigCSharpClassCode(info);
                break;

            case "const":    //常量类
                sb.Append("namespace StaticConfig");
                sb.Append("{");
                sb.Append("    public static class %cls%".Replace(info.rplClsName, className));
                sb.Append("    {");
                sb.Append("    }");
                sb.Append("}");
                break;
            }
            string field, notes, valueInitCode;
            string CSharpScript = sb.ToString();

            sb.Clear();

            object item;
            string parserCode = IDName.Append(GetCSharpForSetValueCode(IDTypeCell.ToString())); //获取到翻译后的 id 赋值语句

            for (int i = dataStartCol + 1; i < colSize; i++)                                    //从id列顺延下一个字段开始构建剩余的脚本
            {
                item      = collect[typeRow][i];                                                //类型
                typeValue = item.ToString();

                if (string.IsNullOrEmpty(typeValue))
                {
                    colSize = i;//读取到无效的表头,此前的所有字段为完整的类成员字段,并更新到列数
                    break;
                }
                else
                {
                }

                typeValue = GetCSharpForTypeValueCode(typeValue);

                item          = collect[keyRow][i];//字段名
                field         = item.ToString();
                notes         = collect[notesRow][i].ToString();
                valueInitCode = collect[typeRow][i].ToString();

                sb.Append("/// <summary>");
                sb.Append("\r\n        /// %notes%")
                .Replace(info.notes, notes);
                sb.Append("\r\n        /// <summary>\r\n        ");
                sb.Append("public %type% %fieldName%;\r\n")
                .Replace(info.typeName, typeValue)
                .Replace(info.fieldName, field);
                sb.Append("        ");

                parserCode = parserCode.Append(field, GetCSharpForSetValueCode(valueInitCode));//获取到翻译后的其他成员字段赋值语句
            }

            CSharpScript = CSharpScript.Replace(info.codes, sb.ToString());  //合成类成员字段的声明语句
            CSharpScript = CSharpScript.Replace(info.parseCode, parserCode); //合成类成员字段的初始化赋值语句
            sb.Clear();

            object     ID;
            string     IDValue;
            DataRow    itemRow;
            ByteBuffer byteBuffer   = ByteBuffer.Allocate(0);
            int        dataRealSize = rowSize - dataStartRow;

            byteBuffer.WriteInt(dataRealSize);
            for (int i = dataStartRow; i < rowSize; i++)
            {
                itemRow = collect[i];
                ID      = itemRow[dataStartCol];

                IDValue = ID.ToString();
                if (string.IsNullOrEmpty(IDValue))
                {
                    Debug.LogWarning("Config ID invalid in row " + i + ", it do not allow empty, config bytes parse will be break.");
                    break;
                }
                else
                {
                    Debug.Log("Writing in ID = " + IDValue.ToString());
                    for (int j = dataStartCol; j < colSize; j++)//从id列顺延下一个字段开始构建剩余的脚本
                    {
                        item = collect[typeRow][j];

                        typeValue = item.ToString();       //字段类型
                        field     = itemRow[j].ToString(); //字段数据

                        WriteField(ref byteBuffer, typeValue, field, collect[keyRow][j].ToString());
                    }
                }
            }
            Debug.Log("Write finished.. length = " + byteBuffer.GetCapacity());

            string path = GetCSharpCodeFilePath(className);

            FileOperater.WriteUTF8Text(CSharpScript, path);//生成代码

            path = GetConfigFilePath(fileName, out relativeName);
            FileOperater.WriteBytes(byteBuffer.ToArray(), path);//生成配置数据文件
        }
コード例 #4
0
ファイル: PostComponents.cs プロジェクト: FairFolk/NetTally
 public override int GetHashCode() => Author.GetHashCode() ^ IDValue.GetHashCode();