public override bool CanExecute(IWuEndpoint endpoint) { return(endpoint != null && (endpoint.State.StateId == WuStateId.Searching || endpoint.State.StateId == WuStateId.Downloading || endpoint.State.StateId == WuStateId.Installing)); }
public WuRemoteCallContext(WuRemoteCall call, IWuEndpoint endpoint, Task <WuRemoteCallResult> task) { if (call == null) { throw new ArgumentNullException(nameof(call)); } if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } if (task == null) { throw new ArgumentNullException(nameof(task)); } if (task.Status != TaskStatus.Created) { throw new InvalidOperationException("Task started before added to call context."); } _callName = call.Name; _endpointName = endpoint.FQDN; Result = null; _call = call; _endpoint = endpoint; task.ContinueWith((t) => OnTaskFinished(t)); }
protected override WuRemoteCallResult CallInternal(IWuEndpoint endpoint, object param) { SelectionParameter parameter; if (param is SelectionParameter) { parameter = (SelectionParameter)param; } else { throw new ArgumentException($"A {nameof(SelectionParameter)} parameter is required.", nameof(param)); } if (ReconnectIfDisconnected(endpoint)) { if (parameter.Value && endpoint.Service.SelectUpdate(parameter.Update.ID)) // try to select update { return(WuRemoteCallResult.SuccessResult(endpoint, this, $"Update {parameter.Update.Title} selected.")); } if (!parameter.Value && endpoint.Service.UnselectUpdate(parameter.Update.ID)) // try to unselect update { return(WuRemoteCallResult.SuccessResult(endpoint, this, $"Update {parameter.Update.Title} unselected.")); } return(new WuRemoteCallResult(endpoint, this, false, null, $"Update {parameter.Update.Title} could not be {(parameter.Value?"selected":"unselected")}.")); } return(WuRemoteCallResult.EndpointNotAvailableResult(endpoint, this)); }
private WuRemoteCallResult Call(IWuEndpoint endpoint, object param) { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } Log.Info($"Execute remote call {GetType().Name} on endpoint {endpoint.FQDN}, param: {param?.ToString()}"); WuRemoteCallResult result = null; try { if (endpoint.IsDisposed) { return(new WuRemoteCallResult(endpoint, this, false, null, "Host connection is disposed, please reconnect to this host.")); } result = CallInternal(endpoint, param); } catch (Exception e) { Log.Error($"Execute remote call {GetType().Name} on endpoint {endpoint.FQDN} failed.", e); return(new WuRemoteCallResult(endpoint, this, false, e, e.Message)); } if (result == null) { return(new WuRemoteCallResult(endpoint, this, true, null, null)); } return(result); }
protected override WuRemoteCallResult CallInternal(IWuEndpoint endpoint, object param) { if (ReconnectIfDisconnected(endpoint)) { switch (endpoint.State.StateId) { case WuStateId.Searching: endpoint.Service.AbortSearchUpdates(); break; case WuStateId.Downloading: endpoint.Service.AbortDownloadUpdates(); break; case WuStateId.Installing: endpoint.Service.AbortInstallUpdates(); break; default: return(new WuRemoteCallResult(endpoint, this, false, null, "The remote service is not searching, downloading or installing updates, can not abort the current state.")); } return(WuRemoteCallResult.SuccessResult(endpoint, this)); } return(WuRemoteCallResult.EndpointNotAvailableResult(endpoint, this)); }
internal EndpointNeedsUpgradeException(IWuEndpoint endpoint) : base($"The version of the endpoint {endpoint?.FQDN} is not uptodate.") { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } Endpoint = endpoint; }
protected override WuRemoteCallResult CallInternal(IWuEndpoint endpoint, object param) { if (ReconnectIfDisconnected(endpoint)) { endpoint.Service.BeginInstallUpdates(); return(WuRemoteCallResult.SuccessResult(endpoint, this)); } return(WuRemoteCallResult.EndpointNotAvailableResult(endpoint, this)); }
protected override WuRemoteCallResult CallInternal(IWuEndpoint endpoint, object param) { if (ReconnectIfDisconnected(endpoint)) { endpoint.Service.ResetService(); endpoint.RefreshState(); return(WuRemoteCallResult.SuccessResult(endpoint, this)); } return(WuRemoteCallResult.EndpointNotAvailableResult(endpoint, this)); }
protected override WuRemoteCallResult CallInternal(IWuEndpoint endpoint, object param) { bool value = (param is bool) ? (bool)param : true; if (ReconnectIfDisconnected(endpoint)) { endpoint.Service.SetAutoSelectUpdates(value); endpoint.RefreshSettings(); return(WuRemoteCallResult.SuccessResult(endpoint, this)); } return(WuRemoteCallResult.EndpointNotAvailableResult(endpoint, this)); }
public AddHostViewModel(string url, bool success, Exception error, IWuEndpoint endpoint) { if (String.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException(nameof(url)); } Exception = error; Success = success; Endpoint = endpoint; Url = url; }
/// <summary> /// Allows to get the <see cref="IWuEndpoint"/> for this View Model. /// </summary> /// <param name="endpoint">The endpoint for the view model.</param> /// <returns>True if the endpoint is available, false if the endpoint is disposed or not longer available.</returns> protected bool TryGetEndpoint(out IWuEndpoint endpoint) { IWuEndpoint e; if (WeakRefEndpoint.TryGetTarget(out e) && !e.IsDisposed) { endpoint = e; return(true); } endpoint = null; return(false); }
public WuRemoteCallResult(IWuEndpoint endpoint, WuRemoteCall call, bool success, Exception failure, string message) { if (call == null) { throw new ArgumentNullException(nameof(call)); } _endpoint = endpoint; _call = call; _success = success; _failure = failure; _message = (message == null && failure != null) ? _failure.Message : message; }
/// <summary> /// Executes the call on the given endpoint. /// </summary> /// <param name="endpoint">The target endpoint.</param> /// <param name="param">Call parameter.</param> public Task <WuRemoteCallResult> CallAsync(IWuEndpoint endpoint, object param) { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } var task = new Task <WuRemoteCallResult>(() => Call(endpoint, param)); CallHistory.Add(this, endpoint, task); task.Start(); return(task); }
public WuEndpointBasedViewModel(IModalService modalService, IWuEndpoint endpoint) { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } if (modalService == null) { throw new ArgumentNullException(nameof(modalService)); } WeakRefEndpoint = new WeakReference <IWuEndpoint>(endpoint); ModalService = modalService; }
/// <summary> /// Tries to reconnect to the given endpoint. /// If the endpoint is already connected, a reconnect will not be executed. /// </summary> /// <param name="e">Endpoint to reconnect.</param> /// <returns>True, if the endpoint is connected, false if the reconnect failed.</returns> protected bool ReconnectIfDisconnected(IWuEndpoint e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.ConnectionState != System.ServiceModel.CommunicationState.Opened) { var reconnect = new ReconnectCall(); var result = reconnect.Call(e, null); return(result.Success); } return(true); }
public override bool CanExecute(IWuEndpoint endpoint) { return(endpoint != null && (endpoint.State.StateId == WuStateId.Ready || endpoint.State.StateId == WuStateId.SearchCompleted || endpoint.State.StateId == WuStateId.SearchCompleted || endpoint.State.StateId == WuStateId.SearchFailed || endpoint.State.StateId == WuStateId.DownloadFailed || endpoint.State.StateId == WuStateId.DownloadCompleted || endpoint.State.StateId == WuStateId.DownloadPartiallyFailed || endpoint.State.StateId == WuStateId.InstallCompleted || endpoint.State.StateId == WuStateId.InstallFailed || endpoint.State.StateId == WuStateId.InstallPartiallyFailed || endpoint.State.StateId == WuStateId.UserInputRequired)); }
public override bool CanExecute(IWuEndpoint endpoint) { return(endpoint != null && (endpoint.State.StateId == WuStateId.SearchCompleted || endpoint.State.StateId == WuStateId.SearchCompleted || endpoint.State.StateId == WuStateId.SearchFailed || endpoint.State.StateId == WuStateId.DownloadFailed || endpoint.State.StateId == WuStateId.DownloadCompleted || endpoint.State.StateId == WuStateId.DownloadPartiallyFailed || endpoint.State.StateId == WuStateId.InstallCompleted || endpoint.State.StateId == WuStateId.InstallFailed || endpoint.State.StateId == WuStateId.InstallPartiallyFailed || endpoint.State.StateId == WuStateId.UserInputRequired) && endpoint.Updates.Any(u => u.SelectedForInstallation && u.IsDownloaded && !u.IsInstalled)); }
internal UpdateOverviewWindow(IWuEndpoint endpoint) { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } _endpoint = new WeakReference <IWuEndpoint>(endpoint); InitializeComponent(); Model = new UpdateOverviewViewModel(ModalService, endpoint); HostNameLabel.Content = endpoint.FQDN; this.Title = $"{endpoint.FQDN}: {this.Title}"; Refresh(); }
protected override WuRemoteCallResult CallInternal(IWuEndpoint endpoint, object param) { UpdateDescription update = param as UpdateDescription; if (update == null) { throw new ArgumentException($"A {nameof(UpdateDescription)} parameter which includes an update id is required.", nameof(param)); } if (ReconnectIfDisconnected(endpoint)) { if (endpoint.Service.AcceptEula(update.ID)) { return(WuRemoteCallResult.SuccessResult(endpoint, this, $"The EULA of update {update.Title} was accepted.")); } return(new WuRemoteCallResult(endpoint, this, false, null, $"The EULA of update {update.Title} could not be accepted.")); } return(WuRemoteCallResult.EndpointNotAvailableResult(endpoint, this)); }
private void OnTaskFinished(Task <WuRemoteCallResult> task) { Result = task.Result; _lastTaskStatus = task.Status; if (task.Exception != null && task.Result == null) { Result = new WuRemoteCallResult(_endpoint, _call, false, task.Exception, task.Exception.Message); } _call = null; _endpoint = null; lock (_taskLock) { _task = null; } OnPropertyChanged(nameof(Result)); }
/// <summary> /// Adds an event handler to each new <see cref="IWuEndpoint"/> to watch state changes. /// Required to raise <see cref="WuEndpointCommand.CanExecuteChanged"/> events to revalidate buttons and command execution rules. /// </summary> private void EndpointCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { Log.Debug($"{nameof(EndpointCollectionChanged)}-Eventhandler activation. Change: {e.Action.ToString()}."); if (e.Action == NotifyCollectionChangedAction.Add) { foreach (var item in e.NewItems) { IWuEndpoint endpoint = item as IWuEndpoint; if (endpoint != null) { Log.Debug($"Register {nameof(endpoint.PropertyChanged)}-Eventhandler for {endpoint.FQDN}"); endpoint.PropertyChanged += (s, args) => { if (args.PropertyName.Equals(nameof(IWuEndpoint.State))) { Log.Debug($"Revalidate buttons and command execution rules because the state of endpoint {endpoint.FQDN} changed."); CommandManager.InvalidateRequerySuggested(); } }; } } } }
/// <summary> /// Returns a unsuccessful call result with a 'service not available' message. /// </summary> /// <param name="endpoint">The target endpoint.</param> /// <param name="call">The call which was send to the endpoint.</param> public static WuRemoteCallResult EndpointNotAvailableResult(IWuEndpoint endpoint, WuRemoteCall call) { return(new WuRemoteCallResult(endpoint, call, false, null, "The remote service is currently not available.")); }
public override bool CanExecute(IWuEndpoint endpoint) => (endpoint != null);
/// <summary> /// Returns a successful call result with the given message. /// </summary> /// <param name="endpoint">The target endpoint.</param> /// <param name="call">The call which was send to the endpoint.</param> /// <param name="message">Message for the user.</param> public static WuRemoteCallResult SuccessResult(IWuEndpoint endpoint, WuRemoteCall call, string message) { return(new WuRemoteCallResult(endpoint, call, true, null, message)); }
/// <summary> /// Returns a successful call result with an empty <see cref="Message"/>. /// </summary> /// <param name="endpoint">The target endpoint.</param> /// <param name="call">The call which was send to the endpoint.</param> public static WuRemoteCallResult SuccessResult(IWuEndpoint endpoint, WuRemoteCall call) { return(SuccessResult(endpoint, call, "")); }
protected override WuRemoteCallResult CallInternal(IWuEndpoint endpoint, object param) { endpoint.Reconnect(); endpoint.RefreshState(); return(WuRemoteCallResult.SuccessResult(endpoint, this)); }
/// <summary> /// Determines if the given <see cref="IWuEndpoint"/> is in a state that allows to successfully execute the call. /// </summary> /// <returns>True if the <see cref="IWuEndpoint"/> should be able to execute the call successfully.</returns> abstract public bool CanExecute(IWuEndpoint endpoint);
abstract protected WuRemoteCallResult CallInternal(IWuEndpoint endpoint, object param);
public async static Task <IEnumerable <UpdateDescriptionViewModel> > GetAvailableUpdatesAsync(IWuEndpoint endpoint, IModalService modalService) { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } if (modalService == null) { throw new ArgumentNullException(nameof(modalService)); } return(await Task.Run(async() => { await endpoint.RefreshUpdatesAsync(); var updates = endpoint.Updates; IList <UpdateDescriptionViewModel> result = new List <UpdateDescriptionViewModel>(); foreach (var u in updates) { result.Add(new UpdateDescriptionViewModel(modalService, u, endpoint)); } return result; })); }
public UpdateDescriptionViewModel(IModalService modalService, UpdateDescription model, IWuEndpoint endpoint) : base(modalService, endpoint) { if (model == null) { throw new ArgumentNullException(nameof(model)); } Model = model; _eulaAccepted = model.EulaAccepted; _selected = model.SelectedForInstallation; }