public static string Serialize(ICommand command) { var stream = new MemoryStream(); XmlWriter writer = GetWriter(stream); SerializationContext context = SerializationCommandFactory.GetSerializationContext(); SerializationCommandFactory.SerializeCommand(command, writer, context); writer.Close(); stream.Seek(0, SeekOrigin.Begin); string value; using (var reader = new StreamReader(stream)) { value = reader.ReadToEnd(); } return(value); }
private void ApplyChanges_Click(object sender, EventArgs e) { string commandText = this.CommandContent.Text; ICommand command = null; try { MemoryStream stream = new MemoryStream(); using (var writer = new StreamWriter(stream)) { writer.Write(commandText); writer.Flush(); stream.Flush(); stream.Seek(0, SeekOrigin.Begin); var reader = CommandSerializer.GetReader(stream); reader.MoveToContent(); SerializationContext context = SerializationCommandFactory.GetSerializationContext(); command = SerializationCommandFactory.DeserializeCommand(reader, context); } } catch (Exception ex) { MessageBox.Show("Invalid command text format. Cannot deserialize the command.", "Desirizalization Error"); return; } if (command == null) { MessageBox.Show("Invalid command text format. Cannot deserialize the command.", "Desirizalization Error"); return; } if (this.selectedCommand == null) { MessageBox.Show("Hm... Command to be updated not found.", "Strange error."); return; } this.diff.Commands.Insert(this.diff.Commands.IndexOf(this.selectedCommand), command); this.diff.Commands.Remove(this.selectedCommand); this.BindCommandText(command); }