public bool CheckIfPluginExistAndHasHigherVersion(Plugin newPlugin) { return(Plugins.Exists(x => x.Name == newPlugin.Name && x.AssemblyVersion > newPlugin.AssemblyVersion)); }
//After configure called public static void AfterInit() { StartedAt = 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.Html & Config.EnableFeatures) != Feature.Html) { Plugins.RemoveAll(x => x is HtmlFormat); } 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.HystrixInfo & Config.EnableFeatures) != Feature.HystrixInfo) { Plugins.RemoveAll(x => x is HystrixInfoFeature); } 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 (ExceptionHandler == null) { // This is where all framework exceptions are centrally handled ExceptionHandler = (httpReq, httpRes, ex) => { //httpRes.WriteToResponse always calls .Close in its finally statement so //if there is a problem writing to response, by now it will be closed if (!httpRes.IsClosed) { httpRes.WriteErrorToResponse(httpReq, httpReq.ResponseContentType, ex); } }; } if (!Plugins.Exists(p => p is DynamicPolicyPlugin)) { Plugins.Add(new DynamicPolicyPlugin()); } if (Config.UseConsulDiscovery && !Plugins.Exists(p => p is ConsulFeature)) { Plugins.Add(new ConsulFeature()); } if (!Plugins.Exists(p => p is SwaggerServicePlugin)) { Plugins.Add(new SwaggerServicePlugin()); } //这里先预留 留着获取动态配置用的 if (AntFxConfigWebServiceUtils.Enabled) { HystrixCommandHelper.SyncGlobalSetting(); AntFxConfigWebServiceUtils.SubscribeFxWebServiceConfigUpdateEvent(HystrixCommandHelper.SyncGlobalSetting); } ConfigurePlugins(); AppHost.LoadPlugin(Plugins.ToArray()); pluginsLoaded = true; AfterPluginsLoaded(); foreach (KeyValuePair <string, string> item in ContentTypeFilter.ContentTypeFormats) { SupportedFormats[item.Key] = item.Value; } if (AppHost.AfterInitCallbacks != null && AppHost.AfterInitCallbacks.Count > 0) { AppHost.AfterInitCallbacks.ForEach(t => t.Invoke(AppHost)); } ReadyAt = DateTime.UtcNow; }