예제 #1
0
        async Task MainAsync()
        {
            string jsonPath = Path.GetDirectoryName(
                Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location))))
                              + @"\Data\Config.json";
            string loadedJson = File.ReadAllText(jsonPath);

            config = JsonConvert.DeserializeObject <ConfigFormat>(loadedJson);
            Console.WriteLine("啟動中... 版本" + config.version);

            client = new DiscordSocketClient(new DiscordSocketConfig {
                LogLevel = LogSeverity.Debug
            });
            command = new CommandService(
                new CommandServiceConfig
            {
                CaseSensitiveCommands = true,
                DefaultRunMode        = RunMode.Async,
                LogLevel = LogSeverity.Debug
            });

            client.MessageReceived += onRecieve;
            await command.AddModulesAsync(Assembly.GetEntryAssembly());

            client.Ready += onReady;
            client.Log   += onLog;
            await client.LoginAsync(TokenType.Bot, config.token);

            await client.StartAsync();

            await Task.Delay(-1);
        }
예제 #2
0
        private void SaveConfig(ConfigFormat configToWrite)
        {
            var json = JsonSerializer.Serialize(configToWrite, new JsonSerializerOptions {
                WriteIndented = true
            });

            Directory.CreateDirectory(Path.GetDirectoryName(Constants.CONFIG_PATH));
            File.WriteAllText(Constants.CONFIG_PATH, json);
        }
예제 #3
0
        public static string GetFileExtension(this ConfigFormat format)
        {
            switch (format)
            {
            case ConfigFormat.Ini: return(".ini");

            default: Debug.Assert(false); return(null);
            }
        }
예제 #4
0
        public void Save()
        {
            var configToWrite = new ConfigFormat
            {
                BaseKeys  = BaseKeys.Select(k => k.ToString()).ToList(),
                Shortcuts = Shortcuts.Select(ps => new Shortcut
                {
                    InputKey  = ps.InputKey.ToString(),
                    OutputKey = ps.InputKey.ToString(),
                }).ToList()
            };

            SaveConfig(configToWrite);
        }
예제 #5
0
        private static IConfigFormatter GetFormatter(ConfigFormat format)
        {
            IConfigFormatter formatter;

            switch (format)
            {
            case ConfigFormat.Properties:
                formatter = new PropertiesConfigFormatter();
                break;

            case ConfigFormat.Xml:
                formatter = new XmlConfigFormatter();
                break;

            default:
                throw new ArgumentException("Format '" + format + "' is not supported.");
            }

            return(formatter);
        }
예제 #6
0
        internal static void ToWriter(TextWriter writer, ConfigFormat format, bool skipComment = false, List<Exception> exceptions = null)
        {
            if (format == ConfigFormat.Json)
                WriteJsonToTextWriter(writer, skipComment);
            if (format == ConfigFormat.AppConfig)
                WriteAppConfigToTextWriter(writer, skipComment);

            if (exceptions == null || !exceptions.Any()) return;
            writer.WriteLine();
            writer.WriteLine();
            WriteExceptions(writer, format, exceptions);
        }
예제 #7
0
 private static void WriteExceptions(TextWriter writer, ConfigFormat format, List<Exception> exceptions)
 {
     writer.WriteLine(format == ConfigFormat.AppConfig ? "<!--" : "/*");
     var e = new AggregateException(exceptions.ToArray()).ToString();
     if (format == ConfigFormat.AppConfig) e = e.Replace("---", "~~~").Replace("--", "~~");
     writer.Write(e);
     writer.WriteLine(format == ConfigFormat.AppConfig ? "-->" : "*/");
 }
예제 #8
0
        private static void WriteComment(TextWriter writer, ConfigFormat format)
        {
            writer.WriteLine(format == ConfigFormat.AppConfig ? "<!--" : "/*");
            writer.WriteLine("Timestamp: {0:O}", _timeStamp);

            var old = _serializer.Formatting;
            _serializer.Formatting = Formatting.None;
            using (var sw = new StringWriter())
            {
                writer.Write("App:  ");
                _serializer.Serialize(sw, new
                {
                    Name = App.Config.Name,
                    Id = App.Config.Id,
                    InstanceId = App.Config.InstanceId,
                    Web = App.IsWebApp,
                    Debug = App.IsDebugConfiguration,
                    Debugging = App.Debugging,
                    Testing = App.Testing
                });
                writer.Write(sw.ToString());
            }
            using (var sw = new StringWriter())
            {
                writer.WriteLine();
                writer.Write("Settings:  ");
                _serializer.Serialize(sw, ConfigSettings.Instance);
                writer.Write(sw.ToString());
            }
            _serializer.Formatting = old;
            writer.WriteLine();
            writer.WriteLine(format == ConfigFormat.AppConfig ? "-->" : "*/");
            writer.WriteLine();
        }
예제 #9
0
        public static void CreateModuleDirStruct(string moduleName, ConfigFormat configFormat) 
        {
            string currApp = Env.GetCurrentApp();
            if (string.IsNullOrWhiteSpace(currApp))
                throw new InvalidOperationException("Active app not set");

            string pascalModName = Utility.PascalCasing(moduleName);
            string snakeModName = Utility.SnakeCasing(moduleName);
            string modDir = Env.GetWorkingDirectory() + "\\" + Utility.PascalCasing(currApp) + "\\modules\\" + pascalModName;
            //if (!Directory.Exists(modDir))
            {
                //mod dir
                FileSystemServices.CreateDirectory(modDir, false);

                //config
                if (configFormat == ConfigFormat.JSON)
                {
                    string modJson = FileSystemServices.ReadTextFromFile(Environment.CurrentDirectory + "\\templates\\module.json");
                    string interfaceJson = FileSystemServices.ReadTextFromFile(Environment.CurrentDirectory + "\\templates\\module_interface.json");
                    FileSystemServices.CreateFile(modDir + string.Format("\\{0}.json", snakeModName), false,
                        Utility.FormatModule(modJson, module_name: snakeModName, ModuleName: pascalModName));
                    FileSystemServices.CreateFile(modDir + "\\interface.json", false,
                        Utility.FormatModule(interfaceJson, module_name: snakeModName, ModuleName: pascalModName));
                }
                else
                {
                    string modXml = FileSystemServices.ReadTextFromFile(Environment.CurrentDirectory + "\\templates\\module.xml");
                    string interfaceXml = FileSystemServices.ReadTextFromFile(Environment.CurrentDirectory + "\\templates\\module_interface.xml");
                    FileSystemServices.CreateFile(modDir + string.Format("\\{0}.xml", snakeModName), false,
                        Utility.FormatModule(modXml, module_name: snakeModName, ModuleName: pascalModName));
                    FileSystemServices.CreateFile(modDir + "\\interface.xml", false,
                        Utility.FormatModule(interfaceXml, module_name: snakeModName, ModuleName: pascalModName));
                }

                //\bin
                FileSystemServices.CreateDirectory(modDir + "\\bin", false);
                //--------------------------
                //\bin\shared
                FileSystemServices.CreateDirectory(modDir + "\\bin\\shared", false);
                //\bin\shared\scripts
                FileSystemServices.CreateDirectory(modDir + "\\bin\\shared\\scripts", false);
                //\bin\shared\styles
                FileSystemServices.CreateDirectory(modDir + "\\bin\\shared\\styles", false);
                //\bin\shared\fonts
                FileSystemServices.CreateDirectory(modDir + "\\bin\\shared\\fonts", false);
                //--------------------------
                //\bin\media
                FileSystemServices.CreateDirectory(modDir + "\\bin\\media", false);
                //--------------------------
                //\bin\configs
                FileSystemServices.CreateDirectory(modDir + "\\bin\\configs", false);
                if (configFormat == ConfigFormat.JSON)
                {
                    FileSystemServices.CreateFile(modDir + "\\bin\\configs\\db.json", false, "");
                    FileSystemServices.CreateFile(modDir + "\\bin\\configs\\module.json", false, "");
                }
                else
                {
                    FileSystemServices.CreateFile(modDir + "\\bin\\configs\\db.xml", false, "");
                    FileSystemServices.CreateFile(modDir + "\\bin\\configs\\module.xml", false, "");
                }
                //--------------------------
                string moduleDir = modDir + "\\" + snakeModName;
                FileSystemServices.CreateDirectory(moduleDir, false);
                if (configFormat == ConfigFormat.JSON)
                {
                    string modJson = FileSystemServices.ReadTextFromFile(Environment.CurrentDirectory + "\\templates\\module.json");
                    FileSystemServices.CreateFile(moduleDir + string.Format("\\{0}.json", snakeModName), false,
                        Utility.FormatModule(modJson, module_name: snakeModName, ModuleName: pascalModName));
                }
                else
                {
                    string modXml = FileSystemServices.ReadTextFromFile(Environment.CurrentDirectory + "\\templates\\module.xml");
                    FileSystemServices.CreateFile(moduleDir + string.Format("\\{0}.xml", snakeModName), false,
                        Utility.FormatModule(modXml, module_name: snakeModName, ModuleName: pascalModName));
                }
                FileSystemServices.CreateDirectory(moduleDir + "\\controller", false);
                FileSystemServices.CreateDirectory(moduleDir + "\\model", false);
                FileSystemServices.CreateDirectory(moduleDir + "\\view", false);

                //--------------------------
                //\tests
                FileSystemServices.CreateDirectory(modDir + "\\tests", false);
            }
            //else
            //{
            //    throw new Exception(string.Format("The module '{0}' already exists in the app '{1}'", moduleName, appLocation));
            //}

            //set active
            Env.SetCurrentModule(moduleName);
        }
예제 #10
0
        public static void CreateAppDirStruct(string appName, ConfigFormat configFormat) 
        {
            string pascalAppName = Utility.PascalCasing(appName);
            string snakeAppName = Utility.SnakeCasing(appName);
            string appDir = Env.GetWorkingDirectory() + "\\" + pascalAppName;
            //if (!Directory.Exists(appDir))
            {
                //app dir
                FileSystemServices.CreateDirectory(appDir, false);

                //config
                if (configFormat == ConfigFormat.JSON)
                {
                    string appJson = FileSystemServices.ReadTextFromFile(Environment.CurrentDirectory + "\\templates\\app.json");
                    FileSystemServices.CreateFile(appDir + string.Format("\\{0}.json", snakeAppName), false,
                        Utility.FormatApp(appJson, app_name: snakeAppName, AppName: pascalAppName));
                }
                else
                {
                    string appXml = FileSystemServices.ReadTextFromFile(Environment.CurrentDirectory + "\\templates\\app.xml");
                    FileSystemServices.CreateFile(appDir + string.Format("\\{0}.xml", snakeAppName), false,
                        Utility.FormatApp(appXml, app_name: snakeAppName, AppName: pascalAppName));
                }

                //.htaccess
                string appHta = FileSystemServices.ReadTextFromFile(Environment.CurrentDirectory + "\\templates\\app.htaccess");
                FileSystemServices.CreateFile(appDir + "\\.htaccess", false, appHta);

                //\bin
                FileSystemServices.CreateDirectory(appDir + "\\bin", false);
                //--------------------------
                //\bin\shared
                FileSystemServices.CreateDirectory(appDir + "\\bin\\shared", false);
                //\bin\shared\scripts
                FileSystemServices.CreateDirectory(appDir + "\\bin\\shared\\scripts", false);
                //\bin\shared\styles
                FileSystemServices.CreateDirectory(appDir + "\\bin\\shared\\styles", false);
                //\bin\shared\fonts
                FileSystemServices.CreateDirectory(appDir + "\\bin\\shared\\fonts", false);
                //--------------------------
                //\bin\media
                FileSystemServices.CreateDirectory(appDir + "\\bin\\media", false);
                //--------------------------
                //\bin\configs
                FileSystemServices.CreateDirectory(appDir + "\\bin\\configs", false);
                if (configFormat == ConfigFormat.JSON)
                {
                    FileSystemServices.CreateFile(appDir + "\\bin\\configs\\db.json", false, "");
                    FileSystemServices.CreateFile(appDir + "\\bin\\configs\\module.json", false, "");
                }
                else
                {
                    FileSystemServices.CreateFile(appDir + "\\bin\\configs\\db.xml", false, "");
                    FileSystemServices.CreateFile(appDir + "\\bin\\configs\\module.xml", false, "");
                }
                //--------------------------
                //\bin\framework
                FileSystemServices.CreateDirectory(appDir + "\\bin\\framework", false);
                //********fetch folder contents from GitHub
                //--------------------------
                //\bin\framework\$(AppName)
                string innerAppDir = appDir + "\\bin\\framework\\" + pascalAppName;
                FileSystemServices.CreateDirectory(innerAppDir, false);
                FileSystemServices.CreateDirectory(innerAppDir + "\\controller", false);
                string appCntrlInterf = FileSystemServices.ReadTextFromFile(Environment.CurrentDirectory + "\\templates\\app.controller.interface.php");
                FileSystemServices.CreateFile(innerAppDir + "\\controller\\ControllerInterface.php", false,
                    Utility.FormatApp(appCntrlInterf, app_name: snakeAppName, AppName: pascalAppName));
                FileSystemServices.CreateDirectory(innerAppDir + "\\model", false);
                string appModelInterf = FileSystemServices.ReadTextFromFile(Environment.CurrentDirectory + "\\templates\\app.model.interface.php");
                FileSystemServices.CreateFile(innerAppDir + "\\model\\ModelInterface.php", false,
                    Utility.FormatApp(appModelInterf, app_name: snakeAppName, AppName: pascalAppName));
                
                //--------------------------
                //\modules
                FileSystemServices.CreateDirectory(appDir + "\\modules", false);
                //--------------------------
                //\webroot
                FileSystemServices.CreateDirectory(appDir + "\\webroot", false);
            }
            //else 
            //{
            //    throw new Exception(string.Format("The app '{0}' already exists in the location '{1}'", appName, location));
            //}

            //set active
            Env.SetCurrentApp(appName);
        }
예제 #11
0
 public ConfigSource(string path, ConfigFormat format)
 {
     Path   = path;
     Format = format;
 }
        public void ResetChanges()
        {
            tempConfig = Config.Settings.Copy();
            lvCheckers.Items.Clear();
            if(tempConfig.Checkers.Count(i => (i.Facebook == i.Name && i.Name == i.Twitch && i.Twitch == i.YouTube && i.YouTube == "TheLockNLol")) == 0)
            {
                ListViewItem i = new ListViewItem("TheLockNLol");
                i.SubItems.Add("TheLockNLol");
                i.SubItems.Add("TheLockNLol");
                i.SubItems.Add("TheLockNLol");
                i.Checked = true;
                lvCheckers.Items.Add(i);
            }
            foreach(CheckerFormat c in tempConfig.Checkers)
            {
                ListViewItem i = new ListViewItem(c.Name);
                i.SubItems.Add("" + c.YouTube);
                i.SubItems.Add("" + c.Twitch);
                i.SubItems.Add("" + c.Facebook);
                i.Checked = c.Enabled;
                lvCheckers.Items.Add(i);
            }
            cbSoundVidup.Checked = tempConfig.Sounds.OnVideo;
            cbSoundLivestream.Checked = tempConfig.Sounds.OnLivestream;
            cbSoundFBook.Checked = tempConfig.Sounds.OnFacebook;
            cbSound.SelectedItem = tempConfig.CurrentSound;

            cbNotifyVideo.Checked = tempConfig.CheckVideo;
            cbNotifySocial.Checked = tempConfig.CheckSocial;
            cbNotifyLivestream.Checked = tempConfig.CheckLivestream;

            tbDuration.Value = Math.Max(tbDuration.Minimum, Math.Min(tbDuration.Maximum, tempConfig.NotifyDelay));
            tbDuration_Scroll(null, EventArgs.Empty);
            palette = new Bitmap(Image.FromStream(new MemoryStream(File.ReadAllBytes("Image/Palette.png"))));
            pictureBox0.BackColor = palette.GetPixel(0, 0);
            pictureBox1.BackColor = palette.GetPixel(1, 0);
            pictureBox2.BackColor = palette.GetPixel(2, 0);
            pictureBox3.BackColor = palette.GetPixel(3, 0);
            pictureBox4.BackColor = palette.GetPixel(4, 0);
            pictureBox5.BackColor = palette.GetPixel(5, 0);
            pictureBox6.BackColor = palette.GetPixel(6, 0);
            pictureBox7.BackColor = palette.GetPixel(7, 0);
            pictureBox8.BackColor = palette.GetPixel(8, 0);
            pictureBox9.BackColor = palette.GetPixel(9, 0);

            List<Control> cons = new List<Control>();
            foreach(Control ci in groupBox2.Controls) cons.Add(ci);
            foreach(Control b in cons.Where(e => e.Name.StartsWith("pictureBox")))
            {
                if(b.Name == "pictureBox" + tempConfig.NotifyColor) ((PictureBox)b).BorderStyle = BorderStyle.Fixed3D;
            }

            tbReloadLength.Value = Math.Max(tbReloadLength.Minimum, Math.Min(tbReloadLength.Maximum, tempConfig.LoadMoreNotifications));
            tbMaxNotify.Value = Math.Max(tbMaxNotify.Minimum, Math.Min(tbMaxNotify.Maximum, tempConfig.MaxNotifications));
            lbReload.Text = tbReloadLength.Value + "";
            lbMaxNotify.Text = tbMaxNotify.Value + "";

            cbAutostart.Checked = tempConfig.AutoStart;
        }
예제 #13
0
        public void Save(ConfigFormat format, Stream output)
        {
            IConfigFormatter formatter = GetFormatter(format);

            Save(formatter, output);
        }
예제 #14
0
        public void Load(ConfigFormat format, Stream input)
        {
            IConfigFormatter formatter = GetFormatter(format);

            formatter.Load(this, input);
        }