Пример #1
0
        public static void LanguageStatistics_OnCommand(CommandEventArgs e)
        {
            var ht = new Dictionary <string, InternationalCodeCounter>();

            using var writer = new StreamWriter("languages.txt");
            if (CountAccounts)
            {
                foreach (Account acc in Accounts.GetAccounts())
                {
                    for (var i = 0; i < acc.Length; i++)
                    {
                        var mob = acc[i];

                        var lang = mob?.Language;

                        if (lang == null)
                        {
                            continue;
                        }

                        lang = lang.ToUpper();

                        if (ht.TryGetValue(lang, out var codes))
                        {
                            codes.Increase();
                        }
                        else
                        {
                            ht[lang] = new InternationalCodeCounter(lang);
                        }

                        break;
                    }
                }
            }
            else
            {
                foreach (var mob in World.Mobiles.Values)
                {
                    if (mob.Player)
                    {
                        var lang = mob.Language;

                        if (lang == null)
                        {
                            continue;
                        }

                        lang = lang.ToUpper();

                        if (ht.TryGetValue(lang, out var codes))
                        {
                            codes.Increase();
                        }
                        else
                        {
                            ht[lang] = new InternationalCodeCounter(lang);
                        }
                    }
                }
            }

            writer.WriteLine(
                $"Language statistics. Numbers show how many {(CountAccounts ? "accounts" : "playermobile")} use the specified language.");
            writer.WriteLine(
                "====================================================================================================");
            writer.WriteLine();

            // sort the list
            var list = new List <InternationalCodeCounter>(ht.Values);

            list.Sort(InternationalCodeComparer.Instance);

            foreach (var c in list)
            {
                writer.WriteLine($"{GetFormattedInfo(c.Code)}‎ : {c.Count}");
            }

            e.Mobile.SendMessage("Languages list generated.");
        }
Пример #2
0
        public static void LanguageStatistics_OnCommand(CommandEventArgs e)
        {
            Dictionary <string, InternationalCodeCounter> ht = new Dictionary <string, InternationalCodeCounter>();

            using (StreamWriter writer = new StreamWriter("languages.txt"))
            {
                if (CountAccounts)
                {
                    // count accounts
                    foreach (Account acc in Accounts.ServerAccounts.GetAccounts())
                    {
                        for (int i = 0; i < acc.Length; i++)
                        {
                            Mobile mob = acc[i];

                            if (mob == null)
                            {
                                continue;
                            }

                            string lang = mob.Language;

                            if (lang != null)
                            {
                                lang = lang.ToUpper();

                                if (!ht.ContainsKey(lang))
                                {
                                    ht[lang] = new InternationalCodeCounter(lang);
                                }
                                else
                                {
                                    ht[lang].Increase();
                                }

                                break;
                            }
                        }
                    }
                }
                else
                {
                    // count playermobiles
                    foreach (Mobile mob in World.Mobiles.Values)
                    {
                        if (mob.Player)
                        {
                            string lang = mob.Language;

                            if (lang != null)
                            {
                                lang = lang.ToUpper();

                                if (!ht.ContainsKey(lang))
                                {
                                    ht[lang] = new InternationalCodeCounter(lang);
                                }
                                else
                                {
                                    ht[lang].Increase();
                                }
                            }
                        }
                    }
                }

                writer.WriteLine(String.Format("Language statistics. Numbers show how many {0} use the specified language.", CountAccounts ? "accounts" : "playermobile"));
                writer.WriteLine("====================================================================================================");
                writer.WriteLine();

                // sort the list
                List <InternationalCodeCounter> list = new List <InternationalCodeCounter>(ht.Values);
                list.Sort(InternationalCodeComparer.Instance);

                foreach (InternationalCodeCounter c in list)
                {
                    writer.WriteLine(String.Format("{0}‎ : {1}", GetFormattedInfo(c.Code), c.Count));
                }

                e.Mobile.SendMessage("Languages list generated.");
            }
        }