public static MenuItem Construct(IContextualOperationContext coc)
        {
            MenuItem miResult = new MenuItem
            {
                Header = OperationClient.GetText(coc.Type, coc.OperationInfo.OperationSymbol),
                Icon   = OperationClient.GetImage(coc.Type, coc.OperationInfo.OperationSymbol).ToSmallImage(),
                Tag    = coc,
            };

            if (coc.OperationSettings != null && coc.OperationSettings.Order != 0)
            {
                Common.SetOrder(miResult, coc.OperationSettings.Order);
            }

            if (coc.CanExecute != null)
            {
                miResult.ToolTip   = coc.CanExecute;
                miResult.IsEnabled = false;
                ToolTipService.SetShowOnDisabled(miResult, true);
                AutomationProperties.SetHelpText(miResult, coc.CanExecute);
            }

            miResult.Click += (object sender, RoutedEventArgs e) =>
            {
                coc.SearchControl.SetDirtySelectedItems();

                if (coc.OperationSettings != null && coc.OperationSettings.HasClick)
                {
                    coc.OperationSettings.OnClick(coc);
                }
                else
                {
                    if (coc.ConfirmMessage())
                    {
                        Entity result = (Entity) new ConstructorContext(coc.SearchControl, coc.OperationInfo).SurroundConstructUntyped(coc.OperationInfo.ReturnType, ctx =>
                                                                                                                                       Server.Return((IOperationServer s) => s.ConstructFromMany(coc.SearchControl.SelectedItems.ToList(), coc.Type, coc.OperationInfo.OperationSymbol, ctx.Args)));

                        if (result != null)
                        {
                            Navigator.Navigate(result);
                        }
                        else
                        {
                            MessageBox.Show(Window.GetWindow(coc.SearchControl), OperationMessage.TheOperation0DidNotReturnAnEntity.NiceToString().FormatWith(coc.OperationInfo.OperationSymbol.NiceToString()));
                        }
                    }
                }
            };

            return(miResult);
        }
        public static MenuItem Construct(IContextualOperationContext coc)
        { 
            MenuItem miResult = new MenuItem
            {
                Header = OperationClient.GetText(coc.Type, coc.OperationInfo.OperationSymbol),
                Icon = OperationClient.GetImage(coc.Type, coc.OperationInfo.OperationSymbol).ToSmallImage(),
                Tag = coc,
            };

            if (coc.OperationSettings != null && coc.OperationSettings.Order != 0)
                Common.SetOrder(miResult, coc.OperationSettings.Order);

            if (coc.CanExecute != null)
            {
                miResult.ToolTip = coc.CanExecute;
                miResult.IsEnabled = false;
                ToolTipService.SetShowOnDisabled(miResult, true);
                AutomationProperties.SetHelpText(miResult, coc.CanExecute);
            }

            miResult.Click += (object sender, RoutedEventArgs e) =>
            {
                coc.SearchControl.SetDirtySelectedItems();

                if (coc.OperationSettings != null && coc.OperationSettings.HasClick)
                    coc.OperationSettings.OnClick(coc);
                else
                {
                    if (coc.ConfirmMessage())
                    {
                        Entity result = (Entity)new ConstructorContext(coc.SearchControl, coc.OperationInfo).SurroundConstructUntyped(coc.OperationInfo.ReturnType, ctx =>
                            Server.Return((IOperationServer s) => s.ConstructFromMany(coc.SearchControl.SelectedItems.ToList(), coc.Type, coc.OperationInfo.OperationSymbol, ctx.Args)));

                        if (result != null)
                            Navigator.Navigate(result);
                        else
                            MessageBox.Show(Window.GetWindow(coc.SearchControl), OperationMessage.TheOperation0DidNotReturnAnEntity.NiceToString().FormatWith(coc.OperationInfo.OperationSymbol.NiceToString()));
                    }
                }
            };

            return miResult;
        }
示例#3
0
        public static MenuItem Construct(IContextualOperationContext coc)
        {
            MenuItem miResult = new MenuItem
            {
                Header = coc.OperationSettings?.Text ?? coc.OperationInfo.OperationSymbol.NiceToString(),
                Icon   = coc.OperationSettings?.Icon.ToSmallImage(),
                Tag    = coc,
            };

            if (coc.CanExecute != null)
            {
                miResult.ToolTip   = coc.CanExecute;
                miResult.IsEnabled = false;
                ToolTipService.SetShowOnDisabled(miResult, true);
                AutomationProperties.SetHelpText(miResult, coc.CanExecute);
            }

            coc.SenderMenuItem = miResult;

            miResult.Click += (object sender, RoutedEventArgs e) =>
            {
                coc.SearchControl.SetDirtySelectedItems();

                if (coc.OperationSettings != null && coc.OperationSettings.HasClick)
                {
                    coc.OperationSettings.OnClick(coc);
                }
                else
                {
                    if (coc.ConfirmMessage())
                    {
                        IEntity entity = Server.Return((IProcessServer s) => s.CreatePackageOperation(coc.Entities.ToList(), coc.OperationInfo.OperationSymbol));

                        Navigator.Navigate(entity);
                    }
                }
            };

            return(miResult);
        }
        public static MenuItem Construct(IContextualOperationContext coc)
        {
            MenuItem miResult = new MenuItem
            {
                Header = coc.OperationSettings?.Text ?? coc.OperationInfo.OperationSymbol.NiceToString(),
                Icon = coc.OperationSettings?.Icon.ToSmallImage(),
                Tag = coc,
            };

            if (coc.CanExecute != null)
            {
                miResult.ToolTip = coc.CanExecute;
                miResult.IsEnabled = false;
                ToolTipService.SetShowOnDisabled(miResult, true);
                AutomationProperties.SetHelpText(miResult, coc.CanExecute);
            }

            coc.SenderMenuItem = miResult;

            miResult.Click += (object sender, RoutedEventArgs e) =>
            {
                coc.SearchControl.SetDirtySelectedItems();

                if (coc.OperationSettings != null && coc.OperationSettings.HasClick)
                    coc.OperationSettings.OnClick(coc);
                else
                {
                    if (coc.ConfirmMessage())
                    {
                        IEntity entity = Server.Return((IProcessServer s) => s.CreatePackageOperation(coc.Entities.ToList(), coc.OperationInfo.OperationSymbol));

                        Navigator.Navigate(entity);
                    }
                }
            };

            return miResult;
        }
        public static MenuItem Construct(IContextualOperationContext coc)
        {
            MenuItem miResult = new MenuItem()
            {
                Header = coc.OperationSettings?.Text ?? coc.OperationInfo.OperationSymbol.NiceToString(),
                Icon = coc.OperationSettings?.Icon.ToSmallImage(),
                Tag = coc,
            };

            if (coc.OperationSettings != null && coc.OperationSettings.Order != 0)
                Common.SetOrder(miResult, coc.OperationSettings.Order);

            if (coc.CanExecute != null)
            {
                miResult.ToolTip = coc.CanExecute;
                miResult.IsEnabled = false;
                ToolTipService.SetShowOnDisabled(miResult, true);
                AutomationProperties.SetHelpText(miResult, coc.CanExecute);
            }

            miResult.Click += (object sender, RoutedEventArgs e) =>
            {
                coc.SearchControl.SetDirtySelectedItems();

                if (coc.OperationSettings != null && coc.OperationSettings.HasClick)
                    coc.OperationSettings.OnClick(coc);
                else
                {
                    var lite = coc.SearchControl.SelectedItems.Single();

                    if (coc.ConfirmMessage())
                    {
                        switch (coc.OperationInfo.OperationType)
                        {
                            case OperationType.Execute:
                                Server.Return((IOperationServer os) => os.ExecuteOperationLite(lite, coc.OperationInfo.OperationSymbol));
                                break;
                            case OperationType.Delete:
                                Server.Execute((IOperationServer os) => os.DeleteLite(lite, coc.OperationInfo.OperationSymbol));
                                break;
                            case OperationType.ConstructorFrom:
                                {
                                    var result = (Entity)new ConstructorContext(coc.SearchControl, coc.OperationInfo).SurroundConstructUntyped(coc.OperationInfo.ReturnType, ctx =>
                                        Server.Return((IOperationServer os) => os.ConstructFromLite(lite, coc.OperationInfo.OperationSymbol)));

                                    if (result == null)
                                    {
                                        MessageBox.Show(Window.GetWindow(miResult), 
                                            OperationMessage.TheOperation0DidNotReturnAnEntity.NiceToString(coc.OperationInfo.OperationSymbol.NiceToString()));
                                    }
                                    else
                                    {
                                        if (Navigator.IsNavigable(result, true))
                                            Navigator.Navigate(result);
                                    };
                                    break;
                                }
                            case OperationType.Constructor:
                            case OperationType.ConstructorFromMany:
                                throw new InvalidOperationException("Unexpected operation type");
                        }
                    }
                }
            };

            return miResult;
        }
示例#6
0
        public static MenuItem Construct(IContextualOperationContext coc)
        {
            MenuItem miResult = new MenuItem()
            {
                Header = coc.OperationSettings?.Text ?? coc.OperationInfo.OperationSymbol.NiceToString(),
                Icon   = coc.OperationSettings?.Icon.ToSmallImage(),
                Tag    = coc,
            };

            if (coc.OperationSettings != null && coc.OperationSettings.Order != 0)
            {
                Common.SetOrder(miResult, coc.OperationSettings.Order);
            }

            if (coc.CanExecute != null)
            {
                miResult.ToolTip   = coc.CanExecute;
                miResult.IsEnabled = false;
                ToolTipService.SetShowOnDisabled(miResult, true);
                AutomationProperties.SetHelpText(miResult, coc.CanExecute);
            }

            miResult.Click += (object sender, RoutedEventArgs e) =>
            {
                coc.SearchControl.SetDirtySelectedItems();

                if (coc.OperationSettings != null && coc.OperationSettings.HasClick)
                {
                    coc.OperationSettings.OnClick(coc);
                }
                else
                {
                    var lite = coc.SearchControl.SelectedItems.Single();

                    if (coc.ConfirmMessage())
                    {
                        switch (coc.OperationInfo.OperationType)
                        {
                        case OperationType.Execute:
                            Server.Return((IOperationServer os) => os.ExecuteOperationLite(lite, coc.OperationInfo.OperationSymbol));
                            break;

                        case OperationType.Delete:
                            Server.Execute((IOperationServer os) => os.DeleteLite(lite, coc.OperationInfo.OperationSymbol));
                            break;

                        case OperationType.ConstructorFrom:
                        {
                            var result = (Entity) new ConstructorContext(coc.SearchControl, coc.OperationInfo).SurroundConstructUntyped(coc.OperationInfo.ReturnType, ctx =>
                                                                                                                                        Server.Return((IOperationServer os) => os.ConstructFromLite(lite, coc.OperationInfo.OperationSymbol)));

                            if (result == null)
                            {
                                MessageBox.Show(Window.GetWindow(miResult),
                                                OperationMessage.TheOperation0DidNotReturnAnEntity.NiceToString(coc.OperationInfo.OperationSymbol.NiceToString()));
                            }
                            else
                            {
                                if (Navigator.IsNavigable(result, true))
                                {
                                    Navigator.Navigate(result);
                                }
                            };
                            break;
                        }

                        case OperationType.Constructor:
                        case OperationType.ConstructorFromMany:
                            throw new InvalidOperationException("Unexpected operation type");
                        }
                    }
                }
            };

            return(miResult);
        }