Beispiel #1
0
        public static void WriteCSV(string path)
        {
            if (!IsRecordTackTimeLogger)
            {
                return;
            }
            object[] headObjs = new object[_tackTimeItemCollection.Count + 2];
            headObjs[0] = "DateTime";
            headObjs[1] = "Millisecond";
            for (int i = 0; i < _tackTimeItemCollection.Count; i++)
            {
                headObjs[i + 2] = string.Format("{0}({1})", _tackTimeItemCollection[i].Name, _tackTimeItemCollection[i].TackTimeInfoCollection.Count);
            }
            string dateTime = DateTime.Now.ToString("yyyyMMdd_HHmmss");

            SimpleCsvHelper.AddData(path, string.Format("TackTime_{0}.csv", dateTime), headObjs);
            for (int j = 0; j < _tackTimeItemCollection[0].TackTimeInfoCollection.Count; j++)
            {
                object[] objs = new object[_tackTimeItemCollection.Count + 2];
                objs[0] = _tackTimeItemCollection[0].TackTimeInfoCollection[j].TimeSpan.ToString();
                objs[1] = _tackTimeItemCollection[0].TackTimeInfoCollection[j].TimeSpan.TotalMilliseconds;
                for (int i = 0; i < _tackTimeItemCollection.Count; i++)
                {
                    objs[i + 2] = _tackTimeItemCollection[i].TackTimeInfoCollection[j].TaskName;
                }
                SimpleCsvHelper.AddData(path, string.Format("TackTime_{0}.csv", dateTime), objs);
            }
        }
Beispiel #2
0
        private void Save(string folderPath, string fileName, string cultureName)
        {
            //ErrorCode error = new ErrorCode()
            //{
            //    ErrorType = ErrorType.Alarm,
            //    Code = -1,
            //    Message = "Unknow Error",
            //    Remark = "中文測試"
            //};
            //ErrorCode error2 = new ErrorCode()
            //{
            //    ErrorType = ErrorType.Warning,
            //    Code = -2,
            //    Message = "Unknow Error",
            //    Remark = "English Test"
            //};
            //_dicAlarmCodeCollection.Add(error.Code, error);
            //_dicWarningCodeCollection.Add(error2.Code, error2);

            string filePath = string.Format(@"{0}\{1}", folderPath, fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            SimpleCsvHelper.AddData(folderPath, fileName, "{0},{1},{2},{3}", "ErrorType", "Code", "Message", "Remark");
            foreach (var item in _dicAlarmCodeCollection)
            {
                ErrorCode errorCode = item.Value;
                SimpleCsvHelper.AddData(folderPath, fileName, errorCode.ErrorType, errorCode.Code, errorCode.Message, errorCode.Remark);
            }
            foreach (var item in _dicWarningCodeCollection)
            {
                ErrorCode errorCode = item.Value;
                SimpleCsvHelper.AddData(folderPath, fileName, errorCode.ErrorType, errorCode.Code, errorCode.Message, errorCode.Remark);
            }
        }
Beispiel #3
0
 private void Load(string folderPath, string fileName, string cultureName)
 {
     try
     {
         string filePath = string.Format(@"{0}\{1}", folderPath, fileName);
         if (!File.Exists(filePath))
         {
             return;
         }
         List <string> csvStrings = SimpleCsvHelper.ReadCsvToList(filePath);
         for (int i = 1; i < csvStrings.Count; i++)
         {
             string[]  subItems  = csvStrings[i].Split(',');
             ErrorCode errorCode = new ErrorCode()
             {
                 ErrorType = (ErrorType)Enum.Parse(typeof(ErrorType), subItems[0]),
                 Code      = int.Parse(subItems[1]),
                 Message   = subItems[2],
                 Remark    = subItems[3]
             };
             if (errorCode.ErrorType == ErrorType.Alarm)
             {
                 _dicAlarmCodeCollection.Add(string.Format("{0}_{1}", cultureName, errorCode.Code), errorCode);
             }
             else
             {
                 _dicWarningCodeCollection.Add(string.Format("{0}_{1}", cultureName, errorCode.Code), errorCode);
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.Exception(ex);
         NotifyLogger.Post(ex);
     }
 }