Exemplo n.º 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;
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Enables logging LHCompiler debug info to file.
        /// </summary>
        /// <value></value>
        public static void LogToFile(string write)
        {
            if (String.IsNullOrEmpty(logfilename))
            {
                logfilename = @"LHCompiler.log";
            }

            logfilename = PathSW.GetFullPath(logfilename);

            switch (write)
            {
            case "Overwrite":
                sw = new StreamWriterSW(logfilename);
                sw.Flush();
                break;

            case "Append":
                if (FileSW.Exists(logfilename))
                {
                    sw = new StreamWriterSW(logfilename, true);
                }
                else
                {
                    sw = new StreamWriterSW(logfilename);
                    sw.Flush();
                }
                break;

            default:
                break;
            }

            if (sw != null)
            {
                sw.Close();
            }
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        private List <ErrorWarningCode> CompileInternal(bool saveProjFile)
        {
            if (FileSW.Exists("ClickOnceTest.pfx"))
            {
                MSBuildProjExecutor.CleanSignFile = false;
            }


            MSBuildProjExecutor build = new MSBuildProjExecutor();

            build.CreateProject();
            build.CreateBuildPropertyGroup("");
            build.CreateBuildItemGroup("");
            build.AddProperty("Configuration", SetupParams.Configuration);
            build.AddProperty("Platform", "AnyCPU");
            build.AddProperty("XamlDebuggingInformation", Convert.ToString(SetupParams.XamlDebuggingInformation));
            build.AddProperty("OutputType", SetupParams.OutputType);

            if (!IsLibrary() && SetupParams.GenerateManifests)
            {
                build.AddProperty("GenerateManifests", Convert.ToString(SetupParams.GenerateManifests));
            }

            string hostInBrowser = "false";

            if (SetupParams.HostInBrowser)
            {
                hostInBrowser = "true";
            }

            build.AddProperty("HostinBrowser", hostInBrowser);

            string localPath = SetupParams.LocalPath;

            if (String.IsNullOrEmpty(localPath))
            {
                localPath = DirectorySW.GetCurrentDirectory();
            }

            if (!IsLibrary() && SetupParams.TargetZone == "")
            {
                // This is for Full Trust Compilation
                string appManifest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                     "<asmv1:assembly manifestVersion=\"1.0\" xmlns=\"urn:schemas-microsoft-com:asm.v1\" xmlns:asmv1=\"urn:schemas-microsoft-com:asm.v1\" xmlns:asmv2=\"urn:schemas-microsoft-com:asm.v2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
                                     "  <trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v2\">" +
                                     "    <security>" +
                                     "      <applicationRequestMinimum>" +
                                     "        <PermissionSet class=\"System.Security.PermissionSet\" version=\"1\" Unrestricted=\"true\" ID=\"Custom\" SameSite=\"site\" />" +
                                     "        <defaultAssemblyRequest permissionSetReference=\"Custom\" />" +
                                     "      </applicationRequestMinimum>" +
                                     "    </security>" +
                                     "  </trustInfo>" +
                                     "</asmv1:assembly>";

                string securityManifestFullTrust = "<Security>" +
                                                   "    <ApplicationRequestMinimum>" +
                                                   "        <PermissionSet ID=\"FT\" temp:Unrestricted=\"true\" />" +
                                                   "        <DefaultAssemblyRequest PermissionSetReference=\"FT\" />" +
                                                   "      </ApplicationRequestMinimum>" +
                                                   "</Security>";


                FileStreamSW   fs     = null;
                StreamWriterSW writer = null;

                if (!FileSW.Exists(app_manifest))
                {
                    try
                    {
                        string path = PathSW.Combine(localPath, app_manifest);
                        fs     = new FileStreamSW(path, FileMode.Create, FileAccess.Write);
                        writer = new StreamWriterSW((Stream)fs.InnerObject);
                        writer.Write(appManifest);
                    }
                    finally
                    {
                        if (writer != null)
                        {
                            writer.Close();
                        }
                        if (fs != null)
                        {
                            fs.Close();
                        }
                    }
                }

                if (!FileSW.Exists(SecurityManifestFullTrust))
                {
                    try
                    {
                        string path = PathSW.Combine(localPath, SecurityManifestFullTrust);
                        fs     = new FileStreamSW(path, FileMode.Create, FileAccess.Write);
                        writer = new StreamWriterSW((Stream)fs.InnerObject);
                        writer.Write(securityManifestFullTrust);
                    }
                    finally
                    {
                        if (writer != null)
                        {
                            writer.Close();
                        }
                        if (fs != null)
                        {
                            fs.Close();
                        }
                    }
                }


                build.AddProperty("TargetZone", "Custom");
                build.AddItem("None", app_manifest);
                build.AddItem("None", SecurityManifestFullTrust);
            }

            build.AddProperty("AssemblyName", SetupParams.AssemblyName);

            build.AddProperty("OutputPath", SetupParams.OutputPath);

            build.AddProperty("RootNamespace", SetupParams.RootNamespace);

            build.AddProperty("UICulture", SetupParams.UICulture);

            if (!IsLibrary())
            {
                build.AddItem("None", "ClickOnceTest.pfx");

                build.AddProperty("SignManifests", "true");
                build.AddProperty("ManifestKeyFile", "ClickOnceTest.pfx");
                build.AddProperty("ManifestCertificateThumbprint", "cd582af19e477ae94a53102e0453e71b3c592a80");
            }

            if (SetupParams.Language == Languages.CSharp)
            {
                build.AddImport(MSBuildDirectory + @"\Microsoft.CSharp.targets");
            }
            else
            {
                build.AddImport(MSBuildDirectory + @"\Microsoft.VisualBasic.targets");
            }

            build.AddImport(MSBuildDirectory + @"\Microsoft.WinFx.targets");

            if (!String.IsNullOrEmpty(SetupParams.ApplicationDefinition))
            {
                build.AddItem("ApplicationDefinition", SetupParams.ApplicationDefinition);
            }

            for (int i = 0; i < SetupParams.XamlPages.Count; i++)
            {
                build.AddItem("Page", SetupParams.XamlPages[i]);
            }

            for (int i = 0; i < SetupParams.CompileFiles.Count; i++)
            {
                build.AddItem("Compile", SetupParams.CompileFiles[i]);
            }

            for (int i = 0; i < SetupParams.Resources.Count; i++)
            {
                build.AddResource(SetupParams.Resources[i].FileName, SetupParams.Resources[i].FileStorage, "");
            }

            for (int i = 0; i < SetupParams.Contents.Count; i++)
            {
                build.AddContent(SetupParams.Contents[i].FileName, SetupParams.Contents[i].CopyToOutputDirectory, "");
            }

            for (int i = 0; i < SetupParams.References.Count; i++)
            {
                build.AddReference(SetupParams.References[i].FileName, "", SetupParams.References[i].HintPath, "");
            }

            //HACK
            build.CommandLineArguements = "/t:Build";

            if (saveProjFile)
            {
                build.SaveProjectFile = Path.Combine(localPath, "__CompilerServicesSave.proj");
            }

            build.Build();

            if (saveProjFile)
            {
                build.SaveProjectFile = Path.Combine(localPath, "__CompilerServicesSave.proj");
            }

            if (build.OutputDirectory != null && !IsLibrary())
            {
                string compiledExtension;
                if (SetupParams.HostInBrowser)
                {
                    compiledExtension = ApplicationDeploymentHelper.BROWSER_APPLICATION_EXTENSION;
                }
                else
                {
                    compiledExtension = ApplicationDeploymentHelper.STANDALONE_APPLICATION_EXTENSION;
                }

                if (SetupParams.GenerateManifests)
                {
                    string fileToSign = PathSW.Combine(build.OutputDirectory, SetupParams.AssemblyName + compiledExtension);
#if (!STRESS_RUNTIME)
                    Microsoft.Test.Logging.GlobalLog.LogStatus("Signing file: " + fileToSign);
#endif
//MQ                    AvalonDeploymentHelper.SignManifest(fileToSign);
                }
            }

            return(build.UnhandledErrorsandWarningsList);
        }