static void Main(string[] args) { string path = Path.GetTempPath(); BinaryFileConverter binConv = new BinaryFileConverter(); XmlFileConverter xmlConv = new XmlFileConverter(); Console.WriteLine("Application will create XML files, read and modify them and convert to BIN files. The same operations will be done with BIN files."); Console.WriteLine("Press Enter to start."); Console.ReadLine(); Console.WriteLine("Generates files dictionary where key is path and value is instance of file model."); Dictionary <string, XmlCarsFile> files = GenerateXMLFilesDictionary(3); Console.WriteLine("3 files in dictionary: {0}", String.Join(Environment.NewLine, files.Keys.ToArray())); Console.WriteLine("Saves files on disk"); xmlConv.Save(files); Console.WriteLine("Reads saved files"); IDictionary <string, XmlCarsFile> xmlFiles = xmlConv.Read(files.Keys.ToArray()); Console.WriteLine("Gets and modifies file_0"); XmlCarsFile file_0 = xmlFiles[Path.Combine(path, String.Format("{0}.cxml", 0))]; file_0.Cars["Mazda"].Price = 22000; file_0.Cars["Mazda"].Date = DateTime.Now.AddMonths(1); file_0.Cars.Remove("Alpha Romeo Brera"); Console.WriteLine("Saves modified file"); xmlConv.Save(xmlFiles); Console.WriteLine("Reads and modifies file_1"); xmlFiles = xmlConv.Read(files.Keys.ToArray()); XmlCarsFile file_1 = xmlFiles[Path.Combine(path, String.Format("{0}.cxml", 1))]; file_1.Cars.Add(new XmlCar { Date = DateTime.Now.AddDays(1), BrandName = "BMW", Price = 40000 }); file_1.Cars.Add(new XmlCar { Date = DateTime.Now.AddMonths(2), BrandName = "ZAZ", Price = 300 }); file_1.Cars.Add(new XmlCar { Date = DateTime.Now.AddMonths(-3), BrandName = "WRANGLER", Price = 60000 }); Console.WriteLine("Saves modified file"); xmlConv.Save(xmlFiles); Console.WriteLine("Reads XML files and converts them to BIN files"); xmlFiles = xmlConv.Read(files.Keys.ToArray()); IDictionary <string, BinaryCarsFile> binaryFiles = xmlConv.Convert <BinaryCarsFile>(xmlFiles); try { Console.WriteLine("Attempt to save BIN files."); binConv.Save(binaryFiles); } catch (AggregateException ex) { Console.WriteLine("each file saving task throws ModifyFileException exception which could contain several validation exceptions"); HandleAggregateException(ex); Console.WriteLine("fix validation errors"); foreach (var pathFile in binaryFiles) { foreach (var car in pathFile.Value.Cars) { car.BrandName = car.BrandName.Substring(0, 2); } } } Console.WriteLine("Saves BIN files"); binConv.Save(binaryFiles); Console.WriteLine("Reads and modifies BIN files"); binaryFiles = binConv.Read(binaryFiles.Keys.ToArray()); BinaryCarsFile file_2 = binaryFiles[Path.Combine(path, String.Format("{0}.cbin", 2))]; file_2.Cars[0].Price = 21000; file_2.Cars[0].Date.AddMonths(13); file_2.Cars.RemoveAt(1); Console.WriteLine("Saves modified BIN files"); binConv.Save(binaryFiles); binaryFiles = binConv.Read(binaryFiles.Keys.ToArray()); if (AskForRemove() == ConsoleKey.Y) { xmlConv.Delete(xmlFiles.Keys.ToArray()); binConv.Delete(binaryFiles.Keys.ToArray()); } }
private void PerformStartupEvents() { if (!TabsterEnvironment.SafeMode) { UpdateSplash("Initializing plugins..."); Logging.GetLogger().Info("Loading plugins..."); Program.GetPluginManager().LoadPlugins(); var disabledGuids = new List <Guid>(); foreach (var guid in Settings.Default.DisabledPlugins) { disabledGuids.Add(new Guid(guid)); } foreach (var pluginHost in Program.GetPluginManager().GetPluginHosts().Where(pluginHost => !disabledGuids.Contains(pluginHost.Plugin.Guid))) { pluginHost.Enabled = true; } CachePluginResources(); } // database file deleted or possible pre-2.0 version, convert existing files if (_databaseHelper.DatabaseCreated) { Logging.GetLogger().Info("Converting old file types..."); UpdateSplash("Converting old file types..."); XmlFileConverter.ConvertXmlFiles(_playlistManager, _libraryManager); } Logging.GetLogger().Info("Initializing library..."); UpdateSplash("Loading library..."); _libraryManager.Load(_databaseHelper.DatabaseCreated); Logging.GetLogger().Info("Initializing playlists..."); UpdateSplash("Loading playlists..."); _playlistManager.Load(); foreach (var playlist in _playlistManager.GetPlaylists()) { AddPlaylistNode(playlist); } PopulatePlaylistMenu(); Logging.GetLogger().Info("Preparing search functions..."); UpdateSplash("Preparing search functions..."); InitializeSearchControls(true); BuildSearchSuggestions(); Logging.GetLogger().Info("Loading user environment..."); UpdateSplash("Loading user environment..."); _recentFilesManager.Load(); LoadRecentItems(); LoadSettings(true); PopulateTabTypeControls(); UpdateCheck.Completed += updateQuery_Completed; if (Settings.Default.StartupUpdate) { UpdateSplash("Checking for updates..."); UpdateCheck.Check(true); } if (_queuedUpdateResponse != null) { OnUpdateResponse(_queuedUpdateResponse); } if (_queuedTablatureFile != null) { PopoutTab(_queuedTablatureFile, _queuedFileInfo); } }