Example #1
0
 public static PushToMonitorService getInstance()
 {
     // - 命令参数不存在‘datatoservice’,不向本机的采集服务中推入数据。
     String[] args = Environment.GetCommandLineArgs();
     if (args == null)
     {
         return(null);
     }
     if (!Array.Exists(args, a => a != null && a.ToLower() == "datatoservice"))
     {
         return(null);
     }
     // - 暂时不做同步处理。
     if (_instance == null)
     {
         _instance = new PushToMonitorService();
     }
     return(_instance);
 }
Example #2
0
        private void Client_Error(MTConnectError.Document errorDocument)
        {
            if (errorDocument == null || errorDocument.Errors == null || errorDocument.Errors.Count < 1)
            {
                return;
            }
            Poco[] pocos = new Poco[errorDocument.Errors.Count];
            for (int i = 0; i < errorDocument.Errors.Count; i++)
            {
                pocos[i] = new Poco()
                {
                    Name      = "err:" + errorDocument.Header + ":" + errorDocument.Errors[i].ErrorCode,
                    Timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    Value     = errorDocument.Errors[i].CDATA
                };

                PushToMonitorService ptms = PushToMonitorService.getInstance();
                if (ptms != null)
                {
                    ptms.push(errorDocument.Errors[i].ErrorCode.ToString(), DateTime.Now, errorDocument.Errors[i].CDATA);
                }
            }
            putToLV(pocos);
        }
Example #3
0
        private void Client_CurrentReceived(MTConnectStreams.Document document)
        {
            if (document == null || document.DeviceStreams == null || document.DeviceStreams.Count < 1)
            {
                return;
            }
            LinkedList <Poco> pocos = new LinkedList <Poco>();

            foreach (MTConnectStreams.DeviceStream ds in document.DeviceStreams)
            {
                // 通过对 Name 的调整(去掉 di,ev,sp, cd)进行验证后,发现 DataItems 中包含了 Event 、 Samples、Conditions
                // ComponentStreams 比较杂,好像什么都包含,就不在这里验证了。
                // 因此在这里只保留了对 DataItems 的读取。
                string namePrefix = ds.Uuid + ":" + ds.Name + ":";
                if (ds.DataItems != null && ds.DataItems.Count > 0)
                {
                    foreach (MTConnect.MTConnectStreams.DataItem di in ds.DataItems)
                    {
                        pocos.AddLast(new Poco()
                        {
                            Device     = namePrefix,
                            Category   = di.Category.ToString(),
                            Sequence   = di.Sequence.ToString(),
                            SubType    = di.SubType,
                            DataItemId = di.DataItemId,
                            Name       = di.Name,
                            Timestamp  = di.Timestamp.ToString("yyyy-MM-dd HH:mm:ss:fff"),
                            Value      = di.CDATA
                        });


                        PushToMonitorService ptms = PushToMonitorService.getInstance();
                        if (ptms != null)
                        {
                            ptms.push(di.DataItemId + "_" + di.Name, di.Timestamp, di.CDATA);
                        }
                    }
                }

                // 经验证,这个节点特别像他的父节点,什么都包含。
                //if (ds.ComponentStreams != null && ds.ComponentStreams.Count > 0)
                //{
                //    foreach (MTConnect.MTConnectStreams.ComponentStream cs in ds.ComponentStreams)
                //    {
                //        pocos.AddLast(new Poco()
                //        {
                //            Name = namePrefix + cs.ComponentId + ":" + cs.Name + "-cs",
                //            Timestamp = cs.Samples .Timestamp.ToString("yyyy-MM-dd HH:mm:ss"),
                //            Value = di.CDATA
                //        });
                //    }
                //}

                //if (ds.Samples != null && ds.Samples.Count > 0)
                //{
                //    foreach (MTConnectStreams.Sample sp in ds.Samples)
                //    {
                //        pocos.AddLast(new Poco()
                //        {
                //            Name = namePrefix + sp.DataItemId + ":" + sp.Name + "-sp",
                //            Timestamp = sp.Timestamp.ToString("yyyy-MM-dd HH:mm:ss"),
                //            Value = sp.CDATA
                //        });
                //    }
                //}

                //if (ds.Events != null && ds.Events.Count > 0)
                //{
                //    foreach (MTConnectStreams.Event ev in ds.Events)
                //    {
                //        pocos.AddLast(new Poco()
                //        {
                //            Name = namePrefix + ev.DataItemId + ":" + ev.Name + "-di",
                //            Timestamp = ev.Timestamp.ToString("yyyy-MM-dd HH:mm:ss"),
                //            Value = ev.CDATA
                //        });
                //    }
                //}

                //if (ds.Conditions != null && ds.Conditions.Count > 0)
                //{
                //    foreach (MTConnect.MTConnectStreams.Condition di in ds.Conditions)
                //    {
                //        pocos.AddLast(new Poco()
                //        {
                //            Name = namePrefix + di.DataItemId + ":" + di.Name + "-cd",
                //            Timestamp = di.Timestamp.ToString("yyyy-MM-dd HH:mm:ss"),
                //            Value = di.CDATA
                //        });
                //    }
                //}
            }
            putToLV(pocos.ToArray());
        }