Beispiel #1
0
        public static void ClearDatabase()
        {
            if (db == null)
            {
                db = new PowerAgregatorContext5();
            }

            db.Accounts.RemoveRange(db.Accounts);

            db.ChatterUser.RemoveRange(db.ChatterUser);

            db.AgregatorUsers.RemoveRange(db.AgregatorUsers);

            db.Messages.RemoveRange(db.Messages);

            db.SaveChanges();
        }
Beispiel #2
0
        public static void SaveAccountDataToDataBase(Core core)
        {
            if (db == null)
            {
                db = new PowerAgregatorContext5();
            }

            db.Accounts.RemoveRange(db.Accounts);
            db.Accounts.AddRange(core.Chatters.Select(x => x.StoreData()));

            db.ChatterUser.RemoveRange(db.ChatterUser);
            db.ChatterUser.AddRange(core.ChatterUsers.Select(x => x.StoreData()));

            db.AgregatorUsers.RemoveRange(db.AgregatorUsers);
            db.AgregatorUsers.AddRange(core.Users.Select(x => x.StoreData()));

            db.SaveChanges();
        }
Beispiel #3
0
        public static void RestoreAccountDataFromDataBase(Core core)
        {
            if (db == null)
            {
                db = new PowerAgregatorContext5();
            }

            core.Chatters.Clear();
            foreach (SerializedAccount acc in db.Accounts)
            {
                var plugin  = PluginHelper.Plugins.First(x => x.FullName == acc.Type);
                var Chatter = Activator.CreateInstance(plugin) as IChatPlugin;
                Chatter.RestoreData(acc);
                Chatter.MessageRecived += core.AddMessage;
                core.Chatters.Add(Chatter);
            }

            core.Users        = db.AgregatorUsers.ToList().Select(x => new AgregatorUser(x)).ToList();
            core.ChatterUsers = db.ChatterUser.ToList().Select(x => new ChatterUser(x, core)).ToList();
        }