public ConfigController(IConfigService service, FileUploadHelper fileUploadHelper, IConfigProvider configProvider, IConfigCollection configCollection) { _service = service; _fileUploadHelper = fileUploadHelper; _configProvider = configProvider; _configCollection = configCollection; }
private IConfigCollection LoadCollection(string path, Type keyType, Type itemType, Type fieldType, IICIndex <IICConfigItemBuffer> index) { IList <IICConfigItemBuffer> items = index.Find(path); string lastKey = null; List <string> keys = new List <string>(); foreach (IICConfigItemBuffer buffer in items) { if (string.IsNullOrEmpty(lastKey) || buffer.Key != lastKey) { if (!string.IsNullOrEmpty(buffer.Key)) { keys.Add(buffer.Key); lastKey = buffer.Key; } } } IConfigCollection collection = (IConfigCollection)Activator.CreateInstance(fieldType); foreach (string key in keys) { object itemObj = LoadItem(path, key, itemType, index); object keyObj = ObjectHelper.ConvertTo(key, keyType); collection.Add(keyObj, itemObj); } return(collection); }
public static void Load(DataSet ds, String configType, Selector sel) { DataTable table = null; IConfigCollection coll = null; //IConfigItem item = null; // Make sure we have a table for this configType table = LoadSchema(ds, configType); // Read the data for the configType coll = (IConfigCollection)ConfigManager.Get(configType, sel); if (coll.Count > 0) // Did we find anything? // Add a row for each config item: // Initialize an array with one value for each property in the config items { Object[] values = new Object[coll[0].Count]; // Enumerate the config items foreach (IConfigItem item1 in (BaseConfigCollection)coll) { // Copy each property to the value array int j = 0; foreach (Object value in (BaseConfigItem)item1) { values[j] = value; j++; } // Add a row with all the config item values table.Rows.Add(values); } } }
public ConfigProvider(IConfigCollection configs, IConfigStorageProvider storageProvider, IServiceProvider serviceProvider, IConfiguration cfg) { _configs = configs; _storageProvider = storageProvider; _serviceProvider = serviceProvider; _cfg = cfg; }
public ConfigProvider(RedisHelper redisHelper, IConfigCollection configs, IRedisSerializer redisSerializer, IConfigStorageProvider storageProvider, IConfiguration cfg) { _redisHelper = redisHelper; _configs = configs; _redisSerializer = redisSerializer; _storageProvider = storageProvider; _cfg = cfg; }
public KeeperEndpoint(string server, IConfigCollection <IServerConfiguration> storage) { _storage = storage; ClientVersion = DefaultClientVersion; DeviceName = DefaultDeviceName; Locale = DefaultLocale(); Server = server; }
private T LoadSection <T>(string sectionName, IICIndex <IICConfigItemBuffer> index) where T : IICConfigSection { IICConfigSectionAttribute sectionAttr = AttributeHelper.GetAttribute <IICConfigSectionAttribute>(typeof(T)); T section = Activator.CreateInstance <T>(); foreach (FieldInfo field in typeof(T).GetFields()) { IICConfigFieldAttribute fieldAttr = AttributeHelper.TryGetAttribute <IICConfigFieldAttribute>(field); if (fieldAttr != null) { IICConfigItemBuffer item = index.TryFindOne(sectionAttr.SectionName, string.Empty, fieldAttr.FieldName); if (item != null) { ObjectHelper.SetValue(field, section, item.Value, field.FieldType); } else { ObjectHelper.SetValue(field, section, fieldAttr.DefaultValue); } continue; } IICConfigItemAttribute itemAttr = AttributeHelper.TryGetAttribute <IICConfigItemAttribute>(field); if (itemAttr != null) { object item = LoadItem(sectionName + "." + itemAttr.ItemName, string.Empty, field.FieldType, index); field.SetValue(section, item); continue; } IICConfigItemCollectionAttribute colletionAttr = AttributeHelper.TryGetAttribute <IICConfigItemCollectionAttribute>(field); if (colletionAttr != null) { Type[] types = field.FieldType.GetGenericArguments(); Type keyType = types[0]; Type itemType = types[1]; IConfigCollection collection = LoadCollection(sectionName + "." + colletionAttr.ItemName, keyType, itemType, field.FieldType, index); field.SetValue(section, collection); continue; } } return(section); }
public CfgFileDialog(String selector, ConfigViewerSample parent) { // // Required for Win Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // this.parent = parent; label1.Text = selector; try { IConfigCollection files = ConfigManager.Get(ConfigViewerSample.ctConfigFileHierarchy, selector); foreach (IConfigItem file in files) { listBox1.Items.Add((String)file["ConfigFilePath"]); } } catch (Exception ex) { listBox1.Items.Add(ex.Message); } }
public ConfigController(IConfigService service, IConfigCollection configCollection, IFileStorageProvider fileStorageProvider) { _service = service; _configCollection = configCollection; _fileStorageProvider = fileStorageProvider; }
public static void Save(DataSet ds, Selector sel) { IConfigCollection Inserts = null; IConfigCollection Updates = null; IConfigCollection Deletes = null; // Obtain the changed rows in the DataSet DataSet changes = ds.GetChanges(); if (null == changes) { return; } // enumerate all changed tables foreach (DataTable table in changes.Tables) { // Create an empty configuration collection to hold the changed items Inserts = ConfigManager.GetEmptyConfigCollection(table.TableName); Inserts.Selector = sel; // identify where the items are to be stored Updates = ConfigManager.GetEmptyConfigCollection(table.TableName); Updates.Selector = sel; // identify where the items are to be stored Deletes = ConfigManager.GetEmptyConfigCollection(table.TableName); Deletes.Selector = sel; // identify where the items are to be stored // enumerate all changed rows in this table foreach (DataRow row in table.Rows) { if (DataRowState.Deleted == row.RowState) { // If the row has been deleted: // Create an empty configuration item for this row IConfigItem item = ConfigManager.GetEmptyConfigItem(table.TableName); // Copy the original values from the row into the item for (int i = 0; i < item.Count; i++) { item[i] = row[i, DataRowVersion.Original]; } Deletes.Add(item); Trace.WriteLine("Deleted: " + item); } else if (DataRowState.Modified == row.RowState || DataRowState.New == row.RowState) { // If the row has been modified or added: // Create an empty configuration item for this row IConfigItem item = ConfigManager.GetEmptyConfigItem(table.TableName); // Copy the values from the row into the item for (int i = 0; i < item.Count; i++) { item[i] = row[i]; } // Add the item to the proper collection if (DataRowState.Modified == row.RowState) { // If the row has been modified, add it to the Updates collection Updates.Add(item); Trace.WriteLine("Updated: " + item); } else if (DataRowState.New == row.RowState) { // If the row has been created, add it to Inserts collection Inserts.Add(item); Trace.WriteLine("Inserted: " + item); } else { // should never get here... throw(new ApplicationException("internal error")); } } } if (Deletes.Count > 0) // any deleted rows? { // Delete them from the store ConfigManager.Delete(Deletes); } if (Inserts.Count > 0) // any inserted rows? { // Add them to the store ConfigManager.Put(Inserts, PutFlags.CreateOnly); } if (Updates.Count > 0) // any modified rows? { // Change them in the store ConfigManager.Put(Updates, PutFlags.UpdateOnly); } // Get ready for the next table/config type... Inserts = null; Updates = null; Deletes = null; } }
public static DataTable LoadSchema(DataSet ds, String configType) { DataTable table = null; DataTable parentTable = null; DataColumn column = null; IConfigCollection parents = null; IConfigItem parent = null; // Do we already have a table for this configType? if (ds.Tables.Contains(configType)) { // Yes: use it. return(ds.Tables[configType]);; } // Create a new table for this configType table = new DataTable(); table.TableName = configType; // Set the schema for the table ArrayList pk = new ArrayList(); foreach (PropertySchema propertyschema in ConfigSchema.PropertySchemaCollection(configType)) { column = table.Columns.Add(propertyschema.PublicName, propertyschema.SystemType); if ((((int)propertyschema["MetaFlags"]) & 1) > 0) { pk.Add(column); } } DataColumn[] pk1 = new DataColumn[pk.Count]; pk.CopyTo(pk1); table.Constraints.Add("PK", pk1, true); // Add the new table to the dataset ds.Tables.Add(table); // Set schema for any parent tables try { parents = ConfigManager.Get("RelationMeta", "", 0); } catch { parents = null; } for (int i = 0; i < parents.Count; i++) { parent = parents[i]; if (parent["ForeignTable"].Equals(ConfigSchema.ConfigTypeSchema(configType).InternalName)) { parentTable = LoadSchema(ds, (String)parent["PrimaryTable"]); // TODO: add DataSet relation info! } } return(table); }
public static int Main(String[] args) { System.Configuration.Web.Assembly a = null; // BUGBUG: need this so that System.Configuration.Objects.dll is found a = new System.Configuration.Web.Assembly(); // get rid of the warning... Boolean bFullPropertyMeta = false; Boolean bShowPropertyNames = true; IConfigCollection props = null; IConfigCollection collection = null; IConfigCollection propmeta = null; String configtype = "AppDomain"; String url = "file://" + new LocalMachineSelector().Argument; for (int i = 0; i < args.Length; i++) { if (args[i].StartsWith("/") || args[i].StartsWith("-")) { String arg = args[i].Substring(1).ToLower(); if ("?" == arg) { Console.WriteLine("Usage: mtest [<configtype>] [<prefix>:<selector>] [/nometa] [/meta] [/?]"); Console.WriteLine(" <configtype> - the config type for which data is to be shown. Default: AppDomain"); Console.WriteLine(" <prefix>:<selector> - a selector string, i.e. file://c:\\foo.cfg. Default: <machinecfgdir>\\config.cfg"); Console.WriteLine(" : - use no selector at all."); Console.WriteLine(" /nometa - don't show property names, only values"); Console.WriteLine(" /meta - show all schema information for each property"); return(0); } if ("meta" == arg) { bFullPropertyMeta = true; } if ("nometa" == arg) { bShowPropertyNames = false; bFullPropertyMeta = false; } } else if (args[i].IndexOf(':') < 0) { configtype = args[i]; } else { if (args[i].Equals(":")) { url = ""; } else { url = args[i]; } } } /* * // strongly typed version... * IISProcessModel pm = (IISProcessModel) ConfigManager.GetItem("iisprocessmodel", "file://c:\\urt\\config\\src\\test\\xsp\\config.web", 0); * * Console.WriteLine(pm.enable); * Console.WriteLine(pm.timeout); * Console.WriteLine(pm.idletimeout); * Console.WriteLine(pm.shutdowntimeout); * Console.WriteLine(pm.requestlimit); * Console.WriteLine(pm.memorylimit); * Console.WriteLine(pm.cpumask); * Console.WriteLine(pm.usecpuaffinity); */ // Read the data collection = ConfigManager.Get(configtype, url, 0); if (bShowPropertyNames) { // Read the schema: to be able to show the property names ConfigQuery q = new ConfigQuery("select * from Property where Table=" + ConfigSchema.ConfigTypeSchema(configtype).InternalName); props = ConfigManager.Get("Property", q, 0); // Read the meta schema for properties: to be able to show the names of the schema information if (bFullPropertyMeta) { ConfigQuery qmetameta = new ConfigQuery("select * from Property where Table=COLUMNMETA"); //qmetameta.Add(0, QueryCellOp.Equal, "COLUMNMETA"); propmeta = ConfigManager.Get("Property", qmetameta, 0); } } for (int k = 0; k < collection.Count; k++) { IConfigItem item = collection[k]; if (bFullPropertyMeta) { // Write the type of each item Console.WriteLine("Type: " + item.ToString()); } for (int i = 0; i < item.Count; i++) { if (bShowPropertyNames) { // Write the property name Console.Write(props[i]["PublicName"] + ": "); } // Write the property value Console.WriteLine(item[i]); if (bFullPropertyMeta) { // Write the schema information for the property Console.WriteLine("["); for (int j = 0; j < props[i].Count; j++) { // Write the name of the meta property Console.Write(" " + propmeta[j]["PublicName"]); // Write the value of the meta property Console.Write("=" + props[i][j]); Console.WriteLine(); } Console.WriteLine("]"); } } } return(0); }
public Object Read(String configType, Selector selector, int los, Object currentObject) { Selector url = null; ConfigQuery query = null; Object val = null; IConfigCollection result = null; IConfigItem node = null; if (selector is ConfigQuery && ((ConfigQuery)selector).Count > 0) { query = (ConfigQuery)selector; url = query.Selector; } else { if (selector is NullSelector) { url = null; } else { url = selector; } query = null; } if (url != null && !(url is HttpSelector) && !(url is WebServiceSelector)) { throw new ConfigException("Invalid Selector"); } switch (configType) { case ctNodes: // LogicalName, PhysicalName, Parent, NodeType // Q by ParentName==NULL: "IISWebService" entry (LogicalName = ?) // Q by "IISWebService" LogicalName: all IIS web sites // Q by LogicalName: UNC from URL - site binding // NodeType: IIS6! // PhysicalName: UNC from URL (MB) if (query != null) { if (query.Count > 1) { throw new ConfigException("Can't query by more than one property"); } val = query[0].Value; } if ((query != null && query[0].PropertyIndex == 2) || url == null) // Query by Parent? { if (val == null || (val is String && ((String)val) == String.Empty)) { // return IISWebService node result = ConfigManager.GetEmptyConfigCollection(configType); node = ConfigManager.GetEmptyConfigItem(configType); WebServiceSelector ws = new WebServiceSelector(); node["LogicalName"] = ws.ToString(); node["PhysicalName"] = new WebServiceSelector().Argument; node["Parent"] = ""; node["RelativeName"] = ".NET Web Service"; node["NodeType"] = nodetypeWebService; result.Add(node); return(result); } if (val is String) { if ((String)val == new WebServiceSelector().ToString()) { // return all sites result = ConfigManager.GetEmptyConfigCollection(configType); node = ConfigManager.GetEmptyConfigItem(configType); // BUGBUG really enumerate the metabase node["LogicalName"] = "http://localhost"; node["PhysicalName"] = IISAdminHelper.GetPathForUrl((String)node["LogicalName"]); node["Parent"] = new WebServiceSelector().ToString(); node["RelativeName"] = node["LogicalName"]; node["NodeType"] = nodetypeWebServer; result.Add(node); return(result); } // read children from metabase String[] children = IISAdminHelper.GetChildrenForUrl((String)val); result = ConfigManager.GetEmptyConfigCollection(configType); foreach (String child in children) { node = ConfigManager.GetEmptyConfigItem(configType); // BUGBUG really enumerate the metabase node["Parent"] = (String)val; node["LogicalName"] = ((String)val) + "/" + child; node["PhysicalName"] = IISAdminHelper.GetPathForUrl((String)node["LogicalName"]); node["RelativeName"] = child; node["NodeType"] = nodetypeWebDirectory; result.Add(node); } return(result); } throw new ConfigException("Invalid query for UINavigationNodes.Parent!"); } if ((query == null && url != null) || (query != null && query[0].PropertyIndex == 0)) // Query by LogicalName? { if (query == null) { val = url.ToString(); } if (!(val is String) || ((String)val) == String.Empty) { throw new ConfigException("Invalid Query for UINavigationNode.LogicalName!"); } WebServiceSelector ws = new WebServiceSelector(); if ((String)val == ws.ToString()) { // return IISWebService node result = ConfigManager.GetEmptyConfigCollection(configType); node = ConfigManager.GetEmptyConfigItem(configType); node["LogicalName"] = ws.ToString(); node["PhysicalName"] = ws.Argument.Substring(0, ws.Argument.LastIndexOf('\\')); node["Parent"] = ""; node["RelativeName"] = ""; node["NodeType"] = nodetypeWebService; result.Add(node); return(result); } result = ConfigManager.GetEmptyConfigCollection(configType); node = ConfigManager.GetEmptyConfigItem(configType); node["LogicalName"] = (String)val; node["PhysicalName"] = IISAdminHelper.GetPathForUrl((String)val); // BUGBUG compute only the immediate parent! String[] parents = IISAdminHelper.GetParentUrlsForUrl((String)val); if (parents.Length >= 2) { node["Parent"] = parents[parents.Length - 2]; node["RelativeName"] = ((String)val).Substring(((String)val).LastIndexOf('/')); } else { node["Parent"] = new WebServiceSelector().ToString(); node["RelativeName"] = node["LogicalName"]; } node["NodeType"] = nodetypeWebDirectory; result.Add(node); return(result); } throw new ConfigException("Invalid Query for UINavigationNode.LogicalName!"); //break; // ******************************************************************************************************* case ctConfigFileHierarchy: // LogicalName, ConfigFilePath, Location // Q by LogicalName=all config file for this node and it's parents if (query == null || query.Count == 0) { if (url == null) { throw new ConfigException("Can't enumerate all nodes!"); } } if (query != null) { if (query.Count > 1) { throw new ConfigException("Can't query by more than one property"); } val = query[0].Value; } if ((query != null && query[0].PropertyIndex == 0) || (query == null && url != null)) // Query by LogicalName? { if (query == null) { val = url.ToString(); } if (val == null || (val is String && ((String)val) == String.Empty)) { throw new ConfigException("Can't query for all root nodes."); } if (val is String) { result = ConfigManager.GetEmptyConfigCollection(configType); node = ConfigManager.GetItem(ctNodes, url); do { IConfigCollection files = ConfigManager.Get(ctFileLocation, (String)node["LogicalName"]); foreach (IConfigItem file in files) { IConfigItem hierarchyfile = ConfigManager.GetEmptyConfigItem(configType); hierarchyfile["LogicalName"] = file["LogicalName"]; hierarchyfile["ConfigFilePath"] = file["ConfigFilePath"]; hierarchyfile["Location"] = ""; result.Add(hierarchyfile); } if (node["Parent"] != "") { node = ConfigManager.GetItem(ctNodes, (String)node["Parent"]); } else { break; } } while (true); return(result); } throw new ConfigException("Invalid query for " + ctConfigFileHierarchy + ".LogicalName!"); } throw new ConfigException("Invalid Query for " + ctHierarchy + "."); //break; case ctFileLocation: // LogicalName, ConfigFilePath, Description IConfigCollection nodes = (IConfigCollection)Read(ctNodes, selector, los, currentObject); if (nodes.Count > 1) { throw new ConfigException("More than one node for this URL!"); } result = ConfigManager.GetEmptyConfigCollection(configType); if (nodes.Count == 1) { node = ConfigManager.GetEmptyConfigItem(configType); node["LogicalName"] = nodes[0]["LogicalName"]; node["ConfigFilePath"] = ((String)nodes[0]["PhysicalName"]) + "\\config.web"; node["Description"] = ""; result.Add(node); } return(result); default: throw new ConfigException("Invalid ConfigType"); } }