public void SavePresetPosition(string Name) { try { PresetPosition pos = new PresetPosition() { Name = Name, MotionComponentHashCode = MotionComponent.GetHashCode(), Items = new PresetPositionItem[AxisControlCollection.Count] }; for (int i = 0; i < AxisControlCollection.Count; i++) { pos.Items[i] = AxisControlCollection[i].PresetAggregation; } using (SqliteDb db = new SqliteDb()) { // check if the preset exists if (db.ReadPresetPosition(pos.MotionComponentHashCode, Name, out PresetPosition preset)) { if (preset == null) { // save the preset position db.SavePresetPosition(pos); Messenger.Default.Send <NotificationMessage <string> >(new NotificationMessage <string>( this, string.Format("The preset position saved successfully."), "NOTIFY")); } else { // overwrite Messenger.Default.Send <NotificationMessageAction <MessageBoxResult> >(new NotificationMessageAction <MessageBoxResult>( this, "AskForOverwrite", (ret) => { if (ret == MessageBoxResult.Yes) { // overwrite the current preset position if (db.DeletePresetPosition(pos.MotionComponentHashCode, pos.Name)) { // save the preset position db.SavePresetPosition(pos); Messenger.Default.Send <NotificationMessage <string> >(new NotificationMessage <string>( this, string.Format("The preset position saved successfully."), "NOTIFY")); } else { Messenger.Default.Send <NotificationMessage <string> >(new NotificationMessage <string>( this, string.Format("Unable to delete the preset position, {0}", db.LastError), "ERROR")); } } } )); } } else { // error while reading preset position from database Messenger.Default.Send <NotificationMessage <string> >(new NotificationMessage <string>( this, string.Format("Unable to check the existence of the preset position, {0}", db.LastError), "ERROR")); } } } catch (Exception ex) { Messenger.Default.Send <NotificationMessage <string> >(new NotificationMessage <string>( this, string.Format("Unable to save the preset position, {0}", ex.Message), "ERROR")); } }