private void saveAndCloseButton_Click(object sender, EventArgs e) { var button = sender as Button; if (button != null) { if (!ValidateViewModel()) { return; } var actions = new List <Action <CancellationToken, IProgress <ProgressInfo> > > { (token, progress) => SaveDocumentDirectory(token, progress) }; if (saveDocumentDirectoryDocumentsCheckBox.Checked) { actions.Add((token, progress) => SaveDocumentDirectoryDocuments(token, progress)); actions.Add((token, progress) => CleanDocumentDirectory(token, progress)); actions.Add((token, progress) => IndexDocumentDirectory(token, progress)); } ProgressViewer.Display(_cancellationTokenIssuer, log: Log, actions: actions.ToArray()); Log.Information($"SAVING DOCUMENT DIRECTORY \"{ViewModel.Label}\"."); DialogResult = DialogResult.OK; } }
/// <summary> /// Stops the specified plugin. /// </summary> /// <param name="progressViewer">The callback object implementing IProgressViewer that will be used to monitor progress.</param> /// <param name="descriptor">The descriptor that contains the plugin to stop.</param> private static void StopPlugin(IProgressViewer progressViewer, PluginDescriptor descriptor) { ProgressViewer.SetExtendedDescription(progressViewer, string.Format("Stopping Plugin: '{0}'.", descriptor.PluginName)); // stop the plugin descriptor.PluginInstance.OnStop(PluginContext.Current, new PluginDescriptorEventArgs(descriptor)); }
private void IndexDocumentDirectory(Entities.DocumentDirectory documentDirectory) { ProgressViewer.Display(_cancellationTokenIssuer, actions: (token, progress) => { _mediator.CommandAsync(new IndexDocumentDirectoryCommand { DocumentDirectoryID = documentDirectory.DocumentDirectoryID }, token, progress).Wait(); }); }
private void Awake() { if (instance == null) { instance = this; } else if (this != instance) { Destroy(this.gameObject); } DontDestroyOnLoad(this.gameObject); LoadData(); }
/// <summary> /// Updates the display of the specified progress dialog /// </summary> /// <param name="progressViewer"></param> /// <param name="bytesReceived"></param> /// <param name="bytesTotal"></param> public virtual void SetDownloadProgress(IProgressViewer progressViewer, long bytesReceived, long bytesTotal) { double p = ((double)bytesReceived / (double)bytesTotal) * 100; int percent = (int)p; string title = string.Format("AutoUpdate Progress..." + "({0}% Completed)", percent.ToString()); string received = this.FormatFileLengthForDisplay(bytesReceived); string total = this.FormatFileLengthForDisplay(bytesTotal); string description = string.Format("Progress: ({0} of {1} downloaded)", received, total); ProgressViewer.SetTitle(progressViewer, title); ProgressViewer.SetExtendedDescription(progressViewer, description); }
private async void ExportAnimationToGifToolStripMenuItem_Click(object sender, EventArgs e) { FileTools.TryOpenSaveFileDialog(out string fileName, "GIF|*.gif", "animation"); var progressViewer = new ProgressViewer { Text = "Processing GIF" }; progressViewer.Show(); var progress = new Progress <int>(percent => progressViewer.SetProgress(percent)); await modelViewport.RenderAnimationToGifAsync(fileName, progress); progressViewer.Close(); }
private void CleanDocumentDirectory(Entities.DocumentDirectory documentDirectory) { var actions = new Action <CancellationToken, IProgress <ProgressInfo> >[] { (token, progress) => { _mediator.CommandAsync(new SaveDocumentDirectoryDocumentsCommand { DocumentDirectoryID = documentDirectory.DocumentDirectoryID }, token, progress).Wait(); }, (token, progress) => { _mediator.CommandAsync(new CleanDocumentDirectoryCommand { DocumentDirectoryID = documentDirectory.DocumentDirectoryID }, token, progress).Wait(); } }; ProgressViewer.Display(_cancellationTokenIssuer, actions: actions); }
/// <summary> /// Creates an instance of the Type described by the PluginDescriptor and asserts that it derives from Plugin. /// </summary> /// <param name="progressViewer">The callback object implementing IProgressViewer that will be used to monitor progress.</param> /// <param name="descriptor">The PluginDescriptor that contains the Type to create.</param> private static void CreatePluginInstance(IProgressViewer progressViewer, PluginDescriptor descriptor) { try { TypeUtilities.AssertTypeIsSubclassOfBaseType(descriptor.PluginType, typeof(Plugin)); string message = string.Format("Creating Plugin: '{0}'.", descriptor.PluginName); ProgressViewer.SetExtendedDescription(progressViewer, message); Log.WriteLine(message); Plugin plugin = (Plugin)TypeUtilities.CreateInstanceOfType(descriptor.PluginType, Type.EmptyTypes, new object[] {}); descriptor.AttachPluginInstance(plugin); } catch (Exception ex) { Log.WriteLine(ex); } }
private void RemoveDocumentDirectory(Entities.DocumentDirectory documentDirectory) { var confirm = MessageBox.Show($"Deseja realmente remover o diretório de documentos \"{documentDirectory.Label}\"?" , "Remover Diretório de Documentos" , MessageBoxButtons.YesNo , MessageBoxIcon.Question); if (confirm == DialogResult.No) { return; } ProgressViewer.Display(_cancellationTokenIssuer, actions: (token, progress) => { _mediator.CommandAsync(new RemoveDocumentDirectoryCommand { DocumentDirectoryID = documentDirectory.DocumentDirectoryID }, token, progress).Wait(); }); FillDocumentDirectoryDataGridView(); }
/// <summary> /// Called when the provider should load the configuration it is managing. /// </summary> public virtual void Load(IProgressViewer progressViewer) { // read or create the local user configuration ProgressViewer.SetExtendedDescription(progressViewer, string.Format("Loading '{0}' configuration...", this.ConfigurationName)); ConfigurationProvidersManager.ReadOrCreateConfiguration( CarbonConfig.Verbose, this.ConfigurationName, this.FullPath, out _configuration, this.GetEncryptionEngine(), this.FormatConfiguration); if (this.Configuration != null) { this.Configuration.TimeToSave += new EventHandler(OnConfigurationTimeToSave); // by default we'll add this to the list so that the configuration shows up in the options dialog ConfigurationProvidersManager.EnumeratingConfigurations += new EventHandler <XmlConfigurationManagerEventArgs>(OnConfigurationProvidersManagerEnumeratingConfigurations); } }
/// <summary> /// Creates new form that edits specified torrent /// </summary> /// <param name="t"></param> /// <param name="creatingNew"></param> public TorrentProperties(Torrent t, bool creatingNew) { InitializeComponent(); progressViewer = new ProgressViewer(t.File) { Location = new Point(56, 73), Size = new Size(504, 20) }; Controls.Add(progressViewer); editing = t; textBoxFileName.Text = t.FilePath; textBoxName.Text = t.Name; labelStatusValue.Text = t.Status.ToString(); if (!creatingNew) { textBoxFileName.ReadOnly = true; } }
public static async Task ConvertAnimationToGif(ModelViewport viewport) { if (!viewport.HasAnimation) { MessageBox.Show("Please open an animation file and select an animation.", "No animation selected"); return; } FileTools.TryOpenSaveFileDialog(out string fileName, "GIF|*.gif", "animation"); var progressViewer = new ProgressViewer { Text = "Processing GIF" }; progressViewer.Show(); var progress = new Progress <int>(percent => progressViewer.SetProgress(percent)); await viewport.RenderAnimationToGifAsync(fileName, progress); progressViewer.Close(); }
public static void ExportFramesToFolder(ModelViewport viewport) { if (!viewport.HasAnimation) { MessageBox.Show("Please open an animation file and select an animation.", "No animation selected"); return; } FileTools.TryOpenFolderDialog(out string folderPath, "animation"); var progressViewer = new ProgressViewer { Text = "Processing Animation" }; progressViewer.Show(); var progress = new Progress <int>(percent => progressViewer.SetProgress(percent)); viewport.RenderAnimationToFolder(folderPath); progressViewer.Close(); }
/// <summary> /// Creates PluginDescriptors from each Plugin Type specified. /// </summary> /// <param name="progressViewer">The callback object implementing IProgressViewer that will be used to monitor progress.</param> /// <param name="types">The collection of Plugin Types to create descriptors for.</param> /// <returns></returns> public static PluginDescriptorCollection CreatePluginDescriptors(IProgressViewer progressViewer, TypeCollection types) { PluginDescriptorCollection descriptors = new PluginDescriptorCollection(); foreach (Type type in types) { try { string message = string.Format("Creating PluginDescriptor, Type: '{0}'.", type.FullName); ProgressViewer.SetExtendedDescription(progressViewer, message); Log.WriteLine(message); PluginDescriptor descriptor = new PluginDescriptor(type); descriptors.Add(descriptor); } catch (Exception ex) { Log.WriteLine(ex); } } return(descriptors); }
/// <summary> /// Searches for plugins in the application's startup path /// </summary> /// <param name="viewer"></param> /// <returns>null if no plugins were found</returns> private TypeCollection InternalSearchForPluginTypes(IProgressViewer progressViewer) { TypeCollection types = null; // starting in the startup path DirectoryInfo directoryInfo = new DirectoryInfo(Application.StartupPath); // look for all the dlls FileInfo[] files = directoryInfo.GetFiles("*.dll"); // see if we can find any plugins defined in each assembly foreach (FileInfo file in files) { // try and load the assembly Assembly assembly = this.LoadAssembly(file.FullName); if (assembly != null) { ProgressViewer.SetExtendedDescription(progressViewer, string.Format("Searching for plugins. Searching '{0}'...", assembly.GetName().Name)); // see if the assembly has any plugins defined in it TypeCollection typesInAssembly = this.LoadPluginTypesFromAssembly(assembly); if (typesInAssembly != null) { if (types == null) { types = new TypeCollection(); } // add the types defined as plugins to the master list types.AddRange(typesInAssembly); } } } return(types); }
/// <summary> /// Raises the AfterPluginsStarted event. /// </summary> /// <param name="e"></param> internal void OnAfterPluginsStarted(PluginContextEventArgs e) { ProgressViewer.SetExtendedDescription(_progressViewer, "Plugins started. Application opening..."); EventManager.Raise <PluginContextEventArgs>(this.AfterPluginsStarted, this, e); }
/// <summary> /// Loads the plugin types this provider brings to the system. /// </summary> /// <param name="progressViewer">The callback object implementing IProgressViewer that will be used to monitor progress.</param> /// <returns></returns> public override TypeCollection LoadPluginTypes(IProgressViewer progressViewer) { ProgressViewer.SetExtendedDescription(progressViewer, "Search for plugins..."); return(TypeLoader.SearchForPluginTypes(progressViewer)); }
public void Run(Assembly startingAssembly, string[] args) { this.AssertThisIsTheOnlyRunningContext(); // create a new application context _appContext = new PluginApplicationContext(); // save the command line args _commandLineArgs = args; if (CarbonConfig.SingleInstance) { // create a new instance manager, don't dispose of it just yet as we'll need to have our ui plugin // grab it and listen for events until the plugin context is destroyed... _instanceManager = new InstanceManager(CarbonConfig.SingleInstancePort, CarbonConfig.SingleInstanceMutexName); // check to see if this one is the only instance running if (!_instanceManager.IsOnlyInstance) { // if not, forward our command line, and then instruct the _instanceManager.SendCommandLineToPreviousInstance(PluginContext.Current.CommandLineArgs); return; } } // load the Carbon core sub-system providers _windowProviders = CarbonConfig.GetWindowProviders(); _configurationProviders = CarbonConfig.GetConfigurationProviders(); //_encryptionProviders = CarbonConfig.GetEncryptionProviders(); _pluginProviders = CarbonConfig.GetPluginProviders(); // show the splash _splashWindow if the config specifies if (CarbonConfig.ShowSplashWindow) { /* * Not-Threaded * */ using (WindowProvider splashWindowProvider = this.GetSplashWindowProvider()) { _splashWindow = splashWindowProvider.CreateWindow(null); } _splashWindow.Show(); _splashWindow.Refresh(); _progressViewer = _splashWindow as IProgressViewer; } ProgressViewer.SetExtendedDescription(_progressViewer, "Initializing Carbon Framework System Providers."); // start configuration providers ConfigurationProvidersManager.InstructConfigurationProvidersToLoad(_progressViewer, _configurationProviders); // use the plugin manager to load the plugin types that the plugin providers want loaded using (TypeCollection pluginTypes = PluginManager.LoadPluginTypes(_progressViewer, _pluginProviders)) { // use the plugin manager to create descriptors for all of the plugins using (_pluginDescriptors = PluginManager.CreatePluginDescriptors(_progressViewer, pluginTypes)) { // validate the plugin dependencies PluginManager.ValidatePluginDependencies(_progressViewer, _pluginDescriptors); // sort plugins to have the least dependent plugins first // NOTE: Always sort first because the dependencies are taken into account during instance construction! _pluginDescriptors = PluginManager.Sort(_pluginDescriptors, true); // create the plugins PluginManager.CreatePluginInstances(_progressViewer, _pluginDescriptors); // start plugins PluginManager.StartPlugins(_progressViewer, _pluginDescriptors); // if we are supposed to run a message loop, do it now if (CarbonConfig.RunApplicationContext) { this.OnEnteringMainMessageLoop(new PluginContextEventArgs(this)); // run the plugin context's main message loop Application.Run(this.ApplicationContext); this.OnExitingMainMessageLoop(new PluginContextEventArgs(this)); } // sort plugins to have the most dependent plugins first _pluginDescriptors = PluginManager.Sort(_pluginDescriptors, false); // stop plugins PluginManager.StopPlugins(null, _pluginDescriptors); } } // stop configuration providers // start configuration providers ConfigurationProvidersManager.InstructConfigurationProvidersToSave(_configurationProviders); }