Example #1
0
        private Configuration(string path = "", bool avoidXmlError = false)
        {
            string configPath = Mobile.ConfigPath;

            device = "PC";

            try
            {
                // Load configuration files ( xml's )
                mtuTypes   = Utils.DeserializeXml <MtuTypes>        (Path.Combine(configPath, XML_MTUS));
                meterTypes = Utils.DeserializeXml <MeterTypes>      (Path.Combine(configPath, XML_METERS));
                Global     = Utils.DeserializeXml <Global>          (Path.Combine(configPath, XML_GLOBAL));
                alarms     = Utils.DeserializeXml <AlarmList>       (Path.Combine(configPath, XML_ALARMS));
                demands    = Utils.DeserializeXml <DemandConf>      (Path.Combine(configPath, XML_DEMANDS));
                users      = Utils.DeserializeXml <UserList>        (Path.Combine(configPath, XML_USERS)).List;
                interfaces = Utils.DeserializeXml <InterfaceConfig> (XML_INTERFACE, true);  // From resources

                // Preload port types, because some ports use a letter but other a list of Meter IDs
                // Done here because Xml project has no reference to MTUComm ( cross references )
                List <string> portTypes;
                foreach (Mtu mtu in mtuTypes.Mtus)
                {
                    foreach (Port port in mtu.Ports)
                    {
                        bool isNumeric = MeterAux.GetPortTypes(port.Type, out portTypes);

                        if (!isNumeric)
                        {
                            port.TypeString = portTypes[0];
                        }
                        else
                        {
                            port.TypeString = meterTypes.FindByMterId(int.Parse(portTypes[0])).Type;
                        }

                        Utils.Print("MTU " + mtu.Id + ": Type " + port.TypeString);
                    }
                }

                // Regenerate certificate from base64 string
                Mobile.configData.GenerateCert();
                //Mobile.configData.LoadCertFromKeychain ();

                // Check global min date allowed
                if (!string.IsNullOrEmpty(Global.MinDate) &&
                    DateTime.Compare(DateTime.ParseExact(Global.MinDate, "MM/dd/yyyy", null), DateTime.Today) < 0)
                {
                    throw new DeviceMinDateAllowedException();
                }
            }
            catch (Exception e)
            {
                if (!avoidXmlError)
                {
                    if (Errors.IsOwnException(e))
                    {
                        throw e;
                    }
                    else if (e is FileNotFoundException)
                    {
                        throw new ConfigurationFilesNotFoundException();
                    }
                    else
                    {
                        throw new ConfigurationFilesCorruptedException();
                    }
                }
            }
        }
Example #2
0
 public Meter getMeterTypeById(int meterId)
 {
     return(meterTypes.FindByMterId(meterId));
 }