private static bool CopyFile(USNJournalSyncLog syncLog, SyncMountpoint syncFrom) { logger.Info($"[{syncLog.Id}] [C] {syncLog.Action.RelativePath}"); var copyAction = syncLog.Action as UpdateAction; var publicPath = syncFrom.Mountpoint.Reference.PublicPath; var relativePath = copyAction.RelativePath; if (publicPath == null) { throw new NullReferenceException("publicPath"); } if (relativePath == null) { throw new NullReferenceException("relativePath"); } var destination = Path.Get(syncFrom.Path, relativePath); string tempPath = Path.Get(syncFrom.Path, ".proximaTemp.", "toCopy", syncLog.Id).FullPath; var source = Path.Get(publicPath, relativePath); if (source.IsDirectory) { DirectoryInfo sourceInfo = new DirectoryInfo(source.FullPath); DirectoryInfo tempInfo = new DirectoryInfo(tempPath); DirectoryInfo destInfo = new DirectoryInfo(destination.FullPath); sourceInfo.CopyTo(tempInfo.FullName); tempInfo.MoveTo(destInfo.FullName); } else { source.Copy(tempPath); FileInfo tempInfo = new FileInfo(tempPath); tempInfo.MoveTo(destination.FullPath, MoveOptions.ReplaceExisting); } return(true); }
private void TransferItem(USNJournalSyncLog syncLog, SyncMountpoint syncFrom) { try { syncLog.ActionStartDate = DateTime.Now; syncLog.ActionFinishDate = null; Singleton.Instance.Repository.Update(syncLog); bool successfull = false; if (syncLog.Action.GetType() == typeof(DeleteAction)) { var path = Path.Get(syncFrom.Path, syncLog.Action.RelativePath); logger.Info($"[{syncLog.Id}] [D] " + path); if (path.Exists) { var destinationPath = Path.Get(syncFrom.Path, ".proximaTemp.", "toDelete", syncLog.Id).FullPath; if (syncLog.Action.IsDirectory) { DirectoryInfo info = new DirectoryInfo(path.FullPath); info.MoveTo(destinationPath); info.Delete(true, true); } else { FileInfo info = new FileInfo(path.FullPath); info.MoveTo(destinationPath); info.Delete(); } } successfull = true; } else if (syncLog.Action.GetType() == typeof(RenameAction)) { var renameAction = syncLog.Action as RenameAction; logger.Info($"[{syncLog.Id}] [R] {renameAction.RenameFrom} to {renameAction.RelativePath}"); if (String.IsNullOrWhiteSpace(renameAction.RenameFrom)) { CopyFile(syncLog, syncFrom); } string pathFrom = Path.Get(syncFrom.Path, renameAction.RenameFrom).FullPath; string tempPath = Path.Get(syncFrom.Path, ".proximaTemp.", "toRename", syncLog.Id).FullPath; string pathTo = Path.Get(syncFrom.Path, renameAction.RelativePath).FullPath; if (syncLog.Action.IsDirectory) { new DirectoryInfo(pathFrom).MoveTo(tempPath, MoveOptions.None); new DirectoryInfo(tempPath).MoveTo(pathTo, MoveOptions.None); } else { Alphaleonis.Win32.Filesystem.File.Move(pathFrom, tempPath, MoveOptions.None); Alphaleonis.Win32.Filesystem.File.Move(tempPath, pathTo, MoveOptions.None); //new FileInfo(pathFrom).MoveTo(tempPath, MoveOptions.WriteThrough); //new FileInfo(tempPath).MoveTo(pathTo, MoveOptions.WriteThrough); } successfull = true; } else { successfull = CopyFile(syncLog, syncFrom); } syncLog.ActionFinishDate = DateTime.Now; syncLog.Successfull = successfull; Singleton.Instance.Repository.Update(syncLog); foreach (var error in Singleton.Instance.Repository.Many <Error>(f => f.SyncLog.Id == syncLog.Id)) { Singleton.Instance.Repository.Delete(error); } } catch (FileNotFoundException ex) { syncLog.RequiresManualIntervention = true; syncLog.ActionFinishDate = DateTime.Now; Singleton.Instance.Repository.Update(syncLog); logger.Error(ex, "Error on item " + syncLog.Id); Error error = new Error(); error.SyncLog = syncLog; error.Exception = ex; error.ItemId = syncLog.Id; error.Message = ex.Message; Singleton.Instance.Repository.Add(error); } catch (Exception e) { syncLog.ActionFinishDate = DateTime.Now; Singleton.Instance.Repository.Update(syncLog); logger.Error(e, "Error on item " + syncLog.Id); Error error = new Error(); error.SyncLog = syncLog; error.Exception = e; error.ItemId = syncLog.Id; error.Message = e.Message; Singleton.Instance.Repository.Add(error); } }
private void DumpGetXxxTimeXxx(bool isLocal) { #region Setup Console.WriteLine("\n=== TEST {0} ===", isLocal ? Local : Network); string path = NotepadExe; if (!isLocal) path = Path.LocalToUnc(path); Console.WriteLine("\nInput File Path: [{0}]\n", path); #endregion // Setup StopWatcher(true); #region GetCreationTimeXxx DateTime actual = File.GetCreationTime(path); DateTime expected = System.IO.File.GetCreationTime(path); Console.WriteLine("\tGetCreationTime() : [{0}] System.IO: [{1}]", actual, expected); Assert.AreEqual(expected, actual, "AlphaFS != System.IO"); actual = File.GetCreationTimeUtc(path); expected = System.IO.File.GetCreationTimeUtc(path); Console.WriteLine("\tGetCreationTimeUtc() : [{0}] System.IO: [{1}]\n", actual, expected); Assert.AreEqual(expected, actual, "AlphaFS != System.IO"); #endregion // GetCreationTimeXxx #region GetLastAccessTimeXxx actual = File.GetLastAccessTime(path); expected = System.IO.File.GetLastAccessTime(path); Console.WriteLine("\tGetLastAccessTime() : [{0}] System.IO: [{1}]", actual, expected); Assert.AreEqual(expected, actual, "AlphaFS != System.IO"); actual = File.GetLastAccessTimeUtc(path); expected = System.IO.File.GetLastAccessTimeUtc(path); Console.WriteLine("\tGetLastAccessTimeUtc(): [{0}] System.IO: [{1}]\n", actual, expected); Assert.AreEqual(expected, actual, "AlphaFS != System.IO"); #endregion // GetLastAccessTimeXxx #region GetLastWriteTimeXxx actual = File.GetLastWriteTime(path); expected = System.IO.File.GetLastWriteTime(path); Console.WriteLine("\tGetLastWriteTime() : [{0}] System.IO: [{1}]", actual, expected); Assert.AreEqual(expected, actual, "AlphaFS != System.IO"); actual = File.GetLastWriteTimeUtc(path); expected = System.IO.File.GetLastWriteTimeUtc(path); Console.WriteLine("\tGetLastWriteTimeUtc() : [{0}] System.IO: [{1}]\n", actual, expected); Assert.AreEqual(expected, actual, "AlphaFS != System.IO"); #endregion // GetLastWriteTimeXxx #region GetChangeTimeXxx Console.WriteLine("\tGetChangeTime() : [{0}] System.IO: [N/A]", File.GetChangeTime(path)); Console.WriteLine("\tGetChangeTimeUtc() : [{0}] System.IO: [N/A]", File.GetChangeTimeUtc(path)); #endregion // GetChangeTimeXxx Console.WriteLine(); Console.WriteLine(Reporter()); Console.WriteLine(); #region Trigger GetChangeTimeXxx // We can not compare ChangeTime against .NET because it does not exist. // Creating a file and renaming it triggers ChangeTime, so test for that. path = Path.GetTempPath("File-GetChangeTimeXxx()-file-" + Path.GetRandomFileName()); if (!isLocal) path = Path.LocalToUnc(path); FileInfo fi = new FileInfo(path); using (fi.Create()) { } string fileName = fi.Name; DateTime lastAccessTimeActual = File.GetLastAccessTime(path); DateTime lastAccessTimeUtcActual = File.GetLastAccessTimeUtc(path); DateTime changeTimeActual = File.GetChangeTime(path); DateTime changeTimeUtcActual = File.GetChangeTimeUtc(path); Console.WriteLine("\nTesting ChangeTime on a temp file."); Console.WriteLine("\nInput File Path: [{0}]\n", path); Console.WriteLine("\tGetChangeTime() : [{0}]\t", changeTimeActual); Console.WriteLine("\tGetChangeTimeUtc() : [{0}]\t", changeTimeUtcActual); fi.MoveTo(fi.FullName.Replace(fileName, fileName + "-Renamed")); // Pause for at least a second so that the difference in time can be seen. int sleep = new Random().Next(2000, 4000); Thread.Sleep(sleep); fi.MoveTo(fi.FullName.Replace(fileName + "-Renamed", fileName)); DateTime lastAccessTimeExpected = File.GetLastAccessTime(path); DateTime lastAccessTimeUtcExpected = File.GetLastAccessTimeUtc(path); DateTime changeTimeExpected = File.GetChangeTime(path); DateTime changeTimeUtcExpected = File.GetChangeTimeUtc(path); Console.WriteLine("\nTrigger ChangeTime by renaming the file."); Console.WriteLine("For Unit Test, ChangeTime should differ approximately: [{0}] seconds.\n", sleep / 1000); Console.WriteLine("\tGetChangeTime() : [{0}]\t", changeTimeExpected); Console.WriteLine("\tGetChangeTimeUtc() : [{0}]\t\n", changeTimeUtcExpected); Assert.AreNotEqual(changeTimeActual, changeTimeExpected); Assert.AreNotEqual(changeTimeUtcActual, changeTimeUtcExpected); Assert.AreEqual(lastAccessTimeExpected, lastAccessTimeActual); Assert.AreEqual(lastAccessTimeUtcExpected, lastAccessTimeUtcActual); #endregion // Trigger GetChangeTimeXxx fi.Delete(); fi.Refresh(); // Must Refresh() to get actual state. Assert.IsFalse(fi.Exists, "Cleanup failed: File should have been removed."); Console.WriteLine(); }
private void DumpMove(bool isLocal) { #region Setup Console.WriteLine("\n=== TEST {0} ===", isLocal ? Local : Network); string path = isLocal ? SysRoot : Path.LocalToUnc(SysRoot); string tempPath = Path.GetTempPath("File-Move-" + Path.GetRandomFileName()); if (!isLocal) tempPath = Path.LocalToUnc(tempPath); bool exception; int expectedLastError; string expectedException; string fileSource = @"file-source-" + Path.GetRandomFileName() + ".exe"; string fileDestination = @"file-destination-" + Path.GetRandomFileName() + ".exe"; string folderSource = tempPath + @"\folder-source-" + Path.GetRandomFileName(); string folderDestination = tempPath + @"\folder-destination-" + Path.GetRandomFileName(); string fullPathSource = folderSource + @"\" + fileSource; string fullPathDestination = folderDestination + @"\" + fileDestination; if (!isLocal) fullPathSource = Path.LocalToUnc(fullPathSource); if (!isLocal) fullPathDestination = Path.LocalToUnc(fullPathDestination); DirectoryInfo dirInfo = new DirectoryInfo(folderDestination); #endregion // Setup try { #region UnauthorizedAccessException Directory.CreateDirectory(folderSource); Directory.CreateDirectory(folderDestination); DirectorySecurity dirSecurity; string user = (Environment.UserDomainName + @"\" + Environment.UserName).TrimStart('\\'); // ╔═════════════╦═════════════╦═══════════════════════════════╦════════════════════════╦══════════════════╦═══════════════════════╦═════════════╦═════════════╗ // ║ ║ folder only ║ folder, sub-folders and files ║ folder and sub-folders ║ folder and files ║ sub-folders and files ║ sub-folders ║ files ║ // ╠═════════════╬═════════════╬═══════════════════════════════╬════════════════════════╬══════════════════╬═══════════════════════╬═════════════╬═════════════╣ // ║ Propagation ║ none ║ none ║ none ║ none ║ InheritOnly ║ InheritOnly ║ InheritOnly ║ // ║ Inheritance ║ none ║ Container|Object ║ Container ║ Object ║ Container|Object ║ Container ║ Object ║ // ╚═════════════╩═════════════╩═══════════════════════════════╩════════════════════════╩══════════════════╩═══════════════════════╩═════════════╩═════════════╝ var rule = new FileSystemAccessRule(user, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Deny); expectedLastError = (int)Win32Errors.ERROR_ACCESS_DENIED; expectedException = "System.UnauthorizedAccessException"; exception = false; try { Console.WriteLine("\nCatch: [{0}]: The caller does not have the required permission.", expectedException); FileInfo fileInfo = new FileInfo(fullPathSource); using (StreamWriter sw = fileInfo.CreateText()) sw.WriteLine("MoveTo-TestFile"); // Set DENY for current user. dirSecurity = dirInfo.GetAccessControl(); dirSecurity.AddAccessRule(rule); dirInfo.SetAccessControl(dirSecurity); fileInfo.MoveTo(fullPathDestination); } catch (Exception ex) { Assert.IsTrue(ex.Message.StartsWith("(" + expectedLastError + ")"), string.Format("Expected Win32Exception error is: [{0}]", expectedLastError)); string exceptionTypeName = ex.GetType().FullName; if (exceptionTypeName.Equals(expectedException)) { exception = true; Console.WriteLine("\n\t[{0}]: [{1}]", exceptionTypeName, ex.Message.Replace(Environment.NewLine, " ")); } else Console.WriteLine("\n\tCaught Unexpected Exception: [{0}]: [{1}]", exceptionTypeName, ex.Message.Replace(Environment.NewLine, " ")); } finally { // Remove DENY for current user. dirSecurity = dirInfo.GetAccessControl(); dirSecurity.RemoveAccessRule(rule); dirInfo.SetAccessControl(dirSecurity, AccessControlSections.Access); Directory.Delete(tempPath, true, true); } Assert.IsTrue(exception, "[{0}] should have been caught.", expectedException); Console.WriteLine(); #endregion // UnauthorizedAccessException #region FileNotFoundException expectedLastError = (int)Win32Errors.ERROR_FILE_NOT_FOUND; expectedException = "System.IO.FileNotFoundException"; exception = false; try { Console.WriteLine("\nCatch: [{0}]: sourceFileName was not found.", expectedException); File.Move(isLocal ? fileSource : Path.LocalToUnc(fileSource), isLocal ? fileDestination : Path.LocalToUnc(fileDestination)); } catch (FileNotFoundException ex) { var win32Error = new Win32Exception("", ex); Assert.IsTrue(win32Error.NativeErrorCode == expectedLastError, string.Format("Expected Win32Exception error should be: [{0}], got: [{1}]", expectedLastError, win32Error.NativeErrorCode)); exception = true; Console.WriteLine("\n\t[{0}]: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\n\tCaught Unexpected Exception: [{0}]: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Assert.IsTrue(exception, "[{0}] should have been caught.", expectedException); Console.WriteLine(); #endregion // FileNotFoundException #region DirectoryNotFoundException expectedLastError = (int)Win32Errors.ERROR_PATH_NOT_FOUND; expectedException = "System.IO.DirectoryNotFoundException"; exception = false; try { Console.WriteLine("\nCatch: [{0}]: The path specified in sourceFileName or destFileName is invalid (for example, it is on an unmapped drive).", expectedException); File.Move(fullPathSource, fullPathDestination); } catch (DirectoryNotFoundException ex) { var win32Error = new Win32Exception("", ex); Assert.IsTrue(win32Error.NativeErrorCode == expectedLastError, string.Format("Expected Win32Exception error should be: [{0}], got: [{1}]", expectedLastError, win32Error.NativeErrorCode)); exception = true; Console.WriteLine("\n\t[{0}]: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\n\tCaught Unexpected Exception: [{0}]: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Assert.IsTrue(exception, "[{0}] should have been caught.", expectedException); Console.WriteLine(); #endregion // DirectoryNotFoundException #region IOException #1 Directory.CreateDirectory(folderSource); Directory.CreateDirectory(folderDestination); using (File.Create(fullPathSource)) { } using (File.Create(fullPathDestination)) { } expectedLastError = (int)Win32Errors.ERROR_ALREADY_EXISTS; expectedException = "System.IO.IOException"; exception = false; try { Console.WriteLine("\nCatch: [{0}]: The destination file already exists.", expectedException); File.Move(fullPathSource, fullPathDestination); } catch (AlreadyExistsException ex) { // win32Error is always 0 //var win32Error = new Win32Exception("", ex); //Assert.IsTrue(win32Error.NativeErrorCode == expectedLastError, string.Format("Expected Win32Exception error should be: [{0}], got: [{1}]", expectedLastError, win32Error.NativeErrorCode)); Assert.IsTrue(ex.Message.StartsWith("(" + expectedLastError + ")"), string.Format("Expected Win32Exception error is: [{0}]", expectedLastError)); exception = true; Console.WriteLine("\n\t[{0}]: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\n\tCaught Unexpected Exception: [{0}]: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Assert.IsTrue(exception, "[{0}] should have been caught.", expectedException); Console.WriteLine(); Directory.Delete(folderSource, true); Directory.Delete(folderDestination, true); #endregion // IOException #1 #region IOException #2 string folderfileName = null; expectedLastError = (int)Win32Errors.ERROR_ACCESS_DENIED; expectedException = "System.IO.IOException"; exception = false; try { Console.WriteLine("\nCatch: [{0}]: A folder with the same name as the file exists.", expectedException); foreach (string file in Directory.EnumerateFiles(path)) { string newFile = Path.Combine(tempPath, Path.GetFileName(file, true)); folderfileName = newFile; // Trigger the Exception. Directory.CreateDirectory(folderfileName); // MoveOptions.None: overwrite existing. File.Move(file, folderfileName, MoveOptions.None); } } catch (AlreadyExistsException ex) { var win32Error = new Win32Exception("", ex); Assert.IsTrue(win32Error.NativeErrorCode == expectedLastError, string.Format("Expected Win32Exception error should be: [{0}], got: [{1}]", expectedLastError, win32Error.NativeErrorCode)); exception = true; Directory.Delete(folderfileName); Console.WriteLine("\n\t[{0}]: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\n\tCaught Unexpected Exception: [{0}]: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Assert.IsTrue(exception, "[{0}] should have been caught.", expectedException); Console.WriteLine(); #endregion // IOException #2 #region Move #region Copy (Use as Move() source) foreach (string file in Directory.EnumerateFiles(path)) File.Copy(file, Path.Combine(tempPath, Path.GetFileName(file, true))); #endregion // Copy (Use as Move() source) string movePath = Path.GetTempPath("File-Move-II-" + Path.GetRandomFileName()); if (!isLocal) movePath = Path.LocalToUnc(movePath); Directory.CreateDirectory(movePath); Console.WriteLine("\nInput Directory Path: [{0}]\n", tempPath); int cnt = 0; string readOnlySource = null; string readOnlyDestination = null; StopWatcher(true); foreach (string file in Directory.EnumerateFiles(tempPath)) { string newFile = Path.Combine(movePath, Path.GetFileName(file, true)); File.Move(file, newFile); // A read-only file triggers UnauthorizedAccessException when moving again. if (cnt == 0) { File.SetAttributes(newFile, FileAttributes.ReadOnly); readOnlySource = file; readOnlyDestination = newFile; } Console.WriteLine("\t#{0:000}\tMoved to: [{1}]", ++cnt, newFile); Assert.IsTrue(File.Exists(newFile)); } Console.WriteLine("\n\tTotal Size: [{0}]{1}", Utils.UnitSizeToText(Directory.GetProperties(movePath)["Size"]), Reporter()); Console.WriteLine(); #endregion // Move // Move again, use overwrite to prevent IOException: The destination file already exists. #region Copy (Use as Move() source) foreach (string file in Directory.EnumerateFiles(path)) File.Copy(file, Path.Combine(tempPath, Path.GetFileName(file, true))); #endregion // Copy (Use as Move() source) #region Remove Read-Only Attribute, Move Again Console.WriteLine("\nRemove read-only attribute and move again."); #region Preserve Timestamps // Test preservation of timestamps. int seed = (int)DateTime.Now.Ticks & 0x0000FFFF; DateTime creationTime = new DateTime(new Random(seed).Next(1971, 2071), new Random(seed).Next(1, 12), new Random(seed).Next(1, 28), new Random(seed).Next(0, 23), new Random(seed).Next(0, 59), new Random(seed).Next(0, 59)); seed += (int)DateTime.Now.Ticks & 0x0000FFFF; DateTime lastAccessTime = new DateTime(new Random(seed).Next(1971, 2071), new Random(seed).Next(1, 12), new Random(seed).Next(1, 28), new Random(seed).Next(0, 23), new Random(seed).Next(0, 59), new Random(seed).Next(0, 59)); seed += (int)DateTime.Now.Ticks & 0x0000FFFF; DateTime lastWriteTime = new DateTime(new Random(seed).Next(1971, 2071), new Random(seed).Next(1, 12), new Random(seed).Next(1, 28), new Random(seed).Next(0, 23), new Random(seed).Next(0, 59), new Random(seed).Next(0, 59)); File.SetCreationTime(readOnlySource, creationTime); File.SetLastAccessTime(readOnlySource, lastAccessTime); File.SetLastWriteTime(readOnlySource, lastWriteTime); #endregion Preserve Timestamps StopWatcher(true); // 3rd parameter MoveOptions.ReplaceExisting: overwrite existing. // File.Move() automatically preserves Timestamps. File.Move(readOnlySource, readOnlyDestination, MoveOptions.ReplaceExisting); Console.WriteLine("\tFile moved.{0}", Reporter()); Assert.IsFalse(File.Exists(readOnlySource)); Assert.IsTrue(File.Exists(readOnlyDestination)); Assert.AreEqual(File.GetCreationTime(readOnlyDestination), creationTime, "File CreationTime should match."); Assert.AreEqual(File.GetLastAccessTime(readOnlyDestination), lastAccessTime, "File LastAccessTime should match."); Assert.AreEqual(File.GetLastWriteTime(readOnlyDestination), lastWriteTime, "File LastWriteTime should match."); Console.WriteLine("\nTimestamps are transferred."); Directory.Delete(movePath, true, true); Assert.IsFalse(Directory.Exists(movePath), "Cleanup failed: Directory should have been removed."); #endregion // Remove Read-Only Attribute, Move Again } finally { if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true, true); Assert.IsFalse(Directory.Exists(tempPath), "Cleanup failed: Directory should have been removed."); } Console.WriteLine(); } }
private void InitDataBase(string alarmImagePath, string videoPath, string xmlFile) { dbConnection?.Close(); dbConnection = null; // 删除旧文件 if (File.Exists("./data.db")) { string ex = DateTime.Now.ToString("yyyyMMddHHmmss"); FileInfo fi = new FileInfo("./data.db"); try { fi.MoveTo("./data.db." + ex, MoveOptions.ReplaceExisting); } catch (IOException e) { MessageWindow.ShowDialog(e.ToString(), this); return; } } // 创建数据表 CreateBlankTabs(); /********************* DataPathTab 数据更新 ********************/ SQLiteCommand cmd = new SQLiteCommand(); cmd.Connection = dbConnection; cmd.CommandText = "BEGIN"; cmd.ExecuteNonQuery(); cmd.CommandText = string.Format($"INSERT INTO DataPathTab(Item, Path) VALUES ('AlarmImagePath', '{alarmImagePath}')"); cmd.ExecuteNonQuery(); cmd.CommandText = string.Format($"INSERT INTO DataPathTab(Item, Path) VALUES ('VideoPath', '{videoPath}')"); cmd.ExecuteNonQuery(); cmd.CommandText = string.Format($"INSERT INTO DataPathTab(Item, Path) VALUES ('VideoInfoFilePath', '{xmlFile}')"); cmd.ExecuteNonQuery(); cmd.CommandText = "COMMIT"; cmd.ExecuteNonQuery(); /********************* AlarmImageTab 数据更新 ********************/ cmd.CommandText = "BEGIN"; cmd.ExecuteNonQuery(); foreach (var item in alarmImageListAll) { cmd.CommandText = string.Format($"INSERT INTO AlarmImageTab(id, image, scene, incident, video, frame, state, count)" + $" VALUES ('{item.ID}', '{item.ImagePath}','{item.Scene}','{item.Incident}', '{item.Video}', '{item.Frame}', '{(int)item.State}', '{item.IncidentCount}')"); cmd.ExecuteNonQuery(); } cmd.CommandText = "COMMIT"; cmd.ExecuteNonQuery(); /************************** TestVideoTab 数据更新 ************************************/ cmd.CommandText = "BEGIN"; cmd.ExecuteNonQuery(); foreach (var item in testVideoList) { cmd.CommandText = string.Format($"INSERT INTO TestVideoTab(VideoName, Directory) VALUES ('{item.VideoName}', '{item.VideoPath}')"); cmd.ExecuteNonQuery(); } cmd.CommandText = "COMMIT"; cmd.ExecuteNonQuery(); /************************** MarkVideoTab 数据更新 ************************************/ cmd.CommandText = "BEGIN"; cmd.ExecuteNonQuery(); foreach (var item in videoInfoList) { cmd.CommandText = string.Format($"INSERT INTO VideoInfoTab(Scene, Video, Incident, Count) " + $"VALUES ('{item.Scene}', '{item.VideoName}', '{item.Incident}', '{item.Count}')"); cmd.ExecuteNonQuery(); } cmd.CommandText = "COMMIT"; cmd.ExecuteNonQuery(); }