private void CheckForUpdates(IUpdateSource source) { // Get a local pointer to the UpdateManager instance UpdateManager updManager = UpdateManager.Instance; // Only check for updates if we haven't done so already if (updManager.State != UpdateManager.UpdateProcessState.NotChecked) { MessageBox.Show("Update process has already initialized; current state: " + updManager.State.ToString()); return; } try { // Check for updates - returns true if relevant updates are found (after processing all the tasks and // conditions) // Throws exceptions in case of bad arguments or unexpected results updManager.CheckForUpdates(source); } catch (Exception ex) { if (ex is NAppUpdateException) { // This indicates a feed or network error; ex will contain all the info necessary // to deal with that } else MessageBox.Show(ex.ToString()); return; } if (updManager.UpdatesAvailable == 0) { MessageBox.Show("Your software is up to date"); return; } DialogResult dr = MessageBox.Show(string.Format("Updates are available to your software ({0} total). Do you want to download and prepare them now? You can always do this at a later time.", updManager.UpdatesAvailable), "Software updates available", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) updManager.BeginPrepareUpdates(OnPrepareUpdatesCompleted, null); }
/// <summary> /// Check for updates asynchronously /// </summary> /// <param name="source">Update source to use</param> /// <param name="callback">Callback function to call when done</param> public void CheckForUpdateAsync(IUpdateSource source, Action <int> callback) { if (IsWorking) { return; } _updatesThread = new Thread(delegate() { try { CheckForUpdates(source, callback); } catch (Exception ex) { // TODO: Better error handling LatestError = ex.ToString(); callback.BeginInvoke(-1, null, null); } }) { IsBackground = true }; _updatesThread.Start(); }
void RaiseStatusUpdate(UpdateType type, IUpdateSource source, uint processedItems) { if (_stopwatch == null) { return; } // if the update is too frequent, slow it down to around 1/sec if (_lastStatusUpdate == 0) { _lastStatusUpdate = _stopwatch.ElapsedMilliseconds; } else if (_stopwatch.ElapsedMilliseconds - _lastStatusUpdate < 800) { source.ReportEveryNth *= 2; } else if (_stopwatch.ElapsedMilliseconds - _lastStatusUpdate > 1200) { source.ReportEveryNth = (uint)(source.ReportEveryNth / 1.5f); } _lastStatusUpdate = _stopwatch.ElapsedMilliseconds; if (StatusUpdate != null) { StatusUpdate(type, source, processedItems); } }
private void btnCheckForUpdatesCustom_Click(object sender, EventArgs e) { string feedUrl = InputBox("Please enter a Url for a valid NauXml feed", "Feed Url required", ""); if (string.IsNullOrEmpty(feedUrl)) { return; } IUpdateSource source = UpdateManager.Instance.UpdateSource; if (source is SimpleWebSource) { // All we need to do is set the feed url and we are all set, no need to create new objects etc ((SimpleWebSource)source).FeedUrl = feedUrl; CheckForUpdates(source); } else { // No idea what we had there, so we create a new feed source and pass it along - note the // source for retreiving the actual updates will keep intact, and will be used when preparing // the updates source = new SimpleWebSource(feedUrl); CheckForUpdates(source); } }
public UpdateChecker(IUpdateSource updateSource, SemanticVersion currentVersion, bool allowPrerelease, TimeSpan checkInterval) : this(updateSource, currentVersion, allowPrerelease, checkInterval, checkInterval) { }
public bool Prepare(IUpdateSource source) { try { if (!Directory.Exists(UpdateManager.Instance.TempPath)) Directory.CreateDirectory(UpdateManager.Instance.TempPath); //download zip file to tmp folder if (!source.DownloadUpdate(RemotePath, PathToZippedUpdate)) throw new Exception("Impossible de télécharger la mise à jour"); //check file checksum if (!string.IsNullOrEmpty(Checksum)) { string checksum = FileChecksum.GetSHA256Checksum(PathToZippedUpdate); if (!checksum.Equals(Checksum)) throw new Exception("Le fichier de mise à jour téléchargé n'est pas valide"); } //extract file to temp folder and delete the zip file. ZipFileUil.Extract(PathToZippedUpdate, UpdateManager.Instance.TempPath); //delete the zipped file if (File.Exists(PathToZippedUpdate)) File.Delete(PathToZippedUpdate); } catch (Exception) { Clear(); throw; } return true; }
/// <summary> /// Fetches version information for the latest release. /// </summary> /// <returns>A <see cref="ProgramVersion"/> describing the latest release.</returns> public static ProgramVersion GetLatestVersion(this IUpdateSource updateSource, bool allowPrerelease) { var releases = updateSource.GetAllReleases(); var latest = releases.OrderByDescending(r => r.VersionNumber).First(r => allowPrerelease || !r.IsPrerelease); return(latest); }
/// <summary> /// Initializes a new instance of the <see cref="AgentUpdater"/> class. /// </summary> /// <param name="connectionProvider">The connection provider.</param> /// <param name="versionProvider">The version provider.</param> /// <param name="updateSource">The update source.</param> /// <param name="agents">The agents.</param> /// <param name="log">The log.</param> public AgentUpdater(IConnectionProvider connectionProvider, IVersionProvider versionProvider, IUpdateSource updateSource, AgentsCollection agents, ILog log) { this.connectionProvider = connectionProvider; this.versionProvider = versionProvider; this.updateSource = updateSource; this.agents = agents; this.log = log; }
void outp_StatusUpdate(UpdateType type, IUpdateSource source, uint processedItems) { // if the update is too frequent, slow it down if (lastStatusUpdate == 0) { lastStatusUpdate = sw.ElapsedMilliseconds; } else if (sw.ElapsedMilliseconds - lastStatusUpdate < 800) { source.ReportEveryNth *= 2; } else if (sw.ElapsedMilliseconds - lastStatusUpdate > 1200) { source.ReportEveryNth = (uint)(source.ReportEveryNth / 1.5f); } lastStatusUpdate = sw.ElapsedMilliseconds; uint itemsPerSec = (uint)(processedItems / (sw.ElapsedMilliseconds / 1000f - outPutstartTime / 1000f)); string currentAction = "Processing"; switch (type) { case UpdateType.Map: break; case UpdateType.Reduce: break; case UpdateType.Input: return; // currently not interesed in Load events //currentAction = "Loading"; //break; case UpdateType.Output: currentAction = "Saving"; break; default: break; } Console.WriteLine(string.Format("[{1,2}.{2:000}] {4} item #{0:0,0} (avg: {3:0,0}/sec)", processedItems, (int)sw.Elapsed.TotalSeconds, sw.Elapsed.Milliseconds, itemsPerSec, currentAction ) ); if (Progress != null) { Progress(type, processedItems, sw.Elapsed.TotalSeconds, itemsPerSec); } }
private void ReadUpdateFeed(IUpdateSource sc) { IUpdateFeedReader fr = new NauXmlFeedReader(); var tasks = fr.Read(sc.GetUpdatesFeed()); Assert.IsNotNull(tasks); Assert.IsTrue(tasks.Count == 3); Assert.IsTrue(tasks[0].Description.StartsWith("��� - some non 7-bit chars")); }
public override void Prepare(IUpdateSource source) { if (string.IsNullOrEmpty(LocalPath)) { UpdateManager.Instance.Logger.Log(Logger.SeverityLevel.Warning, $"DeleteTask: {nameof(LocalPath)} is empty, task is a noop"); } else { UpdateManager.Instance.Logger.Log($"DeleteTask: Checking path '{LocalPath}'"); } }
public UpdateChecker(IUpdateSource updateSource, SemanticVersion currentVersion, bool allowPrerelease, TimeSpan checkInterval, TimeSpan initialDelay) { UpdateSource = updateSource; CurrentVersion = currentVersion; AllowPrerelease = allowPrerelease; CheckInterval = checkInterval; InitialDelay = initialDelay; }
private void CheckForUpdates(IUpdateSource source) { // Get a local pointer to the UpdateManager instance UpdateManager updManager = UpdateManager.Instance; updManager.UpdateSource = source; // Only check for updates if we haven't done so already if (updManager.State != UpdateManager.UpdateProcessState.NotChecked) { MessageBox.Show("Update process has already initialized; current state: " + updManager.State.ToString()); return; } try { // Check for updates - returns true if relevant updates are found (after processing all the tasks and // conditions) // Throws exceptions in case of bad arguments or unexpected results updManager.CheckForUpdates(); } catch (Exception ex) { if (ex is NAppUpdateException) { // This indicates a feed or network error; ex will contain all the info necessary // to deal with that } else { MessageBox.Show(ex.ToString()); } return; } if (updManager.UpdatesAvailable == 0) { MessageBox.Show("Your software is up to date"); return; } DialogResult dr = MessageBox.Show( string.Format( "Updates are available to your software ({0} total). Do you want to download and prepare them now? You can always do this at a later time.", updManager.UpdatesAvailable), "Software updates available", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { updManager.BeginPrepareUpdates(OnPrepareUpdatesCompleted, null); } }
public override void Prepare(IUpdateSource source) { //This was an assumed int, which meant we never reached 100% with an odd number of tasks var info = new UpdateProgressInfo { Message = "Preparing", Percentage = Convert.ToInt32((this.Index + 1) / Count * 100f) }; OnProgress(info); base.Prepare(source); }
public override void Prepare(IUpdateSource source) { if (string.IsNullOrEmpty(LocalPath)) { UpdateManager.Instance.Logger.Log(Logger.SeverityLevel.Warning, "FileUpdateTask: LocalPath is empty, task is a noop"); return; // Errorneous case, but there's nothing to prepare to, and by default we prefer a noop over an error } string fileName; if (!string.IsNullOrEmpty(UpdateTo)) { fileName = UpdateTo; } else { fileName = LocalPath; } _tempFile = null; var baseUrl = UpdateManager.Instance.BaseUrl; var tempFileLocal = Path.Combine(UpdateManager.Instance.Config.TempFolder, Guid.NewGuid().ToString()); UpdateManager.Instance.Logger.Log("FileUpdateTask: Downloading {0} with BaseUrl of {1} to {2}", fileName, baseUrl, tempFileLocal); if (!source.GetData(fileName, baseUrl, OnProgress, ref tempFileLocal)) { throw new UpdateProcessFailedException("FileUpdateTask: Failed to get file from source"); } _tempFile = tempFileLocal; if (_tempFile == null) { throw new UpdateProcessFailedException("FileUpdateTask: Failed to get file from source"); } if (!string.IsNullOrEmpty(Sha256Checksum)) { var checksum = FileChecksum.GetSHA256Checksum(_tempFile); if (!checksum.Equals(Sha256Checksum)) { throw new UpdateProcessFailedException( string.Format("FileUpdateTask: Checksums do not match; expected {0} but got {1}", Sha256Checksum, checksum)); } } _destinationFile = Path.Combine(Path.GetDirectoryName(UpdateManager.Instance.ApplicationPath), LocalPath); UpdateManager.Instance.Logger.Log("FileUpdateTask: Prepared successfully; destination file: {0}", _destinationFile); }
public bool Prepare(IUpdateSource source) { var fileName = Attributes["remotePath"]; try { string tempFileLocal = Path.Combine(UpdateManager.Instance.TempFolder, Guid.NewGuid().ToString()); if (!source.GetData(fileName, string.Empty /* this is not used*/, ref tempFileLocal)) { return(false); } _tempFile = tempFileLocal; } catch (Exception ex) { throw new UpdateProcessFailedException("Couldn't get Data from source", ex); } _tempDecompressedDir = Path.Combine(UpdateManager.Instance.TempFolder, Path.GetRandomFileName()); Directory.CreateDirectory(_tempDecompressedDir); using (ZipFile zip = ZipFile.Read(_tempFile)) { zip.ExtractAll(_tempDecompressedDir, ExtractExistingFileAction.OverwriteSilently); foreach (ZipEntry e in zip) { if (e.IsDirectory) { string appDirectoryName = Path.Combine(_appPath, e.FileName); if (!Directory.Exists(appDirectoryName)) { _directoriesToCreate.Add(appDirectoryName); } } else if (Attributes.ContainsKey("warm-update") && Attributes["warm-update"] == "true") { _warmUpdates[e.FileName] = Path.Combine(_tempDecompressedDir, e.FileName); } else { _coldUpdates[e.FileName] = Path.Combine(_tempDecompressedDir, e.FileName); } } } File.Delete(_tempFile); return(true); }
public async Task<IUpdatePackage> DownloadUpdate(IUpdateSource source) { try { var tempDir = Path.GetTempPath(); var location = new DirectoryInfo(Path.Combine(tempDir,"Revise",source.Name,Guid.NewGuid().ToString())); return await source.DownloadUpdate(location); } catch (Exception e) { Log.Warn("[DownloadUpdate] Error download update for " + source.Name,e); return null; } }
/// <summary> /// Check for updates synchronouly /// </summary> /// <param name="source">Updates source to use</param> /// <param name="callback">Callback function to call when done</param> /// <returns>true if successful and updates exist</returns> private bool CheckForUpdates(IUpdateSource source, Action <int> callback) { LatestError = null; if (UpdateFeedReader == null) { throw new ArgumentException("An update feed reader is required; please set one before checking for updates"); } if (source == null) { throw new ArgumentException("An update source was not specified"); } lock (UpdatesToApply) { UpdatesToApply.Clear(); var tasks = UpdateFeedReader.Read(source.GetUpdatesFeed()); foreach (var t in tasks) { if (ShouldStop) { return(false); } if (t.UpdateConditions.IsMet(t)) // Only execute if all conditions are met { UpdatesToApply.Add(t); } } } if (ShouldStop) { return(false); } State = UpdateProcessState.Checked; if (callback != null) { callback.BeginInvoke(UpdatesToApply.Count, null, null); } if (UpdatesToApply.Count > 0) { return(true); } return(false); }
/// <summary> /// Check for updates synchronouly /// </summary> /// <param name="source">Updates source to use</param> public void CheckForUpdates(IUpdateSource source) { if (IsWorking) { throw new InvalidOperationException("Another update process is already in progress"); } using (WorkScope.New(isWorking => IsWorking = isWorking)) { if (UpdateFeedReader == null) { throw new ArgumentException("An update feed reader is required; please set one before checking for updates"); } if (source == null) { throw new ArgumentException("An update source was not specified"); } if (State != UpdateProcessState.NotChecked) { throw new InvalidOperationException("Already checked for updates; to reset the current state call CleanUp()"); } lock (UpdatesToApply) { UpdatesToApply.Clear(); using (Stream s = source.GetUpdatesFeed()) { var tasks = UpdateFeedReader.Read(s); foreach (var t in tasks) { if (ShouldStop) { throw new UserAbortException(); } if (t.UpdateConditions == null || t.UpdateConditions.IsMet(t)) // Only execute if all conditions are met { UpdatesToApply.Add(t); } } } } State = UpdateProcessState.Checked; } }
public override void Prepare(IUpdateSource source) { if (DataOnly) { return; } if (string.IsNullOrEmpty(LocalPath)) { UpdateManager.Instance.Logger.Log(Logger.SeverityLevel.Warning, "InstallerUpdateTask: LocalPath is empty."); // Errorneous case, but there's nothing to prepare to, and by default we prefer a noop over an error return; } // NAppUpdate needs the assembly for this type in order to deserialize it when running cold updates //var assemblyFile = new FileInfo(GetType().Assembly.Location); //UpdateManager.Instance.Config.DependenciesForColdUpdate = new List<string> { assemblyFile.Name }; UpdateManager.Instance.Config.UpdateExecutableName = LocalPath; UpdateManager.Instance.Config.UpdateProcessName = LocalPath; string fileName; if (!string.IsNullOrEmpty(UpdateTo)) { fileName = UpdateTo; } else { fileName = LocalPath; } _installerDownloadPath = null; string tempFileLocal = Path.Combine(UpdateManager.Instance.Config.TempFolder, LocalPath); if (!source.GetData(fileName, string.Empty, OnProgress, ref tempFileLocal)) { throw new UpdateProcessFailedException("InstallerUpdateTask: Failed to get file from source"); } _installerDownloadPath = tempFileLocal; if (_installerDownloadPath == null) { throw new UpdateProcessFailedException("InstallerUpdateTask: Failed to get file from source"); } UpdateManager.Instance.Logger.Log("InstallerUpdateTask: Prepared successfully; installer file: {0}", _installerDownloadPath); }
/// <summary> /// Initializes a new instance of the <see cref="Server"/> class. /// </summary> /// <param name="updateSource">The update source.</param> /// <param name="versionProvider">The version provider.</param> /// <param name="runner">The manager.</param> /// <param name="requests">The storage.</param> /// <param name="resultsStorage">The results.</param> /// <param name="log">The log.</param> /// <param name="projects">The projects.</param> public Server( IUpdateSource updateSource, IVersionProvider versionProvider, ServerTestRunner runner, IRequestsStorage requests, IResultsStorage resultsStorage, ILog log, IProjectsStorage projects) { this.updateSource = updateSource; this.versionProvider = versionProvider; this.runner = runner; this.requests = requests; this.resultsStorage = resultsStorage; this.log = log; this.projects = projects; }
public override void Prepare(IUpdateSource source) { for (int i = 0; i < 50; i++) { Thread.Sleep(100); OnProgress(new UpdateProgressInfo { Message = "Doing some work, cycle " + i, Percentage = i * 2, StillWorking = true }); } OnProgress(new UpdateProgressInfo { Message = "Finished preperations", Percentage = 100, StillWorking = false, }); }
/// <summary> /// Check for updates asynchronously /// </summary> /// <param name="source">Update source to use</param> /// <param name="callback">Callback function to call when done; can be null</param> /// <param name="state">Allows the caller to preserve state; can be null</param> public IAsyncResult BeginCheckForUpdates(IUpdateSource source, AsyncCallback callback, Object state) { // Create IAsyncResult object identifying the // asynchronous operation var ar = new UpdateProcessAsyncResult(callback, state); // Use a thread pool thread to perform the operation ThreadPool.QueueUserWorkItem(o => { try { // Perform the operation; if sucessful set the result CheckForUpdates(source ?? UpdateSource); ar.SetAsCompleted(null, false); } catch (Exception e) { // If operation fails, set the exception ar.SetAsCompleted(e, false); } }, ar); return(ar); // Return the IAsyncResult to the caller }
/// <summary> /// Check for updates synchronously /// </summary> /// <param name="source">An update source to use</param> /// <returns>true if successful and updates exist</returns> public bool CheckForUpdates(IUpdateSource source) { return CheckForUpdates(source ?? UpdateSource, null); }
/// <summary> /// Check for updates asynchronously /// </summary> /// <param name="source">Update source to use</param> /// <param name="callback">Callback function to call when done</param> public void CheckForUpdateAsync(IUpdateSource source, Action<int> callback) { if (IsWorking) return; _updatesThread = new Thread(delegate() { try { CheckForUpdates(source, callback); } catch (Exception ex) { // TODO: Better error handling LatestError = ex.ToString(); callback.BeginInvoke(-1, null, null); } }) {IsBackground = true}; _updatesThread.Start(); }
public override void Prepare(IUpdateSource source) { }
/// <summary> /// Check for updates asynchronously /// </summary> /// <param name="source">Update source to use</param> /// <param name="callback">Callback function to call when done; can be null</param> /// <param name="state">Allows the caller to preserve state; can be null</param> public IAsyncResult BeginCheckForUpdates(IUpdateSource source, AsyncCallback callback, Object state) { // Create IAsyncResult object identifying the // asynchronous operation var ar = new UpdateProcessAsyncResult(callback, state); // Use a thread pool thread to perform the operation ThreadPool.QueueUserWorkItem(o => { try { // Perform the operation; if sucessful set the result CheckForUpdates(source ?? UpdateSource); ar.SetAsCompleted(null, false); } catch (Exception e) { // If operation fails, set the exception ar.SetAsCompleted(e, false); } }, ar); return ar; // Return the IAsyncResult to the caller }
/// <summary> /// Check for updates synchronouly /// </summary> /// <param name="source">Updates source to use</param> public void CheckForUpdates(IUpdateSource source) { if (IsWorking) throw new InvalidOperationException("Another update process is already in progress"); using (WorkScope.New(isWorking => IsWorking = isWorking)) { if (UpdateFeedReader == null) throw new ArgumentException("An update feed reader is required; please set one before checking for updates"); if (source == null) throw new ArgumentException("An update source was not specified"); if (State != UpdateProcessState.NotChecked) throw new InvalidOperationException("Already checked for updates; to reset the current state call CleanUp()"); lock (UpdatesToApply) { UpdatesToApply.Clear(); var tasks = UpdateFeedReader.Read(source.GetUpdatesFeed()); foreach (var t in tasks) { if (ShouldStop) throw new UserAbortException(); if (t.UpdateConditions == null || t.UpdateConditions.IsMet(t)) // Only execute if all conditions are met UpdatesToApply.Add(t); } } State = UpdateProcessState.Checked; } }
public void CheckForUpdateAsync(IUpdateSource source, Action<int> callback) { if (!IsWorking) { _updatesThread = new Thread(delegate() { try { CheckForUpdates(source, callback); } catch { callback.BeginInvoke(0, null, null); /* TODO: Handle error */ } }); _updatesThread.IsBackground = true; _updatesThread.Start(); } }
public void AddSource(IUpdateSource source) { lock (UpdateSources) UpdateSources.Add(source); }
/// <summary> /// Check for updates synchronously /// </summary> /// <param name="source">An update source to use</param> /// <returns>true if successful and updates exist</returns> public bool CheckForUpdates(IUpdateSource source) { return(CheckForUpdates(source, null)); }
/// <summary> /// Check for updates synchronouly /// </summary> /// <param name="source">Updates source to use</param> /// <param name="callback">Callback function to call when done</param> /// <returns>true if successful and updates exist</returns> private bool CheckForUpdates(IUpdateSource source, Action<int> callback) { LatestError = null; if (UpdateFeedReader == null) throw new ArgumentException("An update feed reader is required; please set one before checking for updates"); if (source == null) throw new ArgumentException("An update source was not specified"); lock (UpdatesToApply) { UpdatesToApply.Clear(); var tasks = UpdateFeedReader.Read(source.GetUpdatesFeed()); foreach (var t in tasks) { if (ShouldStop) return false; if (t.UpdateConditions.IsMet(t)) // Only execute if all conditions are met UpdatesToApply.Add(t); } } if (ShouldStop) return false; State = UpdateProcessState.Checked; if (callback != null) callback.BeginInvoke(UpdatesToApply.Count, null, null); if (UpdatesToApply.Count > 0) return true; return false; }
public abstract void Prepare(IUpdateSource source);
/// <summary> /// Check for updates asynchronously /// </summary> /// <param name="source">Update source to use</param> /// <param name="callback">Callback function to call when done</param> private void CheckForUpdateAsync(IUpdateSource source, Action<bool> callback) { if (IsWorking) return; _updatesThread = new Thread(delegate() { try { CheckForUpdates(source, callback); } catch (Exception ex) { // TODO: Better error handling LatestError = ex.ToString(); if (callback != null) callback(false); } }); _updatesThread.Start(); }
/// <summary> /// Check for updates synchronouly /// </summary> /// <param name="source">Updates source to use</param> /// <param name="callback">Callback function to call when done</param> /// <returns>true if successful and updates exist</returns> private bool CheckForUpdates(IUpdateSource source, Action<bool> callback) { if (IsWorking) return false; using (WorkScope.New(isWorking => IsWorking = isWorking)) { LatestError = null; if (UpdateFeedReader == null) throw new ArgumentException("An update feed reader is required; please set one before checking for updates"); if (source == null) throw new ArgumentException("An update source was not specified"); lock (UpdatesToApply) { UpdatesToApply.Clear(); var tasks = UpdateFeedReader.Read(source.GetUpdatesFeed()); foreach (var t in tasks) { if (ShouldStop) { LatestError = Errors.UserAborted; return false; } if (t.UpdateConditions.IsMet(t)) // Only execute if all conditions are met UpdatesToApply.Add(t); } } if (ShouldStop) { LatestError = Errors.UserAborted; return false; } State = UpdateProcessState.Checked; if (UpdatesToApply.Count == 0) LatestError = Errors.NoUpdatesFound; } if (callback != null) callback(LatestError == null); return LatestError == null; }
public abstract bool Prepare(IUpdateSource source);
public override void Prepare(IUpdateSource source) { // No preparation required }
public override void Prepare(IUpdateSource source) { _appDir = Path.GetDirectoryName(UpdateManager.Instance.ApplicationPath); }
void outp_StatusUpdate(UpdateType type, IUpdateSource source, uint processedItems) { // if the update is too frequent, slow it down if (lastStatusUpdate == 0) { lastStatusUpdate = sw.ElapsedMilliseconds; } else if (sw.ElapsedMilliseconds - lastStatusUpdate < 800) { source.ReportEveryNth *= 2; } else if (sw.ElapsedMilliseconds - lastStatusUpdate > 1200) { source.ReportEveryNth = (uint)(source.ReportEveryNth / 1.5f); } lastStatusUpdate = sw.ElapsedMilliseconds; uint itemsPerSec = (uint)(processedItems / (sw.ElapsedMilliseconds / 1000f - outPutstartTime / 1000f)); string currentAction = "Processing"; switch (type) { case UpdateType.Map: break; case UpdateType.Reduce: break; case UpdateType.Input: return; // currently not interesed in Load events //currentAction = "Loading"; //break; case UpdateType.Output: currentAction = "Saving"; break; default: break; } Console.WriteLine(string.Format("[{1,2}.{2:000}] {4} item #{0:0,0} (avg: {3:0,0}/sec)", processedItems, (int)sw.Elapsed.TotalSeconds, sw.Elapsed.Milliseconds, itemsPerSec, currentAction ) ); if (Progress != null) Progress(type, processedItems, sw.Elapsed.TotalSeconds, itemsPerSec); }
public bool Prepare(IUpdateSource source) { var fileName = Attributes["remotePath"]; try { string tempFileLocal = Path.Combine(UpdateManager.Instance.TempFolder, Guid.NewGuid().ToString()); if (!source.GetData(fileName, string.Empty /* this is not used*/, ref tempFileLocal)) return false; _tempFile = tempFileLocal; } catch (Exception ex) { throw new UpdateProcessFailedException("Couldn't get Data from source", ex); } _tempDecompressedDir = Path.Combine(UpdateManager.Instance.TempFolder, Path.GetRandomFileName()); Directory.CreateDirectory(_tempDecompressedDir); using (ZipFile zip = ZipFile.Read(_tempFile)) { zip.ExtractAll(_tempDecompressedDir, ExtractExistingFileAction.OverwriteSilently); foreach (ZipEntry e in zip) { if (e.IsDirectory) { string appDirectoryName = Path.Combine(_appPath, e.FileName); if (!Directory.Exists(appDirectoryName)) { _directoriesToCreate.Add(appDirectoryName); } } else if(Attributes.ContainsKey("warm-update") && Attributes["warm-update"] == "true") { _warmUpdates[e.FileName] = Path.Combine(_tempDecompressedDir, e.FileName); } else { _coldUpdates[e.FileName] = Path.Combine(_tempDecompressedDir, e.FileName); } } } File.Delete(_tempFile); return true; }