Ejemplo n.º 1
0
        /// <summary>
        /// 启动服务。
        /// </summary>
        protected override void OnStart(string[] args)
        {
            _evnetLog.WriteEntry("Astronergy.MES.IVTest.Service服务启动");
            //获取配置节信息
            this._section = (IVTestConfigurationSection)ConfigurationManager.GetSection("ivtest");
            string sleepTime = System.Configuration.ConfigurationManager.AppSettings["SLEEP_TIME"];

            if (!string.IsNullOrEmpty(sleepTime))
            {
                _sleepTime = Convert.ToInt32(sleepTime);
            }
            //增加线程个数。
            foreach (DeviceElement element in this._section.Devices)
            {
                ParameterizedThreadStart        threadStart = new ParameterizedThreadStart(TransferData);
                IVTestDataTransferThreadWrapper wrapper     = new IVTestDataTransferThreadWrapper(element, threadStart);
                lstWrapper.Add(wrapper);
            }
            //启动线程。
            foreach (IVTestDataTransferThreadWrapper wrapper in lstWrapper)
            {
                Thread.Sleep(100);
                wrapper.Start();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 数据转置
        /// </summary>
        private void TransferData(object obj)
        {
            IVTestDataTransferThreadWrapper wrapper = obj as IVTestDataTransferThreadWrapper;

            if (wrapper == null)
            {
                return;
            }
            TransferData(wrapper);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 数据转置
 /// </summary>
 private void TransferData(IVTestDataTransferThreadWrapper wrapper)
 {
     while (wrapper.Loop)
     {
         try
         {
             DeviceElement device          = wrapper.Device;
             DateTime      dtStartTime     = DateTime.Now;
             string        strFileFullName = DataTransfer.GetFullFile(device.Path, device.Format);
             string        msg             = string.Empty;
             if (!string.IsNullOrEmpty(strFileFullName))
             {
                 string       accConString = string.Format(ACCESS_STRING, strFileFullName);
                 string       sqlConString = SQLSERVER_STRING;
                 DataTransfer sdgData      = new DataTransfer(accConString, sqlConString);
                 sdgData.AccessToSqlServer(device.Name, device.Type, string.Empty);
                 DateTime dtEndTime = DateTime.Now;
                 if (sdgData.TransferCount > 0)
                 {
                     msg = string.Format("开始时间:{0};结束时间:{1};耗用时间:{2}秒;转置数据数量:{3}。{4}",
                                         dtStartTime, dtEndTime, (dtEndTime - dtStartTime).TotalSeconds, sdgData.TransferCount, strFileFullName
                                         );
                     _evnetLog.WriteEntry(msg);
                 }
             }
             else
             {
                 msg = string.Format("开始时间:{0};获取ACCESS数据库文件失败。", dtStartTime);
                 _evnetLog.WriteEntry(msg);
             }
         }
         catch (Exception ex)
         {
             _evnetLog.WriteEntry(ex.Message, EventLogEntryType.Error);
         }
         if (wrapper.Loop)
         {
             Thread.Sleep(_sleepTime);
         }
     }
     wrapper.AutoResetEvent.Set();
 }