I started working here this week after working at HP and Synergetics for 4 years. That was a great place, but now I am in a much better place( not that HP and Synergetics are bad) and have a job doing what I want to do: program all day everyday... Well, almost. I'm doing documentation right now on the current version of the software.
Well, it's 5:20 and I gotta make that 5-10 minute drive home.... YEAH!
Thursday, January 12, 2006
Friday, September 30, 2005
What I learned today... (SMTP via VB.NET, Singleton class instance)
Well, the first thing I learned was more about COM Interop. Boy, is that cool stuff for legacy applications and working with VBA!
At work we use BusinessObjects and publish reports through its Broadcast Agent, which is a tool for scheduling reports to be run and publishing to the BusinessObjects Web Intelligence ASP application. The "full client" has VBA macro capabilities supported by a complete BusinessObjects object model. With that being said, I have created a piece of macro code to automate the publishing process and email the report, either in the standard BO report form, PDF, or Excel XLS spreadsheet format. The class below is the email component. The original came from somewhere here on the web... When I find the original author, I'll update this posting.
Some notes about this code:
Pretty cool, huh?
The other thing I learned was the use of Shared (VB.NET) and static (C#). I found out how to create a Singleton instance of a class and use it correctly (I think)...
Here's a VB.NET sample:
To call this, simply use the following:
I'm not totally clear yet on how this exactly works, but I'm a lot closer and can implement this methodology in my apps.
Looks like I'm a little more learned in .NET!
At work we use BusinessObjects and publish reports through its Broadcast Agent, which is a tool for scheduling reports to be run and publishing to the BusinessObjects Web Intelligence ASP application. The "full client" has VBA macro capabilities supported by a complete BusinessObjects object model. With that being said, I have created a piece of macro code to automate the publishing process and email the report, either in the standard BO report form, PDF, or Excel XLS spreadsheet format. The class below is the email component. The original came from somewhere here on the web... When I find the original author, I'll update this posting.
Imports System.Web.Mail
Imports Microsoft.VisualBasic.Compatibility.VB6
Namespace Mail
Public Class SMTP
Private mTo As String
Private mFrom As String
Private mSubject As String
Private mMessage As String
Private mAttachments As New Collection
Private mServer As String = "localhost"
Public Sub New()
' Needed for COM Interop.
' Do not remove.
' Nothing to see here, move along...
End Sub
Public Property [To]() As String
Get
Return mTo
End Get
Set(ByVal Value As String)
mTo = Value
End Set
End Property
Public Property From() As String
Get
Return mFrom
End Get
Set(ByVal Value As String)
mFrom = Value
End Set
End Property
Public Property Subject() As String
Get
Return mSubject
End Get
Set(ByVal Value As String)
mSubject = Value
End Set
End Property
Public Property Message() As String
Get
Return mMessage
End Get
Set(ByVal Value As String)
mMessage = Value
End Set
End Property
Public Property Attachments() As Collection
Get
Return mAttachments
End Get
Set(ByVal Value As Collection)
mAttachments = Value
End Set
End Property
Public Property Server() As String
Get
Return mServer
End Get
Set(ByVal Value As String)
mServer = Value
End Set
End Property
Public Sub Send()
Try
Dim mail As New MailMessage
With mail
.From = Trim(Me.From)
.To = Trim(Me.To)
.Subject = Trim(Me.Subject)
.Body = Trim(Me.Message)
If Me.Attachments.Count > 0 Then
Dim file As String
For Each file In mAttachments
.Attachments.Add(New MailAttachment(Trim(file)))
Next
End If
End With
SMTPMail.SmtpServer = mServer
SMTPMail.Send(mail)
Catch ex As Exception
Throw New System.Exception(ex.Message, CType(ex, System.Exception))
End Try
End Sub
End Class
End Namespace
Some notes about this code:
- Since this is a COM Interop class, a few things are needed.
- Microsoft.VisualBasic.Compatibility.VB6
: This has the classic Collections object in it. If you aren't using COM, this can easily be replaced with an ArrayList. - A New method. This is the default constructor that COM needs. You can initialize any default values in here, but in this case all I needed was an empty contructor.
- Microsoft.VisualBasic.Compatibility.VB6
- The To property takes a comma delimited list of email addresses.
- The attachment collection needs to be a colelction of strings. These strings would be the file names with path.
Pretty cool, huh?
The other thing I learned was the use of Shared (VB.NET) and static (C#). I found out how to create a Singleton instance of a class and use it correctly (I think)...
Here's a VB.NET sample:
Namespace SingletonExample
Friend Class SingletonClass
Private Shared mSingletonClass As SingletonClass = Nothing
Public Shared ReadOnly Property SingletonClass() As SingletonClass
Get
If mSingletonClass Is Nothing Then
mSingletonClass = New SingletonClass
End If
Return mSingletonClass
End Get
End Property
Shared Sub New()
' Nothing to see here, keep moving...
End Sub
Public Shared Sub Initialize()
Console.WriteLine("In SingletonExample.SingletonClass")
End Sub
End Class
End Namespace
To call this, simply use the following:
SingletonExample.SingletonClass.Initialize()
I'm not totally clear yet on how this exactly works, but I'm a lot closer and can implement this methodology in my apps.
Looks like I'm a little more learned in .NET!
Wednesday, July 27, 2005
Very scary.... "Bloggers Blog: Toxic Weblog Fears Expand to Include All Free Hosting Sites"
Bloggers Blog: Toxic Weblog Fears Expand to Include All Free Hosting Sites
I'm going to have figure out if my blogs are doing this without my knowledge...
I'm going to have figure out if my blogs are doing this without my knowledge...
Monday, July 18, 2005
Monday, June 20, 2005
ComputerZen.com - Scott Hanselman's Weblog - Using a Windows version of GNU Patch.exe with CVS and Diff Files
Scott's got a good method for submitting patches to SourceForge projects. If you work on code for a project you aren't a developer on, check this to to get your patch submitted: ComputerZen.com - Scott Hanselman's Weblog - Using a Windows version of GNU Patch.exe with CVS and Diff Files
Thanks, Scott!
Thanks, Scott!
Quickstart Guide To Open Source Development With CVS and SourceForge
Here's some good "rules" to follow on SourceForge. I guess I'll start using these and getting my guys on WinSnipLib.NET to use them: Quickstart Guide To Open Source Development With CVS and SourceForge
Thanks, Phil!
Thanks, Phil!
ComputerZen.com - Scott Hanselman's Weblog - Scott Hanselman's 2005 Ultimate Developer and Power Users Tool List
Ok, Scott's got quite an extensive list here: ComputerZen.com - Scott Hanselman's Weblog - Scott Hanselman's 2005 Ultimate Developer and Power Users Tool List
If you need anything, it's probably here.
If you need anything, it's probably here.
Subscribe to:
Posts (Atom)