/// <summary> /// Database to Folder Synchronization /// </summary> public static void D2FSync() { ///Get List of Folders from database foreach (Folder folder in FileManagerController.GetAllFolders()) { if (!Directory.Exists(Path.Combine(absolutePath, folder.FolderPath))) { //delete the directory FileManagerController.DeleteFileFolder(folder.FolderId, 0); } else { //get the file list with that folderId List <ATTFile> lstFile = FileManagerController.GetFiles(folder.FolderId); foreach (ATTFile file in lstFile) { if (file.StorageLocation == 0) { if (!File.Exists(Path.Combine(Path.Combine(absolutePath, file.Folder), file.FileName))) { //delete the file from database FileManagerController.DeleteFileFolder(0, file.FileId); } } else if (file.StorageLocation == 1) { if (!File.Exists(Path.Combine(Path.Combine(absolutePath, file.Folder), file.FileName + ".resources"))) { //delete the file from database FileManagerController.DeleteFileFolder(0, file.FileId); } } } } } }
/// <summary> /// Copy or Move the file to the fullToPath location /// </summary> /// <param name="filePath"></param> /// <param name="fileId"></param> /// <param name="toFolderId"></param> /// <param name="toPath"></param> /// <param name="action"></param> /// <param name="mode"></param> /// <param name="fullFilePath"></param> /// <param name="fullFromPath"></param> /// <param name="fullToPath"></param> public static void TransferFile(string filePath, int fileId, int toFolderId, string toPath, int action, int mode, string fullFilePath, string fullFromPath, string fullToPath) { switch (mode) { case 1: switch (action) { case 1: FileInfo fileCopy = new FileInfo(fullFilePath); string fileNameCopy = fileCopy.Name; if (!File.Exists(Path.Combine(fullToPath, fileNameCopy))) { try { fileCopy.CopyTo(Path.Combine(fullToPath, fileNameCopy)); FileManagerController.CopyFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid()); } catch (Exception) { throw; } } break; case 2: FileInfo fileMove = new FileInfo(fullFilePath); string fileNameMove = fileMove.Name; if (fileMove.Exists) { try { fileMove.MoveTo(fullToPath + fileNameMove); FileManagerController.MoveFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid()); } catch (Exception) { throw; } } break; } break; case 2: switch (action) { case 1: FileInfo fileCopy = new FileInfo(fullFilePath); string fileNameCopy = fileCopy.Name; /// Checking if file exists if (!File.Exists(fullToPath + fileNameCopy + ".resources")) { try { fileCopy.CopyTo(fullToPath + fileNameCopy + ".resources"); FileManagerController.CopyFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid()); } catch (Exception) { throw; } } break; case 2: FileInfo fileMove = new FileInfo(fullFilePath); string fileName = fileMove.Name; if (fileMove.Exists) { try { fileMove.MoveTo(fullToPath + fileName + ".resources"); FileManagerController.MoveFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid()); } catch (Exception) { throw; } } break; } break; case 3: switch (action) { case 1: FileInfo fileCopy = new FileInfo(fullFilePath); ATTFile objCopy = new ATTFile(); objCopy.FileName = fileCopy.Name; objCopy.Folder = toPath; objCopy.FolderId = toFolderId; objCopy.AddedBy = "superuser"; objCopy.Extension = fileCopy.Extension; objCopy.PortalId = 1; objCopy.UniqueId = Guid.NewGuid(); objCopy.VersionGuid = Guid.NewGuid(); objCopy.Size = int.Parse(fileCopy.Length.ToString()); objCopy.ContentType = FileManagerHelper.ReturnExtension(fileCopy.Extension); objCopy.IsActive = 1; objCopy.StorageLocation = 2; if (fileCopy.Exists) { byte[] _fileContent = FileManagerHelper.FileToByteArray(fullFilePath); objCopy.Content = _fileContent; try { FileManagerController.AddFile(objCopy); } catch (Exception) { throw; } } break; case 2: FileInfo fileMove = new FileInfo(fullFilePath); ATTFile objMove = new ATTFile(); objMove.FileName = fileMove.Name; objMove.Folder = toPath; objMove.FolderId = toFolderId; objMove.AddedBy = "superuser"; objMove.Extension = fileMove.Extension; objMove.PortalId = 1; objMove.UniqueId = Guid.NewGuid(); objMove.VersionGuid = Guid.NewGuid(); objMove.Size = int.Parse(fileMove.Length.ToString()); objMove.ContentType = FileManagerHelper.ReturnExtension(fileMove.Extension); objMove.IsActive = 1; objMove.StorageLocation = 2; if (fileMove.Exists) { byte[] _fileContent = FileManagerHelper.FileToByteArray(fullFilePath); objMove.Content = _fileContent; try { FileManagerController.AddFile(objMove); fileMove.Delete(); FileManagerController.DeleteFileFolder(0, fileId); } catch (Exception) { throw; } } break; } break; case 4: switch (action) { case 1: FileInfo fileCopy = new FileInfo(fullFilePath + ".resources"); /// Checking if file exists string fileNameCopy = ""; fileNameCopy = fileCopy.Name; if (!File.Exists(Path.Combine(fullToPath, fileNameCopy.Replace(".resources", "")))) { try { fileCopy.CopyTo(Path.Combine(fullToPath, fileNameCopy.Replace(".resources", ""))); FileManagerController.CopyFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid()); } catch (Exception) { throw; } } break; case 2: FileInfo fileMove = new FileInfo(fullFilePath + ".resources"); string fileNameMove = fileMove.Name; if (fileMove.Exists) { try { fileMove.MoveTo(Path.Combine(fullToPath, fileNameMove.Replace(".resources", ""))); FileManagerController.MoveFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid()); } catch (Exception) { throw; } } break; } break; case 5: switch (action) { case 1: FileInfo file11 = new FileInfo(fullFilePath + ".resources"); /// Checking if file exists string fileName11 = ""; fileName11 = filePath.Substring(filePath.LastIndexOf('/') + 1, filePath.Length - 1 - filePath.LastIndexOf('/')); if (!File.Exists(fullToPath + fileName11 + ".resources")) { try { file11.CopyTo(fullToPath + fileName11 + ".resources"); FileManagerController.CopyFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid()); } catch (Exception) { throw; } } break; case 2: FileInfo fileMove = new FileInfo(fullFilePath + ".resources"); /// Checking if file exists string fileNameMove = fileMove.Name; if (fileMove.Exists) { try { fileMove.MoveTo(Path.Combine(fullFilePath, fileNameMove + ".resources")); FileManagerController.MoveFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid()); } catch (Exception) { throw; } } break; } break; case 6: switch (action) { case 1: FileInfo file12 = new FileInfo(fullFilePath + ".resources"); ATTFile obj12 = new ATTFile(); obj12.FileName = RemoveResourceExtension(file12.Name); obj12.Folder = toPath; obj12.FolderId = toFolderId; obj12.AddedBy = "superuser"; obj12.Extension = file12.Extension; obj12.PortalId = 1; obj12.UniqueId = Guid.NewGuid(); obj12.VersionGuid = Guid.NewGuid(); obj12.Size = int.Parse(file12.Length.ToString()); obj12.ContentType = FileManagerHelper.ReturnExtension(file12.Extension); obj12.IsActive = 1; obj12.StorageLocation = 2; if (new FileInfo(fullFilePath + ".resources").Exists) { File.Move(fullFilePath + ".resources", fullFilePath); byte[] _fileContent = FileManagerHelper.FileToByteArray(fullFilePath); obj12.Content = _fileContent; try { FileManagerController.AddFile(obj12); File.Move(fullFilePath, fullFilePath + ".resources"); } catch (Exception) { if (File.Exists(fullFilePath)) { File.Move(fullFilePath, fullFilePath + ".resources"); } throw; } } break; case 2: FileInfo fileMove = new FileInfo(fullFilePath + ".resources"); ATTFile objMove = new ATTFile(); objMove.FileName = RemoveResourceExtension(fileMove.Name); objMove.Folder = toPath; objMove.FolderId = toFolderId; objMove.AddedBy = "superuser"; objMove.Extension = fileMove.Extension; objMove.PortalId = 1; objMove.UniqueId = Guid.NewGuid(); objMove.VersionGuid = Guid.NewGuid(); objMove.Size = int.Parse(new FileInfo(fullFilePath + ".resources").Length.ToString()); objMove.ContentType = FileManagerHelper.ReturnExtension(fileMove.Extension); objMove.IsActive = 1; objMove.StorageLocation = 2; if (new FileInfo(fullFilePath + ".resources").Exists) { byte[] _fileContent = FileManagerHelper.FileToByteArray(fullFilePath + ".resources"); objMove.Content = _fileContent; try { FileManagerController.AddFile(objMove); File.Delete(fullFilePath + ".resources"); FileManagerController.DeleteFileFolder(0, fileId); } catch (Exception) { throw; } } break; } break; case 7: switch (action) { case 1: ATTFile obj20 = new ATTFile(); obj20 = FileManagerController.GetFileDetails(fileId); try { string newFilePath = Path.Combine(fullToPath, obj20.FileName); if (!File.Exists(newFilePath)) { FileManagerHelper.WriteBinaryFile(newFilePath, obj20.Content); FileInfo file20 = new FileInfo(newFilePath); ATTFile obj20New = new ATTFile(file20.Name, toPath, toFolderId, "superuser", file20.Extension, 1, Guid.NewGuid(), Guid.NewGuid(), int.Parse(file20.Length.ToString()), FileManagerHelper.ReturnExtension(file20.Extension), 1, 0); FileManagerController.AddFile(obj20New); } } catch (Exception) { throw; } break; case 2: ATTFile objMove = new ATTFile(); objMove = FileManagerController.GetFileDetails(fileId); try { string newFilePath = Path.Combine(fullToPath, objMove.FileName); FileManagerHelper.WriteBinaryFile(newFilePath, objMove.Content); FileInfo file20 = new FileInfo(newFilePath); ATTFile obj20New = new ATTFile(file20.Name, toPath, toFolderId, "superuser", file20.Extension, 1, Guid.NewGuid(), Guid.NewGuid(), int.Parse(file20.Length.ToString()), FileManagerHelper.ReturnExtension(file20.Extension), 1, 0); FileManagerController.AddFile(obj20New); FileManagerController.DeleteFileFolder(0, fileId); } catch (Exception) { throw; } break; } break; case 8: switch (action) { case 1: ATTFile obj21 = new ATTFile(); obj21 = FileManagerController.GetFileDetails(fileId); try { string newFilePath = Path.Combine(fullToPath, obj21.FileName); if (!File.Exists(newFilePath + ".resources")) { FileManagerHelper.WriteBinaryFile(newFilePath + ".resources", obj21.Content); FileInfo file21 = new FileInfo(newFilePath + ".resources"); ATTFile obj21New = new ATTFile(file21.Name, toPath, toFolderId, "superuser", file21.Extension, 1, Guid.NewGuid(), Guid.NewGuid(), int.Parse(file21.Length.ToString()), FileManagerHelper.ReturnExtension(file21.Extension), 1, 1); FileManagerController.AddFile(obj21New); } } catch (Exception) { throw; } break; case 2: ATTFile objMove = new ATTFile(); objMove = FileManagerController.GetFileDetails(fileId); try { string newFilePath = Path.Combine(fullToPath, objMove.FileName); FileManagerHelper.WriteBinaryFile(newFilePath + ".resources", objMove.Content); FileInfo file21 = new FileInfo(newFilePath + ".resources"); ATTFile obj21New = new ATTFile(file21.Name.Replace(".resources", ""), toPath, toFolderId, "superuser", file21.Extension, 1, Guid.NewGuid(), Guid.NewGuid(), int.Parse(file21.Length.ToString()), FileManagerHelper.ReturnExtension(file21.Extension), 1, 1); FileManagerController.AddFile(obj21New); FileManagerController.DeleteFileFolder(0, fileId); } catch (Exception) { throw; } break; } break; case 9: switch (action) { case 1: ATTFile obj22 = new ATTFile(); obj22 = FileManagerController.GetFileDetails(fileId); try { string newFilePath = Path.Combine(fullToPath, obj22.FileName); FileInfo file22 = new FileInfo(newFilePath); obj22.Folder = toPath; obj22.FolderId = toFolderId; obj22.AddedBy = "superuser"; FileManagerController.AddFile(obj22); } catch (Exception) { throw; } break; case 2: ATTFile objMove = new ATTFile(); objMove = FileManagerController.GetFileDetails(fileId); try { string newFilePath = Path.Combine(fullToPath, objMove.FileName); FileInfo fileMove = new FileInfo(newFilePath); objMove.Folder = toPath; objMove.FolderId = toFolderId; objMove.AddedBy = "superuser"; FileManagerController.AddFile(objMove); FileManagerController.DeleteFileFolder(0, fileId); } catch (Exception) { throw; } break; } break; } }