private static void UpdateFromFolder(string upgradPackae, BundleData item) { FileUtility.CopyFilesDirs(upgradPackae, item.Path, true); string symbolicName = item.SymbolicName; Version version = item.Version; IBundleInstallerService firstOrDefaultService = BundleRuntime.Instance.GetFirstOrDefaultService <IBundleInstallerService>(); firstOrDefaultService.BundleDatas.Remove(item.SymbolicName); BundleData data = firstOrDefaultService.CreateBundleData(item.Path); string text2 = data.SymbolicName; Version version2 = data.Version; FileLogUtility.Inform($"Upgrade the bundle '{item.SymbolicName}' from version '{version}' to '{version2}'."); }
public static void Update(ICollection <BundleData> bundleDatas, string updateFolder) { if (Directory.Exists(updateFolder) && (Directory.GetDirectories(updateFolder).Length != 0)) { foreach (BundleData data in bundleDatas) { Tuple <Version, string> tuple = FindUpgradeVersion(Path.Combine(updateFolder, data.SymbolicName), data.Version); if (tuple != null) { FileLogUtility.Inform($"Find a new version of bundle '{data.SymbolicName}', the new version is '{tuple.Item1}', while the old version is '{data.Version}'."); UpdateFromFolder(tuple.Item2, data); } } } }
/// <summary> /// Restart the website if the bundle runtime state is still in specified state. /// </summary> /// <param name="expectedState">Specified state.</param> private void StateTimeoutToRestart(BundleRuntimeState expectedState) { _appStartingTimeout = new Timer(delegate(object state) { _appStartingTimeout.Dispose(); if (BundleRuntime.State != (BundleRuntimeState)state) { FileLogUtility.Warn(string.Format("Fail to start/stop framework. BundleRuntime state is not in '{0}'.", state)); RestartAppDomain(); return; } FileLogUtility.Inform(string.Format("Dectect that the framework is in '{0}' state.", state)); }, expectedState, 90000, -1); }
protected void CacheLoadedType(string className, Type type) { if (BundleRuntime.Instance.EnableBundleClassLoaderCache) { using (ReaderWriterLockHelper.CreateWriterLock(_cacheLock)) { if (!_classAssemblyNameCache.Contains(className)) { if (_classAssemblyNameCache.Count >= BundleRuntime.Instance.BundleClassLoaderCacheSize) { FileLogUtility.Inform(string.Format(Messages.RemoveCachedTypeForSize, Bundle.SymbolicName, Bundle.Version, BundleRuntime.Instance.BundleClassLoaderCacheSize)); _classAssemblyNameCache.RemoveAt(0); } _classAssemblyNameCache.Add(className, type); } } } }
private Type GetControllerType(string pluginSymbolicName, string controllerName) { var symbolicName = pluginSymbolicName; if (symbolicName != null) { var controllerType = ControllerTypeCache.GetControllerType(symbolicName, controllerName); if (controllerType != null) { FileLogUtility.Inform(string.Format("Loaded controller '{0}' from bundle '{1}' by using cache.", controllerName, symbolicName)); return(controllerType); } var controllerTypeName = controllerName + "Controller"; var runtimeService = BundleRuntime.Instance.GetFirstOrDefaultService <IRuntimeService>(); var assemblies = runtimeService.LoadBundleAssembly(symbolicName); foreach (var assembly in assemblies) { foreach (var type in assembly.GetTypes()) { if (type.Name.Contains(controllerTypeName) && typeof(IController).IsAssignableFrom(type)) { controllerType = type; ControllerTypeCache.AddControllerType(symbolicName, controllerName, controllerType); FileLogUtility.Inform( string.Format("Loaded controller '{0}' from bundle '{1}' and then added to cache.", controllerName, symbolicName)); return(controllerType); } } } FileLogUtility.Error(string.Format("Failed to load controller '{0}' from bundle '{1}'.", controllerName, symbolicName)); } FileLogUtility.Error(string.Format( "Failed to load controller '{0}' since the plugin name is not specified.", controllerName)); return(null); }
private string souideaKey = WebConfigurationManager.AppSettings["WeixinAgentWeiweihiKey"]; //SouideaKey专门用于对接www.souidea.com平台,获取方式见:http://www.souidea.com/ApiDocuments/Item/25#51 #endif public CustomMessageHandler(Stream inputStream, string token, string appid, string secrect, int maxRecordCount = 0) : base(inputStream, maxRecordCount) { //这里设置仅用于测试,实际开发可以在外部更全局的地方设置, //比如MessageHandler<MessageContext>.GlobalWeixinContext.ExpireMinutes = 3。 WeixinContext.ExpireMinutes = 3; try { if (!AccessTokenContainer.CheckRegistered(appid)) { AccessTokenContainer.Register(appid, secrect); } _tokenRes = AccessTokenContainer.GetTokenResult(appid); //CommonAPIs.CommonApi.GetToken(appId, appSecret); } catch { FileLogUtility.Inform(string.Format("获取到 token 失败, appid: {0},secret: {1}。", appid, secrect)); } }
/// <summary> /// Restart the website if the bundle runtime state is still in specified state. /// </summary> /// <param name="expectedState">Specified state.</param> private void StateTimeoutToRestart(BundleRuntimeState expectedState) { _appStartingTimeout = new Timer( state => { _appStartingTimeout.Dispose(); if (BundleRuntime.State != (BundleRuntimeState)state) { // If website is not started within 90 seconds, it will be restarted immediately. FileLogUtility.Warn(string.Format("Fail to start/stop framework. BundleRuntime state is not in '{0}'.", state)); RestartAppDomain(); } else { // If website is not started within 90 seconds, it will be restarted immediately. FileLogUtility.Inform(string.Format("Dectect that the framework is in '{0}' state.", state)); } }, expectedState, StateTimeOut * 1000, -1); }
protected override Type GetControllerType(RequestContext requestContext, string controllerName) { const string namespacesKey = "Namespaces"; string bundleSymbolicName = requestContext.GetBundleSymbolicName(); if (bundleSymbolicName == null) { requestContext = HandleNonPluginRequestContext(requestContext, ref controllerName); } object namespaces; if (!requestContext.RouteData.DataTokens.TryGetValue(namespacesKey, out namespaces)) { namespaces = bundleSymbolicName == null ? DefaultConfig.GetHostingNamespaces() : DefaultConfig.GetBundleNamespaces(bundleSymbolicName); requestContext.RouteData.DataTokens[namespacesKey] = namespaces; } string cacheKey = bundleSymbolicName ?? DefaultConfig.HostingName; //从缓存获取控制器类型 Type controllerType = ControllerTypeCache.GetControllerType(cacheKey, controllerName); if (controllerType != null) { FileLogUtility.Inform(string.Format("Loaded controller '{0}' from bundle '{1}' by using cache.", controllerName, bundleSymbolicName)); return(controllerType); } if (bundleSymbolicName != null) { string value = controllerName + "Controller"; IRuntimeService firstOrDefaultService = BundleRuntime.Instance.GetFirstOrDefaultService <IRuntimeService>(); List <Assembly> assemblies = firstOrDefaultService.LoadBundleAssembly(bundleSymbolicName); foreach (Assembly assembly in assemblies) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (!type.Name.ToLower().Contains(value.ToLower()) || !typeof(IController).IsAssignableFrom(type) || type.IsAbstract) { continue; } controllerType = type; ControllerTypeCache.AddControllerType(cacheKey, controllerName, controllerType); FileLogUtility.Inform(string.Format("Loaded controller '{0}' from bundle '{1}' and then added to cache.", controllerName, bundleSymbolicName)); return(controllerType); } } FileLogUtility.Error(string.Format("Failed to load controller '{0}' from bundle '{1}'.", controllerName, bundleSymbolicName)); } try { controllerType = base.GetControllerType(requestContext, controllerName); if (controllerType != null) { ControllerTypeCache.AddControllerType(cacheKey, controllerName, controllerType); } return(controllerType); } catch (Exception ex) { FileLogUtility.Error(string.Format("Failed to load controller '{0}'", controllerName)); FileLogUtility.Error(ex); } return(null); }
private void LogUnresolvedNode(Interface2 unresolvedNode, Interface2 dependentNode) { FileLogUtility.Inform(string.Format(Messages.BundleMarkedUnresolved, new object[] { unresolvedNode.SymbolicName, unresolvedNode.Version, dependentNode.SymbolicName, dependentNode.Version })); }
private void LogUnresolvedNode(Interface2 unresolvedNode) { FileLogUtility.Inform(string.Format(Messages.BundleNotResolved, unresolvedNode.SymbolicName, unresolvedNode.Version)); }
private void LogUnresolvedNode(IFragmentBundleMetadataNode unresolvedNode) { FileLogUtility.Inform(string.Format(Messages.FragmentDetachedForHostNotResolved, new object[] { unresolvedNode.SymbolicName, unresolvedNode.Version, unresolvedNode.HostNode.SymbolicName, unresolvedNode.HostNode.Version })); }