コード例 #1
0
        private MTConnect.Application.Streams.ReturnData GetCurrent(Data.AgentInfo config)
        {
            MTConnect.Application.Streams.ReturnData result = null;

            string address    = config.Address;
            int    port       = config.Port;
            string deviceName = config.DeviceName;

            // Set Proxy Settings
            var proxy = new HTTP.ProxySettings();

            proxy.Address = config.ProxyAddress;
            proxy.Port    = config.ProxyPort;

            DateTime requestTimestamp = DateTime.Now;

            string url = HTTP.GetUrl(address, port, deviceName) + "current";

            result = MTConnect.Application.Streams.Requests.Get(url, proxy, 2000, 1);
            if (result != null)
            {
                if (verbose)
                {
                    Logger.Log("Current Successful : " + url + " @ " + requestTimestamp.ToString("o") + " : " + result.Header.LastSequence, LogLineType.Console);
                }
            }
            else
            {
                Logger.Log("Current Error : " + url + " @ " + requestTimestamp.ToString("o") + " : Retrying in " + (config.Heartbeat / 1000) + " sec..");
            }

            return(result);
        }
コード例 #2
0
        private MTConnectStreams.Document GetCurrent(Data.AgentInfo config)
        {
            MTConnectStreams.Document result = null;

            string address    = config.Address;
            int    port       = config.Port;
            string deviceName = config.DeviceName;

            //// Set Proxy Settings
            //var proxy = new HTTP.ProxySettings();
            //proxy.Address = config.ProxyAddress;
            //proxy.Port = config.ProxyPort;

            DateTime requestTimestamp = DateTime.Now;

            // Create Agent Url
            var protocol = "http://";
            var adr      = address;

            if (adr.IndexOf(protocol) >= 0)
            {
                adr = adr.Substring(protocol.Length);
            }
            else
            {
                adr = protocol + adr;
            }
            var url = adr;

            if (port > 0 && port != 80)
            {
                url += ":" + port;
            }

            // Send Probe Request
            var current = new MTConnect.Clients.Current(url, deviceName);

            result = current.Execute();
            if (result != null)
            {
                if (verbose)
                {
                    logger.Info("Current Successful : " + url + " @ " + requestTimestamp.ToString("o") + " : " + result.Header.LastSequence);
                }
            }
            else
            {
                logger.Info("Current Error : " + url + " @ " + requestTimestamp.ToString("o") + " : Retrying in " + (config.Heartbeat / 1000) + " sec..");
            }

            return(result);
        }
コード例 #3
0
        private MTConnect.Application.Streams.ReturnData GetSample(Streams header, Data.AgentInfo ac, DeviceConfiguration config)
        {
            MTConnect.Application.Streams.ReturnData result = null;

            string address    = ac.Address;
            int    port       = ac.Port;
            string deviceName = ac.DeviceName;

            // Set Proxy Settings
            var proxy = new HTTP.ProxySettings();

            proxy.Address = ac.ProxyAddress;
            proxy.Port    = ac.ProxyPort;

            SampleInfo info = GetSampleInfo(header, config);

            if (info != null)
            {
                if (info.Count > 0)
                {
                    DateTime requestTimestamp = DateTime.Now;

                    string url = HTTP.GetUrl(address, port, deviceName) + "sample?from=" + info.From.ToString() + "&count=" + info.Count.ToString();

                    result = MTConnect.Application.Streams.Requests.Get(url, proxy, ac.Heartbeat / 2, 2);
                    if (result != null)
                    {
                        UpdateAgentData(header.InstanceId, info.From + info.Count);

                        if (verbose)
                        {
                            Logger.Log("Sample Successful : " + url + " @ " + requestTimestamp.ToString("o"), LogLineType.Console);
                        }
                    }
                    else
                    {
                        Logger.Log("Sample Error : " + url + " @ " + requestTimestamp.ToString("o"));
                    }
                }
                else
                {
                    UpdateAgentData(header.InstanceId, header.LastSequence);
                }
            }

            return(result);
        }
コード例 #4
0
        private static Data.AgentInfo ProcessAgent(XmlNode Node)
        {
            var result = new Data.AgentInfo();

            foreach (XmlNode child in Node.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Element)
                {
                    if (child.InnerText != "")
                    {
                        Type         Settings = typeof(Data.AgentInfo);
                        PropertyInfo info     = Settings.GetProperty(child.Name);

                        if (info != null)
                        {
                            Type t = info.PropertyType;
                            info.SetValue(result, Convert.ChangeType(child.InnerText, t), null);
                        }
                    }
                }
            }

            return(result);
        }
コード例 #5
0
        private MTConnectStreams.Document GetSample(MTConnect.Headers.MTConnectStreamsHeader header, Data.AgentInfo ac, DeviceConfiguration config)
        {
            MTConnectStreams.Document result = null;

            string address    = ac.Address;
            int    port       = ac.Port;
            string deviceName = ac.DeviceName;

            //// Set Proxy Settings
            //var proxy = new HTTP.ProxySettings();
            //proxy.Address = ac.ProxyAddress;
            //proxy.Port = ac.ProxyPort;

            SampleInfo info = GetSampleInfo(header, config);

            if (info != null)
            {
                if (info.Count > 0)
                {
                    DateTime requestTimestamp = DateTime.Now;

                    // Create Agent Url
                    var protocol = "http://";
                    var adr      = address;
                    if (adr.IndexOf(protocol) >= 0)
                    {
                        adr = adr.Substring(protocol.Length);
                    }
                    else
                    {
                        adr = protocol + adr;
                    }
                    var url = adr;
                    if (port > 0 && port != 80)
                    {
                        url += ":" + port;
                    }

                    // Send Probe Request
                    var sample = new MTConnect.Clients.Sample(url, deviceName);
                    sample.From  = info.From;
                    sample.Count = info.Count;
                    result       = sample.Execute();
                    if (result != null)
                    {
                        UpdateAgentData(header.InstanceId, info.From + info.Count);

                        if (verbose)
                        {
                            logger.Info("Sample Successful : " + url + " @ " + requestTimestamp.ToString("o"));
                        }
                    }
                    else
                    {
                        logger.Info("Sample Error : " + url + " @ " + requestTimestamp.ToString("o"));
                    }
                }
                else
                {
                    UpdateAgentData(header.InstanceId, header.LastSequence);
                }
            }

            return(result);
        }