Friday, August 5, 2011

Book Review - Blindsight by Peter Watts

I recently re-read Blindsight by Peter Watts. This is a book for the software engineer in all of us.



If you're reading Charles Stross then chances are you're the developer with Think Geek stuff all over his cubicle. If you're reading Peter Watts, then you're the guy whose cube has minimal personal belongings and is so bare that many wonder whether or not anyone works in it. Your personality is such, that you are slightly confused by normal human interaction, but have learned enough to imitate being human so that human interaction doesn't become a "problem".

Personality issues aside, the book is fantastic. There's enough geek stimulation (AI, genetically revived vampires a la Jurassic Park, linguistics, biology) to keep it from becoming boring. And it doesn't follow the recurring themes that most sci-fi and fantasy seem to follow. This is hard sci-fi, not to be confused with the softer side of sci-fi, which reads more like fantasy. Peter Watts is a biologist and he isn't afraid to engage us non-biologists, even if we have to engage the footnotes.

Peter Watts was generous enough to put his book on the web for free (http://www.rifters.com/real/Blindsight.htm) for the benefit of all.

Lotus Notes Resources

Unfortunately, if you're a Lotus Notes developer StackOverflow doesn't typically have the answer and user base to answer your question. There are, however, two standard places to find what you're looking for. The Lotus Notes Forums ( Lotus Notes 8 Forum, Lotus Notes 6 & 7 Forum ) on the IBM website. They aren't readily apparent on the IBM website and if you think about it, the answer becomes clear.


Remember the video of Steve Ballmer leading the "developers, developers, developers" chant? Microsoft made it clear that it is focused on winning over developers. IBM, on the other hand, is mainly focused on winning over managers (or those with the purse strings).

I don't point that out to make either party look bad, but it does give us an idea of where we'll need to look when searching for resources and tutorials to find out how to best use the tools at our disposal.

All that said, the forums are a great place to find answer to Lotus Notes persistent questions:

Xpages Resources and Tutorials

The absolute best resource for learning XPages is the demonstration example, which can be found here (http://208.85.190.65/demos/demoapp.nsf). XPages heavily uses the Dojo toolkit ( http://dojotoolkit.org/ ), which is much like jQuery (similar concepts, same ideas; use XMLHttpRequest to drive your application).

Still, it doesn't address the main problem with XPages, which is the poor user authentication process. You can't just use the Lotus Notes account to authenticate. You have to set the Internet Password settings in every individual user account. A very tedious process if you didn't start off from the beginning using internet settings. Even in the Lotus Notes web browser it can't authenticate.

There are ways around this using Tivoli (free if you are licensed for Domino Server) or some other user account management program and as always you could write your own and reinvent the wheel.

However, if you can't answer the authentication problem, then you won't get the most out of XPages.

Thursday, August 4, 2011

Dynamic Data Limitations in ASP.NET

I recently completed a small, yet robust Dynamic Data website in ASP.NET 4.0. Going through the whole process, I can't say I recommend a Dynamic Data solution.

Pros:

  • You can get a site up and running very quickly. 
  • Many concepts like routing are used in other places such as MVC, so learning the ins and outs of Dynamic Data doesn't waste too much time. 
  • It works well with the Entity Framework. 
  • The code generation is pretty well done. I wouldn't say it is typical of what I would think of with regards to previous code generation products and that's a good thing.

Cons:

  • Your data needs to be normalized to a fault. Column names needs special ordering (if you want it to work without having to extend everything). This isn't always possible, especially if data is only loosely related. Nothing happens in a vacuum. In a typical shop data will be coming from more than one data source (SQL Server, DB2, MySQL, etc) and trying to get Dynamic Data to work well with all of them in tandem will cause more problems than not.
  • There is simply not enough comprehensive documentation. There's only one blogger http://csharpbits.notaclue.net/ out there who has taken the reigns on a technology Microsoft seems to have forgotten. I have to give the guy props for really making it work. 
  • Little things, like column order and adding a dropdownlist with static, non-relational data can become a very complicated process.

The bottom line is that things that should be easy become difficult, very quickly and I would be very hesitant handing a Dynamic Data solution to an entry level developer. And honestly, I can't say I'd look foward to working on another Dynamic Data solution.

Send an HTML email in Lotus Notes

Below is a fairly straightfoward way to send an HTML email in Lotus Notes. You can place it just about anywhere, but I recommend placing it in an Agent. That will allow you to work against more data than using it strictly inside a document.

Notice "Call stream.WriteText()", which allows us to add our HTML formatting. You'll still have to follow the normal rules of SMTP. For instance, including CSS in your email will require to call your stylesheet.

Set docMail = db.CreateDocument

'// COMPOSE MESSAGE
session.ConvertMIME = False ' Do not convert MIME to rich text
docMail.Form = "Memo"
docMail.Subject = docNotify.emailSubject(0)
docMail.Principal = "Automated Notification"

'// CREATE MAIN MIME MESSAGE
Set stream = session.CreateStream
Set MIMERoot = docMail.CreateMIMEEntity ' message root

'// CREATE CHILD ENTITIES
Set mime = MIMERoot.CreateChildEntity
Set header = MIMERoot.getNthHeader("Content-Type")
Call header.SetHeaderVal("multipart/related")


'// HEADER
Call stream.WriteText(| |) Call stream.WriteText(|

|) Call stream.WriteText(| 
Text | & document.field(0) & |
|) '// BODY Call stream.WriteText(| |) Call stream.WriteText(| | & document.field(0) & | |) Call stream.WriteText(|
|) '// FOOTER Call stream.WriteText(| |) Call stream.WriteText(| |) Call stream.WriteText(|

Text:
|)
Call stream.WriteText(| Database: | & db.Title & |
|)
Call stream.WriteText(| View: | & document.field(0) & |
|) Call mime.SetContentFromText(stream,"text/html",ENC_NONE) Call stream.Close Set header = mime.CreateHeader("Content-ID") Call header.SetHeaderVal("") Call docMail.Send( False, docNotify.notificationList ) '// RESTORE CONVERSION session.ConvertMIME = True


Optional Coding Parameters you may need:


'// OPTIONAL - Create inline image reference
' Set mime = MIMERoot.CreateChildEntity
' Call stream.Open("http://www.myserver.com/applications/mmail.nsf/" & imagename & "?OpenImageResource")
' Call mime.SetContentFromBytes(stream, "image/jpeg", ENC_NONE)
' Call stream.Close
' Call mime.EncodeContent(ENC_BASE64)


Download the code

There is actually a good book out there for learning more about Lotus Notes. It's one of the few:

Wednesday, August 3, 2011

Sending a Lotus Notes document via Email

If you're in a shop that uses Lotus Notes for applications, but MS Outlook for email, you realize pretty quickly that a lot of functionality is lost when the user has to go from one to the other. In this instance, we want to send a Lotus Notes document as a MS Word document.

In the first step, we can use part of the previous post ( see part 1 here ).


REM {  Set some basic variables };
 emailTo := "Test@***.com";
 emailSubject := @GetField("Form");

REM {  Replace spaces with %20, which Windows/web understand as spaces };
 emailSubject := @ReplaceSubstring(emailSubject; " "; "%20");

@Command([FileExport];"Microsoft RTF";"c:\\Folder\\FileName.doc");

@Command([Execute]; "OUTLOOK";"/a c:/Folder/FileName" + 
   uid + ".doc /c ipm.note /m " + emailTo + "&subject=" + emailSubject)

Image of what a final solution may look like.

MS Word should recognize that the document is rtf, but treat it like it's a compatible MS Word document. Also note that your form should be in tables of no more than 6.5 inches in width. The Rtf/Word document will not understand the Lotus Notes "Fit to Margins" settings and the text and tables will overrun the document. Putting everything in pre-formatted tables in your Lotus Notes document design is the best way to avoid it.

Tuesday, August 2, 2011

Saving a Lotus Notes document as Rtf or Word

This is probably not the best solution, but it's quick and it makes use of some built in Lotus Notes functionality.

Assumptions:

  1. We're going to assume that you can write a document to the user’s hard drive.
  2. If you can't, why can't you? If your IT group can stop you from saving, then they can create a folder that can be written to.
Add this code to a button:

@Command([FileExport];"Microsoft RTF";"c:\\Folder\\FileName.doc");



Screenshot in Lotus Notes Designer
Word understands what to do with an RTF. To take advantage of that, we can save the file with a .doc extension and Word will open the document correctly. However, there could be margin issues. Make sure that the text in your document is in a table that has a width of no more than 6.5 inches (see this post for help). This will prevent clipping.


From a standards standpoint, we use the 6.5 inch table width on all our forms instead of using "Fit to Margins" settings. This gives us more control over how the user sees and interacts with the form.