コード例 #1
0
ファイル: VBCSCompiler.cs プロジェクト: wizzardmr42/roslyn
        public static int Main(string[] args)
        {
            CompilerServerLogger.Initialize("SRV");
            CompilerServerLogger.Log("Process started");

            var keepAliveTimeout = GetKeepAliveTimeout();

            // Pipename should be passed as the first and only argument to the server process
            // and it must have the form "-pipename:name". Otherwise, exit with a non-zero
            // exit code
            const string pipeArgPrefix = "-pipename:";

            if (args.Length != 1 ||
                args[0].Length <= pipeArgPrefix.Length ||
                !args[0].StartsWith(pipeArgPrefix))
            {
                return(CommonCompiler.Failed);
            }

            var pipeName        = args[0].Substring(pipeArgPrefix.Length);
            var serverMutexName = BuildProtocolConstants.GetServerMutexName(pipeName);

            // VBCSCompiler is installed in the same directory as csc.exe and vbc.exe which is also the
            // location of the response files.
            var clientDirectory      = AppDomain.CurrentDomain.BaseDirectory;
            var sdkDirectory         = RuntimeEnvironment.GetRuntimeDirectory();
            var compilerServerHost   = new DesktopCompilerServerHost(clientDirectory, sdkDirectory);
            var clientConnectionHost = new NamedPipeClientConnectionHost(compilerServerHost, pipeName);

            return(Run(serverMutexName, clientConnectionHost, keepAliveTimeout));
        }
コード例 #2
0
        /// <summary>
        /// Main entry point for the process. Initialize the server dispatcher
        /// and wait for connections.
        /// </summary>
        public static int Main(string[] args)
        {
            CompilerServerLogger.Initialize("SRV");
            CompilerServerLogger.Log("Process started");

            TimeSpan?keepAliveTimeout = null;

            // VBCSCompiler is installed in the same directory as csc.exe and vbc.exe which is also the
            // location of the response files.
            var compilerExeDirectory = AppDomain.CurrentDomain.BaseDirectory;

            try
            {
                int    keepAliveValue;
                string keepAliveStr = ConfigurationManager.AppSettings["keepalive"];
                if (int.TryParse(keepAliveStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out keepAliveValue) &&
                    keepAliveValue >= 0)
                {
                    if (keepAliveValue == 0)
                    {
                        // This is a one time server entry.
                        keepAliveTimeout = null;
                    }
                    else
                    {
                        keepAliveTimeout = TimeSpan.FromSeconds(keepAliveValue);
                    }
                }
                else
                {
                    keepAliveTimeout = s_defaultServerKeepAlive;
                }
            }
            catch (ConfigurationErrorsException e)
            {
                keepAliveTimeout = s_defaultServerKeepAlive;
                CompilerServerLogger.LogException(e, "Could not read AppSettings");
            }

            CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAliveTimeout?.TotalMilliseconds ?? 0);
            FatalError.Handler = FailFast.OnFatalException;

            var dispatcher = new ServerDispatcher(new CompilerRequestHandler(compilerExeDirectory), new EmptyDiagnosticListener());

            dispatcher.ListenAndDispatchConnections(
                BuildProtocolConstants.GetPipeName(compilerExeDirectory),
                keepAliveTimeout,
                watchAnalyzerFiles: true);
            return(0);
        }
コード例 #3
0
        /// <summary>
        /// Main entry point for the process. Initialize the server dispatcher
        /// and wait for connections.
        /// </summary>
        public static int Main(string[] args)
        {
            CompilerServerLogger.Initialize("SRV");
            CompilerServerLogger.Log("Process started");

            TimeSpan?keepAliveTimeout = null;

            try
            {
                int    keepAliveValue;
                string keepAliveStr = ConfigurationManager.AppSettings["keepalive"];
                if (int.TryParse(keepAliveStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out keepAliveValue) &&
                    keepAliveValue >= 0)
                {
                    if (keepAliveValue == 0)
                    {
                        // This is a one time server entry.
                        keepAliveTimeout = null;
                    }
                    else
                    {
                        keepAliveTimeout = TimeSpan.FromSeconds(keepAliveValue);
                    }
                }
                else
                {
                    keepAliveTimeout = s_defaultServerKeepAlive;
                }
            }
            catch (ConfigurationErrorsException e)
            {
                keepAliveTimeout = s_defaultServerKeepAlive;
                CompilerServerLogger.LogException(e, "Could not read AppSettings");
            }

            CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAliveTimeout?.TotalMilliseconds ?? 0);
            FatalError.Handler = FailFast.OnFatalException;

            // VBCSCompiler is installed in the same directory as csc.exe and vbc.exe which is also the
            // location of the response files.
            var responseFileDirectory = CommonCompiler.GetResponseFileDirectory();
            var dispatcher            = new ServerDispatcher(new CompilerRequestHandler(responseFileDirectory), new EmptyDiagnosticListener());

            // Add the process ID onto the pipe name so each process gets a semi-unique and predictable pipe
            // name.  The client must use this algorithm too to connect.
            string pipeName = BuildProtocolConstants.PipeName + Process.GetCurrentProcess().Id.ToString();

            dispatcher.ListenAndDispatchConnections(pipeName, keepAliveTimeout, watchAnalyzerFiles: true);
            return(0);
        }
コード例 #4
0
ファイル: ServerDispatcher.cs プロジェクト: kvainexx/roslyn
        /// <summary>
        /// Main entry point for the process. Initialize the server dispatcher
        /// and wait for connections.
        /// </summary>
        public static int Main(string[] args)
        {
            CompilerServerLogger.Initialize("SRV");
            CompilerServerLogger.Log("Process started");

            TimeSpan?keepAliveTimeout = null;

            // VBCSCompiler is installed in the same directory as csc.exe and vbc.exe which is also the
            // location of the response files.
            var compilerExeDirectory = AppDomain.CurrentDomain.BaseDirectory;

            // Pipename should be passed as the first and only argument to the server process
            // and it must have the form "-pipename:name". Otherwise, exit with a non-zero
            // exit code
            const string pipeArgPrefix = "-pipename:";

            if (args.Length != 1 ||
                args[0].Length <= pipeArgPrefix.Length ||
                !args[0].StartsWith(pipeArgPrefix))
            {
                return(CommonCompiler.Failed);
            }

            var pipeName = args[0].Substring(pipeArgPrefix.Length);

            // Grab the server mutex to prevent multiple servers from starting with the same
            // pipename and consuming excess resources. If someone else holds the mutex
            // exit immediately with a non-zero exit code
            var  serverMutexName = $"{pipeName}.server";
            bool holdsMutex;

            using (var serverMutex = new Mutex(initiallyOwned: true,
                                               name: serverMutexName,
                                               createdNew: out holdsMutex))
            {
                if (!holdsMutex)
                {
                    return(CommonCompiler.Failed);
                }

                try
                {
                    return(Run(keepAliveTimeout, compilerExeDirectory, pipeName));
                }
                finally
                {
                    serverMutex.ReleaseMutex();
                }
            }
        }
コード例 #5
0
ファイル: ServerDispatcher.cs プロジェクト: sperling/cskarp
        private const int DefaultServerKeepAlive = 100; // Minimal timeout

        /// <summary>
        /// Main entry point for the process. Initialize the server dispatcher
        /// and wait for connections.
        /// </summary>
        public static int Main(string[] args)
        {
            CompilerServerLogger.Initialize("SRV");
            CompilerServerLogger.Log("Process started");

            int keepaliveMs;

            // First try to get the die timeout from an environment variable,
            // then try to get the die timeout from the app.config file.
            // Set to default if any failures
            try
            {
                string keepaliveStr;
                if ((keepaliveStr = ConfigurationManager.AppSettings["keepalive"]) != null &&
                    int.TryParse(keepaliveStr, out keepaliveMs) &&
                    keepaliveMs > 0)
                {
                    // The die timeout settings are stored in seconds, not
                    // milliseconds
                    keepaliveMs *= 1000;
                }
                else
                {
                    keepaliveMs = DefaultServerKeepAlive;
                }
                CompilerServerLogger.Log("Die timeout is: " + keepaliveMs + "milliseconds.");
            }
            catch (ConfigurationErrorsException e)
            {
                keepaliveMs = DefaultServerKeepAlive;
                CompilerServerLogger.LogException(e, "Could not read AppSettings");
            }

            CompilerFatalError.Handler = FailFast.OnFatalException;

            var dispatcher = new ServerDispatcher(BuildProtocolConstants.PipeName,
                                                  new CompilerRequestHandler(),
                                                  keepaliveMs);

            dispatcher.ListenAndDispatchConnections();
            return(0);
        }
コード例 #6
0
ファイル: VBCSCompiler.cs プロジェクト: meankurjain/roslyn
        public static int Main(string[] args)
        {
            CompilerServerLogger.Initialize("SRV");
            CompilerServerLogger.Log("Process started");

            string pipeName;
            bool   shutdown;

            if (!ParseCommandLine(args, out pipeName, out shutdown))
            {
                return(CommonCompiler.Failed);
            }

            var cancellationTokenSource = new CancellationTokenSource();

            Console.CancelKeyPress += (sender, e) => { cancellationTokenSource.Cancel(); };

            return(shutdown
                ? RunShutdown(pipeName, cancellationToken: cancellationTokenSource.Token)
                : RunServer(pipeName, cancellationToken: cancellationTokenSource.Token));
        }
コード例 #7
0
        private const int DefaultServerDieTimeout = 3 * 60 * 60 * 1000; // 3 hours

        /// <summary>
        /// Main entry point for the process. Initialize the server dispatcher
        /// and wait for connections.
        /// </summary>
        public static int Main(string[] args)
        {
            int dieTimeout;

            // Try to get the die timeout from the app.config file.
            // Set to default if any failures
            try
            {
                string dieTimeoutStr = ConfigurationManager.AppSettings["dieTimeout"];
                if (!int.TryParse(dieTimeoutStr, out dieTimeout))
                {
                    dieTimeout = DefaultServerDieTimeout;
                }
                else if (dieTimeout > 0)
                {
                    // The die timeout in the app.config file is stored in
                    // seconds, not milliseconds
                    dieTimeout *= 1000;
                }
            }
            catch (ConfigurationErrorsException)
            {
                dieTimeout = DefaultServerDieTimeout;
            }

            CompilerFatalError.Handler = FailFast.OnFatalException;

            CompilerServerLogger.Initialize("SRV");
            CompilerServerLogger.Log("Process started");
            var dispatcher = new ServerDispatcher(BuildProtocolConstants.PipeName,
                                                  new CompilerRequestHandler(),
                                                  dieTimeout);

            //Debugger.Launch();

            dispatcher.ListenAndDispatchConnections();
            return(0);
        }
コード例 #8
0
        /// <summary>
        /// Main entry point for the process. Initialize the server dispatcher
        /// and wait for connections.
        /// </summary>
        public static int Main(string[] args)
        {
            CompilerServerLogger.Initialize("SRV");
            CompilerServerLogger.Log("Process started");

            TimeSpan?keepAliveTimeout = null;

            // VBCSCompiler is installed in the same directory as csc.exe and vbc.exe which is also the
            // location of the response files.
            var compilerExeDirectory = AppDomain.CurrentDomain.BaseDirectory;

            // Pipename should be passed as the first and only argument to the server process
            // and it must have the form "-pipename:name". Otherwise, exit with a non-zero
            // exit code
            const string pipeArgPrefix = "-pipename:";

            if (args.Length != 1 ||
                args[0].Length <= pipeArgPrefix.Length ||
                !args[0].StartsWith(pipeArgPrefix))
            {
                return(CommonCompiler.Failed);
            }

            var pipeName = args[0].Substring(pipeArgPrefix.Length);

            try
            {
                int    keepAliveValue;
                string keepAliveStr = ConfigurationManager.AppSettings["keepalive"];
                if (int.TryParse(keepAliveStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out keepAliveValue) &&
                    keepAliveValue >= 0)
                {
                    if (keepAliveValue == 0)
                    {
                        // This is a one time server entry.
                        keepAliveTimeout = null;
                    }
                    else
                    {
                        keepAliveTimeout = TimeSpan.FromSeconds(keepAliveValue);
                    }
                }
                else
                {
                    keepAliveTimeout = s_defaultServerKeepAlive;
                }
            }
            catch (ConfigurationErrorsException e)
            {
                keepAliveTimeout = s_defaultServerKeepAlive;
                CompilerServerLogger.LogException(e, "Could not read AppSettings");
            }

            CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAliveTimeout?.TotalMilliseconds ?? 0);
            FatalError.Handler = FailFast.OnFatalException;

            var dispatcher = new ServerDispatcher(new CompilerRequestHandler(compilerExeDirectory), new EmptyDiagnosticListener());

            dispatcher.ListenAndDispatchConnections(
                pipeName,
                keepAliveTimeout,
                watchAnalyzerFiles: true);
            return(CommonCompiler.Succeeded);
        }