示例#1
0
        public XmlNode GenerateXmlNode()
        {
            XmlDocument xml  = new XmlDocument();
            XmlNode     root = xml.CreateElement("PLC");

            root.Attributes.Append(XMLHelper.CreateAttribute(xml, "IPAddress", IPAddress));
            root.Attributes.Append(XMLHelper.CreateAttribute(xml, "Rack", Rack.ToString()));
            root.Attributes.Append(XMLHelper.CreateAttribute(xml, "Slot", Slot.ToString()));
            return(root);
        }
示例#2
0
        public XmlNode GenerateXmlNode()
        {
            XmlDocument xml  = new XmlDocument();
            XmlNode     node = xml.CreateElement("Tag");

            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", Name));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "DataType", DataType.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "Type", Type.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "Offset", Offset));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "Length", length));

            return(node);
        }
示例#3
0
        public XmlNode GenerateXmlNode()
        {
            XmlDocument xml  = new XmlDocument();
            XmlNode     node = xml.CreateElement("ProductionLine");

            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", Name));

            foreach (DeviceEntity device in Devices)
            {
                node.AppendChild(xml.ImportNode(device.GenerateXmlNode(), true));
            }

            return(node);
        }
示例#4
0
        public XmlNode GenerateXmlNode()
        {
            XmlDocument xml  = new XmlDocument();
            XmlNode     node = xml.CreateElement("SubTagGroup");

            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "Prefix", prefix));

            foreach (TagEntity tag in Tags)
            {
                node.AppendChild(xml.ImportNode(tag.GenerateXmlNode(), true));
            }

            return(node);
        }
示例#5
0
        public XmlNode GenerateXmlNode()
        {
            XmlDocument xml  = new XmlDocument();
            XmlNode     node = xml.CreateElement("TagGroup");

            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", Name));

            foreach (TagEntity tag in Tags)
            {
                node.AppendChild(xml.ImportNode(tag.GenerateXmlNode(), true));
            }
            foreach (SubGroupEntity sgroup in SubGroups)
            {
                node.AppendChild(xml.ImportNode(sgroup.GenerateXmlNode(), true));
            }

            return(node);
        }
示例#6
0
        public XmlNode GenerateXmlNode()
        {
            XmlDocument xml  = new XmlDocument();
            XmlNode     node = xml.CreateElement("Device");

            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", Name));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "T133LeafID", T133LeafID.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "T216LeafID", T216LeafID.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "T107LeafID", T107LeafID.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "PLCType", PLCType.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "DBType", DBType.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "DBNumber", DBNumber.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "CycleReadMode", CycleReadMode.ToString()));
            node.Attributes.Append(XMLHelper.CreateAttribute(xml, "SplitterTime", SplitterTime.ToString()));

            node.AppendChild(xml.ImportNode(BelongPLC.GenerateXmlNode(), true));
            foreach (GroupEntity group in Groups)
            {
                node.AppendChild(xml.ImportNode(group.GenerateXmlNode(), true));
            }

            return(node);
        }
示例#7
0
        public void Save(string filename)
        {
            try
            {
                XmlDocument doc      = XMLHelper.CreateXmlDocument("Topology");
                XmlNode     rootNode = doc.LastChild;

                #region Parameter Section
                XmlNode paramsNode = XMLHelper.CreateChildNode(rootNode, "Parameters");
                foreach (OctopusLib.Parameter param in ParameterCollection)
                {
                    XmlNode paramNode = XMLHelper.CreateChildNode(paramsNode, "Parameter");
                    XMLHelper.CreateAttribute(paramNode, "Name", param.Name);
                    XMLHelper.CreateAttribute(paramNode, "Value", param.IsEncrypted ? Encryption.Encrypt(param.Value, _machineId) : param.Value);
                    if (param.IsEncrypted)
                    {
                        XMLHelper.CreateAttribute(paramNode, "IsEncrypted", param.IsEncrypted.ToString());
                    }
                }
                #endregion

                #region Machine Section
                XmlNode machinesNode = XMLHelper.CreateChildNode(rootNode, "Machines");
                foreach (OctopusLib.Machine machine in MachineCollection)
                {
                    XmlNode machineNode = XMLHelper.CreateChildNode(machinesNode, "Machine");
                    XMLHelper.CreateAttribute(machineNode, "Name", machine.Name);
                    XMLHelper.CreateAttribute(machineNode, "IP", machine.IP);
                    XMLHelper.CreateAttribute(machineNode, "Username", machine.Username);
                    XMLHelper.CreateAttribute(machineNode, "Password", Regex.IsMatch(machine.Password, @"{%(.+?)%}") ? machine.Password : Encryption.Encrypt(machine.Password, _machineId));
                    XMLHelper.CreateAttribute(machineNode, "Domain", machine.Domain);
                    XMLHelper.CreateAttribute(machineNode, "Architecture", machine.Architecture.ToString());
                    XMLHelper.CreateAttribute(machineNode, "IsLinux", machine.IsLinux.ToString());
                }
                #endregion

                #region Action Section
                XmlNode actionsNode = XMLHelper.CreateChildNode(rootNode, "Actions");
                foreach (OctopusLib.Action action in ActionCollection)
                {
                    XmlNode actionNode = XMLHelper.CreateChildNode(actionsNode, "Action");
                    XMLHelper.CreateAttribute(actionNode, "Name", action.Name);
                    foreach (OctopusLib.Command command in action.ActionCommands.OrderBy(o => o.Sequence))
                    {
                        XmlNode cmdNode = XMLHelper.CreateChildNode(actionNode, "Command");
                        XMLHelper.CreateAttribute(cmdNode, "Type", command.CommandType.ToString());
                        XMLHelper.CreateAttribute(cmdNode, "Try", command.Try.ToString());
                        XMLHelper.CreateAttribute(cmdNode, "IsEnabled", command.IsEnabled.ToString());
                        XMLHelper.CreateAttribute(cmdNode, "RetryTimes", command.RetryTimes.ToString());
                        XMLHelper.CreateAttribute(cmdNode, "RetryIntervalSeconds", command.RetryIntervalSeconds.ToString());
                        switch (command.CommandType)
                        {
                        case RunCommandType.Copy:
                            XMLHelper.CreateAttribute(cmdNode, "Direction", ((OctopusLib.CopyCommand)command).CopyDirection.ToString());
                            if (!string.IsNullOrEmpty(((OctopusLib.CopyCommand)command).CopySourceFiles))
                            {
                                XMLHelper.CreateAttribute(cmdNode, "SourceFiles", ((OctopusLib.CopyCommand)command).CopySourceFiles.ToString());
                            }
                            if (!string.IsNullOrEmpty(((OctopusLib.CopyCommand)command).CopySourceDir))
                            {
                                XMLHelper.CreateAttribute(cmdNode, "SourceDir", ((OctopusLib.CopyCommand)command).CopySourceDir.ToString());
                            }
                            XMLHelper.CreateAttribute(cmdNode, "TargetDir", ((OctopusLib.CopyCommand)command).CopyTargetDir.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "Force", ((OctopusLib.CopyCommand)command).IsForce.ToString());
                            break;

                        case RunCommandType.Remote:
                            XMLHelper.CreateAttribute(cmdNode, "ExpectedResult", ((OctopusLib.RemoteCommand)command).ExpectedResult.ToString());
                            if (!string.IsNullOrEmpty(((OctopusLib.RemoteCommand)command).WorkingDirectory))
                            {
                                XMLHelper.CreateAttribute(cmdNode, "WorkingDirectory", ((OctopusLib.RemoteCommand)command).WorkingDirectory.ToString());
                            }
                            XMLHelper.CreateAttribute(cmdNode, "Reboot", ((OctopusLib.RemoteCommand)command).IsRebootRequired.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "Interactive", ((OctopusLib.RemoteCommand)command).IsUIInteractive.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "NotLoadProfile", ((OctopusLib.RemoteCommand)command).IsNotLoadProfile.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "RunAsSystemAccount", ((OctopusLib.RemoteCommand)command).IsRunAsSystemAccount.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "RunAsLimittedUser", ((OctopusLib.RemoteCommand)command).IsRunAsLimittedUser.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "Terminate", ((OctopusLib.RemoteCommand)command).IsNotWaitForTerminate.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "Architecture", ((OctopusLib.RemoteCommand)command).Architecture.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "TimeOutSeconds", ((OctopusLib.RemoteCommand)command).TimeOutSeconds.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "RemoteRunAsUsername", string.IsNullOrEmpty(((OctopusLib.RemoteCommand)command).RemoteRunAsUsername) ? string.Empty : ((OctopusLib.RemoteCommand)command).RemoteRunAsUsername.ToString());
                            XMLHelper.CreateAttribute(cmdNode,
                                                      "RemoteRunAsPassword",
                                                      string.IsNullOrEmpty(((OctopusLib.RemoteCommand)command).RemoteRunAsPassword) ? string.Empty : Regex.IsMatch(((OctopusLib.RemoteCommand)command).RemoteRunAsPassword.ToString(), @"{%(.+?)%}") ?
                                                      ((OctopusLib.RemoteCommand)command).RemoteRunAsPassword.ToString() : Encryption.Encrypt(((OctopusLib.RemoteCommand)command).RemoteRunAsPassword.ToString(), _machineId));
                            XMLHelper.CreateAttribute(cmdNode, "OutputParameter", string.IsNullOrEmpty(((OctopusLib.RemoteCommand)command).OutputParameter) ? string.Empty : ((OctopusLib.RemoteCommand)command).OutputParameter.ToString());
                            cmdNode.InnerXml = System.Net.WebUtility.HtmlEncode(command.CommandText);
                            break;

                        case RunCommandType.Local:
                            XMLHelper.CreateAttribute(cmdNode, "IsSystemCommand", ((OctopusLib.LocalCommand)command).IsSystemCommand.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "ExpectedResult", ((OctopusLib.LocalCommand)command).ExpectedResult.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "Architecture", ((OctopusLib.LocalCommand)command).Architecture.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "TimeOutSeconds", ((OctopusLib.LocalCommand)command).TimeOutSeconds.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "OutputParameter", string.IsNullOrEmpty(((OctopusLib.LocalCommand)command).OutputParameter) ? string.Empty : ((OctopusLib.LocalCommand)command).OutputParameter.ToString());
                            cmdNode.InnerXml = System.Net.WebUtility.HtmlEncode(command.CommandText);
                            break;

                        case RunCommandType.LinuxSSH:
                            XMLHelper.CreateAttribute(cmdNode, "ExpectedResult", ((OctopusLib.LinuxSSHCommand)command).ExpectedResult == null ? string.Empty : ((OctopusLib.LinuxSSHCommand)command).ExpectedResult.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "ExpectedPrompt", ((OctopusLib.LinuxSSHCommand)command).ExpectedPrompt == null ? string.Empty : ((OctopusLib.LinuxSSHCommand)command).ExpectedPrompt.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "SSHType", ((OctopusLib.LinuxSSHCommand)command).SshType.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "TimeOutSeconds", ((OctopusLib.LinuxSSHCommand)command).TimeOutSeconds.ToString());
                            XMLHelper.CreateAttribute(cmdNode, "Reboot", ((OctopusLib.LinuxSSHCommand)command).IsRebootRequired.ToString());
                            if (!string.IsNullOrEmpty(command.CommandText))
                            {
                                cmdNode.InnerXml = System.Net.WebUtility.HtmlEncode(command.CommandText);
                            }
                            break;
                        }
                    }
                }
                #endregion

                #region Task Section
                XmlNode runsNode = XMLHelper.CreateChildNode(rootNode, "Tasks");
                foreach (OctopusLib.Task task in TaskCollection.OrderBy(o => o.Sequence))
                {
                    XmlNode runNode = XMLHelper.CreateChildNode(runsNode, "Task");
                    XMLHelper.CreateAttribute(runNode, "Name", task.Name);
                    XMLHelper.CreateAttribute(runNode, "Sequence", task.Sequence.ToString());
                    XMLHelper.CreateAttribute(runNode, "IsEnabled", task.IsEnabled.ToString());

                    StringBuilder msb = new StringBuilder();
                    foreach (OctopusLib.Machine machine in task.Machines)
                    {
                        if (msb.Length == 0)
                        {
                            msb.Append(string.Format("{0}", machine.Name));
                        }
                        else
                        {
                            msb.Append(string.Format(",{0}", machine.Name));
                        }
                    }
                    XMLHelper.CreateAttribute(runNode, "Machine", msb.ToString());
                    foreach (OctopusLib.TaskAction taskAction in task.TaskActionCollection.OrderBy(o => o.Sequence))
                    {
                        XmlNode taskActionNode = XMLHelper.CreateChildNode(runNode, "TaskAction");
                        taskActionNode.InnerText = taskAction.Name;
                        if (taskAction.Machine != null)
                        {
                            XMLHelper.CreateAttribute(taskActionNode, "Machine", taskAction.Machine.Name.ToString());
                        }
                        XMLHelper.CreateAttribute(taskActionNode, "IsEnabled", taskAction.IsEnabled.ToString());
                        XMLHelper.CreateAttribute(taskActionNode, "Fixed", taskAction.IsFixed.ToString());
                    }
                }
                #endregion

                doc.Save(filename);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#8
0
        /// <summary>
        /// 生成需要新增的检验数据 XML 串
        /// </summary>
        private void GenerateNewRSFactXML()
        {
            XmlNode root = xmlRSFact.SelectSingleNode("RSFact");

            if (root == null)
            {
                root = xmlRSFact.CreateElement("RSFact");
                xmlRSFact.AppendChild(root);
            }

            int rowIdx = 1;

            foreach (DataRow dr in dtInspection.Rows)
            {
                EditStatus recordStatus = (EditStatus)dr["RecordStatus"];
                switch (recordStatus)
                {
                case EditStatus.New:
                case EditStatus.Edit:
                    #region 生成新增的 XML 节点
                    XmlNode rsfactNode = xmlRSFact.CreateElement("RF6_2");
                    root.AppendChild(rsfactNode);

                    for (int i = 0; i < inspectionItems.Count; i++)
                    {
                        XmlNode node = null;
                        if (i == 0)
                        {
                            node = rsfactNode;
                        }
                        else
                        {
                            node = xmlRSFact.CreateElement("RF6_2");
                            root.AppendChild(node);
                        }

                        node.Attributes.Append(
                            XMLHelper.CreateAttribute(
                                xmlRSFact,
                                "RowNum",
                                rowIdx.ToString()));
                        node.Attributes.Append(
                            XMLHelper.CreateAttribute(
                                xmlRSFact,
                                "Ordinal",
                                inspectionItems[i].Ordinal.ToString()));
                        node.Attributes.Append(
                            XMLHelper.CreateAttribute(
                                xmlRSFact,
                                "T20LeafID",
                                inspectionItems[i].T20LeafID.ToString()));
                        node.Attributes.Append(
                            XMLHelper.CreateAttribute(
                                xmlRSFact,
                                "LowLimit",
                                ""));
                        node.Attributes.Append(
                            XMLHelper.CreateAttribute(
                                xmlRSFact,
                                "Criterion",
                                ""));
                        node.Attributes.Append(
                            XMLHelper.CreateAttribute(
                                xmlRSFact,
                                "HighLimit",
                                ""));
                        node.Attributes.Append(
                            XMLHelper.CreateAttribute(
                                xmlRSFact,
                                "UnitOfMeasure",
                                inspectionItems[i].UnitOfMeasure));
                        node.Attributes.Append(
                            XMLHelper.CreateAttribute(
                                xmlRSFact,
                                "Metric01",
                                dr[string.Format(
                                       "Column{0}",
                                       inspectionItems[i].Ordinal)].ToString()));
                    }

                    rsfactNode.Attributes.Append(
                        XMLHelper.CreateAttribute(
                            xmlRSFact,
                            "IQCReport",
                            dr["AttachedFile"].ToString()));

                    rowIdx++;
                    #endregion

                    break;
                }
            }
        }
示例#9
0
        public void ExportToXml(string filePath)
        {
            XmlDocument xml = new XmlDocument();

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

            XmlNode root = xml.CreateElement("root");

            xml.AppendChild(root);

            XmlNode plcNode = null;

            if (PLCType == PLCType.SIEMENS)
            {
                plcNode = xml.CreateElement("SiemensPLC");
                plcNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "IPAddress", BelongPLC.IPAddress));
                plcNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Rack", BelongPLC.Rack));
                plcNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Slot", BelongPLC.Slot));
            }
            root.AppendChild(plcNode);

            XmlNode deviceNode = xml.CreateElement("Device");

            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", Name));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "T133LeafID", T133LeafID));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "T216LeafID", T216LeafID));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "T107LeafID", T107LeafID));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "DBType", DBType.ToString()));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "DBNumber", DBNumber));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "CycleReadMode", CycleReadMode.ToString()));
            deviceNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "SplitterTime", SplitterTime));

            foreach (GroupEntity group in Groups)
            {
                XmlNode groupNode = xml.CreateElement("TagGroup");
                groupNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", group.Name));

                foreach (TagEntity tag in group.Tags)
                {
                    XmlNode tagNode = xml.CreateElement("Tag");
                    tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", tag.Name));
                    tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Datatype", tag.DataType.ToString()));
                    if (tag.DataType == TagDataType.ArrayChar)
                    {
                        tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Length", tag.Length));
                    }
                    tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Offset", tag.Offset));
                    tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Type", tag.Type.ToString()));
                    groupNode.AppendChild(tagNode);
                }

                foreach (SubGroupEntity sgroup in group.SubGroups)
                {
                    XmlNode sgroupNode = xml.CreateElement("SubTagGroup");
                    sgroupNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Prefix", sgroup.Prefix));

                    foreach (TagEntity tag in sgroup.Tags)
                    {
                        XmlNode tagNode = xml.CreateElement("Tag");
                        tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", tag.Name));
                        tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Datatype", tag.DataType.ToString()));
                        if (tag.DataType == TagDataType.ArrayChar)
                        {
                            tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Length", tag.Length));
                        }
                        tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Offset", tag.Offset));
                        tagNode.Attributes.Append(XMLHelper.CreateAttribute(xml, "Type", tag.Type.ToString()));
                        sgroupNode.AppendChild(tagNode);
                    }

                    groupNode.AppendChild(sgroupNode);
                }

                deviceNode.AppendChild(groupNode);
            }

            plcNode.AppendChild(deviceNode);

            xml.Save(filePath);
        }