示例#1
0
 /// <summary>
 /// 启动服务。
 /// </summary>
 protected override void OnStart(string[] args)
 {
     try
     {
         this._eventLog.WriteEntry("MES.IVTestDataTransfer 服务启动");
         if (lstWrapper == null)
         {
             lstWrapper = new List <IVTestDataTransferThreadWrapper>();
         }
         //获取配置节信息
         this._section = (IVTestConfigurationSection)ConfigurationManager.GetSection("mes.ivtest");
         //增加线程个数。
         foreach (IVTestDeviceElement 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(500);
             wrapper.Start();
         }
     }
     catch (Exception ex)
     {
         this._eventLog.WriteEntry(string.Format("MES.IVTestDataTransfer:{0}", ex.Message), EventLogEntryType.Error);
     }
 }
示例#2
0
 /// <summary>
 /// 数据转置
 /// </summary>
 private void TransferData(object obj)
 {
     try
     {
         IVTestDataTransferThreadWrapper wrapper = obj as IVTestDataTransferThreadWrapper;
         if (wrapper == null)
         {
             return;
         }
         TransferData(wrapper);
     }
     catch (Exception ex)
     {
         this._eventLog.WriteEntry("MES.IVTestDataTransfer: " + ex.Message);
     }
 }
示例#3
0
 /// <summary>
 /// 数据转置
 /// </summary>
 private void TransferData(IVTestDataTransferThreadWrapper wrapper)
 {
     while (wrapper.Loop)
     {
         try
         {
             IVTestDeviceElement device      = wrapper.Device;
             DateTime            dtStartTime = DateTime.Now;
             //获取IV测试数据文件路径。
             string strFileFullName = IVTestDataTransferAction.GetFullFile(device.Path, device.Format);
             string msg             = string.Empty;
             if (!string.IsNullOrEmpty(strFileFullName))
             {
                 string accConString = string.Format(device.ConnectionString, strFileFullName);
                 IVTestDataTransferAction sdgData = new IVTestDataTransferAction(accConString);
                 sdgData.Execute(device);
                 DateTime dtEndTime = DateTime.Now;
                 if (sdgData.TransferCount > 0)
                 {
                     msg = string.Format("MES.IVTestDataTransfer:开始时间:{0};结束时间:{1};耗用时间:{2}秒;转置 {5} 设备数据数量:{3}。{4}",
                                         dtStartTime
                                         , dtEndTime
                                         , (dtEndTime - dtStartTime).TotalSeconds
                                         , sdgData.TransferCount
                                         , strFileFullName
                                         , wrapper.Device.Name);
                     this._eventLog.WriteEntry(msg);
                 }
             }
             else
             {
                 msg = string.Format("MES.IVTestDataTransfer:开始时间:{0};获取{1} ACCESS数据库文件失败。", dtStartTime, wrapper.Device.Name);
                 this._eventLog.WriteEntry(msg);
             }
         }
         catch (Exception ex)
         {
             this._eventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
         }
         if (wrapper.Loop)
         {
             Thread.Sleep(1000);
         }
     }
     wrapper.AutoResetEvent.Set();
 }