Adding basic display client connection.
1.1 --- a/NotificationPlugin.cs Tue Dec 08 13:52:15 2015 +0100
1.2 +++ b/NotificationPlugin.cs Tue Dec 08 18:49:02 2015 +0100
1.3 @@ -12,6 +12,10 @@
1.4 using System.IO;
1.5 using TvLibrary.Log;
1.6
1.7 +//
1.8 +using SharpLib.Display;
1.9 +using TvEngine.Events;
1.10 +using TvLibrary.Interfaces;
1.11
1.12 namespace TvServerPlugin
1.13 {
1.14 @@ -20,6 +24,8 @@
1.15 public class RecordSatus : ITvServerPlugin
1.16 {
1.17
1.18 + Client iClient;
1.19 +
1.20 /// <summary>
1.21 /// Reference to the tvservice's TVcontroller
1.22 /// </summary>
1.23 @@ -31,7 +37,120 @@
1.24 /// </summary>
1.25 public RecordSatus() { }
1.26
1.27 -
1.28 + /// <summary>
1.29 + ///
1.30 + /// </summary>
1.31 + public void OnCloseOrder()
1.32 + {
1.33 + CloseClient();
1.34 + }
1.35 +
1.36 + /// <summary>
1.37 + ///
1.38 + /// </summary>
1.39 + public void CloseClient()
1.40 + {
1.41 + iClient.Close();
1.42 + iClient = null;
1.43 + }
1.44 +
1.45 + void OpenClient()
1.46 + {
1.47 + iClient = new Client();
1.48 + //iClient.CloseOrderEvent += OnCloseOrder;
1.49 + iClient.Open();
1.50 +
1.51 + //Connect using unique name
1.52 + //string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt");
1.53 + string name = "Client-" + (iClient.ClientCount() - 1);
1.54 + iClient.SetName(name);
1.55 +
1.56 +
1.57 +
1.58 + //iClient.Open(/*"net.tcp://localhost:8111/DisplayService"*/);
1.59 +
1.60 + //Connect using unique name
1.61 + //string name = "Client-" + (iClient.ClientCount() - 1);
1.62 + //iClient.SetName(name);
1.63 + //Console.WriteLine("Name: " + name);
1.64 + }
1.65 +
1.66 + /// <summary>
1.67 + ///
1.68 + /// </summary>
1.69 + public void SetLayout()
1.70 + {
1.71 + TableLayout layout = new TableLayout(1, 1);
1.72 + iClient.SetLayout(layout);
1.73 + //We need to create our fields
1.74 + DataField field = new TextField();
1.75 + iClient.CreateFields(new DataField[]
1.76 + {
1.77 + field
1.78 + });
1.79 + }
1.80 +
1.81 + /// <summary>
1.82 + ///
1.83 + /// </summary>
1.84 + public void SetTextField()
1.85 + {
1.86 + TextField field = new TextField();
1.87 + field.Text = "Notification TV Server Plugin";
1.88 + iClient.SetField(field);
1.89 + }
1.90 +
1.91 +
1.92 + private void UpdateRecordingStatus()
1.93 + {
1.94 + RecordingField field = new RecordingField();
1.95 + field.IsActive = _controller.IsAnyCardRecording();
1.96 + iClient.SetField(field);
1.97 + }
1.98 +
1.99 + private void OnTvServerEvent(object sender, EventArgs eventArgs)
1.100 + {
1.101 + if (iClient==null)
1.102 + {
1.103 + //TODO: Try reconnect
1.104 + return;
1.105 + }
1.106 +
1.107 + TvServerEventArgs tvArgs = eventArgs as TvServerEventArgs;
1.108 + switch (tvArgs.EventType)
1.109 + {
1.110 + case TvServerEventType.RecordingStarted:
1.111 + UpdateRecordingStatus();
1.112 + break;
1.113 +
1.114 + case TvServerEventType.RecordingEnded:
1.115 +
1.116 + break;
1.117 + }
1.118 +
1.119 +
1.120 + /*
1.121 + if (_state == EpgState.Idle)
1.122 + return;
1.123 + TvServerEventArgs tvArgs = eventArgs as TvServerEventArgs;
1.124 + if (eventArgs == null)
1.125 + return;
1.126 + if (tvArgs != null)
1.127 + switch (tvArgs.EventType)
1.128 + {
1.129 + case TvServerEventType.StartTimeShifting:
1.130 + Log.Epg("epg cancelled due to start timeshifting");
1.131 + OnEpgCancelled();
1.132 + break;
1.133 +
1.134 + case TvServerEventType.StartRecording:
1.135 + Log.Epg("epg cancelled due to start recording");
1.136 + OnEpgCancelled();
1.137 + break;
1.138 + }
1.139 + */
1.140 + }
1.141 +
1.142 /// <summary>
1.143 /// Called by the tvservice PluginLoader to start this plugin
1.144 /// </summary>
1.145 @@ -42,6 +161,17 @@
1.146
1.147 _controller = controller;
1.148
1.149 +
1.150 + //Open Display Client Connection
1.151 + OpenClient();
1.152 + SetLayout();
1.153 + SetTextField();
1.154 + UpdateRecordingStatus();
1.155 +
1.156 + //
1.157 + ITvServerEvent events = GlobalServiceProvider.Instance.Get<ITvServerEvent>();
1.158 + events.OnTvServerEvent += new TvServerEventHandler(OnTvServerEvent);
1.159 +
1.160 Log.Debug(Name + " start - ends");
1.161 }
1.162
1.163 @@ -52,6 +182,7 @@
1.164 {
1.165 Log.Debug(Name + " stop");
1.166 _controller = null;
1.167 + CloseClient();
1.168 //PowerScheduler.Instance.Stop();
1.169 }
1.170