public StorageFile(Zongsoft.Services.IServiceProvider serviceProvider) { if(serviceProvider != null) { _storage = serviceProvider.Resolve<Zongsoft.Runtime.Caching.ICache>(); } }
public StorageBucket(Zongsoft.Runtime.Caching.ICache storage) { if(storage == null) throw new ArgumentNullException("storage"); _storage = storage; }
public PluginHttpControllerSelector(Zongsoft.Plugins.PluginContext pluginContext) { if(pluginContext == null) throw new ArgumentNullException("pluginContext"); _pluginContext = pluginContext; }
public FileController(Zongsoft.Services.IServiceProvider serviceProvider) { if(serviceProvider == null) throw new ArgumentNullException("serviceProvider"); _file = serviceProvider.Resolve<IStorageFile>(); _bucket = serviceProvider.Resolve<IStorageBucket>(); }
public CredentialProvider(Zongsoft.Services.IServiceProvider serviceProvider) : base(serviceProvider) { _renewalPeriod = TimeSpan.FromHours(2); _memoryCache = new Runtime.Caching.MemoryCache("Zongsoft.Security.CredentialProvider.MemoryCache"); //挂载内存缓存容器的事件 _memoryCache.Changed += MemoryCache_Changed; }
public virtual void Initialize(Zongsoft.ComponentModel.ApplicationContextBase context) { if(context == null) return; //从当前应用的主配置文件中获取日志器的主配置节 var loggerElement = context.Configuration.GetOptionObject(@"/Diagnostics/Logger") as Configuration.LoggerElement; if(loggerElement == null) return; foreach(Configuration.LoggerHandlerElement handlerElement in loggerElement.Handlers) { var type = Type.GetType(handlerElement.TypeName, true, true); //如果当前处理节配置的日志处理器类型不是一个记录器则抛出异常 if(!typeof(ILogger).IsAssignableFrom(type)) throw new Options.Configuration.OptionConfigurationException(string.Format("The '{0}' type isn't a Logger.", type.FullName)); //获取日志记录器实现类的带参构造函数 var constructor = type.GetConstructor(new Type[] { typeof(Configuration.LoggerHandlerElement) }); ILogger instance; //试图创建日志记录器实例 if(constructor == null) instance = (ILogger)Activator.CreateInstance(type); else instance = (ILogger)Activator.CreateInstance(type, handlerElement); //如果日志记录器实例创建失败则抛出异常 if(instance == null) throw new Options.Configuration.OptionConfigurationException(string.Format("Can not create instance of '{0}' type.", type)); //如果日志记录器配置节含有扩展属性,则设置日志记录器实例的扩展属性 if(handlerElement.HasExtendedProperties) { foreach(var property in handlerElement.ExtendedProperties) { Zongsoft.Common.Convert.SetValue(instance, property.Key, property.Value); } } LoggerHandlerPredication predication = null; if(handlerElement.Predication != null) { predication = new LoggerHandlerPredication() { Source = handlerElement.Predication.Source, ExceptionType = handlerElement.Predication.ExceptionType, MaxLevel = handlerElement.Predication.MaxLevel, MinLevel = handlerElement.Predication.MinLevel, }; } Logger.Handlers.Add(new LoggerHandler(handlerElement.Name, instance, predication)); } }
protected DataProviderBase(string name, Zongsoft.Services.IServiceProvider services) { if(string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException("name"); _name = name.Trim(); if(services != null && !string.IsNullOrWhiteSpace(this.DriverName)) _dbProvider = services.Resolve<DbProviderFactory>(this.DriverName); }
public virtual void Initialize(Zongsoft.ComponentModel.ApplicationContextBase context) { if(context == null) return; var loggerElement = context.Configuration.GetOptionObject(@"/Diagnostics/Logger") as Configuration.LoggerElement; if(loggerElement != null) { foreach(Configuration.LoggerHandlerElement handlerElement in loggerElement.Handlers) { var type = Type.GetType(handlerElement.TypeName, true, true); if(!typeof(ILogger).IsAssignableFrom(type)) throw new Options.Configuration.OptionConfigurationException(string.Format("The '{0}' type isn't a Logger.", type.FullName)); var constructor = type.GetConstructor(new Type[] { typeof(Configuration.LoggerHandlerElement) }); ILogger instance; if(constructor == null) instance = (ILogger)Activator.CreateInstance(type); else instance = (ILogger)Activator.CreateInstance(type, handlerElement); if(instance == null) throw new Options.Configuration.OptionConfigurationException(string.Format("Can not create instance of '{0}' type.", type)); if(constructor == null) { if(handlerElement.Properties != null && handlerElement.Properties.Count > 0) { foreach(var property in handlerElement.Properties) { Zongsoft.Common.Convert.SetValue(instance, property.Key, property.Value); } } } LoggerHandlerPredication predication = null; if(handlerElement.Predication != null) { predication = new LoggerHandlerPredication() { Source = handlerElement.Predication.Source, ExceptionType = handlerElement.Predication.ExceptionType, MaxLevel = handlerElement.Predication.MaxLevel, MinLevel = handlerElement.Predication.MinLevel, }; } Logger.Handlers.Add(new LoggerHandler(handlerElement.Name, instance, predication)); } } }
protected RedisObjectBase(string name, Zongsoft.Collections.ObjectPool<ServiceStack.Redis.IRedisClient> redisPool) { if(string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException("name"); if(redisPool == null) throw new ArgumentNullException("redisPool"); _name = name.Trim(); _redisPool = redisPool; }
private void Application_Started(object sender, Zongsoft.Plugins.ApplicationEventArgs e) { var context = Zongsoft.Plugins.Application.Context; //将应用上下文对象保存到ASP.NET的全局应用缓存容器中 Application["ApplicationContext"] = context; //注册主页的控制器 context.PluginContext.PluginTree.Mount("/Workspace/Controllers/Home", new Func<IController>(() => new DefaultController())); //卸载主题表单构件 context.PluginContext.PluginTree.Unmount(Zongsoft.Plugins.PluginPath.Combine(context.PluginContext.Settings.WorkbenchPath, "__ThemeForm__")); //注销插件应用的启动完成事件的通知 Zongsoft.Plugins.Application.Started -= Application_Started; }
public Censorship(Zongsoft.Services.IServiceProvider serviceProvider, params string[] keys) : base(serviceProvider) { _keys = keys; }
public Censorship(Zongsoft.Services.IServiceProvider serviceProvider) : base(serviceProvider) { }
public Authorization(Zongsoft.Services.IServiceProvider serviceProvider) : base(serviceProvider) { }
public RoleProvider(Zongsoft.Services.IServiceProvider serviceProvider) : base(serviceProvider) { }
public PluginWebFormViewEngine(Zongsoft.Plugins.PluginContext pluginContext) : base(pluginContext) { this.ViewExtensions = new string[] { "aspx", "html", "htm" }; this.PartialViewExtensions = new string[] { "ascx" }; this.MasterExtensions = new string[] { "master" }; }
internal Sitemap(Zongsoft.Plugins.PluginTreeNode sitemapNode) { if(sitemapNode == null) throw new ArgumentNullException("sitemapNode"); _sitemapNode = sitemapNode; }
private Zongsoft.Plugins.PluginTreeNode GetCurrentNode(Zongsoft.Plugins.PluginTreeNode node, string url) { if(node == null || string.IsNullOrWhiteSpace(url)) return null; foreach(var child in node.Children) { var foundNode = this.GetCurrentNode(child, url); if(foundNode != null) return foundNode; } var treeNode = node.UnwrapValue<Controls.TreeViewNode>(ObtainMode.Auto, this, null); if(treeNode != null) { if((!string.IsNullOrWhiteSpace(treeNode.NavigateUrl)) && url.StartsWith(treeNode.NavigateUrl, StringComparison.OrdinalIgnoreCase)) return node; } return null; }
private Zongsoft.Plugins.PluginTreeNode[] GetCurrentNodePath(Zongsoft.Plugins.PluginTreeNode currentNode) { if(currentNode == null) return null; var stack = new Stack<Zongsoft.Plugins.PluginTreeNode>(); while(currentNode != null && currentNode != _sitemapNode) { stack.Push(currentNode); currentNode = currentNode.Parent; } //最后再将主页压入堆栈 stack.Push(_sitemapNode); return stack.ToArray(); }
public virtual IEnumerable<object> Unpack(Zongsoft.Common.Buffer buffer) { int availableLength; while(buffer.CanRead()) { //如果当前头部缓存指针位置小于包头的长度,则必须先读取头部数据 if(_contentLength == 0 && _headOffset < HEAD_LENGTH) { //从当前接受缓存中读取剩下的包头数据 availableLength = buffer.Read(_headBuffer, _headOffset, HEAD_LENGTH - _headOffset); //将当前头部缓存指针加上当前实际读取的长度 _headOffset += availableLength; //如果当前头部缓存指针位置仍然小于包头长度,则说明当前接数据缓存区数据量不够, //即本次接收到的缓存数据已被读完,故直接退出当前方法。 if(_headOffset < HEAD_LENGTH) yield break; //至此头部数据接收完毕,将头部缓存解析成包头实体 _head = this.ResolveHeader(_headBuffer); //如果包头指示当前数据包的实际内容长度为零,则说明此包为空包 if(_head.TotalLength == 0 || _head.ContentLength == 0) { //重置缓存指针位置,以指示下次需要进行包头解析 _headOffset = 0; _contentLength = 0; //接着处理下一个小包 continue; } //映射当前数据包对应的缓存区。 if(!_bufferStates.ContainsKey(_head.SequenceId)) { var bufferManager = this.GetBufferManager(); var id = bufferManager.Allocate(_head.TotalLength); _bufferStates[_head.SequenceId] = new BufferState(bufferManager.GetStream(id)); } } //计算出本次要接受的内容长度 int contentLength = _contentLength == 0 ? _head.ContentLength : _contentLength; //定义当前接收的数据包对应的缓存状态对象 BufferState bufferState; //从缓存容器中获取当前大包的缓存状态对象 if(!_bufferStates.TryGetValue(_head.SequenceId, out bufferState)) throw new InvalidOperationException("Can not obtain the BufferCache with sequence-id."); //将接收到的数据写入缓存区 availableLength = buffer.Read(bufferState.BufferStream, contentLength); //更新当前缓存状态中的缓存数 bufferState.BufferedSize += availableLength; //设置下次要接收的内容长度 _contentLength = contentLength - availableLength; //如果下次要接收的内容长度为零,则指示下次接收要先进行包头的处理,即将头缓存偏移量置零 if(_contentLength == 0) _headOffset = 0; //如果整个大包全部接受完毕 if(bufferState.BufferedSize == _head.TotalLength) { //重置缓存指针位置,以指示下次需要进行包头解析 _headOffset = 0; _contentLength = 0; //重置当前缓存区流的指针 bufferState.BufferStream.Position = 0; //将当前接收的数据包从缓存映射中删除 _bufferStates.Remove(_head.SequenceId); yield return bufferState.BufferStream; } } }
public static void Logout(Zongsoft.Security.ICredentialProvider credentialProvider) { if(credentialProvider == null) { var applicationContext = Zongsoft.ComponentModel.ApplicationContextBase.Current; if(applicationContext != null && applicationContext.ServiceFactory != null) { var serviceProvider = applicationContext.ServiceFactory.GetProvider("Security"); if(serviceProvider != null) credentialProvider = serviceProvider.Resolve<ICredentialProvider>(); } } if(credentialProvider != null) { var credentialId = CredentialId; if(!string.IsNullOrWhiteSpace(credentialId)) credentialProvider.Unregister(credentialId); } HttpContext.Current.Response.Cookies.Remove(CredentialKey); }
public PluginRazorViewEngine(Zongsoft.Plugins.PluginContext pluginContext) : base(pluginContext) { this.ViewExtensions = FileExtensions; this.PartialViewExtensions = FileExtensions; this.MasterExtensions = FileExtensions; }
public PluginExplorerController(Zongsoft.Plugins.PluginContext pluginContext) { _pluginContext = pluginContext; }
public PermissionProvider(Zongsoft.Services.IServiceProvider serviceProvider) : base(serviceProvider) { }
public UseOptionElementExample(Zongsoft.Options.IOptionProvider options) { _options = options; }
public virtual IEnumerable<Zongsoft.Common.Buffer> Pack(Zongsoft.Common.Buffer buffer) { if(buffer == null || buffer.Count == 0) { //遍历返回字节组缓存信息 yield return new Zongsoft.Common.Buffer(new byte[HEAD_LENGTH], 0); } var sequenceId = System.Threading.Interlocked.Increment(ref _sequenceId); var bytes = new byte[_bufferEvaluator.GetBufferSize(buffer.Count)]; int contentLength = 0; while((contentLength = buffer.Read(bytes, HEAD_LENGTH, bytes.Length - HEAD_LENGTH)) > 0) { //设置包的头部字段 this.SetPackageHead(bytes, sequenceId, buffer.Count, contentLength); //遍历返回字节组缓存信息 yield return new Zongsoft.Common.Buffer(bytes, 0, HEAD_LENGTH + contentLength); //注意:一定要重新分配缓存数组,不然同一个缓存在高速发送过程中肯定会发生写入覆盖 bytes = new byte[_bufferEvaluator.GetBufferSize(buffer.Count)]; } }