internal void ReportProgress(string msg) { Application.Current.Dispatcher.Invoke(() => { ProgressReport?.Invoke(this, msg); }); }
void OnRecordingStopped(object sender, StoppedEventArgs e) { int secondsRecorded = (int)(writer.Length / writer.WaveFormat.AverageBytesPerSecond); FinalizeWaveFile(); ProgressReport?.Invoke(this, new ProgressReportEventArgs(false, secondsRecorded, e.Exception)); }
private async Task Run() { Text = "start"; for (int i = 0; i < 100; i++) { ProgressReport?.Invoke(this, i + 1); await Task.Delay(100); } Completed?.Invoke(this, true); }
public async Task Run(RunLog runLog) { this.runLog = runLog; this.runLog.StartTime = DateTime.Now; this.runLog.PackageId = this.package.PackageId; this.runLog.PackageDisplayName = this.package.DisplayName; // Create new folder for logs this.logBasePath = this.package.ParentProject.ProjectFolder.Trim('\\') + @"\logs\"; if (Directory.Exists(this.logBasePath) == false) { Directory.CreateDirectory(this.logBasePath); } this.runLog.RunLogPath = this.logBasePath + this.runLog.RunId; Directory.CreateDirectory(this.runLog.RunLogPath); var progress = new Progress <ProgressReport>(); progress.ProgressChanged += (s, e) => { switch (e.State) { case ItemEvent.Started: if (DesignerItemStart != null) { DesignerItemStart.Invoke(e, new EventArgs()); } break; case ItemEvent.ProgressReport: if (ProgressReport != null) { ProgressReport.Invoke(e, new EventArgs()); } break; case ItemEvent.StoppedNotExecuted: case ItemEvent.StoppedWithError: case ItemEvent.StoppedSuccessful: if (DesignerItemStop != null) { DesignerItemStop.Invoke(e, new EventArgs()); } break; } }; await Task.Run(() => RunInternal(progress)); }
protected virtual void OnReportProgress(ProgressReportEventArgs e) { ProgressReport?.Invoke(this, e); }
/// <summary> /// This method will update the local xml with sites retrieved from the global webservice. It will also download icons, banner and updated dlls. /// Make sure the local sites are loaded and all paths (<see cref="OnlineVideoSettings.DllsDir"/>, <see cref="OnlineVideoSettings.ConfigDir"/>, <see cref="OnlineVideoSettings.ThumbsDir"/>) are set before calling. /// </summary> /// <param name="progressCallback">pointer to the <see cref="ProgressReport"/> delegate that will receive progress information</param> /// <param name="onlineSitesToUpdate">update the local sites from this list of online sites, if null (default) the complete global list is retrieved</param> /// <param name="onlyUpdateNoAdd">true (default) -> only update already existing local sites, false -> update and add sites from the online list</param> /// <param name="skipCategories">do not update the categories of existing local sites if true (default is false so categories will also be updated)</param> /// <returns> /// <list type="bullet"> /// <item><term>true</term><description>new dlls were downloaded during the update</description></item> /// <item><term>false</term><description>no changes to the local sites or dlls were done</description></item> /// <item><term>null</term><description>update changed only the local xml</description></item> /// </list> /// </returns> public static bool? UpdateSites(ProgressReport progressCallback = null, List<Site> onlineSitesToUpdate = null, bool onlyUpdateNoAdd = true, bool skipCategories = false) { bool newDllsDownloaded = false; bool saveRequired = false; try { if (progressCallback != null) progressCallback.Invoke(Translation.Instance.CheckingForPluginUpdate, 0); if (!VersionCompatible) return false; if (progressCallback != null) progressCallback.Invoke(Translation.Instance.RetrievingRemoteSites, 2); GetRemoteOverviews(); if (onlineSitesToUpdate == null && onlineSites != null) onlineSitesToUpdate = onlineSites.ToList(); if (onlineSitesToUpdate == null || onlineSitesToUpdate.Count == 0) return false; if (progressCallback != null) if (!progressCallback.Invoke(null, 10)) return false; Dictionary<string, bool> requiredDlls = new Dictionary<string, bool>(); for (int i = 0; i < onlineSitesToUpdate.Count; i++) { Site onlineSite = onlineSitesToUpdate[i]; SiteSettings localSite = null; int localSiteIndex = OnlineVideoSettings.Instance.GetSiteByName(onlineSite.Name, out localSite); if (localSiteIndex == -1) { // add if (!onlyUpdateNoAdd) { // remember what dlls are required and check for changed dlls later if (!string.IsNullOrEmpty(onlineSite.RequiredDll)) requiredDlls[onlineSite.RequiredDll] = true; if (progressCallback != null) progressCallback.Invoke(onlineSite.Name, null); localSite = GetRemoteSite(onlineSite.Name); if (localSite != null) { // disable local site if broken if (onlineSite.State == SiteState.Broken) localSite.IsEnabled = false; OnlineVideoSettings.Instance.AddSite(localSite); saveRequired = true; } } } else // update { // remember what dlls are required and check for changed dlls later (regardless of lastUpdated on site) if (!string.IsNullOrEmpty(onlineSite.RequiredDll)) requiredDlls[onlineSite.RequiredDll] = true; // get site if updated on server if ((onlineSite.LastUpdated - localSite.LastUpdated).TotalMinutes > 2) { // don't show the name of that site while updating if it is an adult site and the pin has not been entered yet bool preventMessageDuetoAdult = (localSite.ConfirmAge && OnlineVideoSettings.Instance.UseAgeConfirmation && !OnlineVideoSettings.Instance.AgeConfirmed); if (progressCallback != null && !preventMessageDuetoAdult) progressCallback.Invoke(localSite.Name, null); SiteSettings updatedSite = GetRemoteSite(onlineSite.Name); if (updatedSite != null) { // keep Categories if flag was set if (skipCategories) updatedSite.Categories = localSite.Categories; OnlineVideoSettings.Instance.SetSiteAt(localSiteIndex, updatedSite); localSite = updatedSite; saveRequired = true; } } // disable local site if status of online site is broken if (onlineSite.State == OnlineVideos.OnlineVideosWebservice.SiteState.Broken && localSite.IsEnabled) { localSite.IsEnabled = false; OnlineVideoSettings.Instance.SetSiteAt(localSiteIndex, localSite); saveRequired = true; } } if (progressCallback != null) if (!progressCallback.Invoke(null, (byte)(10 + (70 * (i + 1) / onlineSitesToUpdate.Count)))) return false; } if (progressCallback != null) if (!progressCallback.Invoke(null, null)) return false; if (requiredDlls.Count > 0) { if (progressCallback != null) progressCallback.Invoke(Translation.Instance.RetrievingRemoteDlls, null); // temp target directory for dlls (if exists, delete and recreate) string dllTempDir = Path.Combine(Path.GetTempPath(), "OnlineVideos\\"); if (Directory.Exists(dllTempDir)) Directory.Delete(dllTempDir, true); Directory.CreateDirectory(dllTempDir); int dllsToCopy = 0; for (int i = 0; i < onlineDlls.Length; i++) { Dll anOnlineDll = onlineDlls[i]; if (progressCallback != null) progressCallback.Invoke(anOnlineDll.Name, null); if (requiredDlls.ContainsKey(anOnlineDll.Name)) { // update or download dll if needed string location = Path.Combine(OnlineVideoSettings.Instance.DllsDir, anOnlineDll.Name + ".dll"); bool download = true; if (File.Exists(location)) { byte[] data = null; data = File.ReadAllBytes(location); string md5LocalDll = BitConverter.ToString(md5Service.ComputeHash(data)).Replace("-", "").ToLower(); if (md5LocalDll == anOnlineDll.MD5) { download = false; } else { // MD5 is different - check compile time of local dll vs. LastUpdated of remote dll if (Helpers.FileUtils.RetrieveLinkerTimestamp(location) > anOnlineDll.LastUpdated) { download = false; // local dll is most likely self-compiled - do not download server dll Log.Info("Local '{0}.dll' was compiled later that online version - skipping download", anOnlineDll.Name); } } } if (download) { // download dll to temp dir first if (DownloadDll(anOnlineDll.Name, dllTempDir + anOnlineDll.Name + ".dll")) { newDllsDownloaded = true; // if download was successfull, try to copy to target dir (if not successfull, mark for UAC prompted copy later) try { File.Copy(dllTempDir + anOnlineDll.Name + ".dll", location, true); } catch { dllsToCopy++; } } } } if (progressCallback != null) progressCallback.Invoke(null, (byte)(80 + (15 * (i + 1) / onlineDlls.Length))); } if (dllsToCopy > 0) CopyDlls(dllTempDir, OnlineVideoSettings.Instance.DllsDir); } if (saveRequired) { if (progressCallback != null) progressCallback.Invoke(Translation.Instance.SavingLocalSiteList, 98); OnlineVideoSettings.Instance.SaveSites(); } } catch (Exception ex) { Log.Error(ex); } finally { if (progressCallback != null) progressCallback.Invoke(Translation.Instance.Done, 100); } if (newDllsDownloaded) return true; else if (saveRequired) return null; else return false; }
public static void ReportProgress(int min, int max, int value) { ProgressReport?.Invoke(null, new ProgressReport { Min = min, Max = max, Value = value }); }
/// <summary> /// This method will update the local xml with sites retrieved from the global webservice. It will also download icons, banner and updated dlls. /// Make sure the local sites are loaded and all paths (<see cref="OnlineVideoSettings.DllsDir"/>, <see cref="OnlineVideoSettings.ConfigDir"/>, <see cref="OnlineVideoSettings.ThumbsDir"/>) are set before calling. /// </summary> /// <param name="progressCallback">pointer to the <see cref="ProgressReport"/> delegate that will receive progress information</param> /// <param name="onlineSitesToUpdate">update the local sites from this list of online sites, if null (default) the complete global list is retrieved</param> /// <param name="onlyUpdateNoAdd">true (default) -> only update already existing local sites, false -> update and add sites from the online list</param> /// <param name="skipCategories">do not update the categories of existing local sites if true (default is false so categories will also be updated)</param> /// <returns> /// <list type="bullet"> /// <item><term>true</term><description>new dlls were downloaded during the update</description></item> /// <item><term>false</term><description>no changes to the local sites or dlls were done</description></item> /// <item><term>null</term><description>update changed only the local xml</description></item> /// </list> /// </returns> public static bool?UpdateSites(ProgressReport progressCallback = null, List <Site> onlineSitesToUpdate = null, bool onlyUpdateNoAdd = true, bool skipCategories = false) { bool newDllsDownloaded = false; bool saveRequired = false; try { if (progressCallback != null) { progressCallback.Invoke(Translation.Instance.CheckingForPluginUpdate, 0); } if (!VersionCompatible) { return(false); } if (progressCallback != null) { progressCallback.Invoke(Translation.Instance.RetrievingRemoteSites, 2); } GetRemoteOverviews(); if (onlineSitesToUpdate == null && onlineSites != null) { onlineSitesToUpdate = onlineSites.ToList(); } if (onlineSitesToUpdate == null || onlineSitesToUpdate.Count == 0) { return(false); } if (progressCallback != null) { if (!progressCallback.Invoke(null, 10)) { return(false); } } Dictionary <string, bool> requiredDlls = new Dictionary <string, bool>(); for (int i = 0; i < onlineSitesToUpdate.Count; i++) { Site onlineSite = onlineSitesToUpdate[i]; SiteSettings localSite = null; int localSiteIndex = OnlineVideoSettings.Instance.GetSiteByName(onlineSite.Name, out localSite); if (localSiteIndex == -1) { // add if (!onlyUpdateNoAdd) { // remember what dlls are required and check for changed dlls later if (!string.IsNullOrEmpty(onlineSite.RequiredDll)) { requiredDlls[onlineSite.RequiredDll] = true; } if (progressCallback != null) { progressCallback.Invoke(onlineSite.Name, null); } localSite = GetRemoteSite(onlineSite.Name); if (localSite != null) { // disable local site if broken if (onlineSite.State == SiteState.Broken) { localSite.IsEnabled = false; } OnlineVideoSettings.Instance.AddSite(localSite); saveRequired = true; } } } else // update { // remember what dlls are required and check for changed dlls later (regardless of lastUpdated on site) if (!string.IsNullOrEmpty(onlineSite.RequiredDll)) { requiredDlls[onlineSite.RequiredDll] = true; } // get site if updated on server if ((onlineSite.LastUpdated - localSite.LastUpdated).TotalMinutes > 2) { // don't show the name of that site while updating if it is an adult site and the pin has not been entered yet bool preventMessageDuetoAdult = (localSite.ConfirmAge && OnlineVideoSettings.Instance.UseAgeConfirmation && !OnlineVideoSettings.Instance.AgeConfirmed); if (progressCallback != null && !preventMessageDuetoAdult) { progressCallback.Invoke(localSite.Name, null); } SiteSettings updatedSite = GetRemoteSite(onlineSite.Name); if (updatedSite != null) { // keep Categories if flag was set if (skipCategories) { updatedSite.Categories = localSite.Categories; } OnlineVideoSettings.Instance.SetSiteAt(localSiteIndex, updatedSite); localSite = updatedSite; saveRequired = true; } } // disable local site if status of online site is broken if (onlineSite.State == OnlineVideos.OnlineVideosWebservice.SiteState.Broken && localSite.IsEnabled) { localSite.IsEnabled = false; OnlineVideoSettings.Instance.SetSiteAt(localSiteIndex, localSite); saveRequired = true; } } if (progressCallback != null) { if (!progressCallback.Invoke(null, (byte)(10 + (70 * (i + 1) / onlineSitesToUpdate.Count)))) { return(false); } } } if (progressCallback != null) { if (!progressCallback.Invoke(null, null)) { return(false); } } if (requiredDlls.Count > 0) { if (progressCallback != null) { progressCallback.Invoke(Translation.Instance.RetrievingRemoteDlls, null); } // temp target directory for dlls (if exists, delete and recreate) string dllTempDir = Path.Combine(Path.GetTempPath(), "OnlineVideos\\"); if (Directory.Exists(dllTempDir)) { Directory.Delete(dllTempDir, true); } Directory.CreateDirectory(dllTempDir); int dllsToCopy = 0; for (int i = 0; i < onlineDlls.Length; i++) { Dll anOnlineDll = onlineDlls[i]; if (progressCallback != null) { progressCallback.Invoke(anOnlineDll.Name, null); } if (requiredDlls.ContainsKey(anOnlineDll.Name)) { // update or download dll if needed string location = Path.Combine(OnlineVideoSettings.Instance.DllsDir, anOnlineDll.Name + ".dll"); bool download = true; if (File.Exists(location)) { byte[] data = null; data = File.ReadAllBytes(location); string md5LocalDll = BitConverter.ToString(md5Service.ComputeHash(data)).Replace("-", "").ToLower(); if (md5LocalDll == anOnlineDll.MD5) { download = false; } else { // MD5 is different - check compile time of local dll vs. LastUpdated of remote dll if (Helpers.FileUtils.RetrieveLinkerTimestamp(location) > anOnlineDll.LastUpdated) { download = false; // local dll is most likely self-compiled - do not download server dll Log.Info("Local '{0}.dll' was compiled later that online version - skipping download", anOnlineDll.Name); } } } if (download) { // download dll to temp dir first if (DownloadDll(anOnlineDll.Name, dllTempDir + anOnlineDll.Name + ".dll")) { newDllsDownloaded = true; // if download was successfull, try to copy to target dir (if not successfull, mark for UAC prompted copy later) try { File.Copy(dllTempDir + anOnlineDll.Name + ".dll", location, true); } catch { dllsToCopy++; } } } } if (progressCallback != null) { progressCallback.Invoke(null, (byte)(80 + (15 * (i + 1) / onlineDlls.Length))); } } if (dllsToCopy > 0) { CopyDlls(dllTempDir, OnlineVideoSettings.Instance.DllsDir); } } if (saveRequired) { if (progressCallback != null) { progressCallback.Invoke(Translation.Instance.SavingLocalSiteList, 98); } OnlineVideoSettings.Instance.SaveSites(); } } catch (Exception ex) { Log.Error(ex); } finally { if (progressCallback != null) { progressCallback.Invoke(Translation.Instance.Done, 100); } } if (newDllsDownloaded) { return(true); } else if (saveRequired) { return(null); } else { return(false); } }
protected static void OnReportProgress(ProgressReportEventArgs e) { ProgressReport?.Invoke(null, e); }