In Jiwa 7 we wrapped that functionality into plugins. If you create a new plugin in Version 7, you'll see right at the bottom of the code a "ScheduledExecutionPlugin" class which looks like this :
- Code: Select all
Public Class ScheduledExecutionPlugin
Inherits System.MarshalByRefObject
Implements JiwaApplication.IJiwaScheduledExecutionPlugin
Public Sub Execute(ByVal Plugin As JiwaApplication.Plugin.Plugin, ByVal Schedule As JiwaApplication.Schedule.Schedule) Implements JiwaApplication.IJiwaScheduledExecutionPlugin.Execute
End Sub
Public Sub OnServiceStart(ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaScheduledExecutionPlugin.OnServiceStart
End Sub
Public Sub OnServiceStopping(ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaScheduledExecutionPlugin.OnServiceStopping
End Sub
End Class
This class is where you put your code you want to be executed on a scheduled basis.
For example, lets create a new plugin which will log to the application log some information and send an email once every minute.
1. Create a new plugin from the Plugin Maintenance Form.
2. Name the plugin "Schedule Test"
3. Make the "ScheduledExecutionPlugin" look like this :
- Code: Select all
Public Class ScheduledExecutionPlugin
Inherits System.MarshalByRefObject
Implements JiwaApplication.IJiwaScheduledExecutionPlugin
Public Sub Execute(ByVal Plugin As JiwaApplication.Plugin.Plugin, ByVal Schedule As JiwaApplication.Schedule.Schedule) Implements JiwaApplication.IJiwaScheduledExecutionPlugin.Execute
Dim Log As New System.Diagnostics.EventLog("Application")
Log.Source = String.Format("Jiwa Plugin : {0}", plugin.Name )
Log.WriteEntry(String.Format("Execute Called from Schedule {0}", schedule.Name))
Log.Close()
Dim email As JiwaApplication.JiwaEmail.EmailMessage = JiwaApplication.BusinessLogicFactory.Instance.CreateBusinessLogic(Of JiwaApplication.JiwaEmail.EmailMessage)
email.SystemSettings.UseOutlookForEmail = False ' Cannot use outlook from within a Windows Service
email.CreateNew()
email.EmailTo = "[email protected]"
email.EmailSubject = "test email"
email.EmailBody = "This is the body"
email.Save()
End Sub
Public Sub OnServiceStart(ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaScheduledExecutionPlugin.OnServiceStart
End Sub
Public Sub OnServiceStopping(ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaScheduledExecutionPlugin.OnServiceStopping
End Sub
End Class
Obviously you want to make that email recipient your own address. NOTE: Emailing using Outlook from a service is not supported by Microsoft - either make sure your system settings to send emails are not using outlook, or just remove the emailing code for this example.
3. Tick the "Enabled" box on the plugin
4. Click on the "Schedule" Tab of the plugin
5. Add a new schedule by typing in a name - use "Every Minute"
6. Double right-click on the Description to open the schedule editor dialog - set the appropriate settings to schedule for daily and every minute, with no end date - ie: like this :
7. Save the schedule dialog
8. Save the plugin
9. Now we need to start the service. The service will login to Jiwa at a specified poll interval (default is once every 60,000ms - 1 minute), see which plugins have schedule(s) due to run and run them, update their next run date time, and then log off. Note the poll interval in this configuration is not related to the schedule we defined for the plugin.
Locate the JiwaPluginSchedulerService.exe.config (it will be in the same folder as your Jiwa.exe), and open it with notepad or notepad++
The default configuration looks like this :
- Code: Select all
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="ServiceSettings" type="JiwaFinancials.Jiwa.JiwaPluginSchedulerService.Configuration.ConfigurationHandler,JiwaPluginSchedulerService"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
</startup>
<ServiceSettings>
<DatabaseName>JiwaDemo</DatabaseName>
<ServerName>JiwaServer</ServerName>
<JiwaUsername>Admin</JiwaUsername>
<JiwaPassword>password</JiwaPassword>
<PollInterval>60000</PollInterval>
</ServiceSettings>
</configuration>
Just set the DatabaseName, ServerName, JiwaUserName, JiwaPassword and save.
10. Open services.msc and find the Jiwa 7 Plugin Scheduler Service in the list and right click on it to start it.
You should see in the application eventlog (eventvwr.exe) and your email inbox a new message once a minute.
If you're wondering which email address is being used to send - it's the current user in the context of the plugin. The plugin is run by the Plugin Scheduler Service, and the Jiwa user it uses there is the one configured in the JiwaPluginSchedulerService.exe.config file. When it logs in the Email settings are read from the Staff Maintenance for that user - that coupled with the system settings (ie: SMTPRequiresSSL, SMTPServerAddress, SMTPServerPortNumber) is all it needs to send the email. Note in this example we override the Email Business Logic objects system setting "UseOutlookForEmail" because services are not allowed to send using Outlook - so even if your configuration is configured to UseOutlookForEmail as true, this plugin overlooks that and uses whatever you have in your SMTPServerAddress, SMTPServerPortNumber and SMTPRequiresSSL anyway to send the email as it knows if you have UseOutlookForEmail it's not going to work anway.
This was a trivial example, but it should be apparent how easily and quickly you can schedule complex (or simple) tasks - anything you can do in the Jiwa application can be performed in a schedule - report printing, emailing, importing, exporting, processing - it's all possible.