コード例 #1
0
ファイル: ServiceStackHost.cs プロジェクト: hablan/Mainline
        protected ServiceStackHost(string serviceName, params Assembly[] assembliesWithServices)
        {
            this.StartedAt = DateTime.UtcNow;

            ServiceName = serviceName;
            AppSettings = new AppSettings();
            Container   = new Container {
                DefaultOwner = Owner.External
            };
            ServiceController = CreateServiceController(assembliesWithServices);

            ContentTypes                      = Host.ContentTypes.Instance;
            RestPaths                         = new List <RestPath>();
            Routes                            = new ServiceRoutes(this);
            Metadata                          = new ServiceMetadata(RestPaths);
            PreRequestFilters                 = new List <Action <IRequest, IResponse> >();
            RequestConverters                 = new List <Func <IRequest, object, object> >();
            ResponseConverters                = new List <Func <IRequest, object, object> >();
            GlobalRequestFilters              = new List <Action <IRequest, IResponse, object> >();
            GlobalTypedRequestFilters         = new Dictionary <Type, ITypedFilter>();
            GlobalResponseFilters             = new List <Action <IRequest, IResponse, object> >();
            GlobalTypedResponseFilters        = new Dictionary <Type, ITypedFilter>();
            GlobalMessageRequestFilters       = new List <Action <IRequest, IResponse, object> >();
            GlobalTypedMessageRequestFilters  = new Dictionary <Type, ITypedFilter>();
            GlobalMessageResponseFilters      = new List <Action <IRequest, IResponse, object> >();
            GlobalTypedMessageResponseFilters = new Dictionary <Type, ITypedFilter>();
            ViewEngines                       = new List <IViewEngine>();
            ServiceExceptionHandlers          = new List <HandleServiceExceptionDelegate>();
            UncaughtExceptionHandlers         = new List <HandleUncaughtExceptionDelegate>();
            AfterInitCallbacks                = new List <Action <IAppHost> >();
            OnDisposeCallbacks                = new List <Action <IAppHost> >();
            OnEndRequestCallbacks             = new List <Action <IRequest> >();
            RawHttpHandlers                   = new List <Func <IHttpRequest, IHttpHandler> > {
                HttpHandlerFactory.ReturnRequestInfo,
                MiniProfilerHandler.MatchesRequest,
            };
            CatchAllHandlers        = new List <HttpHandlerResolverDelegate>();
            CustomErrorHttpHandlers = new Dictionary <HttpStatusCode, IServiceStackHandler> {
                { HttpStatusCode.Forbidden, new ForbiddenHttpHandler() },
                { HttpStatusCode.NotFound, new NotFoundHttpHandler() },
            };
            StartUpErrors = new List <ResponseStatus>();
            PluginsLoaded = new List <string>();
            Plugins       = new List <IPlugin> {
                new HtmlFormat(),
                new CsvFormat(),
                new MarkdownFormat(),
                new PredefinedRoutesFeature(),
                new MetadataFeature(),
                new NativeTypesFeature(),
            };
            ExcludeAutoRegisteringServiceTypes = new HashSet <Type> {
                typeof(AuthenticateService),
                typeof(RegisterService),
                typeof(AssignRolesService),
                typeof(UnAssignRolesService),
                typeof(NativeTypesService),
                typeof(PostmanService),
            };

            JsConfig.InitStatics();
        }
コード例 #2
0
 /// <summary>
 /// Register Type to Type AutoMapping converter
 /// </summary>
 public static void RegisterConverter <From, To>(Func <From, To> converter)
 {
     JsConfig.InitStatics();
     AutoMappingUtils.converters[Tuple.Create(typeof(From), typeof(To))] = x => converter((From)x);
 }
コード例 #3
0
        public static void RegisterLicense(string licenseKeyText)
        {
            JsConfig.InitStatics();

            if (__activatedLicense != null) //Skip multiple license registrations. Use RemoveLicense() to reset.
            {
                return;
            }

            string subId = null;
            var    hold  = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            try
            {
                var parts = licenseKeyText.SplitOnFirst('-');
                subId = parts[0];

                if (int.TryParse(subId, out var subIdInt) && revokedSubs.Contains(subIdInt))
                {
                    throw new LicenseException("This subscription has been revoked. " + ContactDetails);
                }

                var key = VerifyLicenseKeyText(licenseKeyText);
                ValidateLicenseKey(key);
            }
            catch (PlatformNotSupportedException)
            {
                // Allow usage in environments like dotnet script
                __activatedLicense = new __ActivatedLicense(new LicenseKey {
                    Type = LicenseType.Indie
                });
            }
            catch (Exception ex)
            {
                //bubble unrelated project Exceptions
                if (ex is FileNotFoundException || ex is FileLoadException || ex is BadImageFormatException)
                {
                    throw;
                }

                if (ex is LicenseException)
                {
                    throw;
                }

                var msg = "This license is invalid." + ContactDetails;
                if (!string.IsNullOrEmpty(subId))
                {
                    msg += $" The id for this license is '{subId}'";
                }

                lock (typeof(LicenseUtils))
                {
                    try
                    {
                        var key = PclExport.Instance.VerifyLicenseKeyTextFallback(licenseKeyText);
                        ValidateLicenseKey(key);
                    }
                    catch (Exception exFallback)
                    {
                        if (exFallback is FileNotFoundException || exFallback is FileLoadException || exFallback is BadImageFormatException)
                        {
                            throw;
                        }

                        throw new LicenseException(msg, exFallback).Trace();
                    }
                }

                throw new LicenseException(msg, ex).Trace();
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = hold;
            }
        }
コード例 #4
0
        protected ServiceStackHost(string serviceName, params Assembly[] assembliesWithServices)
        {
            this.StartedAt = DateTime.UtcNow;

            ServiceName = serviceName;
            AppSettings = new AppSettings();
            Container   = new Container {
                DefaultOwner = Owner.External
            };
            ServiceAssemblies = assembliesWithServices.ToList();

            ContentTypes                      = new ContentTypes();
            RestPaths                         = new List <RestPath>();
            Routes                            = new ServiceRoutes(this);
            Metadata                          = new ServiceMetadata(RestPaths);
            PreRequestFilters                 = new List <Action <IRequest, IResponse> >();
            RequestConverters                 = new List <Func <IRequest, object, Task <object> > >();
            ResponseConverters                = new List <Func <IRequest, object, Task <object> > >();
            GlobalRequestFilters              = new List <Action <IRequest, IResponse, object> >();
            GlobalRequestFiltersAsync         = new List <Func <IRequest, IResponse, object, Task> >();
            GlobalTypedRequestFilters         = new Dictionary <Type, ITypedFilter>();
            GlobalResponseFilters             = new List <Action <IRequest, IResponse, object> >();
            GlobalResponseFiltersAsync        = new List <Func <IRequest, IResponse, object, Task> >();
            GlobalTypedResponseFilters        = new Dictionary <Type, ITypedFilter>();
            GlobalMessageRequestFilters       = new List <Action <IRequest, IResponse, object> >();
            GlobalMessageRequestFiltersAsync  = new List <Func <IRequest, IResponse, object, Task> >();
            GlobalTypedMessageRequestFilters  = new Dictionary <Type, ITypedFilter>();
            GlobalMessageResponseFilters      = new List <Action <IRequest, IResponse, object> >();
            GlobalMessageResponseFiltersAsync = new List <Func <IRequest, IResponse, object, Task> >();
            GlobalTypedMessageResponseFilters = new Dictionary <Type, ITypedFilter>();
            GatewayRequestFilters             = new List <Action <IRequest, object> >();
            GatewayRequestFiltersAsync        = new List <Func <IRequest, object, Task> >();
            GatewayResponseFilters            = new List <Action <IRequest, object> >();
            GatewayResponseFiltersAsync       = new List <Func <IRequest, object, Task> >();
            ViewEngines                       = new List <IViewEngine>();
            ServiceExceptionHandlers          = new List <HandleServiceExceptionDelegate>();
            ServiceExceptionHandlersAsync     = new List <HandleServiceExceptionAsyncDelegate>();
            UncaughtExceptionHandlers         = new List <HandleUncaughtExceptionDelegate>();
            UncaughtExceptionHandlersAsync    = new List <HandleUncaughtExceptionAsyncDelegate>();
            BeforeConfigure                   = new List <Action <ServiceStackHost> >();
            AfterConfigure                    = new List <Action <ServiceStackHost> >();
            AfterInitCallbacks                = new List <Action <IAppHost> >();
            OnDisposeCallbacks                = new List <Action <IAppHost> >();
            OnEndRequestCallbacks             = new List <Action <IRequest> >();
            AddVirtualFileSources             = new List <IVirtualPathProvider>();
            RawHttpHandlers                   = new List <Func <IHttpRequest, IHttpHandler> > {
                ReturnRedirectHandler,
                ReturnRequestInfoHandler,
            };
            CatchAllHandlers        = new List <HttpHandlerResolverDelegate>();
            FallbackHandlers        = new List <HttpHandlerResolverDelegate>();
            CustomErrorHttpHandlers = new Dictionary <HttpStatusCode, IServiceStackHandler> {
                { HttpStatusCode.Forbidden, new ForbiddenHttpHandler() },
                { HttpStatusCode.NotFound, new NotFoundHttpHandler() },
            };
            StartUpErrors = new List <ResponseStatus>();
            AsyncErrors   = new List <ResponseStatus>();
            PluginsLoaded = new List <string>();
            Plugins       = new List <IPlugin> {
                new HtmlFormat(),
                new CsvFormat(),
                new PredefinedRoutesFeature(),
                new MetadataFeature(),
                new NativeTypesFeature(),
                new HttpCacheFeature(),
                new RequestInfoFeature(),
                new SpanFormats(),
            };
            ExcludeAutoRegisteringServiceTypes = new HashSet <Type> {
                typeof(AuthenticateService),
                typeof(RegisterService),
                typeof(AssignRolesService),
                typeof(UnAssignRolesService),
                typeof(NativeTypesService),
                typeof(PostmanService),
                typeof(TemplateHotReloadService),
                typeof(HotReloadFilesService),
                typeof(TemplateApiPagesService),
                typeof(TemplateMetadataDebugService),
                typeof(ServerEventsSubscribersService),
                typeof(ServerEventsUnRegisterService),
            };

            JsConfig.InitStatics();
        }
コード例 #5
0
ファイル: QueryStringSerializer.cs プロジェクト: leiwcq/E
 static QueryStringSerializer()
 {
     JsConfig.InitStatics();
     Instance = new JsWriter <JsvTypeSerializer>();
 }
コード例 #6
0
        public static void RegisterLicense(string licenseKeyText)
        {
            JsConfig.InitStatics();

            if (__activatedLicense != null) //Skip multple license registrations. Use RemoveLicense() to reset.
            {
                return;
            }

            string subId = null;

#if !(PCL || NETSTANDARD1_1)
            var hold = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
#endif
            try
            {
                var parts = licenseKeyText.SplitOnFirst('-');
                subId = parts[0];

                int subIdInt;
                if (int.TryParse(subId, out subIdInt) && revokedSubs.Contains(subIdInt))
                {
                    throw new LicenseException("This subscription has been revoked. " + ContactDetails);
                }

                var key = PclExport.Instance.VerifyLicenseKeyText(licenseKeyText);
                ValidateLicenseKey(key);
            }
            catch (Exception ex)
            {
                if (ex is LicenseException)
                {
                    throw;
                }

                var msg = "This license is invalid." + ContactDetails;
                if (!string.IsNullOrEmpty(subId))
                {
                    msg += $" The id for this license is '{subId}'";
                }

                lock (typeof(LicenseUtils))
                {
                    try
                    {
                        var key = PclExport.Instance.VerifyLicenseKeyTextFallback(licenseKeyText);
                        ValidateLicenseKey(key);
                    }
                    catch (Exception exFallback)
                    {
                        throw new LicenseException(msg, exFallback).Trace();
                    }
                }

                throw new LicenseException(msg, ex).Trace();
            }
            finally
            {
#if !(PCL || NETSTANDARD1_1)
                Thread.CurrentThread.CurrentCulture = hold;
#endif
            }
        }
コード例 #7
0
 /// <summary>
 /// Ignore Type to Type Mapping (including collections containing them)
 /// </summary>
 public static void IgnoreMapping(Type fromType, Type toType)
 {
     JsConfig.InitStatics();
     AutoMappingUtils.ignoreMappings[Tuple.Create(fromType, toType)] = true;
 }