示例#1
0
        private NStorageIndex OpenIndex(String storagePath)
        {
            NStorageIndex storageIndex     = null;
            String        storageIndexFile = storagePath + ".index";

            if (File.Exists(storageIndexFile))
            {
                try
                {
                    using (StreamReader sr = new StreamReader(storageIndexFile))
                    {
                        XmlSerializer des = new XmlSerializer(typeof(NStorageIndex));
                        storageIndex      = (NStorageIndex)des.Deserialize(new System.Xml.XmlTextReader(sr));
                        storageIndex.Path = storagePath;
                        sr.Close();
                    }
                }
                catch (Exception)
                {
                    //index is corrupt get rid of it
                    File.Delete(storageIndexFile);
#if (DEBUG)
                    throw;
#endif
                }
            }

            return(storageIndex);
        }
示例#2
0
        public void InitializeStorage(String rootPath)
        {
            this._rootPath    = rootPath;
            this._inboxPath   = rootPath + @"\Inbox\";
            this._archivePath = rootPath + @"\Archive\";
            this._outboxPath  = rootPath + @"\Outbox\";
            this._sentPath    = rootPath + @"\Sent\";
            this.CreateDirectories();

            InboxIndex = OpenIndex(InboxPath);
            if (InboxIndex == null)
            {
                InboxIndex = new NStorageIndex(InboxPath);
                UpdateIndex(NStorageFolder.Inbox);
            }
            ArchiveIndex = OpenIndex(ArchivePath);
            if (ArchiveIndex == null)
            {
                ArchiveIndex = new NStorageIndex(ArchivePath);
                UpdateIndex(NStorageFolder.Archive);
            }
            OutboxIndex = OpenIndex(OutboxPath);
            if (OutboxIndex == null)
            {
                OutboxIndex = new NStorageIndex(OutboxPath);
                UpdateIndex(NStorageFolder.Outbox);
            }
            SentIndex = OpenIndex(SentPath);
            if (SentIndex == null)
            {
                SentIndex = new NStorageIndex(SentPath);
                UpdateIndex(NStorageFolder.Sent);
            }
        }
 public NikotalkieFolderView(NStorageIndex storageIndex, NikotalkieControl owner)
 {
     mOwner = owner;
     mNStorageIndex = storageIndex;
     mNStorageIndex.IndexChanged += new EventHandler(mNStorageIndex_IndexChanged);
     this.Dock = DockStyle.Fill;
     InitializeComponent();
     InitializeItems();
 }
示例#4
0
        public void InitializeStorage(String rootPath)
        {
            this._rootPath = rootPath;
            this._inboxPath = rootPath + @"\Inbox\";
            this._archivePath = rootPath + @"\Archive\";
            this._outboxPath = rootPath + @"\Outbox\";
            this._sentPath = rootPath + @"\Sent\";
            this.CreateDirectories();

            InboxIndex = OpenIndex(InboxPath);
            if (InboxIndex == null)
            {
                InboxIndex = new NStorageIndex(InboxPath);
                UpdateIndex(NStorageFolder.Inbox);
            }
            ArchiveIndex = OpenIndex(ArchivePath);
            if (ArchiveIndex == null)
            {
                ArchiveIndex = new NStorageIndex(ArchivePath);
                UpdateIndex(NStorageFolder.Archive);
            }
            OutboxIndex = OpenIndex(OutboxPath);
            if (OutboxIndex == null)
            {
                OutboxIndex = new NStorageIndex(OutboxPath);
                UpdateIndex(NStorageFolder.Outbox);
            }
            SentIndex = OpenIndex(SentPath);
            if (SentIndex == null)
            {
                SentIndex = new NStorageIndex(SentPath);
                UpdateIndex(NStorageFolder.Sent);
            }
        }
示例#5
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());
        }