Published v1.3.1.0.
authorStephaneLenclud
Wed, 31 Aug 2016 23:59:00 +0200
changeset 266b11d7ebbdc7f
parent 265 82e87f4956ea
child 267 a601b377a3eb
Published v1.3.1.0.
Harmony Auth Token now persisted in settings.
Various EAR view fixes.
Removed Sleep action
Server/App.config
Server/FormEditObject.cs
Server/FormMain.cs
Server/Properties/Settings.Designer.cs
Server/Properties/Settings.settings
Server/SharpDisplayManager.csproj
SharpLibEar/Action.cs
SharpLibEar/ActionSleep.cs
SharpLibEar/SharpLibEar.csproj
     1.1 --- a/Server/App.config	Wed Aug 31 20:20:32 2016 +0200
     1.2 +++ b/Server/App.config	Wed Aug 31 23:59:00 2016 +0200
     1.3 @@ -43,6 +43,9 @@
     1.4              <setting name="LogitechUserName" serializeAs="String">
     1.5                  <value />
     1.6              </setting>
     1.7 +            <setting name="LogitechAuthToken" serializeAs="String">
     1.8 +                <value />
     1.9 +            </setting>
    1.10          </SharpDisplayManager.Properties.Settings>
    1.11      </userSettings>
    1.12  </configuration>
     2.1 --- a/Server/FormEditObject.cs	Wed Aug 31 20:20:32 2016 +0200
     2.2 +++ b/Server/FormEditObject.cs	Wed Aug 31 23:59:00 2016 +0200
     2.3 @@ -111,14 +111,18 @@
     2.4              //Create another type of action only if needed
     2.5              if (Object == null || Object.GetType() != objectType)
     2.6              {
     2.7 +                string name = "";
     2.8                  if (Object != null)
     2.9                  {
    2.10                      // Make sure we exit edit mode and unhook from events
    2.11                      Object.CurrentState = SharpLib.Ear.Object.State.Rest;
    2.12                      Object.PropertyChanged -= PropertyChangedEventHandlerThreadSafe;
    2.13 +                    name = Object.Name;
    2.14                      Object = null;
    2.15                  }
    2.16                  Object = (T)Activator.CreateInstance(objectType);
    2.17 +                //Keep the name when changing the type
    2.18 +                Object.Name = name;
    2.19              }
    2.20  
    2.21              //Create input fields
     3.1 --- a/Server/FormMain.cs	Wed Aug 31 20:20:32 2016 +0200
     3.2 +++ b/Server/FormMain.cs	Wed Aug 31 23:59:00 2016 +0200
     3.3 @@ -371,13 +371,8 @@
     3.4          /// <summary>
     3.5          /// Populate tree view with events and actions
     3.6          /// </summary>
     3.7 -        private void PopulateTreeViewEvents()
     3.8 +        private void PopulateTreeViewEvents(Ear.Object aSelectedObject=null)
     3.9          {
    3.10 -            //Disable action buttons
    3.11 -            buttonActionAdd.Enabled = false;
    3.12 -            buttonActionDelete.Enabled = false;
    3.13 -
    3.14 -            
    3.15              //Reset our tree
    3.16              iTreeViewEvents.Nodes.Clear();
    3.17              //Populate registered events
    3.18 @@ -417,6 +412,12 @@
    3.19  
    3.20              iTreeViewEvents.ExpandAll();
    3.21  
    3.22 +            if (aSelectedObject != null)
    3.23 +            {
    3.24 +                SelectEarObject(aSelectedObject);
    3.25 +            }            
    3.26 +
    3.27 +            // Just to be safe in case the selection did not work
    3.28              UpdateEventView();
    3.29          }
    3.30  
    3.31 @@ -2782,8 +2783,8 @@
    3.32              {
    3.33                  parent.Objects.Add(ea.Object);               
    3.34                  Properties.Settings.Default.Save();
    3.35 -                PopulateTreeViewEvents();
    3.36 -                SelectEarObject(ea.Object);
    3.37 +                // We want to select the parent so that one can easily add another action to the same collection
    3.38 +                PopulateTreeViewEvents(parent);
    3.39              }
    3.40          }
    3.41  
    3.42 @@ -2816,8 +2817,7 @@
    3.43                  parent.Objects[actionIndex]=ea.Object;
    3.44                  //Save and rebuild our event tree view
    3.45                  Properties.Settings.Default.Save();
    3.46 -                PopulateTreeViewEvents();
    3.47 -                SelectEarObject(ea.Object);
    3.48 +                PopulateTreeViewEvents(ea.Object);
    3.49              }
    3.50          }
    3.51  
    3.52 @@ -2880,9 +2880,7 @@
    3.53  
    3.54              //Save and populate our tree again
    3.55              Properties.Settings.Default.Save();
    3.56 -            PopulateTreeViewEvents();
    3.57 -            SelectEarObject(a);
    3.58 -
    3.59 +            PopulateTreeViewEvents(a);
    3.60          }
    3.61  
    3.62          /// <summary>
    3.63 @@ -2910,8 +2908,7 @@
    3.64  
    3.65              //Save and populate our tree again
    3.66              Properties.Settings.Default.Save();
    3.67 -            PopulateTreeViewEvents();
    3.68 -            SelectEarObject(a);
    3.69 +            PopulateTreeViewEvents(a);
    3.70          }
    3.71  
    3.72  
    3.73 @@ -2986,8 +2983,7 @@
    3.74              {
    3.75                  Properties.Settings.Default.EarManager.Events.Add(ea.Object);
    3.76                  Properties.Settings.Default.Save();
    3.77 -                PopulateTreeViewEvents();
    3.78 -                SelectEarObject(ea.Object);
    3.79 +                PopulateTreeViewEvents(ea.Object);
    3.80              }
    3.81          }
    3.82  
    3.83 @@ -3037,8 +3033,7 @@
    3.84                  Properties.Settings.Default.EarManager.Events[index] = ea.Object;
    3.85                  //Save and rebuild our event tree view
    3.86                  Properties.Settings.Default.Save();
    3.87 -                PopulateTreeViewEvents();
    3.88 -                SelectEarObject(ea.Object);
    3.89 +                PopulateTreeViewEvents(ea.Object);
    3.90              }
    3.91          }
    3.92  
    3.93 @@ -3085,19 +3080,20 @@
    3.94              //Tip: Set keep-alive to false when testing reconnection process
    3.95              Program.HarmonyClient = new HarmonyHub.Client(iTextBoxHarmonyHubAddress.Text, true);
    3.96              Program.HarmonyClient.OnConnectionClosedByServer += HarmonyConnectionClosedByServer;
    3.97 -            
    3.98 -            if (File.Exists("SessionToken") && !aForceAuth)
    3.99 +
   3.100 +            string authToken = Properties.Settings.Default.LogitechAuthToken;
   3.101 +            if (!string.IsNullOrEmpty(authToken) && !aForceAuth)
   3.102              {
   3.103 -                var sessionToken = File.ReadAllText("SessionToken");
   3.104 -                Trace.WriteLine("Harmony: Reusing token: {0}", sessionToken);
   3.105 -                await Program.HarmonyClient.TryOpenAsync(sessionToken);
   3.106 +                Trace.WriteLine("Harmony: Reusing token: {0}", authToken);
   3.107 +                await Program.HarmonyClient.TryOpenAsync(authToken);
   3.108              }
   3.109  
   3.110              if (!Program.HarmonyClient.IsReady)
   3.111              {
   3.112                  //We failed to connect using our token
   3.113                  //Delete it then
   3.114 -                File.Delete("SessionToken");
   3.115 +                Properties.Settings.Default.LogitechAuthToken = "";
   3.116 +                Properties.Settings.Default.Save();
   3.117  
   3.118                  //Then try connect using our password
   3.119                  if (string.IsNullOrEmpty(iTextBoxLogitechPassword.Text))
   3.120 @@ -3108,14 +3104,17 @@
   3.121  
   3.122                  Trace.WriteLine("Harmony: Authenticating with Logitech servers...");
   3.123                  await Program.HarmonyClient.TryOpenAsync(iTextBoxLogitechUserName.Text, iTextBoxLogitechPassword.Text);
   3.124 -                File.WriteAllText("SessionToken", Program.HarmonyClient.Token);
   3.125 +                //Persist our authentication token in our setting
   3.126 +                Properties.Settings.Default.LogitechAuthToken = Program.HarmonyClient.Token;
   3.127 +                Properties.Settings.Default.Save();
   3.128              }
   3.129  
   3.130              //Fetch our config
   3.131              Program.HarmonyConfig = await Program.HarmonyClient.GetConfigAsync();
   3.132              PopulateTreeViewHarmony(Program.HarmonyConfig);
   3.133 +
   3.134              //Make sure harmony command actions are showing device name instead of device id
   3.135 -            PopulateTreeViewEvents();
   3.136 +            PopulateTreeViewEvents(CurrentEarObject());
   3.137          }
   3.138  
   3.139          /// <summary>
     4.1 --- a/Server/Properties/Settings.Designer.cs	Wed Aug 31 20:20:32 2016 +0200
     4.2 +++ b/Server/Properties/Settings.Designer.cs	Wed Aug 31 23:59:00 2016 +0200
     4.3 @@ -176,5 +176,17 @@
     4.4                  this["LogitechUserName"] = value;
     4.5              }
     4.6          }
     4.7 +        
     4.8 +        [global::System.Configuration.UserScopedSettingAttribute()]
     4.9 +        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    4.10 +        [global::System.Configuration.DefaultSettingValueAttribute("")]
    4.11 +        public string LogitechAuthToken {
    4.12 +            get {
    4.13 +                return ((string)(this["LogitechAuthToken"]));
    4.14 +            }
    4.15 +            set {
    4.16 +                this["LogitechAuthToken"] = value;
    4.17 +            }
    4.18 +        }
    4.19      }
    4.20  }
     5.1 --- a/Server/Properties/Settings.settings	Wed Aug 31 20:20:32 2016 +0200
     5.2 +++ b/Server/Properties/Settings.settings	Wed Aug 31 23:59:00 2016 +0200
     5.3 @@ -41,5 +41,8 @@
     5.4      <Setting Name="LogitechUserName" Type="System.String" Scope="User">
     5.5        <Value Profile="(Default)" />
     5.6      </Setting>
     5.7 +    <Setting Name="LogitechAuthToken" Type="System.String" Scope="User">
     5.8 +      <Value Profile="(Default)" />
     5.9 +    </Setting>
    5.10    </Settings>
    5.11  </SettingsFile>
    5.12 \ No newline at end of file
     6.1 --- a/Server/SharpDisplayManager.csproj	Wed Aug 31 20:20:32 2016 +0200
     6.2 +++ b/Server/SharpDisplayManager.csproj	Wed Aug 31 23:59:00 2016 +0200
     6.3 @@ -34,7 +34,7 @@
     6.4      <WebPage>index.htm</WebPage>
     6.5      <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
     6.6      <ApplicationRevision>0</ApplicationRevision>
     6.7 -    <ApplicationVersion>1.2.1.0</ApplicationVersion>
     6.8 +    <ApplicationVersion>1.3.1.0</ApplicationVersion>
     6.9      <UseApplicationTrust>false</UseApplicationTrust>
    6.10      <CreateDesktopShortcut>true</CreateDesktopShortcut>
    6.11      <PublishWizardCompleted>true</PublishWizardCompleted>
     7.1 --- a/SharpLibEar/Action.cs	Wed Aug 31 20:20:32 2016 +0200
     7.2 +++ b/SharpLibEar/Action.cs	Wed Aug 31 23:59:00 2016 +0200
     7.3 @@ -12,7 +12,7 @@
     7.4  namespace SharpLib.Ear
     7.5  {
     7.6      [DataContract]
     7.7 -    [AttributeObject(Id = "Action", Name = "Action", Description = "An empty action.")]
     7.8 +    [AttributeObject(Id = "Action", Name = "Action Group", Description = "Use it to group other actions together.")]
     7.9      public class Action: Object
    7.10      {
    7.11          [DataMember]
    7.12 @@ -36,6 +36,20 @@
    7.13              get { return Iterations > 0; }
    7.14          }
    7.15  
    7.16 +
    7.17 +        public override bool IsValid()
    7.18 +        {            
    7.19 +            // We don't want to override this behaviour for derived classes
    7.20 +            if (GetType() == typeof(Action))
    7.21 +            {
    7.22 +                // Avoid having empty actions with no name
    7.23 +                return !string.IsNullOrEmpty(Name);
    7.24 +            }
    7.25 +
    7.26 +            return base.IsValid();
    7.27 +        }
    7.28 +
    7.29 +
    7.30          /// <summary>
    7.31          /// Basic action just does nothing
    7.32          /// </summary>
    7.33 @@ -93,7 +107,7 @@
    7.34          /// <returns></returns>
    7.35          public virtual string BriefBase()
    7.36          {
    7.37 -            return Name;
    7.38 +            return string.IsNullOrEmpty(Name)? AttributeName : Name;
    7.39          }
    7.40  
    7.41          /// <summary>
     8.1 --- a/SharpLibEar/ActionSleep.cs	Wed Aug 31 20:20:32 2016 +0200
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,55 +0,0 @@
     8.4 -//
     8.5 -
     8.6 -
     8.7 -using System.Runtime.Serialization;
     8.8 -using System.Threading;
     8.9 -using System.Threading.Tasks;
    8.10 -
    8.11 -namespace SharpLib.Ear
    8.12 -{
    8.13 -    
    8.14 -
    8.15 -    [DataContract]
    8.16 -    [AttributeObject(Id = "Thread.Sleep", Name = "Sleep", Description = "Have the current thread sleep for the specified amount of milliseconds.")]
    8.17 -    public class ActionSleep : Action
    8.18 -    {
    8.19 -        [DataMember]
    8.20 -        [AttributeObjectProperty
    8.21 -            (
    8.22 -                Id = "Thread.Sleep.Timeout",
    8.23 -                Name = "Timeout (ms)",
    8.24 -                Description = "Specifies the number of milliseconds this action will sleep for.",
    8.25 -                Minimum = "0",
    8.26 -                Maximum = "60000",
    8.27 -                Increment =  "1000"
    8.28 -            )
    8.29 -        ]
    8.30 -        public int TimeoutInMilliseconds { get; set; }
    8.31 -
    8.32 -        public ActionSleep()
    8.33 -        {
    8.34 -            TimeoutInMilliseconds = 1000;
    8.35 -        }
    8.36 -
    8.37 -
    8.38 -        public ActionSleep(int aMillisecondsTimeout)
    8.39 -        {
    8.40 -            TimeoutInMilliseconds = aMillisecondsTimeout;
    8.41 -        }
    8.42 -
    8.43 -        public override string BriefBase()
    8.44 -        {
    8.45 -            return AttributeName + " for " + TimeoutInMilliseconds + " ms";
    8.46 -        }
    8.47 -
    8.48 -
    8.49 -        protected override async Task DoExecute()
    8.50 -        {
    8.51 -            await Task.Delay(TimeoutInMilliseconds);
    8.52 -        }
    8.53 -
    8.54 -    }
    8.55 -
    8.56 -
    8.57 -
    8.58 -}
    8.59 \ No newline at end of file
     9.1 --- a/SharpLibEar/SharpLibEar.csproj	Wed Aug 31 20:20:32 2016 +0200
     9.2 +++ b/SharpLibEar/SharpLibEar.csproj	Wed Aug 31 23:59:00 2016 +0200
     9.3 @@ -68,7 +68,6 @@
     9.4      <Compile Include="ActionDelay.cs" />
     9.5      <Compile Include="ActionLaunchApp.cs" />
     9.6      <Compile Include="ActionOpticalDriveEject.cs" />
     9.7 -    <Compile Include="ActionSleep.cs" />
     9.8      <Compile Include="ActionType.cs" />
     9.9      <Compile Include="AttributeObject.cs" />
    9.10      <Compile Include="AttributeObjectProperty.cs" />