public CalendarEvent GetCurrentMeeting(string password) { NotesSession notesSession = new NotesSession(); NotesDatabase notesDatabase; try { notesSession.Initialize(password); string MailServer = notesSession.GetEnvironmentString("MailServer", true); string MailFile = notesSession.GetEnvironmentString("MailFile", true); notesDatabase = notesSession.GetDatabase(MailServer, MailFile, false); NotesDateTime minStartDate = notesSession.CreateDateTime("Today"); NotesDateTime maxEndDate = notesSession.CreateDateTime("Tomorrow"); // Query Lotus Notes to get calendar entries in our date range. // To understand this SELECT, go to http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp // and search for the various keywords. Here is an overview: // !@IsAvailable($Conflict) will exclude entries that conflicts with another. // LN doesn't show conflict entries and we should ignore them. // @IsAvailable(CalendarDateTime) is true if the LN document is a calendar entry // @Explode splits a string based on the delimiters ",; " // The operator *= is a permuted equal operator. It compares all entries on // the left side to all entries on the right side. If there is at least one // match, then true is returned. String calendarQuery = "SELECT (!@IsAvailable($Conflict) & @IsAvailable(CalendarDateTime) & (@Explode(CalendarDateTime) *= @Explode(@TextToTime(\"" + minStartDate.LocalTime + "-" + maxEndDate.LocalTime + "\"))))"; NotesDocumentCollection appointments = notesDatabase.Search(calendarQuery, null, 25); //appointments.Count NotesDocument Current = appointments.GetFirstDocument(); DateTime rightNow = DateTime.Now; CalendarEvent closestMeeting = null; TimeSpan ts = new TimeSpan(2, 0, 0, 0); //set for 2 days as longest time span while (Current != null) { int repeatCount = ((object[])Current.GetItemValue("StartDateTime")).Length; for (int i = 0; i < repeatCount; i++) { var calendarEvent = GetCallendarEvent(Current, i); if (calendarEvent.Starts <= rightNow && calendarEvent.Ends > rightNow) { //ding ding ding, winner return calendarEvent; } TimeSpan timeToMeeting = calendarEvent.Starts.Subtract(rightNow); if (timeToMeeting < ts && calendarEvent.Starts > rightNow) { ts = timeToMeeting; closestMeeting = calendarEvent; } } Current = appointments.GetNextDocument(Current); } return closestMeeting; } catch (Exception) { //TODO: Catch bad stuff here and provide a message throw; } }
public Program() { ns = new NotesSession(); ns.Initialize("password"); string mailServer = ns.GetEnvironmentString("MailServer", true); string mailFile = ns.GetEnvironmentString("MailFile", true); string userName = ns.UserName; System.Console.WriteLine($"mailServer: {mailServer}"); System.Console.WriteLine($"mailFile: {mailFile}"); System.Console.WriteLine($"userName: {userName}"); StringBuilder fullpathName = new StringBuilder(512); OSPathNetConstruct(null, mailServer, mailFile, fullpathName); System.Console.WriteLine($"fullpathName: {fullpathName.ToString()}"); HANDLE hNotesDB; HANDLE hUnreadListTable; NSFDbOpen(fullpathName.ToString(), out hNotesDB); System.Console.WriteLine($"hNotesDB: {hNotesDB.ToString()}"); NSFDbGetUnreadNoteTable(hNotesDB, userName, (ushort)userName.Length, true, out hUnreadListTable); System.Console.WriteLine($"hUnreadListTable: {hUnreadListTable.ToString()}"); db = ns.GetDatabase(mailServer, mailFile, false); int numUnreadMail = 0; bool first = true; HANDLE id; while (true) { numUnreadMail = 0; first = true; while (IDScan(hUnreadListTable, first, out id)) { doc = db.GetDocumentByID(id.ToString("X")); string subject = (string)((object[])doc.GetItemValue("Subject"))[0]; string sender = (string)((object[])doc.GetItemValue("From"))[0]; if (!sender.Equals("")) { System.Console.WriteLine($" Doc: {subject} / *{sender}*"); if (!sender.Equals(userName)) { numUnreadMail++; } } first = false; } //numUnreadMail -= 3; System.Console.WriteLine($"Unread mail: {numUnreadMail.ToString()}"); System.Threading.Thread.Sleep(3000); NSFDbUpdateUnread(hNotesDB, hUnreadListTable); } IDDestroyTable(hUnreadListTable); NSFDbClose(hNotesDB); /* * db = ns.GetDatabase(mailServer, mailFile, false); * * NotesView inbox = db.GetView("($Inbox)"); * doc = inbox.GetFirstDocument(); * System.Console.WriteLine($"Notes database: /{db.ToString()}"); * * // NotesViewEntryCollection vc = inbox.GetAllUnreadEntries(); * * while (doc != null) * { * System.DateTime lastAccessed = doc.LastAccessed; * System.DateTime lastModified = doc.LastModified; * System.DateTime created = doc.Created; * * //if ( (lastAccessed.Subtract(lastModified)).TotalSeconds==(double)0.0 && (created.Subtract(lastModified)).TotalSeconds<(double)60.0 ) * if (lastAccessed.CompareTo(lastModified) < 0) * * { * string subject = (string)((object[])doc.GetItemValue("Subject"))[0]; * System.Console.WriteLine($"LastAccessed: {doc.LastAccessed} | LastModified: {doc.LastModified} | Created: {doc.Created} | Subject: {subject}"); * } * doc = inbox.GetNextDocument(doc); * } * * db = null; * ns = null; * */ System.Console.WriteLine("Hello world!"); System.Console.ReadLine(); // as pause }