/// <summary> /// Add entry to the xml file. /// </summary> /// <param name="configItem">config item to add.</param> /// <returns>boolean for success/failure.</returns> public void AddEntry(IConfigItem configItem) { //throw new Exception("some error"); var key = WebUtility.HtmlEncode(configItem.key); var value = WebUtility.HtmlEncode(configItem.value); var attributes = new List <object> { new XAttribute(keyAttribute, key), new XAttribute(valueAttribute, value) }; if (configItem is ICustomConfigItem) { attributes.Add(new XAttribute(value2Attribute, ((ICustomConfigItem)configItem).value2)); } var newItem = new XElement(itemElement, attributes.ToArray()); var file = _xDocumentWrapper.Load(filePath); var root = file.Element(itemsElement); var items = root.Elements(itemElement); if (items.Any()) { items.Last().AddAfterSelf(newItem); } else { root.Add(newItem); } file.Save(filePath); }
private static Item CreateItem(byte[] convert, int i, IConfigItem config, bool placeFloor) { Item item; try { item = convert.ToClass <Item>(); } catch (Exception ex) { throw new Exception($"Failed to convert item {i}: {ex.Message}"); } if (!placeFloor) { if (!IsSaneItemForDrop(item) || convert.Length != Item.SIZE) { throw new Exception($"Unsupported item: {i}"); } } if (config.WrapAllItems && item.ShouldWrapItem() && !placeFloor) { item.SetWrapping(ItemWrapping.WrappingPaper, config.WrappingPaper, true); } return(item); }
private static void RunOnConfigDefault(IConfigItem configItem) { CrmServiceClient client = GetConnection(configItem); AssemblyLoaderCrm loader = new AssemblyLoaderCrm(new ConsoleLog(), configItem.Path, client, configItem.IsolationMode, configItem.SourceType); loader.Run(); }
private void AutomationWorker_DoWork() { List <Tuple <ushort, ushort> > tuples = new List <Tuple <ushort, ushort> >() { new Tuple <ushort, ushort>((ushort)PointType.DIGITAL_OUTPUT, (ushort)2000), new Tuple <ushort, ushort>((ushort)PointType.DIGITAL_OUTPUT, (ushort)2001), new Tuple <ushort, ushort>((ushort)PointType.ANALOG_OUTPUT, (ushort)1000) }; List <IPoint> points = storage.GetPoints(tuples); IConfigItem item = configuration.GetConfigurationItems().Find(x => x.StartAddress == 1000); while (!shutDown) { ushort value = points[2].RawValue; if (points[0].RawValue == 1) { value -= (ushort)EGUConverter.ConvertToRaw(item.A, item.B, 10); } if (points[1].RawValue == 1) { value -= (ushort)EGUConverter.ConvertToRaw(item.A, item.B, 15); } if (value != points[2].RawValue) { commandExecutor.CreateAndExecuteFunction(ModbusFunctionCode.WRITE_SINGLE_REGISTER, 1000, value); } Thread.Sleep(1000); } }
public PaymentAcknowledgeJob(IConfigItem item) : base() { string url = "", username = "", pass = ""; foreach (var i in item.GetChildren()) { if (i.ElementName == "serverUrl") { url = i.Value; } if (i.ElementName == "username") { username = i.Value; } if (i.ElementName == "password") { pass = i.Value; } } ftpClient = new FtpClient(url, username, pass); _dAL = Factory.GetDal(); }
public UssdRequestTranslatorCustom(IConfigItem config) { string url = config["prefix"].Value; _httpServer = new HttpServer(url, false); _httpServer.MessageReceived += RequestReceived; }
/// <summary> /// Executes a digital write command. /// </summary> /// <param name="configItem">The configuration item.</param> /// <param name="transactionId">The transaction identifier.</param> /// <param name="remoteUnitAddress">The remote unit address.</param> /// <param name="pointAddress">The point address.</param> /// <param name="value">The value.</param> private void ExecuteDigitalCommand(IConfigItem configItem, ushort transactionId, byte remoteUnitAddress, ushort pointAddress, int value) { ModbusWriteCommandParameters p = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_COIL, pointAddress, (ushort)value, transactionId, remoteUnitAddress); IModbusFunction fn = FunctionFactory.CreateModbusFunction(p); this.functionExecutor.EnqueueCommand(fn); }
/// <summary> /// Update entry in the configuration. /// </summary> /// <param name="key">key of the entry.</param> /// <param name="value">value to use when updating.</param> /// <returns>boolean of success/failure.</returns> public bool Update(IConfigItem configItem) { if (!_memoryCacheService.Contains(configItem.key)) { throw new KeyNotFoundException(string.Format("Configuration key not found {0}", configItem.key)); } if (Monitor.TryEnter(_lockObject)) { try { Thread.Sleep(5000); _memoryCacheService.Update(configItem); _fileManager.UpdateEntry(configItem); } catch (Exception e) { _memoryCacheService.Reset(configItem.key); throw new ConfigUpdateException(string.Format("Configuration update failed for key {0}", configItem.key)); } finally { Monitor.Exit(_lockObject); } } else { throw new ResourceLockedException(string.Format("Resource locked while updating config item {0}", configItem.key)); } return(true); }
private IScanner CreateScanner(IConfigItem config) { IScanPreprocessor preprocessor = CreateScanPreprocessor(); IHashProvider <string> hashProvider = CreateHashProvider(); string scannerNamespace = typeof(IScanner).Namespace; Type[] scannerTypes = config.Scanners .Select(scannerName => $"{scannerNamespace}.{scannerName}Scanner") .Select(scannerType => Type.GetType(scannerType)) .ToArray(); IScanner[] scanners = scannerTypes .Select(scannerType => (IScanner)Activator.CreateInstance(scannerType, config, preprocessor, hashProvider)) .ToArray(); if (scanners.Length > 1) { CompositeScanner compositeScanner = new CompositeScanner(); foreach (IScanner scanner in scanners) { compositeScanner.AddScanner(scanner); } return(compositeScanner); } if (scanners.Length == 1) { return(scanners.First()); } throw new ArgumentOutOfRangeException(nameof(config.Scanners)); }
private IAnalyzer CreateAnalyzer(IDecompiler decompiler, IConfigItem configItem) { IFileProvider fileProvider = CreateFileProvider(configItem); IScanner scanner = CreateScanner(configItem); return(new Analyzer(fileProvider, decompiler, scanner)); }
private void AutomationWorker_DoWork() { List <Tuple <ushort, ushort> > tuples = new List <Tuple <ushort, ushort> >() { new Tuple <ushort, ushort>((ushort)PointType.DIGITAL_INPUT, (ushort)1000), new Tuple <ushort, ushort>((ushort)PointType.DIGITAL_INPUT, (ushort)1001), new Tuple <ushort, ushort>((ushort)PointType.ANALOG_OUTPUT, (ushort)3000), new Tuple <ushort, ushort>((ushort)PointType.ANALOG_OUTPUT, (ushort)3001) }; List <IPoint> points = storage.GetPoints(tuples); IConfigItem AO = configuration.GetConfigurationItems().Find(x => x.StartAddress == 3000); while (!shutDown) { if (points[0].RawValue == 0 && points[1].RawValue == 1 && points[2].RawValue > EGUConverter.ConvertToRaw(AO.A, AO.B, 2000) && points[3].RawValue < EGUConverter.ConvertToRaw(AO.A, AO.B, 1500)) { commandExecutor.CreateAndExecuteFunction(ModbusFunctionCode.WRITE_SINGLE_COIL, 40, 1); commandExecutor.CreateAndExecuteFunction(ModbusFunctionCode.WRITE_SINGLE_REGISTER, 3000, (ushort)(points[2].RawValue - EGUConverter.ConvertToRaw(AO.A, AO.B, 10))); commandExecutor.CreateAndExecuteFunction(ModbusFunctionCode.WRITE_SINGLE_REGISTER, 3001, (ushort)(points[3].RawValue + EGUConverter.ConvertToRaw(AO.A, AO.B, 10))); } Thread.Sleep(2000); // don't burn CPU } }
/// <inheritdoc /> public void ExecuteReadCommand(IConfigItem configItem, ushort transactionId, byte remoteUnitAddress, ushort startAddress, ushort numberOfPoints) { ModbusReadCommandParameters p = new ModbusReadCommandParameters(6, (byte)GetReadFunctionCode(configItem.RegistryType), startAddress, numberOfPoints, transactionId, remoteUnitAddress); IModbusFunction fn = FunctionFactory.CreateModbusFunction(p); this.functionExecutor.EnqueueCommand(fn); }
/// <summary> /// Processes the alarm for digital point. /// </summary> /// <param name="state">The digital point state</param> /// <param name="configItem">The configuration item.</param> /// <returns>The alarm indication.</returns> public AlarmType GetAlarmForDigitalPoint(ushort state, IConfigItem configItem) { if (state == configItem.AbnormalValue) { return(AlarmType.ABNORMAL_VALUE); } return(AlarmType.NO_ALARM); }
/// <summary> /// Executes an analog write command. /// </summary> /// <param name="configItem">The configuration item.</param> /// <param name="transactionId">The transaction identifier.</param> /// <param name="remoteUnitAddress">The remote unit address.</param> /// <param name="pointAddress">The point address.</param> /// <param name="value">The value.</param> private void ExecuteAnalogCommand(IConfigItem configItem, ushort transactionId, byte remoteUnitAddress, ushort pointAddress, int value) { ushort raw = eguConverter.ConvertToRaw(configItem.ScaleFactor, configItem.Deviation, value); ModbusWriteCommandParameters p = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_REGISTER, pointAddress, (ushort)raw, transactionId, remoteUnitAddress); IModbusFunction fn = FunctionFactory.CreateModbusFunction(p); this.functionExecutor.EnqueueCommand(fn); }
public SmsRequestTranslatorCustom(IConfigItem config) { string ip = config["ip"].Value; string port = config["port"].Value; _httpServer = new HttpServer("http://" + ip + ":" + port + "/smsrequests/", false); _httpServer.MessageReceived += RequestReceived; }
public ConfigItem(IConfigItem configItem) { ConnectionString = configItem.ConnectionString; Force = configItem.Force; IsolationMode = configItem.IsolationMode; Path = configItem.Path; SourceType = configItem.SourceType; }
// public ConfigItemViewModel SelectedConfig { get; set; } private static CrmServiceClient GetConnection(IConfigItem confgiItem) { CrmServiceClient client = new CrmServiceClient(confgiItem.ConnectionString); if (!string.IsNullOrWhiteSpace(client.LastCrmError)) { throw new ApplicationException($"CrmServieClient initalization failed with error {client.LastCrmError}"); } return(client); }
public static AlarmType GetAlarmForDigitalPoint(ushort state, IConfigItem configItem) { if (state.Equals(configItem.AbnormalValue)) { return(AlarmType.ABNORMAL_VALUE); } else { return(AlarmType.NO_ALARM); } }
private static bool CheckReasonability(double eguValue, IConfigItem configItem) { if (eguValue <= configItem.EGU_Min || eguValue >= configItem.EGU_Max) { return(false); } else { return(true); } }
private static Item CreateItem(string name, int requestIndex, IConfigItem config, ItemDestination type, string lang = "en") { var item = GetItem(name, lang); if (item.IsNone) { throw new Exception($"Failed to convert item (index {requestIndex}: {name}) for Language {lang}."); } return(FinalizeItem(requestIndex, config, type, item)); }
/// <inheritdoc /> public void ExecuteWriteCommand(IConfigItem configItem, ushort transactionId, byte remoteUnitAddress, ushort pointAddress, int value) { if (configItem.RegistryType == PointType.ANALOG_OUTPUT) { ExecuteAnalogCommand(configItem, transactionId, remoteUnitAddress, pointAddress, value); } else { ExecuteDigitalCommand(configItem, transactionId, remoteUnitAddress, pointAddress, value); } }
static PersonBuilder() { CountryNameMapperConfig = ConfigBuilder.GetConfig <CountryNameMapper>(); var countryList = typeof(Country).ToList <Country>(); foreach (var country in countryList) { CountryNameMaps.Add(new CountryNameMap(country, CountryNameMapperConfig.Get())); } }
public static AlarmType GetAlarmForAnalogPoint(double eguValue, IConfigItem configItem) { if (CheckReasonability(eguValue, configItem)) { return(AlarmType.NO_ALARM); } else { return(AlarmType.REASONABILITY_FAILURE); } }
private static bool CheckReasonability(double eguValue, IConfigItem configItem) { //ovde izmenio bool rez = false; if (eguValue > configItem.EGU_Max || eguValue < configItem.EGU_Min) { rez = true; } return(rez); }
public BasePointItem(IConfigItem c, IProcessingManager processingManager, IStateUpdater stateUpdater, IConfiguration configuration, int i) { this.configItem = c; this.processingManager = processingManager; this.stateUpdater = stateUpdater; this.configuration = configuration; this.type = c.RegistryType; this.address = (ushort)(c.StartAddress + i); this.name = $"{configItem.Description} [{i}]"; this.rawValue = configItem.DefaultValue; this.pointId = PointIdentifierHelper.GetNewPointId(new PointIdentifier(this.type, this.address)); }
public PartsdatabaseItem GetItemById(object id) { IConfigItem dataItem = _GetItemById(id); if (dataItem != null) { return((PartsdatabaseItem)dataItem); } else { return(null); } }
private void InitConfigItem(IConfigItem item) { if (item.SaveAtStart) { SaveRegistryKey(item.Source); } if (item.RestoreAtStart) { //TODO: not implemented yet: check if the local registry keys throw new NotImplementedException("This functionality is not available yet"); } }
public SkuTestItem GetItemById(object id) { IConfigItem dataItem = _GetItemById(id); if (dataItem != null) { return((SkuTestItem)dataItem); } else { return(null); } }
private static int CheckAlarmility(double eguValue, IConfigItem configItem) { if (eguValue <= configItem.LowAlarm) { return(-1); } else if (eguValue >= configItem.HighAlarm) { return(1); } else { return(0); } }
public BasePointItem(IConfigItem c, IFunctionExecutor commandExecutor, IStateUpdater stateUpdater, IConfiguration configuration, int i) { this.configItem = c; this.commandExecutor = commandExecutor; this.stateUpdater = stateUpdater; this.configuration = configuration; this.type = c.RegistryType; this.address = (ushort)(c.StartAddress + i); this.gid = configItem.Gid; this.name = $"{configItem.Description}"; this.rawValue = configItem.DefaultValue; // commandExecutor.UpdatePointEvent += CommandExecutor_UpdatePointEvent; WriteCommand = new RelayCommand(WriteCommand_Execute, WriteCommand_CanExecute); ReadCommand = new RelayCommand(ReadCommand_Execute); }
public static void addLaunchsiteSetting(string name, IConfigItem conf) { launchsiteSettings.Add(name, conf); }
public static void addModelSetting(string name, IConfigItem conf) { modelSettings.Add(name, conf); }
public static void addInstanceSetting(string name, IConfigItem conf) { instanceSettings.Add(name, conf); }
public static void addNationSetting(string name, IConfigItem conf) { nationSettings.Add(name, conf); }