Esempio n. 1
0
 public void Save(bool force = true, bool makeResponse = false, bool markRead = false) => document.Save(force, makeResponse, markRead);
 private void SetMailAsRead(NotesDocument profileDocument, IDocumentCollection documentCollection)
 {
     try
     {
         profileDocument.ReplaceItemValue("UntilTime", documentCollection.UntilTime);
         profileDocument.Save(true, true, true);
     }
     catch (Exception e)
     {
         Logger logger = LogManager.GetCurrentClassLogger();
         logger.Log(LogLevel.Error, e);
     }
 }
        /// <summary>
        /// 获取新信件
        /// </summary>
        /// <returns></returns>
        public bool GetMailInfo()
        {
            bool          bResult       = false;
            NotesView     pMailView     = null;
            NotesDocument pMailDocument = null;
            int           iCount        = 0;

            try
            {
                if (this._strDataBase == "names.nsf")
                {
                    this.pNotesDatabase = this._pNotesSession.GetDatabase(this._strDomain, this._strDataBase, false);
                }

                if (this.pNotesDatabase == null)
                {
                    throw new Exception("不能打开数据库:" + this._strDataBase);
                }

                pMailView = this.pNotesDatabase.GetView("($inbox)");

                pMailDocument = pMailView.GetFirstDocument();
                Console.WriteLine("共计:" + pMailView.EntryCount.ToString());

                CustomDataCollection pMailStruct = new CustomDataCollection(StructType.CUSTOMDATA);

                while (pMailDocument != null)
                {
                    if (((object[])pMailDocument.GetItemValue("Reader"))[0].ToString() != "YES")
                    {
                        string strPUID        = string.Empty;
                        string strSubject     = (((object[])pMailDocument.ColumnValues)[5] == null) ? "N/A" : ((object[])pMailDocument.ColumnValues)[5].ToString();
                        string strSupervisors = (((object[])pMailDocument.GetItemValue("CopyTo")).Length == 0) ? "N/A" : ((object[])pMailDocument.GetItemValue("CopyTo"))[0].ToString();
                        string strSendTo      = (((object[])pMailDocument.GetItemValue("SendTo")).Length == 0) ? "N/A" : ((object[])pMailDocument.GetItemValue("SendTo"))[0].ToString();

                        if (strSendTo != "N/A")
                        {
                            for (int i = 0; i < ((object[])pMailDocument.GetItemValue("SendTo")).Length; i++)
                            {
                                strSupervisors = strSupervisors + ";" + ((object[])pMailDocument.GetItemValue("SendTo"))[i].ToString();
                            }
                        }

                        if (strSupervisors != "N/A")
                        {
                            for (int i = 1; i < ((object[])pMailDocument.GetItemValue("CopyTo")).Length; i++)
                            {
                                strSupervisors = strSupervisors + ";" + ((object[])pMailDocument.GetItemValue("CopyTo"))[i].ToString();
                            }
                        }

                        string strBody = ((object[])pMailDocument.GetItemValue("Body"))[0].ToString();

                        if (((object[])pMailDocument.GetItemValue("SSM_Agent"))[0].ToString().Length != 0)
                        {
                            strPUID = ((object[])pMailDocument.GetItemValue("SSM_Agent"))[0].ToString();
                        }
                        else if (((object[])pMailDocument.GetItemValue("SSM_Agent"))[0].ToString().Length == 0 && pMailDocument.ParentDocumentUNID == null)
                        {
                            strPUID = "N/A";
                        }
                        else
                        {
                            strPUID = pMailDocument.ParentDocumentUNID;
                        }

                        /*
                         * if (pMailDocument.HasItem("SMS Agent"))
                         * {
                         *  strPUID = ((object[])pMailDocument.GetItemValue("SMS Agent"))[0].ToString();
                         * }
                         * else if (!pMailDocument.HasItem("SMS Agent") && pMailDocument.ParentDocumentUNID == null)
                         * {
                         *  strPUID = "N/A";
                         * }
                         * else
                         * {
                         *  strPUID = pMailDocument.ParentDocumentUNID;
                         * }
                         */

                        //剔除--服务器正常和服务器一切正常
                        if (strSubject.IndexOf("服务器正常", StringComparison.CurrentCulture) > 0 || strSubject.IndexOf("服务器一切正常", StringComparison.CurrentCulture) > 0)
                        {
                            if (pMailDocument.HasItem("Reader"))
                            {
                                pMailDocument.ReplaceItemValue("Reader", "YES");
                            }
                            else
                            {
                                pMailDocument.AppendItemValue("Reader", "YES");
                            }

                            pMailDocument.Save(true, true, true);
                        }
                        else
                        {
                            pMailStruct.Add(DataField.NOTES_UID, DataFormat.STRING, pMailDocument.UniversalID);
                            pMailStruct.Add(DataField.NOTES_UID, DataFormat.STRING, strPUID);
                            pMailStruct.Add(DataField.NOTES_SUBJECT, DataFormat.STRING, strSubject);
                            pMailStruct.Add(DataField.NOTES_FROM, DataFormat.STRING, ((object[])pMailDocument.GetItemValue("Principal"))[0].ToString());
                            pMailStruct.Add(DataField.NOTES_DATE, DataFormat.STRING, ((object[])pMailDocument.ColumnValues)[2].ToString());
                            pMailStruct.Add(DataField.NOTES_SUPERVISORS, DataFormat.STRING, (strSupervisors == "") ? "N/A" : strSupervisors);
                            pMailStruct.Add(DataField.NOTES_CONTENT, DataFormat.STRING, (strBody == "") ? "N/A" : strBody);
                            try
                            {
                                pMailStruct.Add(DataField.NOTES_ATTACHMENTCOUNT, DataFormat.STRING, (((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects == null) ? "0" : ((object[])((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects).Length.ToString());
                            }
                            catch
                            {
                                pMailStruct.Add(DataField.NOTES_ATTACHMENTCOUNT, DataFormat.STRING, "信件内包含多个信件主体,请查阅自己的信箱!");
                            }
                            pMailStruct.AddRows();

                            //GlobalStruct[] pMailStruct = new GlobalStruct[8];

                            //pMailStruct[0].oFieldsName = "Notes_UID";
                            //pMailStruct[0].oFiledsTypes = "String";
                            //pMailStruct[0].oFieldValues = pMailDocument.UniversalID;

                            //pMailStruct[1].oFieldsName = "Notes_PUID";
                            //pMailStruct[1].oFiledsTypes = "String";
                            //pMailStruct[1].oFieldValues = strPUID; // (pMailDocument.ParentDocumentUNID == null) ? "N/A" : pMailDocument.ParentDocumentUNID;

                            //pMailStruct[2].oFieldsName = "Notes_Subject";
                            //pMailStruct[2].oFiledsTypes = "String";
                            //pMailStruct[2].oFieldValues = strSubject;

                            //pMailStruct[3].oFieldsName = "Notes_From";
                            //pMailStruct[3].oFiledsTypes = "String";
                            //pMailStruct[3].oFieldValues = ((object[])pMailDocument.GetItemValue("Principal"))[0].ToString(); //((object[])pMailDocument.ColumnValues)[1].ToString();

                            //pMailStruct[4].oFieldsName = "Notes_Date";
                            //pMailStruct[4].oFiledsTypes = "String";
                            //pMailStruct[4].oFieldValues = ((object[])pMailDocument.ColumnValues)[2].ToString();

                            //pMailStruct[5].oFieldsName = "Notes_Supervisors";
                            //pMailStruct[5].oFiledsTypes = "String";
                            //pMailStruct[5].oFieldValues = (strSupervisors == "") ? "N/A" : strSupervisors;

                            //pMailStruct[6].oFieldsName = "Notes_Content";
                            //pMailStruct[6].oFiledsTypes = "String";
                            //pMailStruct[6].oFieldValues = (strBody == "") ? "N/A" : strBody;

                            //pMailStruct[7].oFieldsName = "Notes_AttachmentCount";
                            //pMailStruct[7].oFiledsTypes = "String";
                            //try
                            //{
                            //    pMailStruct[7].oFieldValues = (((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects == null) ? "0" : ((object[])((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects).Length.ToString();
                            //}
                            //catch
                            //{
                            //    pMailStruct[7].oFieldValues = "信件内包含多个信件主体,请查阅自己的信箱!";
                            //}

                            this.pInfoList.Add(pMailStruct);

                            if (pMailDocument.HasItem("Reader"))
                            {
                                pMailDocument.ReplaceItemValue("Reader", "YES");
                            }
                            else
                            {
                                pMailDocument.AppendItemValue("Reader", "YES");
                            }

                            //pMailStruct = null;

                            pMailDocument.Save(true, true, true);
                            iCount++;
                        }
                    }

                    //pMailDocument.PutInFolder("历史纪录", false);

                    pMailDocument = pMailView.GetNextDocument(pMailDocument);

                    //if (pMailDocument != null)
                    //{
                    //    pMailView.GetPrevDocument(pMailDocument).Remove(false);
                    //}
                }

                this.pRecords = pMailStruct;
                bResult       = true;
            }
            catch (Exception ex)
            {
                this.strMessage = ex.Message;
                Console.WriteLine("丢失Notes个数" + iCount.ToString());
                bResult = false;
                //this.pInfoList.Clear();
            }
            finally
            {
                if (pMailDocument != null)
                {
                    Marshal.ReleaseComObject(pMailDocument);
                }

                if (pMailView != null)
                {
                    Marshal.ReleaseComObject(pMailView);
                }

                pMailDocument = null;
                pMailView     = null;
            }

            return(bResult);
        }