private void btnOpen_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Dyno files (*.dyn)|*.dyn"; openFileDialog.FilterIndex = 0; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } XmlSerializer xmlSerializer = new XmlSerializer( typeof(DynoRecord), new System.Type[] { typeof(ArrayList), typeof(DatedValue) } ); FileStream fileStream1 = new FileStream(openFileDialog.FileName, FileMode.Open); FileStream fileStream2 = fileStream1; DynoRecord dynoRecord = (DynoRecord)xmlSerializer.Deserialize((Stream)fileStream2); fileStream1.Close(); m_dVehicleWeight = dynoRecord.Weight; dyno.Label = dynoRecord.Label; m_arrRpmValues = dynoRecord.RpmList; Calculate(); }
private void btnSave_Click(object sender, EventArgs e) { if (m_arrRpmValues == null) { MessageBox.Show("You must first perform a dyno pull or open a previous session.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { SaveFileDialog dialog = new SaveFileDialog(); dialog.Title = "Save Dyno Session"; dialog.Filter = "Dyno files (*.dyn)|*.dyn"; dialog.FilterIndex = 0; dialog.RestoreDirectory = true; dialog.ShowDialog(); if (dialog.FileName != "") { DynoRecord record = new DynoRecord(); record.RpmList = m_arrRpmValues; record.Weight = m_dVehicleWeight; record.Label = dyno.Label; Type[] typeArray = new Type[] { typeof(ArrayList), typeof(DatedValue) }; TextWriter writer = new StreamWriter(dialog.FileName); new XmlSerializer(typeof(DynoRecord), typeArray).Serialize(writer, record); writer.Close(); } } }