private async Task RefreshContextAsync(TemplateViewModel selection) { if (!await EnsureCookiecutterIsInstalled()) { return; } try { IsLoading = true; IsLoadingSuccess = false; IsLoadingError = false; var result = await _cutterClient.LoadContextAsync(selection.ClonedPath, UserConfigFilePath); ContextItems.Clear(); foreach (var item in result.Item1) { ContextItems.Add(new ContextItemViewModel(item.Name, item.DefaultValue, item.Values)); } IsLoading = false; IsLoadingSuccess = true; IsLoadingError = false; _outputWindow.WriteLine(string.Empty); _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.LoadingTemplateSuccess, selection.DisplayName)); _outputWindow.ShowAndActivate(); ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection); // Go to the context page ContextLoaded?.Invoke(this, EventArgs.Empty); } catch (InvalidOperationException ex) { IsLoading = false; IsLoadingSuccess = false; IsLoadingError = true; _outputWindow.WriteErrorLine(ex.Message); _outputWindow.WriteLine(string.Empty); _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.LoadingTemplateFailed, selection.DisplayName)); _outputWindow.ShowAndActivate(); ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection, ex); } catch (ProcessException ex) { IsLoading = false; IsLoadingSuccess = false; IsLoadingError = true; _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.ProcessExitCodeMessage, ex.Result.ExeFileName, ex.Result.ExitCode)); _outputWindow.WriteLine(string.Join(Environment.NewLine, ex.Result.StandardOutputLines)); _outputWindow.WriteErrorLine(string.Join(Environment.NewLine, ex.Result.StandardErrorLines)); _outputWindow.WriteLine(string.Empty); _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.LoadingTemplateFailed, selection.DisplayName)); _outputWindow.ShowAndActivate(); ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection, ex); } }
public MainWindow() { InitializeComponent(); DataContext = this; Loaded += (sender, e) => MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); ContCommand = new RelayCommand <object>((o) => { }); RightCommand = new RelayCommand <object>((o) => { ContextItems.Clear(); string itemClicked = (string)o; ContextItems.Add(new Context() { Name = "Foo " + itemClicked, Enabled = false, guid = Guid.NewGuid() }); ContextItems.Add(new Context() { Name = "Bar " + itemClicked, Enabled = false, guid = Guid.NewGuid() }); ContextItems.Add(new Context() { Name = "Hello", Enabled = false, guid = Guid.NewGuid() }); }); }
// Loads all sample plugins created before yesterday from specified directory public IEnumerable <ISamplePlugin> LoadAllSamplePluginsWithin(string directory) { // Create directory info instance from directory path var path = new DirectoryInfo(directory); // Create a context item collection ICollection <IContextItem> contextItems = new ContextItems(); // Add some context objects contextItems.Add(new ContextItem("HelloWorldObject", "Hello World !!!")); // Enumerate through all plugins with attribute info that match an example predicate foreach (var plugin in new Plugins <ISamplePlugin>(path, x => x.DateCreated > DateTime.Now)) { // Yield return instance of enumerable plugin with injected context yield return(plugin.GetInitialisedPlugin((IContextItems)contextItems)); } }
// Loads all sample plugins created before yesterday from specified directory public IEnumerable<ISamplePlugin> LoadAllSamplePluginsWithin(string directory) { // Create directory info instance from directory path var path = new DirectoryInfo(directory); // Create a context item collection ICollection<IContextItem> contextItems = new ContextItems(); // Add some context objects contextItems.Add(new ContextItem("HelloWorldObject", "Hello World !!!")); // Enumerate through all plugins with attribute info that match an example predicate foreach (var plugin in new Plugins<ISamplePlugin>(path, x => x.DateCreated > DateTime.Now)) { // Yield return instance of enumerable plugin with injected context yield return plugin.GetInitialisedPlugin((IContextItems)contextItems); } }
private async Task RefreshContextAsync(TemplateViewModel selection) { if (!await EnsureCookiecutterIsInstalledAsync()) { return; } try { LoadingStatus = OperationStatus.InProgress; _outputWindow.ShowAndActivate(); _outputWindow.WriteLine(Strings.LoadingTemplateStarted.FormatUI(selection.DisplayName)); var unrenderedContext = await _cutterClient.LoadUnrenderedContextAsync(selection.ClonedPath, UserConfigFilePath); ContextItems.Clear(); foreach (var item in unrenderedContext.Items.Where(it => !it.Name.StartsWith("_", StringComparison.InvariantCulture))) { ContextItems.Add(new ContextItemViewModel(item.Name, item.Selector, item.Label, item.Description, item.Url, item.DefaultValue, item.Values)); } HasPostCommands = unrenderedContext.Commands.Count > 0; ShouldExecutePostCommands = HasPostCommands; LoadingStatus = OperationStatus.Succeeded; _outputWindow.WriteLine(Strings.LoadingTemplateSuccess.FormatUI(selection.DisplayName)); ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection); // Go to the context page ContextLoaded?.Invoke(this, EventArgs.Empty); } catch (Exception ex) when(!ex.IsCriticalException()) { LoadingStatus = OperationStatus.Failed; _outputWindow.WriteErrorLine(ex.Message); _outputWindow.WriteLine(Strings.LoadingTemplateFailed.FormatUI(selection.DisplayName)); ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection, ex); } }
/// <summary> /// Central method to put objects into the store. /// </summary> /// <param name="key">Key to store the object under.</param> /// <param name="o">Object to store.</param> protected void PutObject(string key, object o) { if (key.Length == 0) { Logger.Fatal("PutObject: Empty key!"); throw new EmptyKeyException(); } ; if (HasKey(key)) { Logger.Info("PutObject: Removing existing key '{0}'", key); Items.Remove(key); } ; Logger.Info("PutObject: Adding key '{0}'", key); Item item = new Item(key, Context, o); Items.Add(item.Key, item); Dirty = true; }
private async Task RefreshContextAsync(TemplateViewModel selection) { if (!await EnsureCookiecutterIsInstalled()) { return; } try { LoadingStatus = OperationStatus.InProgress; _outputWindow.ShowAndActivate(); _outputWindow.WriteLine(Strings.LoadingTemplateStarted.FormatUI(selection.DisplayName)); var result = await _cutterClient.LoadContextAsync(selection.ClonedPath, UserConfigFilePath); ContextItems.Clear(); foreach (var item in result) { ContextItems.Add(new ContextItemViewModel(item.Name, item.DefaultValue, item.Values)); } LoadingStatus = OperationStatus.Succeeded; _outputWindow.WriteLine(Strings.LoadingTemplateSuccess.FormatUI(selection.DisplayName)); ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection); // Go to the context page ContextLoaded?.Invoke(this, EventArgs.Empty); } catch (Exception ex) when(!ex.IsCriticalException()) { LoadingStatus = OperationStatus.Failed; _outputWindow.WriteErrorLine(ex.Message); _outputWindow.WriteLine(Strings.LoadingTemplateFailed.FormatUI(selection.DisplayName)); ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection, ex); } }