/// <summary>Executes the command.</summary>
        /// <param name="queue">The command queue involved.</param>
        /// <param name="entry">Entry to be executed.</param>
        public static void Execute(CommandQueue queue, CommandEntry entry)
        {
            string            configName = entry.GetArgument(queue, 0).ToLowerFast();
            AutoConfiguration config     = queue.Engine.Context.GetConfig(configName);

            if (config is null)
            {
                queue.HandleError(entry, $"Invalid config name '{TextStyle.SeparateVal(configName)}' - are you sure you typed it correctly?");
                return;
            }
            string configKey = entry.GetArgument(queue, 1);

            AutoConfiguration.Internal.SingleFieldData field = config.TryGetFieldInternalData(configKey, out AutoConfiguration section, true);
            if (field is null)
            {
                queue.HandleError(entry, $"Invalid config setting key '{TextStyle.SeparateVal(configKey)}' - are you sure you typed it correctly?");
                return;
            }
            if (field.Field.FieldType != typeof(bool))
            {
                queue.HandleError(entry, $"Invalid config setting key '{TextStyle.SeparateVal(configKey)}' - not a bool. Cannot be toggled.");
                return;
            }
            bool currentValue = (bool)field.GetValue(section);

            field.SetValue(section, !currentValue);
            field.OnChanged?.Invoke();
            if (queue.ShouldShowGood())
            {
                queue.GoodOutput($"For config '{TextStyle.SeparateVal(configName)}', toggled '{TextStyle.SeparateVal(configKey)}' to '{TextStyle.SeparateVal(!currentValue)}'");
            }
        }
        /// <summary>Executes the command.</summary>
        /// <param name="queue">The command queue involved.</param>
        /// <param name="entry">Entry to be executed.</param>
        public static void Execute(CommandQueue queue, CommandEntry entry)
        {
            string            configName = entry.GetArgument(queue, 0).ToLowerFast();
            AutoConfiguration config     = queue.Engine.Context.GetConfig(configName);

            if (config is null)
            {
                queue.HandleError(entry, $"Invalid config name '{TextStyle.SeparateVal(configName)}' - are you sure you typed it correctly?");
                return;
            }
            string configKey = entry.GetArgument(queue, 1);

            AutoConfiguration.Internal.SingleFieldData field = config.TryGetFieldInternalData(configKey, out AutoConfiguration section, true);
            if (field is null)
            {
                queue.HandleError(entry, $"Invalid config setting key '{TextStyle.SeparateVal(configKey)}' - are you sure you typed it correctly?");
                return;
            }
            TemplateObject newValue = entry.GetArgumentObject(queue, 2);
            object         rawValue = ConvertForType(field.Field.FieldType, newValue, queue);

            field.SetValue(section, rawValue);
            field.OnChanged?.Invoke();
            if (queue.ShouldShowGood())
            {
                queue.GoodOutput($"For config '{TextStyle.SeparateVal(configName)}', set '{TextStyle.SeparateVal(configKey)}' to '{TextStyle.SeparateVal(rawValue)}'");
            }
        }
Example #3
0
 private void button3_Click(object sender, EventArgs e)
 {
     try {
         server = AutoConfiguration.GetCalendarServer(calendarTypeFromText(comboBox2.Text), usernameTextBox.Text, passwordTextBox.Text);
     }
     catch (Exception ex)
     {
         if (ex.Message == "Authentication is required")
         {
             MessageBox.Show("Could not login.");
         }
         else
         {
             MessageBox.Show("Could not login.");
             return;
         }
     }
     try
     {
         calendars = server.GetCalendars();
     }
     catch (NullReferenceException ex)
     {
         MessageBox.Show("Could not login.");
         return;
     }
     comboBox1.Items.Clear();
     foreach (ICalendar calendar in calendars)
     {
         comboBox1.Items.Add(calendar.Name);
     }
     if (comboBox1.Items.Count > 0)
     {
         comboBox1.Text = (string)comboBox1.Items[0];
     }
 }