Esempio n. 1
0
        /// <summary>
        /// Composes a command envelope with a get method for the specified resource.
        /// </summary>
        /// <typeparam name="TResource">The type of the resource.</typeparam>
        /// <param name="channel">The channel.</param>
        /// <param name="uri">The resource uri.</param>
        /// <param name="from">The originator to be used in the command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">channel</exception>
        /// <exception cref="LimeException">Returns an exception with the failure reason</exception>
        public static async Task <TResource> GetResourceAsync <TResource>(this ICommandChannel channel, LimeUri uri, Node from, CancellationToken cancellationToken) where TResource : Document
        {
            if (channel == null)
            {
                throw new ArgumentNullException(nameof(channel));
            }
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            var requestCommand = new Command
            {
                From   = from,
                Method = CommandMethod.Get,
                Uri    = uri
            };

            var responseCommand = await channel.ProcessCommandAsync(requestCommand, cancellationToken).ConfigureAwait(false);

            if (responseCommand.Status == CommandStatus.Success)
            {
                return((TResource)responseCommand.Resource);
            }
            else if (responseCommand.Reason != null)
            {
                throw new LimeException(responseCommand.Reason.Code, responseCommand.Reason.Description);
            }
            else
            {
                throw new InvalidOperationException("An invalid command response was received");
            }
        }
 public static void UnregisterCte(this ICommandChannel channel, string cteName)
 {
     if (channel == null)
     {
         return;
     }
     channel.Do(CommandUnregisterCteName, cteName);
 }
Esempio n. 3
0
 public ReplyPingChannelModule(ICommandChannel commandChannel)
 {
     if (commandChannel == null)
     {
         throw new ArgumentNullException(nameof(commandChannel));
     }
     _commandChannel = commandChannel;
 }
Esempio n. 4
0
        public void ExecuteActions(ICommandChannel commandChannel)
        {
            if (commandChannel == null) throw new ArgumentNullException("commandChannel");

            foreach (var action in _actions)
            {
                commandChannel.Send(action.Code);
            }
        }
Esempio n. 5
0
        public Controller(IStateMachine stateMachine, ICommandChannel commandChannel)
        {
            if (stateMachine == null) throw new ArgumentNullException("stateMachine");
            if (commandChannel == null) throw new ArgumentNullException("commandChannel");

            _stateMachine = stateMachine;
            _commandChannel = commandChannel;

            CurrentState = _stateMachine.StartingState;
        }
Esempio n. 6
0
        public override int ExecuteOn(ICommandChannel on)
        {
            var affectedLines = base.ExecuteOn(on);

            if (affectedLines != _values)
            {
                throw new Exception($"Tentative d'insertion de {_values} lignes, seulement {affectedLines} insérée(s)");
            }
            return(affectedLines);
        }
Esempio n. 7
0
 /// <summary>
 /// This method handles the acehelp command sent in from admin console or from player chat
 /// </summary>
 public static void HandleAceHelp(Session session, ICommandChannel cmdChannel, params string[] parameters)
 {
     if (session != null)
     {
         // Solely for development testing
         ChangePlayerAccessLevel(session);
         string msg = string.Format(string.Format("Changed your access level to : {0}", session.AccessLevel));
         cmdChannel.SendMsg(session, msg);
     }
     cmdChannel.SendMsg(session, Assembly.GetExecutingAssembly().GetName().Version.ToString());
     cmdChannel.SendMsg(session, "Please use @acecommands for a list of commands.");
 }
Esempio n. 8
0
        private static void DoSomethingInsertAndCommit(ICommandChannel commandChannel, Table table, string what, Action something)
        {
            var initial = GetCount(table, commandChannel);

            commandChannel.ExecuteInTransaction(scope =>
            {
                something.Invoke();
                table.Insert().Values(what).ExecuteOn(scope);
                return(TransactionResult.Commit);
            });

            Assert.AreEqual(initial + 1, GetCount(table, commandChannel));
        }
Esempio n. 9
0
        private static void DoSomethingInsertAndCommit(ICommandChannel adapter, string what, Action something)
        {
            var initial = GetCount(adapter);

            adapter.ExecuteInTransaction(scope =>
            {
                something.Invoke();
                scope.Execute("INSERT INTO test (reference) VALUES ('" + what + "')");
                return(TransactionResult.Commit);
            });

            Assert.AreEqual(initial + 1, GetCount(adapter));
        }
Esempio n. 10
0
        public object Do(string command, object args)
        {
            ICommandChannel nestedCommandChannel = dataStore as ICommandChannel;

            if (nestedCommandChannel == null)
            {
                if (dataStore == null)
                {
                    throw new NotSupportedException(string.Format(CommandChannelHelper.Message_CommandIsNotSupported, command));
                }
                else
                {
                    throw new NotSupportedException(string.Format(CommandChannelHelper.Message_CommandIsNotSupportedEx, command, dataStore.GetType()));
                }
            }
            return(StaSafeHelper.Invoke(() => nestedCommandChannel.Do(command, args)));
        }
Esempio n. 11
0
        /// <summary>
        /// Merges the resource value.
        /// </summary>
        /// <typeparam name="TResource">The type of the resource.</typeparam>
        /// <param name="channel">The channel.</param>
        /// <param name="uri">The resource uri.</param>
        /// <param name="resource">The resource to be merge.</param>
        /// <param name="from">The originator to be used in the command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">channel</exception>
        /// <exception cref="LimeException"></exception>
        public static async Task MergeResourceAsync <TResource>(this ICommandChannel channel, LimeUri uri, TResource resource, Node from, CancellationToken cancellationToken) where TResource : Document
        {
            if (channel == null)
            {
                throw new ArgumentNullException(nameof(channel));
            }
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            var requestCommand = new Command
            {
                From     = from,
                Method   = CommandMethod.Merge,
                Uri      = uri,
                Resource = resource
            };

            var responseCommand = await channel.ProcessCommandAsync(requestCommand, cancellationToken).ConfigureAwait(false);

            if (responseCommand.Status != CommandStatus.Success)
            {
                if (responseCommand.Reason != null)
                {
                    throw new LimeException(responseCommand.Reason.Code, responseCommand.Reason.Description);
                }
                else
                {
#if DEBUG
                    if (requestCommand == responseCommand)
                    {
                        throw new InvalidOperationException("The request and the response are the same instance");
                    }
#endif

                    throw new InvalidOperationException("An invalid command response was received");
                }
            }
        }
Esempio n. 12
0
        public Task <object> DoAsync(string command, object args, CancellationToken cancellationToken = default(CancellationToken))
        {
            ICommandChannelAsync nestedCommandChannelAsync = dataStore as ICommandChannelAsync;

            if (nestedCommandChannelAsync == null || IsStaCurrentThread)
            {
                ICommandChannel nestedCommandChannel = dataStore as ICommandChannel;
                if (nestedCommandChannel == null)
                {
                    if (dataStore == null)
                    {
                        throw new NotSupportedException(string.Format(CommandChannelHelper.Message_CommandIsNotSupported, command));
                    }
                    else
                    {
                        throw new NotSupportedException(string.Format(CommandChannelHelper.Message_CommandIsNotSupportedEx, command, dataStore.GetType()));
                    }
                }
                return(Task.Factory.StartNew(() => nestedCommandChannel.Do(command, args), cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default));
            }
            return(nestedCommandChannelAsync.DoAsync(command, args, cancellationToken));
        }
Esempio n. 13
0
 /// <summary>
 /// This method handles the acecommands command sent in from admin console or from player chat
 /// </summary>
 public static void HandleAceCommands(Session session, ICommandChannel cmdChannel, params string[] parameters)
 {
     if (session != null)
     {
         string msg = string.Format(string.Format("Your Current access level is: {0}", session.AccessLevel));
         cmdChannel.SendMsg(session, msg);
     }
     foreach (var command in CommandManager.GetCommands())
     {
         if (session != null)
         {
             // Show player commands accessible to current player
             if (command.Attribute.Flags == CommandHandlerFlag.ConsoleInvoke)
             {
                 continue;
             }
             int playerlvl = (int)session.AccessLevel;
             int cmdlvl    = (int)command.Attribute.Access;
             if (playerlvl < cmdlvl)
             {
                 continue;
             }
         }
         else
         {
             // Show console commands
             if (command.Attribute.Flags == CommandHandlerFlag.RequiresWorld)
             {
                 continue;
             }
         }
         string msg = string.Format("@{0} ({1}) ({2})",
                                    command.Attribute.Command, command.Attribute.ParameterCount, command.Attribute.Access);
         cmdChannel.SendMsg(session, msg);
     }
 }
Esempio n. 14
0
 public int ExecuteOnAdapter(ICommandChannel adapter, string sql, IEnumerable <KeyValuePair <string, IConvertible> > parameters = null)
 => adapter.Execute(sql, parameters);
Esempio n. 15
0
 public IReadOnlyDictionary <string, IConvertible> ExecuteOnAdapter(ICommandChannel adapter, string sql, IEnumerable <KeyValuePair <string, IConvertible> > parameters = null)
 => adapter.FetchLine(sql, parameters);
Esempio n. 16
0
 private static int GetCount(ICommandChannel adapter)
 {
     return(Convert.ToInt32(adapter.FetchValue("SELECT COUNT(*) FROM test")));
 }
Esempio n. 17
0
 private static int GetCount(Table table, ICommandChannel adapter)
 {
     return(Convert.ToInt32(table.Select("COUNT(*)").ExecuteOn(adapter)));
 }
Esempio n. 18
0
        public bool ExecuteOnAdapter(ICommandChannel adapter, string sql, IEnumerable <KeyValuePair <string, IConvertible> > parameters = null)
        {
            var value = adapter.FetchValue(sql, parameters);

            return(Convert.ToBoolean(value));
        }
 public static void RegisterCte(this ICommandChannel channel, string cteName, string cteBody)
 {
     channel.Do(CommandRegisterCteName, cteName + ' ' + cteBody);
 }
Esempio n. 20
0
        /// <summary>
        /// Composes a command envelope with a get method for the specified resource.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <param name="cancellationToken">The cancellation token.</param>

        /// <param name="uri">The resource uri.</param>
        /// <typeparam name="TResource">The type of the resource.</typeparam>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">channel</exception>
        /// <exception cref="LimeException">Returns an exception with the failure reason</exception>
        public static Task <TResource> GetResourceAsync <TResource>(this ICommandChannel channel, LimeUri uri, CancellationToken cancellationToken) where TResource : Document, new()
        {
            return(GetResourceAsync <TResource>(channel, uri, null, cancellationToken));
        }
Esempio n. 21
0
 /// <summary>
 /// Merges the resource value.
 /// </summary>
 /// <typeparam name="TResource">The type of the resource.</typeparam>
 /// <param name="channel">The channel.</param>
 /// <param name="uri">The resource uri.</param>
 /// <param name="resource">The resource to be merge.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns></returns>
 /// <exception cref="System.ArgumentNullException">channel</exception>
 public static Task MergeResourceAsync <TResource>(this ICommandChannel channel, LimeUri uri, TResource resource, CancellationToken cancellationToken) where TResource : Document
 {
     return(MergeResourceAsync(channel, uri, resource, null, cancellationToken));
 }
Esempio n. 22
0
 /// <summary>
 /// Composes a command envelope with a
 /// delete method for the specified resource.
 /// </summary>
 /// <param name="channel">The channel.</param>
 /// <param name="uri">The resource uri.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns></returns>
 /// <exception cref="System.ArgumentNullException">channel</exception>
 /// <exception cref="LimeException">Returns an exception with the failure reason</exception>
 public static Task DeleteResourceAsync(this ICommandChannel channel, LimeUri uri, CancellationToken cancellationToken)
 {
     return(DeleteResourceAsync(channel, uri, null, cancellationToken));
 }
Esempio n. 23
0
 public XpoImportHelper(IDataLayer dataLayer, int batchSize)
 {
     this.dataLayer      = dataLayer;
     this.commandChannel = dataLayer as ICommandChannel;
     this.batchSize      = batchSize;
 }
 public TaskController(ICommandChannel commandChannel, IQueryHandler<TaskQuery,IEnumerable<Task>> taskQueryHandler)
 {
     _commandChannel = commandChannel;
     _taskQueryHandler = taskQueryHandler;
 }
Esempio n. 25
0
 public CommandChannelLogger(ICommandChannel logged, ILogger <ICommandChannel> logger)
 {
     _logged = logged;
     _logger = logger;
 }
Esempio n. 26
0
 public static void UnregisterCte(this ICommandChannel channel, string cteName)
 {
     channel.Do(CommandUnregisterCteName, cteName);
 }
 public DropBoxController(ICommandChannel commandChannel, IQueryChannel queryChannel, UserModel user)
 {
     _commandChannel = commandChannel;
     _queryChannel   = queryChannel;
     _user           = user;
 }
 public static IConvertible ExecuteOnAndReturnRowId(this ITableInsert insert, ICommandChannel on)
 {
     insert.ExecuteOn(on);
     return(on.LastInsertedId);
 }
 public RemoteCommandProxy(ICommandChannel commandChannel, Type classToProxy) : base(classToProxy)
 {
     this.commandChannel = commandChannel;
     this.classToProxy   = classToProxy;
     binarySerialization = classToProxy.GetCustomAttribute <BinarySerializationAttribute>() != null;
 }
Esempio n. 30
0
 public static T GetServerSideMethods <T>(this ICommandChannel commandChannel)
 {
     return((T) new RemoteCommandProxy(commandChannel, typeof(T)).GetTransparentProxy());
 }
Esempio n. 31
0
 public virtual TResultType ExecuteOn(ICommandChannel on)
 => _executor.ExecuteOnAdapter(on, Statement.Sql, Statement.Parameters);
Esempio n. 32
0
		public void ItShouldAddThePassedInCommandAsAnAction(ICommandChannel commandChannel, Command command, State sut)
		{
			// Arrange

			// Act
			sut.AddAction(command);

			sut.ExecuteActions(commandChannel);

			// Assert
			A.CallTo(() => commandChannel.Send(command.Code)).MustHaveHappened(Repeated.Exactly.Once);
		}
Esempio n. 33
0
 public void Init()
 {
     _adapter = new MySQLCommandChannelFactory().Create(new CreationParameters <MySqlConnectionStringBuilder>(Credentials, "CREATE TABLE example(colA TEXT, colB TEXT)", true));
 }
        public IDataResult ExecuteFunction(IDataParameters Parameters)
        {
            DataResult dataResult = new DataResult();
            string     id         = Parameters.AdditionalValues[DataStoreId].ToString();
            IDataStore DataStore  = null;

            DataStore = this.ConfigResolver.GetById(id);


            if (Parameters.MemberName == nameof(IDataStore.SelectData))
            {
                dataResult.ResultValue =
                    ObjectSerializationService
                    .ToByteArray(
                        DataStore.SelectData(
                            ObjectSerializationService
                            .GetObjectsFromByteArray <SelectStatement[]>(Parameters.ParametersValue)
                            )
                        );
            }
            if (Parameters.MemberName == nameof(IDataStore.ModifyData))
            {
                dataResult.ResultValue =
                    ObjectSerializationService
                    .ToByteArray(
                        DataStore.ModifyData(
                            ObjectSerializationService
                            .GetObjectsFromByteArray <ModificationStatement[]>(Parameters.ParametersValue)
                            )
                        );
            }
            if (Parameters.MemberName == nameof(IDataStore.UpdateSchema))
            {
                UpdateSchemaParameters updateSchemaParameters = ObjectSerializationService
                                                                .GetObjectsFromByteArray <UpdateSchemaParameters>(Parameters.ParametersValue);
                dataResult.ResultValue =
                    ObjectSerializationService
                    .ToByteArray(
                        DataStore.UpdateSchema(updateSchemaParameters.dontCreateIfFirstTableNotExist,
                                               updateSchemaParameters.tables)
                        );
            }
            if (Parameters.MemberName == nameof(ICommandChannel.Do))
            {
                CommandChannelDoParams DoParams = ObjectSerializationService
                                                  .GetObjectsFromByteArray <CommandChannelDoParams>(Parameters.ParametersValue);

                ICommandChannel commandChannel = DataStore as ICommandChannel;
                if (commandChannel != null)
                {
                    object data = commandChannel.Do(DoParams.Command,
                                                    DoParams.Args);


                    switch (DoParams.Command)
                    {
                    case CommandChannelHelper.Command_ExecuteScalarSQL:
                    case CommandChannelHelper.Command_ExecuteScalarSQLWithParams:
                        dataResult.ResultValue =
                            ObjectSerializationService
                            .ToByteArray <object>(
                                data
                                );
                        break;

                    case CommandChannelHelper.Command_ExecuteQuerySQL:
                    case CommandChannelHelper.Command_ExecuteQuerySQLWithParams:
                    case CommandChannelHelper.Command_ExecuteQuerySQLWithMetadata:
                    case CommandChannelHelper.Command_ExecuteQuerySQLWithMetadataWithParams:
                    case CommandChannelHelper.Command_ExecuteStoredProcedure:
                    case CommandChannelHelper.Command_ExecuteStoredProcedureParametrized:
                        dataResult.ResultValue =
                            ObjectSerializationService
                            .ToByteArray <SelectedData>(
                                data as SelectedData
                                );

                        break;

                    case CommandChannelHelper.Command_ExecuteNonQuerySQL:
                    case CommandChannelHelper.Command_ExecuteNonQuerySQLWithParams:
                        dataResult.ResultValue =
                            ObjectSerializationService
                            .ToByteArray <int>(
                                (int)data
                                );
                        break;

                    default:
                        throw new Exception($"ICommandChannel Do method retuned an unknow data type while processing {DoParams.Command}");
                    }
                }
            }
            return(dataResult);
        }