private async void CopyConfiguration(BaseMetroDialog dialog) { dialog.CommandBindings.Clear(); dialog.CommandBindings.Add(new CommandBinding(RoutedCommands.AffirmConfigurationDialogCommand, AffirmCopyConfigurationDialog, CanAffirmConfigurationDialog)); dialog.CommandBindings.Add(new CommandBinding(RoutedCommands.CancelConfigurationDialogCommand, CancelConfigurationDialog)); dialog.Title = "Copy Configuration"; var template = await _templateManager.GetTemplateAsync(_key); var configuration = new NewConfiguration { Name = template.Product.Name, Version = template.Product.Version, Description = template.Product.Description, FolderName = $"{_key} (2)" }; dialog.DataContext = configuration; await _mainWindow.ShowMetroDialogAsync(dialog); }
private async Task LoadConfigurationAsync() { try { _variables.ClearVariables(); var template = await _templateManager.GetTemplateAsync(_key); Configuration?.Dispose(); Configuration = _elementFactory.CreateConfiguration(_key, template); Configuration.Initialize(); SelectedPage = Configuration.Pages.FirstOrDefault(); } catch (Exception ex) { _logger.Log(ex.Message, Category.Exception, Priority.High); } }
private async Task BuildVariablesAsync() { try { ConfiguratorVariables.Clear(); ConfiguratorVariables.Add("libraryPath"); ConfiguratorVariables.Add("tempPath"); ConfiguratorVariables.Add("installPath"); var template = await _templateManager.GetTemplateAsync(_templateManager.CurrentKey); foreach (var option in template.Pages .SelectMany(page => page.Sections) .SelectMany(section => section.Options) .Concat(template.Pages.SelectMany(page => page.Options))) { if (!ConfiguratorVariables.Contains(option.Key)) { ConfiguratorVariables.Add(option.Key); } if (option.Control is CheckControl) { var check = option.Control as CheckControl; foreach (var key in check.Checked.Options .Concat(check.Unchecked.Options) .Select(opt => opt.Key)) { if (!ConfiguratorVariables.Contains(key)) { ConfiguratorVariables.Add(key); } } foreach (var key in check.Checked.Tasks .Concat(check.Unchecked.Tasks) .OfType <SetVariableTask>() .Select(task => task.Key)) { if (!ConfiguratorVariables.Contains(key)) { ConfiguratorVariables.Add(key); } } } else if (option.Control is ComboControl) { var combo = option.Control as ComboControl; foreach (var key in combo.Items .SelectMany(item => item.Tasks) .OfType <SetVariableTask>() .Select(task => task.Key)) { if (!ConfiguratorVariables.Contains(key)) { ConfiguratorVariables.Add(key); } } } else if (option.Control is ListControl) { var list = option.Control as ListControl; foreach (var key in list.Items .SelectMany(item => item.Tasks) .OfType <SetVariableTask>() .Select(task => task.Key)) { if (!ConfiguratorVariables.Contains(key)) { ConfiguratorVariables.Add(key); } } } else if (option.Control is RadioControl) { var radio = option.Control as RadioControl; foreach (var key in radio.Choices .SelectMany(choice => choice.Tasks) .OfType <SetVariableTask>() .Select(task => task.Key)) { if (!ConfiguratorVariables.Contains(key)) { ConfiguratorVariables.Add(key); } } } } } catch (Exception ex) { _logger.Log(ex); } }
public async Task BuildAsync(string key, string drive, Action <string, string, double> progress) { try { var template = await _templateManager.GetTemplateAsync(key); _variables[WellKnownVariableNames.InstallDrive] = drive; var libraryPath = Path.Combine(_settings.LocalLibraryPath, key); _variables[WellKnownVariableNames.LibraryPath] = libraryPath; var installPath = Path.Combine(Path.GetTempPath(), "ixconfig\\install"); _variables[WellKnownVariableNames.InstallPath] = installPath; var tempPath = Path.Combine(Path.GetTempPath(), "ixconfig\\temp"); _variables[WellKnownVariableNames.TempPath] = tempPath; progress.Invoke("Building...", "Loading library...", 0); await _templateManager.LoadLibraryAsync(key); await _fileService.CreateDirectoryAsync(installPath, true); await _fileService.CreateDirectoryAsync(tempPath, true); var commands = new List <TaskCommand>(); commands.AddRange(template.Build.Select(_commandFactory.CreateCommand)); commands.Add(_commandFactory.CreateDeleteCommand($"{drive}", true)); commands.Add(_commandFactory.CreateCopyCommand($"%{WellKnownVariableNames.InstallPath}%", $"{drive}", true, true)); for (var i = 0; i < commands.Count; i++) { var value = ((double)i) / (commands.Count); var message = $"Executing {i + 1} of {commands.Count} tasks..."; var title = "Building..."; var command = commands.ElementAt(i); if (i == commands.Count - 1) { title = "Transferring to USB Device..."; } progress.Invoke(title, message, value); if (command.CanExecute()) { await command.Execute(); } } progress.Invoke("Cleanup...", "Unloading library...", 0); await _templateManager.UnloadLibraryAsync(key); progress.Invoke("Build Comlete", string.Empty, 1); } finally { _variables.RemoveVariable(WellKnownVariableNames.LibraryPath); _variables.RemoveVariable(WellKnownVariableNames.InstallPath); _variables.RemoveVariable(WellKnownVariableNames.InstallDrive); _variables.RemoveVariable(WellKnownVariableNames.TempPath); } }