/// <summary>Hides multiple updates.</summary> /// <param name="hiddenUpdates">The list of updates to hide.</param> /// <returns><c>True</c> if the admin process was executed, otherwise <c>False</c>.</returns> internal static bool HideUpdates(Collection <Suh> hiddenUpdates) { if (!Connect()) { ErrorOccurred(null, new ErrorOccurredEventArgs(Resources.CouldNotConnectService, ErrorType.FatalError)); return(false); } Task.Factory.StartNew(WaitForAdmin).ContinueWith( delegate { try { context.HideUpdates(hiddenUpdates); } catch (CommunicationObjectAbortedException) { context = null; IsConnected = false; ErrorOccurred( null, new ErrorOccurredEventArgs(Resources.CouldNotConnectService, ErrorType.FatalError)); } catch (Exception e) { ErrorOccurred( null, new ErrorOccurredEventArgs(Utilities.GetExceptionAsString(e), ErrorType.FatalError)); throw; } }); return(true); }
/// <summary>Connects to the <c>SevenUpdate</c>.Admin sub program.</summary> /// <returns><c>True</c> if the connection to <c>WcfService</c> was successful.</returns> internal static bool Connect() { MyServiceHost.StartService(); #if (!DEBUG) if (Process.GetProcessesByName("SevenUpdate.Admin").Length < 1) { IsConnected = false; context = null; Core.Instance.IsAdmin = false; bool success = Utilities.StartProcess(Path.Combine(Utilities.AppDir, @"SevenUpdate.Admin.exe")); if (!success) { return(false); } } #else if (Process.GetProcessesByName("SevenUpdate.Admin.vshost").Length < 1 && Process.GetProcessesByName("SevenUpdate.Admin").Length < 1) { IsConnected = false; context = null; Core.Instance.IsAdmin = false; bool success = Utilities.StartProcess(Path.Combine(Utilities.AppDir, @"SevenUpdate.Admin.exe")); if (!success) { return(false); } } #endif return(true); }
/// <summary>Adds an application to Seven Update.</summary> /// <param name="application">The application to add to Seven Update.</param> internal static void AddSua(Sua application) { if (!Connect()) { return; } Task.Factory.StartNew(WaitForAdmin).ContinueWith( delegate { try { context.AddApp(application); } catch (CommunicationObjectAbortedException) { context = null; IsConnected = false; } catch (Exception e) { ErrorOccurred( null, new ErrorOccurredEventArgs(Utilities.GetExceptionAsString(e), ErrorType.FatalError)); throw; } }); }
/// <summary>Occurs when the process as exited.</summary> public void ElevatedProcessStopped() { Core.Instance.IsAdmin = false; IsConnected = false; context = null; // OperationContext.Current.GetCallbackChannel<IElevatedProcess>(); Signal Seven Update it can do elevated // actions now }
/// <summary>Occurs when the process starts.</summary> public void ElevatedProcessStarted() { context = OperationContext.Current.GetCallbackChannel <IElevatedProcess>(); if (context == null) { IsConnected = false; Core.Instance.IsAdmin = false; return; } IsConnected = true; Core.Instance.IsAdmin = true; // Signal Seven Update it can do elevated actions now }
/// <summary>Save the settings and call <c>SevenUpdate</c>.Admin to commit them.</summary> /// <param name="autoOn"><c>True</c> if auto updates are enabled, otherwise <c>False</c>.</param> /// <param name="options">The options to save.</param> /// <param name="sul">The list of application to update to save.</param> /// <returns><c>True</c> if the admin process was executed, otherwise <c>False</c>.</returns> internal static bool SaveSettings(bool autoOn, Config options, Collection <Sua> sul) { if (!Connect()) { return(false); } Task.Factory.StartNew(WaitForAdmin).ContinueWith( delegate { try { context.ChangeSettings(sul, options, autoOn); if (SettingsChanged != null) { SettingsChanged(null, new EventArgs()); } } catch (CommunicationObjectAbortedException) { context = null; IsConnected = false; ErrorOccurred( null, new ErrorOccurredEventArgs(Resources.CouldNotConnectService, ErrorType.FatalError)); } catch (TimeoutException) { ErrorOccurred( null, new ErrorOccurredEventArgs(Resources.CouldNotConnectService, ErrorType.FatalError)); } catch (Exception e) { ErrorOccurred( null, new ErrorOccurredEventArgs(Utilities.GetExceptionAsString(e), ErrorType.FatalError)); throw; } }); return(true); }
/// <summary>Installs selected updates.</summary> /// <returns><c>True</c> if the admin process was executed, otherwise <c>False</c>.</returns> internal static bool Install() { if (!Connect()) { return(false); } Task.Factory.StartNew(WaitForAdmin).ContinueWith( delegate { try { context.InstallUpdates(Core.Applications); IsConnected = true; } catch (CommunicationObjectAbortedException) { context = null; IsConnected = false; ErrorOccurred( null, new ErrorOccurredEventArgs(Resources.CouldNotConnectService, ErrorType.FatalError)); } catch (TimeoutException) { ErrorOccurred( null, new ErrorOccurredEventArgs(Resources.CouldNotConnectService, ErrorType.FatalError)); IsConnected = false; } catch (Exception e) { context = null; IsConnected = false; ErrorOccurred( null, new ErrorOccurredEventArgs(Utilities.GetExceptionAsString(e), ErrorType.FatalError)); } }); return(true); }