/// <summary> /// Builds the invoice /// </summary> /// <returns>Attempt{IInvoice}</returns> public override Attempt <IInvoice> Build() { var unpaid = _salePreparation.MerchelloContext.Services.InvoiceService.GetInvoiceStatusByKey( Constants.DefaultKeys.InvoiceStatus.Unpaid); if (unpaid == null) { return(Attempt <IInvoice> .Fail(new NullReferenceException("Unpaid invoice status query returned null"))); } var attempt = (TaskHandlers.Any()) ? TaskHandlers.First().Execute(new Invoice(unpaid) { VersionKey = _salePreparation.ItemCache.VersionKey }) : Attempt <IInvoice> .Fail(new InvalidOperationException("The configuration Chain Task List could not be instantiated")); if (!attempt.Success) { return(attempt); } // total the invoice attempt.Result.Total = attempt.Result.Items.Sum(x => x.TotalPrice); return(attempt); }
/// <summary> /// Constructs the task chain /// </summary> protected virtual void ResolveChain(string chainConfigurationAlias) { // Types from the merchello.config file var typeList = ChainTaskResolver.GetTypesForChain(chainConfigurationAlias).ToArray(); if (!typeList.Any()) { return; } // instantiate each task in the chain TaskHandlers.AddRange( typeList.Select( typeName => new AttemptChainTaskHandler <T>( ActivatorHelper.CreateInstance <AttemptChainTaskBase <T> >( typeName, ConstructorArgumentValues.ToArray()).Result ))); // register the next task for each link (these are linear chains) foreach (var taskHandler in TaskHandlers.Where(task => TaskHandlers.IndexOf(task) != TaskHandlers.IndexOf(TaskHandlers.Last()))) { taskHandler.RegisterNext(TaskHandlers[TaskHandlers.IndexOf(taskHandler) + 1]); } }
// Apply button on properties tab private void ApplyButton_Click(object sender, EventArgs e) { if (this.configChanged && changedConfigs.Count > 0) { SetUnsetConfig r = TaskHandlers.SetConfig(changedConfigs); if (r.Error == String.Empty) { DisplayMessageBox.Info("Properties configured: " + String.Join(",", r.Properties), "CodeReady Containers - Settings Applied"); } else { DisplayMessageBox.Error(r.Error); } } if (this.configsNeedingUnset.Count > 0) { SetUnsetConfig r = TaskHandlers.UnsetConfig(configsNeedingUnset); if (r.Error == String.Empty) { DisplayMessageBox.Info("Properties unset: " + String.Join(",", r.Properties), "CodeReady Containers - Settings Applied"); } else { DisplayMessageBox.Error(r.Error); } } // Load the configs again and reset the change trackers getConfigurationAndResetChanged(); }
private void getConfigurationAndResetChanged() { this.changedConfigs = new Dictionary <string, dynamic>(); this.configsNeedingUnset = new List <string>(); currentConfig = TaskHandlers.ConfigView(); loadConfigurationValues(currentConfig); configChanged = false; }
// event handlers and methods async static void PollStatus() { var status = await Task.Run(() => TaskHandlers.Status()); if (status != null) { UpdateClusterStatusMenu(status); } }
/// <summary> /// Builds the order /// </summary> /// <returns>Attempt{IOrder}</returns> public override Attempt <IOrder> Build() { var attempt = (TaskHandlers.Any()) ? TaskHandlers.First().Execute(new Order(_orderStatus, _invoice.Key) { OrderNumberPrefix = _invoice.InvoiceNumberPrefix, VersionKey = _invoice.VersionKey }) : Attempt <IOrder> .Fail(new InvalidOperationException("The configuration Chain Task List could not be instantiated.")); return(attempt); }
private void UpdateLogs() { var logs = TaskHandlers.GetDaemonLogs(); var messages = string.Join("\r\n", logs.Messages); if (logsTextBox.Text == messages) { return; } logsTextBox.Text = messages; logsTextBox.SelectionStart = logsTextBox.Text.Length; logsTextBox.ScrollToCaret(); }
private void GetVersion(object sender, EventArgs e) { version = TaskHandlers.Version(); if (version.Success) { CrcVersionLabel.Text = String.Format("{0}+{1}", version.CrcVersion, version.CommitSha); OcpVersion.Text = version.OpenshiftVersion; } else { DisplayMessageBox.Warn("Unable to fetch version information from daemon"); } }
private void HandleTask(string handlerKey, Action <ITaskHandler> act) { ITaskHandler handler; if (!TaskHandlers.TryGetValue(handlerKey, out handler)) { EventLog.Application.WriteError($"Tried to process task without registered handler. Dropping task. Handler: {handlerKey}"); return; } act(handler); }
/// <summary> /// The validate. /// </summary> /// <param name="value"> /// The value. /// </param> /// <returns> /// The <see cref="Attempt"/>. /// </returns> public Attempt <ValidationResult <CustomerItemCacheBase> > Validate(CustomerItemCacheBase value) { var validated = new ValidationResult <CustomerItemCacheBase>() { Validated = value }; if (!value.Items.Any()) { return(Attempt <ValidationResult <CustomerItemCacheBase> > .Succeed(validated)); } return(TaskHandlers.Any() ? TaskHandlers.First().Execute(validated) : Attempt <ValidationResult <CustomerItemCacheBase> > .Succeed(validated)); }
async private void OpenWebConsoleMenu_Click(object sender, EventArgs e) { var consoleResult = await Task.Run(() => TaskHandlers.WebConsole()); if (consoleResult != null) { if (consoleResult.Success) { System.Diagnostics.Process.Start(consoleResult.ClusterConfig.WebConsoleURL); } else { ShowNotification(@"Could not open web console, is CRC running?", ToolTipIcon.Error); } } }
async private void CopyOCLoginForDeveloperMenu_Click(object sender, EventArgs e) { var consoleResult = await Task.Run(() => TaskHandlers.LoginForDeveloper()); if (consoleResult != null) { if (consoleResult.Success) { Clipboard.SetText(string.Format("oc.exe login -u developer -p developer {0}", consoleResult.ClusterConfig.ClusterAPI)); } else { ShowNotification(@"Could not find credentials, is CRC running?", ToolTipIcon.Error); } } }
async private void StopMenu_Click(object sender, EventArgs e) { ShowNotification(@"Stopping Cluster", ToolTipIcon.Info); var stopResult = await Task.Run(() => TaskHandlers.Stop()); if (stopResult != null) { if (stopResult.Success) { DisplayMessageBox.Info(@"CodeReady Containers Cluster has stopped", @"Cluster Stopped"); } else { DisplayMessageBox.Warn(@"Cluster did not stop. Please check detailed status"); } } }
async private void DeleteMenu_Click(object sender, EventArgs e) { ShowNotification(@"Deleting Cluster", ToolTipIcon.Warning); var deleteResult = await Task.Run(() => TaskHandlers.Delete()); if (deleteResult != null) { if (deleteResult.Success) { DisplayMessageBox.Info(@"CodeReady Containers Cluster has been deleted", @"Cluster Deleted"); } else { DisplayMessageBox.Warn(@"Could not delete the cluster"); } } }
/// <summary> /// Builds the invoice /// </summary> /// <returns>The Attempt{IInvoice} representing the successful creation of an invoice</returns> public override Attempt <IInvoice> Build() { var unpaid = _checkoutManager.Context.Services.InvoiceService.GetInvoiceStatusByKey(Core.Constants.InvoiceStatus.Unpaid); if (unpaid == null) { return(Attempt <IInvoice> .Fail(new NullReferenceException("Unpaid invoice status query returned null"))); } //// Invoice needs to be created via the service so that the Creating / Created events get fired. //// see http://issues.merchello.com/youtrack/issue/M-1290 var invoice = _checkoutManager.Context.Services.InvoiceService.CreateInvoice(unpaid.Key); invoice.VersionKey = _checkoutManager.Context.VersionKey; //// var invoice = new Invoice(unpaid) { VersionKey = _checkoutManager.Context.VersionKey }; // Associate a customer with the invoice if it is a known customer. if (!_checkoutManager.Context.Customer.IsAnonymous) { invoice.CustomerKey = _checkoutManager.Context.Customer.Key; } var attempt = TaskHandlers.Any() ? TaskHandlers.First().Execute(invoice) : Attempt <IInvoice> .Fail(new InvalidOperationException("The configuration Chain Task List could not be instantiated")); if (!attempt.Success) { return(attempt); } var charges = attempt.Result.Items.Where(x => x.LineItemType != LineItemType.Discount).Sum(x => x.TotalPrice); var discounts = attempt.Result.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice); // total the invoice decimal converted; attempt.Result.Total = Math.Round(decimal.TryParse((charges - discounts).ToString(CultureInfo.InvariantCulture), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture.NumberFormat, out converted) ? converted : 0, 2); return(attempt); }
/// <summary> /// Builds the order /// </summary> /// <returns>The Attempt{IShipment}</returns> public override Attempt <IShipment> Build() { // invoice var invoice = _merchelloContext.Services.InvoiceService.GetByKey(_order.InvoiceKey); if (invoice == null) { return(Attempt <IShipment> .Fail(new NullReferenceException("An invoice could not be found for the order passed"))); } // shipment line item var shipmentLineItem = invoice.Items.FirstOrDefault(x => x.LineItemType == LineItemType.Shipping); if (shipmentLineItem == null) { return(Attempt <IShipment> .Fail(new NullReferenceException("An shipment could not be found in the invoice assoiciated with the order passed"))); } // the shipment var quoted = shipmentLineItem.ExtendedData.GetShipment <InvoiceLineItem>(); if (quoted == null) { return(Attempt <IShipment> .Fail(new NullReferenceException("An shipment could not be found in the invoice assoiciated with the order passed"))); } var status = _merchelloContext.Services.ShipmentService.GetShipmentStatusByKey(_shipmentStatusKey) ?? _merchelloContext.Services.ShipmentService.GetShipmentStatusByKey(Core.Constants.ShipmentStatus.Quoted); // execute the change var attempt = TaskHandlers.Any() ? TaskHandlers.First().Execute( new Shipment(status, quoted.GetOriginAddress(), quoted.GetDestinationAddress()) { ShipMethodKey = _shipMethodKey, VersionKey = quoted.VersionKey, Carrier = _carrier, TrackingCode = _trackingNumber, TrackingUrl = _trackingUrl }) : Attempt <IShipment> .Fail(new InvalidOperationException("The configuration Chain Task List could not be instantiated.")); return(attempt); }
async private void GetStatus(object sender, EventArgs e) { var status = await Task.Run(() => TaskHandlers.Status()); if (status != null) { var cacheFolderPath = string.Format("{0}\\.crc\\cache", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); if (status.CrcStatus != "") { CrcStatus.Text = status.CrcStatus; } if (status.OpenshiftStatus != "") { OpenShiftStatus.Text = string.Format("{0} (v{1})", status.OpenshiftStatus, status.OpenshiftVersion); } DiskUsage.Text = string.Format("{0} of {1} (Inside the CRC VM)", FileSize.HumanReadable(status.DiskUse), FileSize.HumanReadable(status.DiskSize)); CacheUsage.Text = FileSize.HumanReadable(GetFolderSize.SizeInBytes(cacheFolderPath)); CacheFolder.Text = cacheFolderPath; } }
/// <summary> /// Builds the invoice /// </summary> /// <returns>The Attempt{IInvoice} representing the successful creation of an invoice</returns> public override Attempt <IInvoice> Build() { var unpaid = _salePreparation.MerchelloContext.Services.InvoiceService.GetInvoiceStatusByKey(Core.Constants.DefaultKeys.InvoiceStatus.Unpaid); if (unpaid == null) { return(Attempt <IInvoice> .Fail(new NullReferenceException("Unpaid invoice status query returned null"))); } var invoice = new Invoice(unpaid) { VersionKey = _salePreparation.ItemCache.VersionKey }; // Associate a customer with the invoice if it is a known customer. if (!_salePreparation.Customer.IsAnonymous) { invoice.CustomerKey = _salePreparation.Customer.Key; } var attempt = TaskHandlers.Any() ? TaskHandlers.First().Execute(invoice) : Attempt <IInvoice> .Fail(new InvalidOperationException("The configuration Chain Task List could not be instantiated")); if (!attempt.Success) { return(attempt); } var charges = attempt.Result.Items.Where(x => x.LineItemType != LineItemType.Discount).Sum(x => x.TotalPrice); var discounts = attempt.Result.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice); // total the invoice decimal converted; attempt.Result.Total = Math.Round(decimal.TryParse((charges - discounts).ToString(CultureInfo.InvariantCulture), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture.NumberFormat, out converted) ? converted : 0, 2); return(attempt); }
async private void StartMenu_Click(object sender, EventArgs e) { // Check using get-config if pullSecret is configured var configs = TaskHandlers.ConfigView(); if (configs.Configs.PullSecretFile == "") { var pullSecretForm = new PullSecretPickerForm(); var pullSecretPath = pullSecretForm.ShowFilePicker(); if (pullSecretPath == "") { DisplayMessageBox.Warn("No Pull Secret was provided, Cannot start cluster without pull secret."); return; } Dictionary <String, dynamic> pullSecretConfig = new Dictionary <String, dynamic> { ["pull-secret-file"] = pullSecretPath }; TaskHandlers.SetConfig(pullSecretConfig); } ShowNotification(@"Starting Cluster", ToolTipIcon.Info); var startResult = await Task.Run(() => TaskHandlers.Start()); if (startResult == null) { return; } if (startResult.KubeletStarted) { DisplayMessageBox.Info(@"CodeReady Containers Cluster has started", @"Cluster Started"); } else { DisplayMessageBox.Warn(@"Cluster did not start. Please check detailed status"); } }