Exemplo n.º 1
0
        //public string Keyword { get; set; }

        public List <SelectListItem> GetStatusList(ILocalizationManager localizationManager)
        {
            var list = new List <SelectListItem>
            {
                new SelectListItem
                {
                    Text     = localizationManager.GetString(CRSConsts.LocalizationSourceName, "PleaseSelect"),
                    Value    = "",
                    Selected = Status == null
                }
            };

            list.AddRange(Enum.GetValues(typeof(StatusCode))
                          .Cast <StatusCode>()
                          .Select(status =>
                                  new SelectListItem
            {
                Text     = localizationManager.GetString(CRSConsts.LocalizationSourceName, $"StatusCode_{status}"),
                Value    = status.ToString(),
                Selected = status == Status
            })
                          );

            return(list);
        }
        public void UpdateState(IdCardConsoleBoundUserInterfaceState state)
        {
            _privilegedIdButton.Text = state.IsPrivilegedIdPresent
                ? _localizationManager.GetString("Remove privileged ID card")
                : _localizationManager.GetString("Insert privileged ID card");

            _targetIdButton.Text = state.IsTargetIdPresent
                ? _localizationManager.GetString("Remove target ID card")
                : _localizationManager.GetString("Insert target ID card");

            var interfaceEnabled = state.IsPrivilegedIdPresent && state.IsPrivilegedIdAuthorized && state.IsTargetIdPresent;

            _fullNameLabel.Modulate    = interfaceEnabled ? Color.White : Color.Gray;
            _fullNameLineEdit.Editable = interfaceEnabled;
            _fullNameLineEdit.Text     = state.TargetIdFullName;

            _jobTitleLabel.Modulate    = interfaceEnabled ? Color.White : Color.Gray;
            _jobTitleLineEdit.Editable = interfaceEnabled;
            _jobTitleLineEdit.Text     = state.TargetIdJobTitle;

            foreach (var(accessName, button) in _accessButtons)
            {
                button.Disabled = !interfaceEnabled;
                if (interfaceEnabled)
                {
                    button.Pressed = state.TargetIdAccessList.Contains(accessName);
                }
            }

            _submitButton.Disabled = !interfaceEnabled;
        }
        public MagicMirrorWindow(MagicMirrorBoundUserInterface owner, IResourceCache resourceCache, ILocalizationManager localization)
        {
            Title = "Magic Mirror";

            _hairPickerWindow = new HairPickerWindow(resourceCache, localization);
            _hairPickerWindow.Populate();
            _hairPickerWindow.OnHairStylePicked += newStyle => owner.HairSelected(newStyle, false);
            _hairPickerWindow.OnHairColorPicked += newColor => owner.HairColorSelected(newColor, false);

            _facialHairPickerWindow = new FacialHairPickerWindow(resourceCache, localization);
            _facialHairPickerWindow.Populate();
            _facialHairPickerWindow.OnHairStylePicked += newStyle => owner.HairSelected(newStyle, true);
            _facialHairPickerWindow.OnHairColorPicked += newColor => owner.HairColorSelected(newColor, true);

            var vBox = new VBoxContainer();

            Contents.AddChild(vBox);

            var hairButton = new Button
            {
                Text = localization.GetString("Customize hair")
            };

            hairButton.OnPressed += args => _hairPickerWindow.Open();
            vBox.AddChild(hairButton);

            var facialHairButton = new Button
            {
                Text = localization.GetString("Customize facial hair")
            };

            facialHairButton.OnPressed += args => _facialHairPickerWindow.Open();
            vBox.AddChild(facialHairButton);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Called when you click the owner entity with an empty hand. Opens the UI client-side if possible.
        /// </summary>
        /// <param name="args">Data relevant to the event such as the actor which triggered it.</param>
        void IActivate.Activate(ActivateEventArgs args)
        {
            if (!args.User.TryGetComponent(out IActorComponent actor))
            {
                return;
            }

            if (!args.User.TryGetComponent(out IHandsComponent hands))
            {
                _notifyManager.PopupMessage(Owner.Transform.GridPosition, args.User,
                                            _localizationManager.GetString("You have no hands."));
                return;
            }

            if (!Powered)
            {
                return;
            }

            var activeHandEntity = hands.GetActiveHand?.Owner;

            if (activeHandEntity == null)
            {
                _userInterface.Open(actor.playerSession);
            }
        }
Exemplo n.º 5
0
        public IdCardConsoleWindow(IdCardConsoleBoundUserInterface owner, ILocalizationManager loc)
        {
            _loc   = loc;
            _owner = owner;
            var vBox = new VBoxContainer();

            vBox.AddChild(new GridContainer
            {
                Columns  = 3,
                Children =
                {
                    new Label {
                        Text = loc.GetString("Privileged ID:")
                    },
                    (_privilegedIdButton = new Button()),
                    (_privilegedIdLabel = new Label()),

                    new Label {
                        Text = loc.GetString("Target ID:")
                    },
                    (_targetIdButton = new Button()),
                    (_targetIdLabel = new Label())
                }
            });

            _privilegedIdButton.OnPressed += _ => _owner.ButtonPressed(UiButton.PrivilegedId);
            _targetIdButton.OnPressed     += _ => _owner.ButtonPressed(UiButton.TargetId);

            // Separator
            vBox.AddChild(new Control {
                CustomMinimumSize = (0, 8)
            });
Exemplo n.º 6
0
        public SandboxWindow(ILocalizationManager loc)
        {
            Title = loc.GetString("Sandbox Panel");

            RespawnButton = new Button
            {
                Text = loc.GetString("Respawn")
            };

            SpawnEntitiesButton = new Button
            {
                Text = loc.GetString("Spawn Entities")
            };

            SpawnTilesButton = new Button
            {
                Text = loc.GetString("Spawn Tiles")
            };

            Contents.AddChild(new VBoxContainer
            {
                Children =
                {
                    RespawnButton,
                    SpawnEntitiesButton,
                    SpawnTilesButton
                }
            });
        }
Exemplo n.º 7
0
        public List <SelectListItem> GetTasksStateSelectListItems(ILocalizationManager localizationManager)
        {
            var list = new List <SelectListItem>
            {
                new SelectListItem
                {
                    Text     = localizationManager.GetString(SimpleTaskAppConsts.LocalizationSourceName, "AllTasks"),
                    Value    = "",
                    Selected = SelectedTaskState == null
                }
            };

            list.AddRange(Enum.GetValues(typeof(TaskState))
                          .Cast <TaskState>()
                          .Select(state =>
                                  new SelectListItem
            {
                Text     = localizationManager.GetString(SimpleTaskAppConsts.LocalizationSourceName, $"TaskState_{state}"),
                Value    = state.ToString(),
                Selected = state == SelectedTaskState
            })
                          );

            return(list);
        }
        public CargoConsoleOrderMenu()
        {
            IoCManager.InjectDependencies(this);

            Title = _loc.GetString("Order Form");

            var vBox          = new VBoxContainer();
            var gridContainer = new GridContainer {
                Columns = 2
            };

            var requesterLabel = new Label {
                Text = _loc.GetString("Name:")
            };

            Requester = new LineEdit();
            gridContainer.AddChild(requesterLabel);
            gridContainer.AddChild(Requester);

            var reasonLabel = new Label {
                Text = _loc.GetString("Reason:")
            };

            Reason = new LineEdit();
            gridContainer.AddChild(reasonLabel);
            gridContainer.AddChild(Reason);

            var amountLabel = new Label {
                Text = _loc.GetString("Amount:")
            };

            Amount = new SpinBox
            {
                SizeFlagsHorizontal = SizeFlags.FillExpand,
                Value = 1
            };
            Amount.SetButtons(new List <int>()
            {
                -100, -10, -1
            }, new List <int>()
            {
                1, 10, 100
            });
            Amount.IsValid = (n) => {
                return(n > 0);
            };
            gridContainer.AddChild(amountLabel);
            gridContainer.AddChild(Amount);

            vBox.AddChild(gridContainer);

            SubmitButton = new Button()
            {
                Text      = _loc.GetString("OK"),
                TextAlign = Label.AlignMode.Center,
            };
            vBox.AddChild(SubmitButton);

            Contents.AddChild(vBox);
        }
Exemplo n.º 9
0
        public void FrameUpdate(RenderFrameEventArgs renderFrameEventArgs)
        {
            if (_lobby == null)
            {
                return;
            }

            if (_gameStarted)
            {
                _lobby.StartTime.Text = "";
                return;
            }

            string text;
            var    difference = _startTime - DateTime.UtcNow;

            if (difference.Ticks < 0)
            {
                if (difference.TotalSeconds < -5)
                {
                    text = _localization.GetString("Right Now?");
                }
                else
                {
                    text = _localization.GetString("Right Now");
                }
            }
            else
            {
                text = $"{(int) Math.Floor(difference.TotalMinutes)}:{difference.Seconds:D2}";
            }

            _lobby.StartTime.Text = _localization.GetString("Round Starts In: {0}", text);
        }
Exemplo n.º 10
0
        protected virtual HttpResponseMessage CreateUnAuthorizedResponse(HttpActionContext actionContext)
        {
            HttpStatusCode statusCode;
            ErrorInfo      error;

            if (actionContext.RequestContext.Principal?.Identity?.IsAuthenticated ?? false)
            {
                statusCode = HttpStatusCode.Forbidden;
                error      = new ErrorInfo(
                    _localizationManager.GetString(AbpWebConsts.LocalizaionSourceName, "DefaultError403"),
                    _localizationManager.GetString(AbpWebConsts.LocalizaionSourceName, "DefaultErrorDetail403")
                    );
            }
            else
            {
                statusCode = HttpStatusCode.Unauthorized;
                error      = new ErrorInfo(
                    _localizationManager.GetString(AbpWebConsts.LocalizaionSourceName, "DefaultError401"),
                    _localizationManager.GetString(AbpWebConsts.LocalizaionSourceName, "DefaultErrorDetail401")
                    );
            }

            var response = new HttpResponseMessage(statusCode)
            {
                Content = new ObjectContent <AjaxResponse>(
                    new AjaxResponse(error, true),
                    _configuration.HttpConfiguration.Formatters.JsonFormatter
                    )
            };

            return(response);
        }
Exemplo n.º 11
0
        private void TurnOn(IEntity user)
        {
            if (Activated)
            {
                return;
            }

            var cell = Cell;

            if (cell == null)
            {
                EntitySystem.Get <AudioSystem>().Play("/Audio/machines/button.ogg", Owner);

                _notifyManager.PopupMessage(Owner, user, _localizationManager.GetString("Cell missing..."));
                return;
            }

            // To prevent having to worry about frame time in here.
            // Let's just say you need a whole second of charge before you can turn it on.
            // Simple enough.
            if (cell.AvailableCharge(1) < Wattage)
            {
                EntitySystem.Get <AudioSystem>().Play("/Audio/machines/button.ogg", Owner);
                _notifyManager.PopupMessage(Owner, user, _localizationManager.GetString("Dead cell..."));
                return;
            }

            Activated = true;
            SetState(true);

            EntitySystem.Get <AudioSystem>().Play("/Audio/items/flashlight_toggle.ogg", Owner);
        }
Exemplo n.º 12
0
        private void PerformLayout()
        {
            optionsMenu = new OptionsMenu();

            Resizable = false;

            Title = "Esc Menu";

            var vBox = new VBoxContainer {
                SeparationOverride = 4
            };

            Contents.AddChild(vBox);

            OptionsButton = new Button {
                Text = _localizationManager.GetString("Options")
            };
            OptionsButton.OnPressed += OnOptionsButtonClicked;
            vBox.AddChild(OptionsButton);

            DisconnectButton = new Button {
                Text = _localizationManager.GetString("Disconnect")
            };
            DisconnectButton.OnPressed += OnDisconnectButtonClicked;
            vBox.AddChild(DisconnectButton);

            QuitButton = new Button {
                Text = _localizationManager.GetString("Quit Game")
            };
            QuitButton.OnPressed += OnQuitButtonClicked;
            vBox.AddChild(QuitButton);
        }
Exemplo n.º 13
0
 protected override void OnEnable()
 {
     if (Application.IsPlaying(this))
     {
         Observe(locaManager.OnLanguageChanged);
         text.text = locaManager.GetString(StringID);
     }
 }
Exemplo n.º 14
0
        void UseFood(IEntity user)
        {
            if (user == null)
            {
                return;
            }

            if (UsesLeft() == 0)
            {
                user.PopupMessage(user, _localizationManager.GetString("Empty"));
            }
            else
            {
                // TODO: Add putting food back in boxes here?
                if (user.TryGetComponent(out StomachComponent stomachComponent))
                {
                    var transferAmount = Math.Min(_transferAmount, _contents.CurrentVolume);
                    var split          = _contents.SplitSolution(transferAmount);
                    if (stomachComponent.TryTransferSolution(split))
                    {
                        if (_useSound != null)
                        {
                            Owner.GetComponent <SoundComponent>()?.Play(_useSound);
                            user.PopupMessage(user, _localizationManager.GetString("Nom"));
                        }
                    }
                    else
                    {
                        // Add it back in
                        _contents.TryAddSolution(split);
                        user.PopupMessage(user, _localizationManager.GetString("Can't eat"));
                    }
                }
            }

            if (UsesLeft() > 0)
            {
                return;
            }

            Owner.Delete();

            if (_finishPrototype != null)
            {
                var finisher = Owner.EntityManager.SpawnEntity(_finishPrototype, Owner.Transform.GridPosition);
                if (user.TryGetComponent(out HandsComponent handsComponent) && finisher.TryGetComponent(out ItemComponent itemComponent))
                {
                    if (handsComponent.CanPutInHand(itemComponent))
                    {
                        handsComponent.PutInHand(itemComponent);
                        return;
                    }
                }

                finisher.Transform.GridPosition = user.Transform.GridPosition;
                return;
            }
        }
Exemplo n.º 15
0
        protected virtual string GetAuthorizationExceptionMessage(HttpContext context)
        {
            if (context.Response.StatusCode == (int)HttpStatusCode.Forbidden)
            {
                _localizationManager.GetString(AbpWebConsts.LocalizaionSourceName, "DefaultError403");
            }

            return(_localizationManager.GetString(AbpWebConsts.LocalizaionSourceName, "DefaultError401"));
        }
Exemplo n.º 16
0
 public async Task NotifyTodoResponsibleAssignation(Todo todo)
 {
     if (todo.ResponsibleId.HasValue)
     {
         var message         = _localizationManager.GetString(SapConsts.LocalizationSourceName, "AssignedAsLeader");
         var formatedMessage = string.Format(message, todo.TodoName);
         await _notificationPublisher.PublishAsync(TodoNotificationTypes.AddedAsResponsibleOfTask,
                                                   new AddedAsResponsibleNotificationMessage(todo.Id, todo.TodoList.Id, formatedMessage, todo.TodoName),
                                                   new EntityIdentifier(typeof(Todo), todo.Id));
     }
 }
Exemplo n.º 17
0
        public void SendDeadChat(IPlayerSession player, string message)
        {
            var clients = _playerManager.GetPlayersBy(x => x.AttachedEntity != null && x.AttachedEntity.HasComponent <GhostComponent>()).Select(p => p.ConnectedClient);;

            var msg = _netManager.CreateNetMessage <MsgChatMessage>();

            msg.Channel      = ChatChannel.Dead;
            msg.Message      = message;
            msg.MessageWrap  = $"{_localizationManager.GetString("DEAD")}: {player.AttachedEntity.Name}: {{0}}";
            msg.SenderEntity = player.AttachedEntityUid.GetValueOrDefault();
            _netManager.ServerSendToMany(msg, clients.ToList());
        }
Exemplo n.º 18
0
        public AdminAnnounceWindow()
        {
            RobustXamlLoader.Load(this);
            IoCManager.InjectDependencies(this);

            AnnounceMethod.AddItem(_localization.GetString("announce-type-station"));
            AnnounceMethod.SetItemMetadata(0, AdminAnnounceType.Station);
            AnnounceMethod.AddItem(_localization.GetString("announce-type-server"));
            AnnounceMethod.SetItemMetadata(1, AdminAnnounceType.Server);
            AnnounceMethod.OnItemSelected += AnnounceMethodOnOnItemSelected;
            Announcement.OnTextChanged    += AnnouncementOnOnTextChanged;
        }
Exemplo n.º 19
0
        public List <FeatureDto> ListAllFeatures()
        {
            var features = _featureManager.GetAll();

            List <FeatureDto> dtos = features.Select(
                feature => new FeatureDto()
            {
                Name        = feature.Name,
                DisplayName = _localizationManager.GetString((LocalizableString)feature.DisplayName)
            }).ToList();

            return(dtos);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Create and initialize the chem master UI client-side. Creates the basic layout,
        /// actual data isn't filled in until the server sends data about the chem master.
        /// </summary>
        public ChemMasterWindow()
        {
            IoCManager.InjectDependencies(this);

            Contents.AddChild(new VBoxContainer
            {
                Children =
                {
                    //Container
                    new HBoxContainer
                    {
                        Children =
                        {
                            new Label   {
                                Text = _localizationManager.GetString("Container")
                            },
                            new Control {
                                SizeFlagsHorizontal = SizeFlags.FillExpand
                            },
                            (EjectButton = new Button{
                                Text = _localizationManager.GetString("Eject")
                            })
                        }
                    },
                    //Wrap the container info in a PanelContainer so we can color it's background differently.
                    new PanelContainer
                    {
                        SizeFlagsVertical     = SizeFlags.FillExpand,
                        SizeFlagsStretchRatio = 6,
                        CustomMinimumSize     = (0, 200),
                        PanelOverride         = new StyleBoxFlat
                        {
                            BackgroundColor = new Color(27, 27, 30)
                        },
                        Children =
                        {
                            //Currently empty, when server sends state data this will have container contents and fill volume.
                            (ContainerInfo          = new VBoxContainer
                            {
                                SizeFlagsHorizontal = SizeFlags.FillExpand,
                                Children            =
                                {
                                    new Label
                                    {
                                        Text        = _localizationManager.GetString("No container loaded.")
                                    }
                                }
                            }),
                        }
                    },
Exemplo n.º 21
0
        private ErrorInfo GetUnAuthorizedErrorMessage(HttpStatusCode statusCode)
        {
            if (statusCode == HttpStatusCode.Forbidden)
            {
                return(new ErrorInfo(
                           localizationManager.GetString(StudioXWebConsts.LocalizaionSourceName, "DefaultError403"),
                           localizationManager.GetString(StudioXWebConsts.LocalizaionSourceName, "DefaultErrorDetail403")
                           ));
            }

            return(new ErrorInfo(
                       localizationManager.GetString(StudioXWebConsts.LocalizaionSourceName, "DefaultError401"),
                       localizationManager.GetString(StudioXWebConsts.LocalizaionSourceName, "DefaultErrorDetail401")
                       ));
        }
        private ErrorInfo GetUnAuthorizedErrorMessage(HttpStatusCode statusCode)
        {
            if (statusCode == HttpStatusCode.Forbidden)
            {
                return(new ErrorInfo(
                           _localizationManager.GetString(CodeZeroConsts.LocalizationCodeZeroWeb, "DefaultError403"),
                           _localizationManager.GetString(CodeZeroConsts.LocalizationCodeZeroWeb, "DefaultErrorDetail403")
                           ));
            }

            return(new ErrorInfo(
                       _localizationManager.GetString(CodeZeroConsts.LocalizationCodeZeroWeb, "DefaultError401"),
                       _localizationManager.GetString(CodeZeroConsts.LocalizationCodeZeroWeb, "DefaultErrorDetail401")
                       ));
        }
 void IExamine.Examine(FormattedMessage message)
 {
     message.AddText(_loc.GetString("Contains:\n"));
     foreach (var reagent in ReagentList)
     {
         if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto))
         {
             message.AddText($"{proto.Name}: {reagent.Quantity}u\n");
         }
         else
         {
             message.AddText(_loc.GetString("Unknown reagent: {0}u\n", reagent.Quantity));
         }
     }
 }
            public HumanInventoryWindow(ILocalizationManager loc, IResourceCache resourceCache)
            {
                Title     = loc.GetString("Your Inventory");
                Resizable = false;

                var buttonDict = new Dictionary <Slots, InventoryButton>();

                Buttons = buttonDict;

                const int width  = ButtonSize * 4 + ButtonSeparation * 3 + RightSeparation;
                const int height = ButtonSize * 4 + ButtonSeparation * 3;

                var windowContents = new Control {
                    CustomMinimumSize = (width, height)
                };

                Contents.AddChild(windowContents);

                void AddButton(Slots slot, string textureName, Vector2 position)
                {
                    var texture        = resourceCache.GetTexture($"/Textures/UserInterface/Inventory/{textureName}.png");
                    var storageTexture = resourceCache.GetTexture("/Textures/UserInterface/Inventory/back.png");
                    var button         = new InventoryButton(slot, texture, storageTexture)
                    {
                        Position = position
                    };

                    windowContents.AddChild(button);
                    buttonDict.Add(slot, button);
                }

                const int size = ButtonSize;
                const int sep  = ButtonSeparation;
                const int rSep = RightSeparation;

                // Left column.
                AddButton(Slots.EYES, "glasses", (0, size + sep));
                AddButton(Slots.INNERCLOTHING, "uniform", (0, 2 * (size + sep)));
                AddButton(Slots.EXOSUITSLOT1, "suit_storage", (0, 3 * (size + sep)));

                // Middle column.
                AddButton(Slots.HEAD, "head", (size + sep, 0));
                AddButton(Slots.MASK, "mask", (size + sep, size + sep));
                AddButton(Slots.OUTERCLOTHING, "suit", (size + sep, 2 * (size + sep)));
                AddButton(Slots.SHOES, "shoes", (size + sep, 3 * (size + sep)));

                // Right column
                AddButton(Slots.EARS, "ears", (2 * (size + sep), 0));
                AddButton(Slots.IDCARD, "id", (2 * (size + sep), size + sep));
                AddButton(Slots.GLOVES, "gloves", (2 * (size + sep), 2 * (size + sep)));

                // Far right column.
                AddButton(Slots.BACKPACK, "back", (rSep + 3 * (size + sep), 0));
                AddButton(Slots.BELT, "belt", (rSep + 3 * (size + sep), size + sep));
                AddButton(Slots.POCKET1, "pocket", (rSep + 3 * (size + sep), 2 * (size + sep)));
                AddButton(Slots.POCKET2, "pocket", (rSep + 3 * (size + sep), 3 * (size + sep)));

                Size = CombinedMinimumSize;
            }
        }
Exemplo n.º 25
0
        public List <SelectListItem> GetOfficeList(ILocalizationManager localizationManager)
        {
            var list = new List <SelectListItem>
            {
                new SelectListItem
                {
                    Text     = localizationManager.GetString(CRSConsts.LocalizationSourceName, "PleaseSelect"),
                    Value    = "",
                    Selected = OfficeCode == null
                }
            };
            var officeList = Offices.ToList();

            list.AddRange(officeList
                          .Select(office =>
                                  new SelectListItem
            {
                Text     = office.Name.ToString(),
                Value    = office.Code.ToString(),
                Selected = office.Equals(OfficeCode)
            })
                          );

            return(list);
        }
Exemplo n.º 26
0
 public WiresMenu(ILocalizationManager localizationManager)
 {
     _localizationManager = localizationManager;
     Title           = _localizationManager.GetString("Wires");
     _wiresContainer = new VBoxContainer();
     Contents.AddChild(_wiresContainer);
 }
Exemplo n.º 27
0
        public List <SelectListItem> GetInstructorList(ILocalizationManager localizationManager)
        {
            var list = new List <SelectListItem>
            {
                new SelectListItem
                {
                    Text     = localizationManager.GetString(CRSConsts.LocalizationSourceName, "PleaseSelect"),
                    Value    = "",
                    Selected = InstructorCode == null
                }
            };
            var instructorList = Instructors.ToList();

            list.AddRange(instructorList
                          .Select(instructor =>
                                  new SelectListItem
            {
                Text     = instructor.Name.ToString(),
                Value    = instructor.Code.ToString(),
                Selected = instructor.Equals(InstructorCode)
            })
                          );

            return(list);
        }
Exemplo n.º 28
0
        /// <summary>
        /// 获取枚举的本地化值
        /// </summary>
        /// <typeparam name="T">Enum</typeparam>
        /// <param name="enumValue">Enum value</param>
        /// <param name="localizationService">Localization service</param>
        /// <param name="languageId">Language identifier</param>
        /// <returns>Localized value</returns>
        public static string GetLocalizedEnum <T>(this T enumValue, ILocalizationManager localizationManager, string sourceName = "ServerSide")
        {
            if (localizationManager == null)
            {
                throw new ArgumentNullException("localizationManager");
            }

            if (!typeof(T).GetTypeInfo().IsEnum)
            {
                throw new ArgumentException("T must be an enumerated type");
            }

            //localized value
            string resourceName = string.Format("Enums.{0}.{1}",
                                                typeof(T).ToString(),
                                                //Convert.ToInt32(enumValue)
                                                enumValue.ToString());

            string result = localizationManager.GetString(sourceName, resourceName);

            //set default value if required
            if (String.IsNullOrEmpty(result))
            {
                result = CommonHelper.ConvertEnum(enumValue.ToString());
            }

            return(result);
        }
Exemplo n.º 29
0
        public List <SelectListItem> GetDepartmentList(ILocalizationManager localizationManager)
        {
            var list = new List <SelectListItem>
            {
                new SelectListItem
                {
                    Text     = localizationManager.GetString(CRSConsts.LocalizationSourceName, "PleaseSelect"),
                    Value    = "",
                    Selected = DepartmentCode == null
                }
            };
            var departmentList = Departments.ToList();

            list.AddRange(departmentList
                          .Select(department =>
                                  new SelectListItem
            {
                Text     = department.Name.ToString(),
                Value    = department.Code.ToString(),
                Selected = department.Equals(DepartmentCode)
            })
                          );

            return(list);
        }
Exemplo n.º 30
0
        /// <summary>
        /// 获取枚举的本地化值
        /// </summary>
        /// <typeparam name="T">Enum</typeparam>
        /// <param name="enumValue">Enum value</param>
        /// <param name="localizationService">Localization service</param>
        /// <param name="languageId">Language identifier</param>
        /// <returns>Localized value</returns>
        public static string GetLocalizedEnum(this object enumValue, Type enumType, ILocalizationManager localizationManager, string sourceName)
        {
            if (localizationManager == null)
            {
                throw new ArgumentNullException("localizationManager");
            }

            if (!enumType.GetTypeInfo().IsEnum)
            {
                throw new ArgumentException("T must be an enumerated type");
            }

            //localized value
            string resourceName = string.Format("Enums.{0}.{1}", enumType.ToString(),
                                                //Convert.ToInt32(enumValue)
                                                enumValue.ToString());

            string result = localizationManager.GetString(sourceName, resourceName);

            //如果没有翻译,则获取默认值
            if (String.IsNullOrEmpty(result))
            {
                result = CommonHelper.ConvertEnum(enumValue.ToString());
            }

            return(result);
        }
        public static AjaxResponse ToMvcAjaxResponse(this ModelStateDictionary modelState, ILocalizationManager localizationManager)
        {
            if (modelState.IsValid)
            {
                return new AjaxResponse();
            }

            var validationErrors = new List<ValidationErrorInfo>();

            foreach (var state in modelState)
            {
                foreach (var error in state.Value.Errors)
                {
                    validationErrors.Add(new ValidationErrorInfo(error.ErrorMessage, state.Key));
                }
            }

            var errorInfo = new ErrorInfo(localizationManager.GetString(AbpWebConsts.LocalizaionSourceName, "ValidationError"))
            {
                ValidationErrors = validationErrors.ToArray()
            };

            return new AjaxResponse(errorInfo);
        }