Beispiel #1
0
        /// <summary>
        /// Write to log file.
        /// </summary>
        private static void WriteToLogFile(string message, string logfilename)
        {
            if (String.IsNullOrEmpty(logfilename) == false)
            {
                sw = new StreamWriterSW(logfilename, true);
                if (String.IsNullOrEmpty(message))
                {
                    sw.WriteLine();
                }
                else
                {
                    sw.WriteLine(message);
                }

                sw.Close();
                sw = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Generate Text file
        /// </summary>
        /// <param name="filetext"></param>
        protected virtual void GenerateFile(string filetext)
        {
            Console.Write("Generating {0} text file .", generatedFile);

            System.Text.Encoding currentencoding = System.Text.Encoding.ASCII;

            if (CommonHelper.FileModified)
            {
                currentencoding = System.Text.Encoding.Unicode;
            }

            StreamWriterSW sw = new StreamWriterSW(generatedFile, false, currentencoding);

            sw.Flush();

            sw.WriteLine(filetext);
            sw.Close();
        }
Beispiel #3
0
        /// <summary>
        /// Generate the application definition file.
        /// </summary>
        /// <param name="xamlFile"></param>
        /// <param name="hostType"></param>
        /// <param name="targetType"></param>
        /// <param name="language"></param>
        /// <param name="additionalAppMarkup"></param>
        private void GenerateAppdef(string xamlFile, string hostType, string targetType, Languages language, string additionalAppMarkup)
        {
            TextWriterSW appdefFile = new StreamWriterSW(_appDefFileName);

            const string sysXmlns = "clr-namespace:System;assembly=mscorlib";

            switch (hostType)
            {
            case "Application":
                if (targetType != "Container")
                {
                    if (!String.IsNullOrEmpty(additionalAppMarkup))
                    {
                        appdefFile.WriteLine("<Application x:Class=\"Application__\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" StartupUri=\"" + PathSW.GetFileName(xamlFile) + "\" DispatcherUnhandledException=\"HandleException\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:sys=\"" + sysXmlns + "\">");
                    }
                    else
                    {
                        appdefFile.WriteLine("<Application x:Class=\"Application__\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" StartupUri=\"" + PathSW.GetFileName(xamlFile) + "\" DispatcherUnhandledException=\"HandleException\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">");
                    }
                }
                else
                if (!String.IsNullOrEmpty(additionalAppMarkup))
                {
                    appdefFile.WriteLine("<Application x:Class=\"Application__\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" DispatcherUnhandledException=\"HandleException\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:sys=\"" + sysXmlns + "\">");
                }
                else
                {
                    appdefFile.WriteLine("<Application x:Class=\"Application__\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" DispatcherUnhandledException=\"HandleException\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">");
                }
                break;

            default:
                throw new TestSetupException("Parameter hostType has invalid value of " + hostType
                                             + ". The only valid value is Application");
            }

            if (!String.IsNullOrEmpty(additionalAppMarkup))
            {
                appdefFile.WriteLine(additionalAppMarkup);
            }


            appdefFile.WriteLine("<x:Code>");
            appdefFile.WriteLine("    <![CDATA[");

            if (language == Languages.CSharp)
            {
                if (AutoCloseWindow)
                {
                    appdefFile.WriteLine("    protected override void OnStartup(System.Windows.StartupEventArgs e)");
                    appdefFile.WriteLine("    {");
                    appdefFile.WriteLine("        Microsoft.Test.Logging.GlobalLog.LogStatus(\"In TestParserApp.OnStartup()...\");");
                    appdefFile.WriteLine("        Microsoft.Test.Logging.GlobalLog.LogStatus(\"Current directory: \" + Microsoft.Test.Security.Wrappers.EnvironmentSW.CurrentDirectory);");

                    appdefFile.WriteLine("        System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();");
                    appdefFile.WriteLine("        timer.Interval = TimeSpan.FromSeconds(10);");
                    appdefFile.WriteLine("        timer.Tick += delegate (object o, EventArgs args) {((System.Windows.Threading.DispatcherTimer)o).Stop(); System.Windows.Application.Current.Shutdown();};");
                    appdefFile.WriteLine("        timer.Start();");
                    appdefFile.WriteLine("    }");
                }

                appdefFile.WriteLine("    public void HandleException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)");
                appdefFile.WriteLine("    {");
                appdefFile.WriteLine("        if(null != e.Exception)");
                appdefFile.WriteLine("        {");
                appdefFile.WriteLine("            e.Handled = true;");
                appdefFile.WriteLine("            Microsoft.Test.Serialization.SerializationHelper.StoreException(e.Exception);");
                appdefFile.WriteLine("            System.Windows.Application.Current.Shutdown();");
                appdefFile.WriteLine("        }");
                appdefFile.WriteLine("    }");
            }
            else // Languages.VisualBasic
            {
                if (AutoCloseWindow)
                {
                    appdefFile.WriteLine("    Protected Overrides Sub OnStartup(ByVal e As System.Windows.StartupEventArgs)");

                    appdefFile.WriteLine("        Dim timer As New System.Windows.Threading.DispatcherTimer()");
                    appdefFile.WriteLine("        timer.Interval = TimeSpan.FromSeconds(5)");
                    appdefFile.WriteLine("        AddHandler timer.Tick, AddressOf TimerHandler");
                    appdefFile.WriteLine("        timer.Start()");


                    appdefFile.WriteLine("    End Sub");

                    appdefFile.WriteLine("    Private Sub TimerHandler(ByVal o As Object, ByVal args As EventArgs)");

                    appdefFile.WriteLine("        Dim timer As System.Windows.Threading.DispatcherTimer");
                    appdefFile.WriteLine("        timer = o");
                    appdefFile.WriteLine("        timer.Stop()");

                    appdefFile.WriteLine("        System.Windows.Application.Current.Shutdown()");

                    appdefFile.WriteLine("    End Sub");
                }

                appdefFile.WriteLine("        Sub HandleException(ByVal sender As Object, ByVal e As System.Windows.Threading.DispatcherUnhandledExceptionEventArgs)");
                appdefFile.WriteLine("            If Not (e.Exception is Nothing)");
                appdefFile.WriteLine("                e.Handled = True");
                appdefFile.WriteLine("                Microsoft.Test.Serialization.SerializationHelper.StoreException(e.Exception)");
                appdefFile.WriteLine("                System.Windows.Application.Current.Shutdown()");
                appdefFile.WriteLine("            End If");
                appdefFile.WriteLine("        End Sub");
            }


            appdefFile.WriteLine("    ]]>");
            appdefFile.WriteLine("</x:Code>");

            // Write end tags.
            switch (hostType)
            {
            case "Application":
                appdefFile.Write("</Application>");
                break;
            }

            appdefFile.Close();
        }