private void btnLoad_Click(object sender, RoutedEventArgs e) { byte[] bytes; StockChartX.SerializationTypeEnum serType = (StockChartX.SerializationTypeEnum)System.Enum.Parse(typeof(StockChartX.SerializationTypeEnum), cmbSerType.SelectionBoxItem.ToString(), true); OpenFileDialog ofd = new OpenFileDialog(); switch (serType) { case StockChartX.SerializationTypeEnum.All: ofd.Filter = "StockChartX file (*.scx)|*.scx"; break; case StockChartX.SerializationTypeEnum.General: ofd.Filter = "General Template file (*.scg)|*.scg"; break; case StockChartX.SerializationTypeEnum.Objects: ofd.Filter = "Object template file (*.sco)|*.sco"; break; } if (ofd.ShowDialog() == false) { return; } if (serType == StockChartX.SerializationTypeEnum.All) { _stockChartX.ClearAll();//we must clear the chart when loading ALL _stockChartX.Update(); } using (Stream stream = ofd.File.OpenRead()) { bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); int res = _stockChartX.LoadFile(bytes, serType); if (res == 0) { int count = _stockChartX.RecordCount; int maxBarCount = Math.Min(500, count); int endIndex = count - (int)(maxBarCount * 0.25); int startIndex = count - maxBarCount; _stockChartX.FirstVisibleRecord = startIndex; _stockChartX.LastVisibleRecord = endIndex; _stockChartX.Update(); MessageBox.Show("Chart succesfully deserialized."); } else { MessageBox.Show("Could not deserialize the data. Error " + res); } } }
private void btnSave_Click(object sender, RoutedEventArgs e) { StockChartX.SerializationTypeEnum serType = (StockChartX.SerializationTypeEnum)System.Enum.Parse(typeof(StockChartX.SerializationTypeEnum), cmbSerType.SelectionBoxItem.ToString(), true); SaveFileDialog sfd = new SaveFileDialog(); switch (serType) { case StockChartX.SerializationTypeEnum.All: sfd.Filter = "StockChartX file (*.scx)|*.scx"; sfd.DefaultExt = "*.scx"; break; case StockChartX.SerializationTypeEnum.General: sfd.Filter = "General Template file (*.scg)|*.scg"; sfd.DefaultExt = "*scg"; break; case StockChartX.SerializationTypeEnum.Objects: sfd.Filter = "Object template file (*.sco)|*.sco"; sfd.DefaultExt = "*.sco"; break; } if (sfd.ShowDialog() == false) { return; } byte[] bytes = _stockChartX.SaveFile(serType); using (Stream stream = sfd.OpenFile()) { stream.Write(bytes, 0, bytes.Length); stream.Close(); } MessageBox.Show("Chart saved. Bytes Count: " + bytes.Length); }