public void Test1()
 {
     using (var cs = new CultureScope("da-DK"))
     {
         Assert.AreEqual("This is a test message in Danish.", LocalizationUtil.Localize <Messages>().TestMessage);
     }
 }
        async Task CheckForUpdate()
        {
            var versionInfoUrl = ResourceHolder.Instance.GetString("VersionInfoUrl");
            var latestVersion  = await new LatestVersionInfoRetriever(new Uri(versionInfoUrl))
                                 .GetLatestVersionInfoAsync();

            if (latestVersion.IsNewerThan(PluginInfo.Instance.CurrentVersionString))
            {
                var caption = "提督業も忙しい! - " + ResourceHolder.Instance.GetString("PluginName");
                var message = string.Format(
                    latestVersion.IsEmergency ? "{0}\n{1}" : "{1}",
                    ResourceHolder.Instance.GetString("NewerVersionAvailableMessageEmergencyPrefix"),
                    ResourceHolder.Instance.GetString("NewerVersionAvailableMessage"));

                var app = LocalizationUtil.GetApplication();
                var ret = app?.MainWindow != null
                                        ? MessageBox.Show(app.MainWindow, message, caption, MessageBoxButton.YesNo, MessageBoxImage.Information)
                                        : MessageBox.Show(message, caption, MessageBoxButton.YesNo, MessageBoxImage.Information);

                if (ret == MessageBoxResult.Yes)
                {
                    var url = ResourceHolder.Instance.GetString("KcvdbPluginWebUrl");
                    WebUtil.OpenUri(new Uri(url));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves the continent information for the given map ID
        /// </summary>
        /// <param name="mapId">The ID of a zone</param>
        /// <returns>The continent data</returns>
        public Data.Entities.Continent GetContinentByMap(int mapId)
        {
            Data.Entities.Continent result = null;

            if (this.MapContinentsCache.ContainsKey(mapId))
            {
                int continentId;
                this.MapContinentsCache.TryGetValue(mapId, out continentId);
                this.ContinentsCache.TryGetValue(continentId, out result);
            }

            if (result == null)
            {
                // If we didn't get the continent from our cache of Map ID -> Continent ID,
                // request the map info and add it our cache
                try
                {
                    var map = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Maps.ForCurrentUICulture().Find(mapId) : GW2.V2.Maps.ForDefaultCulture().Find(mapId);
                    if (map != null)
                    {
                        this.MapContinentsCache.TryAdd(mapId, map.ContinentId);
                        this.ContinentsCache.TryGetValue(map.ContinentId, out result);
                    }
                }
                catch (Exception ex)
                {
                    // Don't crash if something goes wrong, but log the error
                    logger.Error(ex);
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Retrieves the name of the zone using the given mapID
        /// </summary>
        /// <param name="mapId">The mapID of the zone to retrieve the name for</param>
        /// <returns>the name of the zone</returns>
        public string GetZoneName(int mapId)
        {
            if (mapId <= 0)
            {
                return("Unknown");
            }

            try
            {
                if (MapNamesCache.ContainsKey(mapId))
                {
                    return(MapNamesCache[mapId]);
                }
                else
                {
                    var map = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Maps.ForCurrentUICulture().Find(mapId) : GW2.V2.Maps.ForDefaultCulture().Find(mapId);
                    if (map != null)
                    {
                        return(map.MapName);
                    }
                    else
                    {
                        return("Unknown");
                    }
                }
            }
            catch (Exception ex)
            {
                // Don't crash if something goes wrong, but log the error
                logger.Error(ex);
                return("Unknown");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the item information for the items with the given ID
        /// </summary>
        /// <param name="itemID">ID of the item</param>
        /// <returns>Item object containing all item information, or null if the itemName is invalid</returns>
        public GW2PAO.API.Data.Entities.Item GetItem(int itemID)
        {
            GW2PAO.API.Data.Entities.Item item = null;

            try
            {
                var itemService = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Items.ForCurrentUICulture() : GW2.V2.Items.ForDefaultCulture();
                var itemDetails = itemService.Find(itemID);
                if (itemDetails != null)
                {
                    item                  = new Data.Entities.Item(itemID, itemDetails.Name);
                    item.Icon             = itemDetails.IconFileUrl;
                    item.Description      = itemDetails.Description;
                    item.Rarity           = (Data.Enums.ItemRarity)itemDetails.Rarity;
                    item.Flags            = (Data.Enums.ItemFlags)itemDetails.Flags;
                    item.GameTypes        = (Data.Enums.ItemGameTypes)itemDetails.GameTypes;
                    item.LevelRequirement = itemDetails.Level;
                    item.VenderValue      = itemDetails.VendorValue;
                    item.ChatCode         = itemDetails.GetItemChatLink().ToString();
                    item.Prices           = this.GetItemPrices(itemID);

                    // Since there is no need to use ALL details right now, we'll just get what we need...
                    // TODO: Finish this up, get all details, such as Type, SkinID
                }
            }
            catch (Exception ex)
            {
                // Don't crash, just return null
                logger.Warn("Error finding item with id {0}: {1}", itemID, ex);
            }

            return(item);
        }
Exemplo n.º 6
0
        private static void InitializeCoreStrings()
        {
            var lang = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Substring(0, 2);

            LocalizationUtil.SetLocalization(typeof(LegalityCheckStrings), lang);
            LocalizationUtil.SetLocalization(typeof(MessageStrings), lang);
            RibbonStrings.ResetDictionary(GameInfo.Strings.ribbons);
            ParseSettings.ChangeLocalizationStrings(GameInfo.Strings.movelist, GameInfo.Strings.specieslist);
        }
 /// <summary>
 /// 设置当前语言文化,使用的是Cookies存储,使用之前必须启用Cookies
 /// </summary>
 /// <param name="context">上下文</param>
 /// <param name="culture">文化</param>
 /// <param name="expireDay">过期天数,默认为30天</param>
 public static void SetCurrentCulture(this HttpContext context, string culture, int expireDay = 30)
 {
     context.Response.Cookies.Append("Culture", culture, new CookieOptions()
     {
         HttpOnly = false,
         Expires  = DateTimeOffset.UtcNow.AddDays(expireDay)
     });
     LocalizationUtil.SetCurrentCulture(culture);
 }
Exemplo n.º 8
0
        private static void DumpStrings(Type t, bool sorted, params string[] rel)
        {
            var dir = GetResourcePath(rel);
            var langs = new[] { DefaultLanguage }.Concat(Languages);

            foreach (var lang in langs)
            {
                LocalizationUtil.SetLocalization(t, lang);
                var entries = LocalizationUtil.GetLocalization(t);
                IEnumerable <string> export = entries.OrderBy(GetName); // sorted lines
        public static void GetTitleStrings(int minCount, int maxCount, string trait, int minExperience, int maxExperience, out string countStr, out string traitStr, out string experienceStr)
        {
            // Build the count string
            if (maxCount == int.MaxValue)
            {
                countStr = Localizer.Format("#cc.param.count.atLeast", minCount);
            }
            else if (minCount == 0)
            {
                countStr = Localizer.Format("#cc.param.count.atMost", maxCount);
            }
            else if (minCount == maxCount)
            {
                countStr = Localizer.Format("#cc.param.count.exact", minCount);
            }
            else
            {
                countStr = Localizer.Format("#cc.param.count.between", minCount, maxCount);
            }

            // Build the trait string
            if (!String.IsNullOrEmpty(trait))
            {
                traitStr = Localizer.Format("#cc.param.HasAstronaut.trait", LocalizationUtil.TraitTitle(trait));
            }
            else
            {
                traitStr = null;
            }

            // Build the experience string
            if (minExperience != 0 && maxExperience != 5)
            {
                if (minExperience == 0)
                {
                    experienceStr = Localizer.Format("#cc.param.HasAstronaut.experience.atMost", maxExperience);
                }
                else if (maxExperience == 5)
                {
                    experienceStr = Localizer.Format("#cc.param.HasAstronaut.experience.atLeast", minExperience);
                }
                else if (minExperience == maxExperience)
                {
                    experienceStr = Localizer.Format("#cc.param.HasAstronaut.experience.exact", minExperience);
                }
                else
                {
                    experienceStr = Localizer.Format("#cc.param.HasAstronaut.experience.between", minExperience, maxExperience);
                }
            }
            else
            {
                experienceStr = null;
            }
        }
        public async void Initialize()
        {
            TaihaToolkit.RegisterComponents(WPFComponent.Instance);

            TelemetryClient.TrackEvent("PluginLoaded");

            // Set a hook to detect app crash
            try {
                var app = LocalizationUtil.GetApplication();
                app.DispatcherUnhandledException += App_DispatcherUnhandledException;
            }
            catch (Exception ex) {
                TelemetryClient.TrackException("Failed to set set a hook to detect app crash.", ex);
            }

            // Obtain default app culture
            try {
                ResourceHolder.Instance.Culture = LocalizationUtil.GetCurrentAppCulture();
                UpdateChineseCulture();
            }
            catch (Exception ex) {
                TelemetryClient.TrackException("Failed to get default app culture.", ex);
            }

            // Initialize KCVDB client
            try {
                var sessionId = Guid.NewGuid().ToString();
                apiSender_ = new ApiSender(sessionId);
                viewModel_ = new ToolViewViewModel(
                    apiSender_.KcvdbClient,
                    sessionId,
                    new WPFDispatcher(Dispatcher.CurrentDispatcher));
            }
            catch (Exception ex) {
                TelemetryClient.TrackException("Failed to initialize KCVDB client.", ex);
            }

            Settings.Default.PropertyChanged += Settings_PropertyChanged;

            TelemetryClient.TrackEvent("PluginInitialized");

            try {
                await CheckForUpdate();
            }
            catch (Exception ex) {
                TelemetryClient.TrackException("Failed to check the latest version.", ex);
                if (ex.IsCritical())
                {
                    throw;
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Application Start and initialize Resource Factory
        /// </summary>
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //  Init Culture
            LocalizationUtil.Init(ConfigurationManager.AppSettings["DefCulture"],
                                  ConfigurationManager.AppSettings["DefCountryCode"],
                                  ConfigurationManager.AppSettings["DefCurrencySymbolCode"],
                                  ConfigurationManager.AppSettings["DefaultCurrencySymbol"]);
        }
        protected override string GetParameterTitle()
        {
            // Set the first part of the output
            string output;

            if (!string.IsNullOrEmpty(title))
            {
                output = title;
            }
            else
            {
                // Set the vessel name
                if ((waiting || state == ParameterState.Complete) && trackedVessel != null)
                {
                    output = Localizer.Format("#cc.param.VesselParameterGroup.default", trackedVessel.vesselName);
                }
                else if (!string.IsNullOrEmpty(define))
                {
                    output = Localizer.Format("#cc.param.VesselParameterGroup.newVessel", define);
                }
                else if (vesselList.Any())
                {
                    output = Localizer.Format("#cc.param.VesselParameterGroup.default",
                                              LocalizationUtil.LocalizeList <string>(LocalizationUtil.Conjunction.OR, vesselList.AsEnumerable(), vesselName =>
                    {
                        if (ContractVesselTracker.Instance != null)
                        {
                            return(ContractVesselTracker.GetDisplayName(vesselName));
                        }
                        else
                        {
                            LoggingUtil.LogWarning(this, "Unable to get vessel display name for '{0}' - ContractVesselTracker is null.  This is likely caused by another ScenarioModule crashing, preventing others from loading.", vesselName);
                            return(vesselName);
                        }
                    }
                                                                                     ));
                }
                else
                {
                    output = Localizer.GetStringByTag("#cc.param.VesselParameterGroup.anyVessel");
                }

                // If we're complete and a custom title hasn't been provided, try to get a better title
                if (state == ParameterState.Complete && ParameterCount == 1 && trackedVessel != null)
                {
                    output = Localizer.Format("#cc.param.VesselParameterGroup.complete", trackedVessel.vesselName, GetParameter(0).Title);
                }
            }

            return(output);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Retrieves map information using the provided continent coordinates,
        /// or null if the coordinates do not fall into any current zone
        /// </summary>
        /// <param name="continentId">ID of the continent that the coordinates are for</param>
        /// <param name="continentCoordinates">Continent coordinates to use</param>
        /// <returns>The map data, or null if not found</returns>
        public Data.Entities.Map GetMap(int continentId, Point continentCoordinates)
        {
            var continent    = this.GetContinent(continentId);
            var floorService = LocalizationUtil.IsSupportedCulture() ? GW2.V1.Floors.ForCurrentUICulture(continentId) : GW2.V1.Floors.ForDefaultCulture(continentId);

            var floor = this.GetFloor(continentId, continent.FloorIds.First());

            if (floor != null && floor.Regions != null)
            {
                foreach (var region in floor.Regions.Values)
                {
                    foreach (var map in region.Maps.Values)
                    {
                        if (continentCoordinates.X >= map.ContinentRectangle.X &&
                            continentCoordinates.X <= (map.ContinentRectangle.X + map.ContinentRectangle.Width) &&
                            continentCoordinates.Y >= map.ContinentRectangle.Y &&
                            continentCoordinates.Y <= (map.ContinentRectangle.Y + map.ContinentRectangle.Height))
                        {
                            Data.Entities.Map mapData = new Data.Entities.Map(map.MapId);

                            mapData.MaxLevel     = map.MaximumLevel;
                            mapData.MinLevel     = map.MinimumLevel;
                            mapData.DefaultFloor = map.DefaultFloor;

                            mapData.ContinentId = continent.Id;
                            mapData.RegionId    = region.RegionId;
                            mapData.RegionName  = region.Name;

                            mapData.MapRectangle.X      = map.MapRectangle.X;
                            mapData.MapRectangle.Y      = map.MapRectangle.Y;
                            mapData.MapRectangle.Height = map.MapRectangle.Height;
                            mapData.MapRectangle.Width  = map.MapRectangle.Width;

                            mapData.ContinentRectangle.X      = map.ContinentRectangle.X;
                            mapData.ContinentRectangle.Y      = map.ContinentRectangle.Y;
                            mapData.ContinentRectangle.Height = map.ContinentRectangle.Height;
                            mapData.ContinentRectangle.Width  = map.ContinentRectangle.Width;

                            // Done - return the data
                            return(mapData);
                        }
                    }
                }
            }

            // Not found
            return(null);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Change Application Culture
        /// </summary>
        /// <param name="culture">new culture</param>
        /// <param name="url">Previous Url to redirect</param>
        /// <returns>Redirect to previous url</returns>
        public ActionResult ChangeCulture(string culture, Uri url)
        {
            MemberState state = MemberStateBL.State;

            // Path to Redirect
            try
            {
                // Change Culture
                LocalizationUtil.SetCurrentCulture(culture);
                state.Culture = culture;
            }
            catch
            {
            }
            return(Redirect(url.ToString()));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Returns the item information for the items with the given IDs
        /// </summary>
        /// <param name="itemIDs">IDs of the items to retrieve</param>
        /// <returns>Collection of Item objects containing all item information</returns>
        public IDictionary <int, GW2PAO.API.Data.Entities.Item> GetItems(ICollection <int> itemIDs)
        {
            Dictionary <int, GW2PAO.API.Data.Entities.Item> items = new Dictionary <int, GW2PAO.API.Data.Entities.Item>();

            try
            {
                // Remove all items with itemID of 0 or less
                var validIDs = itemIDs.Where(id => id > 0).ToList();

                var itemService = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Items.ForCurrentUICulture() : GW2.V2.Items.ForDefaultCulture();
                var itemDetails = itemService.FindAll(validIDs);
                var prices      = this.GetItemPrices(validIDs);

                foreach (var itemDetail in itemDetails)
                {
                    GW2PAO.API.Data.Entities.Item item = new Data.Entities.Item(itemDetail.Key, itemDetail.Value.Name);
                    item.Icon             = itemDetail.Value.IconFileUrl;
                    item.Description      = itemDetail.Value.Description;
                    item.Rarity           = (Data.Enums.ItemRarity)itemDetail.Value.Rarity;
                    item.Flags            = (Data.Enums.ItemFlags)itemDetail.Value.Flags;
                    item.GameTypes        = (Data.Enums.ItemGameTypes)itemDetail.Value.GameTypes;
                    item.LevelRequirement = itemDetail.Value.Level;
                    item.VenderValue      = itemDetail.Value.VendorValue;
                    item.ChatCode         = itemDetail.Value.GetItemChatLink().ToString();
                    if (prices.ContainsKey(item.ID))
                    {
                        item.Prices = prices[item.ID];
                    }
                    else
                    {
                        item.Prices = new ItemPrices(); // empty, no prices found
                    }
                    // Since there is no need to use ALL details right now, we'll just get what we need...
                    // TODO: Finish this up, get all details, such as Type, SkinID

                    items.Add(item.ID, item);
                }
            }
            catch (Exception ex)
            {
                // Don't crash, just return null
                logger.Warn(ex, "Error finding item");
            }

            return(items);
        }
        /// <summary>
        /// 获取当前语言文化,使用的是Cookies存储,使用之前必须启用Cookies
        /// </summary>
        /// <param name="context">上下文</param>
        /// <returns>文化</returns>
        public static string GetCurrentCulture(this HttpContext context)
        {
            string culture;

            if (context.Request.Cookies.TryGetValue("Culture", out culture))
            {
                if (string.IsNullOrWhiteSpace(culture))
                {
                    return(LocalizationUtil.GetCurrentCulture());
                }
                else
                {
                    return(culture);
                }
            }

            return(LocalizationUtil.GetCurrentCulture());
        }
Exemplo n.º 17
0
    /// <summary>
    /// Initializes PKHeX's runtime strings to the specified language.
    /// </summary>
    /// <param name="lang">2-char language ID</param>
    /// <param name="sav">Save data (optional)</param>
    /// <param name="hax">Permit illegal things (items, only)</param>
    public static void InitializeStrings(string lang, SaveFile?sav = null, bool hax = false)
    {
        var str = GameInfo.Strings = GameInfo.GetStrings(lang);

        if (sav != null)
        {
            GameInfo.FilteredSources = new FilteredGameDataSource(sav, GameInfo.Sources, hax);
        }

        // Update Legality Analysis strings
        ParseSettings.ChangeLocalizationStrings(str.movelist, str.specieslist);

        // Update Legality Strings
        Task.Run(() =>
        {
            RibbonStrings.ResetDictionary(str.ribbons);
            LocalizationUtil.SetLocalization(typeof(LegalityCheckStrings), lang);
            LocalizationUtil.SetLocalization(typeof(MessageStrings), lang);
        });
    }
Exemplo n.º 18
0
        /// <summary>
        /// Retrieves the map information for the given map ID
        /// </summary>
        /// <param name="mapId">The ID of a zone</param>
        /// <returns>The map data</returns>
        public Data.Entities.Map GetMap(int mapId)
        {
            try
            {
                // Get the current map info
                var map = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Maps.ForCurrentUICulture().Find(mapId) : GW2.V2.Maps.ForDefaultCulture().Find(mapId);
                if (map != null)
                {
                    Data.Entities.Map m = new Data.Entities.Map(mapId);

                    m.MaxLevel     = map.MaximumLevel;
                    m.MinLevel     = map.MinimumLevel;
                    m.DefaultFloor = map.DefaultFloor;

                    m.ContinentId = map.ContinentId;
                    m.RegionId    = map.RegionId;
                    m.RegionName  = map.RegionName;

                    m.MapRectangle.X      = map.MapRectangle.X;
                    m.MapRectangle.Y      = map.MapRectangle.Y;
                    m.MapRectangle.Height = map.MapRectangle.Height;
                    m.MapRectangle.Width  = map.MapRectangle.Width;

                    m.ContinentRectangle.X      = map.ContinentRectangle.X;
                    m.ContinentRectangle.Y      = map.ContinentRectangle.Y;
                    m.ContinentRectangle.Height = map.ContinentRectangle.Height;
                    m.ContinentRectangle.Width  = map.ContinentRectangle.Width;

                    return(m);
                }
            }
            catch (Exception ex)
            {
                // Don't crash if something goes wrong, but log the error
                logger.Error(ex);
            }

            return(null);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Initializes the zone service
        /// </summary>
        public void Initialize()
        {
            if (Monitor.TryEnter(this.initLock))
            {
                try
                {
                    if (this.MapNamesCache.IsEmpty)
                    {
                        foreach (var mapName in LocalizationUtil.IsSupportedCulture() ? GW2.V2.Maps.ForCurrentUICulture().FindAll() : GW2.V2.Maps.ForDefaultCulture().FindAll())
                        {
                            this.MapNamesCache.TryAdd(mapName.Key, mapName.Value.MapName);
                        }
                    }

                    if (this.ContinentsCache.IsEmpty)
                    {
                        // Get all continents
                        var continents = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Continents.ForCurrentUICulture().FindAll() : GW2.V2.Continents.ForDefaultCulture().FindAll();

                        foreach (var continent in continents.Values)
                        {
                            Data.Entities.Continent cont = new Data.Entities.Continent(continent.ContinentId);
                            cont.Name     = continent.Name;
                            cont.Height   = continent.ContinentDimensions.Height;
                            cont.Width    = continent.ContinentDimensions.Width;
                            cont.FloorIds = continent.FloorIds;
                            cont.MaxZoom  = continent.MaximumZoom;
                            cont.MinZoom  = continent.MinimumZoom;
                            this.ContinentsCache.TryAdd(cont.Id, cont);
                        }
                    }
                }
                finally
                {
                    Monitor.Exit(this.initLock);
                }
            }
        }
Exemplo n.º 20
0
        private static void DumpStrings(Type t, bool sorted, params string[] rel)
        {
            var dir = GetResourcePath(rel);
            var langs = new[] { DefaultLanguage }.Concat(Languages);

            foreach (var lang in langs)
            {
                LocalizationUtil.SetLocalization(t, lang);
                var entries = LocalizationUtil.GetLocalization(t);
                var export  = entries.Select(z => new { Variable = z.Split('=')[0], Line = z })
                              .OrderBy(z => z.Variable) // sort by length (V1 = 2, V100 = 4)
                              .Select(z => z.Line);     // sorted lines

                if (!sorted)
                {
                    export = entries;
                }

                var location = GetFileLocationInText(t.Name, dir, lang);
                File.WriteAllLines(location, export);
                LocalizationUtil.SetLocalization(t, DefaultLanguage);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Retrieves the floor data for the given floor ID, using the internal cache when possible
        /// </summary>
        /// <param name="continentId">ID of the continent the floor is for</param>
        /// <param name="floorId">ID of the floor to retrieve</param>
        /// <returns>The floor data</returns>
        private GW2NET.Maps.Floor GetFloor(int continentId, int floorId)
        {
            GW2NET.Maps.Floor result = null;

            var key = new Tuple <int, int>(continentId, floorId);

            if (this.FloorCache.ContainsKey(key))
            {
                this.FloorCache.TryGetValue(key, out result);
            }
            else
            {
                var floorService = LocalizationUtil.IsSupportedCulture() ? GW2.V1.Floors.ForCurrentUICulture(continentId) : GW2.V1.Floors.ForDefaultCulture(continentId);
                var floor        = floorService.Find(floorId);
                if (floor != null)
                {
                    this.FloorCache.TryAdd(key, floor);
                    result = floor;
                }
            }

            return(result);
        }
Exemplo n.º 22
0
        protected override string GetParameterTitle()
        {
            string output = "";

            if (string.IsNullOrEmpty(title))
            {
                if (vessels.Count == 1)
                {
                    output = Localizer.Format("#cc.param.VesselNotDestroyed", ContractVesselTracker.GetDisplayName(vessels[0]));
                }
                else if (vessels.Count != 0)
                {
                    output = Localizer.Format("#cc.param.VesselNotDestroyed", LocalizationUtil.LocalizeList <string>(LocalizationUtil.Conjunction.OR, vessels, v => ContractVesselTracker.GetDisplayName(v)));
                }
                else if (Parent is VesselParameterGroup && ((VesselParameterGroup)Parent).VesselList.Any())
                {
                    IEnumerable <string> vesselList = ((VesselParameterGroup)Parent).VesselList;
                    if (vesselList.Count() == 1)
                    {
                        output = Localizer.Format("#cc.param.VesselNotDestroyed", ContractVesselTracker.GetDisplayName(vesselList.First()));
                    }
                    else
                    {
                        output = Localizer.Format("#cc.param.VesselNotDestroyed", LocalizationUtil.LocalizeList <string>(LocalizationUtil.Conjunction.OR, vesselList, v => ContractVesselTracker.GetDisplayName(v)));
                    }
                }
                else
                {
                    output = Localizer.GetStringByTag("#cc.param.VesselNotDestroyed.any");
                }
            }
            else
            {
                output = title;
            }
            return(output);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Loads the WvW objects  and initializes all cached information
        /// </summary>
        public void LoadData()
        {
            try
            {
                logger.Info("Loading worlds via API");
                this.Worlds = new List <World>();
                var worldRepository = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Worlds.ForCurrentUICulture() : GW2.V2.Worlds.ForDefaultCulture();
                var worlds          = worldRepository.FindAll();
                foreach (var world in worlds.Values)
                {
                    this.Worlds.Add(new World()
                    {
                        ID   = world.WorldId,
                        Name = world.Name
                    });
                }
            }
            catch (Exception ex)
            {
                logger.Error("Failed to load worlds data: ");
                logger.Error(ex);
            }

            logger.Info("Loading Objectives Table");
            try
            {
                this.ObjectivesTable = WvWObjectivesTable.LoadTable();
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                logger.Info("Error loading Objectives Table, re-creating table");
                WvWObjectivesTable.CreateTable();
                this.ObjectivesTable = WvWObjectivesTable.LoadTable();
            }
        }
Exemplo n.º 24
0
        protected override string GetParameterTitle()
        {
            string output = null;

            if (string.IsNullOrEmpty(title))
            {
                // "Complete any ONE of the following"
                if (state == ParameterState.Complete)
                {
                    output = StringBuilderCache.Format("{0}: {1}", Localizer.GetStringByTag("#cc.param.Any"),
                                                       LocalizationUtil.LocalizeList <ContractParameter>(LocalizationUtil.Conjunction.AND, this.GetChildren().Where(x => x.State == ParameterState.Complete), x => x.Title));
                }
                else
                {
                    output = Localizer.GetStringByTag("#cc.param.Any");
                }
            }
            else
            {
                output = title;
            }

            return(output);
        }
Exemplo n.º 25
0
        protected override string GetParameterTitle()
        {
            string output = null;

            if (string.IsNullOrEmpty(title))
            {
                // "Allow no more than <<1>> of the following"
                if (state == ParameterState.Complete)
                {
                    output = StringBuilderCache.Format("{0}: {1}", Localizer.Format("#cc.param.AtMost", count),
                                                       LocalizationUtil.LocalizeList <ContractParameter>(LocalizationUtil.Conjunction.OR, this.GetChildren().Where(x => x.State == ParameterState.Complete), x => x.Title));
                }
                else
                {
                    output = Localizer.Format("#cc.param.AtMost", count);
                }
            }
            else
            {
                output = title;
            }

            return(output);
        }
Exemplo n.º 26
0
        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="context">http上下文</param>
        /// <returns>任务</returns>
        public async Task InvokeAsync(HttpContext context)
        {
            var routeValue = context.Request.RouteValues;
            var routes     = routeValue.GetControllerAction();

            if (routes.IsNullOrLength0())
            {
                await next(context);

                return;
            }

            // 使用上下文里的文化
            string culture = context.GetCurrentCulture();

            if (string.IsNullOrWhiteSpace(culture))
            {
                // 使用子类的文化
                culture = context.GetCurrentCulture();
            }
            if (string.IsNullOrWhiteSpace(culture))
            {
                // 使用默认的文化
                culture = App.DefaultCulture;
            }
            if (string.IsNullOrWhiteSpace(culture))
            {
                await next(context);

                return;
            }

            LocalizationUtil.SetCurrentCulture(culture);

            await next(context);
        }
Exemplo n.º 27
0
 public string BodyList()
 {
     return(LocalizationUtil.LocalizeList <CelestialBody>(LocalizationUtil.Conjunction.OR, targetBodies, cb => cb.displayName));
 }
Exemplo n.º 28
0
 public string SituationList()
 {
     return(LocalizationUtil.LocalizeList <Vessel.Situations>(LocalizationUtil.Conjunction.OR, situation, sit => ReachSituation.GetTitleStringShort(sit)));
 }
        protected void CreateDelegates()
        {
            foreach (Filter filter in filters)
            {
                if (filter.type == ParameterDelegateMatchType.VALIDATE)
                {
                    foreach (AvailablePart part in filter.parts)
                    {
                        AddParameter(new CountParameterDelegate <Part>(filter.minCount, filter.maxCount, p => p.partInfo.name == part.name,
                                                                       part.title, false));
                    }

                    // Filter by part modules
                    foreach (string partModule in filter.partModules)
                    {
                        AddParameter(new CountParameterDelegate <Part>(filter.minCount, filter.maxCount, p => PartHasModule(p, partModule),
                                                                       Localizer.Format("#cc.param.PartValidation.withModule", ModuleName(partModule)), false));
                    }

                    // Filter by part module types
                    foreach (string partModuleType in filter.partModuleTypes)
                    {
                        AddParameter(new CountParameterDelegate <Part>(filter.minCount, filter.maxCount, p => PartHasObjective(p, partModuleType),
                                                                       Localizer.Format("#cc.param.PartValidation.withModuleType", ModuleTypeName(partModuleType)), false));
                    }
                }
                else
                {
                    // Filter by part
                    if (filter.parts.Any())
                    {
                        AddParameter(new ParameterDelegate <Part>(
                                         Localizer.Format("#cc.param.PartValidation.type", filter.type.Prefix(), LocalizationUtil.LocalizeList <AvailablePart>(LocalizationUtil.Conjunction.OR, filter.parts, p => p.title)),
                                         p => filter.parts.Any(pp => p.partInfo.name == pp.name), filter.type));
                    }

                    // Filter by part modules
                    foreach (string partModule in filter.partModules)
                    {
                        AddParameter(new ParameterDelegate <Part>(Localizer.Format("#cc.param.PartValidation.module", filter.type.Prefix(), ModuleName(partModule)), p => PartHasModule(p, partModule), filter.type));
                    }

                    // Filter by part modules
                    foreach (string partModuleType in filter.partModuleTypes)
                    {
                        AddParameter(new ParameterDelegate <Part>(Localizer.Format("#cc.param.PartValidation.moduleType", filter.type.Prefix(), ModuleTypeName(partModuleType)), p => PartHasObjective(p, partModuleType), filter.type));
                    }

                    // Filter by part modules - extended mode
                    foreach (List <Tuple <string, string, string> > list in filter.partModuleExtended)
                    {
                        ContractParameter wrapperParam = AddParameter(new AllParameterDelegate <Part>(Localizer.Format("#cc.param.PartValidation.moduleShort", filter.type.Prefix()), filter.type));

                        foreach (Tuple <string, string, string> v in list)
                        {
                            string name = v.Item1;
                            string label;
                            if (string.IsNullOrEmpty(v.Item2))
                            {
                                label = Regex.Replace(name, @"([A-Z]+?(?=[A-Z][^A-Z])|\B[A-Z]+?(?=[^A-Z]))", " $1");
                                label = label.Substring(0, 1).ToUpper() + label.Substring(1);
                            }
                            else
                            {
                                label = v.Item2;
                            }
                            string value = name == "name" ? ModuleName(v.Item3) : v.Item3;

                            ParameterDelegateMatchType childFilter = ParameterDelegateMatchType.FILTER;
                            wrapperParam.AddParameter(new ParameterDelegate <Part>(Localizer.Format("#cc.param.PartValidation.generic", childFilter.Prefix(), label, value), p => PartModuleCheck(p, v), childFilter));
                        }
                    }

                    // Filter by category
                    if (filter.category != null)
                    {
                        AddParameter(new ParameterDelegate <Part>(Localizer.Format("#cc.param.PartValidation.category", filter.type.Prefix(), filter.category),
                                                                  p => p.partInfo.category == filter.category.Value, filter.type));
                    }

                    // Filter by manufacturer
                    if (filter.manufacturer != null)
                    {
                        AddParameter(new ParameterDelegate <Part>(Localizer.Format("#cc.param.PartValidation.manufacturer", filter.type.Prefix(), filter.manufacturer),
                                                                  p => p.partInfo.manufacturer == filter.manufacturer, filter.type));
                    }
                }
            }

            // Validate count
            if (minCount != 0 || maxCount != int.MaxValue && !(minCount == maxCount && maxCount == 0))
            {
                AddParameter(new CountParameterDelegate <Part>(minCount, maxCount));
            }
        }
 private string GetNotificationText(int additionalAmount)
 {
     return(LocalizationUtil.LocalizeWithNumber("CardUpgrade_AttackDamage", additionalAmount));
 }