Example #1
0
        /// <summary>
        ///     Dispatch the request to the appropriate consumer.
        ///     If it is a <see cref="DataRequest" /> dispatch it to its target
        ///     <see cref="DataStore" /> according to its CollectionName property
        ///     If it is an administrative request process it directly.
        /// </summary>
        /// <param name="clientRequest"></param>
        /// <param name="client"></param>
        public void DispatchRequest(Request clientRequest, IClient client)
        {
            if (clientRequest == null)
            {
                throw new ArgumentNullException(nameof(clientRequest));
            }
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            try
            {
                if (clientRequest is LockRequest lockRequest)
                {
                    ProcessLockRequest(lockRequest, client);
                    return;
                }

                if (clientRequest is DataRequest dataRequest)
                {
                    ProcessDataRequest(dataRequest, client);
                    return;
                }


                if (clientRequest.RequestClass == RequestClass.Admin)
                {
                    ProcessAdminRequest(clientRequest, client);
                    return;
                }


                if (clientRequest.RequestClass == RequestClass.UniqueIdGeneration)
                {
                    ProcessUniqueIdRequest(clientRequest, client);
                    return;
                }

                if (clientRequest is TransactionRequest transactionRequest)
                {
                    //TODO temporary: move to service container

                    var transactionManager = new TransactionManager(_serviceContainer.LockManager, PersistenceEngine);

                    transactionManager.ProcessTransactionRequest(transactionRequest, client, DataStores);

                    return;
                }

                throw new NotSupportedException(
                          $"An unknown request type was received {clientRequest.GetType().FullName}");
            }
            catch (Exception ex)
            {
                client.SendResponse(new ExceptionResponse(ex));
            }
        }
Example #2
0
        private void ProcessAdminRequest(Request clientRequest, IClient client)
        {
            if (clientRequest is RegisterTypeRequest req)
            {
                RegisterType(req, client);
                return;
            }

            if (clientRequest is GetKnownTypesRequest)
            {
                GetKnownTypes(client);

                return;
            }


            // This one is special. A short lock is required as even the read-only operations write in the ServerLog
            // The lock is inside ServerLog no need to use the scheduler
            if (clientRequest is LogRequest logRequest)
            {
                try
                {
                    var lines = logRequest.LinesCount;

                    var entries      = ServerLog.GetLast(lines);
                    var maxLockEntry = ServerLog.MaxLogEntry;

                    var response = new LogResponse();
                    foreach (var entry in entries)
                    {
                        response.Entries.Add(entry);
                    }

                    response.MaxLockEntry = maxLockEntry;

                    client.SendResponse(response);
                }
                catch (Exception ex)
                {
                    client.SendResponse(new ExceptionResponse(ex));
                }

                return;
            }

            if (clientRequest is DumpRequest dumpRequest)
            {
                Dump(dumpRequest, client);
                return;
            }


            throw new NotSupportedException("Unknown request type: " + clientRequest.GetType());
        }
Example #3
0
        /// <summary>
        ///     Dispatch the request to the appropriate consumer.
        ///     If it is a <see cref="DataRequest" /> dispatch it to its target
        ///     <see cref="DataStore" /> according to its FullTypeName property
        ///     If it is an administrative request process it directly.
        /// </summary>
        /// <param name="clientRequest"></param>
        /// <param name="client"></param>
        public void DispatchRequest(Request clientRequest, IClient client)
        {
            if (clientRequest == null)
            {
                throw new ArgumentNullException(nameof(clientRequest));
            }
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            try
            {
                if (clientRequest is DataRequest dataRequest)
                {
                    ProcessDataRequest(dataRequest, client);
                    return;
                }


                if (clientRequest.RequestClass == RequestClass.Admin)
                {
                    ProcessAdminRequest(clientRequest, client);
                    return;
                }


                if (clientRequest.RequestClass == RequestClass.UniqueIdGeneration)
                {
                    ProcessUniqueIdRequest(clientRequest, client);
                    return;
                }

                if (clientRequest is TransactionRequest transactionRequest)
                {
                    ProcessTransactionRequest(transactionRequest, client);
                    return;
                }

                throw new NotSupportedException(
                          $"An unknown request type was received {clientRequest.GetType().FullName}");
            }
            catch (Exception ex)
            {
                client.SendResponse(new ExceptionResponse(ex));
            }
        }
Example #4
0
 private static IEnumerable <string> GetRequestInfo(Request request) =>
 request.GetType().GetProperties().Select(p => $"<div>{p.Name}: {p.GetValue(request)}</div>");