Exemplo n.º 1
0
        public void LoadFolder(string folder)
        {
            TripCollection.Clear();

            _folder = folder;
            DirectoryInfo dir = new DirectoryInfo(folder);

            DateTime currentDate = DateTime.MinValue;

            Trip trip = null;

            if (!Directory.Exists(folder))
            {
                return;
            }

            foreach (var file in dir.GetFiles("*.mp4"))
            {
                string fileName          = Path.GetFileNameWithoutExtension(file.FullName);
                var    fileStartDateTime = DateTime.ParseExact(fileName.Substring(0, fileName.LastIndexOf("_")), "yyyy_MMdd_HHmmss", null);

                if (currentDate.Date != fileStartDateTime.Date)
                {
                    if (trip != null)
                    {
                        TripCollection.Add(trip);
                    }
                    trip = new Trip();
                }
                else if (fileStartDateTime.Subtract(currentDate) > TimeSpan.FromMinutes(10))
                {
                    TripCollection.Add(trip);
                    trip = new Trip();
                }
                currentDate = fileStartDateTime;

                string jpg = Utils.GetFileNameWithoutExt(file.FullName) + ".jpg";

                if (!File.Exists(jpg))
                {
                    try
                    {
                        VideoFileReader reader = new VideoFileReader();
                        reader.Open(file.FullName);
                        Bitmap frame = reader.ReadVideoFrame();
                        reader.Close();

                        frame.Save(jpg, ImageFormat.Jpeg);
                    }
                    catch (Exception ex)
                    {
                    }
                }

                if (trip.StartDateTime > currentDate)
                {
                    trip.StartDateTime = currentDate;
                }
                if (trip.EndDateTime < currentDate)
                {
                    trip.EndDateTime = currentDate;
                }

                Video video = new Video()
                {
                    FilePath = folder + file.Name, Date = fileStartDateTime, ThumbnailPath = jpg
                };

                trip.Videos.Add(video);
            }

            if (trip != null)
            {
                TripCollection.Add(trip);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// A method called by the UI to start generating the paths
 /// </summary>
 public void StartGeneration()
 {
     TripCollection.Clear();
     Task.Run(() => { CSolver.GetShortestPath(); });
 }