private void OpenScriptCol(string path) { try { scol = ScriptCollection.Deserialize(path); this.Text = Path.GetFileName(scol.SavedPath); scol.PropertyChanged += Scol_PropertyChanged; lstbxScripts.DataSource = scol.Scripts; AddLatest(path); } catch (FileNotFoundException) { if (fpcLatest.Exists(x => x == path)) { if (MessageBox.Show("Filen findes ikke. Fjern fra Seneste?", "Fil ikke fundet", MessageBoxButtons.YesNo) == DialogResult.Yes) { fpcLatest.RemoveAt(fpcLatest.FindIndex(x => x == path)); RefreshLatestMenu(); } } else { MessageBox.Show("Filen findes ikke."); } } catch (InvalidOperationException) { MessageBox.Show("Kunne ikke åbne. Filen er muligvis korrupt."); } }
private void SaveAs(string path) { ScriptCollection.Serialize(scol, path); SetBottomText("Gemt"); saved = true; this.Text = Path.GetFileName(path); AddLatest(path); }
public static void Serialize(ScriptCollection scol, string path) { XmlSerializer serializer = new XmlSerializer(typeof(ScriptCollection)); using (TextWriter writer = new StreamWriter(path)) { serializer.Serialize(writer, scol); } scol.savedPath = path; }
private void mnuFileNew_Click(object sender, EventArgs e) { if (CheckIfSaved()) { scol = new ScriptCollection(); lstbxScripts.DataSource = null; lstbxHosts.DataSource = null; saved = true; this.Text = "Nyt script"; txtCommands.Clear(); txtUsername.Clear(); txtPassword.Clear(); txtOutput.Clear(); } }