/// <summary> /// 외부 트랙파일들을 스토리지의 각 위치에 추가한다. /// </summary> public int Import(Vehicle vehicle, IEnumerable<string> files, bool convert, bool overwrite) { int count = files.Count(); ProgressViewModel progView = CreateProgressView(count); progView.Caption = "SD 트랙 파일들을 로컬 저장소로 저장합니다."; DialogService.RunProgress("저장", progView); count = 0; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (sender, e) => { int cnt = 0; foreach (string file in files) { if (ImportTrackFile(vehicle, file, convert, overwrite)) { count++; if (Application.Current != null) { Application.Current.Dispatcher.Invoke((Action)(() => { progView.Value = ++cnt; progView.Message = file; })); } } } }; worker.RunWorkerCompleted += (sender, e) => { }; worker.RunWorkerAsync(); return count; }
/// <summary> /// 기존에 스토리지에 없는 차량이 추가되면 해당 폴더를 생성한다. /// </summary> public void AddVehicle(Vehicle vehicle) { if (!m_catalogs.ContainsKey(vehicle)) { TrackCatalogCollection cats = new TrackCatalogCollection(); cats.Open(vehicle, RootPath); m_catalogs.Add(vehicle, cats); } }
public void Open(Vehicle vehicle, string rootFolder) { m_vehicle = vehicle; m_root = rootFolder; m_catalogs = new ObservableCollection<TrackCatalog>(); Load(); }
public void Add(Vehicle vehicle) { if (vehicle == null) throw new ArgumentNullException("vehicle"); if (IndexOf(vehicle) < 0) { m_vehicles.Add(vehicle); } }
/// <summary> /// 입력 디바이스의 트랙 목록을 읽어들인다. /// 시작/끝 일시를 계산한다. /// </summary> /// <param name="rootPath"></param> public void Open(Vehicle vehicle, string rootPath, Action callback) { m_vehicle = vehicle; m_rootPath = rootPath; TrackList.Clear(); if (Directory.Exists(rootPath)) { LoadTracks(callback); } }
public void OpenTest() { DeviceRepository repo = new DeviceRepository(); Vehicle vehicle = new Vehicle(); string rootPath = PersonalTest.DeviceRoot; repo.Open(vehicle, rootPath, () => { string[] files = Directory.GetFiles(rootPath, "*.inc"); Assert.AreEqual(files.Length, repo.TrackCount); }); }
public void ImportAllTest() { string repoDir = PersonalTest.StorageRoot; string sourceDir = PersonalTest.DeviceRoot; //string sourceDir = @"x:\gfdata"; LocalRepository repo = new LocalRepository(); repo.Open(repoDir, null); Vehicle vehicle = new Vehicle() { VehicleId = "v121212121212" }; TrackImportHelper helper = new TrackImportHelper(repo); helper.ImportAll(vehicle, sourceDir, false, true); }
public void GetFolderTest() { LocalRepository repo = new LocalRepository(); repo.Open(PersonalTest.StorageRoot, null); TrackFolderManager manager = new TrackFolderManager(repo); Vehicle vehicle = new Vehicle() { VehicleId = "v121212121212" }; string trackFile = "all_2012_03_11_20_37_31"; string folder = manager.GetFolder(vehicle, trackFile, true); Assert.AreEqual(folder, vehicle.VehicleId + @"\2012\03\11"); }
public void Find(Vehicle vehicle, DateTime start, DateTime end, Action callback) { if (end >= start) { IList<string> trackFiles = new List<string>(); string root = m_folderManager.GetRoot(vehicle); Find(trackFiles, root, start, end); if (trackFiles.Count > 0) { TrackList.Load(trackFiles, trackFiles.Count, "트랙 검색", callback); } } }
public void ImportTest() { LocalRepository repo = new LocalRepository(); repo.Open(PersonalTest.StorageRoot, null); Vehicle vehicle = new Vehicle() { VehicleId = "v121212121212" }; TrackImportHelper helper = new TrackImportHelper(repo); List<string> files = new List<string>(); files.Add(Path.Combine(PersonalTest.DeviceRoot, @"all_2012_03_11_20_37_31")); files.Add(Path.Combine(PersonalTest.DeviceRoot, @"all_2012_03_11_20_38_00")); files.Add(Path.Combine(PersonalTest.DeviceRoot, @"event_2012_03_11_20_38_31")); helper.Import(vehicle, files, true, true); }
public VehicleViewModel(Vehicle source) { m_source = source; if (source != null) { Vehicle = (Vehicle)source.Clone(); } else { Vehicle = new Vehicle(); string id = Guid.NewGuid().ToString(); Vehicle.VehicleId = "v" + id.Substring(id.Length - 12, 12); } Vehicle.PropertyChanged += new PropertyChangedEventHandler((sender, e) => { CheckSubmit(); }); CheckSubmit(); }
public void LoadTest() { // save SaveTest(); // load Vehicle vehicle = new Vehicle() { VehicleId = "v121212121212" }; int year = 2012; int month = 03; TrackCatalog cat = new TrackCatalog(vehicle, year, month); string catalogPath = Path.Combine(PersonalTest.StorageRoot, vehicle.VehicleId, TrackCatalog.MakeFileName(year, month)); cat.Load(catalogPath); Assert.AreEqual(cat.Tracks.Count, 2); Assert.AreEqual(cat.Tracks[0].CreateDate, new DateTime(2012, 3, 11, 20, 37, 31)); }
public string GetRoot(Vehicle vehicle) { return Path.Combine(m_owner.RootPath, vehicle.VehicleId); }
/// <summary> /// 가장 최근에 등록된 트랙파일 일자를 리턴한다. /// </summary> /// <returns></returns> public DateTime GetRecentDay(Vehicle vehicle) { DateTime d = DateTime.Today; string root = GetRoot(vehicle); string[] dirs = Directory.GetDirectories(root); // year if (dirs != null && dirs.Length > 0) { Array.Sort(dirs); string dir = dirs[dirs.Length - 1]; // month dirs = Directory.GetDirectories(dir); if (dirs != null && dirs.Length > 0) { Array.Sort(dirs); dir = dirs[dirs.Length - 1]; // day dirs = Directory.GetDirectories(dir); if (dirs != null && dirs.Length > 0) { Array.Sort(dirs); dir = dirs[dirs.Length - 1]; // file dirs = Directory.GetFiles(dir, "*.inc"); if (dirs != null && dirs.Length > 0) { d = DateTime.MinValue; foreach (string file in dirs) { DateTime d2 = DateTime.MinValue; Repository.ParseTrackFile(file, ref d2); if (d2 > d) { d = d2; } } d = new DateTime(d.Year, d.Month, d.Day); } } } } return d; }
public void SaveTest() { Vehicle vehicle = new Vehicle() { VehicleId = "v121212121212" }; int year = 2012; int month = 03; TrackCatalog cat = new TrackCatalog(vehicle, year, month); List<string> files = new List<string>(); files.Add("all_2012_03_11_20_37_31"); files.Add("all_2012_03_12_20_37_31"); cat.Add(files); Assert.AreEqual(cat.Tracks.Count, 2); string catalogPath = Path.Combine(PersonalTest.StorageRoot, vehicle.VehicleId, TrackCatalog.MakeFileName(year, month)); cat.Save(catalogPath); Assert.IsTrue(File.Exists(catalogPath)); }
public void Remove(Vehicle vehicle) { int index = IndexOf(vehicle); if (index >= 0) { RemoveAt(index); } }
/// <summary> /// track file이 저장될 폴더명을 리턴한다. /// relative가 true이면 repository root 상대 경로로 리턴한다. /// 기존하지 않으면 생성한 후 리턴한다. /// </summary> public string GetFolder(Vehicle vehicle, string trackFile, bool relative) { return m_folderManager.GetFolder(vehicle, trackFile, relative); }
/// <summary> /// 외부 폴더에 있는 모든 트랙파일들을 스토리지의 각 위치에 추가한다. /// </summary> /// <param name="folder"></param> /// <param name="overwrite"></param> public int ImportAll(Vehicle vehicle, string folder, bool convert, bool overwrite) { int count = 0; if (Directory.Exists(folder)) { string[] files = Directory.GetFiles(folder, "*.inc"); if (files.Length > 0) { count = Import(vehicle, files, convert, overwrite); } } return count; }
/// <summary> /// file명에 해당하는 inc, log, 264 파일들을 해당하는 스토리지에 복사한다. /// 264파일은 mp4파일로 변환하여 저장한다. /// 264파을을 삭제하지는 않는다. /// </summary> private bool ImportTrackFile(Vehicle vehicle, string file, bool convert, bool overwrite) { // inc 파일은 반드시 존재해야 한다. string source = Path.ChangeExtension(file, ".inc"); if (File.Exists(source)) { string folder = m_owner.GetFolder(vehicle, file, false); if (string.IsNullOrWhiteSpace(folder)) { return false; } string name = Path.GetFileName(source); // inc string target = Path.Combine(folder, name); if (overwrite || !File.Exists(target)) { File.Copy(source, target, true); } // log source = Path.ChangeExtension(file, ".log"); if (File.Exists(source)) { target = Path.Combine(folder, name); target = Path.ChangeExtension(target, ".log"); if (overwrite || !File.Exists(target)) { File.Copy(source, target, true); } } // 264 source = Path.ChangeExtension(file, ".264"); if (File.Exists(source)) { target = Path.Combine(folder, name); target = Path.ChangeExtension(target, ".264"); if (overwrite || !File.Exists(target)) { File.Copy(source, target, true); } // convert to mp4; if (convert) { VideoUtil.RawToMpeg(target, null); } } return true; } return false; }
/// <summary> /// track file이 저장될 폴더명을 리턴한다. /// relative가 true이면 repository root 상대 경로로 리턴한다. /// 기존하지 않으면 생성한 후 리턴한다. /// </summary> public string GetFolder(Vehicle vehicle, string trackFile, bool relative) { string folder = Path.Combine(vehicle.VehicleId, ParseFolder(trackFile)); if (folder != null) { string path = Path.Combine(m_owner.RootPath, folder); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (!relative) { folder = path; } } return folder; }
public TrackCatalog(Vehicle vehicle, int year, int month) { m_vehicle = vehicle; m_year = year; m_month = month; }
public int IndexOf(Vehicle vehicle) { return m_vehicles.IndexOf(vehicle); }