My First Ruby on Rails Application!

I just published my first Ruby on Rails (RoR) application onto my development server – my MacBook Pro.  Learning RoR should prove to be interesting, as the Model-View-Controller (MVC) design pattern is automatically used when setting up the application.  This first app is no more than the equivalent of the “Hello, World” app in some other language.

RoR version: Ruby 1.9.3p194 running Rails 3.2.7

My First RoR Application running on Safari 6.0 / OS X Mountain Lion.

Problems with the Out of Office Indicator and Status Message on Microsoft Lync 2010

This isn’t a software development problem per se, but it was a technical problem I had with Lync that does not appear to have been documented, based on my searches.
In an enterprise environment where Microsoft Lync is integrated with Exchange, Lync has an indicator that shows if your Out of Office Assistant (OoOA) in Outlook is turned on.  It appears as a little red asterisk in the lower right-hand corner of the status light.  Also, your Lync status message is automatically set to whatever your OoOA internal message is.

If you set your OoOA to be turned on and off at a scheduled time, the Lync features will be activated when the start time passes.  The problem I had was that even when the end time had passed and Outlook’s feature had been turned off automatically, Lync’s feature remained on.  Even changing the status message in Lync manually did not work; it was immediately reset to the one set up in Outlook.  Closing and reopening both Lync and Outlook had no apparent effect.

I discovered that if I manually activated the OoOA and then manually deactivated it, Lync was once again properly synched up with Exchange and the red asterisk and status message reverted to their default states.

Creating a Custom GridView Object

An earlier post dealt with creating a GridView programmatically.  In some cases, this GridView might need to be used multiple times throughout a site, either using the same data, or perhaps a different set of data.  Several options exist when determining how to implement this.

The simplest, of course, would be simply to copy the code and then make changes in each copy as needed.  This clearly violates the DRY principle, and will only lead to heartache (and possibly carpal tunnel syndrome) in the long run.  As soon as the customer wants the look and feel of the GridView to change, you would have to change each instance where the code was copied.

The second, and slightly more desirable option, would be to refactor this code into a method that creates the GridView by calling the method.  While this is much preferable to having 20 verbatim copies of code in your site, it’s still not ideal.  This methodology contributes to spaghetti programming, and should be avoided when feasible.

The ideal method is to create an object that inherits from the GridView class, and then setting the attributes in the object.  Once the object is instantiated, any attributes that need to be added or overridden can be at runtime, prior to a databind event.

Here is an example of a class that inherits from GridView:

Public Class MyGridView
Inherits System.Web.UI.WebControls.GridView
Public Sub New(ByVal strID As String)
  ID = strID
  CssClass = "gridview"
  AutoGenerateColumns = False
  CellPadding = 4
  DataKeyNames = New String() {"ExampleID"}
  ForeColor = Drawing.ColorTranslator.FromHtml("#2a2723")
  GridLines = GridLines.None
  Width = Unit.Percentage(100)
  AllowSorting = True
  AllowPaging = False

  Dim strHeadBack As String = "#ffcb00"
  Dim strPagerBack As String = "#009ddb"
  Dim strForeColor As String = "#000000"

  HeaderStyle.BackColor = Drawing.ColorTranslator.FromHtml(strHeadBack)
  HeaderStyle.Font.Bold = True
  HeaderStyle.ForeColor = Drawing.ColorTranslator.FromHtml(strForeColor)

  RowStyle.BackColor = Drawing.ColorTranslator.FromHtml("#FFFBD6")
  RowStyle.ForeColor = Drawing.ColorTranslator.FromHtml("#2a2723")
  RowStyle.HorizontalAlign = HorizontalAlign.Center

  AlternatingRowStyle.BackColor = Drawing.Color.White

  BorderColor = Drawing.ColorTranslator.FromHtml("#d80073")
  BorderStyle = BorderStyle.Groove

  Dim ViewButton As New ButtonField
  ViewButton.HeaderText = "View"
  ViewButton.ButtonType = ButtonType.Button
  ViewButton.Text = "View"
  ViewButton.CommandName = "ViewExample"

  Dim EditButton As New TemplateField
  EditButton.HeaderText = "Edit"
  EditButton.ItemTemplate = New MyButtonTemplate ' This is a user-defined class that creates this Button
  EditButton.Visible = bEditVisible

  Dim Voided As New CheckBoxField
  Voided.HeaderText = "Voided"
  Voided.DataField = "Voided"
  Voided.ReadOnly = True
  Voided.Visible = bVoidVisible

  Dim ExampleDate As New TemplateField
  ExampleDate.HeaderText = "Date/Time"
  ExampleDate.SortExpression = "Date_and_Time"
  ExampleDate.ItemTemplate = New MyLabelTemplate ' This is a user-defined class that creates this Label
  ExampleDate.ItemStyle.Wrap = False

  Dim ShortColumn As New BoundField
  ShortColumn.ItemStyle.CssClass = "left"
  ShortColumn.HeaderText = "Short Column"
  ShortColumn.SortExpression = "Short_Column"
  ShortColumn.DataField = "Short_Column"
  ShortColumn.ItemStyle.Wrap = True
  ShortColumn.ItemStyle.Width = 150

  Dim LongColumn As New BoundField
  LongColumn.ItemStyle.CssClass = "left"
  LongColumn.HeaderText = "Long Column"
  LongColumn.SortExpression = "Long_Column"
  LongColumn.DataField = "Long_Column"
  LongColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Left
  LongColumn.ItemStyle.Wrap = True
  LongColumn.ItemStyle.Width = 200

  Dim CreatedBy As New BoundField
  CreatedBy.HeaderText = "Created By"
  CreatedBy.SortExpression = "CreatedBy"
  CreatedBy.DataField = "CreatedBy"
End Sub
End Class

To instantiate the object, simply declare the GridView as “MyGridView”, as below:

Private WithEvents gv1 As New MyGridView("gv1")


gv1.DataSource = dvDataView  'A previously defined DataView

'...any other attributes to be added or overridden

' To remove a column use:

gv1.Columns.RemoveAt(x) ' where x is the index of the column

' Bind the data to the GridView



And that’s it!  The custom GridView is like any other GridView; DataBind() can be called to rebind data, it can be hidden or made visible, etc.

Running SSRS Reports with Lotus Notes Databases as the Original Data Source

I had a need to be able to report on data inside a set of Lotus Notes 7.0 databases, and I wanted to use SQL Server Reporting Services (SSRS) to do this. There is no direct interface between SSRS and Notes, but I found that IBM provided an ODBC connection from Notes using their NotesSQL drivers.

I have set up an interface between Lotus Notes and Microsoft SQL Server 2000 using IBM’s NotesSQL ODBC drivers. The Lotus Notes 7 Client, NotesSQL 8.5.1 drivers, and an ODBC DSN (using the NotesSQL client) for each Lotus Notes database are all installed on the SQL Server. These ODBC drivers are compatible with 32-bit SQL 2000 but not SQL 2008 R2 (64-bit). I have not had an opportunity to test on any other platform as yet, though it’s certainly safe to assume that other versions of Lotus Notes up to 8.5.1 should work, since that’s what the NotesSQL drivers were written for.

I created a Linked Server on the SQL Server for each ODBC DSN; that is, each connected Notes database. The views and tables in the Notes DBs can be accessed via OPENQUERY commands, which can be included in a SQL database on the SQL Server. Because the connection between the two using only the Linked Server seemed so slow, I built a SQL Server database called Noteslink.

To test, I connected Query Analyzer to the NotesLink database on the SQL Server. I created Stored Procedures with the convention sp_DBname_AllDocuments to pull the All Documents view from the Notes database whose DSN had the name DBname. (In each case where there is a “DBname” below, substitute the name of the ODBC DSN.)

USE [NotesLink]

/****** Object:  StoredProcedure [dbo].[sp_DBname_AllDocuments]  ******/

CREATE PROCEDURE [dbo].[sp_DBname_AllDocuments] AS
'Select * from All_Documents')


Run the command “EXEC sp_DBname_AllDocuments” in Query Analyzer and this will pull the All Documents view from the DBname database.

From here, I built various jobs that would insert the results into tables in the “NotesLink” SQL Server database. I connected the SSRS reports to the “NotesLink” database, and fun was had by all. This exact configuration will not work if you need real-time reports; you would have to use OPENQUERY statements in the SSRS queries to pull directly from the Notes databases.

Please let me know if you have tried this and what other ways this could be accomplished. As SQL Server 2000 is reaching end-of-life, a newer solution using SQL 2005/2008/2012 could become necessary.