예제 #1
0
        private Configuration(string path = "")
        {
            mbase_path = (string.IsNullOrEmpty(path)) ? Mobile.GetPath() : path;

            device = "PC";
            Config config = new Config();

            mtuTypes   = config.GetMtu(Path.Combine(mbase_path, XML_MTUS));
            meterTypes = config.GetMeters(Path.Combine(mbase_path, XML_METERS));
            global     = config.GetGlobal(Path.Combine(mbase_path, XML_GLOBAL));
            interfaces = config.GetInterfaces(Path.Combine(mbase_path, XML_INTERFACE));
            alarms     = config.GetAlarms(Path.Combine(mbase_path, XML_ALARMS));
            demands    = config.GetDemandConf(Path.Combine(mbase_path, XML_DEMANDS));
            users      = config.GetUsers(Path.Combine(mbase_path, XML_USERS)).List;
            errors     = config.GetErrors(Path.Combine(mbase_path, XML_ERRORS)).List;
        }
예제 #2
0
        public static bool CheckLoadXML()
        {
            string configPath = Mobile.ConfigPath;

            try
            {
                // Load configuration files ( xml's )
                MtuTypes   auxMtus   = Utils.DeserializeXml <MtuTypes>(Path.Combine(configPath, XML_MTUS));
                MeterTypes auxMeters = Utils.DeserializeXml <MeterTypes>(Path.Combine(configPath, XML_METERS));
                Global     auxGlobal = Utils.DeserializeXml <Global>(Path.Combine(configPath, XML_GLOBAL));
                AlarmList  auxAlarm  = Utils.DeserializeXml <AlarmList>(Path.Combine(configPath, XML_ALARMS));
                DemandConf auxDemand = Utils.DeserializeXml <DemandConf>(Path.Combine(configPath, XML_DEMANDS));
                User[]     auxUsers  = Utils.DeserializeXml <UserList>(Path.Combine(configPath, XML_USERS)).List;
                return(true);
            }
            catch (Exception)
            {
                //throw new ConfigurationFilesCorruptedException();
                return(false);
            }
        }
예제 #3
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();
                    }
                }
            }
        }