using System.Reflection;
using System.Runtime.InteropServices;
using System.ServiceModel;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls.Primitives;
+using System.Windows.Input;
using AppLimit.NetSparkle;
using Caliburn.Micro;
using Hardcodet.Wpf.TaskbarNotification;
namespace Pithos.Client.WPF {
using System.ComponentModel.Composition;
-
+ public class ToggleStatusCommand:ICommand
+ {
+ private readonly ShellViewModel _model;
+ public ToggleStatusCommand(ShellViewModel model)
+ {
+ _model = model;
+ }
+ public void Execute(object parameter)
+ {
+ _model.CurrentSyncStatus();
+ }
+
+ public bool CanExecute(object parameter)
+ {
+ return true;
+ }
+
+ public event EventHandler CanExecuteChanged;
+ }
+
+
///<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)), Export(typeof(ShellViewModel))]
+ [Export(typeof(IShell)), Export(typeof(ShellViewModel)),Export(typeof(IStatusNotification))]
public class ShellViewModel : Screen, IStatusNotification, IShell,
IHandle<Notification>, IHandle<SelectiveSynchChanges>, IHandle<ShowFilePropertiesEvent>
{
-
- //The Status Checker provides the current synch state
- //TODO: Could we remove the status checker and use events in its place?
- private readonly IStatusChecker _statusChecker;
+
private readonly IEventAggregator _events;
public PithosSettings Settings { get; private set; }
//Logging in the Pithos client is provided by log4net
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- private readonly PollAgent _pollAgent;
- private readonly NetworkAgent _networkAgent;
+ [Import]
+ private PollAgent _pollAgent;
+
+ [Import]
+ private NetworkAgent _networkAgent;
[Import]
public Selectives Selectives { get; set; }
+
+ public ToggleStatusCommand ToggleMiniStatusCommand { get; set; }
+
private MiniStatusViewModel _miniStatus;
[Import]
/// The PithosSettings class encapsulates the app's settings to abstract their storage mechanism (App settings, a database or registry)
///</remarks>
[ImportingConstructor]
- public ShellViewModel(IWindowManager windowManager, IEventAggregator events, IStatusChecker statusChecker, PithosSettings settings,PollAgent pollAgent,NetworkAgent networkAgent)
+ public ShellViewModel(IWindowManager windowManager, IEventAggregator events, PithosSettings settings/*,PollAgent pollAgent,NetworkAgent networkAgent*/)
{
try
{
_windowManager = windowManager;
//CHECK: Caliburn doesn't need explicit command construction
- //OpenPithosFolderCommand = new PithosCommand(OpenPithosFolder);
- _statusChecker = statusChecker;
+ //CurrentSyncStatusCommand = new PithosCommand(OpenPithosFolder);
//The event subst
_events = events;
_events.Subscribe(this);
+/*
_pollAgent = pollAgent;
_networkAgent = networkAgent;
+*/
Settings = settings;
Proxy.SetFromSettings(settings);
};
SetVersionMessage();
+
+ ToggleMiniStatusCommand=new ToggleStatusCommand(this);
}
catch (Exception exc)
{
else
{
if (!_statusVisible)
+ {
_windowManager.ShowWindow(MiniStatus);
+ _statusVisible = true;
+ }
else
{
if (MiniStatus.IsActive)
MiniStatus.TryClose();
+ _statusVisible = false;
}
- _statusVisible = !_statusVisible;
NotifyOfPropertyChange(() => MiniStatusCaption);
}
}
var accounts = Settings.Accounts.Select(MonitorAccount);
- await TaskEx.WhenAll(accounts);
+ await TaskEx.WhenAll(accounts).ConfigureAwait(false);
_statusService = StatusService.Start();
}
{
get
{
- return String.Format("{0}\r\n{1}", "Status Window", "Enable / Dissable the stuatus window");
+ return String.Format("{0}\r\n{1}", "Status Window", "Enable / Disable the status window");
}
}
- public string ToggleStatusWindowMessage
+ /*public string ToggleStatusWindowMessage
{
get
{
return String.Format("{0}" + Environment.NewLine + "{1} Toggle Mini Status");
}
- }
+ }*/
private readonly ObservableConcurrentCollection<AccountInfo> _accounts = new ObservableConcurrentCollection<AccountInfo>();
public ObservableConcurrentCollection<AccountInfo> Accounts
{
//Settings.Reload();
- var preferences = new PreferencesViewModel(_windowManager, _events, this, Settings,currentTab);
- _windowManager.ShowDialog(preferences);
-
+ var preferences = IoC.Get<PreferencesViewModel>();//??new PreferencesViewModel(_windowManager, _events, this, Settings,currentTab);
+ if (!String.IsNullOrWhiteSpace(currentTab))
+ preferences.SelectedTab = currentTab;
+ if (!preferences.IsActive)
+ _windowManager.ShowWindow(preferences);
+ var view = (Window)preferences.GetView();
+ view.NullSafe(v=>v.Activate());
}
public void AboutPithos()
private bool AbandonRetry(PithosMonitor monitor, int retries)
{
- if (retries > 1)
+ if (retries > 3)
{
var message = String.Format("Monitoring of account {0} has failed too many times. Will not retry",
monitor.UserName);
public void Notify(Notification notification)
{
- _events.Publish(notification);
+ TaskEx.Run(()=> _events.Publish(notification));
}
var account = Accounts.FirstOrDefault(acc => acc.AccountKey == message.Account.AccountKey);
if (account != null)
{
- _pollAgent.SetSelectivePaths(account, message.Added, message.Removed);
- _pollAgent.SynchNow();
+ var added=monitor.UrisToFilePaths(message.Added);
+ _pollAgent.SynchNow(added);
}
});
{
StatusMessage = String.Format("{0} {1:p2} of {2} - {3}",
progress.Action,
- progress.Block/(double)progress.TotalBlocks,
+ (progress.Block + progress.BlockPercentage/100.0)/(double)progress.TotalBlocks,
progress.FileSize.ToByteSize(),
progress.FileName);
return;