//public void Update() //{ // Stopwatch sp = new Stopwatch(); // sp.Start(); // Library.Clear(); // //foreach (var l in this.DefaultLibraries) // //{ // // this.Library.Append(l); // //} // //foreach (var l in this.UserLibraries) // //{ // // this.Library.Append(l); // //} // sp.Stop(); // Debug.WriteLine("Update library: " + sp.ElapsedMilliseconds + "ms"); //} public string ImportUserLibraryCSV(string Directory) { string name = Path.GetFileName(Directory); CSLibrary importedLib = null; try { importedLib = CSV.CSVImportExport.ImportLibrary(Directory); } catch { } if (importedLib != null) { try { importedLib.Name = name; importedLib.IsLocked = true; importedLib.IsDefault = true; importedLib.applyLibName(name); importedLib.applyLock(false); importedLib.applyIsDefault(false); this.Library.Merge(importedLib); this.UserLibraries.Add(importedLib); return("Library merged from " + Directory); } catch { return("Library could not be imported"); } } else { return("Library could not be imported"); } }
public void LoadLibrariesFromDirectories() { Debug.WriteLine("LoadLibrariesFromDirectories"); //------ // DEFAULT LOCATION //------ if (Directory.Exists(DefaultFilesAndDirectories.defaultLibPath)) { //Binary Library Files var libFiles = Directory.GetFiles(DefaultFilesAndDirectories.defaultLibPath, "*.csl"); foreach (var p in libFiles) { Stopwatch sp = new Stopwatch(); sp.Start(); string name = Path.GetFileName(p).Replace(".csl", ""); CSLibrary importedLib = null; using (FileStream fileStream = File.OpenRead(p)) { importedLib = Serializer.Deserialize <CSLibrary>(fileStream); } importedLib.Name = name; importedLib.IsLocked = true; importedLib.IsDefault = true; importedLib.applyLibName(name); importedLib.applyLock(true); importedLib.applyIsDefault(true); this.DefaultLibraries.Add(importedLib); this.Library.Append(importedLib); sp.Stop(); Debug.WriteLine("Loading binary " + p + " - " + sp.ElapsedMilliseconds + "ms"); } } //------ // USER LOCATION //------ if (Directory.Exists(DefaultFilesAndDirectories.userLibPath)) { //Binary Library Files var libFiles = Directory.GetFiles(DefaultFilesAndDirectories.userLibPath, "*.csl"); foreach (var p in libFiles) { Stopwatch sp = new Stopwatch(); sp.Start(); string name = Path.GetFileName(p).Replace(".csl", ""); CSLibrary importedLib = null; using (FileStream fileStream = File.OpenRead(p)) { importedLib = Serializer.Deserialize <CSLibrary>(fileStream); } importedLib.Name = name; importedLib.IsLocked = true; importedLib.IsDefault = false; importedLib.applyLibName(name); importedLib.applyLock(true); importedLib.applyIsDefault(false); this.UserLibraries.Add(importedLib); this.Library.Append(importedLib); sp.Stop(); Debug.WriteLine("Loading binary " + p + " - " + sp.ElapsedMilliseconds + "ms"); } } }