当前位置: 首页>>代码示例>>C#>>正文


C# NodeInfo.ToXml方法代码示例

本文整理汇总了C#中NodeInfo.ToXml方法的典型用法代码示例。如果您正苦于以下问题:C# NodeInfo.ToXml方法的具体用法?C# NodeInfo.ToXml怎么用?C# NodeInfo.ToXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NodeInfo的用法示例。


在下文中一共展示了NodeInfo.ToXml方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemainJobCount

        public int RemainJobCount(string taskName)
        {
            int listenPort = SocketHelper.FindSuitablePort(6600, 6699);
            if (listenPort == 0)
            {
                Console.WriteLine("Can not found suitable soket port from 6600 to 6699 to submit job");
                return -1;
            }

            try
            {
                using (UdpClient receiver = new UdpClient(listenPort))
                using (UdpClient sernder = new UdpClient())
                {
                    try
                    {
                        lock (_syncOnXmlDataObject)
                        {
                            _receivedXmlData = null;
                        }

                        receiver.BeginReceive(new AsyncCallback(AsyncReceivePackage), receiver);

                        XmlDocument dom = new XmlDocument();
                        XmlElement ele = dom.CreateElement(MessageType.JobManage.ToString());
                        ele.SetAttribute("command", CommandType.JobQuery.ToString());
                        if (!string.IsNullOrEmpty(taskName))
                        {
                            ele.SetAttribute("taskName", taskName);
                        }

                        NodeInfo ni = new NodeInfo();
                        ni.Name = System.Environment.MachineName;
                        ni.IP = SocketHelper.LocalIP;
                        ni.Port = listenPort;

                        XmlElement nodeEle = ni.ToXml(dom);
                        ele.AppendChild(nodeEle);

                        ProcessNode.SendMessage(sernder, ele.OuterXml, ServerIP, ServerPort);

                        TimeSpan duration = new TimeSpan(0, 0, 3);
                        DateTime startTime = DateTime.Now;
                        while (true)
                        {
                            Thread.Sleep(100);
                            lock (_syncOnXmlDataObject)
                            {
                                if (_receivedXmlData != null)
                                {
                                    break;
                                }
                            }

                            if (DateTime.Now.Ticks - startTime.Ticks > duration.Ticks)
                            {
                                break;
                            }
                        }
                    }
                    finally
                    {
                        ProcessNode.SendMessage(sernder,
                            BasicSignal.QuitUdpSocket.ToString(),
                            SocketHelper.LocalIP, listenPort);
                        Thread.Sleep(200);
                    }
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine(e.ToString());
                return -1;
            }

            if (_receivedXmlData != null &&
                _receivedXmlData.LastIndexOf(BasicSignal.QuitUdpSocket.ToString(), StringComparison.OrdinalIgnoreCase) < 0)
            {
                try
                {
                    XmlDocument dom = new XmlDocument();
                    dom.LoadXml(_receivedXmlData);

                    // query returned
                    int nonScheduled = int.Parse(dom.DocumentElement.GetAttribute("non-scheduled"),
                        CultureInfo.InvariantCulture);
                    int running = int.Parse(dom.DocumentElement.GetAttribute("running"),
                        CultureInfo.InvariantCulture);
                    int dispatched = int.Parse(dom.DocumentElement.GetAttribute("dispatched"),
                        CultureInfo.InvariantCulture);

                    return nonScheduled + running + dispatched;
                }
                catch (XmlException e)
                {
                    Console.WriteLine("RemainJobCount error on message {0}", _receivedXmlData);
                    Console.WriteLine(e.ToString());
                    return -1;
                }
            }
//.........这里部分代码省略.........
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:101,代码来源:CommandLineSubmitter.cs

示例2: ToXml

        /// <summary>
        /// Convert this object into XML presentation.
        /// </summary>
        /// <param name="nodeInfo">Node info.</param>
        /// <returns>XML string.</returns>
        public string ToXml(NodeInfo nodeInfo)
        {
            if (nodeInfo == null)
            {
                throw new ArgumentNullException("nodeInfo");
            }

            XmlDocument dom = new XmlDocument();
            XmlElement ele = dom.CreateElement(MessageType.Control.ToString());

            ele.SetAttribute("command", Command);
            ele.SetAttribute("guid", Guid);

            if (!string.IsNullOrEmpty(Result))
            {
                ele.SetAttribute("result", Result);
            }

            if (nodeInfo != null)
            {
                XmlElement subNodeInfo = nodeInfo.ToXml(dom);
                ele.AppendChild(subNodeInfo);
            }

            return ele.OuterXml;
        } 
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:31,代码来源:ControlMessage.cs


注:本文中的NodeInfo.ToXml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。