Beispiel #1
0
        protected virtual void SerialConfig(XmlElement rootElement, DcmDocument doc,
                                            XmlDocument xmlDoc)
        {
            var configElement = xmlDoc.CreateElement(DcmConfig.CfgElemName);

            rootElement.AppendChild(configElement);

            XmlUtils.AppendComment(configElement, xmlDoc, "Can Id设置");
            XmlUtils.AppendCanIdElement(configElement, xmlDoc,
                                        DcmConfig.PhysicalRequestIdElemName, doc.Config.PhysicalRequestId);
            XmlUtils.AppendCanIdElement(configElement, xmlDoc,
                                        DcmConfig.FunctionRequestidElemName, doc.Config.FunctionRequestId);
            XmlUtils.AppendCanIdElement(configElement, xmlDoc,
                                        DcmConfig.ResponseIdElemName, doc.Config.ResponseId);

            XmlUtils.AppendComment(configElement, xmlDoc, "安全访问设置");
            XmlUtils.AppendElement(configElement, xmlDoc,
                                   DcmConfig.SecurityAccessTypeElemName, doc.Config.SecurityAccessType);

            XmlUtils.AppendComment(configElement, xmlDoc, "下面是维持在线相关设置");
            XmlUtils.AppendElement(configElement, xmlDoc,
                                   DcmConfig.CanTickEnabledElemName, doc.Config.CanTickEnabled);
            XmlUtils.AppendElement(configElement, xmlDoc,
                                   DcmConfig.CanTickPeriodElemName, doc.Config.CanTickPeriod);
            XmlUtils.AppendElement(configElement, xmlDoc,
                                   DcmConfig.SuppressTickResponseElemName, doc.Config.SuppressTickResponse);
        }
Beispiel #2
0
        protected virtual void SerialSubFunction(XmlElement subFunctionsElem, SubFunction subFunction,
                                                 DcmDocument doc, XmlDocument xmlDoc)
        {
            var subFunctionElem = XmlUtils.CreateElement(subFunctionsElem, xmlDoc,
                                                         DcmConfig.SubFunctionElemName);

            XmlUtils.AppendElement(subFunctionElem, xmlDoc, DcmConfig.NameElemName,
                                   subFunction.Name);
            XmlUtils.AppendHexListElement(subFunctionElem, xmlDoc, DcmConfig.PrefixElemName,
                                          subFunction.Prefix);
            XmlUtils.AppendElement(subFunctionElem, xmlDoc, DcmConfig.TypeElemName,
                                   subFunction.DataType);
            XmlUtils.AppendElement(subFunctionElem, xmlDoc, DcmConfig.LenElemName,
                                   subFunction.DataLen);
            XmlUtils.AppendElement(subFunctionElem, xmlDoc, DcmConfig.AddressElemName,
                                   subFunction.CanAddressType);

            if (subFunction.Message != null)
            {
                XmlUtils.AppendElement(subFunctionElem, xmlDoc, DcmConfig.MessageElemName,
                                       subFunction.Message);
            }

            if (subFunction.ParsingDirection != ParsingDirection.None)
            {
                XmlUtils.AppendElement(subFunctionElem, xmlDoc,
                                       DcmConfig.ParsingDirectionElemName, subFunction.ParsingDirection);
            }
        }
Beispiel #3
0
        public /*async*/ void LoadDocument(string configFile)
        {
            mainForm.SetInstStatus(string.Format("正在加载文档: [{0}]", configFile));

            bool   loadStatus = true;
            string errMsg     = null;

            // 这儿相对于普通版本是修改过的程序
            // 个人有点不太愿意编写.net 4.5之前的版本
            Task.Factory.StartNew(() =>
            {
                try
                {
                    dcmDocument = DcmConfig.DcmConfig.LoadFile(configFile);
                    mainForm.UpdateDcmDocument(dcmDocument);
                    DocumentFile = configFile;
                }
                catch (DcmConfig.DcmFileFormatException ex)
                {
                    loadStatus = false;
                    errMsg     = ex.Message;
                }
                finally
                {
                    onLoadDocumentDone(loadStatus, configFile, errMsg);
                }
            } /*, TaskCreationOptions.LongRunning*/);
        }
Beispiel #4
0
        // 保存Vdf设置
        protected virtual void SerialVdf(XmlElement rootElement, DcmDocument doc,
                                         XmlDocument xmlDoc, string file)
        {
            var vdfElement = xmlDoc.CreateElement(DcmConfig.VdfElemName);

            if (string.IsNullOrEmpty(doc.VdfFile))
            {
                doc.VdfFile = Path.GetFileNameWithoutExtension(file) + "Vdf.xml";
            }

            vdfElement.SetAttribute(DcmConfig.FileAttrName, doc.VdfFile);
            rootElement.AppendChild(vdfElement);

            // 保存vdfw文档
            if (doc.VdfDocument != null)
            {
                string fullPath = doc.VdfFile;

                if (!Path.IsPathRooted(doc.VdfFile)) //相对路径
                {
                    var dirName = Path.GetDirectoryName(file);
                    fullPath = Path.Combine(dirName, doc.VdfFile);
                }
                doc.VdfDocument.Save(fullPath);
            }
        }
Beispiel #5
0
        protected override void OnDeserialOK(DcmDocument doc,
                                             XmlDocument xmlDoc)
        {
            base.OnDeserialOK(doc, xmlDoc);

            // 内部缓存所有的VdfMessage
            var vdfDocument = doc.VdfDocument;

            if (vdfDocument == null)
            {
                return;
            }

            foreach (var service in doc.Services)
            {
                foreach (var subFunction in service.SubFunctions)
                {
                    if (!string.IsNullOrEmpty(subFunction.Message))
                    {
                        VdfMessage vdfMessage = vdfDocument.Message(subFunction.Message);
                        if (vdfMessage != null)
                        {
                            subFunction.VdfMessage = vdfMessage;
                        }
                    }
                }
            }
        }
        public DcmContentWindow(MainForm mainForm)
        {
            InitializeComponent();
            this.mainForm = mainForm;

            DcmDocument = null;
        }
Beispiel #7
0
 protected virtual void SerialService(XmlElement serviceElem, Service service,
                                      DcmDocument doc, XmlDocument xmlDoc)
 {
     XmlUtils.AppendElement(serviceElem, xmlDoc, DcmConfig.NameElemName,
                            service.Name);
     SerialSubFunctions(serviceElem, service, doc, xmlDoc);
 }
        protected override void OnBeforeParseDocument(DcmDocument doc, XmlDocument xmlDoc)
        {
            string filePath;

            doc.VdfDocument = DoParseVdf(xmlDoc, out filePath);
            doc.VdfFile     = filePath;
        }
Beispiel #9
0
 internal void New()
 {
     mainForm.ClearAllToolWindow();
     dcmDocument  = new DcmDocument();
     DocumentFile = null;
     mainForm.UpdateDcmDocument(dcmDocument);
     mainForm.OnLoadDocumentDone(null, true);
 }
Beispiel #10
0
        protected virtual void SerialSubFunctions(XmlElement serviceElem, Service service,
                                                  DcmDocument doc, XmlDocument xmlDoc)
        {
            var subFunctionsElem = XmlUtils.CreateElement(serviceElem, xmlDoc, DcmConfig.SubFunctionsElemName);

            foreach (var subFunction in service.SubFunctions)
            {
                SerialSubFunction(subFunctionsElem, subFunction, doc, xmlDoc);
            }
        }
Beispiel #11
0
 public static void Save(DcmDocument document, string file)
 {
     try
     {
         DoSave(document, file);
     }
     catch (DcmFileFormatException)
     {
         document.Version = CurrVersion;
         DoSave(document, file);
     }
 }
Beispiel #12
0
        private static void DoSave(DcmDocument document, string file)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", "utf-8", ""));

            DcmDocumentSerializer serializer = GetSerializer(document.Version);

            serializer.Serial(document, xmlDoc, file);

            xmlDoc.Save(file);
        }
Beispiel #13
0
        protected virtual void SerialRoot(DcmDocument doc, XmlDocument xmlDoc, string file)
        {
            // 保存根
            var element = xmlDoc.CreateElement(DcmConfig.ConfigElemName);

            element.SetAttribute(DcmConfig.ConfigVersionAttrName, DcmConfig.CurrVersion);
            xmlDoc.AppendChild(element);

            SerialVdf(element, doc, xmlDoc, file);   //保存Vdf
            SerialConfig(element, doc, xmlDoc);      //保存配置
            SerialServices(element, doc, xmlDoc);    //保存所有服务
        }
Beispiel #14
0
        public virtual void DoParseCfg(DcmDocument doc, XmlNode cfgNode)
        {
            doc.Config = new Config();
            var cfg = doc.Config;

            // 解析CAN ID
            XmlNode node = cfgNode.SelectSingleNode(DcmConfig.PhysicalRequestIdElemName);
            int     ival;

            if (TryGetHexIntInnerText(node, out ival))
            {
                cfg.PhysicalRequestId = ival;
            }

            node = cfgNode.SelectSingleNode(DcmConfig.FunctionRequestidElemName);
            if (TryGetHexIntInnerText(node, out ival))
            {
                cfg.FunctionRequestId = ival;
            }

            node = cfgNode.SelectSingleNode(DcmConfig.ResponseIdElemName);
            if (TryGetHexIntInnerText(node, out ival))
            {
                cfg.ResponseId = ival;
            }

            node = cfgNode.SelectSingleNode(DcmConfig.SecurityAccessTypeElemName);
            if (node != null)
            {
                cfg.SecurityAccessType = node.InnerText.Trim();
            }

            node = cfgNode.SelectSingleNode(DcmConfig.CanTickEnabledElemName);
            bool bval;

            if (TryGetBoolInnerText(node, out bval))
            {
                cfg.CanTickEnabled = bval;
            }

            node = cfgNode.SelectSingleNode(DcmConfig.CanTickPeriodElemName);
            if (TryGetIntInnerText(node, out ival))
            {
                cfg.CanTickPeriod = ival;
            }

            node = cfgNode.SelectSingleNode(DcmConfig.SuppressTickResponseElemName);
            if (TryGetBoolInnerText(node, out bval))
            {
                cfg.SuppressTickResponse = bval;
            }
        }
        public DcmDocument Deserial(XmlDocument xmlDoc)
        {
            DcmDocument doc = new DcmDocument();

            OnBeforeParseDocument(doc, xmlDoc);

            var elems = xmlDoc.GetElementsByTagName(DcmConfig.ServicesElemName);

            doc.Services = doParseServices(elems);

            OnDeserialOK(doc, xmlDoc);
            return(doc);
        }
Beispiel #16
0
        protected override void OnBeforeParseDocument(DcmDocument doc, XmlDocument xmlDoc)
        {
            base.OnBeforeParseDocument(doc, xmlDoc);

            // 解析配置
            XmlNode node = xmlDoc.SelectSingleNode(DcmConfig.ConfigElemName + "/" +
                                                   DcmConfig.CfgElemName);

            if (node != null)
            {
                DoParseCfg(doc, node);
            }
        }
Beispiel #17
0
        protected virtual void SerialServices(XmlElement rootElement, DcmDocument doc,
                                              XmlDocument xmlDoc)
        {
            var servicesElem = XmlUtils.CreateElement(rootElement, xmlDoc,
                                                      DcmConfig.ServicesElemName);

            foreach (var service in doc.Services)
            {
                var serviceElem = XmlUtils.CreateElement(servicesElem, xmlDoc,
                                                         DcmConfig.ServiceElemName);
                SerialService(serviceElem, service, doc, xmlDoc);
            }
        }
 protected virtual void OnDeserialOK(DcmDocument doc,
                                     XmlDocument xmlDoc)
 {
 }
 protected virtual void OnBeforeParseDocument(DcmDocument doc, XmlDocument xmlDoc)
 {
 }
Beispiel #20
0
 // 之前的版本都没有实现保存功能,当前版本才进行实现
 public override void Serial(DcmDocument doc, XmlDocument xmlDoc, string file)
 {
     SerialRoot(doc, xmlDoc, file);        //保存根部
 }
 public virtual void Serial(DcmDocument doc, XmlDocument xmlDoc, string file)
 {
     throw new NotImplementedException();
 }