Imports MicroFour.StrataFrame.Application Imports MicroFour.StrataFrame.Data Imports MicroFour.StrataFrame.Security Imports MicroFour.StrataFrame.Security.BusinessObjects Imports System.Threading Public NotInheritable Class AppMain _ Public Shared Sub Main() '-- Enable the visual styles System.Windows.Forms.Application.EnableVisualStyles() '-- Add the handlers for the application events AddHandler StrataFrameApplication.ShowGateway, AddressOf ShowGateway AddHandler StrataFrameApplication.InitializingApplication, AddressOf InitApplication AddHandler StrataFrameApplication.SetDataSources, AddressOf SetDataSources AddHandler StrataFrameApplication.UnhandledExceptionFound, AddressOf UnhandledExceptionFound AddHandler StrataFrameApplication.ShowLoginAndInitializeForm, AddressOf ShowLoginAndInitMainForm '-- Run the application StrataFrameApplication.RunApplication() '-- Forcibly close the application to stop message pumps from looping and preventing the application ' from closing End End Sub ''' ''' Gets the connection string if the application will use a custom method to aquire the connection ''' string rather than the StrataFrame Connection String Manager (optional) ''' ''' Private Shared Sub SetDataSources() '-- Set the information specific to this application and the data sources ' The application key: ConnectionManager.ApplicationKey = "MyProject" ConnectionManager.ApplicationDefaultTitle = "Application Module Data Connections" ConnectionManager.ApplicationDefaultDescription = "Any database connections that are required by the Application" '-- Set the required data source information so that the ConnectionManager can gather it ' SQL Connection ConnectionManager.AddRequiredDataSourceItem("" _ , "SQL Connection" _ , DataSourceTypeOptions.SqlServer _ , "MyAppDb" _ , "The application data is stored here.") '-- Set Security connection data source information so the ConnectionManager can gather it ConnectionManager.AddRequiredDataSourceItem("security" _ , "SQL Connection" _ , DataSourceTypeOptions.SqlServer _ , "StrataFrame" _ , "This connection is used to provide security credentials for developement.") '-- Make the call to SetConnections which will gather the connection information, show the connection wizard ' if needed and set the DataSources collection on the DataLayer class. ConnectionManager.SetConnections() '-- ToDo: Set the data source key for the security tables SecurityBasics.SecurityDataSourceKey = "security" End Sub ''' ''' Shows the "Gateway" form (a custom form that gives the user a choice to launch different components ''' within the application) (optional) ''' ''' ''' Private Shared Sub ShowGateway(ByVal e As ShowGatewayEventArgs) '-- Inform the application to not show the "Gateway" form again after the main form has closed e.ShowGatewayAfterMainFormClose = False End Sub ''' ''' Shows a login form before a main form is shown and allows security to be checked before the application ''' launches the main form (optional) ''' ''' ''' Private Shared Sub ShowLoginAndInitMainForm(ByVal e As ShowLoginAndInitFormEventArgs) '-- Set the login form to your custom login form (optional) Login.LoginFormType = GetType(MyLoginForm) '-- Show the login form and authenticate the user e.ShowMainForm = Login.ShowLoginAndAuthUser(True) End Sub ''' ''' Provides a centralized location to add any initialization parameters that need to be set before ''' the application is loaded and defines the form types used as main forms by the application ''' ''' ''' Private Shared Sub InitApplication(ByVal e As InitializingApplicationEventArgs) '-- Add the main form type '-- If more than one form is added to the collection, they can be chosen by showing a "Gateway" form ' and supplying the index of the form to show (At least 1 form type must be added to the collection e.Forms.Add(GetType(MyProject.MainForm)) '-- Open the splash form. We need to close it at the end of this procedure Dim splashForm As New AppSplashScreen splashForm.Show() Application.DoEvents() '-- ToDo: Add any extra application initialization MicroFour.StrataFrame.UI.Localization.MessageKeyType = MicroFour.StrataFrame.Messaging.MessageKeyDataType.XML MicroFour.StrataFrame.UI.Localization.MessageLocaleID = MicroFour.StrataFrame.UI.Localization.GetActiveLanguage("MyProject") '-- ToDo: Configure the security settings '-------------------------------------------- '-- Retrieve the global preferences SFSPreferencesBO.RetrieveSecurityPreferences() '-- Set the encryption key and vector for the user data SecurityBasics.SetSecurityKeyAndVectorForUserAuthentication("MySecurityKey") '-- Start the session locking monitor & set the quick key to lock the application SessionLock.StartSessionMonitoring() SessionLock.SessionLockKey = Keys.F11 '-- Set the administrative and security maintenance usernames and passwords SecurityBasics.AdministratorUserName = "admin" SecurityBasics.AdministratorPassword = "admin" '& DateTime.Now.Day.ToString() '-- set the admin password so that it changes from day to day SecurityBasics.AdministratorUserPk = -1 SecurityBasics.SecurityMaintenanceUserName = "SecurityUser" SecurityBasics.SecurityMaintenancePassword = "mySecurityUserPass1" SecurityBasics.SecurityMaintenanceUserPk = -2 '-- Set the default actions for security enabled objects within the application SecurityBasics.DefaultPermissionInfo = New PermissionInfo(PermissionAction.Deny _ , "Access Denied." _ , DeniedActions.Message) SecurityBasics.DefaultPermissionAction = PermissionAction.Deny SecurityBasics.DefaultBlockedMsg = "Access Denied." 'SecurityBasics.DefaultBlockedMsgKey = "AccessDeniedKey" SecurityBasics.BlockedReplacementCharacter = "*"c SecurityBasics.BlockedReplacementRegex = "[A-Za-z0-9@]" '-- Determine whether to allow Windows authentication SecurityBasics.AllowWindowsAuth = False ' Close the splash form, but indirectly. We need to wait for ' the splash form to close to continue splashForm.SetStartupCodeComplete() While splashForm IsNot Nothing AndAlso splashForm.Visible = True Application.DoEvents() End While splashForm.Close() splashForm.Dispose() End Sub ''' ''' Catches any unhandled exception within the application and provides a place to log the information. ''' ''' ''' ''' This can do a few things. ''' - Provide a user friendly message to the use. ''' - Send email to support team. ''' - Create a log file ''' Which of these occurs, depends on how the error handler is configured. ''' Private Shared Sub UnhandledExceptionFound(ByVal e As UnhandledExceptionFoundEventArgs) '-- ToDo: add any error logging required. To prevent the StrataFrame ApplicationErrorForm from showing, ' set: ' e.Handled = true End Sub End Class