Ejemplo n.º 1
0
 private static SettingsProfile LoadProfileFromDisk(string profilePath)
 {
     return(new SettingsProfile(LayeredProfile.LoadFile(profilePath)));
 }
Ejemplo n.º 2
0
        static ActiveSliceSettings()
        {
            // Ensure the profiles directory exists
            Directory.CreateDirectory(profilesPath);

            if (true)
            {
                ProfileData = new ProfileData();

                if (!File.Exists(profilesDBPath))
                {
                    // Import class profiles from the db into local json files
                    DataStorage.ClassicDB.ClassicSqlitePrinterProfiles.ImportPrinters(ProfileData, profilesPath);
                    File.WriteAllText(profilesDBPath, JsonConvert.SerializeObject(ProfileData, Formatting.Indented));

                    // TODO: Upload new profiles to webservice
                }

                ProfileData.Profiles.CollectionChanged += Profiles_CollectionChanged;

                foreach (string filePath in Directory.GetFiles(profilesPath, "*.json"))
                {
                    string fileName = Path.GetFileName(filePath);
                    if (fileName == "config.json" || fileName == "profiles.json")
                    {
                        continue;
                    }

                    try
                    {
                        var profile = new SettingsProfile(LayeredProfile.LoadFile(filePath));
                        ProfileData.Profiles.Add(new PrinterInfo()
                        {
                            AutoConnect = profile.DoAutoConnect(),
                            BaudRate    = profile.BaudRate(),
                            ComPort     = profile.ComPort(),
                            DriverType  = profile.DriverType(),
                            Id          = profile.ID,
                            Make        = profile.Make,
                            Model       = profile.Model,
                            Name        = profile.Name(),
                        });
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("Error loading profile: {1}\r\n{2}", filePath, ex.Message);
                    }
                }
            }
            else
            {
                // Load or import the profiles.json document
                if (File.Exists(profilesDBPath))
                {
                    ProfileData = JsonConvert.DeserializeObject <ProfileData>(File.ReadAllText(profilesDBPath));
                }
                else
                {
                    ProfileData = new ProfileData();

                    // Import class profiles from the db into local json files
                    DataStorage.ClassicDB.ClassicSqlitePrinterProfiles.ImportPrinters(ProfileData, profilesPath);
                    File.WriteAllText(profilesDBPath, JsonConvert.SerializeObject(ProfileData, Formatting.Indented));

                    // TODO: Upload new profiles to webservice
                }
            }

            ActiveSliceSettings.LoadStartupProfile();
        }