forked from JMS-1/DVB.NET---VCR.NET
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVCRNETControl.cs
More file actions
1655 lines (1366 loc) · 55 KB
/
VCRNETControl.cs
File metadata and controls
1655 lines (1366 loc) · 55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using Microsoft.Win32;
namespace VCRControlCenter
{
/// <summary>
/// Die farbliche Hinterlegung des Symbols im <i>System Tray</i> von Windows
/// beschreibt den Zustand des jeweiligen VCR.NET Recording Service.
/// </summary>
public enum TrayColors
{
/// <summary>
/// Der Zustand wurde noch nicht abgefragt.
/// </summary>
Unknown,
/// <summary>
/// Zumindest ein DVB.NET Geräteprofil ist in Benutzung.
/// </summary>
Blue,
/// <summary>
/// Kein DVB.NET Geräteprofil ist in Benutzung aber es gibt geplante Aufzeichnungen,
/// von denen keine in den nächsten 5 Minuten beginnt.
/// </summary>
Green,
/// <summary>
/// Der aktuelle Zustand des VCR.NET Recording Service konnte nicht ermittelt werden.
/// </summary>
Red,
/// <summary>
/// Kein DVB.NET Geräteprofil ist in Benutzung und es gibt auch keine geplante Aufzeichnungen.
/// </summary>
Standard,
/// <summary>
/// Kein DVB.NET Geräteprofil ist in Benutzung aber es gibt geplante Aufzeichnungen,
/// von denen mindestens eine in den nächsten 5 Minuten beginnt.
/// </summary>
Yellow
};
public partial class VCRNETControl : Form
{
private class CultureItem
{
public readonly CultureInfo Info;
public CultureItem( CultureInfo info )
{
// Remember
Info = info;
}
public override string ToString()
{
// Report
return Info.NativeName;
}
}
private class StreamInfo
{
public readonly Guid UniqueIdentifier;
public readonly bool Disconnect;
public readonly string Station;
public readonly string Profile;
public readonly int Index;
public readonly int Port;
public StreamInfo( string profile, int port, string station, Guid uniqueIdentifier, int index )
{
// Remember
UniqueIdentifier = uniqueIdentifier;
Disconnect = (port < 0);
Station = station;
Profile = profile;
Index = index;
Port = port;
}
}
private static int[] m_HibernateDelays = { 120, 90, 60, 45, 30, 15, 10, 5, -5, -10, -15, -30, -45, -60, -90, -120 };
private static object m_FileLock = new object();
private Dictionary<TrayColors, Icon> m_TrayIcons = new Dictionary<TrayColors, Icon>();
private Properties.Settings m_Settings = Properties.Settings.Default;
private List<NotifyIcon> m_Icons = new List<NotifyIcon>();
private DateTime m_BlockHibernate = DateTime.MaxValue;
private HibernateDialog m_Hibernation = null;
private bool m_QueryEndSession = false;
private NotifyIcon m_Active = null;
private Image m_Connected;
private string m_TopMenu;
public VCRNETControl( string[] args )
{
// Report
Log( "VCC [2013/06/01] starting up" );
// Autostart service
if (m_Settings.AutoStartService)
if (!ThreadPool.QueueUserWorkItem( StartService ))
StartService( null );
// This is us
Type me = GetType();
// Pattern start
string prefix = me.Namespace + ".TrayIcons.";
string suffix = ".ICO";
// Load tray icons
foreach (string resname in me.Assembly.GetManifestResourceNames())
if (resname.StartsWith( prefix ))
if (resname.EndsWith( suffix ))
{
// Icon
string iconname = resname.Substring( prefix.Length, resname.Length - prefix.Length - suffix.Length );
// Load
using (Stream stream = me.Assembly.GetManifestResourceStream( resname ))
{
// Load the icon
Icon icon = new Icon( stream );
// Check for debugger
if (Debugger.IsAttached)
using (var bmp = icon.ToBitmap())
{
// Change
using (var gc = Graphics.FromImage( bmp ))
using (var color = new SolidBrush( Color.Black ))
{
// Paint
gc.FillRectangle( color, 0, 15, bmp.Width, 5 );
}
// Free icon
icon.Dispose();
// Reload
icon = Icon.FromHandle( bmp.GetHicon() );
}
// Get the related color
var colorIndex = (TrayColors) Enum.Parse( typeof( TrayColors ), iconname, true );
// Add to map
m_TrayIcons[colorIndex] = icon;
}
}
// Load picture
using (var stream = me.Assembly.GetManifestResourceStream( me.Namespace + ".Icons.Connected.ico" ))
m_Connected = Image.FromStream( stream );
// Startup
InitializeComponent();
// Load the top menu string
m_TopMenu = mnuDefault.Text;
// Correct IDE problems (destroyed when language changes)
selHibernate.Value = 5;
selHibernate.Minimum = 1;
selHibernate.Maximum = 30;
selInterval.Value = 10;
selInterval.Minimum = 5;
selInterval.Maximum = 300;
selPort.Maximum = ushort.MaxValue;
selPort.Value = 80;
selPort.Minimum = 1;
selStreamPort.Maximum = ushort.MaxValue;
selStreamPort.Value = 2910;
selStreamPort.Minimum = 1;
lstServers.View = View.Details;
errorMessages.SetIconAlignment( txArgs, ErrorIconAlignment.MiddleLeft );
errorMessages.SetIconAlignment( txMultiCast, ErrorIconAlignment.MiddleLeft );
// Make sure that handle exists
CreateHandle();
// Load servers
if (null != m_Settings.Servers)
foreach (var setting in m_Settings.Servers)
lstServers.Items.Add( setting.View );
// Load settings
ckAutoStart.Checked = m_Settings.AutoStartService;
ckHibernate.Checked = (m_Settings.HibernationDelay > 0);
selHibernate.Value = ckHibernate.Checked ? (int) m_Settings.HibernationDelay : 5;
txMultiCast.Text = m_Settings.MulticastIP;
selStreamPort.Value = m_Settings.MinPort;
selDelay.Value = m_Settings.StartupDelay;
txArgs.Text = m_Settings.ViewerArgs;
txViewer.Text = m_Settings.Viewer;
// The default
CultureItem selectedItem = null;
// Fill language list
foreach (var info in CultureInfo.GetCultures( CultureTypes.NeutralCultures ))
{
// Skip all sub-languages
if (info.NativeName.IndexOf( '(' ) >= 0) continue;
// Create
var item = new CultureItem( info );
// Add to map
selLanguage.Items.Add( item );
// Remember default
if (Equals( m_Settings.Language, info.TwoLetterISOLanguageName )) selectedItem = item;
}
// Copy over
selLanguage.SelectedItem = selectedItem;
// Update GUI
CheckLocal();
CheckStream();
// No local service
frameLocal.Enabled = false;
// See if local service exists
try
{
// Attach to registry
using (var vcr = Registry.LocalMachine.OpenSubKey( @"SYSTEM\CurrentControlSet\Services\VCR.NET Service" ))
if (null != vcr)
{
// Load path
string image = (string) vcr.GetValue( "ImagePath" );
if (!string.IsNullOrEmpty( image ))
{
// Correct
if (image.StartsWith( "\"" ) && image.EndsWith( "\"" ) && (image.Length > 1))
{
// Remove quotes
image = image.Substring( 1, image.Length - 2 ).Replace( "\"\"", "\"" );
}
}
// Attach to configuration file
var config = new FileInfo( image + ".config" );
if (config.Exists)
{
// Load DOM
XmlDocument dom = new XmlDocument();
dom.Load( config.FullName );
// Check for port
var portNode = (XmlElement) dom.SelectSingleNode( "configuration/appSettings/add[@key='TCPPort']" );
var port = ushort.Parse( portNode.GetAttribute( "value" ) );
// At least there is a valid local server
frameLocal.Enabled = true;
// Check for defaulting
if (lstServers.Items.Count < 1)
{
// Create a new entry
var settings =
new PerServerSettings
{
ServerName = "localhost",
RefreshInterval = 10,
ServerPort = port,
};
// Add
m_Settings.Servers = new PerServerSettings[] { settings };
// Try add
try
{
// Save
m_Settings.Save();
// Add to list
lstServers.Items.Add( settings.View );
}
catch
{
// Reset
m_Settings.Servers = null;
}
}
}
}
}
catch
{
// Ignore any error
}
// Install tray icons
CreateTrayIcons();
// Prepare buttons
lstServers_SelectedIndexChanged( lstServers, EventArgs.Empty );
}
private PerServerSettings CurrentServer
{
get
{
// Nothing to do
if (null == m_Active) return null;
// Get the index of the icon clicked
int index = m_Icons.IndexOf( m_Active );
if (index < 0) return null;
// Validate
if (index >= lstServers.Items.Count) return null;
// Attach to the related server view
var view = (PerServerSettings.PerServerView) lstServers.Items[index];
// Report server
return view.Settings;
}
}
private void CreateTrayIcons()
{
// Disable timer
tickProcess.Enabled = false;
// Disable hibernation
HideHibernation();
// Reset all
for (int n = components.Components.Count; n-- > 0; )
{
// Read it
NotifyIcon icon = components.Components[n] as NotifyIcon;
if (null == icon) continue;
// Shutdown
icon.Dispose();
// Forget
components.Remove( icon );
}
// Clear internal state
m_Icons.Clear();
m_Active = null;
// Check mode
if (lstServers.Items.Count < 1)
{
// Create dummy
NotifyIcon icon = CreateTrayIcon( Properties.Resources.NoServers );
// Set color
SetNotifyIcon( icon, TrayColors.Red );
// Register double click
icon.DoubleClick += mnuSettings_Click;
}
else
{
// All servers
foreach (PerServerSettings.PerServerView view in lstServers.Items)
{
// Force fast recheck
view.ResetProcessing();
// Attach to server
PerServerSettings server = view.Settings;
// Create
NotifyIcon icon = CreateTrayIcon( string.Format( Properties.Resources.ServerTrayText, server.ServerName, server.ServerPort ) );
// Register double click
icon.DoubleClick += mnuDefault_Click;
}
// Enable timer
tickProcess.Enabled = true;
}
}
private NotifyIcon CreateTrayIcon( string text )
{
// Create new
NotifyIcon icon = new NotifyIcon( components );
// Remember
m_Icons.Add( icon );
// Configure
icon.ContextMenuStrip = trayMenu;
icon.Visible = true;
icon.Text = text;
// Time to set the icon
SetNotifyIcon( icon, TrayColors.Standard );
// Connect events
icon.MouseDown += SetActiveTray;
// Report
return icon;
}
private void SetActiveTray( object sender, MouseEventArgs e )
{
// Remember
m_Active = (NotifyIcon) sender;
}
private void mnuClose_Click( object sender, EventArgs e )
{
// Terminate application loop
Application.Exit();
}
protected override void OnClosing( CancelEventArgs e )
{
// Check mode
if (!m_QueryEndSession)
{
// Abort
e.Cancel = true;
// Hide self
Hide();
}
// Base
base.OnClosing( e );
}
/// <summary>
/// Wird beim Öffnen des Kontextmenüs aktiviert und füllt die dynamischen Menüeinträge.
/// </summary>
/// <param name="sender">Wird ignoriert.</param>
/// <param name="e">Wird ignoriert.</param>
private void trayMenu_Opening( object sender, CancelEventArgs e )
{
// Reset
mnuDefault.Text = m_TopMenu;
// Check mode
var hasHibernate = (m_Settings.HibernationDelay > 0);
var hasServers = (lstServers.Items.Count > 0);
// Enable/disable all
mnuHibernateSep.Visible = hasHibernate;
mnuHibernate.Visible = hasHibernate;
mnuOpenJobList.Enabled = hasServers;
mnuLiveConnect.Enabled = hasServers;
mnuHibernateServer.Visible = false;
mnuWakeupServer.Visible = false;
mnuCurrent.Enabled = hasServers;
mnuDefault.Enabled = hasServers;
mnuNewJob.Enabled = hasServers;
mnuAdmin.Enabled = hasServers;
mnuEPG.Enabled = hasServers;
// Update fonts
mnuSettings.Font = new Font( mnuSettings.Font, hasServers ? FontStyle.Regular : FontStyle.Bold );
mnuDefault.Font = new Font( mnuDefault.Font, hasServers ? FontStyle.Bold : FontStyle.Regular );
// Reset watch list
mnuLiveConnect.DropDownItems.Clear();
mnuCurrent.DropDownItems.Clear();
// See if there are servers configured
if (hasServers)
{
// Find the server
var settings = CurrentServer;
if (settings != null)
{
// Change top menu
mnuDefault.Text += string.Format( " ({0})", settings.ServerName );
// Check mode
if (settings.View.State != TrayColors.Red)
mnuHibernateServer.Visible = true;
else if (!settings.IsLocal)
mnuWakeupServer.Visible = true;
// No viewer
if (!string.IsNullOrEmpty( m_Settings.Viewer ))
{
// See if this is the DVB.NET / VCR.NET Viewer or an equivalent application
var usesViewer = (!string.IsNullOrEmpty( m_Settings.ViewerArgs ) && m_Settings.ViewerArgs.Contains( "{2}" ));
// Port counter
var port = m_Settings.MinPort;
// All profiles
foreach (var profile in settings.View.Profiles)
{
// Attach to the last known recording
var current = profile.CurrentRecordings;
if (current == null)
{
// Only if we can use the dvbnet:// protocol
if (usesViewer)
{
// Create the startup agrument for the DVB.NET Viewer
Uri uri = new Uri( settings.EndPoint );
// Add template
ToolStripItem live = mnuLiveConnect.DropDownItems.Add( profile.Profile );
// Attach recording information
live.Tag = string.Format( "dvbnet://*{0}/{1}/0/Live", uri.Authority, Uri.EscapeDataString( profile.Profile ) );
// Connect event
live.Click += LiveConnect;
}
// Next
continue;
}
// See if streaming is possible
foreach (var stream in current)
if (stream.streamIndex >= 0)
{
// Add template
var added = mnuCurrent.DropDownItems.Add( string.Format( Properties.Resources.StationFormat, stream.name, stream.device, string.IsNullOrEmpty( stream.streamTarget ) ? port.ToString() : stream.streamTarget ).Replace( "&", "&&" ) );
// Attach management
added.Image = string.IsNullOrEmpty( stream.streamTarget ) ? null : m_Connected;
added.Click += StartStopStreaming;
added.Tag = stream;
// Next port
stream.ReservedPort = port++;
}
}
}
}
}
// Disable live connect
mnuLiveConnect.Visible = (mnuLiveConnect.DropDownItems.Count > 0);
// Hibernate control
if (hasHibernate)
{
// Clear sub items from last call
while (mnuHibernate.DropDownItems.Count > 1) mnuHibernate.DropDownItems.RemoveAt( 1 );
// Get the reference time
DateTime now = DateTime.UtcNow, zero = now;
// Reset
if (m_BlockHibernate < now)
m_BlockHibernate = DateTime.MaxValue;
// Check mode
if (m_BlockHibernate < DateTime.MaxValue)
{
// See if hibernate delay is active
mnuHibernateReset.Visible = true;
// Set the text
mnuHibernateReset.Text = string.Format( Properties.Resources.HibernateReset, m_BlockHibernate.ToLocalTime() );
// Add separator
mnuHibernate.DropDownItems.Add( new ToolStripSeparator() );
// Use as reference time
zero = m_BlockHibernate;
}
else
{
// Do not show
mnuHibernateReset.Visible = false;
}
// Show options
foreach (int delay in m_HibernateDelays)
{
// Get the time
DateTime check = zero.AddMinutes( delay );
// Not possible
if (check <= now) break;
// Create entry
ToolStripMenuItem item = new ToolStripMenuItem();
// Fill it
item.Text = string.Format( Properties.Resources.HibernateN, check.ToLocalTime() );
item.Click += new EventHandler( SetHibernateDelay );
item.Tag = check;
// Remember it
mnuHibernate.DropDownItems.Add( item );
}
}
}
/// <summary>
/// Startet das aktuelle Anzeigeprogramm mit einem bestimmten Geräteprofil.
/// </summary>
/// <param name="sender">Der ausgelöste Menüpunkt.</param>
/// <param name="e">Wird ignoriert.</param>
private void LiveConnect( object sender, EventArgs e )
{
// Be safe
try
{
// Attach to menu item
ToolStripItem menu = (ToolStripItem) sender;
// Get the corresponding parameter
string dvbnetURL = (string) menu.Tag;
// Attach to server
Process.Start( m_Settings.Viewer, dvbnetURL );
}
catch
{
// Ignore for now
}
}
void SetHibernateDelay( object sender, EventArgs e )
{
// Convert
ToolStripMenuItem item = (ToolStripMenuItem) sender;
// Just update
m_BlockHibernate = (DateTime) item.Tag;
}
private void OpenBrowser( string page )
{
// Attach to the related server
var settings = CurrentServer;
if (settings != null)
Process.Start( string.Format( "{0}/{1}", settings.EndPoint, page ) );
}
private void mnuDefault_Click( object sender, EventArgs e )
{
// Open browser
OpenBrowser( "default.html" );
}
private void mnuSettings_Click( object sender, EventArgs e )
{
// Show self
Show();
// To top
BringToFront();
}
private void UpdateGUI()
{
// Forward
UpdateGUI( null, EventArgs.Empty );
}
private PerServerSettings FindServer( string server )
{
// Process
foreach (PerServerSettings.PerServerView view in lstServers.Items)
if (0 == string.Compare( view.Settings.ServerName, server, true ))
return view.Settings;
// Not found
return null;
}
private void UpdateGUI( object sender, EventArgs e )
{
// Disable all
cmdAdd.Enabled = false;
cmdDelete.Enabled = false;
cmdUpdate.Enabled = false;
// Get the server name
var serverName = txServer.Text;
if (string.IsNullOrEmpty( serverName ))
return;
// Parse the address
IPAddress subNetAddress;
if (!IPAddress.TryParse( txSubNet.Text, out subNetAddress ))
return;
// Find server
var server = FindServer( serverName );
if (server == null)
{
// At least we can add it
cmdAdd.Enabled = true;
// Done
return;
}
// At least we can delete it
cmdDelete.Enabled = true;
// See if this is an equal entry
if (serverName.Equals( server.ServerName ))
if (subNetAddress.ToString().Equals( server.WakeUpBroadcast ))
if (selInterval.Value == server.RefreshInterval)
if (selPort.Value == server.ServerPort)
return;
// And finally we could update
cmdUpdate.Enabled = true;
}
private void cmdAdd_Click( object sender, EventArgs e )
{
// Create a brand new item
var settings =
new PerServerSettings
{
RefreshInterval = (int) selInterval.Value,
ServerPort = (ushort) selPort.Value,
WakeUpBroadcast = txSubNet.Text,
ServerName = txServer.Text,
};
// Update view
settings.View.Refresh();
// Create the update list
var list = new List<PerServerSettings>();
// Existing
foreach (PerServerSettings.PerServerView view in lstServers.Items)
list.Add( view.Settings );
// the new one
list.Add( settings );
// Old value
PerServerSettings[] oldSettings = m_Settings.Servers;
// Update
m_Settings.Servers = list.ToArray();
// Try save
try
{
// Store to disk
m_Settings.Save();
// Unselect
foreach (PerServerSettings.PerServerView view in lstServers.Items)
view.Selected = false;
// Select
settings.View.Selected = true;
// Update in memory
lstServers.Items.Add( settings.View );
// Show
settings.View.EnsureVisible();
// Refresh icon list
CreateTrayIcons();
}
catch (Exception ex)
{
// Back
m_Settings.Servers = oldSettings;
// Report
MessageBox.Show( this, ex.Message, string.Format( Properties.Resources.AddServerTitle, settings.ServerName ) );
}
}
private void lstServers_SelectedIndexChanged( object sender, EventArgs e )
{
// Single select only
if (lstServers.SelectedItems.Count != 1)
{
// Reste
txServer.Text = (lstServers.Items.Count < 1) ? "VCRServer" : null;
txSubNet.Text = IPAddress.Broadcast.ToString();
selInterval.Value = 10;
selPort.Value = 80;
}
else
{
// Attach to the selected item
var view = (PerServerSettings.PerServerView) lstServers.SelectedItems[0];
var settings = view.Settings;
// Load all
txSubNet.Text = settings.SubNetAddress.ToString();
selInterval.Value = settings.RefreshInterval;
txServer.Text = settings.ServerName;
selPort.Value = settings.ServerPort;
}
// Refresh all
UpdateGUI();
}
private void cmdDelete_Click( object sender, EventArgs e )
{
// Create a brand new item
var settings = FindServer( txServer.Text );
if (settings == null)
return;
// Create the update list
var list = new List<PerServerSettings>();
// Existing
foreach (PerServerSettings.PerServerView view in lstServers.Items)
if (view.Settings != settings)
list.Add( view.Settings );
// Old value
var oldSettings = m_Settings.Servers;
// Update
m_Settings.Servers = list.ToArray();
// Try save
try
{
// Store to disk
m_Settings.Save();
// Update in memory
lstServers.Items.Remove( settings.View );
// Update GUI
lstServers_SelectedIndexChanged( lstServers, EventArgs.Empty );
// Refresh icon list
CreateTrayIcons();
}
catch (Exception ex)
{
// Back
m_Settings.Servers = oldSettings;
// Report
MessageBox.Show( this, ex.Message, string.Format( Properties.Resources.DelServerTitle, settings.ServerName ) );
}
}
private void cmdUpdate_Click( object sender, EventArgs e )
{
// Create a brand new item
var settings = FindServer( txServer.Text );
if (settings == null)
return;
// Remember
var subNetAddress = settings.WakeUpBroadcast;
var interval = settings.RefreshInterval;
var server = settings.ServerName;
var port = settings.ServerPort;
// Update
settings.RefreshInterval = (int) selInterval.Value;
settings.ServerPort = (ushort) selPort.Value;
settings.WakeUpBroadcast = txSubNet.Text;
settings.ServerName = txServer.Text;
// Try save
try
{
// Store to disk
m_Settings.Save();
// Update view
settings.View.Refresh();
// Update GUI
lstServers_SelectedIndexChanged( lstServers, EventArgs.Empty );
// Refresh icon list
CreateTrayIcons();
}
catch (Exception ex)
{
// Back
settings.WakeUpBroadcast = subNetAddress;
settings.RefreshInterval = interval;
settings.ServerName = server;
settings.ServerPort = port;
// Report
MessageBox.Show( this, ex.Message, string.Format( Properties.Resources.UpdateServerTitle, settings.ServerName ) );
}
}
private void mnuAdmin_Click( object sender, EventArgs e )
{
// Jump in
OpenBrowser( "default.html#admin" );
}
private void mnuOpenJobList_Click( object sender, EventArgs e )
{
// Jump in
OpenBrowser( "default.html#plan" );
}
/// <summary>
/// Ruft in der zugehörigen Web Anwendung die Anzeige der aktuellen Aufzeichnungen auf.
/// </summary>
/// <param name="sender">Wird ignoriert.</param>
/// <param name="e">Wird ignoriert.</param>
private void mnuCurrent_Click( object sender, EventArgs e )
{
// Jump in
OpenBrowser( "default.html#current" );
}
private void CheckLocal()
{
// Forward
CheckLocal( null, EventArgs.Empty );
}
private void CheckLocal( object sender, EventArgs e )
{
// Disable / enable
selHibernate.Enabled = ckHibernate.Checked;
// Disable update
cmdUpdateAll.Enabled = false;
// Test all flags
if (m_Settings.AutoStartService == ckAutoStart.Checked)
{
// Get the delay
int delay = ckHibernate.Checked ? (int) selHibernate.Value : 0;
// Compare
if (m_Settings.HibernationDelay == delay) return;
}
// Can update
cmdUpdateAll.Enabled = true;
}
private string CurrentLanguage
{
get
{
// Attach to selected language
CultureItem culture = (CultureItem) selLanguage.SelectedItem;
// Report
return (null == culture) ? string.Empty : culture.Info.TwoLetterISOLanguageName;
}
}
private void cmdUpdateAll_Click( object sender, EventArgs e )
{
// Old values
bool autoStart = m_Settings.AutoStartService;
int delay = m_Settings.HibernationDelay;
// Update the all
m_Settings.HibernationDelay = ckHibernate.Checked ? (int) selHibernate.Value : 0;
m_Settings.AutoStartService = ckAutoStart.Checked;