public InstalledUpdateVariantHandler( IUpdateDownloader updateDownloader, IProcessStartProvider processStartProvider) { this.updateDownloader = updateDownloader; this.processStartProvider = processStartProvider; }
public DownloadUpdateStartupAction(IVersionHelper versionHelper, IOnlineVersionHelper onlineVersionHelper, IUpdateHelper updateHelper, IUpdateDownloader updateDownloader) { _versionHelper = versionHelper; _onlineVersionHelper = onlineVersionHelper; _updateHelper = updateHelper; _updateDownloader = updateDownloader; }
/// <summary> /// Creates a <see cref="WuApiController"/> which uses the given Interfaces to search, download and install updates. /// </summary> /// <param name="session">Session to be used.</param> /// <param name="updateCollectionFactory">Factory to create <see cref="IUpdateCollection"/>s.</param> /// <param name="systemInfo">System informations about the OS enviroment.</param> public WuApiController(IUpdateSession session, UpdateCollectionFactory updateCollectionFactory, ISystemInfo systemInfo) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (updateCollectionFactory == null) { throw new ArgumentNullException(nameof(updateCollectionFactory)); } if (systemInfo == null) { throw new ArgumentNullException(nameof(systemInfo)); } UpdateSession = session; UpdateSession.ClientApplicationID = this.GetType().FullName; UpdateSearcher = session.CreateUpdateSearcher(); UpdateDownloader = session.CreateUpdateDownloader(); UpdateInstaller = session.CreateUpdateInstaller(); UpdateCollectionFactory = updateCollectionFactory; SystemInfo = systemInfo; StateTransitions = SetupStateTransitions(); EnterState((SystemInfo.IsRebootRequired()) ? (WuProcessState) new WuStateRebootRequired() : new WuStateReady()); Log.Info("Initial state: " + _currentState.GetType().Name); if (Log.IsDebugEnabled) { OnStateChanged += (s, e) => { Log.Debug($"Event {nameof(OnStateChanged)} fired: {e.ToString()}"); }; OnAsyncOperationCompleted += (s, e) => { Log.Debug($"Event {nameof(OnAsyncOperationCompleted)} fired: {e.ToString()}"); }; OnProgressChanged += (s, e) => { Log.Debug($"Event {nameof(OnProgressChanged)} fired: {e.ToString()}"); }; } }
static void Main(string[] args) { UpdateSession updateSession = new UpdateSession(); Console.WriteLine("1/3 searching"); IUpdateSearcher updateSearcher = updateSession.CreateUpdateSearcher(); ISearchResult searchResult = updateSearcher.Search("Type='Driver' And IsInstalled=0 And IsHidden=0"); foreach (IUpdate update in searchResult.Updates) { Console.WriteLine(update.Title); } Console.WriteLine("2/3 downloading"); IUpdateDownloader updateDownloader = updateSession.CreateUpdateDownloader(); updateDownloader.Updates = searchResult.Updates; updateDownloader.Download(); Console.WriteLine("3/3 installing"); IUpdateInstaller updateInstaller = updateSession.CreateUpdateInstaller(); updateInstaller.Updates = searchResult.Updates; updateInstaller.Install(); }
private void iUpdateDownload() { UpdateSession = new UpdateSession(); iUpdateDownloader = UpdateSession.CreateUpdateDownloader(); iUpdateDownloader.Updates = NewUpdatesCollection; iUpdateDownloader.Priority = DownloadPriority.dpHigh; iDownloadJob = iUpdateDownloader.BeginDownload(new iUpdateDownloader_onProgressChanged(this), new iUpdateDownloader_onCompleted(this), new iUpdateDownloader_state(this)); }
public UpdateDownloadWindowViewModel( ITranslationUpdater translationUpdater, IReadableFileSizeFormatter readableFileSizeFormatter, ApplicationNameProvider applicationNameProvider, IUpdateDownloader updateDownloader, IDispatcher dispatcher) : base(translationUpdater) { _readableFileSizeFormatter = readableFileSizeFormatter; _applicationNameProvider = applicationNameProvider; _updateDownloader = updateDownloader; Dispatcher = dispatcher; CancelCommand = new DelegateCommand(ExecuteCancel); }
public Updater(IUpdateManifest manifest, IUpdateStatusProvider statusProvider, IUpdateDownloader downloader, IUpdateInstaller installer) { this.manifest = manifest; this.statusProvider = statusProvider; this.downloader = downloader; this.installer = installer; }
public InstalledUpdateVariantHandler( IUpdateDownloader updateDownloader, IProcessStartProvider processStartProvider, IAssemblyProvider assemblyProvider, IApplicationState applicationState) { this.updateDownloader = updateDownloader; this.processStartProvider = processStartProvider; this.assemblyProvider = assemblyProvider; this.applicationState = applicationState; }
public AutoUpdateLauncher(ITranslationFactory translationFactory, IInteractionInvoker interactionInvoker, IInteractionRequest interactionRequest, IHashUtil hashUtil, IThreadManager threadManager, ApplicationNameProvider applicationNameProvider, IUpdateDownloader updateDownloader, IEventAggregator EventAggregator) { UpdateTranslation(translationFactory); translationFactory.TranslationChanged += (sender, args) => UpdateTranslation(translationFactory); _interactionRequest = interactionRequest; _interactionInvoker = interactionInvoker; _hashUtil = hashUtil; _threadManager = threadManager; _applicationNameProvider = applicationNameProvider; _updateDownloader = updateDownloader; _eventAggregator = EventAggregator; }
void BeginDownloadUpdate() { this.AppendString("开始下载更新 ...\r\n"); _updateSession = new UpdateSession(); _updateDownloader = _updateSession.CreateUpdateDownloader(); _updateDownloader.Updates = _updateCollection; _updateDownloader.Priority = DownloadPriority.dpHigh; _downloadJob = _updateDownloader.BeginDownload(new DownloadProgressChangedFunc(this), new DownloadCompleteFunc(this), null // new UpdateDownloader_state(this) ); }
public PortableUpdateVariantHandler( IUpdateDownloader updateDownloader, IProcessStartProvider processStartProvider, IFilesystemProvider filesystem, IApplicationPathsProvider pathsProvider, IAssemblyProvider assemblyProvider, IApplicationState applicationState) { this.updateDownloader = updateDownloader; this.processStartProvider = processStartProvider; this.filesystem = filesystem; this.pathsProvider = pathsProvider; this.assemblyProvider = assemblyProvider; this.applicationState = applicationState; }
public async void DownloadUpdates() { try { UpdateCollection toDwnload = new UpdateCollection(); foreach (IUpdate update in updateCollection) { if (!update.IsDownloaded && !update.IsInstalled) { toDwnload.Add(update); } } if (toDwnload.Count > 0) { //updateSession = new UpdateSession(); //todo what if I: //1. crete new session? //2. create the Downlaoder with new keywoard updateDownloader = updateSession.CreateUpdateDownloader(); updateDownloader.Updates = updateCollection; DebugLog("Update downloader params are: " + Dump(updateDownloader)); downloadJob_ = updateDownloader.BeginDownload(this, this, null); } else if (updateCollection.Count > 0) { //ReadyToInstall?.Invoke(); DownloadCompleted?.Invoke(true); } } catch (Exception ex) { VMManagementTool.Log.Error("WinUpdatesManager.DownloadUpdates", ex.ToString()); //this will allow the caller UI method to finish and //the event will be handled like expected asyncronously await Task.Yield(); DownloadCompleted?.Invoke(false); } }
public void CountPendingUpdates() { Console.WriteLine("WUA_Starting"); IUpdateSession updateSession = new UpdateSessionClass(); IUpdateSearcher updateSearcher = updateSession.CreateUpdateSearcher(); IUpdateDownloader updateDownloader = updateSession.CreateUpdateDownloader(); IUpdateInstaller updateInstaller = updateSession.CreateUpdateInstaller(); // SEARCHING Console.WriteLine("WUA_FindingUpdates"); ISearchResult searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'"); Console.WriteLine(string.Format("WUA_Pending:{0}", searchResult.Updates.Count)); Console.WriteLine("WUA_Finish"); }
public WuStateDownloading(IUpdateDownloader uDownloader, IUpdateCollection updates, DownloadCompletedCallback completedCallback, TimeoutCallback timeoutCallback, ProgressChangedCallback progressCallback, int timeoutSec) : base(WuStateId.Downloading, "Downloading Updates", timeoutSec, timeoutCallback, progressCallback) { if (uDownloader == null) { throw new ArgumentNullException(nameof(uDownloader)); } if (updates == null) { throw new ArgumentNullException(nameof(updates)); } if (completedCallback == null) { throw new ArgumentNullException(nameof(completedCallback)); } _uDownloader = uDownloader; _updates = updates; _completedCallback = completedCallback; }
/// <summary> /// アップデートのダウンロードを非同期に行う /// </summary> /// <param name="downloader"></param> /// <param name="progress"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static Task <IDownloadResult> DownloadAsync(this IUpdateDownloader downloader, Action <IDownloadProgress> progress, CancellationToken cancellationToken = default(CancellationToken)) { var task = new TaskCompletionSource <IDownloadResult>(); if (cancellationToken.IsCancellationRequested) { task.TrySetCanceled(cancellationToken); return(task.Task); } var job = null as IDownloadJob; var reg = null as CancellationTokenRegistration?; job = downloader.BeginDownload(new DownloadProgressChangedCallback(progress), new DownloadCompletedCallback((_job2, args) => { try { try { task.TrySetResult(downloader.EndDownload(_job2)); } catch (Exception e) { task.TrySetException(e); } } finally { job = null; reg?.Dispose(); } }), null); reg = cancellationToken.Register(() => { task.TrySetCanceled(cancellationToken); job?.RequestAbort(); }); return(task.Task); }
public AutoUpdater( MultiInstance.IInstancesCounter mutualExecutionCounter, IUpdateDownloader updateDownloader, ITempFilesManager tempFiles, IShutdown shutdown, IInvokeSynchronization eventInvoker, IFirstStartDetector firstStartDetector, Telemetry.ITelemetryCollector telemetry, Persistence.IStorageManager storage ) { this.mutualExecutionCounter = mutualExecutionCounter; this.updateDownloader = updateDownloader; this.tempFiles = tempFiles; this.manualCheckRequested = new TaskCompletionSource <int>(); this.firstStartDetector = firstStartDetector; this.managedAssembliesPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); this.updateInfoFilePath = Path.Combine(managedAssembliesPath, updateInfoFileName); this.installationDir = Path.GetFullPath( Path.Combine(managedAssembliesPath, installationPathRootRelativeToManagedAssembliesLocation)); this.eventInvoker = eventInvoker; this.telemetry = telemetry; this.storage = storage; shutdown.Cleanup += (s, e) => ((IDisposable)this).Dispose(); this.updatesStorageEntry = storage.GetEntry("updates"); bool isFirstInstance = mutualExecutionCounter.IsPrimaryInstance; bool isDownloaderConfigured = updateDownloader.IsDownloaderConfigured; if (!isDownloaderConfigured) { trace.Info("autoupdater is disabled - update downloader not configured"); isActiveAutoUpdaterInstance = false; state = AutoUpdateState.Disabled; } else if (!isFirstInstance) { trace.Info("autoupdater is deactivated - not a first instance of logjoint"); isActiveAutoUpdaterInstance = false; state = AutoUpdateState.Inactive; } else { trace.Info("autoupdater is enabled"); isActiveAutoUpdaterInstance = true; state = AutoUpdateState.Idle; workerCancellation = new CancellationTokenSource(); workerCancellationToken = workerCancellation.Token; workerCancellationTask = new TaskCompletionSource <int>(); worker = TaskUtils.StartInThreadPoolTaskScheduler(Worker); } }
public AutoUpdater( IFactory factory, MultiInstance.IInstancesCounter mutualExecutionCounter, IShutdown shutdown, ISynchronizationContext eventInvoker, Telemetry.ITelemetryCollector telemetry, Persistence.IStorageManager storage, ITraceSourceFactory traceSourceFactory, Extensibility.IPluginsManagerInternal pluginsManager, IChangeNotification changeNotification ) { this.updateDownloader = factory.CreateAppUpdateDownloader(); this.checkRequested = new TaskCompletionSource <int>(); this.factory = factory; this.pluginsManager = pluginsManager; this.trace = traceSourceFactory.CreateTraceSource("AutoUpdater"); var entryAssemblyLocation = Assembly.GetEntryAssembly()?.Location; if (entryAssemblyLocation != null) { this.managedAssembliesPath = Path.GetDirectoryName(entryAssemblyLocation); this.updateInfoFilePath = Path.Combine(managedAssembliesPath, Constants.updateInfoFileName); this.installationDir = Path.GetFullPath( Path.Combine(managedAssembliesPath, Constants.installationPathRootRelativeToManagedAssembliesLocation)); } this.eventInvoker = eventInvoker; this.telemetry = telemetry; this.storage = storage; shutdown.Cleanup += (s, e) => ((IDisposable)this).Dispose(); this.updatesStorageEntry = storage.GetEntry("updates"); bool isFirstInstance = mutualExecutionCounter.IsPrimaryInstance; bool isDownloaderConfigured = updateDownloader.IsDownloaderConfigured; if (entryAssemblyLocation == null) { trace.Info("autoupdater is disabled - no entry assembly"); isActiveAutoUpdaterInstance = false; state = AutoUpdateState.Disabled; } else if (!isDownloaderConfigured) { trace.Info("autoupdater is disabled - update downloader not configured"); isActiveAutoUpdaterInstance = false; state = AutoUpdateState.Disabled; } else if (!isFirstInstance) { trace.Info("autoupdater is deactivated - not a first instance of logjoint"); isActiveAutoUpdaterInstance = false; state = AutoUpdateState.Inactive; } else { trace.Info("autoupdater is enabled"); isActiveAutoUpdaterInstance = true; state = AutoUpdateState.Idle; workerCancellation = new CancellationTokenSource(); workerCancellationToken = workerCancellation.Token; workerCancellationTask = new TaskCompletionSource <int>(); changeListenerSubscription = changeNotification.CreateSubscription(Updaters.Create( () => pluginsManager.InstallationRequests, (_, prev) => { if (prev != null) { checkRequested.TrySetResult(1); } } )); worker = TaskUtils.StartInThreadPoolTaskScheduler(Worker); } }
public UpdateManager(IUpdateDownloader downloader, IUpdateChecker updateChecker, string arg) { _downloader = downloader; _updateChecker = updateChecker; Arg = arg; }
/// <summary> /// アップデートのダウンロードを非同期に行う /// </summary> /// <param name="downloader"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static Task <IDownloadResult> DownloadAsync(this IUpdateDownloader downloader, CancellationToken cancellationToken = default(CancellationToken)) => DownloadAsync(downloader, null, cancellationToken);
public void Start(bool showProgress) { this.ShowProgress = showProgress; Console.WriteLine("WUA_Starting"); IUpdateSession updateSession = new UpdateSessionClass(); IUpdateSearcher updateSearcher = updateSession.CreateUpdateSearcher(); IUpdateDownloader updateDownloader = updateSession.CreateUpdateDownloader(); IUpdateInstaller updateInstaller = updateSession.CreateUpdateInstaller(); if (updateInstaller.IsBusy) { Console.WriteLine("WUA_IsBusy"); return; } // SEARCHING Console.WriteLine("WUA_FindingUpdates"); ISearchResult searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'"); if (searchResult.Updates.Count.Equals(0)) { Console.WriteLine("WUA_NoApplicableUpdates"); return; } // LISTING UpdateCollection updateToDownload = new UpdateCollectionClass(); for (int i = 0; i < searchResult.Updates.Count; i++) { IUpdate update = searchResult.Updates[i]; Console.WriteLine("WUA_UpdateItem:{0}|{1}", i + 1, update.Title); if (!update.IsDownloaded) { updateToDownload.Add(update); } } // DOWNLOADING if (!updateToDownload.Count.Equals(0)) { Console.WriteLine("WUA_DownloadingStarted"); updateDownloader.Updates = updateToDownload; updateDownloader.IsForced = true; updateDownloader.Priority = DownloadPriority.dpHigh; IDownloadJob job = updateDownloader.BeginDownload(this, this, updateDownloader); IDownloadResult downloaderResult = updateDownloader.EndDownload(job); Console.WriteLine("WUA_DownloadingCompleted:{0}", downloaderResult.ResultCode); } // INSTALLATION updateInstaller.Updates = searchResult.Updates; updateInstaller.IsForced = true; Console.WriteLine("WUA_InstallationStarted"); IInstallationJob installationJob = updateInstaller.BeginInstall(this, this, updateInstaller); IInstallationResult result = updateInstaller.EndInstall(installationJob); Console.WriteLine("WUA_InstallationCompleted:{0}|{1}", result.ResultCode, result.RebootRequired); // RESULT for (int i = 0; i < searchResult.Updates.Count; i++) { IUpdateInstallationResult resultItem = result.GetUpdateResult(i); Console.WriteLine("WUA_InstallationResult:{0}|{1}|{2}", i + 1, resultItem.ResultCode, resultItem.RebootRequired); } Console.WriteLine("WUA_Finish"); }