Esempio n. 1
0
        /// <summary>
        /// Downloads every message in every folder in the system. Used for building the local cache
        /// </summary>
        /// <param name="progCallback"></param>
        /// <param name="completedCallback"></param>
        public void DownloadEntireAccount(AccountDownloadProgressCallback progCallback, AccountDownloadCompleteCallback completedCallback)
        {
            int messagesCompleted = 0;
            IFolder[] folderList = GetAllFolders();
            TimeSpan ts = new TimeSpan();
            int totalMessages = GetMessageCount();
            ManualResetEvent mre = new ManualResetEvent(false);
            foreach (IFolder folder in folderList)
            {
                foreach (IMessage msg in folder.Messages)
                {
                    FullMessageRequest fmr = new FullMessageRequest(_client, msg);
                    fmr.MessageComplete += delegate(IMessage m, TimeSpan totalTime)
                                               {
                                                   progCallback(++messagesCompleted, totalMessages, m.Folder);
                                                   StoreMessage(m);
                                                   ts.Add(totalTime);
                                                   if (messagesCompleted >= totalMessages)
                                                       mre.Set();
                                               };
                    fmr.MessageProgress += delegate(IMessage m, long receieved, long total)
                                               {
                                                   Console.CursorLeft = 0;
                                                   Console.Write("{0}/{1}k downloaded", receieved / 1024, total / 1024);
                                               };
                    fmr.MessageProgress += delegate(IMessage m, long bytesReceived, long totalBytes) { };
                    fmr.Start();
                }
            }

            mre.WaitOne();

            completedCallback(folderList.Length, messagesCompleted, ts.Ticks);


        }
Esempio n. 2
0
        /// <summary>
        /// Downloads every message in every folder in the system. Used for building the local cache
        /// </summary>
        /// <param name="progCallback"></param>
        /// <param name="completedCallback"></param>
        public void DownloadEntireAccount(AccountDownloadProgressCallback progCallback, AccountDownloadCompleteCallback completedCallback)
        {
            int messagesCompleted = 0;

            IFolder[]        folderList    = GetAllFolders();
            TimeSpan         ts            = new TimeSpan();
            int              totalMessages = GetMessageCount();
            ManualResetEvent mre           = new ManualResetEvent(false);

            foreach (IFolder folder in folderList)
            {
                foreach (IMessage msg in folder.Messages)
                {
                    FullMessageRequest fmr = new FullMessageRequest(_client, msg);
                    fmr.MessageComplete += delegate(IMessage m, TimeSpan totalTime)
                    {
                        progCallback(++messagesCompleted, totalMessages, m.Folder);
                        StoreMessage(m);
                        ts.Add(totalTime);
                        if (messagesCompleted >= totalMessages)
                        {
                            mre.Set();
                        }
                    };
                    fmr.MessageProgress += delegate(IMessage m, long receieved, long total)
                    {
                        Console.CursorLeft = 0;
                        Console.Write("{0}/{1}k downloaded", receieved / 1024, total / 1024);
                    };
                    fmr.MessageProgress += delegate(IMessage m, long bytesReceived, long totalBytes) { };
                    fmr.Start();
                }
            }

            mre.WaitOne();

            completedCallback(folderList.Length, messagesCompleted, ts.Ticks);
        }