Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Framework
- {
- using System;
- using Crestron.SimplSharp;
- using Crestron.SimplSharpPro;
- using Crestron.SimplSharpPro.CrestronThread;
- using log4net;
- using SSMono.IO;
- /// <summary>
- /// The control system.
- /// </summary>
- public class ControlSystem : CrestronControlSystem
- {
- /// <summary>
- /// The log.
- /// </summary>
- private static readonly ILog Log =
- LogManager.GetLogger("Framework");
- /// <summary>
- /// Initializes a new instance of the <see cref="ControlSystem"/> class.
- /// ControlSystem Constructor. Starting point for the SIMPL#Pro program.
- /// Use the constructor to:
- /// * Initialize the maximum number of threads (max = 400)
- /// * Register devices
- /// * Register event handlers
- /// * Add Console Commands
- /// Please be aware that the constructor needs to exit quickly; if it doesn't
- /// exit in time, the SIMPL#Pro program will exit.
- /// You cannot send / receive data in the constructor
- /// </summary>
- public ControlSystem()
- {
- try
- {
- Thread.MaxNumberOfUserThreads = 20;
- // Subscribe to the controller events (System, Program, and Ethernet)
- CrestronEnvironment.SystemEventHandler += this.ControlSystem_ControllerSystemEventHandler;
- CrestronEnvironment.ProgramStatusEventHandler += this.ControlSystem_ControllerProgramEventHandler;
- CrestronEnvironment.EthernetEventHandler += this.ControlSystem_ControllerEthernetEventHandler;
- }
- catch (Exception e)
- {
- if (Log.IsErrorEnabled)
- {
- Log.Error("Error in control system constructor", e);
- }
- else
- {
- ErrorLog.Error("{0} {1} - {2} {3} {4}", "ERROR", "CrossColorsFramework", "Error in control system constructor", e.Message, e.StackTrace);
- }
- }
- }
- /// <summary>
- /// Gets or sets the builder.
- /// </summary>
- private SystemBuilder Builder { get; set; }
- /// <summary>
- /// InitializeSystem - this method gets called after the constructor
- /// has finished.
- /// Use InitializeSystem to:
- /// * Start threads
- /// * Configure ports, such as serial and VERSIPORTS
- /// * Start and initialize socket connections
- /// Send initial device configurations
- /// Please be aware that InitializeSystem needs to exit quickly also;
- /// if it doesn't exit in time, the SIMPL#Pro program will exit.
- /// </summary>
- public override void InitializeSystem()
- {
- try
- {
- log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(@"\USER\log4net.config"));
- // this.Builder = new SystemBuilder(this);
- }
- catch (Exception e)
- {
- Log.Error(string.Format("Error in InitializeSystem"), e);
- }
- }
- /// <summary>
- /// Event Handler for Ethernet events: Link Up and Link Down.
- /// Use these events to close / re-open sockets, etc.
- /// </summary>
- /// <param name="ethernetEventArgs">This parameter holds the values
- /// such as whether it's a Link Up or Link Down event. It will also indicate
- /// wich Ethernet adapter this event belongs to.
- /// </param>
- void ControlSystem_ControllerEthernetEventHandler(EthernetEventArgs ethernetEventArgs)
- {
- switch (ethernetEventArgs.EthernetEventType)
- {//Determine the event type Link Up or Link Down
- case (eEthernetEventType.LinkDown):
- //Next need to determine which adapter the event is for.
- //LAN is the adapter is the port connected to external networks.
- if (ethernetEventArgs.EthernetAdapter == EthernetAdapterType.EthernetLANAdapter)
- {
- //
- }
- break;
- case (eEthernetEventType.LinkUp):
- if (ethernetEventArgs.EthernetAdapter == EthernetAdapterType.EthernetLANAdapter)
- {
- }
- break;
- }
- }
- /// <summary>
- /// Event Handler for Programmatic events: Stop, Pause, Resume.
- /// Use this event to clean up when a program is stopping, pausing, and resuming.
- /// This event only applies to this SIMPL#Pro program, it doesn't receive events
- /// for other programs stopping
- /// </summary>
- /// <param name="programStatusEventType"></param>
- void ControlSystem_ControllerProgramEventHandler(eProgramStatusEventType programStatusEventType)
- {
- switch (programStatusEventType)
- {
- case (eProgramStatusEventType.Paused):
- //The program has been paused. Pause all user threads/timers as needed.
- break;
- case (eProgramStatusEventType.Resumed):
- //The program has been resumed. Resume all the user threads/timers as needed.
- break;
- case (eProgramStatusEventType.Stopping):
- //The program has been stopped.
- //Close all threads.
- //Shutdown all Client/Servers in the system.
- //General cleanup.
- //Unsubscribe to all System Monitor events
- break;
- }
- }
- /// <summary>
- /// Event Handler for system events, Disk Inserted/Ejected, and Reboot
- /// Use this event to clean up when someone types in reboot, or when your SD /USB
- /// removable media is ejected / re-inserted.
- /// </summary>
- /// <param name="systemEventType"></param>
- void ControlSystem_ControllerSystemEventHandler(eSystemEventType systemEventType)
- {
- switch (systemEventType)
- {
- case (eSystemEventType.DiskInserted):
- //Removable media was detected on the system
- break;
- case (eSystemEventType.DiskRemoved):
- //Removable media was detached from the system
- break;
- case (eSystemEventType.Rebooting):
- //The system is rebooting.
- //Very limited time to preform clean up and save any settings to disk.
- break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment