Example #1
0
        public void MoveMessage(NStorageFolder destination, NMessage message)
        {

        }
Example #2
0
 public void MoveMessage(NStorageFolder destination, NMessage message)
 {
 }
Example #3
0
        public void UpdateIndex(NStorageFolder folder)
        {
            NStorageIndex storageIndex = null;
            String storagePath = null;
            switch (folder)
            {
                case NStorageFolder.Inbox:
                    storageIndex = InboxIndex;
                    break;
                case NStorageFolder.Archive:
                    storageIndex = ArchiveIndex;
                    break;
                case NStorageFolder.Outbox:
                    storageIndex = OutboxIndex;
                    break;
                case NStorageFolder.Sent:
                    storageIndex = SentIndex;
                    break;
                default:
                    break;
            }
            if (storageIndex == null || !Directory.Exists(storageIndex.Path)) return;

            String[] files = Directory.GetFiles(storageIndex.Path, "*.xml");

            //remove deleted
            
            for (int i = storageIndex.Messages.Count - 1; i >= 0; i--)
            {
                bool exists = false;
                for (int j = 0; j < files.Length; j++)
                {
                    if (files[j] == storageIndex.Messages[i].LocalFileName) exists = true;
                }
                if (!exists)
                {
                    storageIndex.Messages.RemoveAt(i);
                }
            }
            //add new
            for (int i = 0; i < files.Length; i++)
            {

                if (!storageIndex.ExistsFile(files[i]))
                {
                    NMessage message = new NMessage();
                    using (StreamReader sr = new StreamReader(files[i]))
                    {
                        if (File.Exists(files[i]))
                        {
                            XmlSerializer des = new XmlSerializer(typeof(NMessage));
                            message = (NMessage)des.Deserialize(new System.Xml.XmlTextReader(sr));
                            sr.Close();
                        }
                    }

                    if (message != null)
                    {
                        message.Body = null;
                        storageIndex.Messages.Add(message);
                        storageIndex.LastMessageId = message.Header.MsgID;
                    }

                }
            }

            //save index
            try
            {
                using (StreamWriter sw = new StreamWriter(storagePath + ".index"))
                {
                    XmlSerializer ser = new XmlSerializer(typeof(NStorageIndex));
                    ser.Serialize(sw, storageIndex);
                    sw.Close();
                }

            }
            catch (Exception ex)
            {
#if (DEBUG)
                        throw;
#endif
            }

            storageIndex.SortIndex();
            storageIndex.OnIndexChanged(storageIndex, new EventArgs());
        }
Example #4
0
        public void UpdateIndex(NStorageFolder folder)
        {
            NStorageIndex storageIndex = null;
            String        storagePath  = null;

            switch (folder)
            {
            case NStorageFolder.Inbox:
                storageIndex = InboxIndex;
                break;

            case NStorageFolder.Archive:
                storageIndex = ArchiveIndex;
                break;

            case NStorageFolder.Outbox:
                storageIndex = OutboxIndex;
                break;

            case NStorageFolder.Sent:
                storageIndex = SentIndex;
                break;

            default:
                break;
            }
            if (storageIndex == null || !Directory.Exists(storageIndex.Path))
            {
                return;
            }

            String[] files = Directory.GetFiles(storageIndex.Path, "*.xml");

            //remove deleted

            for (int i = storageIndex.Messages.Count - 1; i >= 0; i--)
            {
                bool exists = false;
                for (int j = 0; j < files.Length; j++)
                {
                    if (files[j] == storageIndex.Messages[i].LocalFileName)
                    {
                        exists = true;
                    }
                }
                if (!exists)
                {
                    storageIndex.Messages.RemoveAt(i);
                }
            }
            //add new
            for (int i = 0; i < files.Length; i++)
            {
                if (!storageIndex.ExistsFile(files[i]))
                {
                    NMessage message = new NMessage();
                    using (StreamReader sr = new StreamReader(files[i]))
                    {
                        if (File.Exists(files[i]))
                        {
                            XmlSerializer des = new XmlSerializer(typeof(NMessage));
                            message = (NMessage)des.Deserialize(new System.Xml.XmlTextReader(sr));
                            sr.Close();
                        }
                    }

                    if (message != null)
                    {
                        message.Body = null;
                        storageIndex.Messages.Add(message);
                        storageIndex.LastMessageId = message.Header.MsgID;
                    }
                }
            }

            //save index
            try
            {
                using (StreamWriter sw = new StreamWriter(storagePath + ".index"))
                {
                    XmlSerializer ser = new XmlSerializer(typeof(NStorageIndex));
                    ser.Serialize(sw, storageIndex);
                    sw.Close();
                }
            }
            catch (Exception ex)
            {
#if (DEBUG)
                throw;
#endif
            }

            storageIndex.SortIndex();
            storageIndex.OnIndexChanged(storageIndex, new EventArgs());
        }