Exemple #1
0
        public void _EditDeck(Deck dDeck)
        {
            if (File.Exists(CurrentDeckFile))
            {
                //this is shit
                var db = new LiteDatabase(CurrentDeckFile);
                var wordCol = db.GetCollection<Word>("words");
                var allWords = wordCol.FindAll().ToList();

                //remove all words that were removed
                foreach (Word w in allWords)
                {
                    if (dDeck.Words.FindAll(tw => tw.sGuid.Equals(w.sGuid)).Count == 0)
                    {
                        wordCol.Delete(w.Id);
                    }
                }

                db.Commit();

                UpdateDeckDB(dDeck.Words);

                PamyaDeck.Instance.CurrentDeck = dDeck;

                ShowDeck();
            }
        }
Exemple #2
0
        public static async Task RunBattlelogSearchAsync()
        {
            var client = new BattlelogApiClient();

            LiteCollection<BattlelogUser> userDocs;
            IList<BattlelogUser> storedUsers;

            // Can't get user list, let's just load up our last known users list and hope for the best
            using (var db = new LiteDatabase(AppContext.SQLITE_FILENAME))
            {
                userDocs = db.GetCollection<BattlelogUser>("users");
                storedUsers = userDocs.FindAll().ToList();
            }

            // Autenticate User
            client.Login(ConfigurationManager.AppSettings["BattlelogUserName"],
                ConfigurationManager.AppSettings["BattlelogPassword"]);

            string includeSelfStr = ConfigurationManager.AppSettings["MonitorCurrentUser"];

            // Download ComCenter Statuses
            var users =
                client.GetComCenterStatuses(!string.IsNullOrEmpty(includeSelfStr) && bool.Parse(includeSelfStr)) ??
                storedUsers;

            using (var db = new LiteDatabase(AppContext.SQLITE_FILENAME))
            {
                bool showSavingMsg = false;

                // Add/Update found users locally
                foreach (var user in users)
                {
                    var userRepo = db.GetCollection<BattlelogUser>("users");
                    var matchingUser = userRepo.Find(obj => obj.UserName == user.UserName).SingleOrDefault();
                    if (null != matchingUser)
                    {
                        if (user.IsOnline)
                        {
                            showSavingMsg = true;
                            user.LastSeen = DateTime.UtcNow;
                        }

                        bool isOnlineStatusUpdated = matchingUser.IsOnline != user.IsOnline;
                        if (isOnlineStatusUpdated)
                        {
                            showSavingMsg = true;
                            // User has changed online state since last update
                            Console.WriteLine("[{0}] {1} {2}", DateTime.UtcNow.ToShortTimeString(), user.UserName,
                                user.IsOnline ? "is online" : "has gone offline");
                        }

                        bool isPlayingStatusUpdated = matchingUser.IsPlaying != user.IsPlaying;
                        if (isPlayingStatusUpdated)
                        {
                            showSavingMsg = true;
                            if (user.IsPlaying && matchingUser.IsPlaying && (matchingUser.ServerID != user.ServerID))
                            {
                                // User has changed server since last update
                                await NotifyChats(
                                    string.Format("{0} has changed servers, and is now playing {1} ({2}) on {3} ({4})",
                                        user.UserName,
                                        BattlelogApiClient.GetGameName(user.GameType),
                                        user.Platform,
                                        user.ServerName,
                                        BattlelogApiClient.GetGameUrl(user.GameType, user.Platform, user.ServerID)));
                            }
                            else if (user.IsPlaying && !matchingUser.IsPlaying)
                            {
                                await NotifyChats(
                                    string.Format("{0} has started playing {1} ({2}) on {3} ({4})",
                                        user.UserName,
                                        BattlelogApiClient.GetGameName(user.GameType),
                                        user.Platform,
                                        user.ServerName,
                                        BattlelogApiClient.GetGameUrl(user.GameType, user.Platform, user.ServerID)));
                            }
                            else if (!user.IsPlaying && matchingUser.IsPlaying)
                            {
                                await NotifyChats(
                                    string.Format("{0} has stopped playing {1} ({2})",
                                        user.UserName,
                                        BattlelogApiClient.GetGameName(user.GameType),
                                        user.Platform));
                            }
                        }

                        // Delete stale record
                        userRepo.Delete(obj => obj.UserID == user.UserID);
                    }
                    else
                    {
                        Console.WriteLine("[{0}] {1} {2}", DateTime.UtcNow.ToShortTimeString(), user.UserName,
                            users.Any() ? "has accepted your friend request" : "discovered as friend");
                    }

                    // Insert user record
                    userRepo.Insert(user);
                }

                if (showSavingMsg)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("[{0}] Saving new user statuses to disk", DateTime.UtcNow.ToShortTimeString());
                    Console.ForegroundColor = DefaultColor;
                }

                db.Commit();
            }
        }
Exemple #3
0
        public void UpdateDeckDB(List<Word> ws)
        {
            if (File.Exists(CurrentDeckFile) && CurrentGame.bIsGame) //So that we don't commit whilst in menu mode...
            {
                var db = new LiteDatabase(CurrentDeckFile);
                var wordCol = db.GetCollection<Word>("words");
                foreach (var w in ws)
                {
                    if (wordCol.Find(tw => tw.sGuid.Equals(w.sGuid)).ToList().Count == 0)
                    {

                        wordCol.Insert(w);
                    }
                    else
                    {
                        wordCol.Update(w);
                    }
                }
                db.Commit();
            }
        }
Exemple #4
0
        private void _ImportFromText(string text, string DeckFolder)
        {
            var DeckFile = DeckFolder + @"\word.db";

            Debug.Print(DeckFolder);

            var importDeck = new Deck();
            importDeck.fillDeckFromString(text); // change this
            var db = new LiteDatabase(DeckFile); //this does not belong here, move. FIXME
            var wordCol = db.GetCollection<Word>("words");
            List<Word> newWords = new List<Word>();
            foreach (var w in importDeck.Words)
            {
                if (wordCol.Find(tw => tw.sGuid == w.sGuid).ToList().Count == 0)
                {
                    wordCol.Insert(w);
                }
            }
            db.Commit();
        }