Skip to main content

Feeding the simple Html Calendar with Exoledb

Man this was a lot harder then I expected it would be, When it comes to representing time in anything you are really starting to deal with a different dimension (I think time is the third dimension). Eg you can select all the records in a calendar with the startdate greater then the first of the month and a startdate less then the end of the month but this is going to miss all multi-day appointments. Also in my example say I wanted to know if there where any appointments that where on the 5th then just looking at the start date of an appointment wouldn't necessarily tell me this because I could have a multiday event that started on the 4th and finished on the 6th. The other problem i faced is i wanted to show all the days where there was some appointments scheduled as bold and clickable trying to do this you also run into the same problem where appointments span Multiple days (Also a lot of advanced aggregate functions aren't available in Exoledb).

To solve this problem my solution was to use a sliding time window, so to get all the appointments for the month I had to query for all appointments with a enddate greater then the 1st of the month and a startdate that was less then the 1st day of next month. To work out if there were any appointments on each particular day I did a 31 repetition for next loop using a time window that spanned a 1 day and re-filtered the recordset for each repitition. (the logic sounds a bit weird but its one of those things you really need to think about but it does work and only requires one query of the Exchange Server). Then I just reused the array in the for next loop that generated the calendar

To feed my Asp calendar I packaged up the Exoledb code into a WSC com object and then created a wrapper that runs under an account that had rights to the calendar I wanted this page to access. I also created some click thoughs that would display the days appointments in a table on the right of the page. This still needs a fair bit of work but it works fine at the moment. I would have prefered to maybe use some inline xml so i didn't have to requery Exchange everytime i looked at a different day.

WSC object ..


<?xml version="1.0"?>
<component>

<registration
description="calfeed"
progid="calfeed.WSC"
version="1.00"
classid="{4414f884-d473-401a-8357-b899f3de8f31}"
>
</registration>

<public>
<method name="mailbox">
<PARAMETER name="MBname"/>
</method>
</public>

<implements type="ASP" id="ASP"/>

<script language="VBScript">
<![CDATA[

function mailbox(MBname)

set shell = createobject("wscript.shell")
strValueName = "HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
minTimeOffset = shell.regread(strValueName)
toffset = datediff("h",DateAdd("n", minTimeOffset, now()),now())
dtListFrom = DateAdd("n", minTimeOffset, now())
gmttime = dateadd("h",toffset,now())
dtListTo = isodateit(dateserial(year(now()),month(dateadd("m",1,now())),1)& " " & timeserial(0,0,0))
dtListFrom = isodateit(dateserial(year(now()),month(now()),1) & " " & timeserial(0,0,0))
Set Rs = CreateObject("ADODB.Recordset")
set Rec = CreateObject("ADODB.Record")
Set Conn = CreateObject("ADODB.Connection")
CalendarURL = "http://yourserver/exchange/" & MBname & "/calendar"
Conn.Provider = "ExOLEDB.DataSource"
Rec.Open CalendarURL
Set Rs.ActiveConnection = Rec.ActiveConnection
Rs.Source = "SELECT ""DAV:href"", " & _
" ""urn:schemas:httpmail:subject"", " & _
" ""urn:schemas:calendar:dtstart"", " & _
" ""urn:schemas:calendar:dtend"", " & _
" ""urn:schemas:calendar:organizer"", " & _
" ""urn:schemas:calendar:location"", " & _
" ""DAV:contentclass"" " & _
"FROM scope('shallow traversal of """ & CalendarURL & """') " & _
"WHERE (""urn:schemas:calendar:dtend"" > CAST(""" & dtListFrom & """ as 'dateTime'))" & _
"AND (""urn:schemas:calendar:dtstart"" < CAST(""" & dtListTo & """ as 'dateTime'))"& _
" AND ""DAV:contentclass"" = 'urn:content-classes:appointment'" & _
"ORDER BY ""urn:schemas:calendar:dtstart"" ASC"

Rs.CursorLocation = 3 'adUseServer = 2, adUseClient = 3
Rs.CursorType = 3
Rs.Open
set mailbox = Rs
end function

function isodateit(datetocon)
strDateTime = year(datetocon) & "-"
if (Month(datetocon) < 10) then strDateTime = strDateTime & "0"
strDateTime = strDateTime & Month(datetocon) & "-"
if (Day(datetocon) < 10) then strDateTime = strDateTime & "0"
strDateTime = strDateTime & Day(datetocon) & "T" & formatdatetime(datetocon,4) &":00Z"
isodateit = strDateTime
end function


]]>
</script>

Calendar ASP page ....
<%
CD = request.querystring("cday")
set cfeed = createobject("calfeed.WSC")
set rs = cfeed.mailbox("yourmailbox")
set shell = createobject("wscript.shell")
strValueName = "HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
minTimeOffset = shell.regread(strValueName)
toffset = datediff("h",DateAdd("n", minTimeOffset, now()),now())
dtListFrom = DateAdd("n", minTimeOffset, now())
redim myarray(3,31)
for i = 1 to 31
rs.filter = "urn:schemas:calendar:dtend > '" & dateadd("h",-toffset,dateserial(year(now()),month(now()),i))
& "' and urn:schemas:calendar:dtstart < '" & dateadd("h",-toffset,dateserial(year(now()),month(now()),i+1)) & "'"
myarray(1,i) = rs.recordcount
myarray(2,i) = dateadd("h",-toffset,dateserial(year(now()),month(now()),i))
myarray(3,i) = dateadd("h",-toffset,dateserial(year(now()),month(now()),i+1))
next
rs.filter = ""
%>
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>

<br>
<table border="1" cellspacing="1" width="100%">
<tr>
<td width="151"><table border="0" id="table1" cellpadding="2" width="147">
<tr><b><% response.write "<td style=""padding: 0"" width=""112""
align=""center"" colspan=""7""><b><font face=""Arial"" color=""#000080"">" &
monthname(month(now())) & " " & Year(now()) &"</td>"
%></font></b> </tr>
<tr>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
S</td>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
M</td>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
T</td>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
W</td>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
T</td>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
F</td>
<td style="border-bottom-style: solid; padding: 0" width="16" align="center">
S</td>
</tr>
<%
cdatefday = cdate(dateserial(year(now()),month(now()),"1"))
sday = weekday(cdatefday)
cmonth = month(now())
for x = 1 to 6
response.write "<tr>"
for i = 1 to 7
if cmonth = month(cdatefday) then
if sday =< i then
sday = 0
if myarray(1,day(cdatefday)) = 0 then
response.write "<td style=""padding: 0"" width=""16"" align=""center"">" &
day(cdatefday) & "</td>"
else
response.write "<td style=""padding: 0"" width=""16"" align=""center""><a
href=""caltest2.asp?cday=" & day(cdatefday) & """><b>" & day(cdatefday) & "</a></b></td>"
end if
cdatefday = dateadd("d",1,cdatefday)
else
response.write "<td style=""padding: 0"" width=""16"" align=""center""> </td>"

end if
else
response.write "<td style=""padding: 0"" width=""16"" align=""center""> </td>"

end if
next
response.write "</tr>"
next

%></td>
<td>&nbsp;</td>
</tr>
</table>
<td width="617"><table border="0" cellspacing="0" width="100%" id="table2" cellpadding="0"><tr>
<td width="154"><B>Start Date</B></td>
<td width="154"><B>End Date</B></td>
<td><B>Subject</B></td>
</tr>
<% If CD <> "" then
rs.filter = "urn:schemas:calendar:dtend > '" &
dateadd("h",-toffset,dateserial(year(now()),month(now()),CD)) & "' and urn:schemas:calendar:dtstart < '" & dateadd("h",-toffset,dateserial(year(now()),month(now()),CD+1)) & "'"
end if
while not rs.eof
response.write "<tr>" & vbcrlf
response.write "<td width=""154"">" & dateadd("h",toffset,rs.fields("urn:schemas:calendar:dtstart")) & "</td>" & vbcrlf
response.write "<td width=""154"">" &
dateadd("h",toffset,rs.fields("urn:schemas:calendar:dtend")) & "</td>" & vbcrlf
response.write "<td>" & rs.fields("urn:schemas:httpmail:subject") & "</td>" & vbcrlf
response.write "</tr>" & vbcrlf
rs.movenext
wend
%>
</table>



Popular posts from this blog

The MailboxConcurrency limit and using Batching in the Microsoft Graph API

If your getting an error such as Application is over its MailboxConcurrency limit while using the Microsoft Graph API this post may help you understand why. Background   The Mailbox  concurrency limit when your using the Graph API is 4 as per https://docs.microsoft.com/en-us/graph/throttling#outlook-service-limits . This is evaluated for each app ID and mailbox combination so this means you can have different apps running under the same credentials and the poor behavior of one won't cause the other to be throttled. If you compared that to EWS you could have up to 27 concurrent connections but they are shared across all apps on a first come first served basis. Batching Batching in the Graph API is a way of combining multiple requests into a single HTTP request. Batching in the Exchange Mail API's EWS and MAPI has been around for a long time and its common, for email Apps to process large numbers of smaller items for a variety of reasons.  Batching in the Graph is limited to a m

Sending a Message in Exchange Online via REST from an Arduino MKR1000

This is part 2 of my MKR1000 article, in this previous post  I looked at sending a Message via EWS using Basic Authentication.  In this Post I'll look at using the new Outlook REST API  which requires using OAuth authentication to get an Access Token. The prerequisites for this sketch are the same as in the other post with the addition of the ArduinoJson library  https://github.com/bblanchon/ArduinoJson  which is used to parse the Authentication Results to extract the Access Token. Also the SSL certificates for the login.windows.net  and outlook.office365.com need to be uploaded to the devices using the wifi101 Firmware updater. To use Token Authentication you need to register an Application in Azure https://msdn.microsoft.com/en-us/office/office365/howto/add-common-consent-manually  with the Mail.Send permission. The application should be a Native Client app that use the Out of Band Callback urn:ietf:wg:oauth:2.0:oob. You need to authorize it in you tenant (eg build a small ap

How to test SMTP using Opportunistic TLS with Powershell and grab the public certificate a SMTP server is using

Most email services these day employ Opportunistic TLS when trying to send Messages which means that wherever possible the Messages will be encrypted rather then the plain text legacy of SMTP.  This method was defined in RFC 3207 "SMTP Service Extension for Secure SMTP over Transport Layer Security" and  there's a quite a good explanation of Opportunistic TLS on Wikipedia  https://en.wikipedia.org/wiki/Opportunistic_TLS .  This is used for both Server to Server (eg MTA to MTA) and Client to server (Eg a Message client like Outlook which acts as a MSA) the later being generally Authenticated. Basically it allows you to have a normal plain text SMTP conversation that is then upgraded to TLS using the STARTTLS verb. Not all servers will support this verb so if its not supported then a message is just sent as Plain text. TLS relies on PKI certificates and the administrative issue s that come around certificate management like expired certificates which is why I wrote th
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.