using System; using System.Collections.Generic; using System.Linq; using System.Text; using Composite.C1Console.Elements; using Composite.C1Console.Elements.Plugins.ElementProvider; using Composite.C1Console.Security; using Composite.C1Console.Security.SecurityAncestorProviders; using Composite.Core.ResourceSystem.Icons; namespace MyCode { public sealed class EnvironmentPropertiesElementProvider : IHooklessElementProvider, IAuxiliarySecurityAncestorProvider { private EnvironmentPropertiesElements _environmentPropertiesElements; private IEnumerable Roots { get { yield return _environmentPropertiesElements.EnvironmentElement; } } public EnvironmentPropertiesElementProvider() { AuxiliarySecurityAncestorFacade.AddAuxiliaryAncestorProvider(this); } public ElementProviderContext Context { set { _environmentPropertiesElements = new EnvironmentPropertiesElements(value); } } public IEnumerable GetChildren(EntityToken entityToken, SearchToken seachToken) { if (entityToken.Id == _environmentPropertiesElements.EnvironmentElementId.ToString()) { yield return _environmentPropertiesElements.OSVersionElement; yield return _environmentPropertiesElements.ProcessorCountElement; } yield break; } public IEnumerable GetRoots(SearchToken seachToken) { return Roots; } public Dictionary> GetParents(IEnumerable entityTokens) { var result = new Dictionary>(); foreach (EntityToken entityToken in entityTokens) { if (entityToken.Id == _environmentPropertiesElements.EnvironmentElementId.ToString()) continue; result.Add(entityToken, new EntityToken[] { _environmentPropertiesElements.EnvironmentEntityToken }); } return result; } } internal class EnvironmentPropertiesElements { private ElementProviderContext _providerContext; public EnvironmentPropertiesElements(ElementProviderContext value) { this._providerContext = value; } public Element EnvironmentElement { get { return new Element(_providerContext.CreateElementHandle(EnvironmentEntityToken)) { VisualData = new ElementVisualizedData() { Label = "Environment", ToolTip = "Environment", HasChildren = true, Icon = CommonElementIcons.Folder, OpenedIcon = CommonElementIcons.FolderOpen } }; } } public Element OSVersionElement { get { return new Element(_providerContext.CreateElementHandle(new EnvironmentEntityToken("OSVersion"))) { VisualData = new ElementVisualizedData() { Label = Environment.OSVersion.ToString(), ToolTip = "ProcessorCount", HasChildren = false, Icon = CommonElementIcons.Data, OpenedIcon = CommonElementIcons.Data } }; } } public Element ProcessorCountElement { get { return new Element(_providerContext.CreateElementHandle(new EnvironmentEntityToken("ProcessorCount"))) { VisualData = new ElementVisualizedData() { Label = Environment.ProcessorCount.ToString(), ToolTip = "ProcessorCount", HasChildren = false, Icon = CommonElementIcons.Data, OpenedIcon = CommonElementIcons.Data } }; } } public EntityToken EnvironmentEntityToken { get { return new EnvironmentEntityToken(EnvironmentElementId.ToString()); } } public Guid EnvironmentElementId { get { return new Guid("{CABEDE97-FB1C-48F5-847D-16C7675EB889}"); } } } [SecurityAncestorProvider(typeof(NoAncestorSecurityAncestorProvider))] public class EnvironmentEntityToken : EntityToken { private string _id; public EnvironmentEntityToken(string id) { _id = id; } public override string Id { get { return _id; } } public override string Serialize() { return DoSerialize(); } public override string Source { get { return ""; } } public override string Type { get { return ""; } } public static EntityToken Deserialize(string serializeedEntityToken) { string type, source, id; DoDeserialize(serializeedEntityToken, out type, out source, out id); return new EnvironmentEntityToken(id); } } }