Beispiel #1
0
        public static IVoteSite FindSite(int uid)
        {
            IVoteSite site;

            VoteSites.TryGetValue(uid, out site);
            return(site);
        }
Beispiel #2
0
        private static void CMInvoke()
        {
            if (VoteSites.Count != 0)
            {
                return;
            }

            var sites = new List <IVoteSite>();

            SiteTypes.ForEach(
                type =>
            {
                var site = type.CreateInstanceSafe <IVoteSite>();

                if (site == null)
                {
                    return;
                }

                if (site.Name == "Vita-Nex")
                {
                    site.Enabled = true;
                }

                sites.Add(site);
                CMOptions.ToConsole(
                    "Created site ({0}) '{1}', '{2}'", site.GetType().Name, site.Name, site.Enabled ? "Enabled" : "Disabled");
            });

            sites.ForEach(s => VoteSites.AddOrReplace(s.UID, s));

            InternalSiteSort();
        }
Beispiel #3
0
        public static void Remove(this IVoteSite site)
        {
            VoteSites.Remove(site.UID);

            site.Delete();

            Profiles.Values.ForEach(
                p => p.History.ForEach((t, h) => h.Where(e => e.VoteSite == site).ForEach(e => e.VoteSite = VoteSite.Empty)));
        }
Beispiel #4
0
        private static void InternalSiteSort()
        {
            if (VoteSites.Count < 2)
            {
                return;
            }

            var list = VoteSites.Values.ToList();

            VoteSites.Clear();
            list.Sort(InternalSiteSort);
            list.ForEach(s => VoteSites.Add(s.UID, s));
            list.Clear();
        }
Beispiel #5
0
        private static void CMInvoke()
        {
            if (VoteSites.Count != 0)
            {
                return;
            }

            var sites = new List <IVoteSite>();

            SiteTypes.ForEach(
                type => VitaNexCore.TryCatch(
                    () =>
            {
                var site = type.CreateInstance <IVoteSite>();

                if (site == null)
                {
                    return;
                }

                if (site.Name == "Vita-Nex")
                {
                    site.Enabled = true;
                }

                sites.Add(site);
                CMOptions.ToConsole(
                    "Created site ({0}) '{1}', '{2}'", site.GetType().Name, site.Name, site.Enabled ? "Enabled" : "Disabled");
            },
                    CMOptions.ToConsole));

            sites.ForEach(
                s =>
            {
                if (!VoteSites.ContainsKey(s.UID))
                {
                    VoteSites.Add(s.UID, s);
                }
                else
                {
                    VoteSites[s.UID] = s;
                }
            });

            InternalSiteSort();
        }
Beispiel #6
0
        public static void Remove(this IVoteSite site)
        {
            VoteSites.Remove(site.UID);

            foreach (var h in Profiles.Values.SelectMany(p => p.History.Values))
            {
                h.RemoveAll(
                    e =>
                {
                    if (e.VoteSite != site)
                    {
                        return(false);
                    }

                    e.VoteSite = null;
                    return(true);
                });
            }

            site.Delete();
        }