From: Panagiotis Kanavos Date: Wed, 29 Feb 2012 20:16:02 +0000 (+0200) Subject: Changes to hide the warning image when an account token is refreshed X-Git-Url: https://code.grnet.gr/git/pithos-ms-client/commitdiff_plain/31c97141112604ef6dc1e4ffe5e25035d5fdb184 Changes to hide the warning image when an account token is refreshed --- diff --git a/trunk/Pithos.Client.WPF/Images/SmallWarning.png b/trunk/Pithos.Client.WPF/Images/SmallWarning.png new file mode 100644 index 0000000..23590d7 Binary files /dev/null and b/trunk/Pithos.Client.WPF/Images/SmallWarning.png differ diff --git a/trunk/Pithos.Client.WPF/Pithos.Client.WPF.csproj b/trunk/Pithos.Client.WPF/Pithos.Client.WPF.csproj index c2b1c9b..f7af1b8 100644 --- a/trunk/Pithos.Client.WPF/Pithos.Client.WPF.csproj +++ b/trunk/Pithos.Client.WPF/Pithos.Client.WPF.csproj @@ -262,6 +262,7 @@ + AddAccountView.xaml diff --git a/trunk/Pithos.Client.WPF/Preferences/AccountViewModel.cs b/trunk/Pithos.Client.WPF/Preferences/AccountViewModel.cs new file mode 100644 index 0000000..24f02ec --- /dev/null +++ b/trunk/Pithos.Client.WPF/Preferences/AccountViewModel.cs @@ -0,0 +1,129 @@ +#region +/* ----------------------------------------------------------------------- + * + * + * Copyright 2011-2012 GRNET S.A. All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * + * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and + * documentation are those of the authors and should not be + * interpreted as representing official policies, either expressed + * or implied, of GRNET S.A. + * + * ----------------------------------------------------------------------- + */ +#endregion +using Caliburn.Micro; +using Pithos.Interfaces; + +namespace Pithos.Client.WPF.Preferences +{ + /// + /// ViewModel wrapper for an account + /// + public class AccountViewModel:PropertyChangedBase + { + + private readonly AccountSettings _account; + + public AccountSettings Account + { + get { return _account; } + } + + public AccountViewModel(AccountSettings account) + { + _account = account; + } + + + public string AccountName + { + get { + return _account.AccountName; + } + set { + _account.AccountName = value; + NotifyOfPropertyChange(()=>AccountName); + } + } + + public string RootPath + { + get { return _account.RootPath; } + set + { + _account.RootPath = value; + NotifyOfPropertyChange(()=>RootPath); + } + } + + public bool IsActive + { + get { return _account.IsActive; } + set + { + _account.IsActive = value; + NotifyOfPropertyChange(()=>IsActive); + } + } + + public bool IsExpired + { + get { return _account.IsExpired; } + set + { + _account.IsExpired = value; + NotifyOfPropertyChange(()=>IsExpired); + } + } + + public string ServerUrl + { + get { return _account.ServerUrl; } + set + { + _account.ServerUrl = value; + NotifyOfPropertyChange(()=>ServerUrl); + } + } + + public string ApiKey + { + get { return _account.ApiKey; } + set + { + _account.ApiKey = value; + NotifyOfPropertyChange(() => ApiKey); + } + } + + + } +} diff --git a/trunk/Pithos.Client.WPF/Preferences/PreferencesView.xaml b/trunk/Pithos.Client.WPF/Preferences/PreferencesView.xaml index fbd9760..1686a72 100644 --- a/trunk/Pithos.Client.WPF/Preferences/PreferencesView.xaml +++ b/trunk/Pithos.Client.WPF/Preferences/PreferencesView.xaml @@ -72,7 +72,7 @@ - + diff --git a/trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs b/trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs index 8ece12c..7017cf7 100644 --- a/trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs +++ b/trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs @@ -45,6 +45,7 @@ using System.Collections.Concurrent; using System.ComponentModel.Composition; +using System.Diagnostics; using System.IO; using System.Net; using System.Threading.Tasks; @@ -69,6 +70,8 @@ namespace Pithos.Client.WPF.Preferences { private IEventAggregator _events; + //Logging in the Pithos client is provided by log4net + private static readonly log4net.ILog Log = log4net.LogManager.GetLogger("Pithos"); private PithosSettings _settings; public PithosSettings Settings @@ -81,8 +84,8 @@ namespace Pithos.Client.WPF.Preferences } } - private ObservableConcurrentCollection _accounts; - public ObservableConcurrentCollection Accounts + private ObservableConcurrentCollection _accounts; + public ObservableConcurrentCollection Accounts { get { return _accounts; } set @@ -106,13 +109,16 @@ namespace Pithos.Client.WPF.Preferences Shell = shell; Settings=settings; - Accounts = new ObservableConcurrentCollection(); + Accounts = new ObservableConcurrentCollection(); if (settings.Accounts == null) { settings.Accounts=new AccountsCollection(); settings.Save(); } - Accounts.AddFromEnumerable(settings.Accounts); + var accountVMs = from account in settings.Accounts + select new AccountViewModel(account); + + Accounts.AddFromEnumerable(accountVMs); var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); _shortcutPath = Path.Combine(startupPath, "Pithos.lnk"); @@ -205,7 +211,7 @@ namespace Pithos.Client.WPF.Preferences var monitor = Shell.Monitors[CurrentAccount.AccountName]; - var model = new SelectiveSynchViewModel(monitor,_events,CurrentAccount); + var model = new SelectiveSynchViewModel(monitor,_events,CurrentAccount.Account); if (_windowManager.ShowDialog(model) == true) { @@ -213,10 +219,40 @@ namespace Pithos.Client.WPF.Preferences } public async Task RefreshApiKey() - { - await Shell.TryAuthorize(CurrentAccount.AccountName, 3); - NotifyOfPropertyChange(()=>CurrentAccount); + { + _events.Publish(new Notification { Title = "Authorization failed", Message = "Your API Key has probably expired. You will be directed to a page where you can renew it", Level = TraceLevel.Error }); + + //var userName = CurrentAccount.AccountName; + try + { + + var credentials = await PithosAccount.RetrieveCredentials(Settings.PithosLoginUrl); + + var account = Accounts.First(act => act.AccountName == credentials.UserName); + //The server may return credentials for a different account + var monitor = Shell.Monitors[account.AccountName]; + account.ApiKey = credentials.Password; + monitor.ApiKey = credentials.Password; + account.IsExpired = false; + Settings.Save(); + TaskEx.Delay(10000).ContinueWith(_ =>Shell.MonitorAccount(account.Account)); + NotifyOfPropertyChange(() => Accounts); + } + catch (AggregateException exc) + { + string message = String.Format("API Key retrieval failed"); + Log.Error(message, exc.InnerException); + _events.Publish(new Notification { Title = "Authorization failed", Message = message, Level = TraceLevel.Error }); + } + catch (Exception exc) + { + string message = String.Format("API Key retrieval failed"); + Log.Error(message, exc); + _events.Publish(new Notification { Title = "Authorization failed", Message = message, Level = TraceLevel.Error }); + } + } + public void SaveChanges() { @@ -298,8 +334,9 @@ namespace Pithos.Client.WPF.Preferences IsActive=wizard.IsAccountActive }; Settings.Accounts.Add(newAccount); - (Accounts as IProducerConsumerCollection).TryAdd(newAccount); - CurrentAccount = newAccount; + var accountVM = new AccountViewModel(newAccount); + (Accounts as IProducerConsumerCollection).TryAdd(accountVM); + CurrentAccount = accountVM; NotifyOfPropertyChange(() => Accounts); NotifyOfPropertyChange(() => Settings); } @@ -312,6 +349,7 @@ namespace Pithos.Client.WPF.Preferences { var credentials=await PithosAccount.RetrieveCredentials(Settings.PithosLoginUrl); var account = Settings.Accounts.FirstOrDefault(act => act.AccountName == credentials.UserName); + var accountVM = new AccountViewModel(account); if (account == null) { account=new AccountSettings{ @@ -319,14 +357,15 @@ namespace Pithos.Client.WPF.Preferences ApiKey=credentials.Password }; Settings.Accounts.Add(account); - (Accounts as IProducerConsumerCollection).TryAdd(account); + accountVM = new AccountViewModel(account); + (Accounts as IProducerConsumerCollection).TryAdd(accountVM); } else { account.ApiKey=credentials.Password; } //SelectedAccountIndex= Settings.Accounts.IndexOf(account); - CurrentAccount = account; + CurrentAccount = accountVM; NotifyOfPropertyChange(() => Accounts); NotifyOfPropertyChange(()=>Settings); } @@ -334,7 +373,7 @@ namespace Pithos.Client.WPF.Preferences public void RemoveAccount() { var accountName = CurrentAccount.AccountName; - Settings.Accounts.Remove(CurrentAccount); + Settings.Accounts.Remove(CurrentAccount.Account); Accounts.TryRemove(CurrentAccount); @@ -401,13 +440,13 @@ namespace Pithos.Client.WPF.Preferences } }*/ - private AccountSettings _currentAccount; + private AccountViewModel _currentAccount; private IWindowManager _windowManager; private string _shortcutPath; - public AccountSettings CurrentAccount + public AccountViewModel CurrentAccount { get { return _currentAccount; } set @@ -494,7 +533,7 @@ namespace Pithos.Client.WPF.Preferences monitor.Start(); } else - Shell.MonitorAccount(CurrentAccount); + Shell.MonitorAccount(CurrentAccount.Account); //Finally, notify that the Settings, CurrentAccount have changed NotifyOfPropertyChange(() => CurrentAccount); NotifyOfPropertyChange(() => Settings); diff --git a/trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs b/trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs index e908d50..272c964 100644 --- a/trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs +++ b/trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs @@ -94,4 +94,4 @@ using System.Windows; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("0.7.0.0")] -[assembly: AssemblyFileVersionAttribute("0.7.20228.1899")] +[assembly: AssemblyFileVersionAttribute("0.7.20229.2112")] diff --git a/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs b/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs index fc02d07..1aba5f5 100644 --- a/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs +++ b/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs @@ -124,6 +124,8 @@ namespace Pithos.Client.WPF { //Lazily initialized File Version info. This is done once and lazily to avoid blocking the UI private Lazy _fileVersion; + private PollAgent _pollAgent; + /// /// The Shell depends on MEF to provide implementations for windowManager, events, the status checker service and the settings /// @@ -131,7 +133,7 @@ namespace Pithos.Client.WPF { /// The PithosSettings class encapsulates the app's settings to abstract their storage mechanism (App settings, a database or registry) /// [ImportingConstructor] - public ShellViewModel(IWindowManager windowManager, IEventAggregator events, IStatusChecker statusChecker, PithosSettings settings) + public ShellViewModel(IWindowManager windowManager, IEventAggregator events, IStatusChecker statusChecker, PithosSettings settings,PollAgent pollAgent) { try { @@ -144,6 +146,7 @@ namespace Pithos.Client.WPF { _events = events; _events.Subscribe(this); + _pollAgent = pollAgent; Settings = settings; Proxy.SetFromSettings(settings); @@ -471,8 +474,7 @@ namespace Pithos.Client.WPF { public void SynchNow() { - var agent = IoC.Get(); - agent.SynchNow(); + _pollAgent.SynchNow(); } public ObjectInfo RefreshObjectInfo(ObjectInfo currentInfo) @@ -637,40 +639,6 @@ namespace Pithos.Client.WPF { } - public async Task TryAuthorize(string userName, int retries) - { - _events.Publish(new Notification { Title = "Authorization failed", Message = "Your API Key has probably expired. You will be directed to a page where you can renew it", Level = TraceLevel.Error }); - - try - { - - var credentials = await PithosAccount.RetrieveCredentials(Settings.PithosLoginUrl); - - var account = Settings.Accounts.First(act => act.AccountName == credentials.UserName); - //The server may return credentials for a different account - var monitor = _monitors[account.AccountName]; - account.ApiKey = credentials.Password; - monitor.ApiKey = credentials.Password; - account.IsExpired = false; - Settings.Save(); - TaskEx.Delay(10000).ContinueWith(_=> - StartMonitor(monitor, retries + 1)); - NotifyOfPropertyChange(()=>Accounts); - } - catch (AggregateException exc) - { - string message = String.Format("API Key retrieval for {0} failed", userName); - Log.Error(message, exc.InnerException); - _events.Publish(new Notification { Title = "Authorization failed", Message = message, Level = TraceLevel.Error }); - } - catch (Exception exc) - { - string message = String.Format("API Key retrieval for {0} failed", userName); - Log.Error(message, exc); - _events.Publish(new Notification { Title = "Authorization failed", Message = message, Level = TraceLevel.Error }); - } - - } private static bool IsUnauthorized(WebException exc) { diff --git a/trunk/Pithos.Interfaces/ObjectInfo.cs b/trunk/Pithos.Interfaces/ObjectInfo.cs index 6957189..39105ad 100644 --- a/trunk/Pithos.Interfaces/ObjectInfo.cs +++ b/trunk/Pithos.Interfaces/ObjectInfo.cs @@ -53,7 +53,7 @@ using Newtonsoft.Json; namespace Pithos.Interfaces { [DebuggerDisplay("Name {Name}")] - public class ObjectInfo:DynamicObject + public class ObjectInfo//:DynamicObject { private readonly List _knownContainers= new List{"trash"}; public string Name { get; set; } @@ -234,10 +234,22 @@ namespace Pithos.Interfaces Hash = String.Empty, Bytes = 0, Content_Type = String.Empty, - Last_Modified = DateTime.MinValue + Last_Modified = DateTime.MinValue, + Exists=false }; - + private bool _exists=true; + + public bool Exists + { + get { + return _exists; + } + set { + _exists = value; + } + } + public string RelativeUrlToFilePath(string currentAccount) { @@ -268,6 +280,7 @@ namespace Pithos.Interfaces return finalPath; } +/* public override bool TrySetMember(SetMemberBinder binder, object value) { if (binder.Name.StartsWith("x_object_meta")) @@ -276,6 +289,7 @@ namespace Pithos.Interfaces } return false; } +*/ public string GetPermissionString() { diff --git a/trunk/Pithos.Setup.x64/Pithos.Setup.x64.vdproj b/trunk/Pithos.Setup.x64/Pithos.Setup.x64.vdproj index 7a94cd1..3b0a5b2 100644 --- a/trunk/Pithos.Setup.x64/Pithos.Setup.x64.vdproj +++ b/trunk/Pithos.Setup.x64/Pithos.Setup.x64.vdproj @@ -1310,15 +1310,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:Pithos" - "ProductCode" = "8:{E88F0F45-5BE6-4616-A86B-D595712A5663}" - "PackageCode" = "8:{8314D97A-C981-4184-8444-4DB962DC3240}" + "ProductCode" = "8:{013ABFEC-E6FB-4C5E-930F-736A4730268A}" + "PackageCode" = "8:{C7D65245-240C-42FA-9E46-2AAFB3351131}" "UpgradeCode" = "8:{205365D1-28AA-4322-A46C-FCB37502C6EF}" "AspNetVersion" = "8:4.0.30319.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:0.7.20228" + "ProductVersion" = "8:0.7.20229" "Manufacturer" = "8:GRNET" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:http://code.grnet.gr/projects/pithos-ms-client" diff --git a/trunk/Pithos.Setup.x86/Pithos.Setup.x86.vdproj b/trunk/Pithos.Setup.x86/Pithos.Setup.x86.vdproj index 4fe250d..fe5f650 100644 --- a/trunk/Pithos.Setup.x86/Pithos.Setup.x86.vdproj +++ b/trunk/Pithos.Setup.x86/Pithos.Setup.x86.vdproj @@ -1310,15 +1310,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:Pithos" - "ProductCode" = "8:{F70830AB-AE3C-4721-9FBD-2EF0CD415B7D}" - "PackageCode" = "8:{78D43546-C115-43DE-AAE2-6C262F691990}" + "ProductCode" = "8:{CDF5C181-8F2F-4135-9861-89F031E4B435}" + "PackageCode" = "8:{CD80CD47-92C9-4445-A777-4110130323B8}" "UpgradeCode" = "8:{205365D1-28AA-4322-A46C-FCB37502C6EF}" "AspNetVersion" = "8:4.0.30319.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:0.7.20228" + "ProductVersion" = "8:0.7.20229" "Manufacturer" = "8:GRNET" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:http://code.grnet.gr/projects/pithos-ms-client"