public void MoveLater(string id) { var oldItemOldName = GetFileNameFromId(id); var oldItemIndex = oldItemOldName.Index; var newItemIndex = oldItemIndex - 1; var oldItemNewName = new NewsItemFileName(id, newItemIndex); var newItemOldName = GetFileNameFromIndex(newItemIndex); var newItemNewName = new NewsItemFileName(newItemOldName.Id, oldItemIndex); var tempFileName = Path.GetTempFileName(); var newItemOldInfo = GetFileInfo(newItemOldName); var oldFileOldInfo = GetFileInfo(oldItemOldName); var tempFileInfo = new FileInfo(tempFileName); tempFileInfo.Delete(); newItemOldInfo.MoveTo(tempFileName); oldFileOldInfo.MoveTo(GetFileInfo(oldItemNewName).FullName); tempFileInfo.MoveTo(GetFileInfo(newItemNewName).FullName); }
private string GetFullFileName(NewsItemFileName fileName) { return Path.Combine(_newsDirectory.FullName, Path.ChangeExtension(fileName.FileName, NewsItemExtension)); }
private NewsItem GetItemByFileName(NewsItemFileName fileName) { var fullFileName = GetFullFileName(fileName); var lines = File.ReadAllLines(fullFileName); return new NewsItem { Id = fileName.Id, Title = lines[0], ReleaseDate = DateTime.ParseExact(lines[1], ReleaseDateFormat, CultureInfo.InvariantCulture), Content = lines.Skip(2).Aggregate((x, y) => x + y) }; }
private FileInfo GetFileInfo(NewsItemFileName fileName) { return new FileInfo(GetFullFileName(fileName)); }