# HG changeset patch # User StephaneLenclud # Date 1472680740 -7200 # Node ID b11d7ebbdc7f6356af97329e5df56b23402018f8 # Parent 82e87f4956eadd5d3e1cc1a7e63b8d55fae08541 Published v1.3.1.0. Harmony Auth Token now persisted in settings. Various EAR view fixes. Removed Sleep action diff -r 82e87f4956ea -r b11d7ebbdc7f Server/App.config --- a/Server/App.config Wed Aug 31 20:20:32 2016 +0200 +++ b/Server/App.config Wed Aug 31 23:59:00 2016 +0200 @@ -43,6 +43,9 @@ + + + diff -r 82e87f4956ea -r b11d7ebbdc7f Server/FormEditObject.cs --- a/Server/FormEditObject.cs Wed Aug 31 20:20:32 2016 +0200 +++ b/Server/FormEditObject.cs Wed Aug 31 23:59:00 2016 +0200 @@ -111,14 +111,18 @@ //Create another type of action only if needed if (Object == null || Object.GetType() != objectType) { + string name = ""; if (Object != null) { // Make sure we exit edit mode and unhook from events Object.CurrentState = SharpLib.Ear.Object.State.Rest; Object.PropertyChanged -= PropertyChangedEventHandlerThreadSafe; + name = Object.Name; Object = null; } Object = (T)Activator.CreateInstance(objectType); + //Keep the name when changing the type + Object.Name = name; } //Create input fields diff -r 82e87f4956ea -r b11d7ebbdc7f Server/FormMain.cs --- a/Server/FormMain.cs Wed Aug 31 20:20:32 2016 +0200 +++ b/Server/FormMain.cs Wed Aug 31 23:59:00 2016 +0200 @@ -371,13 +371,8 @@ /// /// Populate tree view with events and actions /// - private void PopulateTreeViewEvents() + private void PopulateTreeViewEvents(Ear.Object aSelectedObject=null) { - //Disable action buttons - buttonActionAdd.Enabled = false; - buttonActionDelete.Enabled = false; - - //Reset our tree iTreeViewEvents.Nodes.Clear(); //Populate registered events @@ -417,6 +412,12 @@ iTreeViewEvents.ExpandAll(); + if (aSelectedObject != null) + { + SelectEarObject(aSelectedObject); + } + + // Just to be safe in case the selection did not work UpdateEventView(); } @@ -2782,8 +2783,8 @@ { parent.Objects.Add(ea.Object); Properties.Settings.Default.Save(); - PopulateTreeViewEvents(); - SelectEarObject(ea.Object); + // We want to select the parent so that one can easily add another action to the same collection + PopulateTreeViewEvents(parent); } } @@ -2816,8 +2817,7 @@ parent.Objects[actionIndex]=ea.Object; //Save and rebuild our event tree view Properties.Settings.Default.Save(); - PopulateTreeViewEvents(); - SelectEarObject(ea.Object); + PopulateTreeViewEvents(ea.Object); } } @@ -2880,9 +2880,7 @@ //Save and populate our tree again Properties.Settings.Default.Save(); - PopulateTreeViewEvents(); - SelectEarObject(a); - + PopulateTreeViewEvents(a); } /// @@ -2910,8 +2908,7 @@ //Save and populate our tree again Properties.Settings.Default.Save(); - PopulateTreeViewEvents(); - SelectEarObject(a); + PopulateTreeViewEvents(a); } @@ -2986,8 +2983,7 @@ { Properties.Settings.Default.EarManager.Events.Add(ea.Object); Properties.Settings.Default.Save(); - PopulateTreeViewEvents(); - SelectEarObject(ea.Object); + PopulateTreeViewEvents(ea.Object); } } @@ -3037,8 +3033,7 @@ Properties.Settings.Default.EarManager.Events[index] = ea.Object; //Save and rebuild our event tree view Properties.Settings.Default.Save(); - PopulateTreeViewEvents(); - SelectEarObject(ea.Object); + PopulateTreeViewEvents(ea.Object); } } @@ -3085,19 +3080,20 @@ //Tip: Set keep-alive to false when testing reconnection process Program.HarmonyClient = new HarmonyHub.Client(iTextBoxHarmonyHubAddress.Text, true); Program.HarmonyClient.OnConnectionClosedByServer += HarmonyConnectionClosedByServer; - - if (File.Exists("SessionToken") && !aForceAuth) + + string authToken = Properties.Settings.Default.LogitechAuthToken; + if (!string.IsNullOrEmpty(authToken) && !aForceAuth) { - var sessionToken = File.ReadAllText("SessionToken"); - Trace.WriteLine("Harmony: Reusing token: {0}", sessionToken); - await Program.HarmonyClient.TryOpenAsync(sessionToken); + Trace.WriteLine("Harmony: Reusing token: {0}", authToken); + await Program.HarmonyClient.TryOpenAsync(authToken); } if (!Program.HarmonyClient.IsReady) { //We failed to connect using our token //Delete it then - File.Delete("SessionToken"); + Properties.Settings.Default.LogitechAuthToken = ""; + Properties.Settings.Default.Save(); //Then try connect using our password if (string.IsNullOrEmpty(iTextBoxLogitechPassword.Text)) @@ -3108,14 +3104,17 @@ Trace.WriteLine("Harmony: Authenticating with Logitech servers..."); await Program.HarmonyClient.TryOpenAsync(iTextBoxLogitechUserName.Text, iTextBoxLogitechPassword.Text); - File.WriteAllText("SessionToken", Program.HarmonyClient.Token); + //Persist our authentication token in our setting + Properties.Settings.Default.LogitechAuthToken = Program.HarmonyClient.Token; + Properties.Settings.Default.Save(); } //Fetch our config Program.HarmonyConfig = await Program.HarmonyClient.GetConfigAsync(); PopulateTreeViewHarmony(Program.HarmonyConfig); + //Make sure harmony command actions are showing device name instead of device id - PopulateTreeViewEvents(); + PopulateTreeViewEvents(CurrentEarObject()); } /// diff -r 82e87f4956ea -r b11d7ebbdc7f Server/Properties/Settings.Designer.cs --- a/Server/Properties/Settings.Designer.cs Wed Aug 31 20:20:32 2016 +0200 +++ b/Server/Properties/Settings.Designer.cs Wed Aug 31 23:59:00 2016 +0200 @@ -176,5 +176,17 @@ this["LogitechUserName"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string LogitechAuthToken { + get { + return ((string)(this["LogitechAuthToken"])); + } + set { + this["LogitechAuthToken"] = value; + } + } } } diff -r 82e87f4956ea -r b11d7ebbdc7f Server/Properties/Settings.settings --- a/Server/Properties/Settings.settings Wed Aug 31 20:20:32 2016 +0200 +++ b/Server/Properties/Settings.settings Wed Aug 31 23:59:00 2016 +0200 @@ -41,5 +41,8 @@ + + + \ No newline at end of file diff -r 82e87f4956ea -r b11d7ebbdc7f Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Wed Aug 31 20:20:32 2016 +0200 +++ b/Server/SharpDisplayManager.csproj Wed Aug 31 23:59:00 2016 +0200 @@ -34,7 +34,7 @@ index.htm false 0 - 1.2.1.0 + 1.3.1.0 false true true diff -r 82e87f4956ea -r b11d7ebbdc7f SharpLibEar/Action.cs --- a/SharpLibEar/Action.cs Wed Aug 31 20:20:32 2016 +0200 +++ b/SharpLibEar/Action.cs Wed Aug 31 23:59:00 2016 +0200 @@ -12,7 +12,7 @@ namespace SharpLib.Ear { [DataContract] - [AttributeObject(Id = "Action", Name = "Action", Description = "An empty action.")] + [AttributeObject(Id = "Action", Name = "Action Group", Description = "Use it to group other actions together.")] public class Action: Object { [DataMember] @@ -36,6 +36,20 @@ get { return Iterations > 0; } } + + public override bool IsValid() + { + // We don't want to override this behaviour for derived classes + if (GetType() == typeof(Action)) + { + // Avoid having empty actions with no name + return !string.IsNullOrEmpty(Name); + } + + return base.IsValid(); + } + + /// /// Basic action just does nothing /// @@ -93,7 +107,7 @@ /// public virtual string BriefBase() { - return Name; + return string.IsNullOrEmpty(Name)? AttributeName : Name; } /// diff -r 82e87f4956ea -r b11d7ebbdc7f SharpLibEar/ActionSleep.cs --- a/SharpLibEar/ActionSleep.cs Wed Aug 31 20:20:32 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -// - - -using System.Runtime.Serialization; -using System.Threading; -using System.Threading.Tasks; - -namespace SharpLib.Ear -{ - - - [DataContract] - [AttributeObject(Id = "Thread.Sleep", Name = "Sleep", Description = "Have the current thread sleep for the specified amount of milliseconds.")] - public class ActionSleep : Action - { - [DataMember] - [AttributeObjectProperty - ( - Id = "Thread.Sleep.Timeout", - Name = "Timeout (ms)", - Description = "Specifies the number of milliseconds this action will sleep for.", - Minimum = "0", - Maximum = "60000", - Increment = "1000" - ) - ] - public int TimeoutInMilliseconds { get; set; } - - public ActionSleep() - { - TimeoutInMilliseconds = 1000; - } - - - public ActionSleep(int aMillisecondsTimeout) - { - TimeoutInMilliseconds = aMillisecondsTimeout; - } - - public override string BriefBase() - { - return AttributeName + " for " + TimeoutInMilliseconds + " ms"; - } - - - protected override async Task DoExecute() - { - await Task.Delay(TimeoutInMilliseconds); - } - - } - - - -} \ No newline at end of file diff -r 82e87f4956ea -r b11d7ebbdc7f SharpLibEar/SharpLibEar.csproj --- a/SharpLibEar/SharpLibEar.csproj Wed Aug 31 20:20:32 2016 +0200 +++ b/SharpLibEar/SharpLibEar.csproj Wed Aug 31 23:59:00 2016 +0200 @@ -68,7 +68,6 @@ -