"John Butler" <nospamjrbutler@btinternet.com> wrote:
>
>Thanks Rob. Not sure you'll shut anyone up...but it is a great illustration
>and I'm sure some of us'll use it...


To go along with this and Pat's comment:
Yes, I'm sure a lot of them don't care. They have consistently shown that
they don't care about the *solution*, they only care to complain - which
is why nobody gives them a shred of respect, or gives their moaning any sympathy.
Also why their credability is in the crapper half the time (if not more).
I'm sure some of them will go right on complaining. However, the original
complaint is why the App object is missing. Well, now it is *not*. All legit
reasons for that particular gripe have been eliminated.

>Observation though: I notice you had to do an API declaration to get the

OS
>version? Would've thought the framework provided that somewhere....but
>obviously not...seems like an oversight...


It is in the framework. I just rushed the code and that was what popped into
my head first.

I'm also expecting there to be some issues with combinations of flags in
the LogMode (I HATED how MS threw these bit flags together - look at the
first 3 to see what I'm talking about).

Here's a revised version of the code (with some other fixes), just in case
anyone goes ripping through the archive one day for it:


=================================================================
Option Explicit On
Option Strict On

Imports System.Reflection
Imports System.Reflection.Assembly
Imports System.Diagnostics.Process
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.IO


' In order to set/retrieve project Comments, you must add this attribute

' to your Assembly Info file.
<Serializable(), AttributeUsage(AttributeTargets.Assembly)> _
Public Class AssemblyCommentAttribute
Inherits System.Attribute

Private _comments As String

Public Sub New(ByVal Comments As String)
_comments = Comments
End Sub

Public ReadOnly Property Comments() As String
Get
Return _comments
End Get
End Property
End Class

' Create a Console or Service type application if you want a truly
' unattended process. If you want to programmatically query for
' unattended app status, add this attribute to the assembly information
' file, and pass TRUE to the constructor. Do this only if your application
' does not have a user interface.
<Serializable(), AttributeUsage(AttributeTargets.Assembly)> _
Public Class UnattendedAppAttribute
Inherits System.Attribute

Private _unattended As Boolean

Public Sub New(ByVal Unattended As Boolean)
_unattended = Unattended
End Sub

Public ReadOnly Property Unattended() As Boolean
Get
Return _unattended
End Get
End Property
End Class

Friend Enum LogModeFlags
vbLogAuto = 0 'If running on Windows 95 or later, this option logs
messages to the file specified in the LogFile property. If running on Windows
NT, messages are logged to the Windows NT Application Event Log, with "VBNET"
used as the application source and App.Title appearing in the description.

VbLogOff = 1 'Turns logging off from the App object.
VbLogToFile = 2 'Forces logging to a file.
VbLogToNT = 3 'Forces logging to the NT event log. If not running
on Windows NT, or the event log is unavailable, logging is ignored and the
property is set to vbLogOff.
VbLogOverwrite = 16 'Indicates that the logfile should be recreated each
time the application starts. This value can be combined with other mode options
using the OR operator. The default action for logging is to append to the
existing file. In the case of NT event logging, this flag has no meaning.

VbLogThreadID = 32 'Indicates that the current thread ID be prepended
to the message, in the form "[T:0nnn] ". This value can be combined with
other mode options using the OR operator.
vbLogAutoWithThreadID = VbLogThreadID
vbLogToFileAndOverwrite = 18
vbLogToFileWithThreadID = 34
vbLogToFileAndOverwriteWithThreadID = 52
vbLogToNTWithThreadID = 35
End Enum

Friend Enum VBEventType
vbLogEventTypeError = 1 'Error.
vbLogEventTypeWarning = 2 'Warning.
vbLogEventTypeInformation = 4 'Information
End Enum

Friend Structure AssemblyInfo
Friend Title As String
Friend Company As String
Friend Description As String
Friend Comments As String
Friend Product As String
Friend Copyright As String
Friend Trademark As String
Friend Unattended As Boolean
Friend PreviousInstance As Boolean
End Structure

Friend Structure Version
Friend Major As Integer
Friend Minor As Integer
Friend Build As Integer
Friend Revision As Integer
End Structure

Friend Class App

Private Const EventLogSource As String = "VBNET"
Private Const ErrOLEAutoModel As String = "Not implmented. .NET does
not use the same OLE Automation RPC model."


Private Shared _initialized As Boolean
Private Shared _assemblyInfo As AssemblyInfo
Private Shared _version As VBApp.Version

Private Shared _logMode As LogModeFlags
Private Shared _logPath As String
Private Shared _ranFirstFileLog As Boolean
Private Shared _eventLog As EventLog

Friend Shared ReadOnly Property PrevInstance() As Boolean
Get
Return _assemblyInfo.PreviousInstance
End Get
End Property

Friend Shared ReadOnly Property TaskVisible() As Boolean
Get
Return Not Process.GetCurrentProcess.MainWindowHandle.Equals(IntPtr.Zero)
End Get
End Property

' See AssemblyCommentsAttribute for more information
Friend Shared ReadOnly Property Comments() As String
Get
If Not _initialized Then InitAssemblyInfo()
Return _assemblyInfo.Comments
End Get
End Property

Friend Shared ReadOnly Property CompanyName() As String
Get
If Not _initialized Then InitAssemblyInfo()
Return _assemblyInfo.Company
End Get
End Property

Friend Shared ReadOnly Property Title() As String
Get
If Not _initialized Then InitAssemblyInfo()
Return _assemblyInfo.Title
End Get
End Property

Friend Shared ReadOnly Property FileDescription() As String
Get
If Not _initialized Then InitAssemblyInfo()
Return _assemblyInfo.Description
End Get
End Property

Friend Shared ReadOnly Property ProductName() As String
Get
If Not _initialized Then InitAssemblyInfo()
Return _assemblyInfo.Product
End Get
End Property

Friend Shared ReadOnly Property LegalCopyright() As String
Get
If Not _initialized Then InitAssemblyInfo()
Return _assemblyInfo.Copyright
End Get
End Property

Friend Shared ReadOnly Property LegalTrademark() As String
Get
If Not _initialized Then InitAssemblyInfo()
Return _assemblyInfo.Trademark
End Get
End Property

Friend Shared ReadOnly Property EXEName() As String
Get
Return [Assembly].GetExecutingAssembly.GetName.Name
End Get
End Property

Friend Shared ReadOnly Property Path() As String
Get
Return IO.Path.GetDirectoryName([Assembly].GetExecutingAssembly.Location)
End Get
End Property

Friend Shared ReadOnly Property Version() As VBApp.Version
Get
If Not _initialized Then InitAssemblyInfo()
Return _version
End Get
End Property

Friend Shared ReadOnly Property Major() As Integer
Get
Return App.Version.Major
End Get
End Property

Friend Shared ReadOnly Property Minor() As Integer
Get
Return App.Version.Minor
End Get
End Property

Friend Shared ReadOnly Property Build() As Integer
Get
Return App.Version.Build
End Get
End Property

Friend Shared ReadOnly Property Revision() As Integer
Get
Return App.Version.Revision
End Get
End Property

<Obsolete(".NET does not use the Component Manager or the VB5/6 Forms
classes. Therefore, non-modal forms in libraries are always allowed.")> _
Friend Shared ReadOnly Property NonModalAllowed() As Boolean
Get
Return True
End Get
End Property

Friend Shared ReadOnly Property hInstance() As IntPtr
Get
Return Marshal.GetHINSTANCE([Assembly].GetExecutingAssembly.GetModules()(0))
End Get
End Property

Friend Shared ReadOnly Property ThreadID() As Integer
Get
Return AppDomain.GetCurrentThreadId
End Get
End Property

' See UnattendedAppAttribute for more details
Friend Shared ReadOnly Property UnattendedApp() As Boolean
Get
Return _assemblyInfo.Unattended
End Get
End Property

<Obsolete("Option doesn't exist. If you are creating remoting objects,
the host keeps the application alive.")> _
Friend Shared ReadOnly Property RetainedPoject() As Boolean
Get
Return False
End Get
End Property

<Obsolete("Option doesn't exist.")> _
Friend Shared ReadOnly Property StartMode() As Integer
Get
Return 0
End Get
End Property

<Obsolete("Each form can now have a help file referred to by a HelpProvider
component. This method shows only the help file for the main form.")> _
Friend Shared ReadOnly Property HelpFile() As String
Get
Dim f As Form = DirectCast(Form.FromHandle(Process.GetCurrentProcess.MainWindowHandle),
Form)
If Not f Is Nothing Then
Dim fi() As FieldInfo
Dim i As Integer

fi = f.GetType.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic)

For i = 0 To fi.GetUpperBound(0)
If fi(i).FieldType.Name = "HelpProvider" Then
Return DirectCast(fi(i).GetValue(f), HelpProvider).HelpNamespace()
End If
Next i
End If
End Get
End Property

<Obsolete(ErrOLEAutoModel)> _
Public Property OleRequestPendingMsgText() As String
Get
Throw New NotImplementedException(ErrOLEAutoModel)
End Get
Set(ByVal Value As String)
Throw New NotImplementedException(ErrOLEAutoModel)
End Set
End Property

<Obsolete(ErrOLEAutoModel)> _
Public Property OleRequestPendingMsgTitle() As String
Get
Throw New NotImplementedException(ErrOLEAutoModel)
End Get
Set(ByVal Value As String)
Throw New NotImplementedException(ErrOLEAutoModel)
End Set
End Property

<Obsolete(ErrOLEAutoModel)> _
Public Property OleRequestPendingTimeout() As Integer
Get
Throw New NotImplementedException(ErrOLEAutoModel)
End Get
Set(ByVal Value As Integer)
Throw New NotImplementedException(ErrOLEAutoModel)
End Set
End Property

<Obsolete(ErrOLEAutoModel)> _
Public Property OleServerBusyMsgText() As String
Get
Throw New NotImplementedException(ErrOLEAutoModel)
End Get
Set(ByVal Value As String)
Throw New NotImplementedException(ErrOLEAutoModel)
End Set
End Property

<Obsolete(ErrOLEAutoModel)> _
Public Property OleServerBusyMsgTitle() As String
Get
Throw New NotImplementedException(ErrOLEAutoModel)
End Get
Set(ByVal Value As String)
Throw New NotImplementedException(ErrOLEAutoModel)
End Set
End Property

<Obsolete(ErrOLEAutoModel)> _
Public Property OleServerBusyRaiseError() As Boolean
Get
Throw New NotImplementedException(ErrOLEAutoModel)
End Get
Set(ByVal Value As Boolean)
Throw New NotImplementedException(ErrOLEAutoModel)
End Set
End Property

<Obsolete(ErrOLEAutoModel)> _
Public Property OleServerBusyTimeout() As Integer
Get
Throw New NotImplementedException(ErrOLEAutoModel)
End Get
Set(ByVal Value As Integer)
Throw New NotImplementedException(ErrOLEAutoModel)
End Set
End Property



<Obsolete("Use the EventLog classes for more flexibility.")> _
Friend Shared ReadOnly Property LogMode() As LogModeFlags
Get
Return _logMode
End Get
End Property

<Obsolete("Use the EventLog classes for more flexibility.")> _
Friend Shared ReadOnly Property LogPath() As String
Get
Return _logPath
End Get
End Property

<Obsolete("Use the EventLog classes for more flexibility.")> _
Friend Shared Sub LogEvent(ByVal LogBuffer As String, ByVal EventType
As VBEventType)

Dim threadText As String

If (_logMode Or LogModeFlags.VbLogThreadID) = LogModeFlags.VbLogThreadID
Then
threadText = "Thread ID: " + ThreadID.ToString
End If

If (_logMode And LogModeFlags.VbLogToNT) = LogModeFlags.VbLogToNT
Then
Dim logEntryType As EventLogEntryType

Select Case EventType
Case VBEventType.vbLogEventTypeError
logEntryType = EventLogEntryType.Error
Case VBEventType.vbLogEventTypeInformation
logEntryType = EventLogEntryType.Information
Case VBEventType.vbLogEventTypeWarning
logEntryType = EventLogEntryType.Warning
End Select

_eventLog.WriteEntry("VBNET", _
"The VB.NET Application identified by the event source logged
this Application event" + _
vbCrLf + Title + threadText + " ,Logged: " + LogBuffer _
, logEntryType, 1)
Exit Sub
End If

If (_logMode And LogModeFlags.VbLogToFile) = LogModeFlags.VbLogToFile
Then
Dim fs As FileStream
Dim sw As StreamWriter
Dim eventTypeText As String

Try
If _ranFirstFileLog Then
fs = File.Open(_logPath, FileMode.Append)
Else
If (_logMode And LogModeFlags.VbLogOverwrite) = LogModeFlags.VbLogOverwrite
Then
If File.Exists(_logPath) Then
File.Delete(_logPath)
End If
fs = File.Open(_logPath, FileMode.CreateNew)
Else
fs = File.Open(_logPath, FileMode.OpenOrCreate Or
FileMode.Append)
End If
_ranFirstFileLog = True
End If
sw = New StreamWriter(fs)
Select Case EventType
Case VBEventType.vbLogEventTypeError
eventTypeText = "Error "
Case VBEventType.vbLogEventTypeInformation
eventTypeText = "Information "
Case VBEventType.vbLogEventTypeWarning
eventTypeText = "Warning "
End Select

sw.WriteLine(eventTypeText + "Application " + _logPath +
": " + threadText + " ,Logged: " + LogBuffer)
sw.Flush()
sw.Close()
Catch ex As Exception
_logMode = LogModeFlags.VbLogOff
Finally
If Not sw Is Nothing Then
sw.Close()
End If
End Try
End If
End Sub

<Obsolete("Use the EventLog classes for more flexibility.")> _
Friend Shared Sub StartLogging(ByVal LogTarget As String, ByVal LogModes
As LogModeFlags)
_logPath = LogTarget

Select Case LogModes
Case LogModeFlags.VbLogOff, LogModeFlags.VbLogToFile, LogModeFlags.vbLogToFileAndOverwrite,
LogModeFlags.vbLogToFileAndOverwriteWithThreadID
_logMode = LogModes
Case LogModeFlags.vbLogAuto, LogModeFlags.vbLogAutoWithThreadID
If IsNT4OrHigherOS() Then
_logMode = LogModeFlags.VbLogToNT
StartNTLog()
Else
_logMode = LogModeFlags.VbLogToFile
End If
If (LogModes And LogModeFlags.VbLogThreadID) = LogModeFlags.VbLogThreadID
Then
_logMode = (_logMode Or LogModeFlags.VbLogThreadID)
End If

Case LogModeFlags.VbLogToNT, LogModeFlags.vbLogToNTWithThreadID
If IsNT4OrHigherOS() Then
StartNTLog()
_logMode = LogModes
Else
_logMode = LogModeFlags.VbLogOff
End If

Case Else
_logMode = LogModeFlags.VbLogOff
End Select
End Sub

Private Shared Function IsNT4OrHigherOS() As Boolean
If Environment.OSVersion.Platform = PlatformID.Win32NT Then
Return True
End If
End Function

Private Shared Sub StartNTLog()
If Not _eventLog Is Nothing Then
_eventLog = New EventLog("Application", ".", EventLogSource)
End If
End Sub

Private Shared Sub InitAssemblyInfo()
Dim assemblyCompany As AssemblyCompanyAttribute()
assemblyCompany = DirectCast(GetExecutingAssembly.GetCustomAttributes(GetType(AssemblyCompanyAttribute),
True), AssemblyCompanyAttribute())
If Not ((assemblyCompany Is Nothing) OrElse (assemblyCompany.Length
= 0)) Then
_assemblyInfo.Company = assemblyCompany(0).Company
End If

Dim assemblyDesc As AssemblyDescriptionAttribute()
assemblyDesc = DirectCast(GetExecutingAssembly.GetCustomAttributes(GetType(AssemblyDescriptionAttribute),
True), AssemblyDescriptionAttribute())
If Not ((assemblyDesc Is Nothing) OrElse (assemblyDesc.Length = 0))
Then
_assemblyInfo.Description = assemblyDesc(0).Description
End If

Dim assemblyTitle As AssemblyTitleAttribute()
assemblyTitle = DirectCast(GetExecutingAssembly.GetCustomAttributes(GetType(AssemblyTitleAttribute),
True), AssemblyTitleAttribute())
If Not ((assemblyTitle Is Nothing) OrElse (assemblyTitle.Length =
0)) Then
_assemblyInfo.Title = assemblyTitle(0).Title()
End If

Dim assemblyProduct As AssemblyProductAttribute()
assemblyProduct = DirectCast(GetExecutingAssembly.GetCustomAttributes(GetType(AssemblyProductAttribute),
True), AssemblyProductAttribute())
If No220 41924 <3cf78b2a@10.1.10.29> article retrieved - head and body follows
Reply-To: "Tim Overbay" <luhar@neverendingsoftware.com>
From: "Tim Overbay" <luhar@neverendingsoftware.com>
Newsgroups: vb.dotnet.discussion
References: <3cf4fd4f@10.1.10.29> <3cf5149e@10.1.10.29> <3cf52743$1@10.1.10.29> <MPG.175f54b8367891a2989680@news.devx.com> <3cf6a9bf@10.1.10.29>
Subject: Re: Converting projects to VB.NET
Date: Fri, 31 May 2002 09:03:37 -0600
Lines: 43
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 12.5.152.60
Message-ID: <3cf78b2a@10.1.10.29>
X-Trace: 31 May 2002 07:39:38 -0800, 12.5.152.60
Path: 10.1.10.29
Xref: 10.1.10.29 vb.dotnet.discussion:41924

I just finished an app that uses both. The scientific data is stored on the
server in a SQL db and the project data is stored locally in an Access db.
They haven't reported any problems with either one. *knock wood* And, as far
as I could tell, the OleDBProvider wasn't any less capable.

SQL server is obviously better performance-wise, but Access is great for
small, local databases.

Tim

"John Butler" <nospamjrbutler@btinternet.com> wrote in message
news:3cf6a9bf@10.1.10.29...
>
> "turbofish" <junk@turbofish.com> wrote in message
> news:MPG.175f54b8367891a2989680@news.devx.com...
> > Well, most of what I do is either desktop accounting programs/office
> > automation with very little network use. Maybe a maximum of 5-7 clients

on
> one
> > database at a time. There are a LOT of programs and offices out there

just
> > like this. .NET focuses on the SQL server. In fact, every book I have on

> .NET
> > when it comes to covering database stuff, they won't even mention

anything
> > less than SQL 2000.
> > It's a real shame that Microsoft has forgotten that not everyone has a

> need
> > for large scale database apps.

>
> I haven't used it, but what is wrong with the OleDB driver in .NET? Far as
> I've seen, it works the same ways as the sql server.net data provider I
> use....Is it slower or less capable? I'm curious, as I haven't seen any
> issues reported...and I might need to use an Access database for a
> customer's website, for an upcoming project....
>
> Rgds
> John Butler
>
>
>