Ejemplo n.º 1
0
        public static void DoSystemEventRecord(Device device, string systemEvent, RecordType recordType = RecordType.Event)
        {
            RecordManager.WriteDataToLog(device, systemEvent, recordType);

            if (analysisToolOpen)
            {
                SendToAnalysisWindow(systemEvent);
            }
        }
Ejemplo n.º 2
0
		// private FieldConfig[] fieldsConfig;

		public DeviceData(Device device, object[] data)
		{
			this.device = device;
			this.data = data;
			this.delay = 0;
            this.time = default(DateTime);
            this.originData = string.Empty;
            this.insertIntoCommand = string.Empty;            
			// this.fieldsConfig = null;
		}
Ejemplo n.º 3
0
        private static void WriteDataToLog(Device device, string content, RecordType recordType)
        {
            DateTime now = DateTime.Now;
            FileStream stream = RecordManager.GetLogFileStream(device, now);
            string time = string.Format("[{0:HH:mm:ss}] ", now);
            StringBuilder sb = new StringBuilder(time);
            sb.Append(string.Format(" <{0}> ", recordType.ToString()));
            sb.Append(content);
            sb.Append("\r\n");
            string line = sb.ToString();

            byte[] bytes = Encoding.ASCII.GetBytes(line);
            stream.Write(bytes, 0, bytes.Length);

            // Flush Control.
            if (flushCtrlCount % 10 == 0)
            {
                stream.Flush();
            }
            flushCtrlCount = (flushCtrlCount + 1) % 5;
        }
Ejemplo n.º 4
0
        private static FileStream GetLogFileStream(Device device, DateTime now)
        {
            string path = GetDeviceLogPath(device, now);
            string deviceName = device.Name;
            if (streams.ContainsKey(deviceName))
            {
                StreamHolder holder = streams[deviceName];
                if (holder.FilePath.ToLower() == path.ToLower())
                {
                    return holder.FileStream;
                }
                else
                {
                    FileStream fileStream = holder.FileStream;
                    if (fileStream != null)
                    {
                        fileStream.Close();
                        fileStream.Dispose();
                    }
                    streams.Remove(deviceName);
                }
            }

            StreamHolder newHolder = new StreamHolder() { FilePath = path };
            if (!File.Exists(path))
            {
                // TODO: TO TEST!
                // string logPath = GetDeviceLogPath(device, DateTime.Now);
                FileStream fs = File.Create(path);
                newHolder.FileStream = fs;
                streams[deviceName] = newHolder;
                return fs;
            }
            else
            {
                FileStream fs = File.Open(path, FileMode.Append);
                newHolder.FileStream = fs;
                streams[deviceName] = newHolder;
                return fs;
            }
        }
Ejemplo n.º 5
0
        private static string GetDeviceLogPath(Device device, DateTime now)
        {
            string deviceLogPath = LogPath.GetDeviceLogFilePath(device.Id, now);
            if (!existPaths.ContainsKey(deviceLogPath.ToLower()))
            {
                if (!Directory.Exists(deviceLogPath))
                {
                    Directory.CreateDirectory(deviceLogPath);
                }
                existPaths.Add(deviceLogPath.ToLower(), true);
            }
            string fileName = string.Format("{0}-{1}-{2}.daq.log", now.Year, now.Month, now.Day);

            string path = string.Format("{0}\\{1}", deviceLogPath, fileName);
            return path;
        }
Ejemplo n.º 6
0
        public static void DoSystemEventRecord(Device device, string systemEvent, RecordType recordType = RecordType.Event, bool flush = false)
		{
			RecordManager.WriteDataToLog(device, systemEvent, recordType, flush);
		}
Ejemplo n.º 7
0
        //////////////////////////////////////////////////////////////////////////////

        private static StreamWriter GetLogFileStream(Device device, DateTime now)
        {
            string path = GetDeviceLogPath(device, now);
            string deviceName = device.Name;
            if (streams.ContainsKey(deviceName))
            {
                FileWriterHolder holder = streams[deviceName];
                if (holder.FilePath.ToLower() == path.ToLower())
                {
                    return holder.FileWriter;
                }
                else
                {
                    StreamWriter fileWriter = holder.FileWriter;
                    if (fileWriter != null)
                    {
                        fileWriter.Close();
                        fileWriter.Dispose();
                    }
                    streams.Remove(deviceName);
                }
            }

            FileWriterHolder newHolder = new FileWriterHolder() { FilePath = path };
            if (!File.Exists(path))
            {
                // TODO: TO TEST!
                // string logPath = GetDeviceLogPath(device, DateTime.Now);
                StreamWriter fsw = new StreamWriter(path, true);
                newHolder.FileWriter = fsw;
                streams[deviceName] = newHolder;
                return fsw;
            }
            else
            {
                StreamWriter fsw = new StreamWriter(path, true);
                newHolder.FileWriter = fsw;
                streams[deviceName] = newHolder;
                return fsw;
            }
        }
Ejemplo n.º 8
0
		private static void WriteDataToLog(Device device, string content, RecordType recordType, bool flush = false)
		{
            // To Log File
			DateTime now = DateTime.Now;
            StreamWriter fileWriter = RecordManager.GetLogFileStream(device, now);
			string time = string.Format("[{0:HH:mm:ss}] ", now);
			StringBuilder sb = new StringBuilder(time);
            sb.Append(string.Format(" <{0}> ", recordType.ToString()));
			sb.Append(content);
			string line = sb.ToString();

            fileWriter.WriteLine(line);

			// Flush Control.
#if DEBUG
            fileWriter.Flush();
#else
            if (flush)
            {
                fileWriter.Flush();
            }
#endif

			if (flushCtrlCount % 10 == 0)
			{
                fileWriter.Flush();
			}
			flushCtrlCount = (flushCtrlCount + 1) % 5;

            // To Log Console
            if (ExistLoggerConsoleProc())
            {
                string deviceKey = device.Id.ToLower();
                if (LoggerClient.Contains(deviceKey))
                {
                    logger.Send(deviceKey, line);
                }
            }
		}