Ejemplo n.º 1
0
        static void SetupCommand(ConsoleShell shell, DeployClient client, bool isAdmin)
        {
            Assembly.GetExecutingAssembly().GetTypes().Where(i => i.IsClass && !i.IsAbstract
                && typeof(XShellCommandBase).IsAssignableFrom(i)).ToList().ForEach(i =>
                {
                    bool load = false;
                    var attr = i.GetCustomAttribute<ShellAuthorityAttribute>();
                    if (attr != null)
                    {
                        if (isAdmin)
                        {
                            load = attr.IsAdministrator;
                        }
                    }
                    else
                    {
                        load = true;
                    }

                    if (load)
                    {
                        var instance = Activator.CreateInstance(i, client);
                        if (instance != null)
                        {
                            shell.SetupCommand(instance as IShellCommand);
                        }
                    }
                });
        }
Ejemplo n.º 2
0
 static void Main(string[] args)
 {
     var bootstrap = BootstrapFactory.CreateBootstrap();
     if (bootstrap.Initialize())
     {
         var result = bootstrap.Start();
         if (result != StartResult.Success)
         {
             Console.WriteLine(DateTime.Now + " 服务启动失败请检查相关日志");
             Console.ReadKey();
         }
         else
         {
             var server = bootstrap.AppServers.First() as DeployServer;
             var shell = new ConsoleShell();
             shell.SetPrefix(server.Name + "> ");
             Assembly.GetExecutingAssembly().GetTypes().Where(i => i.IsClass && !i.IsAbstract
                 && typeof(XShellCommandBase).IsAssignableFrom(i)).ToList().ForEach(i =>
                 {
                     var instance = Activator.CreateInstance(i, server);
                     if (instance != null)
                     {
                         shell.SetupCommand(instance as IShellCommand);
                     }
                 });
             Console.WriteLine("{0} Start Success", server.Name);
             shell.Start();
         }
     }
 }
Ejemplo n.º 3
0
 static void Main(string[] args)
 {
     try
     {
         var shell = new ConsoleShell();
         var client = new DeployClient();
         client.Connected += (sender, e) =>
         {
             ConsoleLogger.InfoFormat("{0} Connected {1} Success", DateTime.Now, client.RemoteEndPoint.ToString());
         };
         client.OnLogin += (sender, e) =>
         {
             string json = JObject.FromObject(e.Data).ToString();
             if (e.Data.Success)
             {
                 shell.SetPrefix(AppConfig.UserName + "> ", true);
                 SetupCommand(shell, client, e.Data.IsAdministrator);
                 ConsoleLogger.Info(json);
             }
             else
             {
                 ConsoleLogger.Error(json);
             }
         };
         client.Error += (sender, e) =>
         {
             ConsoleLogger.ErrorFormat("{0} --> {1}", DateTime.Now, e.Exception);
         };
         client.Closed += (sender, e) =>
         {
             shell.SetPrefix("(nil)> ", true);
             shell.ResetCommand();
             SetupCommand(shell, client, false);
             ConsoleLogger.WarnFormat("{0} Client Closed ", DateTime.Now);
         };
         client.Initialize(new BufferedReceiveFilter());
         SetupCommand(shell, client, false);
         shell.Start();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         Console.ReadKey();
     }
 }