Exemple #1
0
        public MessagePuller(AppContext appContext)
        {
            this.appContext = appContext;

            yamsterArchiveDb = appContext.YamsterArchiveDb;
            yamsterCoreDb    = appContext.YamsterCoreDb;
            yamsterApi       = appContext.YamsterApi;

            HistoryLimitDays = 90;

            UpToDate = false;
        }
Exemple #2
0
        public void ConnectDatabase(EventHandler <SQLiteDataContextUpgradeEventArgs> beforeUpgradeHandler,
                                    EventHandler afterUpgradeHandler)
        {
            if (this.DatabaseConnected)
            {
                throw new InvalidOperationException("The database is already connected");
            }

            this.sqliteMapper = new SQLiteMapper(this.DatabaseFilePath, createIfMissing: true);
            this.sqliteMapper.Open();
            this.yamsterArchiveDb = new YamsterArchiveDb(sqliteMapper,
                                                         beforeUpgradeHandler, afterUpgradeHandler);
            this.yamsterCoreDb = new YamsterCoreDb(yamsterArchiveDb);
            this.yamsterCache  = new YamsterCache(this);

            this.messagePuller = new MessagePuller(this);
        }
Exemple #3
0
        public void Load(string folderPath)
        {
            if (networkId != 0)
            {
                throw new InvalidOperationException("The Load() method was already called for this instance.");
            }

            if (!Directory.Exists(folderPath))
            {
                throw new DirectoryNotFoundException("The specified folder does not exist:\r\n\""
                                                     + folderPath + "\"");
            }

            this.FolderPath = folderPath;

            YamsterCoreDb yamsterCoreDb = appContext.YamsterCoreDb;

            ReadCsvFiles();
            FixupMessageBodies();
            WriteToDatabase(yamsterCoreDb);
        }
Exemple #4
0
        public YamsterCache(AppContext appContext)
        {
            this.AppContext = appContext;

            yamsterCoreDb = appContext.YamsterCoreDb;

            yamsterCoreDb.Groups.RecordChanged      += Groups_RecordChanged;
            yamsterCoreDb.GroupStates.RecordChanged += GroupStates_RecordChanged;

            yamsterCoreDb.ThreadStates.RecordChanged += ThreadStates_RecordChanged;

            yamsterCoreDb.Conversations.RecordChanged += Conversations_RecordChanged;

            yamsterCoreDb.Messages.RecordChanged      += Messages_RecordChanged;
            yamsterCoreDb.MessageStates.RecordChanged += MessageStates_RecordChanged;

            yamsterCoreDb.Users.RecordChanged += Users_RecordChanged;

            GLib.Timeout.Add(500, OnPollTimer);

            this.ReloadEverything();
        }
Exemple #5
0
        void WriteToDatabase(YamsterCoreDb yamsterCoreDb)
        {
            using (var transaction = yamsterCoreDb.BeginTransaction())
            {
                yamsterCoreDb.DeleteEverything(markArchiveDbInactive: true);

                yamsterCoreDb.UpdateProperties(row => {
                    row.CurrentNetworkId = this.networkId;
                });

                foreach (var user in this.usersById.Values)
                {
                    // NOTE: For now, deleted users are always included because they
                    // are heavily referenced
                    //if (this.IncludeDeletedObjects || !this.deletedUsers.Contains(user.UserId))

                    yamsterCoreDb.Users.InsertRecord(user);
                }

                foreach (var group in this.groupsById.Values)
                {
                    if (this.IncludeDeletedObjects || !this.deletedGroups.Contains(group.GroupId))
                    {
                        yamsterCoreDb.Groups.InsertRecord(group);

                        DbGroupState groupState = new DbGroupState()
                        {
                            GroupId = group.GroupId
                        };
                        groupState.ShowInYamster = true;
                        yamsterCoreDb.GroupStates.InsertRecord(groupState);
                    }
                }

                foreach (var conversation in this.conversationsById.Values)
                {
                    if (this.IncludeDeletedObjects || this.notDeletedConversations.Contains(conversation.ConversationId))
                    {
                        yamsterCoreDb.Conversations.InsertRecord(conversation);
                    }
                }

                foreach (var message in this.messagesById.Values)
                {
                    bool messageIsDeleted = this.deletedMessages.Contains(message.MessageId);

                    if (this.IncludeDeletedObjects || !messageIsDeleted)
                    {
                        yamsterCoreDb.Messages.InsertRecord(message);

                        DbMessageState messageState = new DbMessageState()
                        {
                            MessageId = message.MessageId
                        };
                        messageState.Deleted = messageIsDeleted;
                        yamsterCoreDb.MessageStates.InsertRecord(messageState);

                        // Ensure that every message has a corresponding DbThreadState for its thread
                        DbThreadState threadState = new DbThreadState()
                        {
                            ThreadId = message.ThreadId
                        };
                        yamsterCoreDb.ThreadStates.InsertRecord(threadState, SQLiteConflictResolution.Ignore);
                    }
                }

                transaction.Commit();
            }
        }