Exemplo n.º 1
0
        public Result<bool> CheckScenario(Scenario item)
        {
            var result = new Result<bool>();

            if (item.ActionBag == null)
                result.AddWarning(new Warning("Необходимо выбрать вид действия"));
            if (string.IsNullOrEmpty(item.Name))
                result.AddWarning(new Warning("Необходимо ввести имя сценария"));
            if (_scenarios.Count(x => x.Name == item.Name && item.Guid != x.Guid) > 0)
                result.AddWarning(new Warning("Действие с таким именем уже существует"));
            if (_scenarios.Count(x => x.ServerCommand == item.ServerCommand && !string.IsNullOrEmpty(x.ServerCommand) && item.Guid != x.Guid) > 0)
                result.AddWarning(new Warning("Действие с такой командой сервера уже существует"));

            result.Value = result.Warnings.Count() == 0;
            return result;
        }
Exemplo n.º 2
0
 public static Result<ICustomAction> CloneAction(ICustomAction action)
 {
     var res = new Result<ICustomAction>();
     try
     {
         res.Value = (ICustomAction)HierarchicalObjectCrutch.CloneObject(action);
     }
     catch (Exception e)
     {
         res.AddWarning(new Warning(e.Message), true);
     }
     return res;
 }
Exemplo n.º 3
0
 public static Result<ICustomChecker> CloneChecker(ICustomChecker checker)
 {
     var res = new Result<ICustomChecker>();
     try
     {
         res.Value = (ICustomChecker)HierarchicalObjectCrutch.CloneObject(checker);
     }
     catch (Exception e)
     {
         res.AddWarning(new Warning(e.Message), true);
     }
     return res;
 }
Exemplo n.º 4
0
        public Result<IEnumerable<Type>> RegisterChecker(string filename)
        {
            var result = new Result<IEnumerable<Type>>();
            IEnumerable<Type> types = null;
            try
            {
                var assembly = Assembly.LoadFrom(filename);
                types = assembly
                    .GetTypes()
                    .Where(x => x.GetInterfaces()
                        .Contains(typeof(ICustomChecker))
                        && x.CustomAttributes.Any(z => z.AttributeType.Equals(typeof(SerializableAttribute)))
                        );
            }
            catch (Exception e)
            {
                result.AddWarning(new Warning(e.Message));
            }

            var addedTypes = types.Where(x => CanRegisterChecker(x));
            _customCheckers.AddRange(addedTypes);
            HierarchicalObjectCrutch.Register(addedTypes);
            result.Value = addedTypes;
            return result;
        }
Exemplo n.º 5
0
        public Result<ICustomChecker> CreateCheckerInstance(Type type, bool beginSettings)
        {
            var result = new Result<ICustomChecker>();
            try
            {
                var checker = (ICustomChecker)type.GetConstructor(new Type[0]).Invoke(new object[0]);
                if (checker is ICoreElement)
                    ((ICoreElement)checker).CurrentPyrite = Pyrite;

                if (beginSettings)
                {
                    if (checker.BeginUserSettings())
                    {
                        result.Value = checker;
                        result.Value.Refresh();
                    }
                }
                else
                {
                    result.Value = checker;
                }
            }
            catch (Exception e)
            {
                result.AddWarning(new Warning(e.Message));
            }
            return result;
        }
Exemplo n.º 6
0
        public Result<ICustomAction> CreateActionInstance(Type type, bool beginSettings)
        {
            var result = new Result<ICustomAction>();
            try
            {
                var action = (ICustomAction)type.GetConstructor(new Type[0]).Invoke(new object[0]);
                if (action is ICoreElement)
                    ((ICoreElement)action).CurrentPyrite = Pyrite;

                if (beginSettings)
                {
                    if (action.BeginUserSettings())
                    {
                        result.Value = action;
                        result.Value.Refresh();
                    }
                }
                else result.Value = action;
            }
            catch (Exception e)
            {
                result.AddWarning(new Warning(e.Message));
            }

            return result;
        }