using System.Diagnostics.Contracts;
using System.IO;
using System.Net;
+using System.Reflection;
using System.Runtime.InteropServices;
using System.ServiceModel;
using System.ServiceModel.Description;
namespace Pithos.Client.WPF {
using System.ComponentModel.Composition;
- [Export(typeof(IShell))]
+
///<summary>
/// The "shell" of the Pithos application displays the taskbar icon, menu and notifications.
/// The shell also hosts the status service called by shell extensions to retrieve file info
/// * ShowFilePropertiesEvent: Raised when a shell command requests the display of the file/container properties dialog
///</remarks>
//TODO: CODE SMELL Why does the shell handle the SelectiveSynchChanges?
+ [Export(typeof(IShell))]
public class ShellViewModel : Screen, IStatusNotification, IShell,
IHandle<Notification>, IHandle<SelectiveSynchChanges>, IHandle<ShowFilePropertiesEvent>
{
StatusMessage = "In Synch";
+ _accounts.CollectionChanged += (sender, e) =>
+ {
+ NotifyOfPropertyChange(() => OpenFolderCaption);
+ NotifyOfPropertyChange(() => HasAccounts);
+ };
+
}
catch (Exception exc)
{
}
}
+
protected override void OnActivate()
{
base.OnActivate();
//If the account is active
if (account.IsActive)
//Start the monitor. It's OK to start an already started monitor,
- //it will just ignore the call
- monitor.Start();
+ //it will just ignore the call
+ StartMonitor(monitor).Wait();
else
{
//If the account is inactive
protected override void OnViewLoaded(object view)
{
- var window = (Window)view;
- window.Hide();
UpdateStatus();
+ var window = (Window)view;
+ TaskEx.Delay(1000).ContinueWith(t => Execute.OnUIThread(window.Hide));
base.OnViewLoaded(view);
}
}
}
- private ObservableConcurrentCollection<AccountInfo> _accounts = new ObservableConcurrentCollection<AccountInfo>();
+ private readonly ObservableConcurrentCollection<AccountInfo> _accounts = new ObservableConcurrentCollection<AccountInfo>();
public ObservableConcurrentCollection<AccountInfo> Accounts
{
get { return _accounts; }
}
+ public bool HasAccounts
+ {
+ get { return _accounts.Count > 0; }
+ }
- private string _pauseSyncCaption="Pause Syncing";
+
+ public string OpenFolderCaption
+ {
+ get
+ {
+ return (_accounts.Count == 0)
+ ? "No Accounts Defined"
+ : "Open Pithos Folder";
+ }
+ }
+
+ private string _pauseSyncCaption="Pause Synching";
public string PauseSyncCaption
{
get { return _pauseSyncCaption; }
}
- private string _statusIcon="Images/Tray.ico";
+ private string _statusIcon="../Images/Pithos.ico";
public string StatusIcon
{
get { return _statusIcon; }
set
{
- _statusIcon = value;
+ //_statusIcon = value;
NotifyOfPropertyChange(() => StatusIcon);
}
}
public void SendFeedback()
{
- var feedBack = new FeedbackViewModel();
+ var feedBack = IoC.Get<FeedbackViewModel>();
_windowManager.ShowWindow(feedBack);
}
}
+ public void GoToSite()
+ {
+ var site = Properties.Settings.Default.PithosSite;
+ Process.Start(site);
+ }
+
public void GoToSite(AccountInfo account)
{
var site = String.Format("{0}/ui/?token={1}&user={2}",
var account = pair.Key;
var accountMonitor = pair.Value;
- ObjectInfo info = accountMonitor.GetObjectInfo(filePath);
+ if (accountMonitor == null)
+ return;
+
+ var infoTask=Task.Factory.StartNew(()=>accountMonitor.GetObjectInfo(filePath));
- var fileProperties = new FilePropertiesViewModel(this, info,filePath);
+ var fileProperties = new FilePropertiesViewModel(this, infoTask,filePath);
_windowManager.ShowWindow(fileProperties);
}
select monitor).FirstOrDefault();
var account = pair.Key;
var accountMonitor = pair.Value;
- ContainerInfo info = accountMonitor.GetContainerInfo(filePath);
+ var info = accountMonitor.GetContainerInfo(filePath);
PauseSyncCaption = isPaused ? "Resume syncing" : "Pause syncing";
var iconKey = isPaused? "TraySyncPaused" : "TrayInSynch";
- StatusIcon = String.Format(@"Images/{0}.ico", iconKey);
+ StatusIcon = String.Format(@"../Images/{0}.ico", iconKey);
}
public void ExitPithos()
if (iconNames.ContainsKey(pithosStatus))
{
var info = iconNames[pithosStatus];
- StatusIcon = String.Format(@"Images/{0}.ico", info.IconName);
- StatusMessage = String.Format("Pithos 1.0\r\n{0}", info.StatusText);
+ StatusIcon = String.Format(@"../Images/{0}.ico", info.IconName);
+
+ Assembly assembly = Assembly.GetExecutingAssembly();
+ var fileVersion = FileVersionInfo.GetVersionInfo(assembly.Location);
+
+
+ StatusMessage = String.Format("Pithos {0}\r\n{1}", fileVersion.FileVersion,info.StatusText);
}
_events.Publish(new Notification { Title = "Start", Message = "Start Monitoring", Level = TraceLevel.Info});
try
{
- var credentials = await PithosAccount.RetrieveCredentialsAsync(Settings.PithosLoginUrl);
+ var credentials = await PithosAccount.RetrieveCredentials(Settings.PithosLoginUrl);
var account = Settings.Accounts.FirstOrDefault(act => act.AccountName == credentials.UserName);
account.ApiKey = credentials.Password;
Settings.Save();
await TaskEx.Delay(10000);
StartMonitor(monitor, retries + 1);
+ NotifyOfPropertyChange(()=>Accounts);
}
catch (AggregateException exc)
{
if (String.IsNullOrWhiteSpace(accountName))
return;
+ var accountInfo=_accounts.FirstOrDefault(account => account.UserName == accountName);
+ _accounts.TryRemove(accountInfo);
+
PithosMonitor monitor;
if (Monitors.TryGetValue(accountName, out monitor))
{