#region Copyright (C) 2007-2012 Team MediaPortal

/*
    Copyright (C) 2007-2011 Team MediaPortal
    http://www.team-mediaportal.com

    This file is part of MediaPortal 2

    MediaPortal 2 is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MediaPortal 2 is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with MediaPortal 2.  If not, see <http://www.gnu.org/licenses/>.
*/

#endregion


using System;
using System.Drawing;
using System.Collections.Generic;

using MediaPortal.Common;
using MediaPortal.Common.Commands;
using MediaPortal.Common.General;
using MediaPortal.Common.Logging;
using MediaPortal.Common.Messaging;
using MediaPortal.Common.Settings;
using MediaPortal.Common.Localization;
using MediaPortal.UI.Presentation.Models;
using MediaPortal.UI.Presentation.DataObjects;
using MediaPortal.UI.Presentation.Workflow;
using MediaPortal.UI.Presentation.Screens;

using MediaPortal.UI.SkinEngine.ScreenManagement;
using MediaPortal.UI.SkinEngine.Controls.Visuals;

using MediaPortal.Plugins.SlimTvClient.Interfaces;
using MediaPortal.Plugins.SlimTvClient;



using  MediaPortal.Plugins.MyTestPlugin.Settings; //needed for configuration setting loading

namespace MyTestPlugin.Models
{
  /// <summary>
  /// Example for a simple model.
  /// The screenfile to this model is located at:
  /// /Skins/default/screens/hello_world.xaml
  /// </summary>
  /// <remarks>
  /// <para>
  /// Models are used for providing data from the system to the skin and for executing actions (commands)
  /// which are triggered by the Skin, for example by clicking a button.
  /// </para>
  /// <para>
  /// All public properties can be data-bound by the skin, for example the <see cref="HelloString"/> property.
  /// Note that properties, which are updated by the model and whose new value should be propagated to the
  /// skin, must be backed by an instance of <see cref="AbstractProperty"/>. That instance must be made available
  /// to the skin engine by publishing it under the same name as the actual property plus "Property", see for example
  /// <see cref="HelloStringProperty"/>. In models, always <see cref="WProperty"/> instances are used.
  /// </para>
  /// <para>
  /// You can also consider to implement the interface <see cref="IWorkflowModel"/>, which makes it
  /// possible to attend the screenflow = workflow of the user session. When that interface is implemented and this
  /// model is registered in a workflow state as backing workflow model, the model will get notifications when the
  /// GUI navigation switches to or away from its workflow state.
  /// </para>
  /// <para>
  /// To make an UI model known by the system (and thus loadable by the skin), it is necessary to register it
  /// in the <c>plugin.xml</c> file.
  /// </para>
  /// </remarks>
  /// 
    


    public class MyTestPlugin : IWorkflowModel, IDisposable
    {


        


        #region Constants

        //must be model ID defined in workflow and plugin.xml
        public const string MYTESTPLUGIN_MODEL_ID_STR = "023c44f2-3329-4781-9b4a-c974444c0b0d";
        public readonly static Guid MYTESTPLUGIN_MODEL_ID = new Guid(MYTESTPLUGIN_MODEL_ID_STR);


        /// <summary>
        /// This is a localized string resource. Localized string resources always look like this:
        /// <example>
        /// [Section.Name]
        /// </example>
        /// Localized resources must be present at least in the english language, as this is the default.
        /// In the english language file of this hello world plugin, you'll find the translation of this string.
        /// The language file is located at: /Language/strings_en.xml
        /// </summary>
        

        protected const string TOGGLE_BUTTON_1_RESOURCE = "[MyTestPlugin.ToggleButton1]";
        protected const string TOGGLE_BUTTON_2_RESOURCE = "[MyTestPlugin.ToggleButton2]";

        protected const string FUNCTION_BUTTON_RESOURCE = "[MyTestPlugin.FunctionButton]";
        protected const string CONFIG_MYSETTING_STRING_RESOURCE = "[MyTestPlugin.ConfigMySettingString]";
        protected const string MESSAGE_RECEIVED_RESOURCE = "[MyTestPlugin.MessageReceived]";

        protected const string CONFIG_MYSETTING_KEY_RESOURCE = "[MyTestPlugin.ConfigMySettingKey]";

        protected const string MENU_ITEM_1_RESOURCE = "[SimpleDialogMenu.MenuItem1]";
        protected const string MENU_ITEM_2_RESOURCE = "[SimpleDialogMenu.MenuItem2]";
        protected const string MENU_ITEM_3_RESOURCE = "[SimpleDialogMenu.MenuItem3]";
        protected const string MENU_ITEM_4_RESOURCE = "[SimpleDialogMenu.MenuItem4]";

        protected const string LABEL_TEXT_RESOURCE = "[SimpleDialogMenu.LabelText]";

        protected const string SIMPLE_DIALOG_MENU_SCREEN = "SimpleDialogMenu";
        #endregion

        #region Global Variables

        //for labels
        bool ButtonWasPressed = false;
        //int Counter = 0;

        //Logger
        ILogger mylogger = ServiceRegistration.Get<ILogger>();


        //Messaging
        protected AsynchronousMessageQueue _messageQueue;
        protected object _syncObj = new object();
        //create a single instance to enable transfer from static to non static function
        private static MyTestPlugin _instance = new MyTestPlugin();
        // do not forget _instance = this; in the constructor

        protected ITvHandler _tvHandler;

        #endregion Global Variables
         

        #region Properties for skins

        /// <summary>
        /// This property holds a string that we will modify in this tutorial.
        /// </summary>
        protected readonly AbstractProperty _helloStringProperty;
        protected readonly AbstractProperty _functionButtonLabelProperty;
        protected readonly AbstractProperty _config_MySetting_StringProperty;
        protected readonly AbstractProperty _message_receivedProperty;
        protected readonly AbstractProperty _config_MySetting_KeyProperty;
        /// <summary>
        /// This sample property will be accessed by the hello_world screen. Note that the data type must be the same
        /// as given in the instantiation of our backing property <see cref="_helloStringProperty"/>.
        /// </summary>
        public string HelloString
        {
            get { return (string)_helloStringProperty.GetValue(); }
            set { _helloStringProperty.SetValue(value); }
        }

        public string FunctionButtonLabel
        {
            get { return (string)_functionButtonLabelProperty.GetValue(); }
            set { _functionButtonLabelProperty.SetValue(value); }
        }

        public string Config_MySetting_String
        {
            get { return (string)_config_MySetting_StringProperty.GetValue(); }
            set { _config_MySetting_StringProperty.SetValue(value); }
        }

        public string Message_Received
        {
            get { return (string)_message_receivedProperty.GetValue(); }
            set { _message_receivedProperty.SetValue(value); }
        }

        public string Config_MySetting_Key
        {
            get { return (string)_config_MySetting_KeyProperty.GetValue(); }
            set { _config_MySetting_KeyProperty.SetValue(value); }
        }

        /// <summary>
        /// This is the dependency property for our sample string. It is needed to propagate changes to the skin.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If the screen databinds to the <see cref="HelloString"/> property in a binding mode which will propagate data
        /// changes from the model to the skin (OneWay, TwoWay), the SkinEngine will attach a change handler to this property
        /// and react to changes.
        /// </para>
        /// <para>
        /// In other words: For each property <c>Xyz</c>, which should be able to be attached to, there must be an
        /// <see cref="AbstractProperty"/> with name <c>XyzProperty</c>.
        /// Only if <c>XyzProperty</c> is present in the model, value changes can be propagated to the skin.
        /// </para> 
        /// </remarks>
        public AbstractProperty HelloStringProperty
        {
            get { return _helloStringProperty; }
        }

        public AbstractProperty FunctionButtonLabelProperty
        {
            get { return _functionButtonLabelProperty; }
        }

        public AbstractProperty Config_MySetting_StringProperty
        {
            get { return _config_MySetting_StringProperty; }
        }

        public AbstractProperty Message_ReceivedProperty
        {
            get { return _message_receivedProperty; }
        }

        public AbstractProperty Config_MySetting_KeyProperty
        {
            get { return _config_MySetting_KeyProperty; }
        }

        //do not forget Wproperties in constructor!
        #endregion Properties for skins





        #region constructor
        /// <summary>
        /// Constructor... this one is called by the WorkflowManager when this model is loaded due to a screen reference.
        /// </summary>
        public MyTestPlugin()  //will be called when the screen is the first time loaded not the same as Init() !!!
        {

            mylogger.Debug("MyTestPlugin:MyTestPlugin(): Constructor called");

            _instance = this; //needed to ensure transfer from static function later on

            // In models, properties will always be WProperty instances. When using SProperties for screen databinding,
            // the system might run into memory leaks.
            _helloStringProperty = new WProperty(typeof(string), TOGGLE_BUTTON_1_RESOURCE);
            _functionButtonLabelProperty = new WProperty(typeof(string), FUNCTION_BUTTON_RESOURCE);
            _config_MySetting_StringProperty = new WProperty(typeof(string), CONFIG_MYSETTING_STRING_RESOURCE);
            _message_receivedProperty = new WProperty(typeof(string), MESSAGE_RECEIVED_RESOURCE);
            _config_MySetting_KeyProperty = new WProperty(typeof(string), CONFIG_MYSETTING_KEY_RESOURCE);
           

            //messaging start  messages before the plugin screen is loaded will be ignored - do not know how to start earlier
            _messageQueue = new AsynchronousMessageQueue(this, new string[]
          {
            MyTestPluginMessaging.CHANNEL,
          });
            _messageQueue.MessageReceived += OnMessageReceived;
            _messageQueue.Start();


            //get data from tvserver
            if (_tvHandler == null)
            {
                _tvHandler = ServiceRegistration.Get<ITvHandler>();
                _tvHandler.Initialize();
            }

            
        }

        private void MessageFunction(string text)
        {
            Message_Received = text;
        }
            

        private static void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message)
        {
            if (message.ChannelName == MyTestPluginMessaging.CHANNEL)
            {
                if (((MyTestPluginMessaging.MessageType)message.MessageType) == MyTestPluginMessaging.MessageType.ConfigurationChanged)
                {
                    ServiceRegistration.Get<ILogger>().Debug("MyTestPlugin:OnMessageReceived()  MyTestPluginMessaging.MessageType ConfigurationChanged received at " + DateTime.Now.ToString());
                    string formatted_string = LocalizationHelper.Translate(MESSAGE_RECEIVED_RESOURCE, DateTime.Now.ToString());
                    ServiceRegistration.Get<ILogger>().Debug("MyTestPlugin:OnMessageReceived()  formatted_string =" + formatted_string);

                    //Message_Received = this.formatted_string;  not working cannot go from static to non static
                    
                    //what worked was to define a static instance:  private static MyTestPlugin _instance = new MyTestPlugin(); and 
                    // _instance = this;  in the constructor
                    _instance.MessageFunction(formatted_string);
                    
                }
            }
        }
        #endregion constructor



        #region public methods

        protected AbstractProperty _screenProperty;

        public AbstractProperty ScreenProperty
        {
            get { return _screenProperty; }
        }

        public Screen Screen
        {
            get { return (Screen)_screenProperty.GetValue(); }
            set { _screenProperty.SetValue(value); }
        }

        /// <summary>
        /// Gets this element's bounds in this element's coordinate system.
        /// This is a derived property which is calculated by the layout system.
        /// </summary>
        protected RectangleF _innerRect;

        public RectangleF ActualBounds
        {
            get { return _innerRect; }
        }


        /// <summary>
        /// Method which will be called from our screen. We will change the value of our HelloWorld string here.
        /// </summary>
        public void ChangeHelloWorldString()
        {
            
            // Localized resources in the form [Section.Name] can be used in each Label in screens. Labels automatically
            // request the localized string from the system if a text of that form is written into their Content property.
            ButtonWasPressed = !ButtonWasPressed;

            mylogger.Debug("MyTestPlugin:ChangeHelloWorldString(): ButtonWasPressed =" + ButtonWasPressed.ToString());  //example for logging to log file

            if (ButtonWasPressed)
                HelloString = TOGGLE_BUTTON_2_RESOURCE;
            else
                HelloString = TOGGLE_BUTTON_1_RESOURCE;

            mylogger.Debug("MyTestPlugin:ChangeHelloWorldString(): HelloString changed to: " + HelloString);  //example for logging to log file

            DebugPreviousState();
            


            /*
            //virtuel keyboard
            Screen screen = Screen;
            if (screen != null)
                screen.ShowVirtualKeyboard(HelloStringProperty, new VirtualKeyboardSettings
                {
                    ElementArrangeBounds = ActualBounds,
                    TextStyle = VirtualKeyboardTextStyle.None
                });*/

        }

        

        public void PushButtonFunction()
        {
            mylogger.Debug("MyTestPlugin:PushButtonFunction()");
            IWorkflowManager workflowManager = ServiceRegistration.Get<IWorkflowManager>();


            //now push to home screen via button - just an exercise
            string name = "Push to Hello World Screen";
            string displayname = "To hello world";
            string mainscreen = "hello_world";
            Guid HomeModelId = new Guid("D5CD9D35-1B36-4ede-8BED-A4FB658F27BD"); //id of Hallo World

            //generate transient workflowstate and execute
            workflowManager.NavigatePushTransient(new WorkflowState(Guid.NewGuid(), name, displayname, true, mainscreen, false, true, HomeModelId, WorkflowType.Workflow), null);
        }


        public void PopButtonFunction()
        {
            mylogger.Debug("MyTestPlugin:PopButtonFunction()");
            IWorkflowManager workflowManager = ServiceRegistration.Get<IWorkflowManager>();
            workflowManager.NavigatePop(1); //same as escape (takes one entry from the stack)
        }


        public void DebugPreviousState()
        {
            try
            {
                IWorkflowManager workflowManager = ServiceRegistration.Get<IWorkflowManager>();

                NavigationContext currentNavigationContext = workflowManager.CurrentNavigationContext.Predecessor;

                mylogger.Debug("MyTestPlugin:DebugCurrentState():PredecessorNavigationContext.WorkflowState.Name =" + currentNavigationContext.WorkflowState.Name);
                mylogger.Debug("MyTestPlugin:DebugCurrentState():PredecessorNavigationContext.WorkflowState.DisplayLabel =" + currentNavigationContext.WorkflowState.DisplayLabel);
                mylogger.Debug("MyTestPlugin:DebugCurrentState():PredecessorNavigationContext.WorkflowState.StateId =" + currentNavigationContext.WorkflowState.StateId.ToString());
                mylogger.Debug("MyTestPlugin:DebugCurrentState():PredecessorNavigationContext.WorkflowState.WorkflowModelId =" + currentNavigationContext.WorkflowState.WorkflowModelId.ToString());
                mylogger.Debug("MyTestPlugin:DebugCurrentState():PredecessorNavigationContext.WorkflowState.WorkflowType =" + currentNavigationContext.WorkflowState.WorkflowType.ToString());
            }
            catch (Exception exc)
            {
                mylogger.Error("MyTestPlugin:DebugCurrentState():Error: exception=" + exc.Message);
            }



        }

        //will be called from skin with the button "Subroutine Function"
        public void MyFunctionButton()
        {
            //this will call now a simple menu dialog as defined in SimpleDialogMenu.xaml and trigger a command


            /*
            Counter++;
            mylogger.Debug("MyTestPlugin:ChangeHelloWorldString(): counter =" + Counter.ToString());  //example for logging to log file
            string buttonlabel = LocalizationHelper.Translate(FUNCTION_BUTTON_RESOURCE, Counter);
            mylogger.Debug("MyTestPlugin:ChangeHelloWorldString(): buttonlabel =" + buttonlabel);  //example for logging to log file
            FunctionButtonLabel = buttonlabel;*/

            //define menu items for simple dialog menu screen and the executing command if selected
            ItemsList menuItems = new ItemsList();

            ListItem myitem = new ListItem();

            myitem.SetLabel("Item", LocalizationHelper.Translate(MENU_ITEM_1_RESOURCE));
            myitem.Command = new MethodDelegateCommand(() => MenuItemSelected(1));
            menuItems.Add(myitem);

            myitem.SetLabel("Item", LocalizationHelper.Translate(MENU_ITEM_2_RESOURCE));
            myitem.Command = new MethodDelegateCommand(() => MenuItemSelected(2));
            menuItems.Add(myitem);

            myitem.SetLabel("Item", LocalizationHelper.Translate(MENU_ITEM_3_RESOURCE));
            myitem.Command = new MethodDelegateCommand(() => MenuItemSelected(3));
            menuItems.Add(myitem);

            myitem.SetLabel("Item", LocalizationHelper.Translate(MENU_ITEM_4_RESOURCE));
            myitem.Command = new MethodDelegateCommand(() => MenuItemSelected(4));
            menuItems.Add(myitem);

            //button will now call a dialogbox with a given menu
            IScreenManager screenManager = ServiceRegistration.Get<IScreenManager>();
            screenManager.ShowDialog(SIMPLE_DIALOG_MENU_SCREEN);

        }

        //command stencil for all items in the simpledialogmenu
        public void ExecProgramAction(ListItem item)
        {
            if (item == null)
                return;
            if (item.Command != null)
                item.Command.Execute();
        }

        //executed function for a selected menuitem in the dialog menu
        public void MenuItemSelected(int i)
        {
            string buttonlabel = LocalizationHelper.Translate(LABEL_TEXT_RESOURCE, i);
        }


        public void MyConfigLoadSettingExample()
        {

            MyTestPluginSettings settings = ServiceRegistration.Get<ISettingsManager>().Load<MyTestPluginSettings>();
            string formatted_string = LocalizationHelper.Translate(CONFIG_MYSETTING_STRING_RESOURCE, settings.MySetting_String);
            Config_MySetting_String = formatted_string;


            Config_MySetting_Key = LocalizationHelper.Translate(CONFIG_MYSETTING_KEY_RESOURCE);//assigns the key for the button press me from the config
            //protected static void RegisterGlobalKeyBindings()  for an example of how to register a key

        }

        #endregion public methods


        #region IWorkflowModel implementation
        // to use this you must have derived the class from IWorkflowModel, IDisposable
        // and you must have defined in plugin.xml a workflowstate
        // WorkflowModel="023c44f2-3329-4781-9b4a-c974444c0b0d"/> <!-- MyTestPlugin Model -->

        public Guid ModelId
        {
            get { return MYTESTPLUGIN_MODEL_ID; }
        }

        public bool CanEnterState(NavigationContext oldContext, NavigationContext newContext)
        {
            mylogger.Debug("MyTestPlugin:CanEnterState: oldContext.WorkflowModelId =" + oldContext.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:CanEnterState: oldContext.WorkflowState =" + oldContext.WorkflowState);
            mylogger.Debug("MyTestPlugin:CanEnterState: newContext.WorkflowModelId =" + newContext.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:CanEnterState: newContext.WorkflowState =" + newContext.WorkflowState);
            mylogger.Debug("");
            return true;
        }

        public void EnterModelContext(NavigationContext oldContext, NavigationContext newContext)
        {
            mylogger.Debug("MyTestPlugin:EnterModelContext: oldContext.WorkflowModelId =" + oldContext.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:EnterModelContext: oldContext.WorkflowState =" + oldContext.WorkflowState);
            mylogger.Debug("MyTestPlugin:EnterModelContext: newContext.WorkflowModelId =" + newContext.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:EnterModelContext: newContext.WorkflowState =" + newContext.WorkflowState);
            mylogger.Debug("");
            OnPageLoad(oldContext);
        }

        public void ExitModelContext(NavigationContext oldContext, NavigationContext newContext)
        {
            mylogger.Debug("MyTestPlugin:ExitModelContext: oldContext.WorkflowModelId =" + oldContext.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:ExitModelContext: oldContext.WorkflowState =" + oldContext.WorkflowState);
            mylogger.Debug("MyTestPlugin:ExitModelContext: newContext.WorkflowModelId =" + newContext.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:ExitModelContext: newContext.WorkflowState =" + newContext.WorkflowState);
            mylogger.Debug("");
            OnPageDestroy(newContext);
        }

        public void ChangeModelContext(NavigationContext oldContext, NavigationContext newContext, bool push)
        {

            mylogger.Debug("MyTestPlugin:ChangeModelContext: oldContext.WorkflowModelId =" + oldContext.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:ChangeModelContext: oldContext.WorkflowState =" + oldContext.WorkflowState);
            mylogger.Debug("MyTestPlugin:ChangeModelContext: newContext.WorkflowModelId =" + newContext.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:ChangeModelContext: newContext.WorkflowState =" + newContext.WorkflowState);
            mylogger.Debug("");
        }

        public void Deactivate(NavigationContext oldContext, NavigationContext newContext)
        {

            mylogger.Debug("MyTestPlugin:Deactivate: oldContext.WorkflowModelId =" + oldContext.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:Deactivate: oldContext.WorkflowState =" + oldContext.WorkflowState);
            mylogger.Debug("MyTestPlugin:Deactivate: newContext.WorkflowModelId =" + newContext.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:Deactivate: newContext.WorkflowState =" + newContext.WorkflowState);
            mylogger.Debug("");
            OnPageDestroy(newContext);
        }

        public void Reactivate(NavigationContext oldContext, NavigationContext newContext)
        {

            mylogger.Debug("MyTestPlugin:Reactivate: oldContext.WorkflowModelId =" + oldContext.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:Reactivate: oldContext.WorkflowState =" + oldContext.WorkflowState);
            mylogger.Debug("MyTestPlugin:Reactivate: newContext.WorkflowModelId =" + newContext.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:Reactivate: newContext.WorkflowState =" + newContext.WorkflowState);
            mylogger.Debug("");
            OnPageLoad(oldContext);
        }

        public void UpdateMenuActions(NavigationContext context, IDictionary<Guid, WorkflowAction> actions)
        {


            mylogger.Debug("MyTestPlugin:UpdateMenuActions: context.WorkflowModelId =" + context.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:UpdateMenuActions: context.WorkflowState =" + context.WorkflowState);
            mylogger.Debug("");
        }

        public ScreenUpdateMode UpdateScreen(NavigationContext context, ref string screen)
        {

            mylogger.Debug("MyTestPlugin:UpdateScreen: context.WorkflowModelId =" + context.WorkflowModelId);
            mylogger.Debug("MyTestPlugin:UpdateScreen: context.WorkflowState =" + context.WorkflowState);
            mylogger.Debug("MyTestPlugin:UpdateScreen: screen =" + screen);
            mylogger.Debug("");
            return ScreenUpdateMode.AutoWorkflowManager;
        }

        public void Dispose()
        {

            //seems to be usable for MP1 function DeInit()
            mylogger.Debug("MyTestPlugin:Dispose() - disposing");

            //do not forget to end the message queue
            _messageQueue.Shutdown();

        }


        public void OnPageLoad(NavigationContext oldContext)
        {
            //always called when plugin screeen is shown
            mylogger.Debug("MyTestPlugin:OnPageLoad()");

            //show config setting whenever screeen is loaded
            MyConfigLoadSettingExample();
        }

        public void OnPageDestroy(NavigationContext newContext)
        {
            //always called when plugin screeen is left
            // but .. not called when client is exited during screen!
            mylogger.Debug("MyTestPlugin:OnPageDestroy()");
        }
        #endregion





    }
    

    
    


    

    /*
    public class CommonNotificationService : IDisposable
    {
        protected AsynchronousMessageQueue _messageQueue;
        protected object _syncObj = new object();

        public CommonNotificationService()
        {
            _messageQueue = new AsynchronousMessageQueue(this, new string[]
          {
            MyTestPluginMessaging.CHANNEL,
          });
            _messageQueue.MessageReceived += OnMessageReceived;
            _messageQueue.Start();
        }

        public void Dispose()
        {
            _messageQueue.Shutdown();
        }

        private static void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message)
        {
            if (message.ChannelName == MyTestPluginMessaging.CHANNEL)
            {
                if (((MyTestPluginMessaging.MessageType)message.MessageType) == MyTestPluginMessaging.MessageType.ConfigurationChanged)
                {
                    ServiceRegistration.Get<ILogger>().Debug("class CurrentWeatherModel:  OnMessageReceived  Message received at " + DateTime.Now.ToString());
                }
            }
        }
    }*/
    


    /// <summary>
    /// This class provides an interface for the messages sent in this plugin.
    /// </summary>
    public static class MyTestPluginMessaging
    {
        // Message channel name
        public const string CHANNEL = "MyTestPluginMessages";

        // Message type
        public enum MessageType
        {
            /// <summary>
            /// This message will be sent when the weather location has been changed.
            /// </summary>
            ConfigurationChanged,
        }

        public static void SendMyTestPluginMessage(MessageType messageType)
        {
            // Send Startup Finished Message.
            SystemMessage msg = new SystemMessage(messageType);
            ServiceRegistration.Get<IMessageBroker>().Send(CHANNEL, msg);
        }
    }


    
}
