refactoring

main
Paul Schneider 9 years ago
parent 367b68e093
commit afaeb0250d
21 changed files with 98 additions and 57 deletions

@ -252,7 +252,7 @@ namespace BookAStar.Droid
Task.Run(async () => Task.Run(async () =>
{ {
App.ShowBookQuery( App.ShowBookQuery(
await DataManager.Current.BookQueries.Get(queryId)); await DataManager.Instance.BookQueries.Get(queryId));
}); });
} }
} }

@ -107,10 +107,10 @@ namespace BookAStar
{ {
// TODO save the navigation stack // TODO save the navigation stack
int position = 0; int position = 0;
DataManager.Current.AppState.Clear(); DataManager.Instance.AppState.Clear();
foreach (Page page in Navigation.NavigationStack) foreach (Page page in Navigation.NavigationStack)
{ {
DataManager.Current.AppState.Add( DataManager.Instance.AppState.Add(
new PageState new PageState
{ {
Position = position++, Position = position++,
@ -118,7 +118,7 @@ namespace BookAStar
BindingContext = page.BindingContext BindingContext = page.BindingContext
}); });
} }
DataManager.Current.AppState.SaveEntity(); DataManager.Instance.AppState.SaveEntity();
} }
// called on app startup, after OnStartup, not on rotation // called on app startup, after OnStartup, not on rotation
@ -126,14 +126,20 @@ namespace BookAStar
{ {
// TODO restore the navigation stack // TODO restore the navigation stack
base.OnResume(); base.OnResume();
foreach (var pageState in DataManager.Current.AppState) foreach (var pageState in DataManager.Instance.AppState)
{ {
var pageType = Type.GetType(pageState.PageType); if (pageState.PageType != null)
NavigationService.NavigateTo( {
pageType, true, pageState.BindingContext); var pageType = Type.GetType(pageState.PageType);
if (pageState.BindingContext != null)
NavigationService.NavigateTo(
pageType, false, pageState.BindingContext);
else NavigationService.NavigateTo(
pageType, false);
}
} }
DataManager.Current.AppState.Clear(); DataManager.Instance.AppState.Clear();
DataManager.Current.AppState.SaveEntity(); DataManager.Instance.AppState.SaveEntity();
} }
// FIXME Not called? // FIXME Not called?
@ -342,7 +348,7 @@ namespace BookAStar
chatHubProxy = chatHubConnection.CreateHubProxy("ChatHub"); chatHubProxy = chatHubConnection.CreateHubProxy("ChatHub");
chatHubProxy.On<string, string>("addPV", (n, m) => { chatHubProxy.On<string, string>("addPV", (n, m) => {
DataManager.Current.PrivateMessages.Add( DataManager.Instance.PrivateMessages.Add(
new ChatMessage new ChatMessage
{ {
Message = m, Message = m,

@ -56,6 +56,7 @@
<Compile Include="Data\ApiCallFailedException.cs" /> <Compile Include="Data\ApiCallFailedException.cs" />
<Compile Include="Data\EstimateEntity.cs" /> <Compile Include="Data\EstimateEntity.cs" />
<Compile Include="Data\NonCrUD\RemoteFiles.cs" /> <Compile Include="Data\NonCrUD\RemoteFiles.cs" />
<Compile Include="Model\Access\BlackListed.cs" />
<Compile Include="Model\FileSystem\UserDirectoryInfo.cs" /> <Compile Include="Model\FileSystem\UserDirectoryInfo.cs" />
<Compile Include="Model\FileSystem\UserFileInfo.cs" /> <Compile Include="Model\FileSystem\UserFileInfo.cs" />
<Compile Include="Model\Settings\SignatureSettings.cs" /> <Compile Include="Model\Settings\SignatureSettings.cs" />

@ -7,6 +7,7 @@
using ViewModels.EstimateAndBilling; using ViewModels.EstimateAndBilling;
using NonCrUD; using NonCrUD;
using ViewModels; using ViewModels;
using Model.Access;
public class DataManager public class DataManager
{ {
@ -17,23 +18,22 @@
internal RemoteFilesEntity RemoteFiles { get; set; } internal RemoteFilesEntity RemoteFiles { get; set; }
public LocalEntity<ClientProviderInfo, string> Contacts { get; set; } public LocalEntity<ClientProviderInfo, string> Contacts { get; set; }
internal LocalEntity<PageState, int> AppState { get; set; } internal RemoteEntity<BlackListed, long> BlackList { get; set; }
// TODO internal RemoteEntity<Blacklisted, long> { get; set; }
/// <summary> /// <summary>
/// They have no remote exisence ... /// They've got no remote existence ...
/// </summary> /// </summary>
internal LocalEntity<EditEstimateViewModel, long> EstimationCache { get; set; } internal LocalEntity<EditEstimateViewModel, long> EstimationCache { get; set; }
internal LocalEntity<BillingLine, string> EstimateLinesTemplates { get; set; } internal LocalEntity<BillingLine, string> EstimateLinesTemplates { get; set; }
internal LocalEntity<ChatMessage, int> PrivateMessages { get; set; } internal LocalEntity<ChatMessage, int> PrivateMessages { get; set; }
protected static DataManager current ; internal LocalEntity<PageState, int> AppState { get; set; }
protected static DataManager instance = new DataManager();
public static DataManager Current public static DataManager Instance
{ {
get get
{ {
if (current == null) return instance;
current = new DataManager();
return current;
} }
} }

@ -0,0 +1,28 @@
using BookAStar.Model.Access;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yavsc.Models;
namespace BookAStar.Model.Access
{
class BlackListed : IBlackListed
{
public long Id
{
get; set;
}
public string OwnerId
{
get; set;
}
public string UserId
{
get; set;
}
}
}

@ -56,7 +56,7 @@ namespace BookAStar.Model.Workflow
{ {
if (CommandId.HasValue) if (CommandId.HasValue)
{ {
var dm = DataManager.Current; var dm = DataManager.Instance;
return dm.BookQueries.LocalGet(CommandId.Value); return dm.BookQueries.LocalGet(CommandId.Value);
} }
return null; return null;
@ -67,7 +67,7 @@ namespace BookAStar.Model.Workflow
{ {
get get
{ {
return DataManager.Current.Contacts.LocalGet(ClientId); return DataManager.Instance.Contacts.LocalGet(ClientId);
} }
} }

@ -18,6 +18,10 @@ namespace BookAStar.Pages.Chat
InitializeComponent(); InitializeComponent();
Title = "Chat"; Title = "Chat";
ToolbarItems.Add(new ToolbarItem(
name: "...",
icon: null,
activated: () => { }));
BindingContext = new ChatViewModel(); BindingContext = new ChatViewModel();
App.ChatHubConnection.StateChanged += ChatHubConnection_StateChanged; App.ChatHubConnection.StateChanged += ChatHubConnection_StateChanged;
sendButton.Clicked += async (sender, args) => sendButton.Clicked += async (sender, args) =>

@ -13,6 +13,10 @@ namespace BookAStar.Pages.Chat
public PrivateChatPage() public PrivateChatPage()
{ {
InitializeComponent(); InitializeComponent();
ToolbarItems.Add(new ToolbarItem(
name: "...",
icon: null,
activated: () => { }));
} }
} }
} }

@ -17,7 +17,7 @@ namespace BookAStar.Pages
var model = new BookQueriesViewModel(); var model = new BookQueriesViewModel();
model.RefreshQueries = model.RefreshQueries =
new Command( () => { new Command( () => {
DataManager.Current.BookQueries.Execute(null); DataManager.Instance.BookQueries.Execute(null);
this.list.EndRefresh(); this.list.EndRefresh();
}); });

@ -65,13 +65,13 @@ namespace BookAStar.Pages
if (editEstimateViewModel == null) if (editEstimateViewModel == null)
{ {
// First search for an existing estimate // First search for an existing estimate
editEstimateViewModel = DataManager.Current.EstimationCache.FirstOrDefault( editEstimateViewModel = DataManager.Instance.EstimationCache.FirstOrDefault(
estimate=> estimate.Query.Id == bookQueryViewModel.Id estimate=> estimate.Query.Id == bookQueryViewModel.Id
); );
if (editEstimateViewModel == null) if (editEstimateViewModel == null)
{ {
DataManager.Current.Contacts.Merge(BookQuery.Client); DataManager.Instance.Contacts.Merge(BookQuery.Client);
DataManager.Current.Contacts.SaveEntity(); DataManager.Instance.Contacts.SaveEntity();
editEstimateViewModel = new EditEstimateViewModel( new Estimate editEstimateViewModel = new EditEstimateViewModel( new Estimate
{ {
ClientId = BookQuery.Client.UserId, ClientId = BookQuery.Client.UserId,
@ -79,7 +79,7 @@ namespace BookAStar.Pages
OwnerId = MainSettings.CurrentUser.Id, OwnerId = MainSettings.CurrentUser.Id,
Id = 0 Id = 0
}); });
DataManager.Current.EstimationCache.Add(editEstimateViewModel); DataManager.Instance.EstimationCache.Add(editEstimateViewModel);
} }
} }
App.NavigationService.NavigateTo<EditEstimatePage>(true, App.NavigationService.NavigateTo<EditEstimatePage>(true,

@ -44,7 +44,7 @@ namespace BookAStar.Pages
private void EditEstimatePage_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) private void EditEstimatePage_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
DataManager.Current.EstimationCache.SaveEntity(); DataManager.Instance.EstimationCache.SaveEntity();
} }
protected override void OnSizeAllocated(double width, double height) protected override void OnSizeAllocated(double width, double height)
@ -67,7 +67,7 @@ namespace BookAStar.Pages
var lineView = new BillingLineViewModel(com) var lineView = new BillingLineViewModel(com)
{ ValidateCommand = new Command(() => { { ValidateCommand = new Command(() => {
bill.Add(new BillingLineViewModel(com)); bill.Add(new BillingLineViewModel(com));
DataManager.Current.EstimationCache.SaveEntity(); DataManager.Instance.EstimationCache.SaveEntity();
})}; })};
App.NavigationService.NavigateTo<EditBillingLinePage>( App.NavigationService.NavigateTo<EditBillingLinePage>(
true, lineView ); true, lineView );
@ -83,14 +83,14 @@ namespace BookAStar.Pages
line.ValidateCommand = new Command(() => line.ValidateCommand = new Command(() =>
{ {
evm.Check(); evm.Check();
DataManager.Current.EstimationCache.SaveEntity(); DataManager.Instance.EstimationCache.SaveEntity();
}); });
// and setup a removal command, that was not expected at creation time // and setup a removal command, that was not expected at creation time
line.RemoveCommand = new Command(() => line.RemoveCommand = new Command(() =>
{ {
evm.Bill.Remove(line); evm.Bill.Remove(line);
evm.Check(); evm.Check();
DataManager.Current.EstimationCache.SaveEntity(); DataManager.Instance.EstimationCache.SaveEntity();
}); });
App.NavigationService.NavigateTo<EditBillingLinePage>( App.NavigationService.NavigateTo<EditBillingLinePage>(
true, line ); true, line );
@ -105,8 +105,8 @@ namespace BookAStar.Pages
var cmd = new Command<bool>( async (validated) => var cmd = new Command<bool>( async (validated) =>
{ {
if (validated) { if (validated) {
DataManager.Current.EstimationCache.Remove(evm); DataManager.Instance.EstimationCache.Remove(evm);
DataManager.Current.EstimationCache.SaveEntity(); DataManager.Instance.EstimationCache.SaveEntity();
} }
await thisPage.Navigation.PopAsync(); await thisPage.Navigation.PopAsync();
}); });

@ -22,7 +22,7 @@ namespace BookAStar.Pages.EstimatePages
private async void OnValidate (object sender, EventArgs ev) private async void OnValidate (object sender, EventArgs ev)
{ {
btnValidate.IsEnabled = false; btnValidate.IsEnabled = false;
if (DataManager.Current.Estimates.IsExecuting) if (DataManager.Instance.Estimates.IsExecuting)
{ {
await App.DisplayAlert(Strings.OperationPending, Strings.oups); await App.DisplayAlert(Strings.OperationPending, Strings.oups);
return; return;
@ -32,8 +32,8 @@ namespace BookAStar.Pages.EstimatePages
var estimate = evm.Data; var estimate = evm.Data;
var pngStream = await padView.GetImageStreamAsync(SignatureImageFormat.Png); var pngStream = await padView.GetImageStreamAsync(SignatureImageFormat.Png);
pngStream.Seek(0, SeekOrigin.Begin); pngStream.Seek(0, SeekOrigin.Begin);
DataManager.Current.Estimates.SignAsProvider(estimate, pngStream); DataManager.Instance.Estimates.SignAsProvider(estimate, pngStream);
DataManager.Current.Estimates.SaveEntity(); DataManager.Instance.Estimates.SaveEntity();
await Navigation.PopAsync(); await Navigation.PopAsync();
var ParentValidationCommand = ((EstimateSigningViewModel)BindingContext).ValidationCommand; var ParentValidationCommand = ((EstimateSigningViewModel)BindingContext).ValidationCommand;

@ -12,7 +12,7 @@ namespace BookAStar.Pages.UserProfile
public UserFiles() public UserFiles()
{ {
InitializeComponent(); InitializeComponent();
var current = DataManager.Current.RemoteFiles.CurrentItem; var current = DataManager.Instance.RemoteFiles.CurrentItem;
if (current != null) if (current != null)
BindingContext = new DirectoryInfoViewModel(current); BindingContext = new DirectoryInfoViewModel(current);
else BindingContext = new DirectoryInfoViewModel else BindingContext = new DirectoryInfoViewModel
@ -33,8 +33,8 @@ namespace BookAStar.Pages.UserProfile
if (model != null) if (model != null)
model.RefreshCommand = new Command(() => model.RefreshCommand = new Command(() =>
{ {
DataManager.Current.RemoteFiles.Execute(null); DataManager.Instance.RemoteFiles.Execute(null);
var item = DataManager.Current.RemoteFiles.CurrentItem; var item = DataManager.Instance.RemoteFiles.CurrentItem;
if (item != null) if (item != null)
model.InnerModel = item; model.InnerModel = item;
// this.dirlist.EndRefresh(); // this.dirlist.EndRefresh();

@ -12,7 +12,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling
public BookQueriesViewModel() public BookQueriesViewModel()
{ {
queries = new ObservableCollection<BookQueryViewModel> queries = new ObservableCollection<BookQueryViewModel>
(DataManager.Current.BookQueries.Select( (DataManager.Instance.BookQueries.Select(
q => q =>
new BookQueryViewModel(q))); new BookQueryViewModel(q)));
} }

@ -30,7 +30,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling
Previsionnal = data.Previsionnal; Previsionnal = data.Previsionnal;
Id = data.Id; Id = data.Id;
estimates = new ObservableCollection<Estimate>( estimates = new ObservableCollection<Estimate>(
DataManager.Current.Estimates.Where( DataManager.Instance.Estimates.Where(
e => e.Query.Id == Id e => e.Query.Id == Id
)); ));
this.data = data; this.data = data;
@ -65,7 +65,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling
{ {
get get
{ {
return DataManager.Current.EstimationCache.LocalGet(this.Id); return DataManager.Instance.EstimationCache.LocalGet(this.Id);
} }
} }
private ObservableCollection<Estimate> estimates; private ObservableCollection<Estimate> estimates;

@ -28,10 +28,10 @@ namespace BookAStar.ViewModels.Messaging
MainSettings.UserChanged += MainSettings_UserChanged; MainSettings.UserChanged += MainSettings_UserChanged;
Messages = new ObservableCollection<ChatMessage>(); Messages = new ObservableCollection<ChatMessage>();
Notifs = new ObservableCollection<ChatMessage>(); Notifs = new ObservableCollection<ChatMessage>();
PVs = DataManager.Current.PrivateMessages; PVs = DataManager.Instance.PrivateMessages;
Contacts = Contacts =
new ObservableCollection<UserViewModel>( new ObservableCollection<UserViewModel>(
DataManager.Current.Contacts.Select(c=>new UserViewModel { Data = c })); DataManager.Instance.Contacts.Select(c=>new UserViewModel { Data = c }));
App.ChatHubProxy.On<string, string>("addMessage", (n, m) => App.ChatHubProxy.On<string, string>("addMessage", (n, m) =>
{ {
Messages.Add(new ChatMessage Messages.Add(new ChatMessage

@ -192,7 +192,7 @@ namespace BookAStar.ViewModels.UserProfile
{ {
newUserIsPro = UserIsPro; newUserIsPro = UserIsPro;
newQueryCount = newUserIsPro ? DataManager.Current.BookQueries.Count : 0; newQueryCount = newUserIsPro ? DataManager.Instance.BookQueries.Count : 0;
newStatusString = newUserIsPro ? newStatusString = newUserIsPro ?
$"Profile professionel renseigné" : $"Profile professionel renseigné" :

@ -198,7 +198,7 @@ namespace BookAStar.ViewModels.UserProfile
{ {
newUserIsPro = UserIsPro; newUserIsPro = UserIsPro;
newQueryCount = newUserIsPro ? DataManager.Current.BookQueries.Count : 0; newQueryCount = newUserIsPro ? DataManager.Instance.BookQueries.Count : 0;
newStatusString = newUserIsPro ? newStatusString = newUserIsPro ?
$"Profile professionel renseigné" : $"Profile professionel renseigné" :

@ -1,4 +1,4 @@
namespace YavscLib namespace Yavsc.Models
{ {
public interface IBlackListed public interface IBlackListed
{ {

@ -57,7 +57,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="project.json" /> <Content Include="project.json" />
<Content Include="IBlackListed.cs" /> <Compile Include="IBlackListed.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

@ -3,21 +3,19 @@
"version": 2, "version": 2,
"targets": { "targets": {
".NETFramework,Version=v4.5.1": {}, ".NETFramework,Version=v4.5.1": {},
".NETPortable,Version=v4.5,Profile=Profile111": {}, ".NETPortable,Version=v4.5,Profile=Profile111": {}
".NETFramework,Version=v4.5.1/debian.8-x86": {},
".NETFramework,Version=v4.5.1/debian.8-x64": {},
".NETPortable,Version=v4.5,Profile=Profile111/debian.8-x86": {},
".NETPortable,Version=v4.5,Profile=Profile111/debian.8-x64": {}
}, },
"libraries": {}, "libraries": {},
"projectFileDependencyGroups": { "projectFileDependencyGroups": {
"": [], "": [],
".NETFramework,Version=v4.5.1": [], ".NETFramework,Version=v4.5.1": [],
".NETPortable,Version=v4.5,Profile=Profile111": [ ".NETPortable,Version=v4.5,Profile=Profile111": [
"fx/System.Runtime >= 4.0.0", "System.Globalization >= 4.0.0",
"fx/System.Globalization >= 4.0.0", "System.Resources.Reader >= 4.0.0",
"fx/System.Resources.ResourceManager >= 4.0.0", "System.Resources.ResourceManager >= 4.0.0",
"fx/System.Resources.Reader >= 4.0.0" "System.Runtime >= 4.0.0"
] ]
} },
"tools": {},
"projectFileToolGroups": {}
} }
Loading…