Beispiel #1
0
        //Для include
        internal override List <SourceLine> Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error, Func <string, PreprocessorParseResult> recursiveFunc)
        {
            if (enableStack.Contains(false))
            {
                error = null;
                return(null);
            }

            string strInput = input.AsSingleLine();

            strInput = ClearInput(strInput);

            if (!Name1Regex.IsMatch(strInput) && !Name2Regex.IsMatch(strInput))
            {
                error = new ParseError(ParseErrorType.Preprocessor_WrongNameFormat);
                return(null);
            }

            strInput = strInput.Trim('\"', '<', '>');

            var result = recursiveFunc(strInput);

            if (result.error != null)
            {
                error = result.error;
                return(null);
            }
            else
            {
                error = null;
                return(result.sourceLines);
            }
        }
Beispiel #2
0
        public object Convert(object[] values, Type targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            double result = System.Convert.ToDouble(values[0]);

            bool first = true;

            foreach (var item in values)
            {
                //去掉第一个
                if (first)
                {
                    first = false; continue;
                }
                result /= System.Convert.ToDouble(item);
            }

            //获取参数
            StringGroup paramValues = new StringGroup(System.Convert.ToString(parameter), ",");

            if (paramValues.ToString() != "")
            {
                foreach (var item in paramValues.ToStringGroup())
                {
                    result /= double.Parse(item);
                }
            }

            //返回
            return(result);
        }
Beispiel #3
0
        internal override void Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error)
        {
            if (enableStack.Contains(false))
            {
                error = null;
                return;
            }

            string strInput = input.AsSingleLine();

            strInput = ClearInput(strInput);

            if (!PreprocessorIfdef.ArgumentRegex.IsMatch(strInput))
            {
                error = new ParseError(ParseErrorType.Preprocessor_NameExpected);
                return;
            }

            if (!defines.Exists(p => p.Name == strInput))
            {
                error = new ParseError(ParseErrorType.Preprocessor_UnknownDefineName);
                return;
            }

            defines.RemoveAll(p => p.Name == strInput);
            error = null;
        }
 public LineFileBlockStruct()
 {
     lineName     = "";
     lineMessage  = new string[5];
     lineType     = enumLineType.Bus;
     lineWait     = enumLineWait.JustSoSo;
     lineRuntime  = new int[4];
     lineUpStop   = new StringGroup("", "");
     lineDownStop = new StringGroup("", "");
 }
Beispiel #5
0
        /// <summary>
        /// 设置输出的目录
        /// </summary>
        /// <param name="folderPath"></param>
        public void SetFolder(string folderPath)
        {
            StringGroup sg = new StringGroup(ResourcesFiles, ",");

            string[] fileArray = sg.ToStringGroup();
            foreach (string item in fileArray)
            {
                File.Delete(folderPath + item);
            }
        }
Beispiel #6
0
        internal override void Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error)
        {
            if (enableStack.Contains(false))
            {
                error = null;
                return;
            }

            error = null;
        }
Beispiel #7
0
        public void ConvertToResources(Tools.StringGroup value)
        {
            if (value.sourceString == "")
            {
                return;
            }

            //处理文件数据
            string[] result = value.ToStringGroup();
            stopName      = result[0];
            stopCrossLine = new StringGroup(result[1], ",");
        }
Beispiel #8
0
        internal override void Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error)
        {
            if (enableStack.Contains(false))
            {
                error = null;
                return;
            }

            AllowDefinedFunction = true;

            string strInput = input.AsSingleLine();

            strInput = ClearInput(strInput);

            Expression exp;
            var        expError = Expression.Parse(strInput, out exp, (token) =>
            {
                if (token.UnaryFunction == null || token.UnaryFunction.FunctionString != "defined")
                {
                    var def = defines.Find(p => p.Name == token.RawValue);
                    if (def == null)
                    {
                        throw new WrongTokenException();
                    }
                    token.RawValue = def.Value.AsSingleLine();

                    if (!token.IsSimple)
                    {
                        Expression expression;
                        Expression.Parse(token.RawValue, out expression);
                        token.Subtokens = expression.TokenTree.Subtokens;
                    }

                    return(null);
                }

                return(new ObjectReference((Integer)0, ReferenceType.Define));
            });

            if (expError != null)
            {
                error = expError;
                return;
            }

            bool result = exp.Calculate(null).AsBool();

            enableStack.Push(result);

            error = null;
            AllowDefinedFunction = false;
        }
Beispiel #9
0
        /// <summary>
        /// 添加到队列
        /// </summary>
        /// <param name="data">添加内容</param>
        /// <param name="head">头标识</param>
        public void Add(StringGroup data, string head)
        {
            //确定删除
            if (memorizeCore.Count == 10)
            {
                memorizeCore.RemoveAt(0);
                memorizeHead.RemoveAt(0);
            }

            //添加
            memorizeCore.Add(data);
            memorizeHead.Add(head);
        }
Beispiel #10
0
        /// <summary>
        /// 检测文件夹下是否存在需要打包的文件
        /// </summary>
        /// <param name="folderPath">文件夹,需要加\</param>
        /// <returns></returns>
        public bool CheckFolder(string folderPath)
        {
            StringGroup sg = new StringGroup(ResourcesFiles, ",");

            string[] fileArray = sg.ToStringGroup();
            //判断
            foreach (string item in fileArray)
            {
                if (File.Exists(folderPath + item) == false)
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #11
0
        internal override void Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error)
        {
            if (enableStack.Contains(false))
            {
                error = null;
                return;
            }

            if (enableStack.Contains(false))
            {
                error = null;
                return;
            }

            error = new ParseError(ParseErrorType.Preprocessor_UserDefinedError);
        }
Beispiel #12
0
        internal override void Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error)
        {
            if (enableStack.Count == 0)
            {
                error = new ParseError(ParseErrorType.Preprocessor_EndifWithoutPreviousConditionals);
                return;
            }

            if (enableStack.Skip(1).Contains(false))
            {
                error = null;
                return;
            }

            enableStack.Pop();
            error = null;
        }
Beispiel #13
0
        private StringGroup ReadStringGroup(Stream s)
        {
            var result = new StringGroup();

            var groupStartPointer = s.ReadValueS64(Endianness);
            var strCount          = s.ReadValueU16(Endianness);

            result.Unknown = s.ReadBytes(6);

            for (var i = 0; i < strCount; i++)
            {
                s.Seek(groupStartPointer + (i * 12), SeekOrigin.Begin);
                var item = ReadItem(s);
                result.Items.Add(item);
            }

            return(result);
        }
Beispiel #14
0
        public void ConvertToResources(Tools.StringGroup value)
        {
            if (value.sourceString == "")
            {
                return;
            }

            //处理文件数据
            string[] result = value.ToStringGroup();
            stopName = result[0];

            var cache = new StringGroup(result[1], ",");

            foreach (string item in cache.ToStringGroup())
            {
                stopExit.Add(new StringGroup(item, "#"));
            }
        }
Beispiel #15
0
        /// <summary>
        /// 用字符列表填充字符串中的残缺部分
        /// </summary>
        /// <param name="originalStr">要填充的字符串</param>
        /// <param name="blockList">填充字符列表</param>
        /// <returns></returns>
        public static string FillStringByList(string originalStr, StringGroup blockList)
        {
            var cache = blockList.ToStringGroup();

            if (cache.Length == 0)
            {
                return(originalStr);
            }

            int index = 0;

            foreach (string item in cache)
            {
                originalStr.Replace("{" + index.ToString() + "}", item);
                index++;
            }

            return(originalStr);
        }
        /// <summary>
        /// 强制一次获取,必须在停止主循环的前提下调用,且通过此函数返回数据而不使用委托
        /// </summary>
        /// <returns></returns>
        public List <Kernel.Management.UserInterfaceBlockStruct.LinePageRuntimeBlockStruct> ForceToGet()
        {
            if (DllState != enumDllReflectionState.Ready)
            {
                throw new InvalidOperationException();
            }

            //set command
            Command.SetValue(ReflectionClass, DllCommandCreator.CreateCommandOfMonitorDll(enumCommandOfMonitorDll.GetLine, ""));

            string result = "";

            try {
                result = MethodGetData.Invoke(ReflectionClass, null).ToString();
            } catch (Exception) {
                return(new List <Management.UserInterfaceBlockStruct.LinePageRuntimeBlockStruct>());
            }

            if (result == "")
            {
                return(new List <Management.UserInterfaceBlockStruct.LinePageRuntimeBlockStruct>());
            }

            //set list
            var list = new List <Kernel.Management.UserInterfaceBlockStruct.LinePageRuntimeBlockStruct>();

            foreach (var item in new StringGroup(result, "@").ToStringGroup())
            {
                var temp = new StringGroup(item, "#").ToStringGroup();
                list.Add(new Management.UserInterfaceBlockStruct.LinePageRuntimeBlockStruct()
                {
                    ID                = temp[0],
                    IsUpLine          = temp[1] == "0" ? true : false,
                    BelongToStopIndex = System.Convert.ToInt32(temp[2]),
                    Message1          = temp[3],
                    Message2          = temp[4],
                    Message3          = temp[5]
                });
            }

            return(list);
        }
        /// <summary>
        /// 阅读循环
        /// </summary>
        private void ReadLoop()
        {
            string result = "";

            while (true)
            {
                //set command
                Command.SetValue(ReflectionClass, DllCommandCreator.CreateCommandOfMonitorDll(enumCommandOfMonitorDll.GetLine, ""));

                //尝试获取,获取失败返回
                try {
                    result = MethodGetData.Invoke(ReflectionClass, null).ToString();
                } catch (Exception) {
                    continue;
                }

                if (result == "")
                {
                    continue;
                }

                //set list
                var list = new List <Kernel.Management.UserInterfaceBlockStruct.LinePageRuntimeBlockStruct>();
                foreach (var item in new StringGroup(result, "@").ToStringGroup())
                {
                    var temp = new StringGroup(item, "#").ToStringGroup();
                    list.Add(new Management.UserInterfaceBlockStruct.LinePageRuntimeBlockStruct()
                    {
                        ID                = temp[0],
                        IsUpLine          = temp[1] == "0" ? true : false,
                        BelongToStopIndex = System.Convert.ToInt32(temp[2]),
                        Message1          = temp[3],
                        Message2          = temp[4],
                        Message3          = temp[5]
                    });
                }

                NewData(list);
            }
        }
Beispiel #18
0
        public object Convert(object[] values, Type targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            double result = 0;

            foreach (var item in values)
            {
                result *= System.Convert.ToDouble(item);
            }

            //获取参数
            StringGroup paramValues = new StringGroup(System.Convert.ToString(parameter), ",");

            if (paramValues.ToString() != "")
            {
                foreach (var item in paramValues.ToStringGroup())
                {
                    result *= double.Parse(item);
                }
            }

            //返回
            return(result);
        }
Beispiel #19
0
        /// <summary>
        /// 压缩文件,返回true表示成功,false表示失败
        /// </summary>
        /// <param name="outFilePath">输出文件的绝对目录</param>
        /// <param name="fileFolder">输入文件所在的文件夹,需要加\</param>
        /// <param name="fileVersion">需要输入的build版本号</param>
        /// <returns></returns>
        public bool Compress(string outFilePath, string fileFolder, long fileVersion)
        {
            //检查
            if (CheckFolder(fileFolder) == false)
            {
                return(false);
            }
            if (File.Exists(outFilePath) == true)
            {
                File.Delete(outFilePath);
            }

            //开始保存
            FileStream   outFile = new FileStream(outFilePath, FileMode.Create, FileAccess.Write, FileShare.Write);
            BinaryReader br;
            BinaryWriter bw = new BinaryWriter(outFile, System.Text.Encoding.UTF8);

            StringGroup sg = new StringGroup(ResourcesFiles, ",");

            string[] fileArray = sg.ToStringGroup();

            FileStream intoFile;

            //计量数据数字的变量
            //char以1000为基数读取,读不完就写
            Int64     charCount     = 0;
            ArrayList fileCountList = new ArrayList();

            //先乱写文件头
            bw.Write("BRSP".ToCharArray());
            for (int a = 0; a < fileArray.Length; a++)
            {
                bw.Write((Int64)0);
            }

            //读取文件写入
            for (int a = 0; a < fileArray.Length; a++)
            {
                intoFile = new FileStream(fileFolder + fileArray[a], FileMode.Open, FileAccess.Read, FileShare.Read);
                br       = new BinaryReader(intoFile, System.Text.Encoding.UTF8);

                //读取循环
                while (true)
                {
                    //先读取那么多
                    char[] cacheChar = br.ReadChars(1000);

                    //如果为0,没有内容,不结束读取
                    if (cacheChar.Length == 0)
                    {
                        break;
                    }

                    //读取数量不足,说明也到文件尾了
                    if (cacheChar.Length < 1000)
                    {
                        charCount += cacheChar.Length;
                        bw.Write(cacheChar);
                        break;
                    }
                    else
                    {
                        //继续读取
                        charCount += 1000;
                        bw.Write(cacheChar);
                    }
                }

                //善后处理
                br.Dispose();
                intoFile.Dispose();

                fileCountList.Add(charCount);
                charCount = 0;
            }

            //==============================结束各个变量,准备覆写
            bw.Dispose();
            outFile.Dispose();

            //覆写
            FileStream   outFileProcess = new FileStream(outFilePath, FileMode.Open, FileAccess.Write, FileShare.Write);
            BinaryWriter bwProcess      = new BinaryWriter(outFileProcess, System.Text.Encoding.UTF8);

            //写文件头
            bwProcess.Write("BRSP".ToCharArray());
            bwProcess.Write(fileVersion);
            for (int a = 0; a < fileArray.Length; a++)
            {
                bwProcess.Write((Int64)fileCountList[a]);
            }

            bwProcess.Dispose();
            outFileProcess.Dispose();

            return(true);
        }
Beispiel #20
0
 public void FlushTranslateData(StringGroup result)
 {
 }
Beispiel #21
0
 static void testtg()
 {
     string[] txt = File.ReadAllLines("tzt.txt");
     StringGroup.Parse(txt, 0, txt.Length);
 }
Beispiel #22
0
        /// <summary>
        /// 解压缩文件,返回true表示成功,false表示失败
        /// </summary>
        /// <param name="filePath">包文件的绝对目录</param>
        /// <param name="outFileFolder">输出文件所在的文件夹,需要加\</param>
        /// <param name="fileVersion">需要验证的build版本号</param>
        /// <returns></returns>
        public bool Decompress(string filePath, string outFileFolder, long fileVersion)
        {
            //检测
            if (File.Exists(filePath) == false)
            {
                return(false);
            }

            //开始读取
            FileStream   intoFile = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryReader br       = new BinaryReader(intoFile, System.Text.Encoding.UTF8);
            FileStream   outFile;
            BinaryWriter bw;

            StringGroup sg = new StringGroup(ResourcesFiles, ",");

            string[] fileArray = sg.ToStringGroup();

            //计量数据数字的变量
            //char以1000为基数写入
            ArrayList fileCountList = new ArrayList();

            //======================先读文件头,判断
            string fileHead = new string(br.ReadChars(4));

            if (fileHead != "BRSP")
            {
                //不合格,不行,退出
                br.Dispose();
                intoFile.Dispose();
                return(false);
            }
            if (br.ReadInt64() != fileVersion)
            {
                //不合格,不行,退出
                br.Dispose();
                intoFile.Dispose();
                return(false);
            }

            //============确认无误后可以写入===============
            SetFolder(outFileFolder);

            //读入区块
            for (int a = 0; a < fileArray.Length; a++)
            {
                fileCountList.Add(br.ReadInt64());
            }

            //读数据
            for (int a = 0; a < fileArray.Length; a++)
            {
                //如果没有可以读的,取消之
                if ((Int64)fileCountList[a] == 0)
                {
                    continue;
                }

                //打开文件
                outFile = new FileStream(outFileFolder + fileArray[a], FileMode.Create, FileAccess.Write, FileShare.Write);
                bw      = new BinaryWriter(outFile, System.Text.Encoding.UTF8);

                //=================================计算读取次数
                //需要的for循环次数
                int forCount = (int)((Int64)fileCountList[a] / 1000);
                //余下的多余的次数
                int lostCount = (int)((Int64)fileCountList[a] % 1000);

                //====================================读取循环
                //没有达到1000,直接在余下处理里处理
                if (forCount > 0)
                {
                    for (int b = 0; b < forCount; b++)
                    {
                        bw.Write(br.ReadChars(1000));
                    }
                }

                //其余读取
                //是否需要读取
                if (lostCount == 0)   //不需要
                {
                }
                else
                {
                    //需要
                    bw.Write(br.ReadChars(lostCount));
                }

                //===================善后处理
                bw.Dispose();
                outFile.Dispose();
            }

            //善后处理
            br.Dispose();
            intoFile.Dispose();

            return(true);
        }
Beispiel #23
0
 public GuideLineBlockStruct()
 {
     lineName      = "";
     lineCrossLine = new StringGroup("", "");
 }
Beispiel #24
0
        internal override void Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error)
        {
            if (enableStack.Contains(false))
            {
                error = null;
                return;
            }

            string firstLine = ClearInput(input.AsSingleLine());

            if (string.IsNullOrEmpty(firstLine))
            {
                error = new ParseError(ParseErrorType.Preprocessor_NameExpected);
                return;
            }

            string[] parts = firstLine.Split(' ');
            string   name  = parts[0];

            if (name.Contains('(') || name.Contains(')') || name.Contains(','))
            {
                try
                {
                    if (!ParametricDefine.ParametricDefineRegex.IsMatch(name))
                    {
                        error = new ParseError(ParseErrorType.Preprocessor_WrongParametricDefineFormat);
                        return;
                    }
                }
                catch
                {
                    error = new ParseError(ParseErrorType.Preprocessor_WrongParametricDefineFormat);
                    return;
                }

                if (parts.Length == 1 && input.IsSingleLine)
                {
                    error = new ParseError(ParseErrorType.Preprocessor_ParametricDefineWithoutExpression);
                    return;
                }

                var firstValueLine = string.Join(")", firstLine.Split(')').Skip(1).ToArray());
                var group          = new StringGroup(firstValueLine);
                group.Strings.AddRange(input.Strings.Skip(1));

                var newDef = new ParametricDefine(name, group);

                if (defines.Exists(p => p.Name == newDef.Name))
                {
                    error = new ParseError(ParseErrorType.Preprocessor_DefineNameAlreadyExists);
                    return;
                }

                var value = newDef.Value;
                Define.ResolveDefines(defines, ref value, -1, null);
                newDef.Value = value;
                defines.Add(newDef);
            }
            else
            {
                if (!Define.GeneralDefineNameRegex.IsMatch(name))
                {
                    error = new ParseError(ParseErrorType.Preprocessor_WrongDefineName);
                    return;
                }

                if (defines.Exists(p => p.Name == Name))
                {
                    error = new ParseError(ParseErrorType.Preprocessor_DefineNameAlreadyExists);
                    return;
                }

                if (parts.Length == 1)
                {
                    defines.Add(new Define(name));
                }
                else
                {
                    var firstValueLine = string.Join(" ", parts.Skip(1).ToArray());
                    var group          = new StringGroup(firstValueLine);
                    group.Strings.AddRange(input.Strings.Skip(1));

                    var newDef = new Define(name, group);
                    var value  = newDef.Value;
                    Define.ResolveDefines(defines, ref value, -1, null);
                    newDef.Value = value;
                    defines.Add(newDef);
                }
            }
            error = null;
        }
Beispiel #25
0
 public StopFileBlockStruct()
 {
     stopName      = "";
     stopCrossLine = new StringGroup("", "");
 }
        /// <summary>
        /// 设置颜色
        /// </summary>
        private void SetColor()
        {
            //如果没有数据,全部刷为空白
            if (RuntimeBusMsg == "")
            {
                foreach (var item in colorShow)
                {
                    item.Color = Color.FromArgb(0, 30, 144, 255);
                }

                return;
            }

            //如果序列为空,退出之
            if (StopCount == 0)
            {
                return;
            }

            //计算
            var cache = new StringGroup(RuntimeBusMsg, ",").ToStringGroup();

            stopsCountList.Clear();
            //填充数组
            for (int i = 0; i < StopCount; i++)
            {
                stopsCountList.Add(0);
            }

            //统计数组
            foreach (string item in cache)
            {
                if (int.Parse(item) < StopCount)
                {
                    stopsCountList[int.Parse(item)]++;
                }
            }

            //获得区间
            double countAreaUnit = (stopsCountList.Max((numberItem) => { return(numberItem); }) -
                                    stopsCountList.Min((numberItem) => { return(numberItem); })) / 5f;
            //set color
            //0->105->180->225->255为二次函数式渐变,目的在于区分无车和有车状态下颜色过于相似问题
            int index = 0;

            foreach (var item in stopsCountList)
            {
                if (item >= countAreaUnit * 4)
                {
                    colorShow[index].Color = Color.FromArgb(255, 30, 144, 255);
                }
                else if (item >= countAreaUnit * 3)
                {
                    colorShow[index].Color = Color.FromArgb(225, 30, 144, 255);
                }
                else if (item >= countAreaUnit * 2)
                {
                    colorShow[index].Color = Color.FromArgb(180, 30, 144, 255);
                }
                else if (item >= countAreaUnit * 1)
                {
                    colorShow[index].Color = Color.FromArgb(105, 30, 144, 255);
                }
                else
                {
                    colorShow[index].Color = Color.FromArgb(0, 30, 144, 255);
                }
                index++;
            }
        }
Beispiel #27
0
 internal override void Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error)
 {
     throw new NotSupportedException();
 }
Beispiel #28
0
 //Для include
 internal override List <SourceLine> Apply(StringGroup input, Stack <bool> enableStack, List <Define> defines, out ParseError error, Func <string, PreprocessorParseResult> recursiveFunc)
 {
     throw new NotSupportedException();
 }
Beispiel #29
0
        /// <summary>
        /// 检测字符串中是否包含指定内容
        /// </summary>
        /// <param name="checkedWord"></param>
        /// <param name="word"></param>
        /// <returns></returns>
        private bool CheckWordHaveBus(string checkedWord, string word)
        {
            var cache = new StringGroup(checkedWord, ",");

            return(cache.ToArrayList().Contains(word));
        }