private async void SaveScript() { var masterScript = await MasterScriptDb.GetMasterScript(); var scriptToBeUpdated = masterScript.Scripts.FirstOrDefault(s => s.ScriptId.Equals(_script.ScriptId)); if (scriptToBeUpdated != null) { scriptToBeUpdated.Active = !IsDisabled; scriptToBeUpdated.Name = ScriptName; scriptToBeUpdated.Text = ScriptContent; scriptToBeUpdated.Description = ScriptDescription; scriptToBeUpdated.ScriptStateAction = !IsDisabled ? "Disable" : "Enable"; scriptToBeUpdated.RowColor = !IsDisabled ? "Black" : "DarkGray"; await MasterScriptDb.UpdateScript(masterScript); //write masterscript on the disk ProcessScript.ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts); var result = MessageBox.Show("Script edited successfully", string.Empty, MessageBoxButton.OK, MessageBoxImage.Information); if (result == MessageBoxResult.OK) { _mainWindowViewModel.LoadScriptsPage(); } } }
private async void ImportScriptsToMaster() { var scriptsToBeImported = ScriptsCollection.Where(s => s.Value.IsSelected).Select(s => s.Value).ToList(); if (scriptsToBeImported.Count > 0) { foreach (var script in scriptsToBeImported) { script.IsSelected = false; await _scriptDb.AddNewScript(script); } var masterScript = await _masterScriptDb.GetMasterScript(); masterScript.Scripts.AddRange(scriptsToBeImported); await _masterScriptDb.UpdateScript(masterScript); //write masterscript on the disk ProcessScript.ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts); Message = "Scripts imported successfully"; MessageVisibility = "Visible"; } else { MessageBox.Show("Please select at least one script from the grid to import", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private async void ChangePath() { try { var folderDialog = new FolderSelectDialog { Title = "Select a folder where the master script should be saved" }; var folderPath = string.Empty; if (folderDialog.ShowDialog()) { folderPath = folderDialog.FileName; } if (!string.IsNullOrEmpty(folderPath)) { var masterScript = await _masterScriptDb.GetMasterScript(); masterScript.Location = folderPath; await _masterScriptDb.UpdateScript(masterScript); ProcessScript.ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts); } } catch (Exception ex) { Log.Logger.Error($"{Constants.ChangePath}: {Constants.Message}: {ex.Message}\n " + $"{Constants.StackTrace}: {ex.StackTrace}\n {Constants.InnerException}: {ex.InnerException}"); } }
private async void ImportScriptsToMaster() { var scriptsToBeImported = ScriptsCollection.Where(s => s.Value.IsSelected).Select(s => s.Value).ToList(); if (scriptsToBeImported.Count > 0) { foreach (var script in scriptsToBeImported) { script.IsSelected = false; script.ScriptStateAction = script.Active ? "Disable" : "Enable"; script.RowColor = script.Active ? "Black" : "DarkGray"; await _scriptDb.AddNewScript(script); RemoveScriptFromGrid(script); } var masterScript = await _masterScriptDb.GetMasterScript(); masterScript.Scripts.AddRange(scriptsToBeImported); await _masterScriptDb.UpdateScript(masterScript); //write masterscript on the disk ProcessScript.ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts); Message = "Scripts imported successfully"; MessageVisibility = "Visible"; Helpers.Ui.Select(GetObservableCollectionOfScripts(), false); } else { MessageBox.Show("Please select at least one script from the grid to import", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public static async void SaveScriptToMaster(Script script) { var masterScript = await MasterScriptDb.GetMasterScript(); var scriptToBeUpdated = masterScript.Scripts.FirstOrDefault(s => s.ScriptId.Equals(script.ScriptId)); if (scriptToBeUpdated != null) { scriptToBeUpdated.Active = script.Active; scriptToBeUpdated.Text = script.Text; scriptToBeUpdated.RowColor = script.RowColor; scriptToBeUpdated.ScriptStateAction = script.ScriptStateAction; await MasterScriptDb.UpdateScript(masterScript); //write masterscript on the disk ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts); } }
private async void ChangePath() { var folderDialog = new FolderSelectDialog { Title = "Select a folder where the master script should be saved" }; var folderPath = string.Empty; if (folderDialog.ShowDialog()) { folderPath = folderDialog.FileName; } if (!string.IsNullOrEmpty(folderPath)) { var masterScript = await _masterScriptDb.GetMasterScript(); masterScript.Location = folderPath; await _masterScriptDb.UpdateScript(masterScript); } }
private async void InsertScript() { ValidateForm(); MessageVisibility = "Visible"; if (FormIsValid) { var script = new Script { ScriptId = Guid.NewGuid().ToString(), Active = !IsDisabled, Description = ScriptDescription, Name = ScriptName, Text = ScriptContent }; script.ScriptStateAction = script.Active ? "Disable" : "Enable"; script.RowColor = script.Active ? "Black" : "DarkGray"; //add new script in data base await _scriptDb.AddNewScript(script); //add the script in master script too var masterScript = await _masterScriptDb.GetMasterScript(); masterScript.Scripts.Add(script); await _masterScriptDb.UpdateScript(masterScript); //write masterscript on the disk ProcessScript.ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts); Message = "Script added successfully."; MessageColor = "#3EA691"; ClearForm(); } else { Message = "Please fill all the fields."; MessageColor = Color.DarkRed.Name; } }