Example #1
0
        public void LoadDatabase(string file)
        {
            Console.Write("Loading database from file");

            var serializer = new XmlSerializer(typeof(SearchDatabase));

            var fs = new FileStream(file, FileMode.Open);
            XmlReader reader = new XmlTextReader(fs);

            _db = (SearchDatabase)serializer.Deserialize(reader);

            Console.WriteLine("... done");
        }
Example #2
0
        public void RebuildDatabase(string fileLocation)
        {
            string[] images = new[]
                                  {
                                      Directory.GetFiles(fileLocation, "*.jpg"),
                                      Directory.GetFiles(fileLocation, "*.png")
                                  }.SelectMany(x => x).ToArray();

            int i = 0;
            int total = images.Length;

            var entities = images
                    .AsParallel()
                    .Select(f =>
                                {

                                    var s = new SearchEntity(f, new Bitmap(f).GetHistograms());

                                    var current = Interlocked.Increment(ref i);
                                    Console.Write("\rRebuilding database: {0}%   ", (i / (double)total * 100).ToString("N1"));

                                    return s;
                                })
                    .ToArray();

            _db = new SearchDatabase {Images = entities, BasePath = fileLocation};

            Console.WriteLine("");
        }