示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="testInfo"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        public bool SaveToFile(VNPTTestInfo testInfo, VNPTLogMoreInfo info)
        {
            try {
                string title         = "Date_Time_Create,MacAddress,ProductCode,NhanVien,Infor1,Infor2,Infor3,Infor4,Infor5,TestSubject,LowerLimit,UpperLimit,GiaTriDo,PhanDinh";
                string fileFullName  = Path.Combine(this.dirLogTotal, this.fileName);
                bool   IsCreateTitle = !File.Exists(fileFullName);

                //write data to file
                using (StreamWriter sw = new StreamWriter(fileFullName, true, Encoding.Unicode)) {
                    //write title
                    if (IsCreateTitle == true)
                    {
                        sw.WriteLine(title);
                    }

                    foreach (PropertyInfo propertyInfo in testInfo.GetType().GetProperties())
                    {
                        if (propertyInfo.PropertyType == typeof(VNPTTestItemInfo))
                        {
                            VNPTTestItemInfo itemInfo = (VNPTTestItemInfo)propertyInfo.GetValue(testInfo, null);

                            if (itemInfo.Result != "--")
                            {
                                string content = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13}",
                                                               DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss ffff"),
                                                               testInfo.MacAddress.Replace(":", "").ToUpper().Replace(",", ";"),
                                                               testInfo.ProductSerial.Replace(",", ";"),
                                                               testInfo.Operator.Replace(",", ";"),
                                                               info.Info1,
                                                               info.Info2,
                                                               info.Info3,
                                                               info.Info4,
                                                               info.Info5,
                                                               propertyInfo.Name.Replace(",", ";"),
                                                               itemInfo.LowerLimit.Replace(",", ";"),
                                                               itemInfo.UpperLimit.Replace(",", ";"),
                                                               itemInfo.Value.Replace(",", ";"),
                                                               itemInfo.Result.Replace(",", ";")
                                                               );

                                //write content
                                sw.WriteLine(content);
                            }
                        }
                    }
                }

                return(true);
            } catch (Exception ex) {
                throw new Exception(ex.Message);
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="testInfo"></param>
        /// <returns></returns>
        public bool SaveToFile(VNPTTestInfo testInfo)
        {
            try {
                VNPTTestInfo info = new VNPTTestInfo();
                info          = testInfo;
                this.fileName = string.Format("{0}_{1}_{2}_{3}_{4}.xml", this.fileName, info.MacAddress, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), info.TotalResult);
                string fileFullName = Path.Combine(this.dirLogSingle, this.fileName);

                //remove SystemLog from testInfo
                var property = info.GetType().GetProperty("SystemLog");
                property.SetValue(info, null, null);

                //save to xml file
                IO.XmlHelper <VNPTTestInfo> .ToXmlFile(info, fileFullName);

                return(true);
            } catch (Exception ex) {
                throw new Exception(ex.Message);
            }
        }