public override async void Process(ActionData actionData) { string str; if (!this._applicationState.IsLocked) { bool asBoolean = actionData.GetAsBoolean("RunInBackground", true); string backupLocation = DatabaseToolsSettings.GetBackupLocation(); string databaseName = DatabaseToolsSettings.Settings.DatabaseName; if (LocalSettings.DatabaseLabel != "SQ" && LocalSettings.DatabaseLabel != "LD") { asBoolean = false; } if (asBoolean) { str = await this._backupHelper.CreateBackupAsync(backupLocation, databaseName, 'R'); } else { str = this._backupHelper.CreateBackup(backupLocation, databaseName, 'R'); } string str1 = str; if (!string.IsNullOrEmpty(str1)) { MessageBox.Show(str1, "Database Backup Module", MessageBoxButton.OK, MessageBoxImage.Hand); } } else { IMethodQueue methodQueue = this._methodQueue; methodQueue.Queue("BackupDatabase", () => this.Process(actionData)); } }
public override void Process(ActionData actionData) { var priceTag = actionData.GetAsString("PriceTag"); var departmentName = actionData.GetAsString("DepartmentName"); _departmentService.UpdatePriceTag(departmentName, priceTag); _methodQueue.Queue("ResetCache", () => Helper.ResetCache(_triggerService, _applicationState)); }
protected override void OnDeleteItem(object obj) { base.OnDeleteItem(obj); _methodQueue.Queue("UpdateCronObjects", _triggerService.UpdateCronObjects); }
public void DisplayPopup(string title, string content, string headerColor, Action <object> action = null, object actionParameter = null) { _popupDataViewModel.Add(title, content, headerColor, action, actionParameter); PopupWindow.Show(); _methodQueue.Queue("DisplayPopups", DisplayPopups); }
protected override void OnSave(string value) { LastTrigger = DateTime.Now; base.OnSave(value); _methodQueue.Queue("UpdateCronObjects", _triggerService.UpdateCronObjects); }
public override void Process(ActionData actionData) { _methodQueue.Queue("ResetCache", () => Helper.ResetCache(_triggerService, _applicationState)); }
private static void HandleEvents() { EventServiceFactory.EventService.GetEvent <GenericEvent <ActionData> >().Subscribe(x => { if (x.Value.Action.ActionType == ActionNames.StartProcess) { var fileName = x.Value.GetAsString("FileName"); var arguments = x.Value.GetAsString("Arguments"); if (!string.IsNullOrEmpty(fileName)) { var psi = new ProcessStartInfo(fileName, arguments); var isHidden = x.Value.GetAsBoolean("IsHidden"); if (isHidden) { psi.WindowStyle = ProcessWindowStyle.Hidden; } var useShellExecute = x.Value.GetAsBoolean("UseShellExecute"); if (useShellExecute) { psi.UseShellExecute = true; } var workingDirectory = x.Value.GetAsString("WorkingDirectory"); if (!string.IsNullOrEmpty(workingDirectory)) { psi.WorkingDirectory = workingDirectory; } Process.Start(psi); } } if (x.Value.Action.ActionType == ActionNames.SetActiveTicketType) { var ticketTypeName = x.Value.GetAsString("TicketTypeName"); var ticketType = CacheService.GetTicketTypes().SingleOrDefault(y => y.Name == ticketTypeName); if (ticketType != null) { ApplicationState.TempTicketType = ticketType; } else if (ApplicationState.SelectedEntityScreen != null && ApplicationState.SelectedEntityScreen.TicketTypeId != 0) { ApplicationState.TempTicketType = CacheService.GetTicketTypeById(ApplicationState.SelectedEntityScreen.TicketTypeId); } else { ApplicationState.TempTicketType = CacheService.GetTicketTypeById(ApplicationState.CurrentDepartment.TicketTypeId); } } if (x.Value.Action.ActionType == ActionNames.ChangeTicketEntity) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); if (ticket != null) { var entityTypeName = x.Value.GetAsString("EntityTypeName"); var entityName = x.Value.GetAsString("EntityName"); if (!string.IsNullOrEmpty(entityTypeName)) { var entity = CacheService.GetEntityByName(entityTypeName, entityName); if (entity != null) { TicketService.UpdateEntity(ticket, entity); } } } } if (x.Value.Action.ActionType == ActionNames.UpdateOrder) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); var orders = GetOrders(x.Value, ticket); if (orders.Any()) { foreach (var order in orders) { if (!string.IsNullOrEmpty(x.Value.GetAsString("Quantity"))) { order.Quantity = x.Value.GetAsDecimal("Quantity"); } if (!string.IsNullOrEmpty(x.Value.GetAsString("Price"))) { order.UpdatePrice(x.Value.GetAsDecimal("Price"), ""); } if (!string.IsNullOrEmpty(x.Value.GetAsString("IncreaseInventory"))) { order.IncreaseInventory = x.Value.GetAsBoolean("IncreaseInventory"); } if (!string.IsNullOrEmpty(x.Value.GetAsString("DecreaseInventory"))) { order.DecreaseInventory = x.Value.GetAsBoolean("DecreaseInventory"); } if (!string.IsNullOrEmpty(x.Value.GetAsString("Locked"))) { order.Locked = x.Value.GetAsBoolean("Locked"); } if (!string.IsNullOrEmpty(x.Value.GetAsString("CalculatePrice"))) { order.CalculatePrice = x.Value.GetAsBoolean("CalculatePrice"); } if (!string.IsNullOrEmpty(x.Value.GetAsString("AccountTransactionType"))) { TicketService.ChangeOrdersAccountTransactionTypeId(ticket, new List <Order> { order }, CacheService.GetAccountTransactionTypeIdByName (x.Value.GetAsString("AccountTransactionType"))); } if (!string.IsNullOrEmpty(x.Value.GetAsString("PortionName")) || !string.IsNullOrEmpty(x.Value.GetAsString("PriceTag"))) { var portionName = x.Value.GetAsString("PortionName"); var priceTag = x.Value.GetAsString("PriceTag"); TicketService.UpdateOrderPrice(order, portionName, priceTag); } } } } // Not supported on XP machines. We'll move it to a module later //if (x.Value.Action.ActionType == ActionNames.ExecutePowershellScript) //{ // var script = x.Value.GetAsString("Script"); // if (!string.IsNullOrEmpty(script)) // { // if (Utility.IsValidFile(script)) script = File.ReadAllText(script); // var runspace = RunspaceFactory.CreateRunspace(); // runspace.Open(); // runspace.SessionStateProxy.SetVariable("locator", ServiceLocator.Current); // var pipeline = runspace.CreatePipeline(script); // pipeline.Invoke(); // runspace.Close(); // } //} if (x.Value.Action.ActionType == ActionNames.DisplayPaymentScreen) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); if (ticket != null) { ticket.PublishEvent(EventTopicNames.MakePayment); } } if (x.Value.Action.ActionType == ActionNames.LockTicket) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); if (ticket != null) { ticket.RequestLock(); } } if (x.Value.Action.ActionType == ActionNames.LoadTicket) { var ticketId = x.Value.GetAsInteger("TicketId"); var ticket = TicketService.OpenTicket(ticketId); x.Value.DataObject = new { Ticket = ticket }; ticket.PublishEvent(EventTopicNames.SetSelectedTicket); } if (x.Value.Action.ActionType == ActionNames.DisplayTicket) { var ticketId = x.Value.GetAsInteger("TicketId"); if (ticketId > 0) { ExtensionMethods.PublishIdEvent(ticketId, EventTopicNames.DisplayTicket); } else { EventServiceFactory.EventService.PublishEvent(EventTopicNames.RefreshSelectedTicket); } } if (x.Value.Action.ActionType == ActionNames.DisplayTicketList) { var ticketTagName = x.Value.GetAsString("TicketTagName"); var ticketStateName = x.Value.GetAsString("TicketStateName"); if (!string.IsNullOrEmpty(ticketStateName)) { var dt = new TicketStateData { StateName = ticketStateName }; dt.PublishEvent(EventTopicNames.ActivateTicketList); } else if (!string.IsNullOrEmpty(ticketTagName)) { var dt = new TicketTagGroup { Name = ticketTagName }; dt.PublishEvent(EventTopicNames.ActivateTicketList); } } if (x.Value.Action.ActionType == ActionNames.CreateTicket) { EventServiceFactory.EventService.PublishEvent(EventTopicNames.CreateTicket); } if (x.Value.Action.ActionType == ActionNames.UnlockTicket) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); if (ticket != null) { ticket.UnLock(); } EventServiceFactory.EventService.PublishEvent(EventTopicNames.UnlockTicketRequested); } if (x.Value.Action.ActionType == ActionNames.MarkTicketAsClosed) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); if (ticket != null) { ticket.Close(); } } if (x.Value.Action.ActionType == ActionNames.CloseActiveTicket) { EventServiceFactory.EventService.PublishEvent(EventTopicNames.CloseTicketRequested, true); } if (x.Value.Action.ActionType == ActionNames.UpdateEntityState) { var entityId = x.Value.GetDataValueAsInt("EntityId"); var entityTypeId = x.Value.GetDataValueAsInt("EntityTypeId"); var stateName = x.Value.GetAsString("EntityStateName"); var state = x.Value.GetAsString("EntityState"); if (state != null) { if (entityId > 0 && entityTypeId > 0) { EntityService.UpdateEntityState(entityId, entityTypeId, stateName, state); } else { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); if (ticket != null) { var entityTypeName = x.Value.GetDataValueAsString("EntityTypeName"); foreach (var ticketEntity in ticket.TicketEntities) { var entityType = CacheService.GetEntityTypeById(ticketEntity.EntityTypeId); if (string.IsNullOrEmpty(entityTypeName.Trim()) || entityType.Name == entityTypeName) { EntityService.UpdateEntityState(ticketEntity.EntityId, ticketEntity.EntityTypeId, stateName, state); } } } } } } if (x.Value.Action.ActionType == ActionNames.UpdateProgramSetting) { var settingName = x.Value.GetAsString("SettingName"); var updateType = x.Value.GetAsString("UpdateType"); if (!string.IsNullOrEmpty(settingName)) { var isLocal = x.Value.GetAsBoolean("IsLocal"); var setting = isLocal ? SettingService.ReadLocalSetting(settingName) : SettingService.ReadGlobalSetting(settingName); if (updateType == Resources.Increase) { var settingValue = x.Value.GetAsInteger("SettingValue"); if (string.IsNullOrEmpty(setting.StringValue)) { setting.IntegerValue = settingValue; } else { setting.IntegerValue = setting.IntegerValue + settingValue; } } else if (updateType == Resources.Decrease) { var settingValue = x.Value.GetAsInteger("SettingValue"); if (string.IsNullOrEmpty(setting.StringValue)) { setting.IntegerValue = settingValue; } else { setting.IntegerValue = setting.IntegerValue - settingValue; } } else if (updateType == Resources.Toggle) { var settingValue = x.Value.GetAsString("SettingValue"); var parts = settingValue.Split(','); if (string.IsNullOrEmpty(setting.StringValue)) { setting.StringValue = parts[0]; } else { for (var i = 0; i < parts.Length; i++) { if (parts[i] == setting.StringValue) { setting.StringValue = (i + 1) < parts.Length ? parts[i + 1] : parts[0]; break; } } } } else { var settingValue = x.Value.GetAsString("SettingValue"); setting.StringValue = settingValue; } if (!isLocal) { SettingService.SaveProgramSettings(); } } } if (x.Value.Action.ActionType == ActionNames.RefreshCache) { MethodQueue.Queue("ResetCache", ResetCache); } if (x.Value.Action.ActionType == ActionNames.SendMessage) { AppServices.MessagingService.SendMessage("ActionMessage", x.Value.GetAsString("Command")); } if (x.Value.Action.ActionType == ActionNames.SendEmail) { EmailService.SendEMailAsync(x.Value.GetAsString("SMTPServer"), x.Value.GetAsString("SMTPUser"), x.Value.GetAsString("SMTPPassword"), x.Value.GetAsInteger("SMTPPort"), x.Value.GetAsString("ToEMailAddress"), x.Value.GetAsString("CCEmailAddresses"), x.Value.GetAsString("FromEMailAddress"), x.Value.GetAsString("Subject"), x.Value.GetAsString("EMailMessage"), x.Value.GetAsString("FileName"), x.Value.GetAsBoolean("DeleteFile"), x.Value.GetAsBoolean("BypassSslErrors")); } if (x.Value.Action.ActionType == ActionNames.UpdateTicketCalculation) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); if (ticket != null) { var calculationTypeName = x.Value.GetAsString("CalculationType"); var calculationType = CacheService.GetCalculationTypeByName(calculationTypeName); if (calculationType != null) { var amount = x.Value.GetAsDecimal("Amount"); ticket.AddCalculation(calculationType, amount); TicketService.RecalculateTicket(ticket); EventServiceFactory.EventService.PublishEvent(EventTopicNames.RegenerateSelectedTicket); } } } if (x.Value.Action.ActionType == ActionNames.AddOrder) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); if (ticket != null) { var menuItemName = x.Value.GetAsString("MenuItemName"); var menuItem = CacheService.GetMenuItem(y => y.Name == menuItemName); var portionName = x.Value.GetAsString("PortionName"); var quantity = x.Value.GetAsDecimal("Quantity"); var tag = x.Value.GetAsString("Tag"); var order = TicketService.AddOrder(ticket, menuItem.Id, quantity, portionName, null); if (order != null) { order.Tag = tag; } order.PublishEvent(EventTopicNames.OrderAdded); } } if (x.Value.Action.ActionType == ActionNames.UpdateTicketTag) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); if (ticket != null) { var tagName = x.Value.GetAsString("TagName"); var tagValue = x.Value.GetAsString("TagValue"); ticket.SetTagValue(tagName, tagValue); } } if (x.Value.Action.ActionType == ActionNames.UpdateTicketState) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); if (ticket != null) { var stateName = x.Value.GetAsString("StateName"); var currentState = x.Value.GetAsString("CurrentState"); var state = x.Value.GetAsString("State"); var stateValue = x.Value.GetAsString("StateValue"); var quantity = x.Value.GetAsInteger("Quantity"); TicketService.UpdateTicketState(ticket, stateName, currentState, state, stateValue, quantity); } } if (x.Value.Action.ActionType == ActionNames.UpdateOrderState) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); var orders = GetOrders(x.Value, ticket); if (orders.Any()) { var stateName = x.Value.GetAsString("StateName"); var currentState = x.Value.GetAsString("CurrentState"); var groupOrder = x.Value.GetAsInteger("GroupOrder"); var state = x.Value.GetAsString("State"); var stateOrder = x.Value.GetAsInteger("StateOrder"); var stateValue = x.Value.GetAsString("StateValue"); TicketService.UpdateOrderStates(ticket, orders.ToList(), stateName, currentState, groupOrder, state, stateOrder, stateValue); } } if (x.Value.Action.ActionType == ActionNames.TagOrder || x.Value.Action.ActionType == ActionNames.UntagOrder || x.Value.Action.ActionType == ActionNames.RemoveOrderTag) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); var orders = GetOrders(x.Value, ticket); if (orders.Any()) { var tagName = x.Value.GetAsString("OrderTagName"); var orderTag = CacheService.GetOrderTagGroupByName(tagName); if (orderTag != null) { var tagValue = x.Value.GetAsString("OrderTagValue"); var oldTagValue = x.Value.GetAsString("OldOrderTagValue"); var tagNote = x.Value.GetAsString("OrderTagNote"); var orderTagValue = orderTag.OrderTags.SingleOrDefault(y => y.Name == tagValue); if (!string.IsNullOrEmpty(x.Value.GetAsString("OrderTagPrice"))) { var price = x.Value.GetAsDecimal("OrderTagPrice"); orderTagValue.Price = price; } if (orderTagValue != null) { if (!string.IsNullOrEmpty(oldTagValue)) { orders = orders.Where(o => o.OrderTagExists(y => y.OrderTagGroupId == orderTag.Id && y.TagValue == oldTagValue)).ToList(); } if (x.Value.Action.ActionType == ActionNames.TagOrder) { TicketService.TagOrders(ticket, orders, orderTag, orderTagValue, tagNote); } if (x.Value.Action.ActionType == ActionNames.UntagOrder) { TicketService.UntagOrders(ticket, orders, orderTag, orderTagValue); } } } } } if (x.Value.Action.ActionType == ActionNames.MoveTaggedOrders) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); var orderTagName = x.Value.GetAsString("OrderTagName"); if (ticket != null && !string.IsNullOrEmpty(orderTagName)) { var orderTagValue = x.Value.GetAsString("OrderTagValue"); if (ticket.Orders.Any(y => y.OrderTagExists(z => z.TagName == orderTagName && z.TagValue == orderTagValue))) { var tid = ticket.Id; EventServiceFactory.EventService.PublishEvent(EventTopicNames.CloseTicketRequested, true); ticket = TicketService.OpenTicket(tid); var orders = ticket.Orders.Where(y => y.OrderTagExists(z => z.TagName == orderTagName && z.TagValue == orderTagValue)).ToArray(); var commitResult = TicketService.MoveOrders(ticket, orders, 0); if (string.IsNullOrEmpty(commitResult.ErrorMessage) && commitResult.TicketId > 0) { ExtensionMethods.PublishIdEvent(commitResult.TicketId, EventTopicNames.DisplayTicket); } else { ExtensionMethods.PublishIdEvent(tid, EventTopicNames.DisplayTicket); } } } } if (x.Value.Action.ActionType == ActionNames.UpdatePriceTag) { using (var workspace = WorkspaceFactory.Create()) { var priceTag = x.Value.GetAsString("PriceTag"); var departmentName = x.Value.GetAsString("DepartmentName"); var department = workspace.Single <Department>(y => y.Name == departmentName); if (department != null) { department.PriceTag = priceTag; workspace.CommitChanges(); MethodQueue.Queue("ResetCache", ResetCache); } } } if (x.Value.Action.ActionType == ActionNames.ExecutePrintJob) { var ticket = x.Value.GetDataValue <Ticket>("Ticket"); var pjName = x.Value.GetAsString("PrintJobName"); if (!string.IsNullOrEmpty(pjName)) { TicketService.UpdateTicketNumber(ticket, ApplicationState.CurrentTicketType.TicketNumerator); var j = CacheService.GetPrintJobByName(pjName); if (j != null) { if (ticket != null) { var orderTagName = x.Value.GetAsString("OrderTagName"); var orderTagValue = x.Value.GetAsString("OrderTagValue"); var orderStateName = x.Value.GetAsString("OrderStateName"); var orderState = x.Value.GetAsString("OrderState"); var orderStateValue = x.Value.GetAsString("OrderStateValue"); Expression <Func <Order, bool> > expression = ex => true; if (!string.IsNullOrWhiteSpace(orderTagName)) { expression = ex => ex.OrderTagExists(y => y.TagName == orderTagName && y.TagValue == orderTagValue); } if (!string.IsNullOrWhiteSpace(orderStateName)) { expression = expression.And(ex => ex.IsInState(orderStateName, orderState)); if (!string.IsNullOrWhiteSpace(orderStateValue)) { expression = expression.And(ex => ex.IsInState(orderStateValue)); } } PrinterService.PrintTicket(ticket, j, expression.Compile()); } else { PrinterService.ExecutePrintJob(j); } } } } }); }
public void DisplayPopup(string title, string content, object dataObject, string eventMessage, string headerColor) { _popupDataViewModel.Add(title, content, dataObject, eventMessage, headerColor); PopupWindow.Show(); _methodQueue.Queue("DisplayPopups", DisplayPopups); }