public IConnectionResponse Patch(IConnectionRequest connectionRequest)
        {
            if (connectionRequest == null)
            {
                Log.Error(typeof(HttpConnectionWorker).Name, "Patch", "Invalid Connection Request.");
                throw new ConnectionException(typeof(HttpConnectionWorker).Name, "Patch", "Invalid Connection Request.");
            }

            return(null);
        }
예제 #2
0
 public override void PlayerPreJoinEvent(IConnectionRequest request)
 {
 }
예제 #3
0
 public override ConnectionAcceptanceFilterStatus ConnectionRequestEvent(IConnectionRequest request, ref string refusalMessage)
 {
     return(ConnectionAcceptanceFilterStatus.StatusAccepting);
 }
예제 #4
0
 public override void PlayerPreJoinEvent(IConnectionRequest request)
 {
     Update(request.ClientID, request.ClientName, request.ClientAddress.Address, request.ClientSerialHash, $"{request.ClientVersion} {request.ClientRevisionNumber}");
 }
	    public IConnectionResponse Patch(IConnectionRequest connectionRequest) 
        {
		
		    if(connectionRequest == null) 
            {
			    Log.Error(typeof(HttpConnectionWorker).Name, "Patch", "Invalid Connection Request.");
                throw new ConnectionException(typeof(HttpConnectionWorker).Name, "Patch", "Invalid Connection Request.");
		    }

		    return null;
	    }
	    public IConnectionResponse Options(IConnectionRequest connectionRequest) 
        {
		
		    if(connectionRequest == null) 
            {
			    Log.Error(typeof(HttpConnectionWorker).Name, "Options", "Invalid Connection Request.");
                throw new ConnectionException(typeof(HttpConnectionWorker).Name, "Options", "Invalid Connection Request.");
		    }
            
		    /*
		     * Request Parameters
		     */
		    StringBuilder url = new StringBuilder(connectionRequest.GetUrl());
		
		    IEnumerator<String> queryParameters = connectionRequest.GetQueryParameters();
		    IEnumerator<String> headerParameters = connectionRequest.GetHeaderParameters();
		
		
		    /*
		     * Add Query Parameters
		     */
            int count = 0;
		    while(queryParameters.MoveNext()) 
            {
			
			    String parameter = queryParameters.Current;
			    Connect.Model.ServiceDescriptor.Request.QueryParameter queryParameter = connectionRequest.GetQueryParameter(parameter);

                if (count == 0)
                {
                    url.Append("?");
                    url.Append(parameter + "=" + queryParameter.GetValue());
                }
                else
                {
                    url.Append("&");
                    url.Append(parameter + "=" + queryParameter.GetValue());
                }
            }


            /*
             * Make Request
             */
            HttpClient httpClient = new HttpClient();
            HttpResponseMessage httpResponse;
			
		
		    /*
		     * Add Header Parameters
		     */
		    while(headerParameters.MoveNext()) 
            {
			
			    String header = headerParameters.Current;
			    Connect.Model.ServiceDescriptor.Request.HeaderParameter headerParameter = connectionRequest.GetHeaderParameter(header);

                httpClient.DefaultRequestHeaders.TryAddWithoutValidation(header, headerParameter.GetValue());
            }
		

		
            /* execute */
        
            try 
            {
                Task<HttpResponseMessage> httpResponseMessage = null;// httpClient.GetAsync(url.ToString());
                httpResponseMessage.Wait();

                httpResponse = httpResponseMessage.Result; 
            } 
            catch(System.Exception exception) 
            {
                Log.Error(typeof(HttpConnectionWorker).Name, "Options", "Exception caught while executing request, " + exception.Message);
                throw new ConnectionException(typeof(HttpConnectionWorker).Name, "Options", "Exception caught while executing request, " + exception.Message);
            }



            /* return response */
            if (!httpResponse.IsSuccessStatusCode)
            {
                return (IConnectionResponse)new ConnectionResponse(new ConnectionStatusCodes().GetStatusCode(httpResponse.StatusCode.ToString()), new ConnectionStatusCodes().GetStatusMessage(Convert.ToInt32(httpResponse.StatusCode.ToString())));
            }


            Task<Stream> repsonseStreamAsync = httpResponse.Content.ReadAsStreamAsync();
            repsonseStreamAsync.Wait();

            Stream responseStream = repsonseStreamAsync.Result;

            return (IConnectionResponse)new ConnectionResponse(new ConnectionStatusCodes().GetStatusCode(httpResponse.StatusCode.ToString()), responseStream);
	    }
        public IConnectionResponse Get(IConnectionRequest connectionRequest) 
        {

		    if(connectionRequest == null) 
            {
			    Log.Error(typeof(HttpConnectionWorker).Name, "Get", "Invalid Connection Request.");
			    throw new ConnectionException(typeof(HttpConnectionWorker).Name, "Get", "Invalid Connection Request.");
		    }

            /*if (connectionRequest.GetUrl().Contains("get_books"))
            {
                String books = "<books><book><name>C</name><description>C Description</description><author>C Author</author><link>C Link</link></book><book><name>C Plus</name><description>C Plus Description</description><author>C Plus Author</author><link>C Plus Link</link></book><book><name>C Sharp</name><description>C Sharp Description</description><author>C Sharp Author</author><link>C Sharp Link</link></book><book><name>Java</name><description>Java Description</description><author>Java Author</author><link>Java Link</link></book><book><name>JavaScript</name><description>JavaScript Description</description><author>JavaScript Author</author><link>JavaScript Link</link></book><book><name>Swift</name><description>Swift Description</description><author>Swift Author</author><link>Swift Link</link></book><book><name>Objective C</name><description>Objective C Description</description><author>Objective C Author</author><link>Objective C Link</link></book></books>";
                Stream booksStream;

                byte[] bytes = new byte[books.Length * sizeof(char)];
                System.Buffer.BlockCopy(books.ToCharArray(), 0, bytes, 0, bytes.Length);

                try
                {
                    booksStream = Utils.Utils.ToStream(bytes);
                    return new ConnectionResponse(200, booksStream);
                }
                catch (SiminovException se)
                {

                }
            }
            else
            {
                String lessions = "<lessions><lession><name>C First Lession</name><description>C First Lession Description</description><link>C First Lession Link</link></lession><lession><name>C Second Lession</name><description>C Second Lession Description</description><link>C Second Lession Link</link></lession></lessions>";
                Stream lessionsStream;

                byte[] bytes = new byte[lessions.Length * sizeof(char)];
                System.Buffer.BlockCopy(lessions.ToCharArray(), 0, bytes, 0, bytes.Length);

                try
                {
                    lessionsStream = Utils.Utils.ToStream(bytes);
                    return new ConnectionResponse(200, lessionsStream);
                }
                catch (SiminovException se)
                {

                }
            }

            return new ConnectionResponse(200, "");*/
		

		    /*
		     * Request Parameters
		     */
		    StringBuilder url = new StringBuilder(connectionRequest.GetUrl());
		
		    IEnumerator<String> queryParameters = connectionRequest.GetQueryParameters();
		    IEnumerator<String> headerParameters = connectionRequest.GetHeaderParameters();
		
		
		    /*
		     * Make Request
		     */
            HttpClient httpClient = new HttpClient();
            HttpResponseMessage httpResponse;

		    /*
		     * Add Query Parameters
		     */
            int count = 0;
		    while(queryParameters.MoveNext()) 
            {
			
			    String parameter = queryParameters.Current;
			    Connect.Model.ServiceDescriptor.Request.QueryParameter queryParameter = connectionRequest.GetQueryParameter(parameter);
			
                if(count == 0) 
                {
                    url.Append("?");
                    url.Append(parameter + "=" + queryParameter.GetValue());
                } 
                else
                {
                    url.Append("&");
                    url.Append(parameter + "=" + queryParameter.GetValue());
                }
		    }
				
		    /*
		     * Add Header Parameters
		     */
		    while(headerParameters.MoveNext()) 
            {
			
			    String header = headerParameters.Current;
			    Connect.Model.ServiceDescriptor.Request.HeaderParameter headerParameter = connectionRequest.GetHeaderParameter(header);

                httpClient.DefaultRequestHeaders.TryAddWithoutValidation(header, headerParameter.GetValue());
		    }
		

            /* execute */
        
            try 
            {
                Task<HttpResponseMessage> httpResponseMessage = httpClient.GetAsync(url.ToString());
                httpResponseMessage.Wait();

                httpResponse = httpResponseMessage.Result; 
            } 
            catch(System.Exception exception) 
            {
        	    Log.Error(typeof(HttpConnectionWorker).Name, "Get", "Exception caught while executing request, " + exception.Message);
        	    throw new ConnectionException(typeof(HttpConnectionWorker).Name, "Get", "Exception caught while executing request, " + exception.Message);
            }


            /* return response */
            if(!httpResponse.IsSuccessStatusCode) 
            {
                return (IConnectionResponse)new ConnectionResponse(new ConnectionStatusCodes().GetStatusCode(httpResponse.StatusCode.ToString()), new ConnectionStatusCodes().GetStatusMessage(Convert.ToInt32(httpResponse.StatusCode.ToString())));
            }


            Task<Stream> repsonseStreamAsync = httpResponse.Content.ReadAsStreamAsync();
            repsonseStreamAsync.Wait();

            Stream responseStream = repsonseStreamAsync.Result;

            return (IConnectionResponse)new ConnectionResponse(new ConnectionStatusCodes().GetStatusCode(httpResponse.StatusCode.ToString()), responseStream);
	    }
예제 #8
0
 public virtual void OnRequestInvoke(IConnectionRequest connectionRequest)
 {
 }
        public IConnectionResponse Options(IConnectionRequest connectionRequest)
        {
            if (connectionRequest == null)
            {
                Log.Error(typeof(HttpConnectionWorker).Name, "Options", "Invalid Connection Request.");
                throw new ConnectionException(typeof(HttpConnectionWorker).Name, "Options", "Invalid Connection Request.");
            }

            /*
             * Request Parameters
             */
            StringBuilder url = new StringBuilder(connectionRequest.GetUrl());

            IEnumerator <String> queryParameters  = connectionRequest.GetQueryParameters();
            IEnumerator <String> headerParameters = connectionRequest.GetHeaderParameters();


            /*
             * Add Query Parameters
             */
            int count = 0;

            while (queryParameters.MoveNext())
            {
                String parameter = queryParameters.Current;
                Connect.Model.ServiceDescriptor.Request.QueryParameter queryParameter = connectionRequest.GetQueryParameter(parameter);

                if (count == 0)
                {
                    url.Append("?");
                    url.Append(parameter + "=" + queryParameter.GetValue());
                }
                else
                {
                    url.Append("&");
                    url.Append(parameter + "=" + queryParameter.GetValue());
                }
            }


            /*
             * Make Request
             */
            HttpClient          httpClient = new HttpClient();
            HttpResponseMessage httpResponse;


            /*
             * Add Header Parameters
             */
            while (headerParameters.MoveNext())
            {
                String header = headerParameters.Current;
                Connect.Model.ServiceDescriptor.Request.HeaderParameter headerParameter = connectionRequest.GetHeaderParameter(header);

                httpClient.DefaultRequestHeaders.TryAddWithoutValidation(header, headerParameter.GetValue());
            }



            /* execute */

            try
            {
                Task <HttpResponseMessage> httpResponseMessage = null;// httpClient.GetAsync(url.ToString());
                httpResponseMessage.Wait();

                httpResponse = httpResponseMessage.Result;
            }
            catch (System.Exception exception)
            {
                Log.Error(typeof(HttpConnectionWorker).Name, "Options", "Exception caught while executing request, " + exception.Message);
                throw new ConnectionException(typeof(HttpConnectionWorker).Name, "Options", "Exception caught while executing request, " + exception.Message);
            }



            /* return response */
            if (!httpResponse.IsSuccessStatusCode)
            {
                return((IConnectionResponse) new ConnectionResponse(new ConnectionStatusCodes().GetStatusCode(httpResponse.StatusCode.ToString()), new ConnectionStatusCodes().GetStatusMessage(Convert.ToInt32(httpResponse.StatusCode.ToString()))));
            }


            Task <Stream> repsonseStreamAsync = httpResponse.Content.ReadAsStreamAsync();

            repsonseStreamAsync.Wait();

            Stream responseStream = repsonseStreamAsync.Result;

            return((IConnectionResponse) new ConnectionResponse(new ConnectionStatusCodes().GetStatusCode(httpResponse.StatusCode.ToString()), responseStream));
        }
        public IConnectionResponse Get(IConnectionRequest connectionRequest)
        {
            if (connectionRequest == null)
            {
                Log.Error(typeof(HttpConnectionWorker).Name, "Get", "Invalid Connection Request.");
                throw new ConnectionException(typeof(HttpConnectionWorker).Name, "Get", "Invalid Connection Request.");
            }

            /*if (connectionRequest.GetUrl().Contains("get_books"))
             * {
             *  String books = "<books><book><name>C</name><description>C Description</description><author>C Author</author><link>C Link</link></book><book><name>C Plus</name><description>C Plus Description</description><author>C Plus Author</author><link>C Plus Link</link></book><book><name>C Sharp</name><description>C Sharp Description</description><author>C Sharp Author</author><link>C Sharp Link</link></book><book><name>Java</name><description>Java Description</description><author>Java Author</author><link>Java Link</link></book><book><name>JavaScript</name><description>JavaScript Description</description><author>JavaScript Author</author><link>JavaScript Link</link></book><book><name>Swift</name><description>Swift Description</description><author>Swift Author</author><link>Swift Link</link></book><book><name>Objective C</name><description>Objective C Description</description><author>Objective C Author</author><link>Objective C Link</link></book></books>";
             *  Stream booksStream;
             *
             *  byte[] bytes = new byte[books.Length * sizeof(char)];
             *  System.Buffer.BlockCopy(books.ToCharArray(), 0, bytes, 0, bytes.Length);
             *
             *  try
             *  {
             *      booksStream = Utils.Utils.ToStream(bytes);
             *      return new ConnectionResponse(200, booksStream);
             *  }
             *  catch (SiminovException se)
             *  {
             *
             *  }
             * }
             * else
             * {
             *  String lessions = "<lessions><lession><name>C First Lession</name><description>C First Lession Description</description><link>C First Lession Link</link></lession><lession><name>C Second Lession</name><description>C Second Lession Description</description><link>C Second Lession Link</link></lession></lessions>";
             *  Stream lessionsStream;
             *
             *  byte[] bytes = new byte[lessions.Length * sizeof(char)];
             *  System.Buffer.BlockCopy(lessions.ToCharArray(), 0, bytes, 0, bytes.Length);
             *
             *  try
             *  {
             *      lessionsStream = Utils.Utils.ToStream(bytes);
             *      return new ConnectionResponse(200, lessionsStream);
             *  }
             *  catch (SiminovException se)
             *  {
             *
             *  }
             * }
             *
             * return new ConnectionResponse(200, "");*/


            /*
             * Request Parameters
             */
            StringBuilder url = new StringBuilder(connectionRequest.GetUrl());

            IEnumerator <String> queryParameters  = connectionRequest.GetQueryParameters();
            IEnumerator <String> headerParameters = connectionRequest.GetHeaderParameters();


            /*
             * Make Request
             */
            HttpClient          httpClient = new HttpClient();
            HttpResponseMessage httpResponse;

            /*
             * Add Query Parameters
             */
            int count = 0;

            while (queryParameters.MoveNext())
            {
                String parameter = queryParameters.Current;
                Connect.Model.ServiceDescriptor.Request.QueryParameter queryParameter = connectionRequest.GetQueryParameter(parameter);

                if (count == 0)
                {
                    url.Append("?");
                    url.Append(parameter + "=" + queryParameter.GetValue());
                }
                else
                {
                    url.Append("&");
                    url.Append(parameter + "=" + queryParameter.GetValue());
                }
            }

            /*
             * Add Header Parameters
             */
            while (headerParameters.MoveNext())
            {
                String header = headerParameters.Current;
                Connect.Model.ServiceDescriptor.Request.HeaderParameter headerParameter = connectionRequest.GetHeaderParameter(header);

                httpClient.DefaultRequestHeaders.TryAddWithoutValidation(header, headerParameter.GetValue());
            }


            /* execute */

            try
            {
                Task <HttpResponseMessage> httpResponseMessage = httpClient.GetAsync(url.ToString());
                httpResponseMessage.Wait();

                httpResponse = httpResponseMessage.Result;
            }
            catch (System.Exception exception)
            {
                Log.Error(typeof(HttpConnectionWorker).Name, "Get", "Exception caught while executing request, " + exception.Message);
                throw new ConnectionException(typeof(HttpConnectionWorker).Name, "Get", "Exception caught while executing request, " + exception.Message);
            }


            /* return response */
            if (!httpResponse.IsSuccessStatusCode)
            {
                return((IConnectionResponse) new ConnectionResponse(new ConnectionStatusCodes().GetStatusCode(httpResponse.StatusCode.ToString()), new ConnectionStatusCodes().GetStatusMessage(Convert.ToInt32(httpResponse.StatusCode.ToString()))));
            }


            Task <Stream> repsonseStreamAsync = httpResponse.Content.ReadAsStreamAsync();

            repsonseStreamAsync.Wait();

            Stream responseStream = repsonseStreamAsync.Result;

            return((IConnectionResponse) new ConnectionResponse(new ConnectionStatusCodes().GetStatusCode(httpResponse.StatusCode.ToString()), responseStream));
        }
예제 #11
0
        /// <summary>
        /// It handles the service request
        /// </summary>
        /// <param name="service">Service instance</param>
        /// <returns>IConnectionResponse instance</returns>
        /// <exception cref="Siminov.Connect.Exception.ConnectionException">If any exception occur while executing service request</exception>
        public IConnectionResponse Handle(IService service)
        {
            IConnectionRequest connectionRequest = ConnectionHelper.PrepareConnectionRequest(service);

            /*
             * Service Event onServiceApiInvoke
             */
            service.OnRequestInvoke(connectionRequest);

            IConnection connection = null;

            if (connectionRequest.GetProtocol().Equals(Constants.SERVICE_DESCRIPTOR_HTTP_PROTOCOL, StringComparison.OrdinalIgnoreCase))
            {
                connection = httpConnection;
            }
            else if (connectionRequest.GetProtocol().Equals(Constants.SERVICE_DESCRIPTOR_HTTPS_PROTOCOL, StringComparison.OrdinalIgnoreCase))
            {
                connection = httpsConnection;
            }


            IConnectionResponse connectionResponse = null;

            if (connectionRequest.GetType().Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_GET_TYPE, StringComparison.OrdinalIgnoreCase))
            {
                connectionResponse = connection.Get(connectionRequest);
            }
            else if (connectionRequest.GetType().Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_HEAD_TYPE, StringComparison.OrdinalIgnoreCase))
            {
                connectionResponse = connection.Head(connectionRequest);
            }
            else if (connectionRequest.GetType().Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_POST_TYPE, StringComparison.OrdinalIgnoreCase))
            {
                connectionResponse = connection.Post(connectionRequest);
            }
            else if (connectionRequest.GetType().Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_PUT_TYPE, StringComparison.OrdinalIgnoreCase))
            {
                connectionResponse = connection.Put(connectionRequest);
            }
            else if (connectionRequest.GetType().Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_DELETE_TYPE, StringComparison.OrdinalIgnoreCase))
            {
                connectionResponse = connection.Delete(connectionRequest);
            }
            else if (connectionRequest.GetType().Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_TRACE_TYPE, StringComparison.OrdinalIgnoreCase))
            {
                connectionResponse = connection.Trace(connectionRequest);
            }
            else if (connectionRequest.GetType().Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_OPTIONS_TYPE, StringComparison.OrdinalIgnoreCase))
            {
                connectionResponse = connection.Options(connectionRequest);
            }
            else if (connectionRequest.GetType().Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_CONNECT_TYPE, StringComparison.OrdinalIgnoreCase))
            {
                connectionResponse = connection.Connect(connectionRequest);
            }
            else if (connectionRequest.GetType().Equals(Constants.SERVICE_DESCRIPTOR_REQUEST_PATCH_TYPE, StringComparison.OrdinalIgnoreCase))
            {
                connectionResponse = connection.Patch(connectionRequest);
            }

            return(connectionResponse);
        }
예제 #12
0
 public virtual void OnRequestInvoke(IConnectionRequest connectionRequest) { }