Пример #1
0
        private void settingsPage_Save_Exec_Click(object sender, RoutedEventArgs e)
        {
            var configModel    = new ConfigModel();
            var dataHandler    = new EncryptDataHandler(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\SP\data");
            var fileManagement = new FileManagement();


            if (_settings.ShutDownEnable)
            {
                configModel.ShutDownEnable = _settings.ShutDownEnable;
                configModel.ShutDownOption = windowsManagement_ShutDownOption_ComboBox.SelectedItem.GetType().GetProperty("Value")?.GetValue(windowsManagement_ShutDownOption_ComboBox.SelectedItem, null).ToString();
                configModel.ShutDownTime   = int.Parse(windowsManagement_ShutDownTime_TextBox.Text);
            }

            if (_settings.ListProcessesEnable)
            {
                configModel.ListProcessesEnable = _settings.ListProcessesEnable;
            }

            if (_programList.Count != 0)
            {
                configModel.ProgramBlockList = _programList;
            }

            if (_settings.WebHistoryEnable)
            {
                configModel.WebHistoryEnable     = _settings.WebHistoryEnable;
                configModel.WebHistoryQueryLimit = int.Parse(windowsMonitoring_WebHistory_QueryLimit_TextBox.Text);
                configModel.WebHistoryPath       = _pathToWebBrowser;
            }

            if (_settings.PrtScrnEnable)
            {
                configModel.PrtScrnEnable        = _settings.PrtScrnEnable;
                configModel.PrtScrnQualityOption = windowsMonitoring_PrtScrn_Quality_TextBox.SelectedItem.GetType().GetProperty("Value")?.GetValue(windowsMonitoring_PrtScrn_Quality_TextBox.SelectedItem, null).ToString();
                configModel.PrtScrInterval       = int.Parse(windowsMonitoring_PrtScrn_Offset_TextBox.Text);
            }

            if (_scanDirectory.Count != 0)
            {
                configModel.FileDirectoryList      = _scanDirectory;
                configModel.FileDirectoryExtension = windowsMonitoring_FileDirectory_EXT_TextBox.Text;
                configModel.RemovableDevicesEnable = _settings.RemovableDevicesEnable;
            }

            if (ProtectLicenseKey(settingsPage_CC_Key_TextBox.Password).Length == 0 || settingsPage_CC_URL_TextBox.Text.Length == 0 || settingsPage_ID_ID_TextBox.Text.Length == 0 || settingsPage_TP_Offset_TexBox.Text.Length == 0)
            {
                MessageBox.Show("Brak wszystkich wymaganych danych!");
                return;
            }
            configModel.OfflineMode  = _settings.OfflineMode;
            configModel.AddressCc    = settingsPage_CC_URL_TextBox.Text;
            configModel.License      = fileManagement.Base64Encode(dataHandler.EncryptText(ProtectLicenseKey(settingsPage_CC_Key_TextBox.Password)));
            configModel.IntervalTime = int.Parse(settingsPage_TP_Offset_TexBox.Text);
            fileManagement.CreateFile(null, "config.bin", Encoding.ASCII.GetBytes(JsonSerializer.Serialize(configModel)), true);
            HttpClient client = new HttpClient();

            if (_settings.OfflineMode.Equals(false))
            {
                var           identification = new UserIdentification();
                StringBuilder urlBuilder     = new StringBuilder(settingsPage_CC_URL_TextBox.Text + "/api/1.1/users/" + settingsPage_CC_Key_TextBox.Password + "/" + settingsPage_ID_ID_TextBox.Text);
                client.SetDeviceID(urlBuilder.ToString());
            }
            using (StreamWriter sw = File.CreateText(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\SP\data\debug.bin"))
            {
                sw.WriteLine(settingsPage_ID_ID_TextBox.Text);
            }
            MessageBox.Show("Zapisano ustawienia, uruchom ponownie program!");
        }