コード例 #1
0
        // Export Device Settings to File
        private void ButtonExportFile_Click(object sender, RoutedEventArgs e)
        {
            // Create new Device Settings object
            DeviceSettings deviceSettings = new DeviceSettings(this.deviceSettings.SelectedDevice)
            {
                // Simplified initialization
                ColorMatrix    = this.deviceSettings.ColorMatrix,   // Store the current Colors set for each key
                KeyColorAll    = this.deviceSettings.KeyColorAll,   // Store the current Key Color for All keys
                SelectedEffect = this.deviceSettings.SelectedEffect // Store the current Effect
            };

            if (String.IsNullOrWhiteSpace(this.deviceSettings.BoundExe))
            {
                deviceSettings.BoundExe = null;
            }
            else
            {
                deviceSettings.BoundExe = this.deviceSettings.BoundExe + "";
            }

            JsonSerializer serializer = new JsonSerializer()
            {
                // Simplified initialization
                Formatting = Formatting.Indented
            };


            SaveFileDialog saveFileDialog = new SaveFileDialog()
            {
                // Simplified initialization
                Filter = "JSON Device Settings File|*.json",
                Title  = "Save a Device Settings/Profile"
            };

            saveFileDialog.ShowDialog();

            // If the file name is not an empty string, open it for saving.
            if (String.IsNullOrWhiteSpace(saveFileDialog.FileName) == false)
            {
                FileStream fs = (FileStream)saveFileDialog.OpenFile();
                using (StreamWriter sw = new StreamWriter(fs))
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        serializer.Serialize(writer, deviceSettings);
                    }
                fs.Close();
            }
        }
コード例 #2
0
        private void LoadDeviceSettings(DeviceSettings deviceSettings)
        {
            if (deviceSettings != null)
            {
                if (deviceSettings.ColorMatrix.KeyColor != null)
                {
                    this.deviceSettings.ColorMatrix = deviceSettings.ColorMatrix; // Load the current Colors set for each key
                }
                this.deviceSettings.KeyColorAll    = deviceSettings.KeyColorAll;  // Load the current Key Color for All keys
                this.deviceSettings.SelectedDevice = deviceSettings.SelectedDevice;
                this.deviceSettings.SelectedEffect = deviceSettings.SelectedEffect;

                cbDeviceSelect.SelectedIndex    = (int)this.deviceSettings.SelectedDevice;
                cbLEDEffectChoose.SelectedIndex = (int)this.deviceSettings.SelectedEffect;

                if (String.IsNullOrWhiteSpace(deviceSettings.BoundExe))
                {
                    this.deviceSettings.BoundExe = null;
                }
                else
                {
                    this.deviceSettings.BoundExe = deviceSettings.BoundExe + "";
                }
            }

            // Update the value for the currently selected key
            // Not needed to update each key at this time (the others will be updated the LED Row or Column selection changes)
            UpdateSelectedLEDColor();

            // Update the current value for the All Keys
            UpdateAllLEDColor();

            SetDevice(this.deviceSettings.SelectedDevice);
            SetLedEffect(this.deviceSettings.SelectedEffect);

            if (String.IsNullOrWhiteSpace(this.deviceSettings.BoundExe))
            {
                tbProfileExe.Text = "";
            }
            else
            {
                tbProfileExe.Text = this.deviceSettings.BoundExe + "";
            }
        }
コード例 #3
0
        // Save the Default Settings
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            // Create new Device Settings object
            DeviceSettings deviceSettings = new DeviceSettings(this.deviceSettings.SelectedDevice)
            {
                // Simplified initialization
                ColorMatrix    = this.deviceSettings.ColorMatrix,    // Store the current Colors set for each key
                KeyColorAll    = this.deviceSettings.KeyColorAll,    // Store the current Key Color for All keys
                SelectedEffect = this.deviceSettings.SelectedEffect, // Store the current Effect
                BoundExe       = null                                // No bound process/EXE for default Device Settings
            };

            // Convert the Device Settings to a JSON object string
            string output = JsonConvert.SerializeObject(deviceSettings);

            // Store the JSON string in User (Default) Settings, as the Default Device Settings
            Properties.Settings.Default.DefaultDeviceSettingsJson = output + "";
            Properties.Settings.Default.Save(); // Save the User (Default) Settings
        }
コード例 #4
0
        // Import Device Settings from File
        private void ButtonImportFile_Click(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show("#TODO: Please Implement Me :)", "Not Yet Implemented...");
            DeviceSettings deviceSettings = null;

            JsonSerializer serializer = new JsonSerializer()
            {
                // Simplified initialization
                Formatting = Formatting.Indented
            };

            OpenFileDialog openFileDialog = new OpenFileDialog()
            {
                // Simplified initialization
                Filter = "JSON Device Settings File|*.json",
                Title  = "Open a Device Settings/Profile"
            };

            openFileDialog.ShowDialog();

            if (String.IsNullOrWhiteSpace(openFileDialog.FileName) == false)
            {
                FileStream fs = (FileStream)openFileDialog.OpenFile();
                using (StreamReader sr = new StreamReader(fs))
                    using (JsonReader reader = new JsonTextReader(sr))
                    {
                        // Convert the JSON object string to a Device Settings object
                        deviceSettings = serializer.Deserialize <DeviceSettings>(reader);
                    }
                fs.Close();
            }

            if (deviceSettings != null)
            {
                LoadDeviceSettings(deviceSettings);
            }
        }