public DataManagement() { logger = new Logger(Constants.logFolderPath, Constants.logFileName); fileScanner = new FileScanner(); tagDatabase = new TagDatabase(); photoDatabase = new PhotoDatabase(); }
private void createFromFile(string dbFilePath) { string[] lines; try { lines = File.ReadAllLines(dbFilePath); } catch (Exception e) { logger.log("Was not able to read from db-file '" + dbFilePath + " || " + e.ToString()); return; } int mode = 0; List <Tag> tags = new List <Tag>(10); List <string> scanPaths = new List <string>(10); List <Photo> photos = new List <Photo>(lines.Length); List <HashSet <Tag> > tagsOnPhoto = new List <HashSet <Tag> >(photos.Count); try { string element; for (int i = 0; i < lines.Length; i++) { element = lines[i]; if (element == Constants.lineSeparator) { switch (mode) { case 0: tagDatabase = new TagDatabase(tags); break; case 1: photoDatabase = new PhotoDatabase(photos, tagsOnPhoto); break; case 2: fileScanner = new FileScanner(scanPaths, photos); break; } mode++; continue; } switch (mode) { case 0: tags.Add(Tag.FromString(element)); break; case 1: photos.Add(Photo.FromString(element, tagDatabase, tagsOnPhoto[i])); break; case 2: scanPaths.Add(element); break; } } } catch (Exception e) { logger.log("db-file is corrupted: '" + dbFilePath + " || " + e.ToString()); } }