Merge pull request #1047 from jlewin/master

Profile Sync
This commit is contained in:
johnlewin 2016-07-07 13:01:27 -07:00 committed by GitHub
commit 4fe235beca
6 changed files with 49 additions and 20 deletions

View file

@ -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";

View file

@ -451,7 +451,8 @@ namespace MatterHackers.MatterControl
}
#if DEBUG
public static string MCWSBaseUri { get; } = "http://localhost.: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

View file

@ -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);

View file

@ -184,6 +184,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (printerInfo != null)
{
printerInfo.SHA1 = sha1;
printerInfo.IsDirty = true;
ProfileManager.Instance.Save();
}
}

View file

@ -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<ProfileManager>(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)
@ -279,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);
@ -300,10 +309,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
"profiles",
() =>
{
string responseText = null;
responseText = RetrievePublicProfileRequest.DownloadPrinterProfile(deviceToken);
string responseText = RetrievePublicProfileRequest.DownloadPrinterProfile(deviceToken);
return responseText;
});
}

View file

@ -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);
@ -887,8 +889,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");