Beispiel #1
0
        /// <summary> 递归获取节点 match1 = 查找匹配条件 match2 = 结束查找匹配条件 </summary>
        public bool GetKeys <T>(ref List <T> findKey, BaseKey key, Predicate <BaseKey> match, Predicate <BaseKey> endOfMatch) where T : class
        {
            if (endOfMatch(key))
            {
                return(true);
            }

            if (match(key) && key is T)
            {
                T find = key as T;
                findKey.Add(find);
            }

            if (key.Keys.Count > 0)
            {
                foreach (var k in key.Keys)
                {
                    if (k is BaseKey)
                    {
                        BaseKey kn = k as BaseKey;
                        //  递归处
                        bool isEndOfMatch = GetKeys(ref findKey, kn, match, endOfMatch);

                        if (isEndOfMatch)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
 /// <summary> 插入节点到指定位置 </summary>
 public void InsertKey(int index, BaseKey key)
 {
     this.keys.Insert(index, key);
     key.parentKey = this;
     this.Lines.Add(key.ID);
     key.baseFile = this.baseFile;
 }
        public override BaseKey ReadKeyLine(System.IO.StreamReader reader)
        {
            BaseKey overKey = base.ReadKeyLine(reader);

            CmdGetWellItems();
            return(overKey);
        }
Beispiel #4
0
        /// <summary> 插入在本节点前 </summary>
        public bool InsertBefore(BaseKey inKey)
        {
            BaseKey parentKey = this.parentKey;

            inKey.parentKey = parentKey;

            if (parentKey == null)
            {
                return(false);
            }
            else
            {
                //  当前关键字标记
                int findKey = parentKey.Keys.FindIndex(l => l.Equals(this));

                //  找到到当前行的占位标记
                //int findLine = parentKey.lines.FindIndex(l => l == this.ID);

                if (findKey == -1)//|| findLine == -1
                {
                    return(false);
                }
                else
                {
                    parentKey.Keys.Insert(findKey, inKey);
                    //parentKey.lines.Insert(findLine, inKey.ID);
                    return(true);
                }
            }
        }
Beispiel #5
0
        /// <summary> 插入在本节点后 </summary>
        public bool InsertAfter(BaseKey inKey)
        {
            BaseKey parentKey = this.parentKey;

            inKey.parentKey = parentKey;
            if (parentKey == null)
            {
                return(false);
            }
            else
            {
                int findKey = parentKey.Keys.FindIndex(l => l.Equals(this));

                ////  找到到当前行的占位标记
                //int findLine = parentKey.lines.FindIndex(l => l == this.ID);

                if (findKey == -1)
                {
                    return(false);
                }
                else
                {
                    parentKey.Keys.Insert(findKey + 1, inKey);
                    return(true);
                }
            }
        }
        /// <summary> 增加重启时间 </summary>
        public static DATES AddSchDates(this SCHEDULE schDate, DateTime startTime, DateTime pTime)
        {
            BaseKey findKey = null;

            DateTime nowTime = startTime;

            if (nowTime > pTime)
            {
                throw new ArgumentException("插入的时间不能小于案例的起始时间!");
            }

            schDate.Foreach(
                l =>
            {
                if (l is DATES)
                {
                    DATES date = l as DATES;
                    nowTime    = date.DateTime;

                    //  记录比当前时间小的
                    if (nowTime < pTime)
                    {
                        findKey = l;
                    }
                }
                //else if (l is TSTEP)
                //{
                //    TSTEP step = l as TSTEP;
                //    int dayCount = step.DataCount;
                //    nowTime.AddDays(dayCount);

                //    //  记录比当前时间小的
                //    if (nowTime <= pTime)
                //    {
                //        findKey = l;
                //    }
                //}
            }
                );

            DATES insertDate = new DATES("DATES");

            insertDate.SetDateTime(pTime);

            //  没有找到 = 插入END前面
            if (findKey == null)
            {
                END endKey = schDate.Find <END>();
                schDate.InsertBefore(endKey, insertDate);
            }

            //  找到了 = 插入指定关键字前面
            else
            {
                schDate.InsertAfter(findKey, insertDate);
            }


            return(insertDate);
        }
Beispiel #7
0
        /// <summary> 获取匹配的一个节点 找到一个立即返回 </summary>
        T GetKeys <T>(BaseKey key, Predicate <BaseKey> match) where T : class
        {
            if (match(key) && key is T)
            {
                T find = key as T;
                return(find);
            }

            if (key.Keys.Count > 0)
            {
                foreach (var k in key.Keys)
                {
                    if (k is BaseKey)
                    {
                        BaseKey kn = k as BaseKey;

                        T temp = GetKeys <T>(kn, match);
                        //  递归处
                        if (temp != null)
                        {
                            return(temp);
                        }
                    }
                }

                return(null);
            }
            else
            {
                return(null);
            }
        }
        /// <summary> 查找所有到 指定条件时结束 </summary>
        public static List <T> FindAllEndOfMatch <T>(this BaseKey bk, Predicate <BaseKey> match, Predicate <BaseKey> endOfmatch) where T : class
        {
            List <T> findKeys = new List <T>();

            bk.GetKeys <T>(ref findKeys, bk, match, endOfmatch);

            return(findKeys);
        }
        /// <summary> 删除指定关键字同级所有关键字 isContainThis是否删除本节点 </summary>
        public static void ClearChildAfter(this BaseKey bk, bool isContainThis = true)
        {
            if (bk.ParentKey == null)
            {
                return;
            }

            int index = isContainThis ? bk.ParentKey.Keys.IndexOf(bk) + 1 : bk.ParentKey.Keys.IndexOf(bk);

            bk.ParentKey.RemoveRange(index);
        }
Beispiel #10
0
        /// <summary> 是否相等(只比较名称) </summary>
        public override bool Equals(object obj)
        {
            if (!(obj is BaseKey))
            {
                return(false);
            }

            BaseKey pKey = obj as BaseKey;

            return(pKey.ID.Equals(this.ID));
        }
        /// <summary> 查找指定井ming的注入模型起始时间 </summary>
        public DATES GetWellInjStartDate(BaseKey key, string wellName)
        {
            List <DATES> ds = key.FindAll <DATES>();

            if (ds != null)
            {
                return(this.GetWellInjStartDate(ds, wellName));
            }

            return(null);
        }
        /// <summary> 删除指定关键字后面所有关键字 </summary>
        public static void ClearAllAfter(this BaseKey bk, bool isContainThis = true)
        {
            if (bk.ParentKey == null)
            {
                return;
            }

            bk.ClearChildAfter(isContainThis);

            //  递归清理
            bk.ParentKey.ClearAllAfter();
        }
Beispiel #13
0
        /// <summary> 增加节点 注意: 此方法改变了原节点的父节点引用 </summary>
        public void Add(BaseKey key)
        {
            key.ParentKey = this;
            //  记录位置
            //this.Lines.Add(key.ID);
            this.keys.Add(key);

            key.baseFile = this.baseFile;

            // Todo :替换所有关键字文件
            key.Foreach(l => l.baseFile = this.baseFile);
        }
        /// <summary> 递归查找父节点 </summary>
        public static BaseKey FindParentKey(this BaseKey bk, Predicate <BaseKey> match)
        {
            if (match(bk))
            {
                return(bk);
            }

            if (bk.ParentKey == null)
            {
                return(null);
            }

            return(bk.ParentKey.FindParentKey(match));
        }
        /// <summary> 判断当前关键字的父关键字是否匹配 </summary>
        public static bool IsMatchParent <T>(this BaseKey sender) where T : ParentKey
        {
            var pk = sender.GetParentKey();

            if (pk == null)
            {
                return(false);
            }

            if (pk is T)
            {
                return(true);
            }

            return(false);
        }
 /// <summary> 递归查找指定节点的八大关键字 </summary>
 public static ParentKey GetParentKey(this BaseKey bk)
 {
     if (bk.ParentKey != null)
     {
         if (bk.ParentKey is ParentKey)
         {
             return(bk.ParentKey as ParentKey);
         }
         else
         {
             return(bk.ParentKey.GetParentKey());
         }
     }
     else
     {
         return(null);
     }
 }
Beispiel #17
0
        /// <summary> 替换对应节点的所有内容 </summary>
        public bool ExChangeData(BaseKey key)
        {
            //  删除本节点所有数据
            this.Keys.RemoveAll(l => true);

            if (key == null)
            {
                return(true);
            }

            ////  添加替换的数据
            //this.Keys.AddRange(key.Keys);

            foreach (var item in key.Keys)
            {
                this.Add(item);
            }

            return(true);
        }
Beispiel #18
0
        /// <summary> 写关键字  </summary>
        public virtual void WriteKey(StreamWriter writer)
        {
            BaseKey index = null;

            //  写本行
            foreach (var str in this.lines)

            {
                //Guid tempId;

                //if (!Guid.TryParse(str, out tempId))
                //{
                writer.WriteLine(str);
                //}
            }


            //  写子关键字
            foreach (BaseKey key in this.keys)
            {
                key.WriteKey(writer);
            }
        }
        /// <summary> 关闭所有内存镜像资源流(删除文件) </summary>
        public static void SetAllMmfDispose(this BaseKey key)
        {
            List <TableKey> finds = key.FindAll <TableKey>();

            finds.ForEach(l => l.Close());
        }
Beispiel #20
0
        /// <summary> 将本节点替换为指定节点 </summary>
        public void ReplaceTo(BaseKey key)
        {
            this.InsertBefore(key);

            this.Delete();
        }
Beispiel #21
0
 /// <summary> 增加节点 注意: 此方法改变了原节点的父节点引用 </summary>
 public void AddClone(BaseKey key)
 {
     this.keys.Add(key);
     key.baseFile = this.baseFile;
 }
Beispiel #22
0
 /// <summary> 查找指定关键字处的索引 </summary>
 public int FindIndex(BaseKey key)
 {
     return(this.keys.FindIndex(l => l == key));
 }
Beispiel #23
0
 /// <summary> 查找Key </summary>
 public BaseKey Find(BaseKey key)
 {
     return(this.Keys.Find(l => l.Equals(key)));
 }
Beispiel #24
0
 /// <summary> 移除 </summary>
 public void Delete(BaseKey key)
 {
     this.keys.Remove(key);
 }
Beispiel #25
0
        /// <summary> 读取关键字内容 (具体关键字读取方法不同)  return  用于关键字传递 </summary>
        public virtual BaseKey ReadKeyLine(StreamReader reader)
        {
            string tempStr = string.Empty;

            #region - 读取数据 -

            while (!reader.EndOfStream)
            {
                // HTodo  :读取数据要处理的方法 一般用来截取前面空格判断是否解析成关键字
                tempStr = this.eachLineCmdHandler(reader.ReadLine());

                try
                {
                    // HTodo  :当前关键字用来判断文本是否为关键字的方法
                    if (this.IsKeyChar(tempStr))
                    {
                        #region - 交接关键字 -

                        // Todo :没有找到主文件默认Eclipse关键字
                        SimKeyType typesim = this.baseFile == null ? SimKeyType.Eclipse : this.baseFile.SimKeyType;

                        BaseKey newKey = KeyConfigerFactroy.Instance.CreateKey <BaseKey>(tempStr, typesim);

                        LogProviderHandler.Instance.OnRunLog("", "正在读取关键字 - " + newKey.Name);

                        BaseKey perTempKey = this;

                        if (this._builderHandler != null)
                        {
                            // Todo :当碰到新关键字 触发本节点构建方法
                            BaseKey temp = this._builderHandler.Invoke(this, newKey);

                            if (temp != null)
                            {
                                perTempKey = temp;
                            }

                            if (this.baseFile != null && this is IProductTime)
                            {
                                // HTodo  :将读取到的生产信息记录到主文件中,用于解析TSTEP
                                IProductTime p = this as IProductTime;
                                this.baseFile.ReadTempTime = p.DateTime;
                            }
                        }

                        if (newKey._createrHandler != null)
                        {
                            // Todo :触发新关键字构建节点结构的方法
                            newKey._createrHandler.Invoke(perTempKey, newKey);
                        }


                        // Todo :读到未解析关键字触发事件
                        if (newKey is UnkownKey)
                        {
                            // Todo :触发事件
                            if (newKey.BaseFile != null && newKey.BaseFile.OnUnkownKey != null)
                            {
                                newKey.BaseFile.OnUnkownKey(newKey.BaseFile, newKey);
                            }
                        }


                        // Todo :开始读取新关键字
                        newKey.ReadKeyLine(reader);

                        #endregion
                    }
                    else
                    {
                        #region - 记录数据 -

                        if (tempStr.IsNotExcepLine())
                        {
                            if (this.ReadNewLineHandler == null)
                            {
                                // Todo :当前关键字没有实时读取方法
                                this.Lines.Add(tempStr);
                            }
                            else
                            {
                                // Todo :当前关键字实现实时读取方法
                                this.ReadNewLineHandler(tempStr);
                            }
                        }

                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    LogProviderHandler.Instance.OnErrLog("读取关键字" + this.GetType().Name + "错误!", ex);
                }
                finally
                {
                }
            }

            #endregion

            return(this);
        }