コード例 #1
0
 public void Export(List <CustomFilter> filters)
 {
     if (filters != null && filters.Count != 0)
     {
         using (SaveFileDialog saveFileDialog = new SaveFileDialog())
         {
             saveFileDialog.Title  = SR.GetString("CFEP_Title");
             saveFileDialog.Filter = SR.GetString("CFEP_Filter");
             if (saveFileDialog.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(saveFileDialog.FileName))
             {
                 FileInfo fileInfo = null;
                 try
                 {
                     fileInfo = Utilities.CreateFileInfoHelper(saveFileDialog.FileName);
                 }
                 catch (LogFileException ex)
                 {
                     errorReport.ReportErrorToUser(ex.Message);
                     return;
                 }
                 if (fileInfo.Exists)
                 {
                     try
                     {
                         Utilities.DeleteFileByFileInfoHelper(fileInfo);
                     }
                     catch (LogFileException ex2)
                     {
                         errorReport.ReportErrorToUser(ex2.Message);
                         return;
                     }
                 }
                 FileStream fileStream = null;
                 try
                 {
                     fileStream = Utilities.CreateFileStreamHelper(saveFileDialog.FileName, FileMode.CreateNew, FileAccess.Write, FileShare.Read);
                 }
                 catch (LogFileException ex3)
                 {
                     errorReport.ReportErrorToUser(SR.GetString("CF_Err12") + ex3.Message);
                     return;
                 }
                 XmlTextWriter xmlTextWriter = new XmlTextWriter(fileStream, Encoding.UTF8);
                 xmlTextWriter.WriteStartElement("customFilters");
                 foreach (CustomFilter filter in filters)
                 {
                     filter.OutputToStream(xmlTextWriter);
                 }
                 xmlTextWriter.WriteEndElement();
                 xmlTextWriter.Flush();
                 xmlTextWriter.Close();
             }
         }
     }
 }
コード例 #2
0
 private void Initialzie(string fileName)
 {
     if (!string.IsNullOrEmpty(fileName))
     {
         if (!Utilities.CreateFileInfoHelper(fileName).Exists)
         {
             throw new FileNotFoundException(SR.GetString("MsgSFNotFound"), fileName);
         }
         Utilities.CreateFileStreamHelper(fileName).Close();
         reader          = new EtwTraceReader(QueueProcessor, StartTime, EndTime);
         reader.FileName = fileName;
     }
 }
コード例 #3
0
 private XmlNode InternalLoadSettingNodeFromAppConfigFile(string nodeName)
 {
     if (!string.IsNullOrEmpty(configFilePath))
     {
         if (Utilities.CreateFileInfoHelper(configFilePath).Exists)
         {
             FileStream fileStream = Utilities.CreateFileStreamHelper(configFilePath);
             try
             {
                 XmlDocument xmlDocument = new XmlDocument();
                 xmlDocument.Load(fileStream);
                 XmlNode documentElement = xmlDocument.DocumentElement;
                 if (documentElement != null)
                 {
                     foreach (XmlNode childNode in documentElement.ChildNodes)
                     {
                         if (childNode != null && childNode.Name == nodeName)
                         {
                             return(childNode);
                         }
                     }
                 }
                 return(null);
             }
             catch (XmlException)
             {
                 return(null);
             }
             finally
             {
                 Utilities.CloseStreamWithoutException(fileStream, isFlushStream: false);
             }
         }
         return(null);
     }
     return(null);
 }