Ejemplo n.º 1
0
        public ConfigInfo GetAll(String appId, String secret, String token, String scope, Int32 version)
        {
            if (appId.IsNullOrEmpty() && token.IsNullOrEmpty()) throw new ArgumentNullException(nameof(appId));

            // 验证
            var app = Valid(appId, secret, token);
            var ip = HttpContext.GetUserHost();

            // 版本没有变化时,不做计算处理,不返回配置数据
            if (version > 0 && version >= app.Version) return new ConfigInfo { Version = app.Version, UpdateTime = app.UpdateTime };

            // 作用域为空时重写
            scope = scope.IsNullOrEmpty() ? AppRule.CheckScope(app.Id, ip) : scope;

            var dic = _configService.GetConfigs(app, scope);

            return new ConfigInfo
            {
                Version = app.Version,
                Scope = scope,
                SourceIP = ip,
                NextVersion = app.NextVersion,
                NextPublish = app.PublishTime.ToFullString(""),
                UpdateTime = app.UpdateTime,
                Configs = dic,
            };
        }
Ejemplo n.º 2
0
        private bool SatisfiesCustomConstraints(AppRule appRule, object dataObject)
        {
            var cv = appRule.RuleConstraints;

            if (string.IsNullOrEmpty(cv))
            {
                return(true);
            }
            cv = _preprocessor.Process(cv, dataObject);
            var cvs = JsonHelper.Deserialize <List <RuleConstraintValue> >(cv);

            if (!cvs.Any())
            {
                return(true);
            }
            switch ((RuleConstraintMatch)appRule.ConstraintMatch)
            {
            case RuleConstraintMatch.MatchesAny: return(cvs.Any(x => x.Satisfies(dataObject)));

            case RuleConstraintMatch.MatchesAll: return(cvs.All(x => x.Satisfies(dataObject)));

            case RuleConstraintMatch.NotMatchesAny: return(cvs.Any(x => !x.Satisfies(dataObject)));

            case RuleConstraintMatch.NotMatchesAll: return(cvs.All(x => !x.Satisfies(dataObject)));

            default: return(cvs.GroupBy(x => x.Left).All(x => x.Any(y => y.Satisfies(dataObject))));
            }
        }
Ejemplo n.º 3
0
        public ConfigInfo GetAll([FromBody] ConfigInModel model, String token)
        {
            if (model.AppId.IsNullOrEmpty() && token.IsNullOrEmpty()) throw new ArgumentNullException(nameof(model.AppId));

            // 验证
            var app = Valid(model.AppId, model.Secret, token);
            var ip = HttpContext.GetUserHost();

            // 使用键和缺失键
            if (!model.UsedKeys.IsNullOrEmpty()) app.UsedKeys = model.UsedKeys;
            if (!model.MissedKeys.IsNullOrEmpty()) app.MissedKeys = model.MissedKeys;
            app.Update();

            // 版本没有变化时,不做计算处理,不返回配置数据
            if (model.Version > 0 && model.Version >= app.Version) return new ConfigInfo { Version = app.Version, UpdateTime = app.UpdateTime };

            // 作用域为空时重写
            var scope = model.Scope;
            scope = scope.IsNullOrEmpty() ? AppRule.CheckScope(app.Id, ip) : scope;

            var dic = _configService.GetConfigs(app, scope);

            return new ConfigInfo
            {
                Version = app.Version,
                Scope = scope,
                SourceIP = ip,
                NextVersion = app.NextVersion,
                NextPublish = app.PublishTime.ToFullString(""),
                UpdateTime = app.UpdateTime,
                Configs = dic,
            };
        }
Ejemplo n.º 4
0
        public override void Up()
        {
            var dc = ApplicationContext as DbContext;

            if (dc != null)
            {
                var updateTicketStatusAction = dc.Set <AppAction>().SingleOrDefault(x => x.Name == Resources.UpdateTicketStatus);
                var updateMergedTicket       = dc.Set <AppRule>().SingleOrDefault(x => x.Name == Resources.UpdateMergedTicketsState);
                if (updateTicketStatusAction != null)
                {
                    if (updateMergedTicket != null)
                    {
                        updateMergedTicket.Actions.Add(new ActionContainer(updateTicketStatusAction)
                        {
                            ParameterValues = string.Format("Status={0}", Resources.NewOrders)
                        });
                    }

                    var ticketMovedRule = new AppRule {
                        Name = Resources.TicketMovedRule, EventName = "TicketMoved"
                    };
                    ticketMovedRule.Actions.Add(new ActionContainer(updateTicketStatusAction)
                    {
                        ParameterValues = string.Format("Status={0}", Resources.NewOrders)
                    });
                    ticketMovedRule.AddRuleMap();
                    dc.Set <AppRule>().Add(ticketMovedRule);
                }
                dc.SaveChanges();
            }

            Create.Column("UsePlainSum").OnTable("Calculations").AsBoolean().WithDefaultValue(false);
            Create.Column("UsePlainSum").OnTable("CalculationTypes").AsBoolean().WithDefaultValue(false);
        }
Ejemplo n.º 5
0
        public override void Up()
        {
            var dc = ApplicationContext as DbContext;

            var closeTicketAutomation = new AutomationCommand {
                Name = Resources.CloseTicket, ButtonHeader = Resources.Close, SortOrder = -1, Color = "#FFFF0000", FontSize = 40
            };

            closeTicketAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                EnabledStates = string.Format("{0},{1},{2},{3},IsClosed", Resources.New, Resources.NewOrders, Resources.Unpaid, Resources.Locked), VisibleStates = "*", DisplayUnderTicket = true
            });
            dc.Set <AutomationCommand>().Add(closeTicketAutomation);

            var settleAutomation = new AutomationCommand {
                Name = Resources.Settle, ButtonHeader = Resources.Settle, SortOrder = -2, FontSize = 40
            };

            settleAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                EnabledStates = "*", VisibleStates = "*", DisplayUnderTicket = true
            });
            dc.Set <AutomationCommand>().Add(settleAutomation);

            dc.SaveChanges();

            var displayPaymentScreenAction = new AppAction {
                ActionType = ActionNames.DisplayPaymentScreen, Name = Resources.DisplayPaymentScreen, Parameter = "", SortOrder = -1
            };

            dc.Set <AppAction>().Add(displayPaymentScreenAction);

            var closeTicketAction = dc.Set <AppAction>().FirstOrDefault(x => x.ActionType == ActionNames.CloseActiveTicket);

            if (closeTicketAction == null)
            {
                closeTicketAction = new AppAction {
                    ActionType = ActionNames.CloseActiveTicket, Name = Resources.CloseTicket, Parameter = "", SortOrder = -1
                };
                dc.Set <AppAction>().Add(closeTicketAction);
            }
            dc.SaveChanges();

            var closeTicketRule = new AppRule {
                Name = string.Format(Resources.Rule_f, Resources.CloseTicket), EventName = "AutomationCommandExecuted", EventConstraints = "AutomationCommandName;=;" + Resources.CloseTicket, SortOrder = -1
            };

            closeTicketRule.Actions.Add(new ActionContainer(closeTicketAction));
            closeTicketRule.AddRuleMap();
            dc.Set <AppRule>().Add(closeTicketRule);

            var settleTicketRule = new AppRule {
                Name = string.Format(Resources.Rule_f, Resources.Settle), EventName = "AutomationCommandExecuted", EventConstraints = "AutomationCommandName;=;" + Resources.Settle, SortOrder = -1
            };

            settleTicketRule.Actions.Add(new ActionContainer(displayPaymentScreenAction));
            settleTicketRule.AddRuleMap();
            dc.Set <AppRule>().Add(settleTicketRule);

            dc.SaveChanges();
        }
Ejemplo n.º 6
0
        private bool CanExecuteRule(AppRule appRule, object dataObject)
        {
            if (string.IsNullOrEmpty(appRule.CustomConstraint))
            {
                return(true);
            }
            var expression = _settingService.ReplaceSettingValues(appRule.CustomConstraint);

            return(_expressionService.Eval("result = " + expression, dataObject, true));
        }
Ejemplo n.º 7
0
        public ConfigInfo GetAll([FromBody] ConfigInModel model, String token)
        {
            if (model.AppId.IsNullOrEmpty() && token.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(model.AppId));
            }

            // 验证
            var(app, online) = Valid(model.AppId, model.Secret, model.ClientId, token);
            var ip = HttpContext.GetUserHost();

            // 使用键和缺失键
            if (!model.UsedKeys.IsNullOrEmpty())
            {
                app.UsedKeys = model.UsedKeys;
            }
            if (!model.MissedKeys.IsNullOrEmpty())
            {
                app.MissedKeys = model.MissedKeys;
            }
            app.Update();

            // 作用域为空时重写
            var scope = model.Scope;

            scope = scope.IsNullOrEmpty() ? AppRule.CheckScope(app.Id, ip) : scope;

            // 作用域有改变时,也要返回配置数据
            var change = online.Scope != scope;

            online.Scope = scope;
            online.SaveAsync(3_000);

            // 版本没有变化时,不做计算处理,不返回配置数据
            if (!change && model.Version > 0 && model.Version >= app.Version)
            {
                return new ConfigInfo {
                           Version = app.Version, UpdateTime = app.UpdateTime
                }
            }
            ;

            var dic = _configService.GetConfigs(app, scope);

            return(new ConfigInfo
            {
                Version = app.Version,
                Scope = scope,
                SourceIP = ip,
                NextVersion = app.NextVersion,
                NextPublish = app.PublishTime.ToFullString(""),
                UpdateTime = app.UpdateTime,
                Configs = dic,
            });
        }
Ejemplo n.º 8
0
        public bool Satisfies(AppRule appRule, object dataParameter)
        {
            if (string.IsNullOrEmpty(appRule.EventConstraints))
            {
                return(true);
            }

            _dataObject = dataParameter.ToDynamic();

            if (GetConditions(appRule).Any(DoesNotSatisfy))
            {
                return(false);
            }

            return(SatisfiesCustomConstraint(appRule.CustomConstraint, dataParameter));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Serializes this instance of <see cref="NetworkSecurityRuleResources" /> into a <see cref="Carbon.Json.JsonNode" />.
        /// </summary>
        /// <param name="container">The <see cref="Carbon.Json.JsonObject"/> container to serialize this object into. If the caller
        /// passes in <c>null</c>, a new instance will be created and returned to the caller.</param>
        /// <param name="serializationMode">Allows the caller to choose the depth of the serialization. See <see cref="Microsoft.Rest.ClientRuntime.SerializationMode"/>.</param>
        /// <returns>
        /// a serialized instance of <see cref="NetworkSecurityRuleResources" /> as a <see cref="Carbon.Json.JsonNode" />.
        /// </returns>
        public Carbon.Json.JsonNode ToJson(Carbon.Json.JsonObject container, Microsoft.Rest.ClientRuntime.SerializationMode serializationMode)
        {
            container = container ?? new Carbon.Json.JsonObject();

            bool returnNow = false;

            BeforeToJson(ref container, ref returnNow);
            if (returnNow)
            {
                return(container);
            }
            AddIf(null != AppRule ? (Carbon.Json.JsonNode)AppRule.ToJson(null) : null, "app_rule", container.Add);
            AddIf(null != IsolationRule ? (Carbon.Json.JsonNode)IsolationRule.ToJson(null) : null, "isolation_rule", container.Add);
            AddIf(null != QuarantineRule ? (Carbon.Json.JsonNode)QuarantineRule.ToJson(null) : null, "quarantine_rule", container.Add);
            AfterToJson(ref container);
            return(container);
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> AddRule(string packetType)
        {
            bool ret = PacketType.TryParse(packetType, true, out PacketType inputPacketType);

            if (ret != true)
            {
                return(BadRequest("packetType error."));
            }
            AppRule rule = new AppRule()
            {
                PacketType = inputPacketType,
            };

            db.AppRules.Add(rule);
            await db.SaveChangesAsync();

            return(Ok(rule.Id));
        }
Ejemplo n.º 11
0
        public ConfigInfo GetAll(String appId, String secret, String clientId, String token, String scope, Int32 version)
        {
            if (appId.IsNullOrEmpty() && token.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(appId));
            }

            // 验证
            var(app, online) = Valid(appId, secret, clientId, token);
            var ip = HttpContext.GetUserHost();

            // 作用域为空时重写
            scope = scope.IsNullOrEmpty() ? AppRule.CheckScope(app.Id, ip) : scope;

            // 作用域有改变时,也要返回配置数据
            var change = online.Scope != scope;

            online.Scope = scope;
            online.SaveAsync(3_000);

            // 版本没有变化时,不做计算处理,不返回配置数据
            if (!change && version > 0 && version >= app.Version)
            {
                return new ConfigInfo {
                           Version = app.Version, UpdateTime = app.UpdateTime
                }
            }
            ;
            var dic = _configService.GetConfigs(app, scope);

            return(new ConfigInfo
            {
                Version = app.Version,
                Scope = scope,
                SourceIP = ip,
                NextVersion = app.NextVersion,
                NextPublish = app.PublishTime.ToFullString(""),
                UpdateTime = app.UpdateTime,
                Configs = dic,
            });
        }
Ejemplo n.º 12
0
        private bool SatisfiesConditions(AppRule appRule, object dataObject)
        {
            var conditions = appRule.EventConstraints.Split('#').Select(x => new RuleConstraint(x));

            var parameterNames = ((IDictionary <string, object>)dataObject).Keys;

            foreach (var condition in conditions)
            {
                var parameterName = parameterNames.FirstOrDefault(condition.Name.Equals);

                if (!string.IsNullOrEmpty(parameterName))
                {
                    var parameterValue = ((IDictionary <string, object>)dataObject)[parameterName];
                    if (condition.IsValueDifferent(parameterValue))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 13
0
        private bool SatisfiesConditions(AppRule appRule, object dataObject)
        {
            var conditions = appRule.EventConstraints.Split('#').Select(x => new RuleConstraint(x));

            var parameterNames = dataObject.GetType().GetProperties().Select(x => x.Name).ToList();

            foreach (var condition in conditions)
            {
                var parameterName = parameterNames.FirstOrDefault(condition.Name.Equals);

                if (!string.IsNullOrEmpty(parameterName))
                {
                    var property       = dataObject.GetType().GetProperty(parameterName);
                    var parameterValue = property.GetValue(dataObject, null) ?? "";
                    if (condition.IsValueDifferent(parameterValue))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 14
0
        private bool SatisfiesConditions(AppRule appRule, object dataObject)
        {
            var conditions = appRule.EventConstraints.Split('#')
                             .Select(x => new RuleConstraint(x));

            var parameterNames = dataObject.GetType().GetProperties().Select(x => x.Name).ToList();

            foreach (var condition in conditions)
            {
                var parameterName = parameterNames.FirstOrDefault(condition.Name.Equals);

                if (!string.IsNullOrEmpty(parameterName))
                {
                    var property       = dataObject.GetType().GetProperty(parameterName);
                    var parameterValue = property.GetValue(dataObject, null) ?? "";
                    if (!condition.ValueEquals(parameterValue))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (condition.Name.StartsWith("SN$"))
                    {
                        var settingData = condition.Name.Replace("SN$", "");
                        while (Regex.IsMatch(settingData, "\\[[^\\]]+\\]"))
                        {
                            var paramvalue  = Regex.Match(settingData, "\\[[^\\]]+\\]").Groups[0].Value;
                            var insideValue = paramvalue.Trim(new[] { '[', ']' });
                            if (parameterNames.Contains(insideValue))
                            {
                                var v = dataObject.GetType().GetProperty(insideValue).GetValue(dataObject, null).ToString();
                                settingData = settingData.Replace(paramvalue, v);
                            }
                            else
                            {
                                if (paramvalue == "[Day]")
                                {
                                    settingData = settingData.Replace(paramvalue, DateTime.Now.Day.ToString());
                                }
                                else if (paramvalue == "[Month]")
                                {
                                    settingData = settingData.Replace(paramvalue, DateTime.Now.Month.ToString());
                                }
                                else if (paramvalue == "[Year]")
                                {
                                    settingData = settingData.Replace(paramvalue, DateTime.Now.Year.ToString());
                                }
                                else
                                {
                                    settingData = settingData.Replace(paramvalue, "");
                                }
                            }
                        }

                        var customSettingValue = _settingService.ReadSetting(settingData).StringValue ?? "";
                        if (!condition.ValueEquals(customSettingValue))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 15
0
 public RlGet(AppRule origin)
 {
     _origin = origin;
 }
Ejemplo n.º 16
0
 private static IEnumerable <RuleConstraint> GetConditions(AppRule appRule)
 {
     return(appRule.EventConstraints.Split('#').Select(x => new RuleConstraint(x)));
 }
Ejemplo n.º 17
0
        public void GenerateSystemRules(IWorkspace workspace)
        {
            var closeTicketAutomation = new AutomationCommand {
                Name = Resources.CloseTicket, ButtonHeader = Resources.Close, SortOrder = -1, Color = "#FFFF0000", FontSize = 40
            };

            closeTicketAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                EnabledStates = string.Format("{0},{1},{2},{3},IsClosed", Resources.New, Resources.NewOrders, Resources.Unpaid, Resources.Locked), VisibleStates = "*", DisplayUnderTicket = true
            });
            workspace.Add(closeTicketAutomation);

            var settleAutomation = new AutomationCommand {
                Name = Resources.Settle, ButtonHeader = Resources.Settle, SortOrder = -2, FontSize = 40
            };

            settleAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                EnabledStates = "*", VisibleStates = "*", DisplayUnderTicket = true
            });
            workspace.Add(settleAutomation);

            var printBillAutomation = new AutomationCommand {
                Name = Resources.PrintBill, ButtonHeader = Resources.PrintBill, SortOrder = -1
            };

            printBillAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                EnabledStates = Resources.NewOrders + "," + Resources.Unpaid + ",IsClosed", VisibleStates = "*", DisplayOnTicket = true, DisplayOnPayment = true
            });
            workspace.Add(printBillAutomation);

            var unlockTicketAutomation = new AutomationCommand {
                Name = Resources.UnlockTicket, ButtonHeader = Resources.UnlockTicket, SortOrder = -1
            };

            unlockTicketAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                EnabledStates = Resources.Locked, VisibleStates = Resources.Locked, DisplayOnTicket = true
            });
            workspace.Add(unlockTicketAutomation);

            var addTicketAutomation = new AutomationCommand {
                Name = string.Format(Resources.Add_f, Resources.Ticket), ButtonHeader = string.Format(Resources.Add_f, Resources.Ticket), SortOrder = -1
            };

            addTicketAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                EnabledStates = string.Format("{0},{1}", Resources.Unpaid, Resources.Locked), VisibleStates = "*", DisplayOnTicket = true
            });
            workspace.Add(addTicketAutomation);

            var giftItemAutomation = new AutomationCommand {
                Name = Resources.Gift, ButtonHeader = Resources.Gift, SortOrder = -1
            };

            giftItemAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                EnabledStates = "GStatus=", VisibleStates = "GStatus=", DisplayOnOrders = true
            });
            workspace.Add(giftItemAutomation);

            var cancelGiftItemAutomation = new AutomationCommand {
                Name = string.Format(Resources.Cancel_f, Resources.Gift), ButtonHeader = string.Format(Resources.Cancel_f, Resources.Gift), SortOrder = -1
            };

            cancelGiftItemAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                EnabledStates = Resources.Gift, VisibleStates = Resources.Gift, DisplayOnOrders = true
            });
            workspace.Add(cancelGiftItemAutomation);

            var voidItemAutomation = new AutomationCommand {
                Name = Resources.Void, ButtonHeader = Resources.Void, SortOrder = -1
            };

            voidItemAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                EnabledStates = string.Format("GStatus={0}," + Resources.Submitted, Resources.Gift), VisibleStates = string.Format("GStatus=,GStatus={0}", Resources.Gift), DisplayOnOrders = true
            });
            workspace.Add(voidItemAutomation);

            var cancelVoidItemAutomation = new AutomationCommand {
                Name = string.Format(Resources.Cancel_f, Resources.Void), ButtonHeader = string.Format(Resources.Cancel_f, Resources.Void), SortOrder = -1
            };

            cancelVoidItemAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                EnabledStates = Resources.New, VisibleStates = Resources.Void, DisplayOnOrders = true
            });
            workspace.Add(cancelVoidItemAutomation);

            var newOrderState = new State {
                Name = Resources.NewOrders, Color = "Orange", GroupName = "Status"
            };

            workspace.Add(newOrderState);

            var availableState = new State {
                Name = Resources.Available, Color = "White", GroupName = "Status"
            };

            workspace.Add(availableState);

            var billRequestedState = new State {
                Name = Resources.BillRequested, Color = "Maroon", GroupName = "Status"
            };

            workspace.Add(billRequestedState);

            var giftStatus = new State {
                Name = Resources.Gift, GroupName = "GStatus", ShowOnEndOfDayReport = true, ShowOnProductReport = true, ShowOnTicket = true
            };

            workspace.Add(giftStatus);

            var status = new State {
                Name = Resources.Status, GroupName = "Status", ShowOnEndOfDayReport = true, ShowOnProductReport = false, ShowOnTicket = true
            };

            workspace.Add(status);

            var updateOrderAction = new AppAction
            {
                ActionType = ActionNames.UpdateOrder,
                Name       = string.Format(Resources.Update_f, Resources.Order),
                Parameter  = Params()
                             .Add("IncreaseInventory", "[:Increase]").Add("DecreaseInventory", "[:Decrease]")
                             .Add("CalculatePrice", "[:Calculate Price]").Add("Locked", "[:Locked]").
                             ToString(),
                SortOrder = -1
            };

            workspace.Add(updateOrderAction);

            var updateTicketStatusAction = new AppAction {
                ActionType = ActionNames.UpdateTicketState, Name = Resources.UpdateTicketStatus, Parameter = Params().Add("StateName", Resources.Status).Add("State", "[:Status]").Add("CurrentState", "[:Current Status]").ToString(), SortOrder = -1
            };

            workspace.Add(updateTicketStatusAction);
            var updateOrderStatusAction = new AppAction {
                ActionType = ActionNames.UpdateOrderState, Name = string.Format(Resources.Update_f, Resources.OrderStatus), Parameter = Params().Add("StateName", "Status").Add("State", "[:Status]").Add("CurrentState", "[:Current Status]").ToString(), SortOrder = -1
            };

            workspace.Add(updateOrderStatusAction);
            var updateOrderGiftStatusAction = new AppAction
            {
                ActionType = ActionNames.UpdateOrderState,
                Name       = Resources.UpdateOrderGiftState,
                Parameter  = Params()
                             .Add("StateName", "GStatus").Add("GroupOrder", "1")
                             .Add("CurrentState", "[:Current Status]").Add("State", "[:Status]")
                             .Add("StateOrder", "1").Add("StateValue", "[:Value]")
                             .ToString(),
                SortOrder = -1
            };

            workspace.Add(updateOrderGiftStatusAction);

            var updateEntityStateAction = new AppAction {
                ActionType = ActionNames.UpdateEntityState, Name = Resources.UpdateEntityState, Parameter = Params().Add("EntityStateName", "Status").Add("EntityState", "[:Status]").ToString(), SortOrder = -1
            };

            workspace.Add(updateEntityStateAction);
            var createTicketAction = new AppAction {
                ActionType = ActionNames.CreateTicket, Name = string.Format(Resources.Create_f, Resources.Ticket), Parameter = "", SortOrder = -1
            };

            workspace.Add(createTicketAction);
            var closeTicketAction = new AppAction {
                ActionType = ActionNames.CloseActiveTicket, Name = Resources.CloseTicket, Parameter = "", SortOrder = -1
            };

            workspace.Add(closeTicketAction);
            var displayPaymentScreenAction = new AppAction {
                ActionType = ActionNames.DisplayPaymentScreen, Name = Resources.DisplayPaymentScreen, Parameter = "", SortOrder = -1
            };

            workspace.Add(displayPaymentScreenAction);
            var printBillAction = new AppAction {
                ActionType = ActionNames.ExecutePrintJob, Name = Resources.ExecutePrintBillJob, Parameter = Params().Add("PrintJobName", Resources.PrintBill).ToString(), SortOrder = -1
            };

            workspace.Add(printBillAction);
            var printKitchenOrdersAction = new AppAction {
                ActionType = ActionNames.ExecutePrintJob, Name = Resources.ExecuteKitchenOrdersPrintJob, Parameter = Params().Add("PrintJobName", Resources.PrintOrdersToKitchenPrinter).Add("OrderStateName", "Status").Add("OrderState", Resources.New).ToString(), SortOrder = -1
            };

            workspace.Add(printKitchenOrdersAction);
            var lockTicketAction = new AppAction {
                ActionType = ActionNames.LockTicket, Name = Resources.LockTicket, Parameter = "", SortOrder = -1
            };

            workspace.Add(lockTicketAction);
            var unlockTicketAction = new AppAction {
                ActionType = ActionNames.UnlockTicket, Name = Resources.UnlockTicket, Parameter = "", SortOrder = -1
            };

            workspace.Add(unlockTicketAction);
            var markTicketAsClosed = new AppAction {
                ActionType = ActionNames.MarkTicketAsClosed, Name = Resources.MarkTicketAsClosed, Parameter = "", SortOrder = -1
            };

            workspace.Add(markTicketAsClosed);
            workspace.CommitChanges();

            var newTicketRule = new AppRule {
                Name = Resources.NewTicketCreatingRule, EventName = RuleEventNames.TicketCreated, SortOrder = -1
            };

            newTicketRule.Actions.Add(new ActionContainer(updateTicketStatusAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.New)
            });
            newTicketRule.AddRuleMap();
            workspace.Add(newTicketRule);

            var newOrderAddingRule = new AppRule {
                Name = Resources.NewOrderAddingRule, EventName = RuleEventNames.OrderAdded, SortOrder = -1
            };

            newOrderAddingRule.Actions.Add(new ActionContainer(updateTicketStatusAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.NewOrders)
            });
            newOrderAddingRule.Actions.Add(new ActionContainer(updateOrderStatusAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.New)
            });
            newOrderAddingRule.AddRuleMap();
            workspace.Add(newOrderAddingRule);

            var ticketPayCheckRule = new AppRule {
                Name = Resources.TicketPaymentCheck, EventName = RuleEventNames.BeforeTicketClosing, EventConstraints = "RemainingAmount;=;0", SortOrder = -1
            };

            ticketPayCheckRule.Actions.Add(new ActionContainer(updateTicketStatusAction)
            {
                ParameterValues = "Status=" + Resources.Paid
            });
            ticketPayCheckRule.Actions.Add(new ActionContainer(markTicketAsClosed));
            ticketPayCheckRule.AddRuleMap();
            workspace.Add(ticketPayCheckRule);

            var ticketMovedRule = new AppRule {
                Name = Resources.TicketMovedRule, EventName = RuleEventNames.TicketMoved, SortOrder = -1
            };

            ticketMovedRule.Actions.Add(new ActionContainer(updateTicketStatusAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.NewOrders)
            });
            ticketMovedRule.AddRuleMap();
            workspace.Add(ticketMovedRule);

            var ticketClosingRule = new AppRule {
                Name = string.Format(Resources.Rule_f, Resources.TicketClosing), EventName = RuleEventNames.TicketClosing, SortOrder = -1
            };

            ticketClosingRule.Actions.Add(new ActionContainer(printKitchenOrdersAction));
            ticketClosingRule.Actions.Add(new ActionContainer(updateTicketStatusAction)
            {
                ParameterValues = string.Format("Status={0}#Current Status={1}", Resources.Unpaid, Resources.NewOrders)
            });
            ticketClosingRule.Actions.Add(new ActionContainer(updateOrderStatusAction)
            {
                ParameterValues = string.Format("Status={0}#Current Status={1}", Resources.Submitted, Resources.New)
            });
            ticketClosingRule.AddRuleMap();
            workspace.Add(ticketClosingRule);

            var giftOrderRule = new AppRule {
                Name = string.Format(Resources.Rule_f, Resources.Gift), EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = string.Format("AutomationCommandName;=;{0}", giftItemAutomation.Name), SortOrder = -1
            };

            giftOrderRule.Actions.Add(new ActionContainer(updateOrderAction)
            {
                ParameterValues = "Decrease=True#Calculate Price=False"
            });
            giftOrderRule.Actions.Add(new ActionContainer(updateOrderGiftStatusAction)
            {
                ParameterValues = string.Format("Status={0}#Value=[:Value]", Resources.Gift)
            });
            giftOrderRule.AddRuleMap();
            workspace.Add(giftOrderRule);

            var cancelGiftOrderRule = new AppRule {
                Name = string.Format(Resources.Rule_f, string.Format(Resources.Cancel_f, Resources.Gift)), EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = string.Format("AutomationCommandName;=;{0}", cancelGiftItemAutomation.Name), SortOrder = -1
            };

            cancelGiftOrderRule.Actions.Add(new ActionContainer(updateOrderAction)
            {
                ParameterValues = "Decrease=True#Calculate Price=True"
            });
            cancelGiftOrderRule.Actions.Add(new ActionContainer(updateOrderGiftStatusAction)
            {
                ParameterValues = string.Format("Current Status={0}#Status=#Value=", Resources.Gift)
            });
            cancelGiftOrderRule.AddRuleMap();
            workspace.Add(cancelGiftOrderRule);

            var voidOrderRule = new AppRule {
                Name = string.Format(Resources.Rule_f, Resources.Void), EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = string.Format("AutomationCommandName;=;{0}", voidItemAutomation.Name), SortOrder = -1
            };

            voidOrderRule.Actions.Add(new ActionContainer(updateOrderAction)
            {
                ParameterValues = "Decrease=False#Calculate Price=False"
            });
            voidOrderRule.Actions.Add(new ActionContainer(updateOrderGiftStatusAction)
            {
                ParameterValues = string.Format("Status={0}#Value=[:Value]", Resources.Void)
            });
            voidOrderRule.Actions.Add(new ActionContainer(updateOrderStatusAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.New)
            });
            voidOrderRule.AddRuleMap();
            workspace.Add(voidOrderRule);

            var cancelVoidOrderRule = new AppRule {
                Name = string.Format(Resources.Rule_f, string.Format(Resources.Cancel_f, Resources.Void)), EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = string.Format("AutomationCommandName;=;{0}", cancelVoidItemAutomation.Name), SortOrder = -1
            };

            cancelVoidOrderRule.Actions.Add(new ActionContainer(updateOrderAction)
            {
                ParameterValues = "Decrease=True#Calculate Price=True"
            });
            cancelVoidOrderRule.Actions.Add(new ActionContainer(updateOrderGiftStatusAction)
            {
                ParameterValues = string.Format("Current Status={0}#Status=#Value=", Resources.Void)
            });
            cancelVoidOrderRule.Actions.Add(new ActionContainer(updateOrderStatusAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.Submitted)
            });
            cancelVoidOrderRule.AddRuleMap();
            workspace.Add(cancelVoidOrderRule);

            var newOrderRule = new AppRule {
                Name = Resources.UpdateNewOrderEntityColor, EventName = RuleEventNames.TicketStateUpdated, EventConstraints = "State;=;" + Resources.Unpaid, SortOrder = -1
            };

            newOrderRule.Actions.Add(new ActionContainer(updateEntityStateAction)
            {
                ParameterValues = "Status=" + Resources.NewOrders
            });
            newOrderRule.AddRuleMap();
            workspace.Add(newOrderRule);

            var availableRule = new AppRule {
                Name = Resources.UpdateAvailableEntityColor, EventName = RuleEventNames.EntityUpdated, EventConstraints = "OpenTicketCount;=;0", SortOrder = -1
            };
            var ac2 = new ActionContainer(updateEntityStateAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.Available)
            };

            availableRule.Actions.Add(ac2);
            availableRule.AddRuleMap();
            workspace.Add(availableRule);

            var movingRule = new AppRule {
                Name = Resources.UpdateMovedEntityColor, EventName = "TicketEntityChanged", EventConstraints = "OrderCount;>;0", SortOrder = -1
            };
            var ac3 = new ActionContainer(updateEntityStateAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.NewOrders)
            };

            movingRule.Actions.Add(ac3);
            movingRule.AddRuleMap();
            workspace.Add(movingRule);

            var printBillRule = new AppRule {
                Name = string.Format(Resources.Rule_f, Resources.PrintBill), EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = "AutomationCommandName;=;" + Resources.PrintBill, SortOrder = -1
            };

            printBillRule.Actions.Add(new ActionContainer(printBillAction));
            printBillRule.Actions.Add(new ActionContainer(lockTicketAction));
            printBillRule.Actions.Add(new ActionContainer(updateEntityStateAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.BillRequested)
            });
            printBillRule.Actions.Add(new ActionContainer(updateTicketStatusAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.Locked)
            });
            printBillRule.Actions.Add(new ActionContainer(closeTicketAction));
            printBillRule.AddRuleMap();
            workspace.Add(printBillRule);

            var unlockTicketRule = new AppRule {
                Name = string.Format(Resources.Rule_f, Resources.UnlockTicket), EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = "AutomationCommandName;=;" + Resources.UnlockTicket, SortOrder = -1
            };

            unlockTicketRule.Actions.Add(new ActionContainer(unlockTicketAction));
            unlockTicketRule.Actions.Add(new ActionContainer(updateTicketStatusAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.Unpaid)
            });
            unlockTicketRule.AddRuleMap();
            workspace.Add(unlockTicketRule);

            var createTicketRule = new AppRule {
                Name = string.Format(Resources.Rule_f, string.Format(Resources.Create_f, Resources.Ticket)), EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = "AutomationCommandName;=;" + string.Format(Resources.Add_f, Resources.Ticket), SortOrder = -1
            };

            createTicketRule.Actions.Add(new ActionContainer(createTicketAction));
            createTicketRule.AddRuleMap();
            workspace.Add(createTicketRule);

            var updateMergedTicket = new AppRule {
                Name = Resources.UpdateMergedTicketsState, EventName = RuleEventNames.TicketsMerged, SortOrder = -1
            };

            updateMergedTicket.Actions.Add(new ActionContainer(updateEntityStateAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.NewOrders)
            });
            updateMergedTicket.Actions.Add(new ActionContainer(updateTicketStatusAction)
            {
                ParameterValues = string.Format("Status={0}", Resources.NewOrders)
            });
            updateMergedTicket.AddRuleMap();
            workspace.Add(updateMergedTicket);

            var closeTicketRule = new AppRule {
                Name = string.Format(Resources.Rule_f, Resources.CloseTicket), EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = "AutomationCommandName;=;" + Resources.CloseTicket, SortOrder = -1
            };

            closeTicketRule.Actions.Add(new ActionContainer(closeTicketAction));
            closeTicketRule.AddRuleMap();
            workspace.Add(closeTicketRule);

            var settleTicketRule = new AppRule {
                Name = string.Format(Resources.Rule_f, Resources.Settle), EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = "AutomationCommandName;=;" + Resources.Settle, SortOrder = -1
            };

            settleTicketRule.Actions.Add(new ActionContainer(displayPaymentScreenAction));
            settleTicketRule.AddRuleMap();
            workspace.Add(settleTicketRule);

            workspace.CommitChanges();
        }
Ejemplo n.º 18
0
 public RlMethods(AppRule origin, IEnumerable <string> methods)
 {
     _origin  = origin;
     _methods = methods.ToList().ConvertAll(m => m.ToUpper());
 }
Ejemplo n.º 19
0
        private static bool SatisfiesConditions(AppRule appRule, object dataObject)
        {
            var constraints = SettingAccessor.ReplaceSettings(appRule.EventConstraints);

            var conditions = constraints.Split('#')
                             .Select(x => new RuleConstraintViewModel(x));

            var parameterNames = dataObject.GetType().GetProperties().Select(x => x.Name);

            foreach (var condition in conditions)
            {
                var parameterName = parameterNames.FirstOrDefault(condition.Name.Equals);

                if (!string.IsNullOrEmpty(parameterName))
                {
                    var property       = dataObject.GetType().GetProperty(parameterName);
                    var parameterValue = property.GetValue(dataObject, null) ?? "";
                    if (!condition.ValueEquals(parameterValue))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (condition.Name.StartsWith("SN$"))
                    {
                        var settingName = condition.Name.Replace("SN$", "");
                        while (Regex.IsMatch(settingName, "\\[[^\\]]+\\]"))
                        {
                            var paramvalue  = Regex.Match(settingName, "\\[[^\\]]+\\]").Groups[0].Value;
                            var insideValue = paramvalue.Trim(new[] { '[', ']' });
                            if (parameterNames.Contains(insideValue))
                            {
                                var v = dataObject.GetType().GetProperty(insideValue).GetValue(dataObject, null).ToString();
                                settingName = settingName.Replace(paramvalue, v);
                            }
                            else
                            {
                                if (paramvalue == "[Day]")
                                {
                                    settingName = settingName.Replace(paramvalue, DateTime.Now.Day.ToString());
                                }
                                else if (paramvalue == "[Month]")
                                {
                                    settingName = settingName.Replace(paramvalue, DateTime.Now.Month.ToString());
                                }
                                else if (paramvalue == "[Year]")
                                {
                                    settingName = settingName.Replace(paramvalue, DateTime.Now.Year.ToString());
                                }
                                else
                                {
                                    settingName = settingName.Replace(paramvalue, "");
                                }
                            }
                        }

                        var customSettingValue = AppServices.SettingService.ReadSetting(settingName).StringValue ?? "";
                        if (!condition.ValueEquals(customSettingValue))
                        {
                            return(false);
                        }
                    }
                    if (condition.Name == "TerminalName" && !string.IsNullOrEmpty(condition.Value))
                    {
                        if (!condition.Value.Equals(AppServices.CurrentTerminal.Name))
                        {
                            return(false);
                        }
                    }
                    if (condition.Name == "DepartmentName" && !string.IsNullOrEmpty(condition.Value))
                    {
                        if (AppServices.MainDataContext.SelectedDepartment == null ||
                            !condition.Value.Equals(AppServices.MainDataContext.SelectedDepartment.Name))
                        {
                            return(false);
                        }
                    }

                    if (condition.Name == "UserName" && !string.IsNullOrEmpty(condition.Value))
                    {
                        if (AppServices.CurrentLoggedInUser == null ||
                            !condition.Value.Equals(AppServices.CurrentLoggedInUser.Name))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 20
0
 public RlDelete(AppRule origin)
 {
     _origin = origin;
 }
Ejemplo n.º 21
0
        public void CreateData()
        {
            CreateDefaultCurrenciesIfNeeded();

            if (!ShouldCreateData())
            {
                return;
            }

            var saleAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Sales)
            };
            var receivableAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Receiveable)
            };
            var paymentAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Payment)
            };
            var discountAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Discount)
            };
            var customerAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Customer)
            };

            _workspace.Add(receivableAccountType);
            _workspace.Add(saleAccountType);
            _workspace.Add(paymentAccountType);
            _workspace.Add(discountAccountType);
            _workspace.Add(customerAccountType);
            _workspace.CommitChanges();

            var customerResourceType = new ResourceType {
                Name = Resources.Customers, EntityName = Resources.Customer, AccountTypeId = customerAccountType.Id
            };

            customerResourceType.ResoruceCustomFields.Add(new ResourceCustomField {
                EditingFormat = "(###) ### ####", FieldType = 0, Name = Resources.Phone
            });
            customerResourceType.AccountNameTemplate = "[Name]-[Phone]";
            var tableResourceType = new ResourceType {
                Name = Resources.Tables, EntityName = Resources.Table
            };

            _workspace.Add(customerResourceType);
            _workspace.Add(tableResourceType);

            _workspace.CommitChanges();

            var accountScreen = new AccountScreen {
                Name = Resources.General
            };

            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = saleAccountType.Name, AccountTypeId = saleAccountType.Id, DisplayDetails = true
            });
            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = receivableAccountType.Name, AccountTypeId = receivableAccountType.Id, DisplayDetails = true
            });
            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = discountAccountType.Name, AccountTypeId = discountAccountType.Id, DisplayDetails = true
            });
            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = paymentAccountType.Name, AccountTypeId = paymentAccountType.Id, DisplayDetails = true
            });
            _workspace.Add(accountScreen);

            var defaultSaleAccount = new Account {
                AccountTypeId = saleAccountType.Id, Name = Resources.Sales
            };
            var defaultReceivableAccount = new Account {
                AccountTypeId = receivableAccountType.Id, Name = Resources.Receivables
            };
            var cashAccount = new Account {
                AccountTypeId = paymentAccountType.Id, Name = Resources.Cash
            };
            var creditCardAccount = new Account {
                AccountTypeId = paymentAccountType.Id, Name = Resources.CreditCard
            };
            var voucherAccount = new Account {
                AccountTypeId = paymentAccountType.Id, Name = Resources.Voucher
            };
            var defaultDiscountAccount = new Account {
                AccountTypeId = discountAccountType.Id, Name = Resources.Discount
            };
            var defaultRoundingAccount = new Account {
                AccountTypeId = discountAccountType.Id, Name = Resources.Rounding
            };

            _workspace.Add(defaultSaleAccount);
            _workspace.Add(defaultReceivableAccount);
            _workspace.Add(defaultDiscountAccount);
            _workspace.Add(defaultRoundingAccount);
            _workspace.Add(cashAccount);
            _workspace.Add(creditCardAccount);
            _workspace.Add(voucherAccount);

            _workspace.CommitChanges();

            var discountTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Discount),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = discountAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id,
                DefaultTargetAccountId = defaultDiscountAccount.Id
            };

            var roundingTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Rounding),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = discountAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id,
                DefaultTargetAccountId = defaultRoundingAccount.Id
            };

            var saleTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Sale),
                SourceAccountTypeId    = saleAccountType.Id,
                TargetAccountTypeId    = receivableAccountType.Id,
                DefaultSourceAccountId = defaultSaleAccount.Id,
                DefaultTargetAccountId = defaultReceivableAccount.Id
            };

            var paymentTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Payment),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = paymentAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id,
                DefaultTargetAccountId = cashAccount.Id
            };

            var customerAccountTransactionType = new AccountTransactionType
            {
                Name = "Customer Account Transaction",
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = customerAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id
            };

            var customerCashPaymentType = new AccountTransactionType
            {
                Name = "Customer Cash Payment",
                SourceAccountTypeId    = customerAccountType.Id,
                TargetAccountTypeId    = paymentAccountType.Id,
                DefaultTargetAccountId = cashAccount.Id
            };

            var customerCreditCardPaymentType = new AccountTransactionType
            {
                Name = "Customer Credit Card Payment",
                SourceAccountTypeId    = customerAccountType.Id,
                TargetAccountTypeId    = paymentAccountType.Id,
                DefaultTargetAccountId = creditCardAccount.Id
            };

            _workspace.Add(saleTransactionType);
            _workspace.Add(paymentTransactionType);
            _workspace.Add(discountTransactionType);
            _workspace.Add(roundingTransactionType);
            _workspace.Add(customerAccountTransactionType);
            _workspace.Add(customerCashPaymentType);
            _workspace.Add(customerCreditCardPaymentType);

            var customerCashDocument = new AccountTransactionDocumentType
            {
                Name                = "Customer Cash",
                ButtonHeader        = Resources.Cash,
                DefaultAmount       = string.Format("[{0}]", Resources.Balance),
                DescriptionTemplate = string.Format(Resources.Payment_f, Resources.Cash),
                MasterAccountTypeId = customerAccountType.Id
            };

            customerCashDocument.AddAccountTransactionDocumentTypeMap();
            customerCashDocument.TransactionTypes.Add(customerCashPaymentType);

            var customerCreditCardDocument = new AccountTransactionDocumentType
            {
                Name                = "Customer Credit Card",
                ButtonHeader        = Resources.CreditCard,
                DefaultAmount       = string.Format("[{0}]", Resources.Balance),
                DescriptionTemplate = string.Format(Resources.Payment_f, Resources.CreditCard),
                MasterAccountTypeId = customerAccountType.Id
            };

            customerCreditCardDocument.AddAccountTransactionDocumentTypeMap();
            customerCreditCardDocument.TransactionTypes.Add(customerCreditCardPaymentType);

            _workspace.Add(customerCashDocument);
            _workspace.Add(customerCreditCardDocument);

            var discountService = new CalculationType
            {
                AccountTransactionType = discountTransactionType,
                CalculationMethod      = 0,
                DecreaseAmount         = true,
                Name = Resources.Discount
            };

            var roundingService = new CalculationType
            {
                AccountTransactionType = roundingTransactionType,
                CalculationMethod      = 2,
                DecreaseAmount         = true,
                IncludeTax             = true,
                Name = Resources.Round
            };

            var discountSelector = new CalculationSelector {
                Name = Resources.Discount, ButtonHeader = Resources.DiscountPercentSign
            };

            discountSelector.CalculationTypes.Add(discountService);
            discountSelector.AddCalculationSelectorMap();

            var roundingSelector = new CalculationSelector {
                Name = Resources.Round, ButtonHeader = Resources.Round
            };

            roundingSelector.CalculationTypes.Add(roundingService);
            roundingSelector.AddCalculationSelectorMap();


            _workspace.Add(discountService);
            _workspace.Add(roundingService);
            _workspace.Add(discountSelector);
            _workspace.Add(roundingSelector);

            var screen = new ScreenMenu();

            _workspace.Add(screen);

            var ticketNumerator = new Numerator {
                Name = Resources.TicketNumerator
            };

            _workspace.Add(ticketNumerator);

            var orderNumerator = new Numerator {
                Name = Resources.OrderNumerator
            };

            _workspace.Add(orderNumerator);

            var printBillAutomation = new AutomationCommand {
                Name = Resources.PrintBill, ButtonHeader = Resources.PrintBill
            };

            printBillAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                VisualBehaviour = 1
            });
            _workspace.Add(printBillAutomation);

            var unlockTicketAutomation = new AutomationCommand {
                Name = Resources.UnlockTicket, ButtonHeader = Resources.UnlockTicket
            };

            unlockTicketAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                VisualBehaviour = 2
            });
            _workspace.Add(unlockTicketAutomation);

            var addTicketAutomation = new AutomationCommand {
                Name = string.Format(Resources.Add_f, Resources.Ticket), ButtonHeader = string.Format(Resources.Add_f, Resources.Ticket)
            };

            addTicketAutomation.AddAutomationCommandMap();
            _workspace.Add(addTicketAutomation);

            _workspace.CommitChanges();

            var ticketTemplate = new TicketTemplate
            {
                Name                = Resources.TicketTemplate,
                TicketNumerator     = ticketNumerator,
                OrderNumerator      = orderNumerator,
                SaleTransactionType = saleTransactionType,
            };

            var cashPayment = new PaymentType
            {
                AccountTransactionType = paymentTransactionType,
                Account = cashAccount,
                Name    = cashAccount.Name
            };

            cashPayment.PaymentTypeMaps.Add(new PaymentTypeMap {
                DisplayAtPaymentScreen = true
            });

            var creditCardPayment = new PaymentType
            {
                AccountTransactionType = paymentTransactionType,
                Account = creditCardAccount,
                Name    = creditCardAccount.Name
            };

            creditCardPayment.PaymentTypeMaps.Add(new PaymentTypeMap {
                DisplayAtPaymentScreen = true
            });

            var voucherPayment = new PaymentType
            {
                AccountTransactionType = paymentTransactionType,
                Account = voucherAccount,
                Name    = voucherAccount.Name
            };

            voucherPayment.PaymentTypeMaps.Add(new PaymentTypeMap {
                DisplayAtPaymentScreen = true
            });

            var accountPayment = new PaymentType
            {
                AccountTransactionType = customerAccountTransactionType,
                Name = Resources.CustomerAccount
            };

            accountPayment.PaymentTypeMaps.Add(new PaymentTypeMap {
                DisplayAtPaymentScreen = true
            });

            _workspace.Add(cashPayment);
            _workspace.Add(creditCardPayment);
            _workspace.Add(voucherPayment);
            _workspace.Add(ticketTemplate);
            _workspace.Add(accountPayment);

            var department = new Department
            {
                Name           = Resources.Restaurant,
                TicketTemplate = ticketTemplate,
                ScreenMenuId   = screen.Id,
            };

            _workspace.Add(department);

            var role = new UserRole("Admin")
            {
                IsAdmin = true, DepartmentId = 1
            };

            _workspace.Add(role);

            var u = new User("Administrator", "1234")
            {
                UserRole = role
            };

            _workspace.Add(u);

            var ticketPrinterTemplate = new PrinterTemplate {
                Name = Resources.TicketTemplate, Template = Resources.TicketTemplateValue
            };
            var kitchenPrinterTemplate = new PrinterTemplate {
                Name = Resources.KitchenOrderTemplate, Template = Resources.KitchenTemplateValue
            };

            _workspace.Add(ticketPrinterTemplate);
            _workspace.Add(kitchenPrinterTemplate);

            var printer1 = new Printer {
                Name = Resources.TicketPrinter
            };
            var printer2 = new Printer {
                Name = Resources.KitchenPrinter
            };
            var printer3 = new Printer {
                Name = Resources.InvoicePrinter
            };

            _workspace.Add(printer1);
            _workspace.Add(printer2);
            _workspace.Add(printer3);

            _workspace.CommitChanges();

            var t = new Terminal
            {
                IsDefault     = true,
                Name          = Resources.Server,
                ReportPrinter = printer1,
            };

            var pm1 = new PrinterMap {
                PrinterId = printer1.Id, PrinterTemplateId = ticketPrinterTemplate.Id
            };

            _workspace.Add(pm1);

            var pj1 = new PrintJob
            {
                Name        = Resources.PrintBill,
                LocksTicket = true,
                WhatToPrint = (int)WhatToPrintTypes.Everything,
            };

            pj1.PrinterMaps.Add(pm1);


            _workspace.Add(pj1);

            var pm2 = new PrinterMap {
                PrinterId = printer2.Id, PrinterTemplateId = kitchenPrinterTemplate.Id
            };
            var pj2 = new PrintJob
            {
                Name        = Resources.PrintOrdersToKitchenPrinter,
                WhatToPrint = (int)WhatToPrintTypes.NewLines,
            };

            pj2.PrinterMaps.Add(pm2);

            _workspace.Add(pj2);
            _workspace.Add(t);

            var orderTag1 = new OrderStateGroup {
                Name = Resources.Gift, ButtonHeader = Resources.Gift, CalculateOrderPrice = false, DecreaseOrderInventory = true
            };

            orderTag1.OrderStates.Add(new OrderState {
                Name = Resources.Gift
            });
            orderTag1.AddOrderStateMap();
            _workspace.Add(orderTag1);

            var orderTag2 = new OrderStateGroup {
                Name = Resources.Void, ButtonHeader = Resources.Void, CalculateOrderPrice = false, DecreaseOrderInventory = false
            };

            orderTag2.OrderStates.Add(new OrderState {
                Name = Resources.Void
            });
            orderTag2.UnlocksOrder = true;
            orderTag2.AddOrderStateMap();
            _workspace.Add(orderTag2);

            const string parameterFormat = "[{{\"Key\":\"{0}\",\"Value\":\"{1}\"}}]";
            //const string doubleParameterFormat = "[{{\"Key\":\"{0}\",\"Value\":\"{1}\"}},{{\"Key\":\"{2}\",\"Value\":\"{3}\"}}]";

            var newOrderState = new ResourceState {
                Name = "New Orders", Color = "Orange"
            };

            _workspace.Add(newOrderState);

            var availableState = new ResourceState {
                Name = "Available", Color = "White"
            };

            _workspace.Add(availableState);

            var billRequestedState = new ResourceState {
                Name = "Bill Requested", Color = "Maroon"
            };

            _workspace.Add(billRequestedState);

            var newOrderAction = new AppAction {
                ActionType = "UpdateResourceState", Name = "Update New Order State", Parameter = string.Format(parameterFormat, "ResourceState", "New Orders")
            };

            _workspace.Add(newOrderAction);
            var availableAction = new AppAction {
                ActionType = "UpdateResourceState", Name = "Update Available State", Parameter = string.Format(parameterFormat, "ResourceState", "Available")
            };

            _workspace.Add(availableAction);
            var billRequestedAction = new AppAction {
                ActionType = "UpdateResourceState", Name = "Update Bill Requested State", Parameter = string.Format(parameterFormat, "ResourceState", "Bill Requested")
            };

            _workspace.Add(billRequestedAction);
            var createTicketAction = new AppAction {
                ActionType = "CreateTicket", Name = string.Format(Resources.Create_f, Resources.Ticket), Parameter = ""
            };

            _workspace.Add(createTicketAction);
            var closeTicketAction = new AppAction {
                ActionType = "CloseActiveTicket", Name = Resources.CloseTicket, Parameter = ""
            };

            _workspace.Add(closeTicketAction);
            var printBillAction = new AppAction {
                ActionType = "ExecutePrintJob", Name = "Execute Bill Print Job", Parameter = string.Format(parameterFormat, "PrintJobName", Resources.PrintBill)
            };

            _workspace.Add(printBillAction);
            var printKitchenOrdersAction = new AppAction {
                ActionType = "ExecutePrintJob", Name = "Execute Kitchen Orders Print Job", Parameter = string.Format(parameterFormat, "PrintJobName", Resources.PrintOrdersToKitchenPrinter)
            };

            _workspace.Add(printKitchenOrdersAction);
            var unlockTicketAction = new AppAction {
                ActionType = "UnlockTicket", Name = Resources.UnlockTicket, Parameter = ""
            };

            _workspace.Add(unlockTicketAction);
            _workspace.CommitChanges();

            var newOrderRule = new AppRule {
                Name = "Update New Order Resource Color", EventName = "TicketClosing", EventConstraints = "NewOrderCount;>;0"
            };

            newOrderRule.Actions.Add(new ActionContainer(printKitchenOrdersAction));
            newOrderRule.Actions.Add(new ActionContainer(newOrderAction));
            newOrderRule.AddRuleMap();
            _workspace.Add(newOrderRule);

            var availableRule = new AppRule {
                Name = "Update Available Resource Color", EventName = "ResourceUpdated", EventConstraints = "OpenTicketCount;=;0"
            };
            var ac2 = new ActionContainer(availableAction);

            availableRule.Actions.Add(ac2);
            availableRule.AddRuleMap();
            _workspace.Add(availableRule);

            var movingRule = new AppRule {
                Name = "Update Moved Resource Color", EventName = "TicketResourceChanged", EventConstraints = "OrderCount;>;0"
            };
            var ac3 = new ActionContainer(newOrderAction);

            movingRule.Actions.Add(ac3);
            movingRule.AddRuleMap();
            _workspace.Add(movingRule);

            var printBillRule = new AppRule {
                Name = "Print Bill Rule", EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = "AutomationCommandName;=;" + Resources.PrintBill
            };

            printBillRule.Actions.Add(new ActionContainer(printBillAction));
            printBillRule.Actions.Add(new ActionContainer(billRequestedAction));
            printBillRule.Actions.Add(new ActionContainer(closeTicketAction));
            printBillRule.AddRuleMap();
            _workspace.Add(printBillRule);

            var unlockTicketRule = new AppRule {
                Name = "Unlock Ticket Rule", EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = "AutomationCommandName;=;Unlock Ticket"
            };

            unlockTicketRule.Actions.Add(new ActionContainer(unlockTicketAction));
            unlockTicketRule.AddRuleMap();
            _workspace.Add(unlockTicketRule);

            var createTicketRule = new AppRule {
                Name = "Create Ticket Rule", EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = "AutomationCommandName;=;Add Ticket"
            };

            createTicketRule.Actions.Add(new ActionContainer(createTicketAction));
            createTicketRule.AddRuleMap();
            _workspace.Add(createTicketRule);

            var updateMergedTicket = new AppRule {
                Name = "Update Merged Tickets State", EventName = RuleEventNames.TicketsMerged
            };

            updateMergedTicket.Actions.Add(new ActionContainer(newOrderAction));
            updateMergedTicket.AddRuleMap();
            _workspace.Add(updateMergedTicket);

            ImportMenus(screen);
            ImportTableResources(tableResourceType, availableState.Id);

            var customerScreen = new ResourceScreen {
                Name = "Customer Search", DisplayMode = 2, ResourceTypeId = customerResourceType.Id
            };

            customerScreen.ResourceScreenMaps.Add(new ResourceScreenMap());
            _workspace.Add(customerScreen);

            var customerTicketScreen = new ResourceScreen {
                Name = "Customer Tickets", DisplayMode = 0, ResourceTypeId = customerResourceType.Id, StateFilterId = newOrderState.Id, ColumnCount = 6, RowCount = 6
            };

            customerTicketScreen.ResourceScreenMaps.Add(new ResourceScreenMap());
            _workspace.Add(customerTicketScreen);


            ImportItems(BatchCreateResources);
            ImportItems(BatchCreateTransactionTypes);
            ImportItems(BatchCreateTransactionTypeDocuments);

            _workspace.CommitChanges();
            _workspace.Dispose();
        }
Ejemplo n.º 22
0
 public RlPut(AppRule origin)
 {
     _origin = origin;
 }