using Pithos.Interfaces;
using System;
using System.Linq;
+using MessageBox = System.Windows.MessageBox;
using Screen = Caliburn.Micro.Screen;
namespace Pithos.Client.WPF.Preferences
return;
//The server will return credentials for a different account, not just the current account
//We need to find the correct account first
- var account = Accounts.First(act => act.AccountName == credentials.UserName && act.ServerUrl == ?? );
+ var account = Accounts.First(act => act.AccountName == credentials.UserName && act.ServerUrl == CurrentAccount.ServerUrl);
account.ApiKey = credentials.Password;
account.IsExpired = false;
Settings.Save();
actualRootPath = String.Format("{0} {1}", initialRootPath, attempt++);
}
}
- ### Check that the account does not already exist
-
- var newAccount = new AccountSettings
- {
- AccountName = wizard.AccountName,
- ServerUrl=wizard.CurrentServer,
- ApiKey=wizard.Token,
- RootPath = actualRootPath,
- IsActive=wizard.IsAccountActive
- };
- _accountsToAdd.Add(newAccount);
- var accountVm = new AccountViewModel(newAccount);
- (Accounts as IProducerConsumerCollection<AccountViewModel>).TryAdd(accountVm);
- CurrentAccount = accountVm;
+
+
+
+ var account = Accounts.FirstOrDefault(act => act.AccountName == wizard.AccountName && act.ServerUrl == wizard.CurrentServer);
+ if (account != null)
+ {
+ if (MessageBox.Show("The account you specified already exists. Do you want to update it?","The account exists") == MessageBoxResult.Yes)
+ {
+ account.ApiKey = wizard.Token;
+ account.IsExpired = false;
+ CurrentAccount = account;
+ }
+ }
+ else
+ {
+ var newAccount = new AccountSettings
+ {
+ AccountName = wizard.AccountName,
+ ServerUrl = wizard.CurrentServer,
+ ApiKey = wizard.Token,
+ RootPath = actualRootPath,
+ IsActive = wizard.IsAccountActive
+ };
+ _accountsToAdd.Add(newAccount);
+ var accountVm = new AccountViewModel(newAccount);
+ (Accounts as IProducerConsumerCollection<AccountViewModel>).TryAdd(accountVm);
+ CurrentAccount = accountVm;
+ }
NotifyOfPropertyChange(() => Accounts);
NotifyOfPropertyChange(() => Settings);
}
<MenuItem Header="{Binding OpenFolderCaption}" IsEnabled="{Binding HasAccounts}" x:Name="OpenPithosFolder" ItemsSource="{Binding Accounts}" >
<MenuItem.ItemTemplate>
<DataTemplate>
+ <StackPanel>
<TextBlock x:Name="AccountLink" Text="{Binding Path=UserName}" cal:Message.Attach="[Event MouseLeftButtonUp]=[Action OpenPithosFolder($dataContext)]"
cal:Action.TargetWithoutContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=MenuItem, AncestorLevel=2}, Path=DataContext}" />
+ <TextBlock Text="{Binding Path=StorageUri}" FontStyle="Italic" FontSize="10" />
+ </StackPanel>
</DataTemplate>
</MenuItem.ItemTemplate>
<MenuItem.Icon>
<MenuItem Header="Go to Account Site" x:Name="GoToSiteMenu" ItemsSource="{Binding Accounts}" Visibility="{Binding Path=HasAccounts, Converter={StaticResource BooleanToVisible}}" >
<MenuItem.ItemTemplate>
<DataTemplate>
- <TextBlock x:Name="AccountLink" Text="{Binding Path=UserName}" cal:Message.Attach="[Event MouseLeftButtonUp]=[Action GoToSite($dataContext)]"
- cal:Action.TargetWithoutContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=MenuItem, AncestorLevel=2}, Path=DataContext}" />
+ <StackPanel>
+ <TextBlock x:Name="AccountLink" Text="{Binding Path=UserName}" cal:Message.Attach="[Event MouseLeftButtonUp]=[Action GoToSite($dataContext)]"
+ cal:Action.TargetWithoutContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=MenuItem, AncestorLevel=2}, Path=DataContext}" />
+ <TextBlock Text="{Binding Path=StorageUri}" FontStyle="Italic" FontSize="10" />
+ </StackPanel>
</DataTemplate>
</MenuItem.ItemTemplate>
<MenuItem.Icon>