//----------------------make the actual file and get the new id back--------------------------- public string CreateNewFile(string body, string path) { string ID = ""; int data = 0; int current = 0; string filename = ""; string theWay = (AppDomain.CurrentDomain.BaseDirectory + path); //DirectoryInfo directory = new DirectoryInfo(theWay); FileInfo[] files = _fileHandler.GetFileInfo(theWay); //if there is no file in the folder yet; if (files.Length < 1) { filename = (theWay + "/" + "1.txt"); _fileHandler.NewMessage(body, filename); /*using (StreamWriter sw = File.CreateText(filename)) * { * sw.WriteLine(body); * } */ ID = "Created new Id: 1"; return(ID); } //if there are other files check the names of the files (names should all be number + .txt) foreach (var item in files) { String checkout = item.ToString(); checkout = checkout.Substring(checkout.LastIndexOf('\\') + 1); checkout = checkout.Remove(checkout.LastIndexOf('.')); current = Int16.Parse(checkout); if (current > data) { data = current; } } data++; filename = (theWay + "/" + data.ToString() + ".txt"); _fileHandler.NewMessage(body, filename); /*using (StreamWriter sw = File.CreateText(filename)) * { * sw.WriteLine(body); * }*/ ID = ("Created new Id: " + data.ToString()); return(ID); }
private static FileDiff GetFileDiff(Sync sync, IFileHandler contentFileHandler, IFileHandler outputFileHandler) { var sourceInfo = contentFileHandler.GetFileInfo(sync.SourcePath); var targetInfo = outputFileHandler.GetFileInfo(sync.TargetPath); if (sourceInfo.Exists == true && targetInfo.Exists == false) { return(FileDiff.DiffTargetMissing); } if (sourceInfo.Exists == false && targetInfo.Exists == true) { return(FileDiff.DiffSourceMissing); } //if (sourceInfo.Attributes != targetInfo.Attributes) //{ // return FileDiff.DiffContent; //} if (FileComparer.FilesContentsAreEqual(sourceInfo, targetInfo)) { return(FileDiff.Equal); } if (sourceInfo.LastWriteTime < targetInfo.LastWriteTime) { return(FileDiff.DiffTargetNewer); } if (targetInfo.LastWriteTime < sourceInfo.LastWriteTime) { return(FileDiff.DiffSourceNewer); } return(FileDiff.DiffContent); }