From 58a27356c273e0a54b0045f5e5c4852f4a56966b Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 1 Jul 2016 17:11:05 -0700 Subject: [PATCH 1/3] Profile Sync --- MatterControlApplication.cs | 2 +- .../Settings/LayeredProfile.cs | 1 + .../Settings/ProfileManager.cs | 24 ++++++++++++------- .../Settings/SettingsProfile.cs | 23 ++++++++++++++++-- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index 2a5cead7d..1a277d930 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -451,7 +451,7 @@ namespace MatterHackers.MatterControl } #if DEBUG - public static string MCWSBaseUri { get; } = "http://localhost.:9206"; + public static string MCWSBaseUri { get; } = "http://192.168.2.129:9206"; #else public static string MCWSBaseUri { get;} = "https://mattercontrol.appspot.com"; #endif diff --git a/SlicerConfiguration/Settings/LayeredProfile.cs b/SlicerConfiguration/Settings/LayeredProfile.cs index 648368646..d4e88a444 100644 --- a/SlicerConfiguration/Settings/LayeredProfile.cs +++ b/SlicerConfiguration/Settings/LayeredProfile.cs @@ -184,6 +184,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration if (printerInfo != null) { printerInfo.SHA1 = sha1; + printerInfo.IsDirty = true; ProfileManager.Instance.Save(); } } diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index eb1204dec..9eb09dc97 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -83,16 +83,16 @@ namespace MatterHackers.MatterControl.SlicerConfiguration // Ensure the profiles directory exists Directory.CreateDirectory(ProfilesPath); - - Instance = new ProfileManager(); - + // Load the profiles.json document if (File.Exists(profilesDBPath)) { Instance = JsonConvert.DeserializeObject(File.ReadAllText(profilesDBPath)); } - else // One time import + else { + Instance = new ProfileManager(); + if (Path.GetFileName(profilesDBPath) == "profiles.json") { // Import classic db based profiles into local json files @@ -100,6 +100,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } } + // In either case, wire up the CollectionChanged event Instance.Profiles.CollectionChanged += Profiles_CollectionChanged; } @@ -148,7 +149,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return empytProfile; } - internal static SettingsProfile LoadProfileFromMCWS(string deviceToken) + public static SettingsProfile LoadProfileFromMCWS(string deviceToken) { WebClient client = new WebClient(); string json = client.DownloadString($"{MatterControlApplication.MCWSBaseUri}/api/1/device/get-profile?PrinterToken={deviceToken}"); @@ -157,7 +158,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return new SettingsProfile(printerSettings); } - internal static SettingsProfile LoadProfile(string profileID) + public static SettingsProfile LoadProfile(string profileID) { //return LoadProfileFromMCWS(profileID); @@ -167,6 +168,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return null; } + if (ActiveSliceSettings.Instance?.ID == profileID) + { + return ActiveSliceSettings.Instance; + } + string profilePath = Path.Combine(ProfilesPath, profileID + ".json"); return File.Exists(profilePath) ? LoadProfileFromDisk(profilePath) : null; } @@ -195,6 +201,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration case ".printer": var profile = ProfileManager.LoadProfileFromDisk(settingsFilePath); profile.ID = printerInfo.ID; + profile.ClearValue("device_token"); + printerInfo.DeviceToken = ""; // TODO: Resolve name conflicts profile.SetName(printerInfo.Name); @@ -216,14 +224,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration // TODO: Resolve name conflicts layeredProfile.UserLayer[SettingsKey.printer_name.ToString()] = printerInfo.Name; + layeredProfile.ClearValue("device_token"); + printerInfo.DeviceToken = ""; Instance.Profiles.Add(printerInfo); layeredProfile.Save(); break; } - - ProfileManager.Instance.Save(); } internal static void AcquireNewProfile(string make, string model, string printerName) diff --git a/SlicerConfiguration/Settings/SettingsProfile.cs b/SlicerConfiguration/Settings/SettingsProfile.cs index 71986fc0e..a0ca346cf 100644 --- a/SlicerConfiguration/Settings/SettingsProfile.cs +++ b/SlicerConfiguration/Settings/SettingsProfile.cs @@ -887,8 +887,27 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public string ComPort { get; set; } public string ID { get; set; } public string Name { get; set; } - public bool MarkedForDelete { get; set; } - public string SHA1 { get; internal set; } + public string DeviceToken { get; set; } + public bool IsDirty { get; set; } = false; + public bool MarkedForDelete { get; set; } = false; + public string SHA1 { get; set; } + + public void ChangeID(string newID) + { + string existingProfile = ProfilePath; + if (File.Exists(existingProfile)) + { + this.ID = newID; + File.Move(existingProfile, ProfilePath); + } + + var profile = ProfileManager.LoadProfile(newID); + + profile.ID = newID; + profile.SetActiveValue("device_token", newID); + profile.SaveChanges(); + ProfileManager.Instance.Save(); + } [JsonIgnore] public string ProfilePath => Path.Combine(ProfileManager.ProfilesPath, ID + ".json"); From ba41f4ebee93aa29426d73fb8e6acfb2584a3be5 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Wed, 6 Jul 2016 15:05:06 -0700 Subject: [PATCH 2/3] Migrate make/model settings keys to SettingsKey, revise service urls --- DataStorage/Classic/ClassicSqlitePrinterProfiles.cs | 4 ++-- MatterControlApplication.cs | 3 ++- SlicerConfiguration/Settings/ActiveSliceSettings.cs | 2 +- SlicerConfiguration/Settings/SettingsProfile.cs | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/DataStorage/Classic/ClassicSqlitePrinterProfiles.cs b/DataStorage/Classic/ClassicSqlitePrinterProfiles.cs index 7f5377f28..89d817430 100644 --- a/DataStorage/Classic/ClassicSqlitePrinterProfiles.cs +++ b/DataStorage/Classic/ClassicSqlitePrinterProfiles.cs @@ -91,8 +91,8 @@ namespace MatterHackers.MatterControl.DataStorage.ClassicDB layeredProfile.ID = printer.Id.ToString(); layeredProfile.UserLayer[SettingsKey.printer_name] = printer.Name ?? ""; - layeredProfile.UserLayer["MatterControl_Make"] = printer.Make ?? ""; - layeredProfile.UserLayer["model"] = printer.Model ?? ""; + layeredProfile.UserLayer[SettingsKey.make] = printer.Make ?? ""; + layeredProfile.UserLayer[SettingsKey.model] = printer.Model ?? ""; layeredProfile.UserLayer["baud_rate"] = printer.BaudRate ?? ""; layeredProfile.UserLayer["com_port"] = printer.ComPort ?? ""; layeredProfile.UserLayer["auto_connect"] = printer.AutoConnect ? "1" : "0"; diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index 1a277d930..89a6cd3fb 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -451,7 +451,8 @@ namespace MatterHackers.MatterControl } #if DEBUG - public static string MCWSBaseUri { get; } = "http://192.168.2.129:9206"; + //public static string MCWSBaseUri { get; } = "http://192.168.2.129:9206"; + public static string MCWSBaseUri { get; } = "https://mattercontrol-test.appspot.com"; #else public static string MCWSBaseUri { get;} = "https://mattercontrol.appspot.com"; #endif diff --git a/SlicerConfiguration/Settings/ActiveSliceSettings.cs b/SlicerConfiguration/Settings/ActiveSliceSettings.cs index fd8e3e199..f6f6fc4f4 100644 --- a/SlicerConfiguration/Settings/ActiveSliceSettings.cs +++ b/SlicerConfiguration/Settings/ActiveSliceSettings.cs @@ -68,7 +68,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration activeInstance = value; if (activeInstance != null) { - BedSettings.SetMakeAndModel(activeInstance.GetValue("MatterControl_Make"), activeInstance.GetValue("model")); + BedSettings.SetMakeAndModel(activeInstance.GetValue(SettingsKey.make), activeInstance.GetValue(SettingsKey.model)); } SwitchToPrinterTheme(MatterControlApplication.IsLoading); diff --git a/SlicerConfiguration/Settings/SettingsProfile.cs b/SlicerConfiguration/Settings/SettingsProfile.cs index a0ca346cf..40f9c6a5a 100644 --- a/SlicerConfiguration/Settings/SettingsProfile.cs +++ b/SlicerConfiguration/Settings/SettingsProfile.cs @@ -66,6 +66,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public const string nozzle_diameter = nameof(nozzle_diameter); public const string print_center = nameof(print_center); public const string printer_name = nameof(printer_name); + public const string make = nameof(make); + public const string model = nameof(model); public const string publish_bed_image = nameof(publish_bed_image); public const string resume_position_before_z_home = nameof(resume_position_before_z_home); public const string z_homes_to_max = nameof(z_homes_to_max); From 35a0c26916e321c9c6c401427021de9057223f76 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Thu, 7 Jul 2016 12:24:42 -0700 Subject: [PATCH 3/3] Fix empty SHA1 field, add to ProfileManager before save --- SlicerConfiguration/Settings/ProfileManager.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index 9eb09dc97..3640f30b0 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -287,14 +287,15 @@ namespace MatterHackers.MatterControl.SlicerConfiguration layeredProfile.QualityLayers.Add(qualityPreset); } - layeredProfile.Save(); - Instance.Profiles.Add(new PrinterInfo { Name = printerName, ID = guid }); + // Update SHA1 + layeredProfile.Save(); + UserSettings.Instance.set("ActiveProfileID", guid); ActiveSliceSettings.Instance = new SettingsProfile(layeredProfile); @@ -308,10 +309,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration "profiles", () => { - string responseText = null; - - responseText = RetrievePublicProfileRequest.DownloadPrinterProfile(deviceToken); - + string responseText = RetrievePublicProfileRequest.DownloadPrinterProfile(deviceToken); return responseText; }); }