private void toolStripButtonLoadConifg_Click(object sender, EventArgs e) { if (this.cbxtoolStripSelectObejct.ComboBox.SelectedIndex >= 0) { if (this.openFileDialogInputUIConfig.ShowDialog() == DialogResult.OK) { FormUISetting uis = XmlConfigReader.GetConfig <FormUISetting>(this.openFileDialogInputUIConfig.FileName); ITable selectTable = this.cbxtoolStripSelectObejct.ComboBox.SelectedValue as MyMeta.ITable; IDatabase database = selectTable.Database; for (int i = 0; i < this.cbxtoolStripSelectObejct.ComboBox.Items.Count; i++) { ITable table = (ITable)this.cbxtoolStripSelectObejct.ComboBox.Items[i]; if (table.Name == uis.TableName) { this.cbxtoolStripSelectObejct.ComboBox.SelectedIndex = i; break; } } this.dataGridViewField.DataSource = uis.Items; } } }
/// <summary> /// Initialize a registered cache given by the ID. /// </summary> /// <param name="cacheId">A string identifier of configuration.</param> static public CacheServerConfig GetConfigDom(string cacheId, string filePath, bool inProc) { try { XmlConfigReader configReader = new XmlConfigReader(filePath, cacheId); CacheServerConfig config = configReader.GetConfigDom(); CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; if (config == null) { return(config); } if (!inProc) { inProc = config.InProc; } if (inProc) { return(config); } return(null); } catch (ManagementException) { throw; } catch (Exception e) { throw new ManagementException(e.Message, e); } }
public void Read_NoDevice() { var xmlConfigReader = new XmlConfigReader("_TestData\\config_no_device.xml"); var settings = xmlConfigReader.Read(); Assert.Empty(settings); }
static public bool SetupConfigSystem(string configFilePath) { ModManager.ApplicationExit += ModManagerApplicationExit; LoggingManager.SendMessage("ConfigManager - Setting up config system..."); if (!File.Exists(configFilePath)) { LoggingManager.SendMessage("ConfingManager - No plugins.config found, creating one from scratch"); } s_sConfigFilePath = configFilePath; FileStream config = null; try { config = File.Open(configFilePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read); s_pluginsConfig = XmlConfigReader.Read(config); } catch (Exception e) { LoggingManager.SendMessage("ConfigManager - Failed to set up config system from file: " + configFilePath); LoggingManager.HandleException(e); return(false); } finally { if (config != null) { config.Close(); } } LoggingManager.SendMessage("ConfigManager - Config system set up successfully!"); return(true); }
/// <summary> /// Initialize a registered cache given by the ID. /// </summary> /// <param name="cacheId">A string identifier of configuration.</param> static public ArrayList GetCacheConfig(string cacheId, string filePath, bool inProc) { try { XmlConfigReader configReader = new XmlConfigReader(filePath, cacheId); ArrayList propsList = configReader.PropertiesList; ArrayList configsList = CacheConfig.GetConfigs(propsList, DEF_TCP_PORT); foreach (CacheConfig config in configsList) { if (!inProc) { inProc = config.UseInProc; } break; } if (inProc) { return(configsList); } return(null); } catch (ManagementException) { throw; } catch (Exception e) { throw new ManagementException(e.Message, e); } }
private void toolStripButtonLoadConifg_Click(object sender, EventArgs e) { if ((cbxtoolStripSelectDataBase.ComboBox.SelectedIndex >= 0) && (cbxtoolStripSelectObejct.ComboBox.SelectedIndex >= 0)) { if (openFileDialogInputUIConfig.ShowDialog() == DialogResult.OK) { var uis = XmlConfigReader.GetConfig <FormUISetting>(openFileDialogInputUIConfig.FileName); var database = cbxtoolStripSelectDataBase.ComboBox.SelectedValue as IDatabase; for (int i = 0; i < cbxtoolStripSelectObejct.ComboBox.Items.Count; i++) { var table = (ITable)cbxtoolStripSelectObejct.ComboBox.Items[i]; if (table.Name == uis.TableName) { cbxtoolStripSelectObejct.ComboBox.SelectedIndex = i; break; } } dataGridViewField.DataSource = uis.Items; } } }
public void Read_DeviceWithoutMapping() { var xmlConfigReader = new XmlConfigReader("_TestData\\config_device_without_mapping.xml"); var settings = xmlConfigReader.Read(); Assert.Single(settings); Assert.Equal("Dings", settings.First().Name); Assert.Empty(settings.First().Mapping); }
/// <summary> /// Creates a cache object by reading in cofiguration parameters from a .NET XML file. /// </summary> /// <param name="configFileName">Name and/or path of the configuration file.</param> /// <param name="configSection">Name and/or ID of the section in the configuration file.</param> /// <param name="itemAdded">item added handler</param> /// <param name="itemRemoved">item removed handler</param> /// <param name="itemUpdated">item updated handler</param> /// <param name="cacheMiss">cache miss handler</param> /// <param name="cacheCleared">cache cleared handler</param> /// <returns>return the Cache object</returns> static public Cache CreateFromXmlConfig(string configFileName, string configSection, CustomRemoveCallback customRemove, CustomUpdateCallback customUpdate) { ConfigReader xmlReader = new XmlConfigReader(configFileName, configSection); return(CreateFromProperties(xmlReader.Properties, customRemove, customUpdate)); }
public void Read_OneDevice() { var xmlConfigReader = new XmlConfigReader("_TestData\\config_one_device.xml"); var settings = xmlConfigReader.Read(); Assert.Single(settings); Assert.Equal("Dings", settings.First().Name); Assert.Equal(2, settings.First().Mapping.Count); Assert.Contains(new KeyValuePair <int, int>(1, 111), settings.First().Mapping); Assert.Contains(new KeyValuePair <int, int>(2, 222), settings.First().Mapping); }
private void toolStripButtonSaveConfig_Click(object sender, EventArgs e) { if ((cbxtoolStripSelectDataBase.ComboBox.SelectedIndex >= 0) && (cbxtoolStripSelectObejct.ComboBox.SelectedIndex >= 0)) { var database = cbxtoolStripSelectDataBase.ComboBox.SelectedValue as IDatabase; var selectTable = cbxtoolStripSelectObejct.ComboBox.SelectedValue as ITable; FormUISetting uis = GetFormUIConfig(database, selectTable); string pathKey = "Key|KilerCodeGeneration|UI|" + database.Name + "|" + selectTable.Name; XmlConfigReader.SetConfig <FormUISetting>(pathKey, uis, saveFileDialogInputUIConfig); } }
public void Read_OneDevice() { var xmlConfigReader = new XmlConfigReader("_TestData\\config_one_device.xml"); var settings = xmlConfigReader.Read(); var device = settings.FirstOrDefault(); Assert.Single(settings); Assert.Equal("Sam", device.Name); Assert.Equal(4, device.Pins.Count()); Assert.Contains(new Pin(1, 6, "Relay + LED", PinLogic.Negative), device.Pins); Assert.Contains(new Pin(2, 8, "Relay + LED", PinLogic.Positive), device.Pins); Assert.Contains(new Pin(3, 10, "Relay + LED", PinLogic.Positive), device.Pins); Assert.Contains(new Pin(4, 12, "Relay + LED", PinLogic.Positive), device.Pins); }
/// <summary> /// Initialize a registered cache given by the ID. /// </summary> /// <param name="cacheId">A string identifier of configuration.</param> static public ArrayList GetCacheConfig(string cacheId, string userId, string password, bool inProc) { if (FileName.Length == 0) { throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt"); } try { XmlConfigReader configReader = new XmlConfigReader(FileName, cacheId); ArrayList propsList = configReader.PropertiesList; ArrayList configsList = CacheConfig.GetConfigs(propsList); foreach (CacheConfig config in configsList) { if (!inProc) { inProc = config.UseInProc; } break; } if (inProc) { bool isAuthorize = false; Hashtable ht = (Hashtable)propsList[0]; Hashtable cache = (Hashtable)ht["cache"]; return(configsList); } return(null); } catch (SecurityException) { throw; } catch (ManagementException) { throw; } catch (Exception e) { throw new ManagementException(e.Message, e); } }
/// <summary> /// Initialize a registered cache given by the ID. /// </summary> /// <param name="cacheId">A string identifier of configuration.</param> static public CacheConfig GetCacheConfig(string cacheId) { if (FileName.Length == 0) { throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt"); } try { XmlConfigReader configReader = new XmlConfigReader(FileName, cacheId); return(CacheConfig.FromProperties(configReader.Properties)); } catch (ManagementException) { throw; } catch (Exception e) { throw new ManagementException(e.Message, e); } }
public static void CourierStatusThread(object state) { var diagnosticService = Program.Container.Resolve <IDiagnosticService>(); var courierService = Program.Container.Resolve <ICourierService>(); var systemEventService = Program.Container.Resolve <ISystemEventService>(); var timeout = 30; int.TryParse(XmlConfigReader.GetValue("CourierStatusTimeoutBySecond"), out timeout); try { var listCourier = courierService.ListAll(); var listUpdate = new List <Courier>(); //status online/ofline foreach (var courier in listCourier.Where(courier => (DateTime.UtcNow - courier.LastTime.GetValueOrDefault()).TotalSeconds >= timeout && courier.Status == (int)StatusCourier.Online)) { courier.Status = (int)StatusCourier.Offline; listUpdate.Add(courier); systemEventService.Add(EventMessage.CourierOffline, new Dictionary <EventMessageParam, string>() { { EventMessageParam.Courier, courier.User.LastName + " " + courier.User.FirstName + (string.IsNullOrEmpty(courier.User.MiddleName) ? "" : " " + courier.User.MiddleName) } }); } //reset request var current = DateTime.UtcNow; foreach (var courier in listCourier.Where(courier => courier.ServiceResetTime == null || (DateTime.UtcNow - courier.ServiceResetTime.GetValueOrDefault()).TotalSeconds >= 86400)) { courier.ServiceResetTime = current; courier.CurrentReq = 0; listUpdate.Add(courier); } courierService.UpdateListCourierForService(listUpdate); } catch (Exception ex) { diagnosticService.Error(ex); } }
/// <summary> /// Initialize a registered cache given by the ID. /// </summary> /// <param name="cacheId">A string identifier of configuration.</param> static public ArrayList GetCacheConfig(string cacheId, string filePath, string userId, string password, bool inProc) { try { XmlConfigReader configReader = new XmlConfigReader(filePath, cacheId); ArrayList propsList = configReader.PropertiesList; ArrayList configsList = CacheConfig.GetConfigs(propsList, DEF_TCP_PORT); foreach (CacheConfig config in configsList) { if (!inProc) { inProc = config.UseInProc; } break; } if (inProc) { Hashtable ht = (Hashtable)propsList[0]; Hashtable cache = (Hashtable)ht["cache"]; return(configsList); } return(null); } catch (SecurityException) { throw; } catch (ManagementException) { throw; } catch (Exception e) { throw new ManagementException(e.Message, e); } }
private void toolStripButtonSaveConfig_Click(object sender, EventArgs e) { if (this.cbxtoolStripSelectObejct.ComboBox.SelectedIndex >= 0) { ITable selectTable = this.cbxtoolStripSelectObejct.ComboBox.SelectedValue as MyMeta.ITable; IDatabase database = selectTable.Database; List <TableUIGenerationParams> tableUIGenerationParamsList = null; if (database != null && selectTable != null) { tableUIGenerationParamsList = new List <TableUIGenerationParams>(); foreach (DataGridViewRow row in this.dataGridViewField.Rows) { TableUIGenerationParams tableUIGenerationParams = new TableUIGenerationParams(); tableUIGenerationParams.IsSelect = (bool)row.Cells["colIsSelect"].Value; tableUIGenerationParams.FieldName = (string)row.Cells["colFieldName"].Value; tableUIGenerationParams.FieldNameCn = (string)row.Cells["colFieldNameCn"].Value; tableUIGenerationParams.LanguageType = (string)row.Cells["colLanguageType"].Value; tableUIGenerationParams.Size = (int)row.Cells["colSize"].Value; tableUIGenerationParams.IsAutoKey = (bool)row.Cells["colIsAutoKey"].Value; tableUIGenerationParams.InputType = (string)row.Cells["colInputType"].Value; tableUIGenerationParams.IsReqiured = (bool)row.Cells["colIsReqiured"].Value; tableUIGenerationParams.DefaultValue = (string)row.Cells["colDefaultValue"].Value; tableUIGenerationParams.Items = (string)row.Cells["colSelectItem"].Value; tableUIGenerationParams.DbColumnName = (string)row.Cells["colIndexName"].Value; tableUIGenerationParamsList.Add(tableUIGenerationParams); } } FormUISetting uis = new FormUISetting(); uis.TableName = selectTable.Name; uis.Items = tableUIGenerationParamsList; string pathKey = "Key|KilerCodeGeneration|UI|" + database.Name + "|" + selectTable.Name; XmlConfigReader.SetConfig <FormUISetting>(pathKey, uis, this.saveFileDialogInputUIConfig); } }
public IEnumerable <IController> Create() { string currentAssemblyFilePath = new Uri(typeof(XmlConfigReader).Assembly.CodeBase).LocalPath; string currentAssemblyDirectoryPath = Path.GetDirectoryName(currentAssemblyFilePath); string schemaFilePath = currentAssemblyDirectoryPath + "\\config.xsd"; string configFilePath = currentAssemblyDirectoryPath + "\\config.xml"; var validator = new XmlSchemaValidator(schemaFilePath, configFilePath); bool isValid = validator.Validate(); if (!isValid) { throw new ConfigurationErrorsException("Serial controller configuration is not valid."); } else { var xmlConfigReader = new XmlConfigReader(configFilePath); var devices = xmlConfigReader.Read(); return(devices.Select(x => new SerialController(x)).ToList()); } }
/// <summary> /// Loads and returns all cache configurations from the configuration file. /// </summary> static public CacheConfig[] GetConfiguredCaches2() { if (FileName.Length == 0) { throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt."); } try { XmlConfigReader xcr = new XmlConfigReader("", ""); IDictionary propMap = null; propMap = xcr.GetProperties2(CacheConfigManager.FileName); ArrayList configList = new ArrayList(); IDictionaryEnumerator ide = propMap.GetEnumerator(); while (ide.MoveNext()) { IDictionary properties = (IDictionary)ide.Value; configList.Add(CacheConfig.FromProperties2(properties)); } CacheConfig[] configs = new CacheConfig[configList.Count]; for (int i = 0; i < configList.Count; i++) { configs[i] = configList[i] as CacheConfig; } return(configs); } catch (ManagementException) { throw; } catch (Exception e) { throw new ManagementException(e.Message, e); } }
/// <summary> /// Initialize a registered cache given by the ID. /// </summary> /// <param name="cacheId">A string identifier of configuration.</param> static public ArrayList GetCacheConfig(string cacheId, bool inProc) { if (FileName.Length == 0) { throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt"); } try { XmlConfigReader configReader = new XmlConfigReader(FileName, cacheId); ArrayList propsList = configReader.PropertiesList; ArrayList configsList = CacheConfig.GetConfigs(propsList); foreach (CacheConfig config in configsList) { if (!inProc) { inProc = config.UseInProc; } break; } if (inProc) { return(configsList); } return(null); } catch (ManagementException) { throw; } catch (Exception e) { throw new ManagementException(e.Message, e); } }
public IEnumerable <IController> Create() { string directoryPath = getCurrentDirectoryPath(); string schemaFilePath = directoryPath + "\\config.xsd"; string configFilePath = directoryPath + "\\config.xml"; var xmlSchemaValidator = new XmlSchemaValidator(schemaFilePath, configFilePath); bool isValid = xmlSchemaValidator.Validate(out string message); if (!isValid) { throw new ConfigurationErrorsException("Arduino controller configuration is not valid."); } var xmlConfigReader = new XmlConfigReader(configFilePath); var config = xmlConfigReader.Read(); return(config.Select(x => { var majoro = findConnection(x.Name); return new ArduinoController(majoro, x); })); }
/// <summary> /// Creates a cache object by reading in cofiguration parameters from a .NET XML file. /// </summary> /// <param name="configFileName">Name and/or path of the configuration file.</param> /// <param name="configSection">Name and/or ID of the section in the configuration file.</param> /// <returns>return the Cache object</returns> static public Cache CreateFromXmlConfig(string configFileName, string configSection) { ConfigReader xmlReader = new XmlConfigReader(configFileName, configSection); return(CreateFromProperties(xmlReader.Properties, null, null)); }
public ConfigSection(XmlConfigReader root, string path) { Root = root; Path = path; }
public static void RequestStatusThread(object state) { var diagnosticService = Program.Container.Resolve <IDiagnosticService>(); var systemEventService = Program.Container.Resolve <ISystemEventService>(); var listRequestUpdate = new List <Request>(); var timeout = 600; int.TryParse(XmlConfigReader.GetValue("RequestStatusTimeoutBySecond"), out timeout); try { var requestService = Program.Container.Resolve <IRequestService>(); var requestHistoryService = Program.Container.Resolve <IRequestHistoryService>(); var listRequest = requestService.Get(p => p.Status == (int)StatusRequest.Waiting || p.Status == (int)StatusRequest.Sent); foreach (var request in listRequest.Where(request => (DateTime.UtcNow - request.SendingTime.GetValueOrDefault()).TotalSeconds >= timeout)) { request.Status = (int)StatusRequest.Abandoned; listRequestUpdate.Add(request); systemEventService.Add(EventMessage.RequestAbandoned, new Dictionary <EventMessageParam, string>() { { EventMessageParam.Request, request.RequestNo }, { EventMessageParam.Courier, request.Courier.User.LastName + " " + request.Courier.User.FirstName + (string.IsNullOrEmpty(request.Courier.User.MiddleName) ? "" : " " + request.Courier.User.MiddleName) } }); } var listRequestNotSend = requestService.Get(p => p.Status == (int)StatusRequest.NotSent); foreach (var request in listRequestNotSend.Where(request => (DateTime.UtcNow - request.SendingTime.GetValueOrDefault()).TotalSeconds >= 0)) { request.Status = (int)StatusRequest.Sent; listRequestUpdate.Add(request); systemEventService.Add(EventMessage.RequestSent, new Dictionary <EventMessageParam, string>() { { EventMessageParam.Request, request.RequestNo }, { EventMessageParam.Courier, request.Courier.User.LastName + " " + request.Courier.User.FirstName + (string.IsNullOrEmpty(request.Courier.User.MiddleName) ? "" : " " + request.Courier.User.MiddleName) } }); } var history = new List <RequestHistory>(); var listRequestExpired = requestService.Get(p => p.Status != (int)StatusRequest.Cancelled && p.Status != (int)StatusRequest.Completed && !(p.IsExpired ?? false)); foreach (var request in listRequestExpired.Where(request => (DateTime.UtcNow - request.CreatedOn.GetValueOrDefault()).TotalSeconds >= request.ExpiredTime.GetValueOrDefault(0))) { request.IsExpired = true; if (request.Courier.CurrentReq == request.Id) { request.Courier.CurrentReq = 0; } listRequestUpdate.Add(request); //add to history history.Add(new RequestHistory() { ActionType = (int)HistoryRequestActionType.Expired, Comment = "Request expired", CourierId = request.CourierId.GetValueOrDefault(), LastRequestStatus = request.Status, TimeChanged = DateTime.UtcNow, RequestId = request.Id }); systemEventService.Add(EventMessage.RequestExpired, new Dictionary <EventMessageParam, string>() { { EventMessageParam.Request, request.RequestNo }, { EventMessageParam.Courier, request.Courier.User.LastName + " " + request.Courier.User.FirstName + (string.IsNullOrEmpty(request.Courier.User.MiddleName) ? "" : " " + request.Courier.User.MiddleName) } }); } requestService.UpdateListRequestForService(listRequestUpdate); requestHistoryService.AddListRequestHistoryForWindowsService(history); } catch (Exception ex) { diagnosticService.Error(ex); } }
static public CacheServerConfig GetUpdatedCacheConfig(string cacheId, string partId, string newNode, ref ArrayList affectedNodes, bool isJoining) { if (FileName.Length == 0) { throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt"); } try { XmlConfigReader configReader = new XmlConfigReader(FileName, cacheId); CacheServerConfig config = configReader.GetConfigDom(); string list = config.Cluster.Channel.InitialHosts.ToLower(); string[] nodes = list.Split(','); if (isJoining) { foreach (string node in nodes) { string[] nodename = node.Split('['); affectedNodes.Add(nodename[0]); } if (list.IndexOf(newNode) == -1) { list = list + "," + newNode + "[" + config.Cluster.Channel.TcpPort + "]"; } } else { foreach (string node in nodes) { string[] nodename = node.Split('['); if (nodename[0] != newNode) { affectedNodes.Add(nodename[0]); } } list = string.Empty; foreach (string node in affectedNodes) { if (list.Length == 0) { list = node + "[" + config.Cluster.Channel.TcpPort + "]"; } else { list = list + "," + node + "[" + config.Cluster.Channel.TcpPort + "]"; } } } config.Cluster.Channel.InitialHosts = list; return(config); } catch (ManagementException) { throw; } catch (Exception e) { throw new ManagementException(e.Message, e); } }
public WebCrawlerModel() { IConfigReader configReader = new XmlConfigReader(); ConfigData = LoadApplicationConfig(configReader); }