public void CopyFile(FileSystemEventArgs e) { List <ItemPath> paths = Utility.GetListMapPath(Constants.MAPPING_SERVER_FILENAME); string dir = e.FullPath.Substring(0, e.FullPath.LastIndexOf("\\")); ItemPath item = paths.Find(i => i.Source == dir); if (item != null) { string filename = e.FullPath.Substring(e.FullPath.LastIndexOf("\\") + 1); string sourceFile = item.Source + "\\" + filename; string desFile = item.Destination + "\\" + filename; DTProcess dTProcess = new DTProcess(); dTProcess.SourceDir = sourceFile; dTProcess.DesDir = desFile; dTProcess.Type = TypeProcess.COPY; dTProcess.ClientProcess = false; dTProcess.log = log; if (!fileProcessor.CheckExistProcess(dTProcess)) { fileProcessor.EnqueueProcess(dTProcess); log.Info("File: " + e.FullPath + " " + filename); } } else { log.Error("Do not exist path in map: " + e.FullPath); } }
public void Delete(FileSystemEventArgs e) { List <ItemPath> paths = Utility.GetListMapPath(Constants.MAPPING_SERVER_FILENAME); string dir = Utility.GetDirFromPath(e.FullPath); string fileName = Utility.GetFilenameFromPath(e.FullPath); ItemPath item = paths.Find(i => i.Source == dir); if (item != null) { string filePath = item.Destination + "\\" + fileName; DTProcess dTProcess = new DTProcess(); dTProcess.SourceDir = filePath; dTProcess.Type = TypeProcess.DELETE; dTProcess.ClientProcess = false; dTProcess.log = log; if (!fileProcessor.CheckExistProcess(dTProcess)) { fileProcessor.EnqueueProcess(dTProcess); log.Info("File : " + e.FullPath); } } else { log.Error("Do not exist path in map: " + e.FullPath); } }
public void Rename(RenamedEventArgs e) { List <ItemPath> paths = Utility.GetListMapPath(Constants.MAPPING_CLIENT_FILENAME); string dir = Utility.GetDirFromPath(e.FullPath); // ItemPath item = paths.Find(i => i.Source == dir); foreach (var item in paths) { if (item.Source == dir) { InitFtp(); string newName = Utility.GetFilenameFromPath(e.FullPath); string newPath = item.Destination + "\\" + newName; string oldname = Utility.GetFilenameFromPath(e.OldFullPath); DTProcess dTProcess = new DTProcess(); dTProcess.SourceDir = e.OldFullPath; dTProcess.DesDir = newPath; dTProcess.Type = TypeProcess.RENAME; dTProcess.ftp = ftp; dTProcess.log = log; if (!fileProcessor.CheckExistProcess(dTProcess)) { fileProcessor.EnqueueProcess(dTProcess); log.Info("File: " + oldname + " to " + newPath); } } } }
private void Work() { while (true) { DTProcess currentProcess = null; lock (locker) if (processQueue.Count > 0) { currentProcess = processQueue.Dequeue(); if (currentProcess == null) { return; } } if (currentProcess != null) { try { ProcessFile(currentProcess); } catch (Exception) { } } else { eventWaitHandle.WaitOne(); } } }
public void CopyFile(FileSystemEventArgs e) { List <ItemPath> paths = Utility.GetListMapPath(Constants.MAPPING_CLIENT_FILENAME); string dir = e.FullPath.Substring(0, e.FullPath.LastIndexOf("\\")); // var items = paths.Find(i => i.Source == dir); foreach (var item in paths) { if (item.Source == dir) { InitFtp(); string filename = e.FullPath.Substring(e.FullPath.LastIndexOf("\\") + 1); string sourceFile = item.Source + "\\" + filename; DTProcess dTProcess = new DTProcess(); dTProcess.SourceDir = sourceFile; dTProcess.DesDir = item.Destination; dTProcess.Type = TypeProcess.COPY; dTProcess.ftp = ftp; dTProcess.log = log; if (!fileProcessor.CheckExistProcess(dTProcess)) { fileProcessor.EnqueueProcess(dTProcess); log.Info("File: " + e.FullPath); } } } }
public void Delete(FileSystemEventArgs e) { InitFtp(); List <ItemPath> paths = Utility.GetListMapPath(Constants.MAPPING_CLIENT_FILENAME); string dir = Utility.GetDirFromPath(e.FullPath); string fileName = Utility.GetFilenameFromPath(e.FullPath); foreach (var item in paths) { if (item.Source == dir) { InitFtp(); string filePath = item.Destination + "\\" + fileName; DTProcess dTProcess = new DTProcess(); dTProcess.SourceDir = filePath; dTProcess.Type = TypeProcess.DELETE; dTProcess.ftp = ftp; dTProcess.log = log; if (!fileProcessor.CheckExistProcess(dTProcess)) { fileProcessor.EnqueueProcess(dTProcess); log.Info("File : " + e.FullPath); } } } ftp.Close(); }
private void ProcessFile(DTProcess Process) { try { Process.Execute(); } catch (Exception) { throw; } }
public void EnqueueProcess(DTProcess Process) { if (processQueue.Contains(Process, new DTProcessComparer())) { return; } lock (locker) processQueue.Enqueue(Process); eventWaitHandle.Set(); }
public Dictionary <string, string> AutoMapFolderClientServer(string sourceDir, string desDir) { try { // upload folder client to server by loop DTProcess dTProcess = new DTProcess(); dTProcess.SourceDir = sourceDir; dTProcess.DesDir = desDir; dTProcess.SyncFolderClientToServer(); return(dTProcess.pairPath); } catch (Exception ex) { log.Error(ex.Message); ErrorMessage = ex.Message; return(null); } }
public void CopyAll(string sourceDir, string desDirs) { try { string[] fileList = Directory.GetFiles(sourceDir); foreach (string filePath in fileList) { try { string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1); string sourceFile = sourceDir + "\\" + filename; string desFile = desDirs + "\\" + filename; DTProcess dTProcess = new DTProcess(); dTProcess.SourceDir = sourceFile; dTProcess.DesDir = desFile; dTProcess.Type = TypeProcess.COPY; if (!fileProcessor.CheckExistProcess(dTProcess)) { fileProcessor.EnqueueProcess(dTProcess); log.Info("File: " + sourceFile); } } catch (Exception e) { log.Error(e.Message); } } } catch (Exception e) { log.Error(e.Message); } }
public bool CheckExistProcess(DTProcess Process) { return(processQueue.Contains(Process, new DTProcessComparer())); }