Exemplo n.º 1
0
 private void Form1_WizardCompleting(object sender, CancellableWizardEventArgs e)
 {
     e.Cancel = MessageBox.Show("Cancel?", "Test", MessageBoxButtons.YesNo) == DialogResult.Yes;
     if (!e.Cancel)
     {
         string mainFileNameTemp = Path.GetTempFileName();
         string stubFileNameTemp = Path.GetTempFileName();
         try
         {
             TraceFileProcessor tfp = new TraceFileProcessor();
             tfp.ProcessTraceFile("WizardTester", e.Data.TraceFile, null, e.Data.Configuration, mainFileNameTemp, stubFileNameTemp);
             System.Diagnostics.Process.Start("notepad", mainFileNameTemp);
             System.Diagnostics.Process.Start("notepad", stubFileNameTemp);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             e.Cancel = true;
         }
         ////finally
         ////{
         ////    //File.Delete(mainFileNameTemp);
         ////    //File.Delete(stubFileNameTemp);
         ////}
     }
 }
Exemplo n.º 2
0
        public void ProcessorInAppDomain()
        {
            this.config.testMethodMode = TestMethodMode.IncludeIndividualOperations;

            TraceFileProcessor.ProcessTraceFileInAppDomain("SampleWithNamespaces", "SampleWithNamespaces.svclog", null, this.config, "SampleWithNamespaces.cs", "SampleWithNamespaces.stubs");
            Assert.IsTrue(System.IO.File.Exists("SampleWithNamespaces.cs"));
            Assert.IsTrue(System.IO.File.Exists("SampleWithNamespaces.stubs"));
            TestHelper.CheckFileContains("SampleWithNamespaces.cs", @"\[TestMethod\(\)\]", 10);
            TestHelper.CheckFileContains("SampleWithNamespaces.cs", @"BeginTimer", 9);
        }
Exemplo n.º 3
0
        public void InitConfig()
        {
            this.config = new WcfUnitConfiguration();
            this.config.testMethodMode     = TestMethodMode.ScenarioMethodOnly;
            this.config.operationTimerMode = OperationTimerMode.IncludeOperationTimers;
            AssemblyType a = new AssemblyType();

            a.fileName              = "ClientProxies.dll";
            this.config.assembly    = new AssemblyType[] { a };
            this.config.soapActions = new WcfUnitConfigurationSoapActions();
            this.config.soapActions.soapActionMode = SoapActionMode.Include;
            File.Delete("SampleWithNamespaces.cs");
            File.Delete("SampleWithNamespaces.stubs");
            this.sut = new TraceFileProcessor();
        }
Exemplo n.º 4
0
 private void WizardCompletingHandler(object sender, CancellableWizardEventArgs e)
 {
     // Process the data and if it fails prevent the closing of the wizard
     this.mainFileNameTemp = Path.GetTempFileName();
     this.stubFileNameTemp = Path.GetTempFileName();
     try
     {
         this.proxyAssemblies = TraceFileProcessor.ProcessTraceFileInAppDomain(this.scenarioName, e.Data.TraceFile, null, e.Data.Configuration, this.mainFileNameTemp, this.stubFileNameTemp);
     }
     catch (Exception ex)
     {
         this.errorDisplay(ex.Message);
         File.Delete(this.mainFileNameTemp);
         File.Delete(this.stubFileNameTemp);
         e.Cancel = true;
     }
 }
        private static void PerformImport()
        {
            try
            {
                DateTime startTime = DateTime.Now;

                string path    = TraceFilePath.Substring(0, TraceFilePath.LastIndexOf('\\') + 1);
                string trcbase = TraceFilePath.Substring(TraceFilePath.LastIndexOf('\\') + 1);
                // Remove numbers trailing from trace file name (if they are there) as well as file extension...
                trcbase = trcbase.Substring(0, trcbase.Length - 4); int j = trcbase.Length - 1; while (Char.IsDigit(trcbase[j]))
                {
                    j--;
                }
                trcbase = trcbase.Substring(0, j + 1);
                FileInfo fi        = new FileInfo(TraceFilePath);
                var      fileInfos = Directory.GetFiles(path, trcbase + "*.trc", SearchOption.TopDirectoryOnly).Select(p => new FileInfo(p))
                                     .OrderBy(x => x.CreationTime).Where(x => x.CreationTime >= fi.CreationTime.Subtract(new TimeSpan(0, 0, 45))).ToList();
                List <string> files = fileInfos.Select(x => x.Name.Substring(trcbase.Length)).ToList();
                files.Sort((x, y) => ExtractNumberPartFromText(x).CompareTo(ExtractNumberPartFromText(y)));
                if (TraceFilePath != path + trcbase + files[0])
                {
                    files.RemoveRange(0, files.IndexOf(TraceFilePath.Substring((path + trcbase).Length)));
                }
                FileCount = files.Count;

                List <Thread> workers = new List <Thread>();
                int           CurFile = -1;
                cols = String.Empty;
                tfps = new List <TraceFileProcessor>();

                Semaphore s = new Semaphore(1, System.Environment.ProcessorCount * 2); // throttles simultaneous threads to number of processors, starts with just 1 free thread until cols are initialized
                foreach (string f in files)
                {
                    if (!bCancel)
                    {
                        CurFile++;
                        TraceFileProcessor tfp = new TraceFileProcessor(CurFile, path + trcbase + f, Table, s, new TraceFile(), new TraceTable());
                        tfps.Add(tfp);
                        workers.Add(new Thread(() => tfp.ProcessTraceFile()));
                        workers.Last().Start();
                    }
                }

                if (!bCancel)
                {
                    SqlConnection conn2 = new System.Data.SqlClient.SqlConnection(ConnStr);
                    conn2.Open();
                    for (int i = 0; i <= CurFile; i++)
                    {
                        if (i > 0 && !bCancel)
                        {
                            workers[i].Join();
                            try
                            {
                                SqlCommandInfiniteConstructor("delete from [##" + Table + "_" + i + "] where eventclass = 65528", conn2).ExecuteNonQuery();
                                SqlCommandInfiniteConstructor("insert into [" + Table + "] (" + cols + ") select " + cols + " from [##" + Table + "_" + i + "]", conn2).ExecuteNonQuery();
                            }
                            catch (Exception ex)
                            {
                                SetText("Exception in trace import: \r\n" + ex.Message);
                            }
                            if (i == 1)
                            {
                                SetText("File 1 saved to base table [" + Table + "].\r\nTemp tables generated for other files must be merged serially.");
                            }
                            SetText("Merging file " + (i + 1) + "...");
                        }
                        else
                        {
                            workers[0].Join();
                        }
                        tfps[i].tIn.Close();
                        tfps[i].tOut.Close();
                        tfps[i].tIn  = null;
                        tfps[i].tOut = null;
                    }

                    if (!bCancel)
                    {
                        SetText("Building index and adding views...");
                        SetText("Done loading " + String.Format("{0:#,##0}", (RowCount)) + " rows in " + Math.Round((DateTime.Now - startTime).TotalSeconds, 1) + "s.");
                        cols = SqlCommandInfiniteConstructor("SELECT SUBSTRING((SELECT ', t.' + QUOTENAME(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + Table + "' AND COLUMN_NAME <> 'RowNumber' ORDER BY ORDINAL_POSITION FOR XML path('')), 3, 200000);", conn2).ExecuteScalar() as string;
                        try
                        {
                            SqlCommandInfiniteConstructor(Properties.Resources.EventClassSubClassTablesScript, conn2).ExecuteNonQuery();
                            SqlCommandInfiniteConstructor("if exists(select * from sys.views where name = '" + Table + "_v') drop view [" + Table + "_v];", conn2).ExecuteNonQuery();
                            SqlCommandInfiniteConstructor("create view [" + Table + "_v] as select t.[RowNumber], " + cols.Replace("t.[EventClass]", "c.[Name] as EventClassName, t.EventClass").Replace("t.[EventSubclass]", "s.[Name] as EventSubclassName, t.EventSubclass").Replace("t.[TextData]", "convert(nvarchar(max), t.[TextData]) TextData") + " from [" + Table + "]  t left outer join ProfilerEventClass c on c.EventClassID = t.EventClass left outer join ProfilerEventSubclass s on s.EventClassID = t.EventClass and s.EventSubclassID = t.EventSubclass;", conn2).ExecuteNonQuery();
                            SqlCommandInfiniteConstructor("if exists(select * from sys.views where name = '" + Table + "_QueriesAndCommandsIncludingIncomplete') drop view [" + Table + "_IncompleteQueriesAndCommands];", conn2).ExecuteNonQuery();
                            SqlCommandInfiniteConstructor("create view [" + Table + "_QueriesAndCommandsIncludingIncomplete] as select StartRow, EndRow, Duration, EventClass, case when EventClass in (-10, -16) then 0 else 1 end as RequestCompleted, ConnectionID, StartTime from (select min(RowNumber) StartRow, max(RowNumber) EndRow, sum(Duration) Duration, max(EventClass) EventClass, ConnectionID, StartTime from [" + Table + "] where EventClass in (9, 10, 15, 16) group by ConnectionID, StartTime having count(*) = 2 union select StartRow, EndRow, a.[Time Captured in Trace] Duration, -EventClass - (case when EventClass % 2 = 1 then 1 else -1 end) EventClass, ConnectionID, StartTime from(select case when max(EventClass) in (9, 15) then max(RowNumber) else null end StartRow, case when max(EventClass) in (10, 16) then max(RowNumber) else null end EndRow, datediff(\"ms\", max(StartTime),(select max(CurrentTime) from[" + Table + "])) [Time Captured in Trace] from [" + Table + "] a where EventClass in (9, 10, 15, 16) and not StartTime is null group by a.StartTime, ConnectionID having count(*) = 1) a, [" + Table + "] b where b.RowNumber = a.StartRow) a", conn2).ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            SetText("Exception creating event class/subclass view:\r\n" + ex.Message);
                            Trace.WriteLine("Can safely ignore since view creation will fail if necessary EvenClass and/or EventSubclass events are missing.");
                        }
                        SqlCommandInfiniteConstructor("if exists(select * from sys.views where name = '" + Table + "EventClassIndex') drop view [" + Table + "EventClassIndex];", conn2).ExecuteNonQuery();
                        SqlCommandInfiniteConstructor("create index [" + Table + "EventClassIndex] on [" + Table + "] (EventClass)", conn2).ExecuteNonQuery();
                        SqlCommandInfiniteConstructor("if exists(select * from sys.views where name = '" + Table + "ConnectionStarTimeIndex') drop view [" + Table + "ConnectionStarTimeIndex];", conn2).ExecuteNonQuery();
                        SqlCommandInfiniteConstructor("create nonclustered index [" + Table + "ConnectionStarTimeIndex] on [" + Table + "] (ConnectionID, StartTime)", conn2).ExecuteNonQuery();
                        SetText("Merged " + (CurFile + 1).ToString() + " files.");
                        SetText("Created view including incomplete commands and queries at [" + Table + "_QueriesAndCommandsIncludingIncomplete].\r\nCreated event names view [" + Table + "_v].");
                    }
                    conn2.Close();
                    if (!bCancel)
                    {
                        SetText("Database prepared for analysis.");
                    }
                }
                if (bCancel)
                {
                    SetText("Cancelled loading after reading " + String.Format("{0:#,##0}", (RowCount + 1)) + " rows.");
                }
            }
            catch (Exception exc)
            {
                if (!bCancel)
                {
                    Console.WriteLine(exc.ToString(), "Oops!  Exception...");
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// The main entry point.
        /// </summary>
        /// <param name="args">Command line parameters.</param>
        public static void Main(string[] args)
        {
            Console.WriteLine(Resources.ProgramTitle, Utility.ReadVersion());
            if (args == null || (args.Length != 3 && args.Length != 4))
            {
                Console.WriteLine(Resources.ProgramUsage);
                Console.WriteLine(Resources.ProgramUsageExample);
            }
            else
            {
                string scenarioName = args[0];
                string traceFile    = args[1];
                string configFile   = args[2];
                string timingsFile  = (args.Length == 4) ? args[3] : null;

                Stream timings = null;

                try
                {
                    if (timingsFile != null)
                    {
                        if (File.Exists(timingsFile))
                        {
                            try
                            {
                                timings = new FileStream(timingsFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                        }
                        else
                        {
                            Console.WriteLine(Resources.TimingsFileDoesNotExist, timingsFile);
                        }
                    }

                    if (Utility.IsValidIdentifier(scenarioName))
                    {
                        try
                        {
                            WcfUnitConfiguration config = ConfigurationReader.Read(configFile);
                            TraceFileProcessor   tfp    = new TraceFileProcessor();
                            tfp.ProcessTraceFile(scenarioName, traceFile, timings, config);
                        }
                        catch (UserException ue)
                        {
                            Console.WriteLine(ue.Message);
                            Exception e = ue.InnerException;
                            while (e != null)
                            {
                                Console.WriteLine(e.Message);
                                e = e.InnerException;
                            }

                            Environment.Exit(1);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Resources.InvalidScenarioName);
                        Environment.Exit(1);
                    }
                }
                finally
                {
                    if (timings != null)
                    {
                        timings.Dispose();
                    }
                }
            }
        }