Example #1
0
        public static MySqlConnection GetConnection()
        {
            MySqlConnection connection;

            try
            {
                Dictionary <string, string> defaults = new Dictionary <string, string>();
                defaults.Add("connectionString", "datasource=localhost;port=3306;username=talky;password=talky;");
                defaults.Add("database", "talky");

                ConfigurationFile config = new ConfigurationFile("database");
                if (!config.Exists())
                {
                    config.Write(defaults);
                }

                string connectionString;
                string db;
                config.Values(defaults).TryGetValue("connectionString", out connectionString);
                config.Values(defaults).TryGetValue("database", out db);

                connection = new MySqlConnection(connectionString);
                connection.Open();
                connection.ChangeDatabase(db);

                return(connection);
            } catch (MySqlException e)
            {
                Program.Instance.OHGODNO("Terminate!! Could not connect to MySQL!! Danger!! Danger!!", e);
                return(null);
            }
        }
        /// <summary>
        /// Initialize the Steeltoe Configuration file.
        /// </summary>
        /// <exception cref="ToolingException">If an error occurs when initialization the Steeltoe Configuration file.</exception>
        protected override void Execute()
        {
            var path = _path == null
                ? Context.ProjectDirectory
                : Path.Combine(Context.ProjectDirectory, _path);

            var cfgFile = new ConfigurationFile(path);

            if (cfgFile.Exists())
            {
                if (!_force)
                {
                    throw new ToolingException("Steeltoe Developer Tools already initialized");
                }

                File.Delete(cfgFile.File);
                cfgFile = new ConfigurationFile(path);
            }

            Context.Configuration = cfgFile.Configuration;

            if (_autodetect)
            {
                foreach (var appInfo in new AppScanner().Scan(Context.ProjectDirectory))
                {
                    // TODO: guess framework/runtime rather than hardcode
                    new AddAppExecutor(appInfo.App, "netcoreapp2.1", "win10-x64").Execute(Context);
                }
            }

            cfgFile.Store();
            Context.Console.WriteLine("Initialized Steeltoe Developer Tools");
        }
Example #3
0
        protected override void Execute()
        {
            Context.Console.WriteLine($"Steeltoe Developer Tools version ... {Program.GetVersion()}");

            // dotnet
            Context.Console.Write("DotNet ... ");
            var dotnetVersion = new Tooling.Cli("dotnet", Context.Shell).Run("--version").Trim();

            Context.Console.WriteLine($"dotnet version {dotnetVersion}");

            // is intialized?
            Context.Console.Write("initialized ... ");
            var cfgFile = new ConfigurationFile(Context.ProjectDirectory);

            if (!cfgFile.Exists())
            {
                Context.Console.WriteLine($"!!! no (run '{Program.Name} {InitCommand.Name}' to initialize)");
                return;
            }

            Context.Console.WriteLine("yes");

            // target deployment environment
            Context.Console.Write("target ... ");
            string target = cfgFile.Configuration.Target;

            if (target == null)
            {
                Context.Console.WriteLine($"!!! not set (run '{Program.Name} {TargetCommand.Name} <env>' to set)");
                return;
            }

            Context.Console.WriteLine(target);
            Registry.GetTarget(target).IsHealthy(Context);
        }
Example #4
0
        protected int OnExecute(CommandLineApplication app)
        {
            try
            {
                Logger.LogDebug($"tooling working directory: {app.WorkingDirectory}");
                var cfgFilePath = Program.ProjectConfigurationPath ?? app.WorkingDirectory;

                Configuration cfg;
                var           cfgFile = new ConfigurationFile(cfgFilePath);
                if (cfgFile.Exists())
                {
                    cfg = cfgFile.Configuration;
                    Logger.LogDebug($"tooling configuration file: {cfgFile.File}");
                }
                else
                {
                    cfg = null;
                    Logger.LogDebug($"tooling configuration file not found: {cfgFile.File}");
                }

                var context = new Context(
                    app.WorkingDirectory,
                    cfg,
                    _console.Out,
                    new CommandShell()
                    );
                GetExecutor().Execute(context);
                return(0);
            }
            catch (ArgumentException e)
            {
                if (!string.IsNullOrEmpty(e.Message))
                {
                    app.Error.WriteLine(e.Message);
                }

                return(1);
            }
            catch (ToolingException e)
            {
                if (!string.IsNullOrEmpty(e.Message))
                {
                    app.Error.WriteLine(e.Message);
                }

                return(2);
            }
            catch (Exception e)
            {
                Logger.LogDebug($"unhandled exception: {e}{Environment.NewLine}{e.StackTrace}");
                app.Error.WriteLine(e.Message);
                return(-1);
            }
        }
Example #5
0
        /// <summary>
        /// Initialize the Steeltoe Configuration file.
        /// </summary>
        /// <exception cref="ToolingException">If an error occurs when initialization the Steeltoe Configuration file.</exception>
        protected override void Execute()
        {
            var path = _path == null
                ? Context.ProjectDirectory
                : Path.Combine(Context.ProjectDirectory, _path);

            var cfgFile = new ConfigurationFile(path);

            if (cfgFile.Exists() && !_force)
            {
                throw new ToolingException("Steeltoe Developer Tools already initialized");
            }

            cfgFile.Store();
            Context.Console.WriteLine("Initialized Steeltoe Developer Tools");
        }
Example #6
0
        private Program(int port)
        {
            Instance = this;
            Port     = port;

            Dictionary <string, string> defaults = new Dictionary <string, string>();

            defaults.Add("+lobby", "true,false");
            defaults.Add("+admins", "false,true");

            ConfigurationFile config = new ConfigurationFile("channels");

            if (!config.Exists())
            {
                config.Write(defaults);
            }

            IReadOnlyDictionary <string, string> channels = config.Values();

            foreach (string key in channels.Keys)
            {
                string channelName = key;
                if (!channelName.StartsWith("+"))
                {
                    channelName = "+" + channelName;
                }

                string   settings;
                string[] splitSettings;
                channels.TryGetValue(key, out settings);
                splitSettings = settings.Split(new char[] { ',' }, 2);

                if (splitSettings.Length != 2)
                {
                    continue;
                }

                bool lobby  = (splitSettings[0].Equals("true") ? true : false);
                bool locked = (splitSettings[1].Equals("true") ? true : false);

                if (lobby && _channelRepository.GetLobby() != null)
                {
                    continue;
                }

                if (_channelRepository.Get(channelName) != null)
                {
                    continue;
                }

                if (lobby)
                {
                    _channelRepository.Store(new LobbyChannel(channelName));
                }
                else
                {
                    _channelRepository.Store(new SystemChannel(channelName, locked));
                }
            }

            try
            {
                _commandManager.RegisterCommand(new CommandHelp());
                _commandManager.RegisterCommand(new CommandName());
                _commandManager.RegisterCommand(new CommandJoin());
                _commandManager.RegisterCommand(new CommandClist());
                _commandManager.RegisterCommand(new CommandCC());
                _commandManager.RegisterCommand(new CommandAuth());
                _commandManager.RegisterCommand(new CommandRegister());
                _commandManager.RegisterCommand(new CommandRole());
                _commandManager.RegisterCommand(new CommandKick());
                _commandManager.RegisterCommand(new CommandMute());
                _commandManager.RegisterCommand(new CommandChangePassword());
                _commandManager.RegisterCommand(new CommandMsg());
            } catch (CommandExistsException cEE)
            {
                Console.WriteLine(cEE.StackTrace);
                return;
            }

            Thread listenerThread = new Thread(new ThreadStart(ListenForClients));

            listenerThread.Start();

            Thread consoleThread = new Thread(new ThreadStart(ShowConsole));

            consoleThread.Start();

            Thread channelManagerThread = new Thread(new ThreadStart(MonitorChannels));

            channelManagerThread.Start();

            Thread activityMonitorThread = new Thread(new ThreadStart(MonitorActivity));

            activityMonitorThread.Start();
        }