Ejemplo n.º 1
0
 /// <summary>
 /// 指定した<see cref="DebuggerInfoProvider"/>を登録します。
 /// </summary>
 /// <param name="provider">登録する<see cref="DebuggerInfoProvider"/>。</param>
 public static void Register(DebuggerInfoProvider provider)
 {
     lock (_Providers)
     {
         _Providers.Add(provider);
     }
 }
Ejemplo n.º 2
0
        protected static Process Start <T>(string executableFileName, T parameter, SubprocessConfiguration configuration, Uri address)
        {
            var configPath = Path.Combine(TempDir, "C" + Interlocked.Increment(ref _AssemblyCount) + ".T" + DateTime.Now.Ticks + ".config");

            var configDocument = new ConfigXmlDocument();

            AppendConfig(configDocument, ConfigurationUserLevel.None);
            AppendConfig(configDocument, ConfigurationUserLevel.PerUserRoaming);
            AppendConfig(configDocument, ConfigurationUserLevel.PerUserRoamingAndLocal);

            if (configuration.ShouldCreateConfig)
            {
                if (configDocument.DocumentElement == null)
                {
                    configDocument.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<configuration></configuration>");
                }
                configDocument.Save(configPath);
                configuration.RaiseConfigCreated(new ConfigCreatedEventArgs(configPath));
            }
            else if (configDocument.DocumentElement != null)
            {
                configDocument.Save(configPath);
            }

            var psi = new ProcessStartInfo(executableFileName);

            var spp = new SubprocessArgument <T>();

            spp.TemporaryDirectory = TempDir;
            spp.Address            = address;
            spp.Parameter          = parameter;
            spp.ParentProcessId    = Process.GetCurrentProcess().Id;
            spp.IsStandalone       = configuration.IsStandalone;
            if (configuration.AttachDebugger)
            {
                spp.DebuggerInfo = DebuggerInfoProvider.GetCurrent();
            }

            var argFilePath = Path.Combine(TempDir, "A" + Interlocked.Increment(ref _AssemblyCount) + ".T" + DateTime.Now.Ticks + ".xml");

            using (var fs = new FileStream(argFilePath, FileMode.Create))
            {
                new DataContractSerializer(spp.GetType()).WriteObject(fs, spp);
            }

            psi.Arguments = configDocument.DocumentElement != null
                            ? (argFilePath + " \"" + configPath + "\"")
                            : argFilePath;


            var p = Process.Start(psi);

            return(p);
        }