Пример #1
0
        /// <summary>
        /// 将单表信息存储到日志文件
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        private bool WriteOneMeterDataLogFile(OneMeterDataLogMsg msg)
        {
            LogStreamWriter sm = null;// this._dpLogStreamList.Where(p => p.DtuID == msg.DTUID && p.DataPointID == msg.DataPointID).Single();

            if (this._oneMeterDataLogStreamList.Count > 0)
            {
                List <LogStreamWriter> list = this._oneMeterDataLogStreamList.ToList();
                if (list.Count == 1)
                {
                    sm = list[0];
                }
            }
            if (sm == null)
            {
                //记录该监视信息对象不存在,创建该对象。
                sm = CreateOneMeterDataLog(msg.mac);
                this._oneMeterDataLogStreamList.Add(sm);
            }
            else
            {
                sm.Close();
                this._oneMeterDataLogStreamList.Remove(sm);
                //创建新日志文件
                sm = CreateOneMeterDataLog(msg.mac);
                this._oneMeterDataLogStreamList.Add(sm);
            }
            //记录日志
            try
            {
                sm.WriteLine(msg.text);
                sm.Flush();
                return(true);
            }
            catch
            {
                sm.Close();
                //如果写流失败
                this._oneMeterDataLogStreamList.Remove(sm);
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// 将采集服务器监测信息存储到文件
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        private bool WriteHisMonitorInfoLogFile(MonitorLogMsg msg)
        {
            LogStreamWriter sm = null;// this._dpLogStreamList.Where(p => p.DtuID == msg.DTUID && p.DataPointID == msg.DataPointID).Single();

            if (this._monitorinfoLogStreamList.Count > 0)
            {
                List <LogStreamWriter> list = this._monitorinfoLogStreamList.Where(p => p.DtuID == msg.cjdID).ToList();
                if (list.Count == 1)
                {
                    sm = list[0];
                }
            }
            if (sm == null)
            {
                //记录该监视信息对象不存在,创建该对象。
                sm = CreateHisMonitorInfo(msg.cjdID);
                this._monitorinfoLogStreamList.Add(sm);
            }
            if (DateTime.Now >= sm.TimeSign)
            {
                sm.Close();
                this._monitorinfoLogStreamList.Remove(sm);
                //创建新日志文件
                sm = CreateHisMonitorInfo(msg.cjdID);
                this._monitorinfoLogStreamList.Add(sm);
            }
            //记录日志
            try
            {
                sm.WriteLine(msg.text);
                sm.Flush();
                return(true);
            }
            catch
            {
                sm.Close();
                //如果写流失败
                this._monitorinfoLogStreamList.Remove(sm);
                return(false);
            }
        }