public void SetGraphErrors(IntegrityCheckException ex) { GraphExplorer.SetValidationErrors(GraphExplorer.FromRoot(this), ex); }
static void OperationExecute(IEntityOperationContext eoc) { if (eoc.CanExecute != null) { throw new ApplicationException("Operation {0} is disabled: {1}".FormatWith(eoc.OperationInfo.OperationSymbol, eoc.CanExecute)); } if (eoc.OperationSettings != null && eoc.OperationSettings.HasClick) { IEntity newIdent = eoc.OperationSettings.OnClick(eoc); if (newIdent != null) { eoc.EntityControl.RaiseEvent(new ChangeDataContextEventArgs(newIdent)); } } else { Entity ident = (Entity)(IEntity)eoc.Entity; if (eoc.OperationInfo.OperationType == OperationType.Execute) { if (eoc.OperationInfo.Lite.Value) { if (eoc.EntityControl.LooseChangesIfAny()) { if (eoc.ConfirmMessage()) { Lite <Entity> lite = ident.ToLite(); IEntity newIdent = Server.Return((IOperationServer s) => s.ExecuteOperationLite(lite, eoc.OperationInfo.OperationSymbol, null)); if (eoc.OperationInfo.Returns) { eoc.EntityControl.RaiseEvent(new ChangeDataContextEventArgs(newIdent)); } } } } else { if (eoc.ConfirmMessage()) { try { IEntity newIdent = Server.Return((IOperationServer s) => s.ExecuteOperation(ident, eoc.OperationInfo.OperationSymbol, null)); if (eoc.OperationInfo.Returns) { eoc.EntityControl.RaiseEvent(new ChangeDataContextEventArgs(newIdent)); } } catch (IntegrityCheckException e) { GraphExplorer.SetValidationErrors(GraphExplorer.FromRoot(ident), e); throw e; } } } } else if (eoc.OperationInfo.OperationType == OperationType.ConstructorFrom) { if (eoc.OperationInfo.Lite.Value && !eoc.EntityControl.LooseChangesIfAny()) { return; } if (!eoc.ConfirmMessage()) { return; } IEntity result = (Entity) new ConstructorContext(eoc.EntityControl, eoc.OperationInfo).SurroundConstructUntyped(eoc.OperationInfo.ReturnType, ctx => { Entity r; if (eoc.OperationInfo.Lite.Value) { r = Server.Return((IOperationServer s) => s.ConstructFromLite(ident.ToLite(), eoc.OperationInfo.OperationSymbol, null)); } else { try { r = Server.Return((IOperationServer s) => s.ConstructFrom(ident, eoc.OperationInfo.OperationSymbol, null)); } catch (IntegrityCheckException e) { GraphExplorer.SetValidationErrors(GraphExplorer.FromRoot(ident), e); throw e; } } if (r == null) { MessageBox.Show(Window.GetWindow(eoc.EntityControl), OperationMessage.TheOperation0DidNotReturnAnEntity.NiceToString().FormatWith(eoc.OperationInfo.OperationSymbol.NiceToString())); } return(r); }); if (result != null) { Navigator.Navigate(result); } } else if (eoc.OperationInfo.OperationType == OperationType.Delete) { if (eoc.ConfirmMessage()) { Lite <Entity> lite = ident.ToLite(); Server.Execute((IOperationServer s) => s.DeleteLite(lite, eoc.OperationInfo.OperationSymbol, null)); Window.GetWindow(eoc.EntityControl).Close(); } } } }