コード例 #1
0
        //[TestMethod]
        public void TestLoginExportType()
        {
            TempFile temp = new TempFile();

            temp.Write(Resources.AltoroLogin);

            TrafficViewerFile origFile = new TrafficViewerFile();

            origFile.Open(temp.Path);

            Assert.AreEqual(4, origFile.RequestCount);

            //export

            IList <ITrafficExporter> exporters = TrafficViewer.Instance.TrafficExporters;

            ITrafficExporter loginExporter = null;

            foreach (ITrafficExporter exporter in exporters)
            {
                if (exporter.Caption == "ASE Login Files (.login)")
                {
                    loginExporter = exporter;
                }
            }

            Assert.IsNotNull(loginExporter);

            TempFile exportedFile = new TempFile("exporttest.login");
            Stream   stream       = exportedFile.OpenStream();

            loginExporter.Export(origFile, stream, "demo.testfire.net", 80);

            stream.Close();

            //import the exported file

            TrafficViewerFile import = new TrafficViewerFile();

            ITrafficParser configurationParser = TrafficViewer.Instance.GetParser("Configuration Parser");

            Assert.IsNotNull(configurationParser);

            configurationParser.Parse(exportedFile.Path, import, ParsingOptions.GetLegacyAppScanProfile());


            Assert.AreEqual(origFile.RequestCount, import.RequestCount);

            int           i = -1;
            TVRequestInfo origInfo;

            while ((origInfo = origFile.GetNext(ref i)) != null)
            {
                TVRequestInfo importInfo      = import.GetRequestInfo(origInfo.Id);
                string        origRequest     = Constants.DefaultEncoding.GetString(origFile.LoadRequestData(origInfo.Id));
                string        importedRequest = Constants.DefaultEncoding.GetString(import.LoadRequestData(origInfo.Id));

                Assert.AreEqual(origRequest, importedRequest);
            }
        }
コード例 #2
0
        private static void TestImportParser(ITrafficParser parser, TempFile log, ParsingOptions profile)
        {
            TrafficViewerFile tvFile = new TrafficViewerFile();

            tvFile.StartImport(parser, log.Path, profile);
            ValidateASEFile(tvFile);
        }
コード例 #3
0
        /// <summary>
        /// Starts an asyncroneus import operation
        /// </summary>
        /// <param name="parser"></param>
        /// <param name="sender"></param>
        /// <param name="options"></param>
        /// <param name="callback"></param>
        public void BeginImport(ITrafficParser parser, object sender, ParsingOptions options, AsyncCallback callback)
        {
            ImportInfo info = new ImportInfo();

            info.Parser  = parser;
            info.Sender  = sender;
            info.Profile = options;

            BeginImport(info, callback);
        }
コード例 #4
0
        /// <summary>
        /// Starts an asyncroneus import operation
        /// </summary>
        /// <param name="parser"></param>
        /// <param name="pathsToFilesToImport"></param>
        /// <param name="options"></param>
        /// <param name="callback"></param>
        public void BeginImport(ITrafficParser parser, List <string> pathsToFilesToImport, ParsingOptions options, AsyncCallback callback)
        {
            ImportInfo info = new ImportInfo();

            info.Parser      = parser;
            info.TargetFiles = pathsToFilesToImport;
            info.Profile     = options;

            BeginImport(info, callback);
        }
コード例 #5
0
 private static bool ParserMatchesFile(ITrafficParser parser, string filePath)
 {
     foreach (string typeMatch in parser.ImportTypes.Values)
     {
         Regex typeMatchRegex = new Regex(typeMatch.Replace("*", ".*") + "$");
         if (typeMatchRegex.IsMatch(filePath))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #6
0
 /// <summary>
 /// Imports from a object
 /// </summary>
 /// <param name="parser">parser object containing the parsing logic</param>
 /// <param name="sender">the raw traffic file to use</param>
 /// <param name="profile">The parsing options for the current parsing operation</param>
 public void StartImport(ITrafficParser parser, object sender, ParsingOptions profile)
 {
     if (parser != null)
     {
         SetState(AccessorState.Loading);
         //save parsing options
         Profile = profile;
         //save parser
         _parser = parser;
         //save sender object
         _sender = sender;
         //start parsing
         _parser.Parse(sender, this, profile);
         SetState(AccessorState.Idle);
     }
 }
コード例 #7
0
 /// <summary>
 /// Imports from a Raw Traffic Log
 /// </summary>
 /// <param name="parser">parser object containing the parsing logic</param>
 /// <param name="rawTrafficLog">the raw traffic file to use</param>
 /// <param name="profile">The parsing options for the current parsing operation</param>
 public void StartImport(ITrafficParser parser, string rawTrafficLog, ParsingOptions profile)
 {
     if (parser != null)
     {
         SetState(AccessorState.Loading);
         //save parsing options
         Profile = profile;
         //save target path
         _importedFileName = rawTrafficLog;
         //save parser
         _parser = parser;
         //start parsing
         _parser.Parse(rawTrafficLog, this, profile);
         SetState(AccessorState.Idle);
     }
 }
コード例 #8
0
        private void ImportLogStart(ImportInfo importInfo)
        {
            _lastImportInfo = importInfo;

            if (!importInfo.Append)
            {
                if (!CloseTVF())
                {
                    return;
                }
                NewTVF();
            }

            _tvfChanged         = true;
            _currentTVFilePath  = String.Empty;
            _currentRawLogPaths = importInfo.TargetFiles;
            Text = String.Empty;
            foreach (string path in _currentRawLogPaths)
            {
                Text += Path.GetFileName(path) + "; ";
            }

            Text = Text.TrimEnd(' ', ';');
            if (importInfo.TargetFiles.Count == 0 && importInfo.Sender != null)
            {
                Text += String.Format("{0} - {1}", _lastImportInfo.Sender, _nameAndVersion);
            }
            else
            {
                Text += " - " + _nameAndVersion;
            }
            _parsingOptions = importInfo.Profile;
            //load the parser
            _parser = importInfo.Parser;

            try
            {
                TrafficViewer.Instance.BeginImport(importInfo, null);
            }
            catch (Exception ex)
            {
                SdkSettings.Instance.Logger.Log(TraceLevel.Error, ex.Message);
                MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #9
0
        private void SelectedIndexChanged(object sender, EventArgs e)
        {
            ITrafficParser selectedParser = _parsers[_boxParserDll.SelectedIndex];
            //construct filter
            StringBuilder sb = new StringBuilder();

            _checkSender.Checked = (selectedParser.ImportSupport & ImportMode.Objects) != 0 & _importResult.ImportInfo.Sender != null;

            foreach (string importType in selectedParser.ImportTypes.Keys)
            {
                sb.Append(importType);
                sb.Append('|');
                sb.Append(selectedParser.ImportTypes[importType]);
                sb.Append('|');
            }

            _dialogSelectFile.Filter = sb.ToString().TrimEnd('|');
        }
コード例 #10
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: Traffic2Exd <traffic file path> <EXD file path>");
                Console.WriteLine("Supported import formats: .har, .txt, .htd");
                Console.WriteLine("If the EXD file already exists the tool will append to it.");

                Console.WriteLine("Exit codes: 1 - No args, 2 - Incorrect file path, 3 - Parsing error, 4 - Export error, 5 - Unsupported Exception.");
                Environment.ExitCode = 1;
            }
            else
            {
                string trafficFilePath = args[0];
                string exdFilePath     = args[1];
                if (!File.Exists(trafficFilePath))
                {
                    Console.WriteLine("Could not find har file: '{0}'", trafficFilePath);
                    Environment.ExitCode = 2;
                }
                else
                {
                    TrafficViewerFile tvf = new TrafficViewerFile();
                    try
                    {
                        if (File.Exists(exdFilePath))
                        {
                            Console.WriteLine("EXD file {0} already exists. Appending to it.", exdFilePath);
                            ConfigurationParser exdParser = new ConfigurationParser();
                            exdParser.Parse(exdFilePath, tvf, ParsingOptions.GetDefaultProfile());
                        }


                        Console.WriteLine("Importing from '{0}'...", trafficFilePath);
                        ITrafficParser parser = null;


                        if (trafficFilePath.ToLower().EndsWith(".har"))
                        {
                            parser = new HarParser();
                        }
                        else if (trafficFilePath.ToLower().EndsWith(".txt"))
                        {
                            parser = new DefaultTrafficParser();
                        }
                        else if (trafficFilePath.ToLower().EndsWith(".htd"))
                        {
                            TrafficViewerFile tvf2 = new TrafficViewerFile();
                            tvf2.Open(trafficFilePath);
                            int           id   = -1;
                            TVRequestInfo info = null;

                            while ((info = tvf2.GetNext(ref id)) != null)
                            {
                                tvf.AddRequestResponse(tvf2.LoadRequestData(info.Id), tvf2.LoadResponseData(info.Id));
                            }
                        }
                        else
                        {
                            Console.WriteLine("File extension is unsupported. Supported extensions/formats: .har, .txt, .htd");
                            Environment.ExitCode = 5;
                        }

                        if (parser != null)
                        {
                            parser.Parse(trafficFilePath, tvf, ParsingOptions.GetRawProfile());
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Parsing exception: '{0}'", ex.Message);
                        Environment.ExitCode = 3;
                    }
                    //now export

                    try
                    {
                        Console.WriteLine("Exporting to '{0}'...", exdFilePath);
                        var exporter = new ManualExploreExporter();
                        exporter.Export(tvf, new FileStream(exdFilePath, FileMode.Create, FileAccess.ReadWrite));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Export exception: '{0}'", ex.Message);
                        Environment.ExitCode = 4;
                    }
                    tvf.Close(false);
                    Console.WriteLine("Done.");
                }
            }
        }