public void Remove(IEnumerable <EndpointToHost> endpoints)
        {
            string localResource;

            if (!SafeRoleEnvironment.TryGetRootPath(LocalResource, out localResource))
            {
                return;
            }

            foreach (var endpoint in endpoints)
            {
                var path = Path.Combine(localResource, endpoint.EndpointName);
                Directory.Delete(path, true);
            }
        }
        public void Provision(IEnumerable <EndpointToHost> endpoints)
        {
            try
            {
                var localResource = SafeRoleEnvironment.GetRootPath(LocalResource);

                foreach (var endpoint in endpoints)
                {
                    endpoint.ExtractTo(localResource);

                    endpoint.EntryPoint = Path.Combine(localResource, endpoint.EndpointName, "NServiceBus.Hosting.Azure.HostProcess.exe");
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message);

                if (RecycleRoleOnError)
                {
                    SafeRoleEnvironment.RequestRecycle();
                }
            }
        }
        public void Start(IEnumerable <EndpointToHost> toHost)
        {
            foreach (var service in toHost)
            {
                try
                {
                    var processStartInfo = new ProcessStartInfo(service.EntryPoint)
                    {
                        UseShellExecute        = false,
                        CreateNoWindow         = true,
                        RedirectStandardInput  = true,
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true
                    };

                    var process = new Process
                    {
                        StartInfo           = processStartInfo,
                        EnableRaisingEvents = true
                    };
                    var processWasKilledOnPurpose = false;

                    process.ErrorDataReceived += (o, args) =>
                    {
                        logger.Error(args.Data);
                        if (process.ExitCode != 0 && !processWasKilledOnPurpose)
                        {
                            if (RecycleRoleOnError)
                            {
                                SafeRoleEnvironment.RequestRecycle();
                            }
                        }
                    };

                    process.OutputDataReceived += (o, args) => logger.Debug(args.Data);

                    process.Exited += (o, args) =>
                    {
                        bool trash;
                        processWasKilledOnPurpose = StoppedProcessIds.TryRemove(process.Id, out trash);
                        if (process.ExitCode != 0 && !processWasKilledOnPurpose)
                        {
                            if (RecycleRoleOnError)
                            {
                                SafeRoleEnvironment.RequestRecycle();
                            }
                        }
                    };

                    process.Start();

                    service.ProcessId = process.Id;

                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);

                    if (RecycleRoleOnError)
                    {
                        SafeRoleEnvironment.RequestRecycle();
                    }
                }
            }
        }
示例#4
0
        public void Start(IEnumerable <EndpointToHost> toHost)
        {
            foreach (var service in toHost)
            {
                try
                {
                    var processStartInfo = new ProcessStartInfo(service.EntryPoint,
                                                                "/serviceName:\"" + service.EndpointName +
                                                                "\" /displayName:\"" + service.EndpointName +
                                                                "\" /description:\"" + service.EndpointName + "\"")
                    {
                        UseShellExecute        = false,
                        CreateNoWindow         = true,
                        RedirectStandardInput  = true,
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true
                    };

                    var process = new Process {
                        StartInfo = processStartInfo, EnableRaisingEvents = true
                    };

                    process.ErrorDataReceived += (o, args) =>
                    {
                        logger.Error(args.Data);

                        if (RecycleRoleOnError)
                        {
                            SafeRoleEnvironment.RequestRecycle();
                        }
                    };

                    process.OutputDataReceived += (o, args) => logger.Debug(args.Data);

                    process.Exited += (o, args) =>
                    {
                        if (process.ExitCode != 0)
                        {
                            if (RecycleRoleOnError)
                            {
                                SafeRoleEnvironment.RequestRecycle();
                            }
                        }
                    };

                    process.Start();

                    service.ProcessId = process.Id;

                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);

                    if (RecycleRoleOnError)
                    {
                        SafeRoleEnvironment.RequestRecycle();
                    }
                }
            }
        }