// byte [] leak = new byte[50*1024*1024]; public SelectMeterTypeViewModel(Action <SelectMeterTypeResult> onComplete) { this.onComplete = onComplete; initializeCommands(); MeterTypes.Add("УРАН"); MeterTypes.Add("ИРВИ"); }
public string ImageDataPath( MeterTypes mt, BuiltInMeters bim = BuiltInMeters.Original) { int imt = (int)mt; int ibim = (int)bim; string mypath = DataFolder + "\\" + imt.ToString() + ibim.ToString() + ".bin"; return(mypath); }
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; }
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); } }
public ImageStructEx ImageStructExDeSerialize( MeterTypes mt, BuiltInMeters bim = BuiltInMeters.Original) { ImageStructEx ret = new ImageStructEx(); string folder = DataFolder; if (!System.IO.Directory.Exists(folder)) { return(defaultImageStruct()); } string imgpath = ImageFilePath(mt, bim); if (!System.IO.File.Exists(imgpath)) { return(defaultImageStruct()); } byte[] imgarray = File.ReadAllBytes(imgpath); byte[] dataarray = File.ReadAllBytes(ImageDataPath(mt, bim)); using (var ms = new MemoryStream(imgarray)) { ret.bitmap = new Bitmap(ms); } string structpath = ImageDataPath(mt, bim); if (!File.Exists(structpath)) { return(ret); } using (var file = File.OpenRead(structpath)) { var reader = new BinaryFormatter(); ret.data = (ImageStruct)reader.Deserialize(file); } return(ret); }
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(); } } } }