|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CBR.Core.Models;
using CBR.Core.Helpers;
using System.IO;
namespace CBR.Core.Services
{
/// <summary>
/// Provide access to the workspace settings
/// </summary>
public class WorkspaceService
{
#region ----------------SINGLETON----------------
public static readonly WorkspaceService Instance = new WorkspaceService();
/// <summary>
/// Private constructor for singleton pattern
/// </summary>
private WorkspaceService()
{
}
#endregion
#region ----------------PROPERTIES----------------
private WorkspaceInfo _Settings = new WorkspaceInfo();
public WorkspaceInfo Settings
{
get { return _Settings; }
set
{
if (value != null && value != _Settings) _Settings = value;
}
}
#endregion
#region ----------------METHODS----------------
public void AddRecent(Catalog catlog)
{
if (Settings.RecentCatalogList == null)
Settings.RecentCatalogList = new List<RecentFileInfo>();
Add(Path.GetDirectoryName(catlog.CatalogFilePath), Path.GetFileName(catlog.CatalogFilePath), Settings.RecentCatalogList);
}
public void AddRecent(Book bk)
{
if (Settings.RecentFileList == null)
Settings.RecentFileList = new List<RecentFileInfo>();
Add(Path.GetDirectoryName(bk.FilePath), Path.GetFileName(bk.FilePath), Settings.RecentFileList);
}
internal void Add(string filePath, string fileName, List<RecentFileInfo> list)
{
try
{
RecentFileInfo rfi = list.Find(p => p.FileName == fileName && p.FilePath == filePath);
if (rfi == null)
{
list.Add(new RecentFileInfo()
{
FilePath = filePath,
FileName = fileName,
IsPined = false,
LastAccess = DateTime.Now
});
Mediator.Instance.NotifyColleagues(ViewModelBaseMessages.RecentListChanged, list);
}
else
{
rfi.LastAccess = DateTime.Now;
Mediator.Instance.NotifyColleagues(ViewModelBaseMessages.RecentFileChanged, rfi);
}
//check the max
int execiding = list.Count - Settings.MaxRecentFile;
if (execiding > 0)
{
List<RecentFileInfo> temp = new List<RecentFileInfo>();
temp.AddRange(list.OrderBy(o => o.LastAccess).Where(p => p.IsPined == false));
for (int i = 0; i < execiding; i++)
list.Remove(temp[i]);
Mediator.Instance.NotifyColleagues(ViewModelBaseMessages.RecentListChanged, list);
}
}
catch (Exception err)
{
ExceptionHelper.Manage("CatalogService:Load", err);
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
WPF and MVVM fan, I practice C # in all its forms from the beginning of the NET Framework without mentioning C ++ / MFC and other software packages such as databases, ASP, WCF, Web & Windows services, Application, and now Core and UWP.
In my wasted hours, I am guilty of having fathered C.B.R. and its cousins C.B.R. for WinRT and UWP on the Windows store.
But apart from that, I am a great handyman ... the house, a rocket stove to heat the jacuzzi and the last one: a wood oven for pizza, bread, and everything that goes inside
https://guillaumewaser.wordpress.com/
https://fouretcompagnie.wordpress.com/