Imports System.Windows.Threading Imports Effector.Plugin.Lib Imports Effector.Plugin.Interface Public Class MainWindowVM Inherits VMBase Friend m_PluginTestInfo As Integer = 764 ' Riferimento al Model della MainWindow Private m_MainWindowM As MainWindowM Friend ReadOnly Property MainWindowM As MainWindowM Get Return m_MainWindowM End Get End Property ' Riferimento al gestore delle macchine a stati Private m_FiniteStateMachineManager As FiniteStateMachineManager Friend ReadOnly Property FiniteStateMachineManager As FiniteStateMachineManager Get Return m_FiniteStateMachineManager End Get End Property ' Riferimento al gestore del della comunicazione macchine Private m_MachineManager As MachineManager Friend ReadOnly Property MachineManager As MachineManager Get Return m_MachineManager End Get End Property ' Riferimento al gestore del server Redis Private m_RedisManager As RedisManager Friend ReadOnly Property RedisManager As RedisManager Get Return m_RedisManager End Get End Property Private m_ContentPanel As Panel Public ReadOnly Property ContentPanel As Panel Get Return m_ContentPanel End Get End Property Private m_ContentMenu As Panel Public ReadOnly Property ContentMenu As Panel Get Return m_ContentMenu End Get End Property Private m_SplashScreen_Timer As New DispatcherTimer Private m_WaitAfterRender As Integer = 0 Private m_Window_Opacity As Double = 0.2 Public ReadOnly Property Window_Opacity As Double Get Return m_Window_Opacity End Get End Property ' Titolo Public ReadOnly Property sTitle As String Get Return EgtMsg(1) End Get End Property Sub New() ' Avvio l'inizializzazione della mappa passandogli il riferimento al MainWindowVM Map.BeginInit(Me) ' imposto e avvio contatore SplashScreen m_SplashScreen_Timer.Interval = New TimeSpan(0, 0, 0, 0, 500) AddHandler m_SplashScreen_Timer.Tick, AddressOf SplashScreenTimer_Tick If Not IsNothing(Map.refSplashScreen) Then m_SplashScreen_Timer.Start() End If ' Creo Model della MainWindow m_MainWindowM = New MainWindowM ' creo gestore della comunicazione m_MachineManager = New MachineManager m_MachineManager.Init() ' recupero nome del plugin Dim sPluginName As String = "" If GetMainPrivateProfileString(S_GENERAL, K_PLUGINNAME, "", sPluginName) > 0 AndAlso Not String.IsNullOrWhiteSpace(sPluginName) Then ' aggiungo Dictionary del plugin Dim PluginDictionary As IPluginControl = GetDictionary(Of IPluginControl)(sPluginName) Application.Current.Resources.MergedDictionaries.Add(PluginDictionary) '' aggiungo MainMenu dal plugin Dim PluginMainMenu As IPluginControl = GetControlByName(Of IPluginControl)(sPluginName, "MainMenu") m_ContentMenu = PluginMainMenu '' aggiungo manager delle funzioni Lua del Plugin Dim PluginLuaManager As IPluginLuaManager = Map.refMainWindowVM.GetLuaManager(Of IPluginLuaManager)(sPluginName) PluginLuaManager.PlgInit(LuaManager.state) ' aggiungo Project dal plugin Dim ProjectPlugin As IPluginControl = GetControlByName(Of IPluginControl)(sPluginName, "Project") m_ContentPanel = ProjectPlugin End If ' creo variabile globale Effector per dati programma LuaManager.CreateGlobTable("EFFECTOR") LuaManager.SetGlobVar("EFFECTOR.INIPATH", Map.refMainWindowVM.MainWindowM.sConfigDir & "\" & INI_FILE_NAME) ' creo gestore delle macchine a stati m_FiniteStateMachineManager = New FiniteStateMachineManager If GetMainPrivateProfileInt(S_REDIS, K_ENABLED, 0) = 1 Then m_RedisManager = New RedisManager End If End Sub Friend Sub ContentRendered() ' segno su contatore splashscreen render finito m_WaitAfterRender = 1 End Sub Friend Function OnClose() As Boolean If Not IsNothing(FiniteStateMachineManager) Then FiniteStateMachineManager.ResetFiniteStateMachineTimer() LuaManager.Close() ' chiudo comunicazione macchine m_MachineManager.Close() ' Termino il Model m_MainWindowM.Close() Return True End Function Private Sub SplashScreenTimer_Tick() If m_WaitAfterRender > 1 Then m_Window_Opacity = 1 NotifyPropertyChanged(NameOf(Window_Opacity)) ' chiudo SplashScreen Map.refSplashScreen.Close() Map.SetRefSplashScreen(Nothing) m_SplashScreen_Timer.Stop() ElseIf m_WaitAfterRender > 0 Then m_WaitAfterRender += 1 End If End Sub #Region "Plugin" Private m_Loader As MEFLoader = New MEFLoader() Private Function GetPathByName(sPluginFileName As String) As String Return MainWindowM.sDataRoot & "\Plugin\" & sPluginFileName End Function Friend Function GetControlByName(Of T)(sPluginFileName As String, sPluginTagName As String) As Panel Dim PlugInControl As Object = m_Loader.LoadByTag(Of T)(GetPathByName(sPluginFileName), sPluginTagName).FirstOrDefault() Dim PluginPanel As Panel = Nothing If PlugInControl.GetType().BaseType.FullName = GetType(Panel).FullName OrElse PlugInControl.GetType().BaseType.FullName = GetType(Grid).FullName Then PluginPanel = TryCast(PlugInControl, Panel) End If Return PluginPanel End Function Friend Function GetDictionary(Of T)(sPluginFileName As String) As ResourceDictionary Dim DictionaryControl As Object = m_Loader.LoadByTag(Of T)(GetPathByName(sPluginFileName), "Dictionary").FirstOrDefault() Dim Dictionary As ResourceDictionary = Nothing Dictionary = TryCast(DictionaryControl, ResourceDictionary) Return DictionaryControl End Function Friend Function GetLuaManager(Of T)(sPluginFileName As String) As IPluginLuaManager Dim LuaManager As Object = m_Loader.LoadByTag(Of T)(GetPathByName(sPluginFileName), "LuaManager").FirstOrDefault() Return LuaManager End Function #End Region ' Plugin End Class