Exemplo n.º 1
0
        public static TagItemModel Convert(
            this Tag tag,
            bool withSEO = false
            )
        {
            var _return = new TagItemModel()
            {
                Id   = tag.Id,
                Name = tag.Name,
                URL  = tag.URL
            };

            if (withSEO)
            {
                _return.SeoTitle       = tag.SeoTitle;
                _return.SeoKeyword     = tag.SeoKeyword;
                _return.SeoDescription = tag.SeoDescription;
            }
            return(_return);
        }
Exemplo n.º 2
0
        public static void StartClient()
        {
            LogPath = ConfigurationManager.AppSettings["LogAddress"];
            if (!Directory.Exists(LogPath))
            {
                Directory.CreateDirectory(LogPath);
            }
            LogQueue.Enqueue("StartClient");
            if (dtTags == null)
            {
                var bllTags = new BllMachineTagList();
                dtTags = bllTags.GetAllTags();
            }
            var serverAddress  = ConfigurationManager.AppSettings["ServerAddress"];
            var serverNameList = dtTags.AsEnumerable().Select(dr => dr["ServerAddress"].ToString()).Distinct().ToList();

            ClientList.EnqueueRec   += client_EnqueueRec;
            ClientList.EnqueueLog   += client_EnqueueLog;
            ClientList.ServerAddress = serverAddress + "/" + serverNameList.First();
            ClientList.ConnectServer();
            ClientList.AddItems(dtTags.AsEnumerable().Select(dr => dr["DeviceName"].ToString()).Distinct().ToArray());
            ClientList.StartRead();

            ThreadPool.QueueUserWorkItem(w =>
            {
                while (_isRun)
                {
                    if (LogQueue.Count > 0)
                    {
                        var log = LogQueue.Dequeue();
                        File.AppendAllText(LogPath + "\\Log" + DateTime.Now.ToString("yyyyMMdd") + ".txt",
                                           "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") + "]" + log + "\r\n");
                    }
                    Thread.Sleep(100);
                }
            });



            ThreadPool.QueueUserWorkItem(w =>
            {
                while (_isRun)
                {
                    if (RecQueue.Count > 0)
                    {
                        lock (MLock)
                        {
                            var rec = RecQueue.Dequeue();
                            for (var i = 0; i < rec.Length / 5; i++)
                            {
                                var key = rec[i, 4].ToString();
                                if (ItemTable.ContainsKey(key))
                                {
                                    var tag = ItemTable[key] as TagItemModel;
                                    if (tag == null)
                                    {
                                        ItemTable[key] = new TagItemModel
                                        {
                                            Key       = key,
                                            Name      = rec[i, 0].ToString(),
                                            Value     = rec[i, 1],
                                            TimeStamp = (DateTime)rec[i, 2],
                                            Quality   = rec[i, 3].ToString()
                                        };
                                    }
                                    else
                                    {
                                        tag.Name      = rec[i, 0].ToString();
                                        tag.Value     = rec[i, 1];
                                        tag.TimeStamp = (DateTime)rec[i, 2];
                                        tag.Quality   = rec[i, 3].ToString();
                                    }
                                }
                                else
                                {
                                    ItemTable.Add(key, new TagItemModel
                                    {
                                        Key       = key,
                                        Name      = rec[i, 0].ToString(),
                                        Value     = rec[i, 1],
                                        TimeStamp = (DateTime)rec[i, 2],
                                        Quality   = rec[i, 3].ToString()
                                    });
                                }
                            }
                        }
                    }
                    Thread.Sleep(100);
                }
            });


            //_Client.ConnectServer();


            //_Client.Connect("123.57.57.171", "8081", "IODriver");
            //_Client.Groups.Add("test", 1000);
            //var items = _Client.BrownseAllTags();
            //foreach (var smartItem in items)
            //{
            //    ItemTable.Add(smartItem.SmartItemKey, new TagItemModel
            //    {
            //        Desc = smartItem.Description,
            //        Key = smartItem.SmartItemKey,
            //        Name = smartItem.Name,
            //        Quality = smartItem.Quality,
            //        TimeStamp = smartItem.TimeStamp,
            //        Value = smartItem.Value,
            //        ValueIsChanged = smartItem.IsChanged,
            //        ValueType = smartItem.ValueType
            //    });
            //    _Client.Groups[0].Items.Add(smartItem.SmartItemKey);
            //}


            //opcThread = new Thread(start =>
            //{
            //    while (_IsRun)
            //    {
            //        try
            //        {
            //            for (var i = 0; i < _Client.Groups[0].Items.Count; i++)
            //            {
            //                var key = _Client.Groups[0].Items[i].SmartItemKey;
            //                var tag = ItemTable[key] as TagItemModel;
            //                tag.Value = _Client.Groups[0].Items[i].Value;
            //                tag.TimeStamp = _Client.Groups[0].Items[i].TimeStamp;
            //                tag.Quality = _Client.Groups[0].Items[i].Quality;
            //            }
            //        }
            //        catch (Exception ex)
            //        {

            //        }
            //        Thread.Sleep(1000);
            //    }
            //});
            //_IsRun = true;
            //opcThread.Start();
        }