示例#1
0
 public void Stop(IStoppable service)
 {
     try
     {
         service.Stop();
     }
     catch (Exception e)
     {
         OnException(service, e);
     }
 }
示例#2
0
        /// <summary>
        /// Sets the <c>PublicRootActor</c> instances as a <c>IStoppable</c>. (INTERNAL ONLY)
        /// </summary>
        /// <param name="publicRoot">The <c>IStoppable</c> protocol backed by the <c>PublicRootActor</c></param>
        internal void SetPublicRoot(IStoppable publicRoot)
        {
            lock (publicRootMutex)
            {
                if (publicRoot != null && PublicRoot != null)
                {
                    throw new InvalidOperationException("The public root already exists.");
                }

                PublicRoot = publicRoot;
            }
        }
示例#3
0
        public bool Start(HostControl hostControl)
        {
            var applicationFileName = Program.GetApplicationFileName(new string[0]);

            if (!File.Exists(applicationFileName))
            {
                throw new Exception($"Could not find the {applicationFileName} file");
            }

            _stoppable = Program.StartAsync(applicationFileName).Result;
            return(true);
        }
示例#4
0
        /// <summary>
        /// Sets the <c>PrivateRootActor</c> instances as a <c>IStoppable</c>. (INTERNAL ONLY)
        /// </summary>
        /// <param name="privateRoot">The <c>IStoppable</c> protocol backed by the <c>PrivateRootActor</c></param>
        internal void SetPrivateRoot(IStoppable privateRoot)
        {
            lock (privateRootMutex)
            {
                if (privateRoot != null && PrivateRoot != null)
                {
                    privateRoot.Stop();
                    throw new InvalidOperationException("Private root already exists.");
                }

                PrivateRoot = privateRoot;
            }
        }
示例#5
0
 public void SetupStop(bool isLive, IStoppable stoppable)
 {
     if (this.thread != null)
     {
         throw new Exception("ASSERT: Unexpected thread.");
     }
     if (isLive)
     {
         this.stoppable = stoppable;
         Console.WriteLine("Press any key to stop recording!");
         this.thread = new Thread(new ThreadStart(StopRecoding));
         this.thread.Start();
     }
 }
示例#6
0
        public void Start(string logPath, string assemblyPath)
        {
            try
            {
                _path = assemblyPath;
                AppDomain.CurrentDomain.AssemblyResolve    += CurrentDomain_AssemblyResolve;
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                var file = File.CreateText(Path.Combine(logPath, $"Output-{DateTime.Now.ToString("yyyyMMddHHmmss")}.txt"));
                Trace.AutoFlush = true;

                Trace.Listeners.Clear();
                _file = new TextWriterTraceListener(file);
                Trace.Listeners.Add(_file);

                var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
                foreach (var item in new DirectoryInfo(_path).GetFiles("*.dll"))
                {
                    if (allAssemblies.FirstOrDefault(x => x.GetName().Name == item.Name.Replace(".dll", string.Empty)) == null)
                    {
                        var binaries     = File.ReadAllBytes(Path.Combine(_path, item.Name));
                        var thisAssembly = Assembly.Load(binaries);
                        LoadResource(thisAssembly);
                    }
                }

                var type  = typeof(Document);
                var types = AppDomain.CurrentDomain.GetAssemblies()
                            .SelectMany(s => s.GetTypes())
                            .Where(p => type.IsAssignableFrom(p)).ToArray();

                foreach (var item in types)
                {
                    try
                    {
                        var methodInfo = typeof(TypeUtil).GetMethod("RegisterDocument", BindingFlags.Public | BindingFlags.Static);
                        var generic    = methodInfo.MakeGenericMethod(item);
                        generic.Invoke(null, null);
                    }
                    catch (Exception ex) { }
                }

                var application = Application.ParseFromJsonFile(Path.Combine(_path, Bootstrapper.DefaultApplicationFileName));
                _stoppable = Bootstrapper.StartAsync(application, loadAssembliesFromWorkingDirectory: false).Result;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
        }
示例#7
0
        public void Start(string[] startupArguments, ServiceStoppedCallback serviceStoppedCallback)
        {
            var optionsParserResult = Parser.Default.ParseArguments <Options>(startupArguments);

            if (optionsParserResult.Tag == ParserResultType.NotParsed)
            {
                throw new ArgumentException("Invalid arguments");
            }
            var options = ((Parsed <Options>)optionsParserResult).Value;

            options.RunAsService = false;
            options.ServiceName  = ServiceName;
            var applicationJsonPath = ConsoleRunner.GetApplicationJsonPath(options);

            using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(options.StartTimeout)))
            {
                _stoppable = ConsoleRunner.StartAsync(applicationJsonPath, cts.Token).Result;
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="isLive"></param>
        /// <param name="stoppable"></param>
        public void SetupStop(bool isLive, IStoppable stoppable)
        {
            if (_thread != null)
            {
                throw new Exception();
            }

            if (isLive == false)
            {
                return;
            }

            _stoppable = stoppable;
            Console.WriteLine("Press any key to stop recording!");

            _thread = new Thread(() =>
            {
                Console.ReadKey(true);
                _stoppable.Stop();
            });

            _thread.Start();
        }
示例#9
0
        /// <summary>
        /// Creates and starts an application with the given settings.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <param name="application">The application instance. If not defined, the class will look for an application.json file in the current directory.</param>
        /// <param name="builder">The builder instance to be used.</param>
        /// <param name="typeResolver">The resolver for type names.</param>
        /// <param name="logger">The logger instance to be used.</param>
        public static async Task <IStoppable> StartAsync(
            CancellationToken cancellationToken,
            Application application    = null,
            BlipClientBuilder builder  = null,
            ITypeResolver typeResolver = null,
            ILogger logger             = null)
        {
            if (application == null)
            {
                if (!File.Exists(DefaultApplicationFileName))
                {
                    throw new FileNotFoundException($"Could not find the '{DefaultApplicationFileName}' file", DefaultApplicationFileName);
                }
                application = Application.ParseFromJsonFile(DefaultApplicationFileName);
            }

            if (builder == null)
            {
                builder = new BlipClientBuilder(new TcpTransportFactory(), logger);
            }
            if (application.Identifier != null)
            {
                if (application.Password != null)
                {
                    builder = builder.UsingPassword(application.Identifier, application.Password);
                }
                else if (application.AccessKey != null)
                {
                    builder = builder.UsingAccessKey(application.Identifier, application.AccessKey);
                }
                else
                {
                    throw new ArgumentException("At least an access key or password must be defined", nameof(application));
                }
            }
            else
            {
                builder = builder.UsingGuest();
            }

            if (application.Instance != null)
            {
                builder = builder.UsingInstance(application.Instance);
            }
            if (application.RoutingRule != null)
            {
                builder = builder.UsingRoutingRule(application.RoutingRule.Value);
            }
            if (application.Domain != null)
            {
                builder = builder.UsingDomain(application.Domain);
            }
            if (application.Scheme != null)
            {
                builder = builder.UsingScheme(application.Scheme);
            }
            if (application.HostName != null)
            {
                builder = builder.UsingHostName(application.HostName);
            }
            if (application.Port != null)
            {
                builder = builder.UsingPort(application.Port.Value);
            }
            if (application.SendTimeout != 0)
            {
                builder = builder.WithSendTimeout(TimeSpan.FromMilliseconds(application.SendTimeout));
            }
            if (application.SessionEncryption.HasValue)
            {
                builder = builder.UsingEncryption(application.SessionEncryption.Value);
            }
            if (application.SessionCompression.HasValue)
            {
                builder = builder.UsingCompression(application.SessionCompression.Value);
            }
            if (application.Throughput != 0)
            {
                builder = builder.WithThroughput(application.Throughput);
            }
            if (application.DisableNotify)
            {
                builder = builder.WithAutoNotify(false);
            }
            if (application.ChannelCount.HasValue)
            {
                builder = builder.WithChannelCount(application.ChannelCount.Value);
            }
            if (application.ReceiptEvents != null && application.ReceiptEvents.Length > 0)
            {
                builder = builder.WithReceiptEvents(application.ReceiptEvents);
            }
            else if (application.ReceiptEvents != null)
            {
                builder = builder.WithReceiptEvents(new[] { Event.Failed });
            }

            if (typeResolver == null)
            {
                typeResolver = new TypeResolver();
            }
            var localServiceProvider = BuildServiceProvider(application, typeResolver);

            localServiceProvider.RegisterService(typeof(BlipClientBuilder), builder);

            var client = await BuildClientAsync(application, builder.Build, localServiceProvider, typeResolver, cancellationToken, logger : logger);

            var stoppables = new IStoppable[2];

            stoppables[0] = client;
            var startable = await BuildStartupAsync(application, localServiceProvider, typeResolver);

            if (startable != null)
            {
                stoppables[1] = startable as IStoppable;
            }

            return(new StoppableWrapper(stoppables));
        }
示例#10
0
 static void Sammuta(IStoppable laite)
 {
     laite.Stop();
 }
示例#11
0
 static void Shutdown(IStoppable machine)
 {
     machine.Stop();
 }
    static void Main(string[] args)
    {
        HondaAccord danielsCar = new HondaAccord();
            ChevySilverado casonsdreamCar = new ChevySilverado();
            Ford150 tomsCar = new Ford150();

            Car[] cars = new Car[3];
            cars[0] = danielsCar;
            cars[1] = casonsdreamCar;
            cars[2] = tomsCar;

            IStoppable[] vehicles = new IStoppable[3];
            vehicles[0] = danielsCar;
            vehicles[1] = casonsdreamCar;
            //vehicles[2] = tomsCar;
            foreach (var v in vehicles)
            {
                v.Brake();
            }

            Square s = new Square();

            s.LengthOfSide = 10;

            Triangle t = new Triangle();
            t.LengthOfSide = 5;

            //Polygon p = new Polygon();
            //p.NumberOfSides = 6;
            //p.LengthOfSide = 10;

            var areaOfP = s.GetArea();
            Console.WriteLine($"The area is {areaOfP} for this {s.GetShapeName()}. # of sides: {s.NumberOfSides}. Length of Sides: {s.LengthOfSide}");

            var areaOfP2 = t.GetArea();
            Console.WriteLine($"The area is {areaOfP2} for this {t.GetShapeName()}. # of sides: {t.NumberOfSides}. Length of Sides: {t.LengthOfSide}");

            Console.ReadLine();
    }
示例#13
0
 /// <summary>
 /// Stops the tranport listener.
 /// </summary>
 /// <returns></returns>
 public static Task StopAsync(this IStoppable stoppable) => stoppable.StopAsync(CancellationToken.None);
示例#14
0
        /// <summary>
        /// Creates ans starts an application with the given settings.
        /// </summary>
        /// <param name="application">The application instance. If not defined, the class will look for an application.json file in the current directory.</param>
        /// <param name="loadAssembliesFromWorkingDirectory">if set to <c>true</c> indicates to the bootstrapper to load all assemblies from the current working directory.</param>
        /// <param name="path">Assembly path to load</param>
        /// <param name="builder">The builder instance to be used.</param>
        /// <param name="typeResolver">The type provider.</param>
        /// <returns></returns>
        /// <exception cref="System.IO.FileNotFoundException">Could not find the '{DefaultApplicationFileName}'</exception>
        /// <exception cref="System.ArgumentException">At least an access key or password must be defined</exception>
        /// <exception cref="FileNotFoundException"></exception>
        /// <exception cref="ArgumentException">At least an access key or password must be defined</exception>
        /// <exception cref="FileNotFoundException"></exception>
        /// <exception cref="ArgumentException">At least an access key or password must be defined</exception>
        public static async Task <IStoppable> StartAsync(
            Application application = null,
            bool loadAssembliesFromWorkingDirectory = true,
            string path = ".",
            MessagingHubClientBuilder builder = null,
            ITypeResolver typeResolver        = null)
        {
            if (application == null)
            {
                if (!File.Exists(DefaultApplicationFileName))
                {
                    throw new FileNotFoundException($"Could not find the '{DefaultApplicationFileName}' file", DefaultApplicationFileName);
                }
                application = Application.ParseFromJsonFile(DefaultApplicationFileName);
            }

            if (loadAssembliesFromWorkingDirectory)
            {
                ReferencesUtil.LoadAssembliesAndReferences(path, assemblyFilter: ReferencesUtil.IgnoreSystemAndMicrosoftAssembliesFilter, ignoreExceptionLoadingReferencedAssembly: true);
            }

            if (builder == null)
            {
                builder = new MessagingHubClientBuilder();
            }
            if (application.Identifier != null)
            {
                if (application.Password != null)
                {
                    builder = builder.UsingPassword(application.Identifier, application.Password);
                }
                else if (application.AccessKey != null)
                {
                    builder = builder.UsingAccessKey(application.Identifier, application.AccessKey);
                }
                else
                {
                    throw new ArgumentException("At least an access key or password must be defined", nameof(application));
                }
            }
            else
            {
                builder = builder.UsingGuest();
            }

            if (application.Instance != null)
            {
                builder = builder.UsingInstance(application.Instance);
            }
            if (application.RoutingRule != null)
            {
                builder = builder.UsingRoutingRule(application.RoutingRule.Value);
            }
            if (application.Domain != null)
            {
                builder = builder.UsingDomain(application.Domain);
            }
            if (application.Scheme != null)
            {
                builder = builder.UsingScheme(application.Scheme);
            }
            if (application.HostName != null)
            {
                builder = builder.UsingHostName(application.HostName);
            }
            if (application.Port != null)
            {
                builder = builder.UsingPort(application.Port.Value);
            }
            if (application.SendTimeout != 0)
            {
                builder = builder.WithSendTimeout(TimeSpan.FromMilliseconds(application.SendTimeout));
            }
            if (application.SessionEncryption.HasValue)
            {
                builder = builder.UsingEncryption(application.SessionEncryption.Value);
            }
            if (application.SessionCompression.HasValue)
            {
                builder = builder.UsingCompression(application.SessionCompression.Value);
            }
            if (application.Throughput != 0)
            {
                builder = builder.WithThroughput(application.Throughput);
            }
            if (application.ChannelBuffer != 0)
            {
                builder = builder.WithChannelBuffer(application.ChannelBuffer);
            }
            if (application.DisableNotify)
            {
                builder = builder.WithAutoNotify(false);
            }
            if (application.ChannelCount.HasValue)
            {
                builder = builder.WithChannelCount(application.ChannelCount.Value);
            }
            if (application.ReceiptEvents != null && application.ReceiptEvents.Any())
            {
                builder = builder.WithReceiptEvents(application.ReceiptEvents);
            }
            else if (application.ReceiptEvents != null)
            {
                builder = builder.WithReceiptEvents(new[] { Event.Failed });
            }

            if (typeResolver == null)
            {
                typeResolver = TypeResolver.Instance;
            }

            var localServiceProvider = BuildServiceProvider(application, typeResolver);

            localServiceProvider.RegisterService(typeof(MessagingHubClientBuilder), builder);

            var client = await BuildMessagingHubClientAsync(application, builder.Build, localServiceProvider, typeResolver);

            await client.StartAsync().ConfigureAwait(false);

            var stoppables = new IStoppable[2];

            stoppables[0] = client;
            var startable = await BuildStartupAsync(application, localServiceProvider, typeResolver);

            if (startable != null)
            {
                stoppables[1] = startable as IStoppable;
            }

            return(new StoppableWrapper(stoppables));
        }
示例#15
0
 public void SetupStop(bool isLive, IStoppable stoppable)
 {
     if (this.thread != null) {
       throw new Exception("ASSERT: Unexpected thread.");
     }
     if (isLive) {
       this.stoppable = stoppable;
       Console.WriteLine("Press any key to stop recording!");
       this.thread = new Thread(new ThreadStart(StopRecoding));
       this.thread.Start();
     }
 }
示例#16
0
 public ExitGameInteractor(IStoppable target)
 {
     this.target = target;
 }