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(); } } } }
public async static Task ShowAlert( Exception e) { await Errors.GetInstance()._ShowAlert(e); }
public static void LogRegisteredErrors( bool forceException = false) { Errors.GetInstance()._LogRegisteredErrors(forceException); }
/// <summary> /// Used during the initialization process, when the app /// is not loaded yet and the error forces to close the app /// </summary> /// <param name="e">Exception that represents the last error happened</param> public static void LogErrorNowAndKill( Exception e) { Errors.GetInstance()._LogErrorNow(e, 1, false, true); // Port index has not importance in this case }
/// <summary> /// Registers a new error based on an ( own or .Net ) exception /// </summary> /// <param name="e">Exception that represents the last error happened</param> /// <param name="portIndex">MTU port index related</param> public static void AddError( Exception e, int portIndex = 1) { Errors.GetInstance().AddErrorByException(e, portIndex); }
/// <summary> /// Gets all errors registered to log, used from class Logger /// </summary> /// <returns>Array of registered errors</returns> /// <param name="clearList">Clear list of registered errors after being returned</param> public static Error[] GetErrorsToLog( bool clearList = true) { return(Errors.GetInstance()._GetErrorsToLog(clearList)); }