public void BuildFromDirectory(string Directory) { // Get list of files string[] Files = System.IO.Directory.GetFiles(Directory).OrderBy(x => x).ToArray(); List <TeslaCamFile> CurrentTeslaCams = new List <TeslaCamFile>(); foreach (var File in Files) { try { TeslaCamFile f = new TeslaCamFile(File); CurrentTeslaCams.Add(f); } catch { } } List <string> DistinctEvents = CurrentTeslaCams.Select(e => e.Date.UTCDateString).Distinct().ToList(); foreach (var CurrentEvent in DistinctEvents) { List <TeslaCamFile> MatchedFiles = CurrentTeslaCams.Where(e => e.Date.UTCDateString == CurrentEvent).ToList(); TeslaCamFileSet CurrentFileSet = new TeslaCamFileSet(); CurrentFileSet.SetCollection(MatchedFiles); this.Recordings.Add(CurrentFileSet); } this.Recordings = Recordings.OrderBy(e => e.Date.UTCDateString).ToList(); this.StartDate = Recordings.First().Date; this.EndDate = Recordings.Last().Date; }
public bool BuildFromDirectory(string Directory) { // Get list of raw files string[] Files = System.IO.Directory.GetFiles(Directory, "*.mp4").OrderBy(x => x).ToArray(); // Make sure there's at least one valid file if (Files.Length < 1) { return(false); } // Create a list of cam files List <TeslaCamFile> CurrentTeslaCams = new List <TeslaCamFile>(Files.Length); // Convert raw file to cam file foreach (var File in Files) { TeslaCamFile f = TeslaCamFile.TryParse(File); if (f != null) { CurrentTeslaCams.Add(f); } } if (CurrentTeslaCams.Count == 0) { return(false); } // Now get list of only distinct events List <string> DistinctEvents = CurrentTeslaCams.Select(e => e.Date.UTCDateString).Distinct().ToList(); // Find the files that match the distinct event foreach (var CurrentEvent in DistinctEvents) { List <TeslaCamFile> MatchedFiles = CurrentTeslaCams.Where(e => e.Date.UTCDateString == CurrentEvent).ToList(); TeslaCamFileSet CurrentFileSet = new TeslaCamFileSet(); CurrentFileSet.SetCollection(MatchedFiles); this.Recordings.Add(CurrentFileSet); } // Set metadata this.Recordings = Recordings.OrderBy(e => e.Date.UTCDateString).ToList(); this.StartDate = Recordings.First().Date; this.EndDate = Recordings.Last().Date; // Success return(true); }
public bool BuildFromDirectory(string directory) { // Get list of raw files var files = System.IO.Directory.GetFiles(directory, "*.mp4").OrderBy(x => x).ToArray(); // Make sure there's at least one valid file if (files.Length < 1) { return(false); } // Create a list of cam files var currentTeslaCams = new List <TeslaCamFile>(files.Length); // Convert raw file to cam file foreach (var file in files) { var teslaCamFile = new TeslaCamFile(file); currentTeslaCams.Add(teslaCamFile); } // Now get list of only distinct events var distinctEvents = currentTeslaCams.Select(e => e.Date.UTCDateString).Distinct().ToList(); // Find the files that match the distinct event foreach (var currentEvent in distinctEvents) { var matchedFiles = currentTeslaCams.Where(e => e.Date.UTCDateString == currentEvent).ToList(); var currentFileSet = new TeslaCamFileSet(); currentFileSet.SetCollection(matchedFiles); Recordings.Add(currentFileSet); } // Set metadata Recordings = Recordings.OrderBy(e => e.Date.UTCDateString).ToList(); StartDate = Recordings.First().Date; EndDate = Recordings.Last().Date; // Success return(true); }
public static TeslaCamFile TryParse(string filePath) { TeslaCamFile file = new TeslaCamFile { FilePath = filePath }; var m = FileNameRegex.Match(file.FileName); if (!m.Success) { return(null); } file.Date = new TeslaCamDate(m.Groups["date"].Value); string cameraType = m.Groups["camera"].Value; if (cameraType == "front") { file.CameraLocation = CameraType.FRONT; } else if (cameraType == "left_repeater") { file.CameraLocation = CameraType.LEFT_REPEATER; } else if (cameraType == "right_repeater") { file.CameraLocation = CameraType.RIGHT_REPEATER; } else if (cameraType == "back") { file.CameraLocation = CameraType.BACK; } else { return(null); } return(file); }