Published V.1.0.5.
authorStephaneLenclud
Mon, 29 Aug 2016 17:36:02 +0200
changeset 25651b86efdc448
parent 255 c57b8ac80fc6
child 257 3f1d16d233dc
Published V.1.0.5.
Providing Harmony Hub reconnect.
Server/Actions/ActionHarmonyCommand.cs
Server/FormMain.cs
Server/SharpDisplayManager.csproj
Server/packages.config
     1.1 --- a/Server/Actions/ActionHarmonyCommand.cs	Thu Aug 25 13:34:05 2016 +0200
     1.2 +++ b/Server/Actions/ActionHarmonyCommand.cs	Mon Aug 29 17:36:02 2016 +0200
     1.3 @@ -74,13 +74,14 @@
     1.4              //TODO: check if the harmony client connection is opened
     1.5              if (Program.HarmonyClient!=null)
     1.6              {
     1.7 -                Program.HarmonyClient.SendCommandAsync(DeviceId, FunctionName);
     1.8 +                // Wait synchronously for now until we figure out how we could do async stuff in EAR.
     1.9 +                // TODO: Have an abort option in EAR. For instance we don't want to keep sending Harmony command if one failed.
    1.10 +                Program.HarmonyClient.TrySendCommandAsync(DeviceId, FunctionName).Wait(10*1000);
    1.11              }
    1.12              else
    1.13              {
    1.14                  Trace.WriteLine("WARNING: No Harmony client connection.");
    1.15 -            }
    1.16 -            
    1.17 +            }            
    1.18          }
    1.19  
    1.20  
     2.1 --- a/Server/FormMain.cs	Thu Aug 25 13:34:05 2016 +0200
     2.2 +++ b/Server/FormMain.cs	Mon Aug 29 17:36:02 2016 +0200
     2.3 @@ -2982,6 +2982,18 @@
     2.4          }
     2.5  
     2.6          /// <summary>
     2.7 +        /// Called whenever we loose connection with our HarmonyHub.
     2.8 +        /// </summary>
     2.9 +        /// <param name="aRequestWasCancelled"></param>
    2.10 +        private void HarmonyConnectionClosedByServer(object aSender, bool aRequestWasCancelled)
    2.11 +        {
    2.12 +            //Try reconnect then
    2.13 +#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
    2.14 +            ResetHarmonyAsync();
    2.15 +#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
    2.16 +        }
    2.17 +
    2.18 +        /// <summary>
    2.19          /// 
    2.20          /// </summary>
    2.21          /// <returns></returns>
    2.22 @@ -2997,16 +3009,24 @@
    2.23              Program.HarmonyConfig = null;
    2.24  
    2.25              Trace.WriteLine("Harmony: Connecting... ");
    2.26 +            //First create our client and login
    2.27              Program.HarmonyClient = new HarmonyHub.Client(iTextBoxHarmonyHubAddress.Text);
    2.28 -            //First create our client and login
    2.29 +            Program.HarmonyClient.OnConnectionClosedByServer += HarmonyConnectionClosedByServer;
    2.30 +            
    2.31              if (File.Exists("SessionToken") && !aForceAuth)
    2.32              {
    2.33                  var sessionToken = File.ReadAllText("SessionToken");
    2.34                  Trace.WriteLine("Harmony: Reusing token: {0}", sessionToken);
    2.35 -                await Program.HarmonyClient.OpenAsync(sessionToken);
    2.36 +                await Program.HarmonyClient.TryOpenAsync(sessionToken);
    2.37              }
    2.38 -            else
    2.39 +
    2.40 +            if (!Program.HarmonyClient.IsReady)
    2.41              {
    2.42 +                //We failed to connect using our token
    2.43 +                //Delete it then
    2.44 +                File.Delete("SessionToken");
    2.45 +
    2.46 +                //Then try connect using our password
    2.47                  if (string.IsNullOrEmpty(iTextBoxLogitechPassword.Text))
    2.48                  {
    2.49                      Trace.WriteLine("Harmony: Credentials missing!");
    2.50 @@ -3014,18 +3034,13 @@
    2.51                  }
    2.52  
    2.53                  Trace.WriteLine("Harmony: Authenticating with Logitech servers...");
    2.54 -                await Program.HarmonyClient.OpenAsync(iTextBoxLogitechUserName.Text, iTextBoxLogitechPassword.Text);
    2.55 +                await Program.HarmonyClient.TryOpenAsync(iTextBoxLogitechUserName.Text, iTextBoxLogitechPassword.Text);
    2.56                  File.WriteAllText("SessionToken", Program.HarmonyClient.Token);
    2.57              }
    2.58  
    2.59 -            Trace.WriteLine("Harmony: Fetching Harmony Hub configuration...");
    2.60 -
    2.61              //Fetch our config
    2.62              Program.HarmonyConfig = await Program.HarmonyClient.GetConfigAsync();
    2.63              PopulateTreeViewHarmony(Program.HarmonyConfig);
    2.64 -
    2.65 -            Trace.WriteLine("Harmony: Ready");
    2.66 -
    2.67              //Make sure harmony command actions are showing device name instead of device id
    2.68              PopulateEventsTreeView();
    2.69          }
     3.1 --- a/Server/SharpDisplayManager.csproj	Thu Aug 25 13:34:05 2016 +0200
     3.2 +++ b/Server/SharpDisplayManager.csproj	Mon Aug 29 17:36:02 2016 +0200
     3.3 @@ -34,7 +34,7 @@
     3.4      <WebPage>index.htm</WebPage>
     3.5      <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
     3.6      <ApplicationRevision>0</ApplicationRevision>
     3.7 -    <ApplicationVersion>1.0.2.0</ApplicationVersion>
     3.8 +    <ApplicationVersion>1.0.5.0</ApplicationVersion>
     3.9      <UseApplicationTrust>false</UseApplicationTrust>
    3.10      <CreateDesktopShortcut>true</CreateDesktopShortcut>
    3.11      <PublishWizardCompleted>true</PublishWizardCompleted>
    3.12 @@ -112,7 +112,7 @@
    3.13        <Private>True</Private>
    3.14      </Reference>
    3.15      <Reference Include="HarmonyHub, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    3.16 -      <HintPath>..\packages\SharpLibHarmony.0.5.0\lib\net451\HarmonyHub.dll</HintPath>
    3.17 +      <HintPath>..\packages\SharpLibHarmony.0.6.1\lib\net451\HarmonyHub.dll</HintPath>
    3.18        <Private>True</Private>
    3.19      </Reference>
    3.20      <Reference Include="LibCecSharp, Version=2.2.0.0, Culture=neutral, processorArchitecture=x86">
     4.1 --- a/Server/packages.config	Thu Aug 25 13:34:05 2016 +0200
     4.2 +++ b/Server/packages.config	Mon Aug 29 17:36:02 2016 +0200
     4.3 @@ -4,7 +4,7 @@
     4.4    <package id="Loamen.agsXMPP" version="1.3.1" targetFramework="net46" />
     4.5    <package id="NAudio" version="1.7.3" targetFramework="net45" />
     4.6    <package id="SharpLibDisplay" version="0.2.5" targetFramework="net46" />
     4.7 -  <package id="SharpLibHarmony" version="0.5.0" targetFramework="net46" />
     4.8 +  <package id="SharpLibHarmony" version="0.6.1" targetFramework="net46" />
     4.9    <package id="SharpLibHid" version="1.4.2" targetFramework="net46" />
    4.10    <package id="SharpLibNotification" version="0.0.1" targetFramework="net46" />
    4.11    <package id="SharpLibWin32" version="0.0.9" targetFramework="net46" />