示例#1
0
        public void GetProps()
        {
            // Arrange
            ICommandConfiguration Configuration = this.mockRepository
                                                  .Of <ICommandConfiguration>()
                                                  .Where(x => x.TableName == "Persona")
                                                  .Where(x => x.PrimaryKeyTable == "Id")
                                                  .Where(x => x.IncludeId == true)
                                                  .First();

            IClassConfiguration ClassConfiguration = this.mockRepository
                                                     .Of <IClassConfiguration>()
                                                     .Where(x => x.FieldsInclude == false)
                                                     .Where(x => x.PropsInclude == true)
                                                     .First();

            Persona Entidad = GetPersona();

            // Act
            var result = SqlEntityUtil.GetKeysValues(
                ClassConfiguration,
                Configuration,
                Entidad);

            // Assert
            Assert.IsTrue(
                result.Count() == 4 &&
                result["Fecha"] == "'19820326 00:00'" &&
                result["Nombre"] == "N'Miguel Angel'" &&
                result["Id"] == "5" &&
                result["Saldo"] == "null"
                );
        }
        public IEnumerable <ICommandMessageHandler> GetCommands(ICommandConfiguration definition)
        {
            Type concreteCommandType = typeof(ICommandHandler <>).MakeGenericType(definition.CommandMessageType);
            var  commands            = CommandLocator(concreteCommandType);

            return(commands.Select(command => new CommandMessageHandlerProxy(command)).ToArray());
        }
		public IEnumerable<ICommandMessageHandler> GetCommands(ICommandConfiguration definition)
		{
			Type concreteCommandType = _genericHandler.MakeGenericType(definition.CommandMessageType);
			IEnumerable<ICommandMessageHandler> commands =
				ServiceLocator.Current.GetAllInstances(concreteCommandType).Cast<ICommandMessageHandler>();
			return commands;
		}
示例#4
0
        public void GetFields()
        {
            // Arrange
            ICommandConfiguration Configuration = this.mockRepository
                                                  .Of <ICommandConfiguration>()
                                                  .Where(x => x.TableName == "Persona")
                                                  .Where(x => x.PrimaryKeyTable == "Id")
                                                  .Where(x => x.IncludeId == true)
                                                  .First();

            IClassConfiguration ClassConfiguration = this.mockRepository
                                                     .Of <IClassConfiguration>()
                                                     .Where(x => x.FieldsInclude == true)
                                                     .Where(x => x.PropsInclude == false)
                                                     .First();

            Persona Entidad = GetPersona();

            // Act
            var result = SqlEntityUtil.GetKeysValues(
                ClassConfiguration,
                Configuration,
                Entidad);

            // Assert
            Assert.IsTrue(result.Count() == 1 && result["edad"] == "37");
        }
		private void AddDefinitions(ICommandConfiguration[] configurationImplementations)
		{
			var commandDefinitions = configurationImplementations.Select(x =>
			                                                             {
				                                                             var property = x.GetType()
				                                                                             .GetProperty("Configuration",
				                                                                                          BindingFlags.IgnoreCase
				                                                                                          | BindingFlags.NonPublic
				                                                                                          | BindingFlags.Instance);
				                                                             var value =
					                                                             (CommandDefinition) property.GetValue(x, null);
				                                                             return value;
			                                                             });

			if (
				commandDefinitions.Any(
					x =>
						commandDefinitions.Count(y => y.Signature == x.Signature) > 1
						|| _configurations.Any(y => y.Signature == x.Signature)))
				throw new ArgumentException(
					"Multiple commands with same signature detected. Each command signature must be unique.",
					nameof(configurationImplementations));


			_configurations.AddRange(
				commandDefinitions);
		}
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationConfiguration"/> class.
 /// </summary>
 /// <param name="secrets">The secrets.</param>
 /// <param name="commands">The commands.</param>
 public ApplicationConfiguration(
     ISecretConfiguration secrets,
     ICommandConfiguration commands)
 {
     Secrets  = secrets;
     Commands = commands;
 }
示例#7
0
 private void AugmentCommandDetails(ICommandConfiguration<Command> x, string name, BaseObject bo)
 {
     x.ConstructUsing(() => construct(name, bo));
     x.OnFailure(f => fail(f));
     x.OnSuccess(s => success(s));
     x.OnProgress(p => progress(p));
 }
        public IEnumerable <ICommandMessageHandler> GetCommands(ICommandConfiguration definition)
        {
            Type concreteCommandType = _genericHandler.MakeGenericType(definition.CommandMessageType);
            IEnumerable <ICommandMessageHandler> commands =
                ServiceLocator.Current.GetAllInstances(concreteCommandType).Cast <ICommandMessageHandler>();

            return(commands);
        }
示例#9
0
        private CommandConfiguration <T> AddCommand(MethodInfo method)
        {
            ICommandConfiguration config = null;

            if (!_Commands.TryGetValue(method.Name, out config))
            {
                config = new CommandConfiguration <T>(method);
                _Commands[method.Name] = config;
            }
            return((CommandConfiguration <T>)config);
        }
        private string table(ICommandConfiguration configuration)
        {
            var table = $"{typeof(T).Name}";

            if (configuration.Schema != null)
            {
                return($"{schema}.{table}");
            }

            return(table);
        }
        /// <summary>
        /// Parameter constructor that adds the start and the end point of the program
        /// </summary>
        /// <param name="start">The start point of the program</param>
        /// <param name="end">The end point of the program</param>
        public ProgramManager(ICommand start, ICommand end)
        {
            // initializez cele 2 componente primare
            _variableConfiguration = new GlobalVariables();
            _commandConfiguration  = new CommandGraph(start, end);

            // trebuie sa existe o instanta de tip Eticheta cu numele "Start" pentru a incepe
            //ICommand startCmd = new Command(new Eticheta("Start"));

            // adaug comanda in lista de comenzi
            //_commandConfiguration.AddElement(startCmd);
        }
示例#12
0
        public ExecutionResult Process(object commandMessage, ICommandConfiguration commandConfiguration)
        {
            ExecutionResult executionResult = _validationEngine.ValidateCommand(commandMessage, commandConfiguration);

            if (executionResult.Successful)
            {
                IEnumerable<ICommandMessageHandler> handlers = _handerFactory.GetCommands(commandConfiguration);

                foreach (ICommandMessageHandler handler in handlers)
                {
                    ReturnValue returnObject = handler.Execute(commandMessage);

                    executionResult.Merge(returnObject);
                }
            }

            return executionResult;
        }
        public ExecutionResult Process(object commandMessage, ICommandConfiguration commandConfiguration)
        {
            ExecutionResult executionResult = _validationEngine.ValidateCommand(commandMessage, commandConfiguration);

            if (executionResult.Successful)
            {
                IEnumerable <ICommandMessageHandler> handlers = _handerFactory.GetCommands(commandConfiguration);

                foreach (ICommandMessageHandler handler in handlers)
                {
                    ReturnValue returnObject = handler.Execute(commandMessage);

                    executionResult.Merge(returnObject);
                }
            }

            return(executionResult);
        }
示例#14
0
        }                                                                      // Предполагается, что работа с коллекцией будет производиться из потока пользователя

        public DeviceConfiguration(IWorker <Action> backWorker, IThreadNotifier uiNotifier)
        {
            _backWorker = backWorker;
            _uiNotifier = uiNotifier;
            _flasher    = new DeviceFlasher(_backWorker, _uiNotifier);

            _customConfig  = new CustomConfigurationBuilderDefault().BuildConfiguration();
            _systemConfig  = new SystemConfigurationBuilderDefault().BuildConfiguration();
            _commandConfig = new CommandConfigurationBuilderDefault().BuildConfiguration();

            RpdMeters = new ObservableCollection <IRpdMeter>();

            Comment = string.Empty;

            _cycledPsnCmdPartInfos = new List <ICyclePsnCmdPartInfo>();
            _psnChannelInfos       = new List <IPsnChannelInfo>();
            PsnMeters = new ObservableCollection <IPsnMeter>();
        }
示例#15
0
        public static ISqlCommandConsultant CreateCommander(SqlType type, ICommandConfiguration commandConfiguration)
        {
            ISqlCommandConsultant oResult = null;

            switch (type)
            {
            case SqlType.SqlServer:
                oResult = new SqlServerConsultant()
                {
                    CommandConfiguration = commandConfiguration
                };
                break;

            default:
                break;
            }

            return(oResult);
        }
示例#16
0
        public ExecutionResult ValidateCommand(object commandMessage, ICommandConfiguration commandConfiguration)
        {
            var totalResult = new ExecutionResult();

            IEnumerable<ValidationRuleInstance> ruleInstances = commandConfiguration.GetValidationRules();

            foreach (ValidationRuleInstance instance in ruleInstances)
            {
                if (instance.ShouldApply != null)
                    if (!(bool) instance.ShouldApply.DynamicInvoke(commandMessage))
                        continue;

                Delegate compile = instance.ToCheckExpression.Compile();
                object input = compile.DynamicInvoke(new object[] {commandMessage});
                bool stopProcessing = false;

                if (instance.ArrayRule)
                {
                    var enumerable = (IEnumerable) input;

                    int i = 0;

                    foreach (object item in enumerable)
                    {
                        if (item == null) continue;

                        IValidationRule rule = _ruleFactory.ConstructRule(instance);
                        string result = rule.IsValid(item);

                        bool ruleFailed = result != null;

                        if (ruleFailed)
                        {
                            var indexedUiExpression = new IndexReplacerVisitor(i).Visit(instance.UIAttributeExpression);
                            totalResult.AddMessage(result, instance.ToCheckExpression, (LambdaExpression)indexedUiExpression, instance.ToCompareExpression);

                            if (rule.StopProcessing)
                            {
                                stopProcessing = true;
                                break;
                            }
                        }
                        i++;
                    }
                }
                else
                {
                    IValidationRule rule = _ruleFactory.ConstructRule(instance);

                    if (rule is ICrossReferencedValidationRule)
                    {
                        Delegate toCompareDelegate = instance.ToCompareExpression.Compile();
                        object toCompare = toCompareDelegate.DynamicInvoke(new object[] {commandMessage});
                        ((ICrossReferencedValidationRule) rule).ToCompare = toCompare;
                    }

                    string result = rule.IsValid(input);

                    bool ruleFailed = result != null;

                    if (ruleFailed)
                    {
                        totalResult.AddMessage(result, instance.ToCheckExpression, instance.UIAttributeExpression, instance.ToCompareExpression);

                        if (rule.StopProcessing)
                        {
                            break;
                        }
                    }
                }
                if (stopProcessing)
                    break;
            }

            return totalResult;
        }
示例#17
0
 public static IEnumerable <string> GetValues <T>(IClassConfiguration Configuration, ICommandConfiguration CommandConfiguration, T Entidad)
 {
     return(GetKeysValues <T>(Configuration, CommandConfiguration, Entidad).Values.ToList());
 }
示例#18
0
 public static IEnumerable <string> GetKeys <T>(IClassConfiguration configuration, ICommandConfiguration commandConfiguration = null)
 {
     return(GetKeysValues <T>(configuration, commandConfiguration, default(T)).Keys.ToList());
 }
示例#19
0
        public static IDictionary <string, string> GetKeysValues <T>(IClassConfiguration configuration, ICommandConfiguration commandConfiguration, T entity)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var aSqlFields = new List <SqlField>();

            if (configuration.PropsInclude)
            {
                var props = typeof(T).GetProperties()
                            .Where(c => c.GetCustomAttributes(typeof(NonQuerable), false).Count() == 0)
                            .Select(x => new SqlField()
                {
                    name = x.Name, value = entity != null ? SqlValueUtil.GetValue(x.GetValue(entity)) : null
                });

                aSqlFields.AddRange(props);
            }

            if (configuration.FieldsInclude)
            {
                var fields = typeof(T).GetFields()
                             .Where(c => c.GetCustomAttributes(typeof(NonQuerable), false).Count() == 0)
                             .Select(x => new SqlField()
                {
                    name = x.Name, value = entity != null ? SqlValueUtil.GetValue(x.GetValue(entity)) : null
                });

                aSqlFields.AddRange(fields);
            }

            if (commandConfiguration != null)
            {
                if (!commandConfiguration.IncludeId)
                {
                    aSqlFields = aSqlFields
                                 .Where(x => x.name.ToUpper() != commandConfiguration.PrimaryKeyTable.ToUpper())
                                 .ToList();
                }
            }
            var Elementos = aSqlFields.ToDictionary(x => x.name, y => y.value);

            return(Elementos);
        }
示例#20
0
 public bool TryGetCommandConfig(Type commandType, out ICommandConfiguration commandConfiguration)
 {
     return(_commandConfigurations.TryGetValue(commandType, out commandConfiguration));
 }
		public void AddMultiple(ICommandConfiguration[] configurations)
		{
			AddDefinitions(configurations);
		}
 private string selection(IClassConfiguration configuration, ICommandConfiguration commandConfiguration = null)
 {
     return
         (string.Join(",",
                      ExpressionToSQL.util.SqlEntityUtil.GetKeys <T>(configuration, commandConfiguration)));
 }
        public ExecutionResult ValidateCommand(object commandMessage, ICommandConfiguration commandConfiguration)
        {
            var totalResult = new ExecutionResult();

            IEnumerable <ValidationRuleInstance> ruleInstances = commandConfiguration.GetValidationRules();

            foreach (ValidationRuleInstance instance in ruleInstances)
            {
                if (instance.ShouldApply != null)
                {
                    if (!(bool)instance.ShouldApply.DynamicInvoke(commandMessage))
                    {
                        continue;
                    }
                }

                Delegate compile        = instance.ToCheckExpression.Compile();
                object   input          = compile.DynamicInvoke(new object[] { commandMessage });
                bool     stopProcessing = false;

                if (instance.ArrayRule)
                {
                    var enumerable = (IEnumerable)input;

                    int i = 0;

                    foreach (object item in enumerable)
                    {
                        if (item == null)
                        {
                            continue;
                        }

                        IValidationRule rule   = _ruleFactory.ConstructRule(instance);
                        string          result = rule.IsValid(item);

                        bool ruleFailed = result != null;

                        if (ruleFailed)
                        {
                            var indexedUiExpression = new IndexReplacerVisitor(i).Visit(instance.UIAttributeExpression);
                            totalResult.AddMessage(result, instance.ToCheckExpression, (LambdaExpression)indexedUiExpression, instance.ToCompareExpression);

                            if (rule.StopProcessing)
                            {
                                stopProcessing = true;
                                break;
                            }
                        }
                        i++;
                    }
                }
                else
                {
                    IValidationRule rule = _ruleFactory.ConstructRule(instance);

                    if (rule is ICrossReferencedValidationRule)
                    {
                        Delegate toCompareDelegate = instance.ToCompareExpression.Compile();
                        object   toCompare         = toCompareDelegate.DynamicInvoke(new object[] { commandMessage });
                        ((ICrossReferencedValidationRule)rule).ToCompare = toCompare;
                    }

                    string result = rule.IsValid(input);

                    bool ruleFailed = result != null;

                    if (ruleFailed)
                    {
                        totalResult.AddMessage(result, instance.ToCheckExpression, instance.UIAttributeExpression, instance.ToCompareExpression);

                        if (rule.StopProcessing)
                        {
                            break;
                        }
                    }
                }
                if (stopProcessing)
                {
                    break;
                }
            }

            return(totalResult);
        }
			public StubCommandRegistration(ICommandConfiguration commandConfiguration)
			{
				_commandConfiguration = commandConfiguration;
			}
 /// <summary>
 /// Initializes an instance of <see cref="CommandExecutionException"/>.
 /// </summary>
 public CommandExecutionException(ICommandConfiguration command, int exitCode, string message) : base(message)
 {
     Command  = command;
     ExitCode = exitCode;
 }
示例#26
0
 public IEnumerable<ICommandMessageHandler> GetCommands(ICommandConfiguration definition)
 {
     Type concreteCommandType = typeof(ICommandHandler<>).MakeGenericType(definition.CommandMessageType);
     var commands = CommandLocator(concreteCommandType);
     return commands.Select(command => new CommandMessageHandlerProxy(command)).ToArray();
 }