当前位置: 首页>>代码示例>>C#>>正文


C# Application.Stop方法代码示例

本文整理汇总了C#中Application.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# Application.Stop方法的具体用法?C# Application.Stop怎么用?C# Application.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Application的用法示例。


在下文中一共展示了Application.Stop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            if (args == null || args.Length < 1)
            {
                Usage();
                System.Environment.Exit(1);
            }

            int port = 0;
            var success = Int32.TryParse(args[0], out port);
            if (!success)
            {
                Usage();
                System.Environment.Exit(1);
            }

            bool simulationsSpecified = false;
            string simulationsPath = null;
            Moksy.Common.SimulationCollection simulations = new Common.SimulationCollection();
            simulationsPath = args.FirstOrDefault(f => f.StartsWith("/File:", StringComparison.InvariantCultureIgnoreCase));
            if (simulationsPath != null)
            {
                simulationsPath = simulationsPath.Substring(6);
                simulationsSpecified = true;
            }
            var log = args.FirstOrDefault(f => f.StartsWith("/Log:true", StringComparison.InvariantCultureIgnoreCase) || string.Compare(f, "/log", true) == 0);

            System.Reflection.Assembly thisExe;
            thisExe = System.Reflection.Assembly.GetExecutingAssembly();
            var list = thisExe.GetManifestResourceNames();

            var header = ReadResource("Moksy.Host.Resources.Header.txt");
            var simulationsText = ReadResource("Moksy.Host.Resources.Simulations.txt");

            ApplicationDirectives parameters = new ApplicationDirectives() { Log = (log != null) };

            try
            {
                Console.WriteLine("----------------------------------------------");
                Console.WriteLine("MOKSY: REST API / JSON Endpoint Faking Toolkit");
                Console.WriteLine("----------------------------------------------");
                Console.WriteLine("by Grey Ham");
                Console.WriteLine();
                Console.WriteLine("See www.brekit.com for more information. ");
                Console.WriteLine("Source at https://github.com/greyham/Moksy");
                Console.WriteLine();

                if (simulationsSpecified)
                {
                    Console.Write(string.Format("Loading simulations from {0}...", simulationsPath));

                    var contents = System.IO.File.ReadAllText(simulationsPath);
                    simulations = Newtonsoft.Json.JsonConvert.DeserializeObject<Moksy.Common.SimulationCollection>(contents);

                    Console.WriteLine(string.Format("{0} simulations have been loaded. ", simulations.Count));
                    Console.WriteLine("");

                    // ASSERTION: We have loaded the simulations into memory.
                }

                Application app = new Application(port, parameters);
                app.Start();

                Console.WriteLine(string.Format("Running Moksy on Port {0}. ", port));
                Console.WriteLine(string.Format("Navigate to: http://localhost:{0} for a sanity test.", port));

                if (simulationsSpecified)
                {
                    Task.Factory.StartNew(() =>
                    {
                        Proxy proxy = new Proxy(port);
                        proxy.Wait(20);

                        // We need to wait until the service has started.
                        foreach (var simulation in simulations)
                        {
                            proxy.Add(simulation);
                        }
                    }, TaskCreationOptions.LongRunning
                    );
                }

                Console.WriteLine("Press a key to exit...");
                Console.ReadKey();
                app.Stop();
            }
            catch (System.AggregateException aggregate)
            {
                Console.WriteLine("ERROR: Launching Moksy.Host.Exe");
                Console.WriteLine(aggregate.Message);
                if (aggregate.InnerException.GetType().FullName == "System.ServiceModel.AddressAccessDeniedException")
                {
                    Console.WriteLine();
                    Console.WriteLine("Moksy launches a real HTTP Server and opens up a HTTP Endpoint so that your");
                    Console.WriteLine("tests and other services can hit it. ");
                    Console.WriteLine();
                    Console.WriteLine("By default, only applications launched as Administrator are allowed to");
                    Console.WriteLine("launch the HTTP Server and create the end-point. ");
                    Console.WriteLine();
                    Console.WriteLine("You are not running as Administrator. ");
//.........这里部分代码省略.........
开发者ID:aidancasey,项目名称:Moksy,代码行数:101,代码来源:Program.cs

示例2: StopStopsProjects

        public void StopStopsProjects()
        {
            var started = false;
            var stopped = false;
            var project = new ProjectStub
                              {
                                  Name = "Test",
                                  OnStart = () => started = true,
                                  OnStop = () => stopped = true,
                                  OnLoadState = () => { }
                              };
            var server = new Server(project);
            var application = new Application
                                  {
                                      Configuration = server
                                  };
            application.Start();

            // Give the projects time to start
            SpinWait.SpinUntil(() => started, TimeSpan.FromSeconds(5));
            Assert.IsTrue(started); 
            application.Stop();

            // Give the projects time to stop
            SpinWait.SpinUntil(() => stopped, TimeSpan.FromSeconds(5));
            Assert.IsTrue(stopped);
        }
开发者ID:BiYiTuan,项目名称:CruiseControl.NET,代码行数:27,代码来源:ApplicationTests.cs

示例3: StopClosesCommunications

 public void StopClosesCommunications()
 {
     var cleaned = false;
     var channel = new ChannelStub
                       {
                           OnCleanUpAction = () => cleaned = true
                       };
     var server = new Server("Test", new[] { channel });
     var application = new Application
                           {
                               Configuration = server
                           };
     application.Stop();
     Assert.IsTrue(cleaned);
 }
开发者ID:BiYiTuan,项目名称:CruiseControl.NET,代码行数:15,代码来源:ApplicationTests.cs

示例4: Stop

 public void Stop(Application application)
 {
     application.Stop();
     UpdateApplication(application);
 }
开发者ID:niemyjski,项目名称:ironfoundry,代码行数:5,代码来源:AppsHelper.cs


注:本文中的Application.Stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。