public Control GetScreen(ScreenContainerContext context)
        {
            _context = context ?? throw new ArgumentNullException(nameof(context));

            var origin =
                new AccountListScreenOrigin(context, ExtensionCatalog.TrustsScreen)
            {
                MenuItemsTagName  = ExtensionCatalog.Tags.TrustExtension,
                CommandBarTagName = ExtensionCatalog.Tags.TrustsScreenExtension
            };

            var template = AccountDisplayHelper.LoadListScreenTemplate(origin);

            _screen = new ListScreen
            {
                Dock = DockStyle.Fill
            };

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, _screen);

            EventBroker.TrustChanged += EventBrokerOnTrustChanged;

            _screen.Disposed += (sender, args) =>
            {
                EventBroker.TrustChanged -= EventBrokerOnTrustChanged;
            };

            _screen.ApplyTemplate(template);

            // Команда Refresh
            _screen.RefreshCallback += () => SelectTrusts(true);

            _screen.MenuItemResolver = (entity, command) =>
            {
                var trust = _screen.CurrentEntity as ITrust;

                if (null == trust)
                {
                    return(false);
                }

                var trustContext = new TrustContext(context, trust);

                if (command.Equals(ExtensionCatalog.CopyPurseNumber))
                {
                    return(true);
                }

                var formProvider = context.ExtensionManager.TryGetTrustFormProvider(command);
                return(formProvider?.CheckCompatibility(trustContext) ?? false);
            };

            // Обработка событий.
            _screen.ServiceCommand += (sender, args) =>
            {
                string command = args.Command;

                if (null == command)
                {
                    throw new InvalidOperationException("null == command");
                }

                switch (command)
                {
                case "BeginRefresh":
                    context.ScreenContainer.OnStartProgress();
                    break;

                case "EndRefresh":
                    context.ScreenContainer.OnStopProgress();
                    break;

                default:
                {
                    var trust = args.Argument as ITrust;

                    // Кнопки
                    if (null == trust)
                    {
                        var formProvider =
                            context.ExtensionManager.TryGetTopFormProvider(command);
                        formProvider?.GetForm(context).Show(context.ScreenContainer);
                    }
                    else
                    {
                        if (command.Equals(TunableList.CellMouseDoubleClickCommandName))
                        {
                            command = ExtensionCatalog.UpdateTrust;
                        }

                        var trustContext = new TrustContext(context, trust);

                        // Системная
                        if (command.Equals(ExtensionCatalog.CopyPurseNumber))
                        {
                            var actionProvider = context.ExtensionManager.TryGetTrustActionProvider(command);
                            actionProvider?.RunAction(trustContext);
                        }
                        else
                        {
                            var formProvider = context.ExtensionManager.TryGetTrustFormProvider(command);
                            formProvider?.GetForm(trustContext).Show(context.ScreenContainer);
                        }
                    }
                }
                break;
                }
            };

            _screen.DisplayContent(SelectTrusts(false));

            return(_screen);
        }
Exemple #2
0
        public static ListScreenTemplate LoadListScreenTemplate(AccountListScreenOrigin origin)
        {
            if (null == origin)
            {
                throw new ArgumentNullException(nameof(origin));
            }

            var template = ListScreenDisplayHelper.LoadListScreenTemplate(origin);

            // Группы и иконки.
            template.TunableList.Groups.Clear();
            template.TunableList.Icons.Clear();

            var currencyService = origin.Context.UnityContainer.Resolve <ICurrencyService>();

            foreach (var currency in currencyService.SelectCurrencies(CurrencyCapabilities.None))
            {
                // Group
                string groupKey = BuildGroupKey(currencyService, currency);
                string groupHeaderText;

                if (currencyService.CheckCapabilities(currency, CurrencyCapabilities.Debit) ||
                    currencyService.CheckCapabilities(currency, CurrencyCapabilities.Credit))
                {
                    groupHeaderText = Translator.Instance.Translate(ExtensionCatalog.PursesScreen, "Credit transfers");
                }
                else
                {
                    groupHeaderText = string.Format(CultureInfo.InvariantCulture, "{0}{1}", currency,
                                                    Translator.Instance.Translate(ExtensionCatalog.PursesScreen, "-purses"));
                }

                var groupTemplate = new ListGroupTemplate(groupKey, groupHeaderText, true);

                // Icon
                var currencyWithPrefix = currencyService.AddPrefix(currency);

                var iconFileName = Path.ChangeExtension(currencyWithPrefix, IconFileExtension);

                if (null == iconFileName)
                {
                    throw new InvalidOperationException("null == iconFileName");
                }

                string iconPath = Path.Combine(IconFolder, iconFileName);

                var iconTemplate = new ListIconTemplate(currency)
                {
                    IconPath = iconPath
                };

                groupTemplate.SetTemplateInternals(template.TemplateName, template.BaseDirectory);
                iconTemplate.SetTemplateInternals(template.TemplateName, template.BaseDirectory);

                template.TunableList.Groups.Add(groupTemplate);
                template.TunableList.Icons.Add(iconTemplate);
            }

            // Отключаем кнопки.
            foreach (var templateCommandButton in template.CommandButtons)
            {
                var formProvider =
                    origin.Context.ExtensionManager.TryGetTopFormProvider(templateCommandButton.Command);

                templateCommandButton.Enabled = formProvider?.CheckCompatibility(origin.Context) ?? false;
            }

            return(template);
        }