public bool LoadShapeList(string filePath, ref string errorMessage) { try { string formatName = Path.GetExtension(filePath); if (formatName.Length > 1) { formatName = formatName.Substring(1); } SerializationFormat serializationFormat = SerializationFormat.Binary; if (Functionality.GetSerializationFormatByName(formatName, ref serializationFormat)) { ISerializator serializator = SerializationManager.getInstance().GetSerializatorForFormat(serializationFormat); if (null != serializator) { using (FileStream fileStream = new FileStream(filePath, FileMode.Open)) { //plugins work routine var bytes = Utils.ReadStream(fileStream); for (int i = Settings.OrderedAppliedPluginsList.Count - 1; i >= 0; i--) { bytes = Settings.OrderedAppliedPluginsList[i].ProcessDataOnLoad(filePath, serializationFormat, bytes); } //shapes deserealization using (MemoryStream memoryStream = new MemoryStream(bytes)) { ListOfShapes loadedShapeList = serializator.Deserialize <ListOfShapes>(memoryStream); if (null != loadedShapeList) { foreach (Shape shape in loadedShapeList.Shapes) { ListOfShapes.AddShape(shape); } return(true); } } } } } return(false); } catch (Exception e) { errorMessage = e.Message; return(false); } }
private void buttonSave_Click(object sender, EventArgs e) { string dirPath = ""; if (Utils.SelectFolder(ref dirPath)) { string selectedFormatName = comboBoxSerializationFormats.SelectedItem.ToString(); SerializationFormat serializationFormat = SerializationFormat.Binary; if (Functionality.GetSerializationFormatByName(selectedFormatName, ref serializationFormat)) { string filePath = ""; if (Editor.getInstance().SaveShapeList(serializationFormat, dirPath, ref filePath)) { MessageBox.Show( "Shape successfully stored to '" + filePath + "'", "", MessageBoxButtons.OK, MessageBoxIcon.None); } else { MessageBox.Show( "Failed to load save shape", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show( "Unsuppoted serialization format", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }