Exemple #1
0
 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);
 }
Exemple #2
0
 private string GetFullFileName(NewsItemFileName fileName)
 {
     return Path.Combine(_newsDirectory.FullName, Path.ChangeExtension(fileName.FileName, NewsItemExtension));
 }
Exemple #3
0
 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)
         };
 }
Exemple #4
0
 private FileInfo GetFileInfo(NewsItemFileName fileName)
 {
     return new FileInfo(GetFullFileName(fileName));
 }