protected override void LoadSessionConfigurationFromJson(string json)
 {
     if (PluginName == PluginsSection.GoosePub)
     {
         _sessionSpecific = JsonConvert.DeserializeObject <GooseSubSpecificConfig>(json);
     }
     else
     {
         _sessionSpecific = JsonConvert.DeserializeObject <GoosePubSpecificConfig>(json);
     }
 }
        protected override void LoadSessionConfigurationFromJson(string json)
        {
            if (PluginName == PluginsSection.Dnp3Master)
            {
                try
                {
                    _sessionSpecific = JsonConvert.DeserializeObject <Dnp3MasterSpecificConfig>(json);
                }
                catch (Exception ex)
                {
                    // older version
                    _logger.Log(Level.Error, ex.Message, ex);
                    _logger.Log(Level.Info, "Unable to parse session configuration.  Will try to parse manually.");

                    var jsonObject = JsonConvert.DeserializeObject(json) as JObject;

                    if (jsonObject.ContainsKey("channel"))
                    {
                        var channel = jsonObject["channel"] as JObject;
                        if (channel != null)
                        {
                            if (channel.ContainsKey("port"))
                            {
                                var port = channel["port"].ToString();
                                int temp;
                                if (!int.TryParse(port, out temp))
                                {
                                    channel["port"] = new JValue(20000);
                                }
                            }
                        }
                    }

                    json = JsonConvert.SerializeObject(jsonObject);
                    try
                    {
                        _sessionSpecific = JsonConvert.DeserializeObject <Dnp3MasterSpecificConfig>(json);
                    }
                    catch { }
                }
            }
            else
            {
                try
                {
                    _sessionSpecific = JsonConvert.DeserializeObject <Dnp3OutstationSpecificConfig>(json);
                }
                catch (Exception ex)
                {
                    _logger.Log(Level.Error, ex.Message, ex);
                }
            }
        }
Exemplo n.º 3
0
 protected override void LoadSessionConfigurationFromJson(string json)
 {
     try
     {
         if (PluginName == PluginsSection.IccpClient)
         {
             _sessionSpecific = JsonConvert.DeserializeObject <IccpClientSpecificConfig>(json);
         }
         else
         {
             _sessionSpecific = JsonConvert.DeserializeObject <IccpServerSpecificConfig>(json);
         }
     }
     catch (Exception ex)
     {
         _logger.Log(Level.Error, ex.Message, ex);
     }
 }
Exemplo n.º 4
0
        protected override void LoadSessionConfigurationFromJson(string json)
        {
            if (PluginName == PluginsSection.ModbusMaster)
            {
                try
                {
                    _sessionSpecific = JsonConvert.DeserializeObject <ModbusMasterSpecificConfig>(json);
                }
                catch (Exception ex)
                {
                    _logger.Log(Level.Error, ex.Message, ex);
                    _logger.Log(Level.Info, "Unable to parse session configuration.  Will try to parse manually.");

                    ModbusMasterSpecificConfig config = new ModbusMasterSpecificConfig();

                    var jsonObject = JsonConvert.DeserializeObject(json) as JObject;

                    if (jsonObject.ContainsKey("name"))
                    {
                        config.Name = jsonObject["name"].ToString();
                    }
                    if (jsonObject.ContainsKey("log-level"))
                    {
                        LogLevel level;
                        if (Enum.TryParse(jsonObject["log-level"].ToString(), out level))
                        {
                            config.LogLevel = level;
                        }
                    }
                    if (jsonObject.ContainsKey("remote-ip"))
                    {
                        config.Name = jsonObject["remote-ip"].ToString();
                    }
                    if (jsonObject.ContainsKey("port"))
                    {
                        int port;
                        if (int.TryParse(jsonObject["name"].ToString(), out port))
                        {
                            config.Port = port;
                        }
                    }
                    if (jsonObject.ContainsKey("adapter"))
                    {
                        config.Name = jsonObject["adapter"].ToString();
                    }

                    if (jsonObject.ContainsKey("unit-identifier"))
                    {
                        int id;
                        if (int.TryParse(jsonObject["unit-identifier"].ToString(), out id))
                        {
                            config.UnitIdentifier = id;
                        }
                    }

                    if (jsonObject.ContainsKey("response_timeout_ms"))
                    {
                        int id;
                        if (int.TryParse(jsonObject["response_timeout_ms"].ToString(), out id))
                        {
                            config.ResponseTimeout = id;
                        }
                    }

                    if (jsonObject.ContainsKey("always-write-multiple-registers"))
                    {
                        config.AlwaysWriteMultipleRegisters = jsonObject["always-write-multiple-registers"].ToString().ToLower() == "true" ? true : false;
                    }

                    if (jsonObject.ContainsKey("auto_polling"))
                    {
                        var autoPolling = jsonObject["auto_polling"] as JObject;
                        if (autoPolling != null)
                        {
                            if (autoPolling.ContainsKey("max_register_gaps"))
                            {
                                int id;
                                if (int.TryParse(autoPolling["max_register_gaps"].ToString(), out id))
                                {
                                    config.AutoPollingMaxRegisterGaps = id;
                                }
                            }
                            if (autoPolling.ContainsKey("max_bit_gaps"))
                            {
                                int id;
                                if (int.TryParse(autoPolling["max_bit_gaps"].ToString(), out id))
                                {
                                    config.AutoPollingMaxBitGaps = id;
                                }
                            }
                        }
                    }

                    if (jsonObject.ContainsKey("heartbeats"))
                    {
                        var heartbeats = jsonObject["heartbeats"] as JArray;
                        if (heartbeats != null)
                        {
                            foreach (JObject h in heartbeats)
                            {
                                var hb = new HeartBeat();
                                if (h.ContainsKey("index"))
                                {
                                    int id;
                                    if (int.TryParse(h["index"].ToString(), out id))
                                    {
                                        hb.Index = id;
                                    }
                                }
                                if (h.ContainsKey("period_ms"))
                                {
                                    int id;
                                    if (int.TryParse(h["period_ms"].ToString(), out id))
                                    {
                                        hb.PeriodMs = id;
                                    }
                                }
                                if (h.ContainsKey("mask"))
                                {
                                    var value = h["mask"].ToString();
                                    hb.Mask = NumberConverter.ToInteger(value);
                                }
                                config.HeartBeats.Add(hb);
                            }
                        }
                    }

                    _sessionSpecific = config;
                }
            }
            else
            {
                try
                {
                    _sessionSpecific = JsonConvert.DeserializeObject <ModbusOutstationSpecificConfig>(json);
                }
                catch (Exception ex)
                {
                    _logger.Log(Level.Error, ex.Message, ex);
                }
            }
        }