Esempio n. 1
0
        public void TestGetResponseFromServerMethodWithNullRequest()
        {
            IRequestable <int> testReq = null;
            var testDict   = new Dictionary <string, IServable <int> >();
            var testRouter = new Router <int>(testDict);

            testRouter.GetResponseFromServer(testReq);
        }
Esempio n. 2
0
        public void CallRouter(IRequestable <string> req)
        {
            if (req == null)
            {
                throw new ArgumentNullException();
            }

            EmbeddedRouter.GetResponseFromServer(req);
        }
        public CommunicationHandler(IInvokable invokable, IRequestable requestable) {
            _client = new UdpClient(Properties.Settings.Default.DefaultPort);
            _client.DataReceived += UdpClient_DataReceived;
            _client.Start();
            Console.WriteLine($"Started listening on udp port: {Properties.Settings.Default.DefaultPort}");

            _processor = new DataProcessor(_client, invokable, requestable);

        }
Esempio n. 4
0
        /// <summary>
        /// Passes requet through variable number of functions that are saved to the server instance
        /// </summary>
        /// <param name="req">Instance of request passed to the router</param>
        /// <param name="middleWareItems">Series of functions that take a request and return a processed resquest</param>
        /// <returns>Parsed Request</returns>
        IResponsable <T> ParseRequest(IRequestable <T> req, params MiddleWareOperation <T>[] middleWareItems)
        {
            IResponsable <T> res = null;

            foreach (var operation in middleWareItems)
            {
                operation(ref req, ref res);
            }

            return(res);
        }
Esempio n. 5
0
 /// <summary>
 /// Attempts to parse passed request with the routes middleware.
 /// Throw a custom exception if the function fails
 /// </summary>
 /// <param name="req">Request to be parsed</param>
 /// <param name="server">Server containing functionality to be used</param>
 /// <returns>A parsed request or an exception</returns>
 IResponsable <T> ValidateRouteProcesses(IRequestable <T> req, IServable <T> server)
 {
     try
     {
         IResponsable <T> res = server.Process(req);
         return(res);
     }
     catch (Exception)
     {
         throw new Router400BadRequestException <T>(req);
     }
 }
 //TODO: move to separate class {READY}
 public void ShowDifferences(IEnumerable<FileDifferences> differences, IRequestable requestable)
 {
     foreach (var file in differences)
     {
         requestable.SendMessage($"This file has differences: {file.Mp3File.FilePath}");
         foreach (var diff in file.Diffs)
         {
             requestable.SendMessage($"{diff.Key} in Mp3File Name: {diff.Value.FileNameValue}");
             requestable.SendMessage($"{diff.Key} in Tags: {diff.Value.TagValue}");
             requestable.SendMessage("\n");
         }
     }
 }
Esempio n. 7
0
 //TODO: move to separate class {READY}
 public void ShowDifferences(IEnumerable <FileDifferences> differences, IRequestable requestable)
 {
     foreach (var file in differences)
     {
         requestable.SendMessage($"This file has differences: {file.Mp3File.FilePath}");
         foreach (var diff in file.Diffs)
         {
             requestable.SendMessage($"{diff.Key} in Mp3File Name: {diff.Value.FileNameValue}");
             requestable.SendMessage($"{diff.Key} in Tags: {diff.Value.TagValue}");
             requestable.SendMessage("\n");
         }
     }
 }
        public IRequestable GetParameters(LambdaExpression lambdaExpression, TargetMethodType methodType, AggregationType aggType = AggregationType.Min)
        {
            IRequestable condition = null;

            switch (methodType)
            {
            case TargetMethodType.Projection: {
                switch (lambdaExpression.Body.NodeType)
                {
                case ExpressionType.Equal: {
                    condition = createSingleSelectionFunctionFromBinaryExpression(lambdaExpression);                                       // Select a variable with condition
                } break;

                case ExpressionType.New: {
                    condition = createMultipleSelectionFunction(lambdaExpression);                                       // Select many variables
                } break;

                case ExpressionType.Call: {
                    condition = createSingleSelectionFunction(lambdaExpression);                                       // Select a variable
                } break;

                case ExpressionType.Parameter: {
                    condition = new All();                                     // Select all with no condition
                } break;

                default: {
                    condition = createSingleSelectionFunctionFromBinaryExpression(lambdaExpression);                                       // Select a variable with condition
                } break;
                }
            } break;

            case TargetMethodType.Selection: {
                condition = createFilterForSelection(lambdaExpression);
            } break;

            case TargetMethodType.Aggregation: {
                switch (aggType)
                {
                case AggregationType.Count: {
                    condition = createCountFunction(lambdaExpression);
                } break;

                default: {
                    condition = createAggregationForAggregationFunction(lambdaExpression, aggType);
                } break;
                }
            } break;
            }

            return(condition);
        }
        public CommunicationHandler(int port, IPlayerContainer container, INotifiable notify, IRequestable request) { // TODO: Interface ILobby

            _playerContainer = container;
            _tcpListener = new TcpListener(port);
            _tcpListener.SocketAccepted += SocketAccepted;
            _tcpListener.Start();

            _udpClient = new UdpClient(port);
            _udpClient.DataReceived += UdpClient_DataReceived;
            _udpClient.Start();

            _processor = new DataProcessor(notify, request);
            Console.WriteLine("Server started listening on port : {0}", ((IPEndPoint)_tcpListener.Socket.LocalEndPoint).Port);
        }
Esempio n. 10
0
        /// <summary>
        /// constructs a response from the parsed user request
        /// </summary>
        /// <param name="req">Request passed on the instance of the Router query. Will constantly change for the route</param>
        /// <param name="middleWareItems">Middle ware saved to the instance of a server. The middle ware will be constant</param>
        /// <returns>A response constructed from a parsed request body</returns>
        public IResponsable <T> GetResponseFromServer(IRequestable <T> req)
        {
            if (req == null)
            {
                throw new ArgumentNullException();
            }

            IServable <T> server = GetServer(req.Path);
            var           res    = ValidateRouteProcesses(req, server);

            if (res == null)
            {
                throw new Router400ErrorNoResponseDefined <T>(req);
            }

            return(res);
        }
 internal DataProcessor(UdpClient client, IInvokable invoke, IRequestable request) {
     _invoke = new Invoke(client, invoke);
     _request = new Request(client, request);
 }
 internal Request(UdpClient client, IRequestable request) {
     _client = client;
     _request = request;
 }
 public DataProcessor(INotifiable notify, IRequestable request) {
     _notify = new Notify(notify);
     _request = new Request(request);
 }
Esempio n. 14
0
 public RequestHandler(IRequestable request)
 {
     this.request = request;
 }
Esempio n. 15
0
 public Router400BadRequestException(IRequestable <T> req) : base(404, req)
 {
 }
Esempio n. 16
0
 public Router400ErrorNoResponseDefined(IRequestable <T> req) : base(404, req)
 {
 }
 public Request(IRequestable _params, int id)
 {
     Params = _params;
     Id     = id;
 }
 public Request(IRequestable _params)
 {
     Params = _params;
 }
 public KeyCardCheck(IRequestable securityUI)
 {
     this.securityUI = securityUI;
 }
Esempio n. 20
0
 /// <summary>
 /// Passes the response's contents to the instance of the RouterResponse
 /// </summary>
 /// <param name="req"></param>
 public RouterResponse(IRequestable <T> req)
 {
     Path = req.Path;
     Body = req.Body;
 }
 public Request(IRequestable request) {
     _request = request;
 }
Esempio n. 22
0
 public RouterAbstractException(int errorCode, IRequestable <T> req) : this(errorCode)
 {
     Body = req.Body;
     Path = req.Path;
 }