Exemple #1
0
        public FileDescriptor(string filePath, SourceFileChanged fileChangedCallback, TraceDataSource dataSource)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException();
            }
            this.dataSource = dataSource;
            FileStream fileStream = Utilities.CreateFileStreamHelper(filePath);

            this.filePath = filePath;
            fileLength    = fileStream.Length;
            xmlUtil       = new XmlUtils(null);
            try
            {
                FileSectorIndicator(fileStream);
            }
            catch (LogFileException ex)
            {
                fileStream.Close();
                throw ex;
            }
            this.fileStream = fileStream;
            if (fileChangedCallback != null)
            {
                sourceFileChangedCallback = (SourceFileChanged)Delegate.Combine(sourceFileChangedCallback, fileChangedCallback);
            }
        }
Exemple #2
0
 private void CrimsonToE2eThreadProc(object o)
 {
     if (o != null && o is InternalCrimsonToE2eConvertingParameter)
     {
         InternalCrimsonToE2eConvertingParameter internalCrimsonToE2eConvertingParameter = (InternalCrimsonToE2eConvertingParameter)o;
         if (!string.IsNullOrEmpty(internalCrimsonToE2eConvertingParameter.SourceFileName) && !string.IsNullOrEmpty(internalCrimsonToE2eConvertingParameter.ConvertedFilename))
         {
             FileStream fileStream  = null;
             FileStream fileStream2 = null;
             try
             {
                 fileStream = Utilities.CreateFileStreamHelper(internalCrimsonToE2eConvertingParameter.SourceFileName);
                 if (fileStream.Length > 0)
                 {
                     List <InternalTargetTraceRecord> list = new List <InternalTargetTraceRecord>();
                     fileStream2 = Utilities.CreateFileStreamHelper(internalCrimsonToE2eConvertingParameter.ConvertedFilename, FileMode.Create, FileAccess.Write, FileShare.Read);
                     XmlTextReader xmlTextReader = new XmlTextReader(fileStream, XmlNodeType.Element, null);
                     XmlWriter     xmlWriter     = new XmlTextWriter(fileStream2, Encoding.UTF8);
                     xmlTextReader.WhitespaceHandling = WhitespaceHandling.None;
                     xmlTextReader.MoveToContent();
                     while (InternalReadToXml(xmlTextReader, "Event"))
                     {
                         string text = xmlTextReader.ReadOuterXml();
                         if (!string.IsNullOrEmpty(text))
                         {
                             InternalTargetTraceRecord item = InternalConstructTargetTraceRecordXml(text);
                             list.Add(item);
                         }
                         internalCrimsonToE2eConvertingParameter.Percentage = (int)((double)fileStream.Position / (double)fileStream.Length);
                         internalCrimsonToE2eConvertingParameter.TraceConvertedEvent.Set();
                     }
                     OutputCrimsonToE2EResults(list, xmlWriter);
                     xmlWriter.Flush();
                 }
             }
             catch (LogFileException ex)
             {
                 InternalCrimsonToE2eConvertingParameter internalCrimsonToE2eConvertingParameter2 = internalCrimsonToE2eConvertingParameter;
                 internalCrimsonToE2eConvertingParameter2.Exception = new FileConverterException(internalCrimsonToE2eConvertingParameter2.SourceFileName, internalCrimsonToE2eConvertingParameter.ConvertedFilename, ex.Message, ex);
             }
             catch (ArgumentException e)
             {
                 InternalCrimsonToE2eConvertingParameter internalCrimsonToE2eConvertingParameter3 = internalCrimsonToE2eConvertingParameter;
                 internalCrimsonToE2eConvertingParameter3.Exception = new FileConverterException(internalCrimsonToE2eConvertingParameter3.SourceFileName, internalCrimsonToE2eConvertingParameter.ConvertedFilename, SR.GetString("MsgCannotWriteToFile") + internalCrimsonToE2eConvertingParameter.ConvertedFilename + SR.GetString("MsgCannotWriteToFileEnd"), e);
             }
             catch (XmlException ex2)
             {
                 errorReport.ReportErrorToUser(new FileConverterException(internalCrimsonToE2eConvertingParameter.SourceFileName, internalCrimsonToE2eConvertingParameter.ConvertedFilename, SR.GetString("MsgErrorOccursOnConvertCrimson") + ex2.Message + SR.GetString("MsgCannotWriteToFileEnd"), ex2));
             }
             finally
             {
                 Utilities.CloseStreamWithoutException(fileStream, isFlushStream: false);
                 Utilities.CloseStreamWithoutException(fileStream2, isFlushStream: false);
                 internalCrimsonToE2eConvertingParameter.IsFinished = true;
                 internalCrimsonToE2eConvertingParameter.TraceConvertedEvent.Set();
             }
         }
     }
 }
 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();
             }
         }
     }
 }
Exemple #4
0
 internal static SupportedFileFormat DetectFileSchema(string filePath)
 {
     if (!string.IsNullOrEmpty(filePath))
     {
         if (filePath.EndsWith(SR.GetString("MainFrm_FileEtl"), StringComparison.OrdinalIgnoreCase))
         {
             return(SupportedFileFormat.EtlBinary);
         }
         if (filePath.EndsWith(SR.GetString("PJ_Extension"), StringComparison.OrdinalIgnoreCase))
         {
             return(SupportedFileFormat.STVProjectFile);
         }
         FileStream fileStream = null;
         char[]     array      = new char[8192];
         try
         {
             fileStream = Utilities.CreateFileStreamHelper(filePath);
             Utilities.SeekFileStreamHelper(fileStream, 0L, SeekOrigin.Begin);
             Utilities.CreateStreamReaderHelper(fileStream).Read(array, 0, array.Length);
         }
         catch (IOException)
         {
             return(SupportedFileFormat.UnknownFormat);
         }
         finally
         {
             Utilities.CloseStreamWithoutException(fileStream, isFlushStream: false);
         }
         string text = new string(array);
         text = text.Trim(' ', '\0', '\t', '\n');
         if (string.IsNullOrEmpty(text))
         {
             return(SupportedFileFormat.E2ETraceEventSchema);
         }
         int num  = text.IndexOf(crimsonSchemaTag, StringComparison.Ordinal);
         int num2 = text.IndexOf(e2eSchemaTag, StringComparison.Ordinal);
         if (num != -1 && num2 == -1)
         {
             return(SupportedFileFormat.CrimsonSchema);
         }
         if (num == -1 && num2 != -1)
         {
             return(SupportedFileFormat.E2ETraceEventSchema);
         }
         if (num != -1 && num2 == -1 && num < num2)
         {
             return(SupportedFileFormat.CrimsonSchema);
         }
         if (num != -1 && num2 == -1 && num > num2)
         {
             return(SupportedFileFormat.E2ETraceEventSchema);
         }
     }
     return(SupportedFileFormat.NotSupported);
 }
Exemple #5
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;
     }
 }
Exemple #6
0
        private bool SaveProjectToFile(string filePath)
        {
            List <string> list          = openedFilePaths;
            FileStream    fileStream    = null;
            XmlTextWriter xmlTextWriter = null;

            try
            {
                fileStream    = Utilities.CreateFileStreamHelper(filePath, FileMode.Create, FileAccess.Write, FileShare.Read);
                xmlTextWriter = new XmlTextWriter(fileStream, Encoding.UTF8);
            }
            catch (LogFileException ex)
            {
                throw new TraceViewerException(ex.Message);
            }
            catch (ArgumentException)
            {
                throw new TraceViewerException(SR.GetString("MsgFailSavePrj") + filePath);
            }
            if (!ComposeProjectFileStream(xmlTextWriter, filePath))
            {
                openedFilePaths = list;
                return(false);
            }
            try
            {
                xmlTextWriter.Close();
                PersistedSettings.SaveRecentFiles(new string[1]
                {
                    filePath
                }, isProject: true);
            }
            catch (InvalidOperationException)
            {
                openedFilePaths = list;
                return(false);
            }
            finally
            {
                Utilities.CloseStreamWithoutException(fileStream, isFlushStream: false);
            }
            return(true);
        }
 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);
 }
        public bool UpdateConfigFile(CustomFilterManager filterManager)
        {
            FileStream fileStream = null;
            int        num        = 5;
            bool       flag       = true;

            while (flag)
            {
                try
                {
                    fileStream = Utilities.CreateFileStreamHelper(configFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
                    if (fileStream != null)
                    {
                        flag = false;
                    }
                }
                catch (LogFileException ex)
                {
                    if (ex.InnerException == null || !(ex.InnerException is IOException) || num < 0)
                    {
                        switch (userIP.ShowMessageBox(SR.GetString("CF_Err10") + ex.Message, null, MessageBoxIcon.Hand, MessageBoxButtons.AbortRetryIgnore))
                        {
                        case DialogResult.Abort:
                            return(false);

                        case DialogResult.Ignore:
                            return(true);

                        case DialogResult.Retry:
                            flag = true;
                            break;
                        }
                    }
                    else
                    {
                        flag = true;
                        num--;
                        Thread.Sleep(new Random((int)DateTime.Now.Ticks).Next(200, 600));
                    }
                }
            }
            XmlTextWriter xmlTextWriter = null;

            try
            {
                xmlTextWriter = new XmlTextWriter(fileStream, Encoding.UTF8);
                xmlTextWriter.WriteStartElement("appSettings");
                xmlTextWriter.WriteStartElement("customFilters");
                filterManager.UpdateCurrentFilters(xmlTextWriter);
                xmlTextWriter.WriteEndElement();
                xmlTextWriter.WriteStartElement("filterOptions");
                customFilterOptionSettings.OutputToStream(xmlTextWriter);
                xmlTextWriter.WriteEndElement();
                xmlTextWriter.WriteStartElement("uiSettings");
                InternalPersisitRegisteredObjects(xmlTextWriter);
                xmlTextWriter.WriteEndElement();
                xmlTextWriter.WriteEndElement();
                xmlTextWriter.Flush();
                return(true);
            }
            catch (XmlException)
            {
                errorReport.ReportErrorToUser(SR.GetString("CF_Err10"));
                return(true);
            }
            finally
            {
                Utilities.CloseStreamWithoutException(fileStream, isFlushStream: false);
            }
        }
 public bool Import()
 {
     using (OpenFileDialog openFileDialog = new OpenFileDialog())
     {
         openFileDialog.CheckFileExists = true;
         openFileDialog.CheckPathExists = true;
         openFileDialog.ValidateNames   = true;
         openFileDialog.Title           = SR.GetString("CFIP_Title");
         openFileDialog.Filter          = SR.GetString("CFIP_Filter");
         openFileDialog.Multiselect     = false;
         if (openFileDialog.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(openFileDialog.FileName))
         {
             FileStream fileStream = null;
             try
             {
                 fileStream = Utilities.CreateFileStreamHelper(openFileDialog.FileName);
             }
             catch (LogFileException ex)
             {
                 errorReport.ReportErrorToUser(SR.GetString("CF_Err11") + ex.Message);
                 return(false);
             }
             try
             {
                 XmlDocument xmlDocument = new XmlDocument();
                 xmlDocument.Load(fileStream);
                 List <CustomFilter> list = null;
                 foreach (XmlNode childNode in xmlDocument.ChildNodes)
                 {
                     if (childNode.Name == "customFilters")
                     {
                         list = LoadCustomFilters(childNode, reportErrors: true);
                         break;
                     }
                 }
                 if (list != null && list.Count != 0)
                 {
                     Random random = new Random((int)DateTime.Now.Ticks);
                     foreach (CustomFilter item in list)
                     {
                         if (IsDuplicateFilterName(item.FilterName))
                         {
                             item.ChangeFilterName(item.FilterName + random.Next(0, 65535).ToString(CultureInfo.InvariantCulture));
                         }
                         currentFilters.Add(item);
                     }
                 }
             }
             catch (XmlException)
             {
                 errorReport.ReportErrorToUser(SR.GetString("CF_InvalidFilterFile"));
             }
             finally
             {
                 Utilities.CloseStreamWithoutException(fileStream, isFlushStream: false);
             }
             return(true);
         }
         return(false);
     }
 }