Add retry if Skype initialization fails

This commit is contained in:
2014-05-14 16:35:06 -04:00
parent daf2c0f885
commit e918c863b9
5 changed files with 56 additions and 15 deletions

View File

@@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Timers;
using Common.Native; using Common.Native;
using SKYPE4COMLib; using SKYPE4COMLib;
using WorkIndicator.Delcom; using WorkIndicator.Delcom;
@@ -23,6 +23,7 @@ namespace WorkIndicator
private static StoplightIndicator _stoplightIndicator; private static StoplightIndicator _stoplightIndicator;
private static bool _initialized; private static bool _initialized;
private static Status _status = Status.Auto; private static Status _status = Status.Auto;
private static Timer _retryTimer;
public static void Initialize() public static void Initialize()
{ {
@@ -61,9 +62,9 @@ namespace WorkIndicator
private static void UpdateLights() private static void UpdateLights()
{ {
StoplightIndicator.LightState red = StoplightIndicator.LightState.Off; var red = StoplightIndicator.LightState.Off;
StoplightIndicator.LightState yellow = StoplightIndicator.LightState.Off; var yellow = StoplightIndicator.LightState.Off;
StoplightIndicator.LightState green = StoplightIndicator.LightState.Off; var green = StoplightIndicator.LightState.Off;
if (_status == Status.Auto) if (_status == Status.Auto)
{ {
@@ -112,13 +113,31 @@ namespace WorkIndicator
public static void InitializeSkypeDetection() public static void InitializeSkypeDetection()
{ {
_skype = new Skype(); try
_skype.Attach(); {
_skype = new Skype();
_skype.Attach();
_ISkypeEvents_Event skypeEvents = _skype; _ISkypeEvents_Event skypeEvents = _skype;
skypeEvents.CallStatus += HandleSkypeCallStatus; skypeEvents.CallStatus += HandleSkypeCallStatus;
skypeEvents.Mute += HandleSkypeEventsMute; skypeEvents.Mute += HandleSkypeEventsMute;
}
catch (Exception)
{
if (_retryTimer == null)
{
_retryTimer = new Timer(Properties.Settings.Default.RetryInterval.TotalMilliseconds) { AutoReset = false };
_retryTimer.Elapsed += HandRetryTimerElapsed;
}
_retryTimer.Start();
}
}
static void HandRetryTimerElapsed(object sender, ElapsedEventArgs e)
{
InitializeSkypeDetection();
} }
static void HandleSkypeEventsMute(bool mute) static void HandleSkypeEventsMute(bool mute)

View File

@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
// Runtime Version:4.0.30319.34011 // Runtime Version:4.0.30319.34209
// //
// Changes to this file may cause incorrect behavior and will be lost if // Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. // the code is regenerated.
@@ -46,5 +46,14 @@ namespace WorkIndicator.Properties {
this["WindowPattern"] = value; this["WindowPattern"] = value;
} }
} }
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("00:00:10")]
public global::System.TimeSpan RetryInterval {
get {
return ((global::System.TimeSpan)(this["RetryInterval"]));
}
}
} }
} }

View File

@@ -8,5 +8,8 @@
<Setting Name="WindowPattern" Type="System.String" Scope="User"> <Setting Name="WindowPattern" Type="System.String" Scope="User">
<Value Profile="(Default)">.* - CKACZOR - Remote Desktop Connection</Value> <Value Profile="(Default)">.* - CKACZOR - Remote Desktop Connection</Value>
</Setting> </Setting>
<Setting Name="RetryInterval" Type="System.TimeSpan" Scope="Application">
<Value Profile="(Default)">00:00:10</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View File

@@ -17,11 +17,11 @@ namespace WorkIndicator
_trayIcon = new NotifyIcon { Icon = Resources.MainIcon, Text = Resources.ApplicationName }; _trayIcon = new NotifyIcon { Icon = Resources.MainIcon, Text = Resources.ApplicationName };
// Setup the menu // Setup the menu
ContextMenuStrip contextMenuStrip = new ContextMenuStrip(); var contextMenuStrip = new ContextMenuStrip();
contextMenuStrip.Opening += HandleContextMenuStripOpening; contextMenuStrip.Opening += HandleContextMenuStripOpening;
// Add the menu items // Add the menu items
ToolStripMenuItem menuItem = new ToolStripMenuItem(Resources.Auto, null, HandleStatusMenuClick) { Tag = Status.Auto }; var menuItem = new ToolStripMenuItem(Resources.Auto, null, HandleStatusMenuClick) { Tag = Status.Auto };
contextMenuStrip.Items.Add(menuItem); contextMenuStrip.Items.Add(menuItem);
// -- // --
@@ -65,7 +65,7 @@ namespace WorkIndicator
if (menuItem.Tag == null) if (menuItem.Tag == null)
continue; continue;
Status status = (Status) menuItem.Tag; var status = (Status) menuItem.Tag;
((ToolStripMenuItem) menuItem).Checked = (LightController.Status == status); ((ToolStripMenuItem) menuItem).Checked = (LightController.Status == status);
} }
@@ -73,9 +73,9 @@ namespace WorkIndicator
private static void HandleStatusMenuClick(object sender, System.EventArgs e) private static void HandleStatusMenuClick(object sender, System.EventArgs e)
{ {
ToolStripMenuItem menuItem = (ToolStripMenuItem) sender; var menuItem = (ToolStripMenuItem) sender;
Status status = (Status) menuItem.Tag; var status = (Status) menuItem.Tag;
LightController.Status = status; LightController.Status = status;
} }

View File

@@ -4,6 +4,9 @@
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="WorkIndicator.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> <section name="WorkIndicator.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup> </sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="WorkIndicator.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections> </configSections>
<userSettings> <userSettings>
<WorkIndicator.Properties.Settings> <WorkIndicator.Properties.Settings>
@@ -15,4 +18,11 @@
</setting> </setting>
</WorkIndicator.Properties.Settings> </WorkIndicator.Properties.Settings>
</userSettings> </userSettings>
<applicationSettings>
<WorkIndicator.Properties.Settings>
<setting name="RetryInterval" serializeAs="String">
<value>00:00:10</value>
</setting>
</WorkIndicator.Properties.Settings>
</applicationSettings>
</configuration> </configuration>