⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notificationservice.vb

📁 一個強大的定時服務程序
💻 VB
字号:
Option Explicit On 
Option Strict On

Imports System.ServiceProcess
Imports System.Xml
Imports System.Text
Imports System.IO
Imports System.Diagnostics
Imports System.Threading
Imports System.Data
Imports System.Net.Mail
Imports Microsoft.VisualBasic.ControlChars
Imports XMLDBLib

Public Class NotificationService
    Inherits System.ServiceProcess.ServiceBase
    Private mWorker As Thread = Nothing
    Private mdocXmlFile As XmlDocument = New XmlDocument()
    
#Region " Component Designer generated code "

    Public Sub New()
        MyBase.New()

        ' This call is required by the Component Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call

    End Sub

    'UserService overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' The main entry point for the process
    <MTAThread()> _
    Shared Sub Main()
        Dim ServicesToRun() As System.ServiceProcess.ServiceBase

        ' More than one NT Service may run within the same process. To add
        ' another service to this process, change the following line to
        ' create a second service object. For example,
        '
        '
        ServicesToRun = New System.ServiceProcess.ServiceBase() {New NotificationService()}

        System.ServiceProcess.ServiceBase.Run(ServicesToRun)
    End Sub

    'Required by the Component Designer
    Private components As System.ComponentModel.IContainer

    ' NOTE: The following procedure is required by the Component Designer
    ' It can be modified using the Component Designer.  
    ' Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
        Me.ServiceName = "NotificationService"
    End Sub

#End Region

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' The XML configuration file is in the Xml subfoler of the current folder
        Dim sXmlFile As String = AppDomain.CurrentDomain.BaseDirectory + "Xml\Notification.xml"
        LogInfo("Coinfiguration File = " + sXmlFile)
        Try
            ' Load the XML configuration file
            mdocXmlFile.Load(sXmlFile)
            ' Start the worker thread
            Dim start As ThreadStart = New ThreadStart(AddressOf Working)
            mWorker = New Thread(start)
            mWorker.Start()
        Catch obug As Exception
            LogEvent(obug.Message)
            Throw obug
        End Try
    End Sub

    Protected Overrides Sub OnStop()
        Try
            ' Kill the worker thread
            If Not (mWorker Is Nothing) And mWorker.IsAlive Then
                mWorker.Abort()
            End If
        Catch obug As Exception
            LogEvent(obug.Message)
        End Try
    End Sub

    Private Sub Working()
        ' Local variables
        Dim sConnection As String = String.Empty
        Dim nSleep As Integer = 15
        Dim nPause As Integer = 1000
        Dim sGetListProc As String = String.Empty
        Dim sIDField1 As String = String.Empty
        Dim sIDField2 As String = String.Empty
        Dim sIDField3 As String = String.Empty
        Dim sIDField4 As String = String.Empty
        Dim sIDField5 As String = String.Empty
        Dim sIDField6 As String = String.Empty
        Dim sIDField7 As String = String.Empty
        Dim sIDField8 As String = String.Empty
        Dim sIDField9 As String = String.Empty
        Dim sIDField10 As String = String.Empty
        Dim sIDField11 As String = String.Empty

        Dim sProcessItemProc As String = String.Empty
        Dim sParameterName As String = String.Empty
        Dim oNode As XmlNode = Nothing
        Dim sFrom As String = String.Empty
        Dim sTo As String = String.Empty
        Dim sCc As String = String.Empty
        Dim sBcc As String = String.Empty
        Dim sSubject As String = String.Empty
        Dim sPort As String = String.Empty
        Dim sSmtpServer As String = String.Empty
        Dim sBody As String = String.Empty
        ' Initialize variables from the XML configuration file
        oNode = mdocXmlFile.SelectSingleNode("//dbconnection")
        If Not oNode Is Nothing Then
            sConnection = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//sleep")
        If Not oNode Is Nothing Then
            nSleep = CInt(oNode.InnerText)
        End If
        oNode = mdocXmlFile.SelectSingleNode("//pause")
        If Not oNode Is Nothing Then
            nPause = CInt(oNode.InnerText)
        End If
        oNode = mdocXmlFile.SelectSingleNode("//getlistproc")
        If Not oNode Is Nothing Then
            sGetListProc = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//idfield1")
        If Not oNode Is Nothing Then
            sIDField1 = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//idfield2")
        If Not oNode Is Nothing Then
            sIDField2 = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//idfield3")
        If Not oNode Is Nothing Then
            sIDField3 = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//idfield4")
        If Not oNode Is Nothing Then
            sIDField4 = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//idfield5")
        If Not oNode Is Nothing Then
            sIDField5 = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//idfield6")
        If Not oNode Is Nothing Then
            sIDField6 = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//idfield7")
        If Not oNode Is Nothing Then
            sIDField7 = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//idfield8")
        If Not oNode Is Nothing Then
            sIDField8 = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//idfield9")
        If Not oNode Is Nothing Then
            sIDField9 = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//idfield10")
        If Not oNode Is Nothing Then
            sIDField10 = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//idfield11")
        If Not oNode Is Nothing Then
            sIDField11 = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//processitemproc")
        If Not oNode Is Nothing Then
            sProcessItemProc = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//parametername")
        If Not oNode Is Nothing Then
            sParameterName = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//email/from")
        If Not oNode Is Nothing Then
            sFrom = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//email/to")
        If Not oNode Is Nothing Then
            sTo = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//email/cc")
        If Not oNode Is Nothing Then
            sCc = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//email/bcc")
        If Not oNode Is Nothing Then
            sBcc = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//email/subject")
        If Not oNode Is Nothing Then
            sSubject = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//email/body")
        If Not oNode Is Nothing Then
            sBody = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//email/port")
        If Not oNode Is Nothing Then
            sPort = oNode.InnerText
        End If
        oNode = mdocXmlFile.SelectSingleNode("//email/smtpserver")
        If Not oNode Is Nothing Then
            sSmtpServer = oNode.InnerText
        End If
        ' Enter the infinite loop
        sBody = "<html><head><style type='text/css'><!--.style1 {font-size: 14px} td { background-color: #FFFFFF;} table { font-family: Arial, Helvetica, sans-serif; color: #2461BF; align:left; text-decoration: none; background-color: #D1DDF1;} body { font-size:16pt;color: #2461BF;} --></style>" + _
        "</head><body>" + sBody + "<br /><hr /><table width='450' border='0'  cellpadding='8' cellspacing='1' class='style1' ><tr><td><strong>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -