Exemplo n.º 1
0
 public DataManagement()
 {
     logger        = new Logger(Constants.logFolderPath, Constants.logFileName);
     fileScanner   = new FileScanner();
     tagDatabase   = new TagDatabase();
     photoDatabase = new PhotoDatabase();
 }
Exemplo n.º 2
0
        // tagList gets filled!
        internal static Photo FromString(string element, TagDatabase tagDB, HashSet <Tag> emptyTagList)
        {
            string[] parts  = element.Split(Constants.splitChar);
            string[] tagIDs = parts[1].Split(Constants.subSplitChar);

            for (int i = 0; i < tagIDs.Length; i++)
            {
                emptyTagList.Add(tagDB.GiveTag(Int32.Parse(tagIDs[i])));
            }

            return(new Photo(parts[0], DateTime.Parse(parts[2]), emptyTagList));
        }
Exemplo n.º 3
0
        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());
            }
        }