Exemple #1
0
        public void Init()
        {
            if (Instance != null)
            {
                throw new InvalidDataException("AppHostBase.Instance has already been set");
            }

            Instance = this;

            EndpointHost.Config.DebugMode = GetType().Assembly.IsDebugBuild();
            var serviceManager = EndpointHost.Config.ServiceManager;

            if (serviceManager != null)
            {
                serviceManager.Init();
                Configure(EndpointHost.Config.ServiceManager.Container);
            }
            else
            {
                Configure(null);
            }

            EndpointHost.AfterInit();

            if (serviceManager != null)
            {
                //Required for adhoc services added in Configure()
                EndpointHost.SetOperationTypes(
                    serviceManager.ServiceOperations,
                    serviceManager.AllServiceOperations
                    );
            }
        }
Exemple #2
0
        public void Init()
        {
            if (Instance != null)
            {
                throw new InvalidDataException("HttpListenerBase.Instance has already been set");
            }

            Instance = this;

            if (this.serviceManager != null)
            {
                serviceManager.Init();
                Configure(serviceManager.Container);
            }
            else
            {
                Configure(null);
            }

            EndpointHost.SetOperationTypes(
                EndpointHost.Config.ServiceController.OperationTypes,
                EndpointHost.Config.ServiceController.AllOperationTypes
                );

            var elapsed = DateTime.Now - this.startTime;

            log.InfoFormat("Initializing Application took {0}ms", elapsed.TotalMilliseconds);
        }
Exemple #3
0
        public void Init()
        {
            if (Instance != null)
            {
                throw new InvalidDataException("AppHostBase.Instance has already been set");
            }

            Instance = this;

            var serviceManager = EndpointHost.Config.ServiceManager;

            if (serviceManager != null)
            {
                serviceManager.Init();
                Configure(EndpointHost.Config.ServiceManager.Container);

                EndpointHost.SetOperationTypes(
                    serviceManager.ServiceOperations,
                    serviceManager.AllServiceOperations
                    );
            }
            else
            {
                Configure(null);
            }

            EndpointHost.AfterInit();

            var elapsed = DateTime.Now - this.startTime;

            log.InfoFormat("Initializing Application took {0}ms", elapsed.TotalMilliseconds);
        }
Exemple #4
0
        public static void AddPluginsFromAssembly(this IAppHost appHost, params Assembly[] assembliesWithPlugins)
        {
            foreach (Assembly assembly in assembliesWithPlugins)
            {
                var pluginTypes =
                    from t in assembly.GetExportedTypes()
                    where t.GetInterfaces().Any(x => x == typeof(IPlugin))
                    select t;

                foreach (var pluginType in pluginTypes)
                {
                    try
                    {
                        var plugin = ReflectionUtils.CreateInstance(pluginType) as IPlugin;
                        if (plugin != null)
                        {
                            EndpointHost.AddPlugin(plugin);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error("Error adding new Plugin " + pluginType.Name, ex);
                    }
                }
            }
        }
        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            var responseContentType = EndpointHost.Config.DefaultContentType;

            try
            {
                var restPath = GetRestPath(httpReq.HttpMethod, httpReq.PathInfo);
                if (restPath == null)
                {
                    throw new NotSupportedException("No RestPath found for: " + httpReq.HttpMethod + " " + httpReq.PathInfo);
                }

                operationName = restPath.RequestType.Name;

                var callback = httpReq.QueryString["callback"];
                var doJsonp  = EndpointHost.Config.AllowJsonpRequests &&
                               !string.IsNullOrEmpty(callback);

                responseContentType = httpReq.ResponseContentType;
                EndpointHost.Config.AssertContentType(responseContentType);

                var request = GetRequest(httpReq, restPath);
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request))
                {
                    return;
                }

                var response = GetResponse(httpReq, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response))
                {
                    return;
                }

                if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
                {
                    JsvSyncReplyHandler.WriteDebugResponse(httpRes, response);
                    return;
                }

                if (doJsonp)
                {
                    httpRes.Write(callback + "(");
                }

                httpRes.WriteToResponse(httpReq, response);

                if (doJsonp)
                {
                    httpRes.Write(")\n");
                }
            }
            catch (Exception ex)
            {
                var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
                Log.Error(errorMessage, ex);

                var attrEndpointType = ContentType.GetEndpointAttributes(responseContentType);
                httpRes.WriteErrorToResponse(attrEndpointType, operationName, errorMessage, ex);
            }
        }
        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes))
                {
                    return;
                }

                var restPath = GetRestPath(httpReq.HttpMethod, httpReq.PathInfo);
                if (restPath == null)
                {
                    throw new NotSupportedException("No RestPath found for: " + httpReq.HttpMethod + " " + httpReq.PathInfo);
                }

                operationName = restPath.RequestType.Name;

                var callback = httpReq.GetJsonpCallback();
                var doJsonp  = EndpointHost.Config.AllowJsonpRequests &&
                               !string.IsNullOrEmpty(callback);

                var responseContentType = httpReq.ResponseContentType;
                EndpointHost.Config.AssertContentType(responseContentType);

                var request = GetRequest(httpReq, restPath);
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request))
                {
                    return;
                }

                var response = GetResponse(httpReq, httpRes, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response))
                {
                    return;
                }

                if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
                {
                    JsvSyncReplyHandler.WriteDebugResponse(httpRes, response);
                    return;
                }

                if (doJsonp && !(response is CompressedResult))
                {
                    httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                }
                else
                {
                    httpRes.WriteToResponse(httpReq, response);
                }
            }
            catch (Exception ex)
            {
                if (!EndpointHost.Config.WriteErrorsToResponse)
                {
                    throw;
                }
                HandleException(httpReq, httpRes, operationName, ex);
            }
        }
        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                EndpointHost.Config.AssertFeatures(format);

                if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes))
                {
                    return;
                }

                httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
                var callback = httpReq.QueryString["callback"];
                var doJsonp  = EndpointHost.Config.AllowJsonpRequests &&
                               !string.IsNullOrEmpty(callback);

                var request = CreateRequest(httpReq, operationName);
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request))
                {
                    return;
                }

                var response = GetResponse(httpReq, httpRes, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response))
                {
                    return;
                }

                if (doJsonp && !(response is CompressedResult))
                {
                    httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                }
                else
                {
                    httpRes.WriteToResponse(httpReq, response);
                }
            }
            catch (Exception ex)
            {
                if (!EndpointHost.Config.WriteErrorsToResponse)
                {
                    throw;
                }
                HandleException(httpReq, httpRes, operationName, ex);
            }
        }
Exemple #8
0
        //public StreamSerializerDelegate GetStreamSerializer(string contentType)
        //{
        //    return GetContentFilters().GetStreamSerializer(contentType);
        //}

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                EndpointHost.Config.AssertFeatures(usesFeature);

                httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
                var callback = httpReq.QueryString["callback"];
                var doJsonp  = EndpointHost.Config.AllowJsonpRequests &&
                               !string.IsNullOrEmpty(callback);

                var request = CreateRequest(httpReq, operationName);
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request))
                {
                    return;
                }

                var response = GetResponse(httpReq, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response))
                {
                    return;
                }
                if (doJsonp)
                {
                    httpRes.Write(callback + "(");
                }

                httpRes.WriteToResponse(httpReq, response);

                if (doJsonp)
                {
                    httpRes.Write(")");
                }
            }
            catch (Exception ex)
            {
                var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
                Log.Error(errorMessage, ex);

                httpRes.WriteErrorToResponse(HandlerContentType, operationName, errorMessage, ex);
            }
        }
Exemple #9
0
        public void Init()
        {
            if (Instance != null)
            {
                throw new InvalidDataException("AppHostBase.Instance has already been set");
            }

            Instance = this;

            var serviceManager = EndpointHost.Config.ServiceManager;

            if (serviceManager != null)
            {
                serviceManager.Init();
                Configure(EndpointHost.Config.ServiceManager.Container);
            }
            else
            {
                Configure(null);
            }

            EndpointHost.AfterInit();
        }
Exemple #10
0
 protected AppHostBase(string serviceName, params Assembly[] assembliesWithServices)
 {
     EndpointHost.ConfigureHost(this, serviceName, CreateServiceManager(assembliesWithServices));
 }