Пример #1
0
        //After configure called
        public virtual void OnAfterInit()
        {
            AfterInitAt = DateTime.UtcNow;

            if (config.EnableFeatures != Feature.All)
            {
                if ((Feature.Xml & config.EnableFeatures) != Feature.Xml)
                {
                    config.IgnoreFormatsInMetadata.Add("xml");
                    Config.PreferredContentTypes.Remove(MimeTypes.Xml);
                }
                if ((Feature.Json & config.EnableFeatures) != Feature.Json)
                {
                    config.IgnoreFormatsInMetadata.Add("json");
                    Config.PreferredContentTypes.Remove(MimeTypes.Json);
                }
                if ((Feature.Jsv & config.EnableFeatures) != Feature.Jsv)
                {
                    config.IgnoreFormatsInMetadata.Add("jsv");
                    Config.PreferredContentTypes.Remove(MimeTypes.Jsv);
                }
                if ((Feature.Csv & config.EnableFeatures) != Feature.Csv)
                {
                    config.IgnoreFormatsInMetadata.Add("csv");
                    Config.PreferredContentTypes.Remove(MimeTypes.Csv);
                }
                if ((Feature.Html & config.EnableFeatures) != Feature.Html)
                {
                    config.IgnoreFormatsInMetadata.Add("html");
                    Config.PreferredContentTypes.Remove(MimeTypes.Html);
                }
                if ((Feature.Soap11 & config.EnableFeatures) != Feature.Soap11)
                {
                    config.IgnoreFormatsInMetadata.Add("soap11");
                }
                if ((Feature.Soap12 & config.EnableFeatures) != Feature.Soap12)
                {
                    config.IgnoreFormatsInMetadata.Add("soap12");
                }
            }

            if ((Feature.Html & config.EnableFeatures) != Feature.Html)
            {
                Plugins.RemoveAll(x => x is HtmlFormat);
            }

            if ((Feature.Csv & config.EnableFeatures) != Feature.Csv)
            {
                Plugins.RemoveAll(x => x is CsvFormat);
            }

            if ((Feature.Markdown & config.EnableFeatures) != Feature.Markdown)
            {
                Plugins.RemoveAll(x => x is MarkdownFormat);
            }

            if ((Feature.PredefinedRoutes & config.EnableFeatures) != Feature.PredefinedRoutes)
            {
                Plugins.RemoveAll(x => x is PredefinedRoutesFeature);
            }

            if ((Feature.Metadata & config.EnableFeatures) != Feature.Metadata)
            {
                Plugins.RemoveAll(x => x is MetadataFeature);
                Plugins.RemoveAll(x => x is NativeTypesFeature);
            }

            if ((Feature.RequestInfo & config.EnableFeatures) != Feature.RequestInfo)
            {
                Plugins.RemoveAll(x => x is RequestInfoFeature);
            }

            if ((Feature.Razor & config.EnableFeatures) != Feature.Razor)
            {
                Plugins.RemoveAll(x => x is IRazorPlugin);    //external
            }
            if ((Feature.ProtoBuf & config.EnableFeatures) != Feature.ProtoBuf)
            {
                Plugins.RemoveAll(x => x is IProtoBufPlugin); //external
            }
            if ((Feature.MsgPack & config.EnableFeatures) != Feature.MsgPack)
            {
                Plugins.RemoveAll(x => x is IMsgPackPlugin);  //external
            }
            if (config.HandlerFactoryPath != null)
            {
                config.HandlerFactoryPath = config.HandlerFactoryPath.TrimStart('/');
            }

            var specifiedContentType = config.DefaultContentType; //Before plugins loaded

            var plugins = Plugins.ToArray();

            delayLoadPlugin = true;
            LoadPluginsInternal(plugins);

            AfterPluginsLoaded(specifiedContentType);

            if (!TestMode && Container.Exists <IAuthSession>())
            {
                throw new Exception(ErrorMessages.ShouldNotRegisterAuthSession);
            }

            if (!Container.Exists <IAppSettings>())
            {
                Container.Register(AppSettings);
            }

            if (!Container.Exists <ICacheClient>())
            {
                if (Container.Exists <IRedisClientsManager>())
                {
                    Container.Register(c => c.Resolve <IRedisClientsManager>().GetCacheClient());
                }
                else
                {
                    Container.Register <ICacheClient>(new MemoryCacheClient());
                }
            }

            if (Container.Exists <IMessageService>() &&
                !Container.Exists <IMessageFactory>())
            {
                Container.Register(c => c.Resolve <IMessageService>().MessageFactory);
            }

            if (Container.Exists <IUserAuthRepository>() &&
                !Container.Exists <IAuthRepository>())
            {
                Container.Register <IAuthRepository>(c => c.Resolve <IUserAuthRepository>());
            }

            foreach (var callback in AfterInitCallbacks)
            {
                try
                {
                    callback(this);
                }
                catch (Exception ex)
                {
                    OnStartupException(ex);
                }
            }

            ReadyAt = DateTime.UtcNow;
        }
Пример #2
0
        //After configure called
        public virtual void OnAfterInit()
        {
            AfterInitAt = DateTime.UtcNow;

            if (config.EnableFeatures != Feature.All)
            {
                if ((Feature.Xml & config.EnableFeatures) != Feature.Xml)
                {
                    config.IgnoreFormatsInMetadata.Add("xml");
                    Config.PreferredContentTypes.Remove(MimeTypes.Xml);
                }
                if ((Feature.Json & config.EnableFeatures) != Feature.Json)
                {
                    config.IgnoreFormatsInMetadata.Add("json");
                    Config.PreferredContentTypes.Remove(MimeTypes.Json);
                }
                if ((Feature.Jsv & config.EnableFeatures) != Feature.Jsv)
                {
                    config.IgnoreFormatsInMetadata.Add("jsv");
                    Config.PreferredContentTypes.Remove(MimeTypes.Jsv);
                }
                if ((Feature.Csv & config.EnableFeatures) != Feature.Csv)
                {
                    config.IgnoreFormatsInMetadata.Add("csv");
                    Config.PreferredContentTypes.Remove(MimeTypes.Csv);
                }
                if ((Feature.Html & config.EnableFeatures) != Feature.Html)
                {
                    config.IgnoreFormatsInMetadata.Add("html");
                    Config.PreferredContentTypes.Remove(MimeTypes.Html);
                }
                if ((Feature.Soap11 & config.EnableFeatures) != Feature.Soap11)
                {
                    config.IgnoreFormatsInMetadata.Add("soap11");
                }
                if ((Feature.Soap12 & config.EnableFeatures) != Feature.Soap12)
                {
                    config.IgnoreFormatsInMetadata.Add("soap12");
                }
            }

            if ((Feature.Html & config.EnableFeatures) != Feature.Html)
            {
                Plugins.RemoveAll(x => x is HtmlFormat);
            }

            if ((Feature.Csv & config.EnableFeatures) != Feature.Csv)
            {
                Plugins.RemoveAll(x => x is CsvFormat);
            }

            if ((Feature.Markdown & config.EnableFeatures) != Feature.Markdown)
            {
                Plugins.RemoveAll(x => x is MarkdownFormat);
            }

            if ((Feature.PredefinedRoutes & config.EnableFeatures) != Feature.PredefinedRoutes)
            {
                Plugins.RemoveAll(x => x is PredefinedRoutesFeature);
            }

            if ((Feature.Metadata & config.EnableFeatures) != Feature.Metadata)
            {
                Plugins.RemoveAll(x => x is MetadataFeature);
                Plugins.RemoveAll(x => x is NativeTypesFeature);
            }

            if ((Feature.RequestInfo & config.EnableFeatures) != Feature.RequestInfo)
            {
                Plugins.RemoveAll(x => x is RequestInfoFeature);
            }

            if ((Feature.Razor & config.EnableFeatures) != Feature.Razor)
            {
                Plugins.RemoveAll(x => x is IRazorPlugin);    //external
            }
            if ((Feature.ProtoBuf & config.EnableFeatures) != Feature.ProtoBuf)
            {
                Plugins.RemoveAll(x => x is IProtoBufPlugin); //external
            }
            if ((Feature.MsgPack & config.EnableFeatures) != Feature.MsgPack)
            {
                Plugins.RemoveAll(x => x is IMsgPackPlugin);  //external
            }
            if (config.HandlerFactoryPath != null)
            {
                config.HandlerFactoryPath = config.HandlerFactoryPath.TrimStart('/');
            }

            if (config.UseCamelCase)
            {
                JsConfig.EmitCamelCaseNames = true;
            }

            if (config.EnableOptimizations)
            {
                MemoryStreamFactory.UseRecyclableMemoryStream = true;
            }

            var specifiedContentType = config.DefaultContentType; //Before plugins loaded

            var plugins = Plugins.ToArray();

            delayLoadPlugin = true;
            LoadPluginsInternal(plugins);

            AfterPluginsLoaded(specifiedContentType);

            if (!TestMode && Container.Exists <IAuthSession>())
            {
                throw new Exception(ErrorMessages.ShouldNotRegisterAuthSession);
            }

            if (!Container.Exists <IAppSettings>())
            {
                Container.Register(AppSettings);
            }

            if (!Container.Exists <ICacheClient>())
            {
                if (Container.Exists <IRedisClientsManager>())
                {
                    Container.Register(c => c.Resolve <IRedisClientsManager>().GetCacheClient());
                }
                else
                {
                    Container.Register <ICacheClient>(ServiceExtensions.DefaultCache);
                }
            }

            if (!Container.Exists <MemoryCacheClient>())
            {
                Container.Register(ServiceExtensions.DefaultCache);
            }

            if (Container.Exists <IMessageService>() &&
                !Container.Exists <IMessageFactory>())
            {
                Container.Register(c => c.Resolve <IMessageService>().MessageFactory);
            }

            if (Container.Exists <IUserAuthRepository>() &&
                !Container.Exists <IAuthRepository>())
            {
                Container.Register <IAuthRepository>(c => c.Resolve <IUserAuthRepository>());
            }

            if (config.LogUnobservedTaskExceptions)
            {
                System.Threading.Tasks.TaskScheduler.UnobservedTaskException += (sender, args) =>
                {
                    args.SetObserved();
                    args.Exception.Handle(ex =>
                    {
                        lock (AsyncErrors)
                        {
                            AsyncErrors.Add(DtoUtils.CreateErrorResponse(null, ex).GetResponseStatus());
                            return(true);
                        }
                    });
                };
            }

            foreach (var callback in AfterInitCallbacks)
            {
                callback(this);
            }

            ReadyAt = DateTime.UtcNow;
        }
Пример #3
0
        //After configure called
        public void OnAfterInit()
        {
            AfterInitAt = DateTime.UtcNow;

            if (config.EnableFeatures != Feature.All)
            {
                if ((Feature.Xml & config.EnableFeatures) != Feature.Xml)
                {
                    config.IgnoreFormatsInMetadata.Add("xml");
                }
                if ((Feature.Json & config.EnableFeatures) != Feature.Json)
                {
                    config.IgnoreFormatsInMetadata.Add("json");
                }
                if ((Feature.Jsv & config.EnableFeatures) != Feature.Jsv)
                {
                    config.IgnoreFormatsInMetadata.Add("jsv");
                }
                if ((Feature.Csv & config.EnableFeatures) != Feature.Csv)
                {
                    config.IgnoreFormatsInMetadata.Add("csv");
                }
                if ((Feature.Html & config.EnableFeatures) != Feature.Html)
                {
                    config.IgnoreFormatsInMetadata.Add("html");
                }
                if ((Feature.Soap11 & config.EnableFeatures) != Feature.Soap11)
                {
                    config.IgnoreFormatsInMetadata.Add("soap11");
                }
                if ((Feature.Soap12 & config.EnableFeatures) != Feature.Soap12)
                {
                    config.IgnoreFormatsInMetadata.Add("soap12");
                }
            }

            if ((Feature.Html & config.EnableFeatures) != Feature.Html)
            {
                Plugins.RemoveAll(x => x is HtmlFormat);
            }

            if ((Feature.Csv & config.EnableFeatures) != Feature.Csv)
            {
                Plugins.RemoveAll(x => x is CsvFormat);
            }

            if ((Feature.Markdown & config.EnableFeatures) != Feature.Markdown)
            {
                Plugins.RemoveAll(x => x is MarkdownFormat);
            }

            if ((Feature.PredefinedRoutes & config.EnableFeatures) != Feature.PredefinedRoutes)
            {
                Plugins.RemoveAll(x => x is PredefinedRoutesFeature);
            }

            if ((Feature.Metadata & config.EnableFeatures) != Feature.Metadata)
            {
                Plugins.RemoveAll(x => x is MetadataFeature);
            }

            if ((Feature.RequestInfo & config.EnableFeatures) != Feature.RequestInfo)
            {
                Plugins.RemoveAll(x => x is RequestInfoFeature);
            }

            if ((Feature.Razor & config.EnableFeatures) != Feature.Razor)
            {
                Plugins.RemoveAll(x => x is IRazorPlugin);    //external
            }
            if ((Feature.ProtoBuf & config.EnableFeatures) != Feature.ProtoBuf)
            {
                Plugins.RemoveAll(x => x is IProtoBufPlugin); //external
            }
            if ((Feature.MsgPack & config.EnableFeatures) != Feature.MsgPack)
            {
                Plugins.RemoveAll(x => x is IMsgPackPlugin);  //external
            }
            if (config.ServiceStackHandlerFactoryPath != null)
            {
                config.ServiceStackHandlerFactoryPath = config.ServiceStackHandlerFactoryPath.TrimStart('/');
            }

            var specifiedContentType = config.DefaultContentType; //Before plugins loaded

            ConfigurePlugins();

            LoadPlugin(Plugins.ToArray());
            pluginsLoaded = true;

            AfterPluginsLoaded(specifiedContentType);

            var registeredCacheClient = TryResolve <ICacheClient>();

            using (registeredCacheClient)
            {
                if (registeredCacheClient == null)
                {
                    Container.Register <ICacheClient>(new MemoryCacheClient());
                }
            }

            var registeredMqService = TryResolve <IMessageService>();
            var registeredMqFactory = TryResolve <IMessageFactory>();

            if (registeredMqService != null && registeredMqFactory == null)
            {
                Container.Register(c => registeredMqService.MessageFactory);
            }

            ReadyAt = DateTime.UtcNow;
        }