Exemple #1
0
        // TODO : change list to set for a better merge
        public List <Message> GetMessagesFrom(DateTime date, int msgCount, Exception e)
        {
            MessageSet msgSet = null;

            // if their is a change in te architecture of packs while we retreive messages, then we try again
            // To detect when the structure has changed, we add a guid in metadata to get the version of the structure
            do
            {
                // get blobs
                List <KeyValuePair <DateTime, CloudBlob> > blobsList = GetBlobs();
                if (!blobsList.Any())
                {
                    throw e;
                }

                // get the right blob
                // TODO : find a better datasutrcture to do this faster
                int blobIndex = blobsList.IndexOf(blobsList.Last(p => p.Key <= date));

                // get the messages
                try
                {
                    msgSet = GetMessageSet(new Blob <MessageSet>(blobsList[blobIndex].Value));
                    msgSet = msgSet.GetViewBetween(Message.FirstMessage(date), Message.LastMessage());

                    // get messages from following sets while we need them
                    for (blobIndex++; blobIndex < blobsList.Count && msgSet.Count < msgCount; blobIndex++)
                    {
                        msgSet.UnionWith(GetMessageSet(new Blob <MessageSet>(blobsList[blobIndex].Value)));
                    }
                }
                catch (VersionHasChanged) { continue; }
            } while (false);

            List <Message> msgList = msgSet.ToList();

            if (msgList.Count > msgCount)
            {
                msgList = msgList.GetRange(0, msgCount);
            }

            return(msgList);
        }
Exemple #2
0
        // TODO : change list to set for a better merge
        public List <Message> GetMessagesTo(DateTime date, int msgCount, Exception e)
        {
            MessageSet msgSet = null;

            // TODO : use something else than reverse
            do
            {
                // get blobs
                List <KeyValuePair <DateTime, CloudBlob> > blobsList = GetBlobs();
                if (!blobsList.Any())
                {
                    throw e;
                }

                // get the right blob
                // TODO : find a better datasutrcture to do this faster
                int blobIndex = blobsList.IndexOf(blobsList.Last(p => p.Key <= date));

                // get the messages
                try
                {
                    msgSet = GetMessageSet(new Blob <MessageSet>(blobsList[blobIndex].Value));
                    msgSet = msgSet.GetViewBetween(Message.FirstMessage(), Message.LastMessage(date));

                    // get messages from following sets while we need them
                    for (blobIndex--; blobIndex >= 0 && msgSet.Count < msgCount; blobIndex--)
                    {
                        msgSet.UnionWith(GetMessageSet(new Blob <MessageSet>(blobsList[blobIndex].Value)));
                    }
                }
                catch (VersionHasChanged) { continue; }
            } while (false);

            List <Message> msgList = msgSet.ToList();

            if (msgList.Count > msgCount)
            {
                msgList = msgList.GetRange(msgList.Count - msgCount, msgCount);
            }

            return(msgList);
        }