Esempio n. 1
0
        public async Task AttachDebugger(string host, bool local = false)
        {
            string  target = GetStartupAssemblyPath();
            string  exe = null, debug = null;
            string  outputDirectory  = Path.GetDirectoryName(target);
            string  url              = null;
            string  serverurl        = null;
            string  page             = null;
            string  workingDirectory = null;
            string  arguments        = null;
            Project startup          = GetStartupProject();
            var     props            = startup.ConfigurationManager.ActiveConfiguration.Properties;

            //Dump(startup);

            bool isWeb = ((object[])startup.ExtenderNames).Any(x => x.ToString() == "WebApplication") || startup.Object is VsWebSite.VSWebSite;

            var isNet4        = true;
            var frameworkprop = props.Get("TargetFrameworkMoniker")
                                ?.Split(',')
                                .Where(t => t.StartsWith("Version="))
                                .Select(t => t.Substring("Version=".Length))
                                .FirstOrDefault();

            isNet4 = (frameworkprop == null || string.Compare(frameworkprop, "v4.0") >= 0);
            Frameworks framework = isNet4 ? Frameworks.Net4 : Frameworks.Net2;

            var action = "0";

            action           = props.Get("StartAction");
            exe              = props.Get("StartProgram");
            arguments        = props.Get("StartArguments");
            workingDirectory = props.Get("StartWorkingDirectory");
            url              = props.Get("StartURL");
            page             = props.Get("StartPage");

            if (isWeb)
            {
                outputDirectory = Path.GetDirectoryName(outputDirectory);
                var ext = (WAProjectExtender)startup.Extender["WebApplication"];
                action    = ext.DebugStartAction.ToString();
                serverurl = ext.BrowseURL ?? ext.NonSecureUrl ?? ext.SecureUrl ?? ext.IISUrl ?? "http://127.0.0.1:9000";
                var uri  = new Uri(serverurl);
                var port = uri.Port;
                if (ext.UseIIS)                   // when running IIS, use random xsp port
                {
                    port      = 15000 + new Random(target.GetHashCode()).Next(5000);
                    uri       = new Uri($"{uri.Scheme}://{uri.Host}:{port}");
                    serverurl = uri.AbsoluteUri;
                }

                var task = new StartWebTask()
                {
                    Framework = framework, LogLevels = "All", NetFXBuild = false, OpenUrl = serverurl, Ssl = uri.Scheme.StartsWith("https"), SourcePath = outputDirectory, XspPort = port
                };

                if (action == "2")
                {
                    task.StartProgram = new StartProgramTask()
                    {
                        Program = ext.StartExternalProgram, Arguments = ext.StartCmdLineArguments, WorkingDir = ext.StartWorkingDirectory
                    };
                }
                else if (action == "3")
                {
                    task.OpenUrl = ext.StartExternalUrl;
                }
                else if (action == "0")
                {
                    task.OpenUrl = ext.CurrentDebugUrl;
                }
                else if (action == "1")
                {
                    task.OpenUrl = ext.StartPageUrl;
                }

                await StartDebugger(Server.Default, task);
            }
            else
            {
                var outputType = startup.Properties.Get("OutputType");                 // output type (0: windows app, 1: console app, 2: class lib)
                if (outputType == "2")
                {
                    throw new InvalidOperationException("Cannot start a class library.");
                }

                var appType = outputType == "0" ? ApplicationTypes.WindowsApplication : ApplicationTypes.ConsoleApplication;

                var task = new StartProgramTask()
                {
                    Framework = framework, NetFXBuild = false, Program = target, Arguments = arguments, SourcePath = outputDirectory, WorkingDir = workingDirectory
                };

                if (action == "2")
                {
                    System.Diagnostics.Process.Start(url);
                }
                else if (action == "1")
                {
                    var run = new ProcessStartInfo(exe, arguments)
                    {
                        WorkingDirectory = workingDirectory,
                        UseShellExecute  = false,
                        CreateNoWindow   = false
                    };
                    System.Diagnostics.Process.Start(run);
                }
            }
        }
Esempio n. 2
0
        public async void Start()
        {
            try {
                BuildSolution();

                string  target           = GetStartupAssemblyPath();
                string  exe              = null;
                string  outputDirectory  = Path.GetDirectoryName(target);
                string  url              = null;
                string  serverurl        = null;
                string  page             = null;
                string  workingDirectory = null;
                string  arguments        = null;
                Project startup          = GetStartupProject();
                var     props            = startup.ConfigurationManager.ActiveConfiguration.Properties;

                //Dump(startup);

                bool isWeb = ((object[])startup.ExtenderNames).Any(x => x.ToString() == "WebApplication") || startup.Object is VsWebSite.VSWebSite;

                var isNet4        = true;
                var frameworkprop = props.Get("TargetFrameworkMoniker")
                                    ?.Split(',')
                                    .Where(t => t.StartsWith("Version="))
                                    .Select(t => t.Substring("Version=".Length))
                                    .FirstOrDefault();
                isNet4 = (frameworkprop == null || string.Compare(frameworkprop, "v4.0") >= 0);

                var action = "0";
                action           = props.Get("StartAction");
                exe              = props.Get("StartProgram");
                arguments        = props.Get("StartArguments");
                workingDirectory = props.Get("StartWorkingDirectory");
                url              = props.Get("StartURL");
                page             = props.Get("StartPage");

                if (isWeb)
                {
                    var ext = (WAProjectExtender)startup.Extender["WebApplication"];
                    action          = ext.DebugStartAction.ToString();
                    outputDirectory = new Uri(ext.OpenedURL).LocalPath;
                    serverurl       = ext.BrowseURL ?? ext.NonSecureUrl ?? ext.SecureUrl ?? ext.IISUrl ?? "http://127.0.0.1:9000";
                    var uri  = new Uri(serverurl);
                    var port = uri.Port;
                    if (ext.UseIIS)                       // when running IIS, use random xsp port
                    {
                        port      = 15000 + new Random(target.GetHashCode()).Next(5000);
                        uri       = new Uri($"{uri.Scheme}://{uri.Host}:{port}");
                        serverurl = uri.AbsoluteUri;
                    }
                    var ssl = uri.Scheme.StartsWith("https");

                    var task = new StartWebTask()
                    {
                        Framework  = isNet4 ? Frameworks.Net4 : Frameworks.Net2,
                        LogLevels  = "All",
                        NetFXBuild = false,
                        SourcePath = outputDirectory,
                        Ssl        = ssl,
                        XspPort    = port
                    };

                    if (action == "2")
                    {
                        task.StartProgram = new StartProgramTask()
                        {
                            Program    = ext.StartExternalProgram,
                            Arguments  = ext.StartCmdLineArguments,
                            WorkingDir = ext.StartWorkingDirectory,
                        };
                    }
                    else if (action == "3")
                    {
                        task.OpenUrl = ext.StartExternalUrl;
                        return;
                    }
                    else if (action == "0")
                    {
                        task.OpenUrl = ext.CurrentDebugUrl;
                    }
                    else if (action == "1")
                    {
                        task.OpenUrl = ext.StartPageUrl;
                    }

                    Server.Default.Start(task);
                }
                else
                {
                    if (action == "0" || action == "2")
                    {
                        exe = target;
                    }

                    var task = new StartProgramTask()
                    {
                        Program    = exe,
                        Arguments  = arguments,
                        WorkingDir = workingDirectory
                    };

                    Server.Default.Start(task);

                    if (action == "2")
                    {
                        System.Diagnostics.Process.Start(url);
                    }
                }
            } catch (Exception ex) {
                logger.Error(ex);
                MessageBox.Show(ex.Message, "MonoTools.Debugger", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Static method to generate an example configuration as file or string
        /// </summary>
        /// <param name="file">File name of the demo configuration</param>
        /// <param name="type">Task type of the demo configuration</param>
        /// <param name="asFile">If true a file will be generated, otherwise a string returned</param>
        private static string CreateDemoFile(string file, TaskType type, bool asFile)
        {
            Task t = new Task();

            t.TaskName    = "Demo-Task";
            t.Description = "This is a demo Task with several sub-tasks of the type " + type.ToString();
            t.Type        = type;
            SubTask tb = null;
            SubTask t1, t2, t3;

            if (type == TaskType.DeleteFile)
            {
                tb = new DeleteFileTask();
            }
            else if (type == TaskType.DeleteRegKey)
            {
                tb = new DeleteRegKeyTask();
            }
            else if (type == TaskType.StartProgram)
            {
                tb = new StartProgramTask();
            }
            else if (type == TaskType.WriteLog)
            {
                tb = new WriteLogTask();
            }
            else if (type == TaskType.ControlService)
            {
                tb = new ControlServiceTask();
            }
            else if (type == TaskType.KillProcess)
            {
                tb = new KillProcessTask();
            }
            else if (type == TaskType.MetaTask)
            {
                tb = new MetaTask();
            }
            t1 = tb.GetDemoFile(1);
            t2 = tb.GetDemoFile(2);
            t3 = tb.GetDemoFile(3);
            t3.UseParameter = true;
            t3.MainValue    = "PARAM_NAME_1";
            t3.Description  = t3.Description + ". This Sub-Tasks uses a value of a global Parameter (passed as flag -p|--param) with the parameter name PARAM_NAME_1";
            t.Items.Add(t1);
            t.Items.Add(t2);
            t.Items.Add(t3);
            if (asFile == true)
            {
                t.Serialize(file);
                return("");
            }
            else
            {
                try
                {
                    MemoryStream ms     = t.SerializeAsStream();
                    StreamReader sr     = new StreamReader(ms);
                    string       output = sr.ReadToEnd();
                    ms.Close();
                    ms.Dispose();
                    return(output);
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("Error while loading demo file as string\n" + e.Message);
                    return("");
                }
            }
        }