Ejemplo n.º 1
0
        public void Analyze()
        {
            //获得参数的个数。
            QLineInfo line = GetPram("K0100");

            //默认为-1,如果没读取值还是-1.
            int count = -1;

            if (line != null)
            {
                count = int.Parse(line.value);
                for (int j = 0; j < count; j++)
                {
                    Charactericstics.Add(new QCharacteristic());
                }
            }

            //小于0的话就退出。
            if (count < 0)
            {
                return;
            }

            //对每一个参数进行初始化。
            for (int i = 0; i < Lines.Count; i++)
            {
                line = Lines[i];
                int id = line.pid;

                if (id > 0)
                {
                    QCharacteristic p = Charactericstics[id - 1];
                    p.DealLine(line);
                }
            }

            //参数进行调整
            for (int i = 0; i < Charactericstics.Count; i++)
            {
                //pramters[i].Adjust();
            }

            //对数据进行调整,移除第1个参数为256的项。
            for (int i = 0; i < Data.Count; i++)
            {
                QData qd = Data[i];
                for (int j = 0; j < qd.items.Count; j++)
                {
                    if (!qd.items[j].addon[1].Equals("256"))
                    {
                        Charactericstics[j].data.Add(qd.items[j]);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static List<QLineInfo> read(string file)
        {
            string[] lines = File.ReadAllLines(file, Encoding.Default);
            List<QLineInfo> qlines = new List<QLineInfo>();
            for (int i = 0; i < lines.Length; i++)
            {
                // QLineInfo.Parse(lines[i]);
                QLineInfo qinfo = parse(lines[i]);
                if (qinfo != null)
                    qlines.Add(qinfo);

            } 
            return qlines;
        }
Ejemplo n.º 3
0
        public static QCatalog load(string file)
        {
            if (!File.Exists(file))
            {
                return(null);
            }

            try
            {
                QCatalog qc = new QCatalog();
                qc.qlines = QLineInfo.read(file);
                return(qc);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(null);
        }
Ejemplo n.º 4
0
        public static QLineInfo parse(string line)
        {
            try
            {
                if (line == null || line.Trim() == "")
                    return null;

                int p = line.IndexOf(' ');
                QLineInfo qline = new QLineInfo();

                qline.key = line.Substring(0, p).Split('/')[0].ToUpper().Trim();
                qline.pid = int.Parse(line.Substring(0, p).Split('/')[1].Trim());
                qline.value = line.Substring(p + 1).Trim();

                return qline;
            }
            catch { }

            return null;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 用于从文件中加载DFQ文件。
        /// </summary>
        /// <param name="path">DFQ文件的完整路径。</param>
        /// <returns></returns>
        public static QFile LoadFile(string path)
        {
            QFile qf = new QFile();

            //参数列表
            List <QCharacteristic> ps = new List <QCharacteristic>();


            // 文件读取部分,完成了以下几件事:
            // 1、读取每行,生成每行的QLineInfo对象
            // 2、先交给对应的参数处理,如果处理失败,再交给QFile处理
            // 3、如果不是QlineInfo对象,那么交给QFile的Data
            StreamReader sr = new StreamReader(path, Encoding.Default);

            while (!sr.EndOfStream)
            {
                try
                {
                    //先读取一行进来。
                    string s = sr.ReadLine();

                    //如果为空或长度为0,则继续下一次循环。
                    if (string.IsNullOrEmpty(s))
                    {
                        continue;
                    }

                    //去除前缀的空格,如果长度为0,则继续下一次循环。
                    s = s.TrimStart();
                    if (s.Length == 0)
                    {
                        continue;
                    }

                    //如果是K开头,那么就是定义,如果是‘/’那么就是注释,取消,否则就是数据。
                    if (s[0] == 'K' || s[0] == 'k')
                    {
                        QLineInfo line = new QLineInfo(s);

                        //如果是零配件信息,交由QF处理。"K1001 jet2013"
                        if (s[1] == '1')
                        {
                            qf.DealLine(line);
                        }
                        //否则是参数信息,交由参数层处理
                        else if (line.pid > 0)
                        {
                            if (line.pid > ps.Count)
                            {
                                for (int j = ps.Count; j < line.pid; j++)
                                {
                                    QCharacteristic p = new QCharacteristic();
                                    p.id = j + 1;
                                    ps.Add(p);
                                }
                            }
                            ps[line.pid - 1].DealLine(line);
                        }
                    }
                    //如果是/,那么就是注释,忽略。
                    else if (s[0] == '/')
                    {
                    }
                    else
                    {
                        qf.Data.Add(new QData(s));
                    }
                }
                catch { }
            }
            sr.Close();

            //取出生成的参数,添加至QFile中
            for (int i = 0; i < ps.Count; i++)
            {
                if (ps[i].id > 0)
                {
                    qf.Charactericstics.Add(ps[i]);
                }
            }

            //此处将QFile中的Data中的DataItem与
            //每个QPramater的QDataItem数据组一一对应。
            for (int i = 0; i < qf.Data.Count; i++)
            {
                for (int j = 0; j < qf.Data[i].items.Count; j++)
                {
                    qf.Charactericstics[j].data.Add(qf.Data[i].items[j]);
                }
            }

            return(qf);
        }
Ejemplo n.º 6
0
        public static QFile LoadFromStrings(string[] data)
        {
            QFile qf = new QFile();

            //开始默认加载100个参数,方便下面的ps[line.pid - 1]的调用
            List <QCharacteristic> ps = new List <QCharacteristic>();

            for (int i = 0; i < 100; i++)
            {
                ps.Add(new QCharacteristic());
            }

            // 文件读取部分,完成了以下几件事:
            // 1、读取每行,生成每行的QLineInfo对象
            // 2、先交给对应的参数处理,如果处理失败,再交给QFile处理
            // 3、如果不是QlineInfo对象,那么交给QFile的Data


            for (int i = 0; i < data.Length; i++)
            {
                string s = data[i];

                if (s == null || s.Length == 0)
                {
                    continue;
                }

                if (s[s.Length - 1] == '\r')
                {
                    s = s.Substring(0, s.Length - 1);
                }

                //如果是K开头,那么就是定义,如果是‘/’那么就是注释,取消,否则就是数据。
                if (s[0] == 'K' || s[0] == 'k')
                {
                    QLineInfo line = new QLineInfo(s);

                    //如果是零配件信息,交由QF处理。
                    if (s[1] == '1')
                    {
                        qf.DealLine(line);
                    }
                    //否则是参数信息,交由参数层处理
                    else if (line.pid > 0)
                    {
                        QCharacteristic p = ps[line.pid - 1];
                        p.DealLine(line);
                    }
                }
                //如果是/,那么就是注释,忽略。
                else if (s[0] == '/')
                {
                }
                else
                {
                    qf.Data.Add(new QData(s));
                }
            }


            //取出生成的参数,添加至QFile中
            for (int i = 0; i < ps.Count; i++)
            {
                if (ps[i].id > 0)
                {
                    qf.Charactericstics.Add(ps[i]);
                }
            }

            //此处将QFile中的Data中的DataItem与
            //每个QPramater的QDataItem数据组一一对应。
            for (int i = 0; i < qf.Data.Count; i++)
            {
                for (int j = 0; j < qf.Data[i].items.Count; j++)
                {
                    qf.Charactericstics[j].data.Add(qf.Data[i].items[j]);
                }
            }

            return(qf);
        }
Ejemplo n.º 7
0
        public bool LoadFile(string path)
        {
            //参数列表
            List <QCharacteristic> ps = new List <QCharacteristic>();

            // 文件读取部分,完成了以下几件事:
            // 1、读取每行,生成每行的QLineInfo对象
            // 2、先交给对应的参数处理,如果处理失败,再交给QFile处理
            // 3、如果不是QlineInfo对象,那么交给QFile的Data
            List <string> strs = GetLines(path);


            int   partid = 0;
            QPart part   = new QPart();

            foreach (string str in strs)
            {
                try
                {
                    //如果是K开头,那么就是定义,如果是‘/’那么就是注释,取消,否则就是数据。
                    if (str[0] == 'K' || str[0] == 'k')
                    {
                        QLineInfo line = new QLineInfo(str);

                        //如果是零配件信息,交由QF处理。"K1001 jet2013"
                        if (str[1] == '1')
                        {
                            partid = line.pid > 0 ? line.pid - 1 : 0;
                            if (partid + 1 > parts.Count)
                            {
                                QPart pt = new QPart();
                                pt.partid = line.pid;
                                parts.Add(pt);
                            }
                            parts[partid].DealLine(line);
                        }
                        //否则是参数信息,交由参数层处理
                        else if (str[1] == '2')
                        {
                            if (line.pid > ps.Count)
                            {
                                for (int j = ps.Count; j < line.pid; j++)
                                {
                                    QCharacteristic p = new QCharacteristic();
                                    p.partId = partid + 1;
                                    p.id     = j + 1;
                                    ps.Add(p);
                                    parts[partid].pramters.Add(p);
                                }
                            }
                            ps[line.pid - 1].DealLine(line);
                        }
                    }
                    //如果是/,那么就是注释,忽略。
                    else if (str[0] == '/')
                    {
                    }
                    else
                    {
                        this.data.Add(new QData(str));
                    }
                }
                catch { }
            }

            //取出生成的参数,添加至QFile中
            for (int i = 0; i < ps.Count; i++)
            {
                if (ps[i].id > 0)
                {
                    this.pramters.Add(ps[i]);
                }
            }

            //此处将QFile中的Data中的DataItem与
            //每个QPramater的QDataItem数据组一一对应。
            for (int i = 0; i < this.data.Count; i++)
            {
                for (int j = 0; j < this.data[i].items.Count; j++)
                {
                    this.pramters[j].data.Add(this.data[i].items[j]);
                }
            }


            return(true);
        }
Ejemplo n.º 8
0
 public virtual void DealLine(QLineInfo line)
 {
     this[line.key] = line.value;
 }