From afaeb0250dd3ca2d3efbff43747a86c34253d434 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Tue, 13 Dec 2016 12:28:38 +0100 Subject: [PATCH] refactoring --- BookAStar/BookAStar.Droid/MainActivity.cs | 2 +- BookAStar/BookAStar/App.xaml.cs | 26 ++++++++++------- BookAStar/BookAStar/BookAStar.csproj | 1 + BookAStar/BookAStar/Data/DataManager.cs | 16 +++++------ .../BookAStar/Model/Access/BlackListed.cs | 28 +++++++++++++++++++ .../BookAStar/Model/Workflow/Estimate.cs | 4 +-- .../BookAStar/Pages/Chat/ChatPage.xaml.cs | 4 +++ .../Pages/Chat/PrivateChatPage.xaml.cs | 4 +++ .../EstimatePages/BookQueriesPage.xaml.cs | 2 +- .../Pages/EstimatePages/BookQueryPage.xaml.cs | 8 +++--- .../EstimatePages/EditEstimatePage.xaml.cs | 12 ++++---- .../EstimatePages/EstimateSigningPage.xaml.cs | 6 ++-- .../Pages/UserProfile/UserFiles.xaml.cs | 6 ++-- .../BookQueriesViewModel.cs | 2 +- .../EstimateAndBilling/BookQueryViewModel.cs | 4 +-- .../ViewModels/Messaging/ChatViewModel.cs | 4 +-- .../UserProfile/DashboardViewModel.cs | 2 +- .../UserProfile/UserProfileViewModel.cs | 2 +- YavscLib/IBlackListed.cs | 2 +- YavscLib/YavscLib.csproj | 2 +- YavscLib/project.lock.json | 18 ++++++------ 21 files changed, 98 insertions(+), 57 deletions(-) create mode 100644 BookAStar/BookAStar/Model/Access/BlackListed.cs diff --git a/BookAStar/BookAStar.Droid/MainActivity.cs b/BookAStar/BookAStar.Droid/MainActivity.cs index 24c5dad9..6041f8e5 100644 --- a/BookAStar/BookAStar.Droid/MainActivity.cs +++ b/BookAStar/BookAStar.Droid/MainActivity.cs @@ -252,7 +252,7 @@ namespace BookAStar.Droid Task.Run(async () => { App.ShowBookQuery( - await DataManager.Current.BookQueries.Get(queryId)); + await DataManager.Instance.BookQueries.Get(queryId)); }); } } diff --git a/BookAStar/BookAStar/App.xaml.cs b/BookAStar/BookAStar/App.xaml.cs index 8e73b3cf..ce7000e6 100644 --- a/BookAStar/BookAStar/App.xaml.cs +++ b/BookAStar/BookAStar/App.xaml.cs @@ -107,10 +107,10 @@ namespace BookAStar { // TODO save the navigation stack int position = 0; - DataManager.Current.AppState.Clear(); + DataManager.Instance.AppState.Clear(); foreach (Page page in Navigation.NavigationStack) { - DataManager.Current.AppState.Add( + DataManager.Instance.AppState.Add( new PageState { Position = position++, @@ -118,7 +118,7 @@ namespace BookAStar BindingContext = page.BindingContext }); } - DataManager.Current.AppState.SaveEntity(); + DataManager.Instance.AppState.SaveEntity(); } // called on app startup, after OnStartup, not on rotation @@ -126,14 +126,20 @@ namespace BookAStar { // TODO restore the navigation stack base.OnResume(); - foreach (var pageState in DataManager.Current.AppState) + foreach (var pageState in DataManager.Instance.AppState) { - var pageType = Type.GetType(pageState.PageType); - NavigationService.NavigateTo( - pageType, true, pageState.BindingContext); + if (pageState.PageType != null) + { + 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.Current.AppState.SaveEntity(); + DataManager.Instance.AppState.Clear(); + DataManager.Instance.AppState.SaveEntity(); } // FIXME Not called? @@ -342,7 +348,7 @@ namespace BookAStar chatHubProxy = chatHubConnection.CreateHubProxy("ChatHub"); chatHubProxy.On("addPV", (n, m) => { - DataManager.Current.PrivateMessages.Add( + DataManager.Instance.PrivateMessages.Add( new ChatMessage { Message = m, diff --git a/BookAStar/BookAStar/BookAStar.csproj b/BookAStar/BookAStar/BookAStar.csproj index 7a4dd978..276a241c 100644 --- a/BookAStar/BookAStar/BookAStar.csproj +++ b/BookAStar/BookAStar/BookAStar.csproj @@ -56,6 +56,7 @@ + diff --git a/BookAStar/BookAStar/Data/DataManager.cs b/BookAStar/BookAStar/Data/DataManager.cs index 311a5f0d..6bb5dd38 100644 --- a/BookAStar/BookAStar/Data/DataManager.cs +++ b/BookAStar/BookAStar/Data/DataManager.cs @@ -7,6 +7,7 @@ using ViewModels.EstimateAndBilling; using NonCrUD; using ViewModels; + using Model.Access; public class DataManager { @@ -17,23 +18,22 @@ internal RemoteFilesEntity RemoteFiles { get; set; } public LocalEntity Contacts { get; set; } - internal LocalEntity AppState { get; set; } - // TODO internal RemoteEntity { get; set; } + internal RemoteEntity BlackList { get; set; } /// - /// They have no remote exisence ... + /// They've got no remote existence ... /// internal LocalEntity EstimationCache { get; set; } internal LocalEntity EstimateLinesTemplates { get; set; } internal LocalEntity PrivateMessages { get; set; } - protected static DataManager current ; + internal LocalEntity AppState { get; set; } + + protected static DataManager instance = new DataManager(); - public static DataManager Current + public static DataManager Instance { get { - if (current == null) - current = new DataManager(); - return current; + return instance; } } diff --git a/BookAStar/BookAStar/Model/Access/BlackListed.cs b/BookAStar/BookAStar/Model/Access/BlackListed.cs new file mode 100644 index 00000000..7e0866f2 --- /dev/null +++ b/BookAStar/BookAStar/Model/Access/BlackListed.cs @@ -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; + } + } +} diff --git a/BookAStar/BookAStar/Model/Workflow/Estimate.cs b/BookAStar/BookAStar/Model/Workflow/Estimate.cs index 2640e744..cf213a06 100644 --- a/BookAStar/BookAStar/Model/Workflow/Estimate.cs +++ b/BookAStar/BookAStar/Model/Workflow/Estimate.cs @@ -56,7 +56,7 @@ namespace BookAStar.Model.Workflow { if (CommandId.HasValue) { - var dm = DataManager.Current; + var dm = DataManager.Instance; return dm.BookQueries.LocalGet(CommandId.Value); } return null; @@ -67,7 +67,7 @@ namespace BookAStar.Model.Workflow { get { - return DataManager.Current.Contacts.LocalGet(ClientId); + return DataManager.Instance.Contacts.LocalGet(ClientId); } } diff --git a/BookAStar/BookAStar/Pages/Chat/ChatPage.xaml.cs b/BookAStar/BookAStar/Pages/Chat/ChatPage.xaml.cs index 3330b026..e29ccbe8 100644 --- a/BookAStar/BookAStar/Pages/Chat/ChatPage.xaml.cs +++ b/BookAStar/BookAStar/Pages/Chat/ChatPage.xaml.cs @@ -18,6 +18,10 @@ namespace BookAStar.Pages.Chat InitializeComponent(); Title = "Chat"; + ToolbarItems.Add(new ToolbarItem( + name: "...", + icon: null, + activated: () => { })); BindingContext = new ChatViewModel(); App.ChatHubConnection.StateChanged += ChatHubConnection_StateChanged; sendButton.Clicked += async (sender, args) => diff --git a/BookAStar/BookAStar/Pages/Chat/PrivateChatPage.xaml.cs b/BookAStar/BookAStar/Pages/Chat/PrivateChatPage.xaml.cs index 754164ce..3c6c5233 100644 --- a/BookAStar/BookAStar/Pages/Chat/PrivateChatPage.xaml.cs +++ b/BookAStar/BookAStar/Pages/Chat/PrivateChatPage.xaml.cs @@ -13,6 +13,10 @@ namespace BookAStar.Pages.Chat public PrivateChatPage() { InitializeComponent(); + ToolbarItems.Add(new ToolbarItem( + name: "...", + icon: null, + activated: () => { })); } } } diff --git a/BookAStar/BookAStar/Pages/EstimatePages/BookQueriesPage.xaml.cs b/BookAStar/BookAStar/Pages/EstimatePages/BookQueriesPage.xaml.cs index 3cfb96f4..2fe06982 100644 --- a/BookAStar/BookAStar/Pages/EstimatePages/BookQueriesPage.xaml.cs +++ b/BookAStar/BookAStar/Pages/EstimatePages/BookQueriesPage.xaml.cs @@ -17,7 +17,7 @@ namespace BookAStar.Pages var model = new BookQueriesViewModel(); model.RefreshQueries = new Command( () => { - DataManager.Current.BookQueries.Execute(null); + DataManager.Instance.BookQueries.Execute(null); this.list.EndRefresh(); }); diff --git a/BookAStar/BookAStar/Pages/EstimatePages/BookQueryPage.xaml.cs b/BookAStar/BookAStar/Pages/EstimatePages/BookQueryPage.xaml.cs index fb7b960f..d97efab5 100644 --- a/BookAStar/BookAStar/Pages/EstimatePages/BookQueryPage.xaml.cs +++ b/BookAStar/BookAStar/Pages/EstimatePages/BookQueryPage.xaml.cs @@ -65,13 +65,13 @@ namespace BookAStar.Pages if (editEstimateViewModel == null) { // First search for an existing estimate - editEstimateViewModel = DataManager.Current.EstimationCache.FirstOrDefault( + editEstimateViewModel = DataManager.Instance.EstimationCache.FirstOrDefault( estimate=> estimate.Query.Id == bookQueryViewModel.Id ); if (editEstimateViewModel == null) { - DataManager.Current.Contacts.Merge(BookQuery.Client); - DataManager.Current.Contacts.SaveEntity(); + DataManager.Instance.Contacts.Merge(BookQuery.Client); + DataManager.Instance.Contacts.SaveEntity(); editEstimateViewModel = new EditEstimateViewModel( new Estimate { ClientId = BookQuery.Client.UserId, @@ -79,7 +79,7 @@ namespace BookAStar.Pages OwnerId = MainSettings.CurrentUser.Id, Id = 0 }); - DataManager.Current.EstimationCache.Add(editEstimateViewModel); + DataManager.Instance.EstimationCache.Add(editEstimateViewModel); } } App.NavigationService.NavigateTo(true, diff --git a/BookAStar/BookAStar/Pages/EstimatePages/EditEstimatePage.xaml.cs b/BookAStar/BookAStar/Pages/EstimatePages/EditEstimatePage.xaml.cs index 9cd92e6a..163d8b12 100644 --- a/BookAStar/BookAStar/Pages/EstimatePages/EditEstimatePage.xaml.cs +++ b/BookAStar/BookAStar/Pages/EstimatePages/EditEstimatePage.xaml.cs @@ -44,7 +44,7 @@ namespace BookAStar.Pages 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) @@ -67,7 +67,7 @@ namespace BookAStar.Pages var lineView = new BillingLineViewModel(com) { ValidateCommand = new Command(() => { bill.Add(new BillingLineViewModel(com)); - DataManager.Current.EstimationCache.SaveEntity(); + DataManager.Instance.EstimationCache.SaveEntity(); })}; App.NavigationService.NavigateTo( true, lineView ); @@ -83,14 +83,14 @@ namespace BookAStar.Pages line.ValidateCommand = new Command(() => { evm.Check(); - DataManager.Current.EstimationCache.SaveEntity(); + DataManager.Instance.EstimationCache.SaveEntity(); }); // and setup a removal command, that was not expected at creation time line.RemoveCommand = new Command(() => { evm.Bill.Remove(line); evm.Check(); - DataManager.Current.EstimationCache.SaveEntity(); + DataManager.Instance.EstimationCache.SaveEntity(); }); App.NavigationService.NavigateTo( true, line ); @@ -105,8 +105,8 @@ namespace BookAStar.Pages var cmd = new Command( async (validated) => { if (validated) { - DataManager.Current.EstimationCache.Remove(evm); - DataManager.Current.EstimationCache.SaveEntity(); + DataManager.Instance.EstimationCache.Remove(evm); + DataManager.Instance.EstimationCache.SaveEntity(); } await thisPage.Navigation.PopAsync(); }); diff --git a/BookAStar/BookAStar/Pages/EstimatePages/EstimateSigningPage.xaml.cs b/BookAStar/BookAStar/Pages/EstimatePages/EstimateSigningPage.xaml.cs index 03dc4453..a975e099 100644 --- a/BookAStar/BookAStar/Pages/EstimatePages/EstimateSigningPage.xaml.cs +++ b/BookAStar/BookAStar/Pages/EstimatePages/EstimateSigningPage.xaml.cs @@ -22,7 +22,7 @@ namespace BookAStar.Pages.EstimatePages private async void OnValidate (object sender, EventArgs ev) { btnValidate.IsEnabled = false; - if (DataManager.Current.Estimates.IsExecuting) + if (DataManager.Instance.Estimates.IsExecuting) { await App.DisplayAlert(Strings.OperationPending, Strings.oups); return; @@ -32,8 +32,8 @@ namespace BookAStar.Pages.EstimatePages var estimate = evm.Data; var pngStream = await padView.GetImageStreamAsync(SignatureImageFormat.Png); pngStream.Seek(0, SeekOrigin.Begin); - DataManager.Current.Estimates.SignAsProvider(estimate, pngStream); - DataManager.Current.Estimates.SaveEntity(); + DataManager.Instance.Estimates.SignAsProvider(estimate, pngStream); + DataManager.Instance.Estimates.SaveEntity(); await Navigation.PopAsync(); var ParentValidationCommand = ((EstimateSigningViewModel)BindingContext).ValidationCommand; diff --git a/BookAStar/BookAStar/Pages/UserProfile/UserFiles.xaml.cs b/BookAStar/BookAStar/Pages/UserProfile/UserFiles.xaml.cs index 34de11ad..e86b9c51 100644 --- a/BookAStar/BookAStar/Pages/UserProfile/UserFiles.xaml.cs +++ b/BookAStar/BookAStar/Pages/UserProfile/UserFiles.xaml.cs @@ -12,7 +12,7 @@ namespace BookAStar.Pages.UserProfile public UserFiles() { InitializeComponent(); - var current = DataManager.Current.RemoteFiles.CurrentItem; + var current = DataManager.Instance.RemoteFiles.CurrentItem; if (current != null) BindingContext = new DirectoryInfoViewModel(current); else BindingContext = new DirectoryInfoViewModel @@ -33,8 +33,8 @@ namespace BookAStar.Pages.UserProfile if (model != null) model.RefreshCommand = new Command(() => { - DataManager.Current.RemoteFiles.Execute(null); - var item = DataManager.Current.RemoteFiles.CurrentItem; + DataManager.Instance.RemoteFiles.Execute(null); + var item = DataManager.Instance.RemoteFiles.CurrentItem; if (item != null) model.InnerModel = item; // this.dirlist.EndRefresh(); diff --git a/BookAStar/BookAStar/ViewModels/EstimateAndBilling/BookQueriesViewModel.cs b/BookAStar/BookAStar/ViewModels/EstimateAndBilling/BookQueriesViewModel.cs index cc3945e0..ae3ba388 100644 --- a/BookAStar/BookAStar/ViewModels/EstimateAndBilling/BookQueriesViewModel.cs +++ b/BookAStar/BookAStar/ViewModels/EstimateAndBilling/BookQueriesViewModel.cs @@ -12,7 +12,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling public BookQueriesViewModel() { queries = new ObservableCollection - (DataManager.Current.BookQueries.Select( + (DataManager.Instance.BookQueries.Select( q => new BookQueryViewModel(q))); } diff --git a/BookAStar/BookAStar/ViewModels/EstimateAndBilling/BookQueryViewModel.cs b/BookAStar/BookAStar/ViewModels/EstimateAndBilling/BookQueryViewModel.cs index 31ecc2cf..4147e636 100644 --- a/BookAStar/BookAStar/ViewModels/EstimateAndBilling/BookQueryViewModel.cs +++ b/BookAStar/BookAStar/ViewModels/EstimateAndBilling/BookQueryViewModel.cs @@ -30,7 +30,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling Previsionnal = data.Previsionnal; Id = data.Id; estimates = new ObservableCollection( - DataManager.Current.Estimates.Where( + DataManager.Instance.Estimates.Where( e => e.Query.Id == Id )); this.data = data; @@ -65,7 +65,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling { get { - return DataManager.Current.EstimationCache.LocalGet(this.Id); + return DataManager.Instance.EstimationCache.LocalGet(this.Id); } } private ObservableCollection estimates; diff --git a/BookAStar/BookAStar/ViewModels/Messaging/ChatViewModel.cs b/BookAStar/BookAStar/ViewModels/Messaging/ChatViewModel.cs index 7eaa0a8c..615c6d98 100644 --- a/BookAStar/BookAStar/ViewModels/Messaging/ChatViewModel.cs +++ b/BookAStar/BookAStar/ViewModels/Messaging/ChatViewModel.cs @@ -28,10 +28,10 @@ namespace BookAStar.ViewModels.Messaging MainSettings.UserChanged += MainSettings_UserChanged; Messages = new ObservableCollection(); Notifs = new ObservableCollection(); - PVs = DataManager.Current.PrivateMessages; + PVs = DataManager.Instance.PrivateMessages; Contacts = new ObservableCollection( - DataManager.Current.Contacts.Select(c=>new UserViewModel { Data = c })); + DataManager.Instance.Contacts.Select(c=>new UserViewModel { Data = c })); App.ChatHubProxy.On("addMessage", (n, m) => { Messages.Add(new ChatMessage diff --git a/BookAStar/BookAStar/ViewModels/UserProfile/DashboardViewModel.cs b/BookAStar/BookAStar/ViewModels/UserProfile/DashboardViewModel.cs index b567cda9..8c8b6454 100644 --- a/BookAStar/BookAStar/ViewModels/UserProfile/DashboardViewModel.cs +++ b/BookAStar/BookAStar/ViewModels/UserProfile/DashboardViewModel.cs @@ -192,7 +192,7 @@ namespace BookAStar.ViewModels.UserProfile { newUserIsPro = UserIsPro; - newQueryCount = newUserIsPro ? DataManager.Current.BookQueries.Count : 0; + newQueryCount = newUserIsPro ? DataManager.Instance.BookQueries.Count : 0; newStatusString = newUserIsPro ? $"Profile professionel renseigné" : diff --git a/BookAStar/BookAStar/ViewModels/UserProfile/UserProfileViewModel.cs b/BookAStar/BookAStar/ViewModels/UserProfile/UserProfileViewModel.cs index 5e18bab3..2b5143a9 100644 --- a/BookAStar/BookAStar/ViewModels/UserProfile/UserProfileViewModel.cs +++ b/BookAStar/BookAStar/ViewModels/UserProfile/UserProfileViewModel.cs @@ -198,7 +198,7 @@ namespace BookAStar.ViewModels.UserProfile { newUserIsPro = UserIsPro; - newQueryCount = newUserIsPro ? DataManager.Current.BookQueries.Count : 0; + newQueryCount = newUserIsPro ? DataManager.Instance.BookQueries.Count : 0; newStatusString = newUserIsPro ? $"Profile professionel renseigné" : diff --git a/YavscLib/IBlackListed.cs b/YavscLib/IBlackListed.cs index 3d898a4b..93723cb1 100644 --- a/YavscLib/IBlackListed.cs +++ b/YavscLib/IBlackListed.cs @@ -1,4 +1,4 @@ -namespace YavscLib +namespace Yavsc.Models { public interface IBlackListed { diff --git a/YavscLib/YavscLib.csproj b/YavscLib/YavscLib.csproj index 0305d7aa..fe316d96 100644 --- a/YavscLib/YavscLib.csproj +++ b/YavscLib/YavscLib.csproj @@ -57,7 +57,7 @@ - + diff --git a/YavscLib/project.lock.json b/YavscLib/project.lock.json index 29807b00..fff20ee0 100644 --- a/YavscLib/project.lock.json +++ b/YavscLib/project.lock.json @@ -3,21 +3,19 @@ "version": 2, "targets": { ".NETFramework,Version=v4.5.1": {}, - ".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": {} + ".NETPortable,Version=v4.5,Profile=Profile111": {} }, "libraries": {}, "projectFileDependencyGroups": { "": [], ".NETFramework,Version=v4.5.1": [], ".NETPortable,Version=v4.5,Profile=Profile111": [ - "fx/System.Runtime >= 4.0.0", - "fx/System.Globalization >= 4.0.0", - "fx/System.Resources.ResourceManager >= 4.0.0", - "fx/System.Resources.Reader >= 4.0.0" + "System.Globalization >= 4.0.0", + "System.Resources.Reader >= 4.0.0", + "System.Resources.ResourceManager >= 4.0.0", + "System.Runtime >= 4.0.0" ] - } + }, + "tools": {}, + "projectFileToolGroups": {} } \ No newline at end of file