diff --git a/BookAStar/BookAStar/App.xaml.cs b/BookAStar/BookAStar/App.xaml.cs index a339ede9..b5a00742 100644 --- a/BookAStar/BookAStar/App.xaml.cs +++ b/BookAStar/BookAStar/App.xaml.cs @@ -25,6 +25,7 @@ namespace BookAStar using ViewModels.UserProfile; using Pages.UserProfile; using ViewModels.EstimateAndBilling; + using System.Net; public partial class App : Application // superclass new in 1.3 { @@ -109,7 +110,7 @@ namespace BookAStar BindingContext = page.BindingContext }); } - DataManager.Current.AppState.SaveCollection(); + DataManager.Current.AppState.SaveEntity(); } // called on app startup, after OnStartup, not on rotation @@ -124,7 +125,7 @@ namespace BookAStar pageType, true, pageState.BindingContext); } DataManager.Current.AppState.Clear(); - DataManager.Current.AppState.SaveCollection(); + DataManager.Current.AppState.SaveEntity(); } // FIXME Not called? @@ -206,6 +207,7 @@ namespace BookAStar masterDetail.Detail = new NavigationPage(home); ToolbarItem tiSetts = new ToolbarItem() { + // FIXME what for? Priority = 0, Text = "Paramètres", Icon = "ic_corp_icon.png", Command = new Command( @@ -290,7 +292,19 @@ namespace BookAStar // Start the Hub connection public async void StartHubConnection () { - await chatHubConnection.Start(); + try + { + await chatHubConnection.Start(); + } + catch (WebException webex ) + { + // TODO use webex, set this cx down status somewhere, + // & display it & maybe try again later. + } + catch (Exception ex) + { + // TODO use ex + } } public void SetupHubConnection() diff --git a/BookAStar/BookAStar/BookAStar.csproj b/BookAStar/BookAStar/BookAStar.csproj index b4071ac0..a686bc5d 100644 --- a/BookAStar/BookAStar/BookAStar.csproj +++ b/BookAStar/BookAStar/BookAStar.csproj @@ -61,6 +61,9 @@ UserFiles.xaml + + UserProfilePage.xaml + @@ -78,7 +81,6 @@ - @@ -422,6 +424,12 @@ Designer + + + MSBuild:UpdateDesignTimeXaml + Designer + + diff --git a/BookAStar/BookAStar/Data/DataManager.cs b/BookAStar/BookAStar/Data/DataManager.cs index bd3b3c98..84e08776 100644 --- a/BookAStar/BookAStar/Data/DataManager.cs +++ b/BookAStar/BookAStar/Data/DataManager.cs @@ -7,6 +7,7 @@ using Model.Social.Messaging; using Model.FileSystem; using ViewModels.EstimateAndBilling; + using NonCrUD; public class DataManager { @@ -14,7 +15,7 @@ public RemoteEntityRO BookQueries { get; set; } public RemoteEntity Estimates { get; set; } public RemoteEntity Blogspot { get; set; } - internal RemoteEntity RemoteFiles { get; set; } + internal RemoteFilesEntity RemoteFiles { get; set; } public LocalEntity Contacts { get; set; } internal LocalEntity AppState { get; set; } @@ -48,7 +49,7 @@ EstimationCache = new LocalEntity(e => e.Query.Id); EstimateLinesTemplates = new LocalEntity(l => l.Description); PrivateMessages = new LocalEntity(m=> m.GetHashCode()); - RemoteFiles = new RemoteEntity ("fs", d => d.SubPath); + RemoteFiles = new RemoteFilesEntity (); PrivateMessages.Load(); BookQueries.Load(); diff --git a/BookAStar/BookAStar/Data/LocaLEntity.cs b/BookAStar/BookAStar/Data/LocaLEntity.cs index 56d800ce..9b6013f6 100644 --- a/BookAStar/BookAStar/Data/LocaLEntity.cs +++ b/BookAStar/BookAStar/Data/LocaLEntity.cs @@ -40,14 +40,24 @@ namespace BookAStar.Data return CurrentItem; } - public void Load() + public virtual bool Load() { - this.Populate(); + return this.Populate(); } - public void Load(string subKey) + public virtual bool Load(string subKey) { - this.Populate(subKey); + return (this.Populate(subKey)); + } + public virtual bool Seek(int index) + { + + if (this.Count>index && index >=0) + { + CurrentItem = this[index]; + return true; + } + return false; } } diff --git a/BookAStar/BookAStar/Data/NonCrUD/RemoteFiles.cs b/BookAStar/BookAStar/Data/NonCrUD/RemoteFiles.cs index 01878198..aa7e6eaa 100644 --- a/BookAStar/BookAStar/Data/NonCrUD/RemoteFiles.cs +++ b/BookAStar/BookAStar/Data/NonCrUD/RemoteFiles.cs @@ -6,10 +6,17 @@ namespace BookAStar.Data.NonCrUD { using Helpers; using Model.FileSystem; - - public class RemoteFiles : RemoteEntity + using System.Linq; + /* + public class DirectoryEntryChangingEvent : EventArgs { - public RemoteFiles() : base("fs", d => d) + public UserDirectoryInfo OldItem { get; set; } + public UserDirectoryInfo NewItem { get; set; } + }*/ + + public class RemoteFilesEntity : RemoteEntity + { + public RemoteFilesEntity() : base("fs", d => d) { } @@ -23,14 +30,15 @@ namespace BookAStar.Data.NonCrUD try { var subpath = parameter as string; - string path = ControllerUri.AbsolutePath + ((subpath != null) ? "/" + subpath : null); - using (var response = await client.GetAsync(ControllerUri)) + string path = ControllerUri.AbsoluteUri + ((subpath != null) ? "/" + subpath : null); + using (var response = await client.GetAsync(path)) { if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); var di = JsonConvert.DeserializeObject(content); this.Merge(di); + this.SaveEntity(); } else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) throw new Exception("Bad request"); @@ -43,8 +51,32 @@ namespace BookAStar.Data.NonCrUD throw new Exception("Remote call failed", ex); } } + AfterExecuting(); } - + /* + public override void Merge(UserDirectoryInfo item) + { + var key = GetKey(item); + DirectoryEntryChangingEvent itemChanged = null; + if (this.Any(x => GetKey(x).Equals(key))) + { + var old = LocalGet(key); + itemChanged = new DirectoryEntryChangingEvent + { + OldItem = old, + NewItem = item + }; + Remove(old); + } + Add(item); + CurrentItem = item; + if (DirectoryEntryChanged != null && itemChanged != null) + DirectoryEntryChanged.Invoke(this, itemChanged); + } + + public event EventHandler DirectoryEntryChanged; + */ + } } diff --git a/BookAStar/BookAStar/Data/RemoteEntity.cs b/BookAStar/BookAStar/Data/RemoteEntity.cs index 96bbb9df..3a4b8b62 100644 --- a/BookAStar/BookAStar/Data/RemoteEntity.cs +++ b/BookAStar/BookAStar/Data/RemoteEntity.cs @@ -65,7 +65,7 @@ namespace BookAStar.Data { Merge(item); } - this.SaveCollection(); + this.SaveEntity(); } } } diff --git a/BookAStar/BookAStar/Helpers/ObservableString.cs b/BookAStar/BookAStar/Helpers/ObservableString.cs deleted file mode 100644 index 2049d950..00000000 --- a/BookAStar/BookAStar/Helpers/ObservableString.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace BookAStar -{ - public class ObservableString : IObservable, IDisposable - { - public ObservableString(string data) - { - this.data = data; - } - private string data = null; - private List> observers = new List>(); - - public string Data - { - get - { - return data; - } - - set - { - if (data != value) - { - data = value; - foreach (var obs in observers) - obs.OnCompleted(); - } - } - } - - public override string ToString() - { - return data; - } - - public static explicit operator ObservableString (string data) - { - return new ObservableString(data); - } - - public static explicit operator string (ObservableString observable) - { - return observable.ToString(); - } - - public void Dispose() - { - observers = null; - } - - public IDisposable Subscribe(IObserver observer) - { - observers.Add(observer); - return this; - } - } -} \ No newline at end of file diff --git a/BookAStar/BookAStar/Interfaces/ILocalEntity.cs b/BookAStar/BookAStar/Interfaces/ILocalEntity.cs index 8e1f1945..44ea2f79 100644 --- a/BookAStar/BookAStar/Interfaces/ILocalEntity.cs +++ b/BookAStar/BookAStar/Interfaces/ILocalEntity.cs @@ -1,10 +1,11 @@ using System; +using System.Collections; namespace BookAStar { public interface ILoadable { - void Load(); + bool Load(); } public interface IPersistentOnDemand : ILoadable @@ -12,7 +13,7 @@ namespace BookAStar void Save(); } - public interface ILocalEntity : ILoadable where K : IEquatable + public interface ILocalEntity : IList, ILoadable where K : IEquatable { V CurrentItem { get; } @@ -22,5 +23,6 @@ namespace BookAStar void Merge(V item); + bool Seek(int index); } } \ No newline at end of file diff --git a/BookAStar/BookAStar/Pages/Estimate/BookQueryPage.xaml.cs b/BookAStar/BookAStar/Pages/Estimate/BookQueryPage.xaml.cs index a09a7e63..0f73d1ed 100644 --- a/BookAStar/BookAStar/Pages/Estimate/BookQueryPage.xaml.cs +++ b/BookAStar/BookAStar/Pages/Estimate/BookQueryPage.xaml.cs @@ -58,7 +58,7 @@ namespace BookAStar.Pages private void OnEditEstimate(object sender, EventArgs ev) { - var bookQueryViewModel = (BookQueryViewModel)BindingContext; + var bookQueryViewModel = (BookQueryViewModel) BindingContext; var editEstimateViewModel = bookQueryViewModel.DraftEstimate; if (editEstimateViewModel == null) @@ -70,7 +70,7 @@ namespace BookAStar.Pages if (estimateToEdit == null) { DataManager.Current.Contacts.Merge(BookQuery.Client); - DataManager.Current.Contacts.SaveCollection(); + DataManager.Current.Contacts.SaveEntity(); estimateToEdit = new Estimate() { ClientId = BookQuery.Client.UserId, diff --git a/BookAStar/BookAStar/Pages/Estimate/EditEstimatePage.xaml.cs b/BookAStar/BookAStar/Pages/Estimate/EditEstimatePage.xaml.cs index a280e617..8c1e2392 100644 --- a/BookAStar/BookAStar/Pages/Estimate/EditEstimatePage.xaml.cs +++ b/BookAStar/BookAStar/Pages/Estimate/EditEstimatePage.xaml.cs @@ -24,7 +24,7 @@ namespace BookAStar.Pages private void EditEstimatePage_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { - DataManager.Current.EstimationCache.SaveCollection(); + DataManager.Current.EstimationCache.SaveEntity(); } protected override void OnSizeAllocated(double width, double height) @@ -47,7 +47,7 @@ namespace BookAStar.Pages var lineView = new BillingLineViewModel(com) { ValidateCommand = new Command(() => { bill.Add(com); - bill.SaveCollection(); + DataManager.Current.EstimationCache.SaveEntity(); })}; App.NavigationService.NavigateTo( true, @@ -60,7 +60,7 @@ namespace BookAStar.Pages var lineView = new BillingLineViewModel(line) { ValidateCommand = new Command(() => { - bill.SaveCollection(); + DataManager.Current.EstimationCache.SaveEntity(); }) }; lineView.PropertyChanged += LineView_PropertyChanged; @@ -71,7 +71,7 @@ namespace BookAStar.Pages private void LineView_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { - DataManager.Current.EstimationCache.SaveCollection(); + DataManager.Current.EstimationCache.SaveEntity(); } protected void OnEstimateValidated(object sender, EventArgs e) @@ -88,9 +88,9 @@ namespace BookAStar.Pages { DataManager.Current.Estimates.Update(evm.Data); } - DataManager.Current.Estimates.SaveCollection(); + DataManager.Current.Estimates.SaveEntity(); DataManager.Current.EstimationCache.Remove(evm); - DataManager.Current.EstimationCache.SaveCollection(); + DataManager.Current.EstimationCache.SaveEntity(); Navigation.PopAsync(); } } diff --git a/BookAStar/BookAStar/Pages/UserProfile/DashboardPage.xaml b/BookAStar/BookAStar/Pages/UserProfile/DashboardPage.xaml index a6c1ab0b..2ef86a72 100644 --- a/BookAStar/BookAStar/Pages/UserProfile/DashboardPage.xaml +++ b/BookAStar/BookAStar/Pages/UserProfile/DashboardPage.xaml @@ -18,36 +18,18 @@ - - - - - - - - - - +