コード例 #1
0
ファイル: MnaPresenter.cs プロジェクト: id717890/mna.pna
 public void SetCurrentMna(Mna mna)
 {
     _model.CurrentMna = mna;
     _view.IsMnaNumber = mna.TagWithNumber;
 }
コード例 #2
0
ファイル: MnaPresenter.cs プロジェクト: id717890/mna.pna
 public void OnMnaChenged(Mna mna)
 {
     SetCurrentMna(mna);
 }
コード例 #3
0
ファイル: MnaPresenter.cs プロジェクト: id717890/mna.pna
        public void ReadConfig()
        {
            if (_isInit)
            {
                return;
            }
            List <Mna> model = new List <Mna>();

            if (Directory.Exists(AppSettings.AppFolder + "\\configs"))
            {
                if (File.Exists(AppSettings.AppFolder + CfgFile))
                {
                    var xdoc    = XDocument.Load(AppSettings.AppFolder + CfgFile);
                    var mnaList = xdoc.Element("sdku_reader")?.Element("to_object")?.Elements("object");
                    if (mnaList != null && mnaList.Any())
                    {
                        foreach (var mna in mnaList)
                        {
                            if (mna != null)
                            {
                                XAttribute captionMna  = mna.Attribute("caption");
                                XAttribute tagMna      = mna.Attribute("tag");
                                XAttribute positionMna = mna.Attribute("position");
                                if ((captionMna != null) && (tagMna != null) && (positionMna != null))
                                {
                                    var mnaItem = new Mna
                                    {
                                        Caption  = captionMna.Value,
                                        BaseTag  = tagMna.Value,
                                        Position = positionMna.Value,
                                        Id       = Guid.NewGuid()
                                    };

                                    XAttribute tagWithNumber = mna.Attribute("numeric");
                                    if (tagWithNumber != null && Boolean.Parse(tagWithNumber.Value))
                                    {
                                        mnaItem.TagWithNumber = true;
                                    }
                                    else
                                    {
                                        mnaItem.TagWithNumber = false;
                                    }

                                    #region Читаем раздел "ts_security"
                                    var tsSecurityInner = mna.Element("ts_security");
                                    if (tsSecurityInner != null)
                                    {
                                        var tsSecurityCaption = mna.Element("ts_security").Attribute("caption");
                                        var tsSecurityList    = mna.Element("ts_security").Elements("ts");
                                        var tsSecurity        = new List <Tag>();
                                        foreach (var ts in tsSecurityList)
                                        {
                                            if (ts != null)
                                            {
                                                XAttribute captionTag   = ts.Attribute("caption");
                                                XAttribute checkableTag = ts.Attribute("checkable");
                                                XAttribute textTag      = ts.Attribute("text");

                                                var nameTag = ts.Value;
                                                if ((captionTag != null) && (nameTag != null))
                                                {
                                                    Tag newTag = new Tag()
                                                    {
                                                        Caption  = captionTag.Value,
                                                        Name     = nameTag,
                                                        FullName = mnaItem.BaseTag + "." + nameTag
                                                    };
                                                    if (checkableTag != null && Boolean.Parse(checkableTag.Value))
                                                    {
                                                        newTag.Checkable = true;
                                                    }
                                                    else
                                                    {
                                                        newTag.Checkable = false;
                                                    }
                                                    if (textTag != null)
                                                    {
                                                        newTag.Text = textTag.Value;
                                                    }
                                                    tsSecurity.Add(newTag);
                                                }
                                            }
                                        }
                                        mnaItem.TsSecurity        = tsSecurity;
                                        mnaItem.TsSecurityCaption = tsSecurityCaption.Value;
                                    }
                                    #endregion

                                    #region Читаем раздел "ts_other"
                                    var tsOtherInner = mna.Element("ts_other");
                                    if (tsOtherInner != null)
                                    {
                                        var tsOtherCaption = mna.Element("ts_other").Attribute("caption");
                                        var tsOtherList    = mna.Element("ts_other").Elements("ts");
                                        var tsOther        = new List <Tag>();
                                        foreach (var ts in tsOtherList)
                                        {
                                            if (ts != null)
                                            {
                                                XAttribute captionTag   = ts.Attribute("caption");
                                                XAttribute checkableTag = ts.Attribute("checkable");
                                                XAttribute textTag      = ts.Attribute("text");

                                                var nameTag = ts.Value;
                                                if ((captionTag != null) && (nameTag != null))
                                                {
                                                    Tag newTag = new Tag()
                                                    {
                                                        Caption  = captionTag.Value,
                                                        Name     = nameTag,
                                                        FullName = mnaItem.BaseTag + "." + nameTag
                                                    };
                                                    if (checkableTag != null && Boolean.Parse(checkableTag.Value))
                                                    {
                                                        newTag.Checkable = true;
                                                    }
                                                    else
                                                    {
                                                        newTag.Checkable = false;
                                                    }
                                                    if (textTag != null)
                                                    {
                                                        newTag.Text = textTag.Value;
                                                    }
                                                    tsOther.Add(newTag);
                                                }
                                            }
                                        }
                                        mnaItem.TsOther        = tsOther;
                                        mnaItem.TsOtherCaption = tsOtherCaption.Value;
                                    }
                                    #endregion
                                    #region Читаем раздел "tu"
                                    var tuInner = mna.Element("tu_command");
                                    if (tuInner != null)
                                    {
                                        var tuCaption = mna.Element("tu_command").Attribute("caption");
                                        var tuList    = mna.Element("tu_command").Elements("tu");
                                        var tuCommand = new List <Tag>();
                                        foreach (var tu in tuList)
                                        {
                                            if (tu != null)
                                            {
                                                XAttribute captionTag = tu.Attribute("caption");
                                                XAttribute textTag    = tu.Attribute("text");

                                                var nameTag = tu.Value;
                                                if ((captionTag != null) && (nameTag != null))
                                                {
                                                    var newTag = new Tag()
                                                    {
                                                        Caption  = captionTag.Value,
                                                        Name     = nameTag,
                                                        FullName = mnaItem.BaseTag + "." + nameTag,
                                                        Id       = Guid.NewGuid()
                                                    };
                                                    if (textTag != null)
                                                    {
                                                        newTag.Text = textTag.Value;
                                                    }
                                                    tuCommand.Add(newTag);
                                                }
                                            }
                                        }
                                        mnaItem.Tu        = tuCommand;
                                        mnaItem.TuCaption = tuCaption.Value;
                                    }
                                    #endregion
                                    model.Add(mnaItem);
                                }
                            }
                        }
                        _isInit = true;
                        _model  = new MnaViewModel {
                            MnaList = model.OrderBy(x => x.Position), CurrentMna = model[0]
                        };
                        _view.SetModel(_model);
                        _view.IsMnaNumber = _model.CurrentMna.TagWithNumber;
                    }
                }
            }
        }