public string RoutingNode { get; set; } // "<ip>:<port>" || "" // public Module() { Name = ""; Address = ""; Description = ""; DeviceType = MIG.ModuleTypes.Generic; Properties = new TsList<ModuleParameter>(); RoutingNode = ""; }
public ValueStatistics() { LastProcessedTimestap = DateTime.UtcNow; statValues = new List<StatValue>(); statValues.Add(new StatValue(0, LastProcessedTimestap)); lastEvent = lastOn = lastOff = new StatValue(0, LastProcessedTimestap); historyValues = new TsList<StatValue>(); historyValues.Add(lastEvent); }
public Module() { Name = ""; Address = ""; Description = ""; DeviceType = MIG.ModuleTypes.Generic; Properties = new TsList <ModuleParameter>(); Stores = new TsList <Store>(); }
public ValueStatistics() { LastProcessedTimestap = DateTime.UtcNow; statValues = new List <StatValue>(); statValues.Add(new StatValue(0, LastProcessedTimestap)); lastEvent = lastOn = lastOff = new StatValue(0, LastProcessedTimestap); historyValues = new TsList <StatValue>(); historyValues.Add(lastEvent); }
} // "<ip>:<port>" || "" // public Module() { Name = ""; Address = ""; Description = ""; Type = Types.Generic; DeviceType = DeviceTypes.Generic; Properties = new TsList <ModuleParameter>(); RoutingNode = ""; }
private void _loginterval_Elapsed(object sender, ElapsedEventArgs e) { DateTime logend = DateTime.UtcNow; TsList <Module> modules = (TsList <Module>)_homegenie.Modules; //.Clone(); foreach (Module m in modules) { foreach (ModuleParameter mp in m.Properties) { // enntry counter if (mp.Statistics.Values.Count > 0) { List <ValueStatistics.StatValue> values = mp.Statistics.Values.FindAll(sv => (sv.Timestamp.Ticks <= logend.Ticks && sv.Timestamp.Ticks > mp.Statistics.LastProcessedTimestap.Ticks)); // if (values.Count > 0) { TimeSpan trange = new TimeSpan(logend.Ticks - mp.Statistics.LastProcessedTimestap.Ticks); double average = (values.Sum(d => d.Value) / values.Count); // //TODO: check db file age/size for archiving old data // string dbname = _getStatisticsDatabaseName(); FileInfo fi = new FileInfo(dbname); if (fi.Length > _dbsizelimit) // 5Mb limit for stats - temporary limitations to get rid of in the future { _resetStatisticsDatabase(); } // try { SQLiteCommand dbcmd = _dbconnection.CreateCommand(); // "TimeStart","TimeEnd","Domain","Address","Parameter","AverageValue" dbcmd.CommandText = "INSERT INTO ValuesHist VALUES ('" + _dateTimeSQLite(mp.Statistics.LastProcessedTimestap) + "','" + _dateTimeSQLite(logend) + "','" + m.Domain + "','" + m.Address + "','" + mp.Name + "'," + average.ToString(System.Globalization.CultureInfo.InvariantCulture) + ")"; dbcmd.ExecuteNonQuery(); } catch (Exception ex) { HomeGenieService.LogEvent(Domains.HomeAutomation_HomeGenie, "Service.StatisticsLogger", ex.Message, "Exception.StackTrace", ex.StackTrace); } // mp.Statistics.LastProcessedTimestap = logend; //Console.WriteLine("Average value: " + average); //Console.WriteLine("Time range: " + trange.TotalSeconds); mp.Statistics.Values.Clear(); } } } } }
private void LoadModules() { try { var serializer = new XmlSerializer(typeof(HomeGenie.Service.TsList<Module>)); using (var reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "modules.xml"))) { var modules = (HomeGenie.Service.TsList<Module>)serializer.Deserialize(reader); foreach (var module in modules) { foreach (var parameter in module.Properties) { try { if (!String.IsNullOrEmpty(parameter.Value)) parameter.Value = StringCipher.Decrypt( parameter.Value, GetPassPhrase() ); } catch { } } } modulesGarbage.Clear(); systemModules.Clear(); systemModules = modules; } } catch (Exception ex) { LogError( Domains.HomeAutomation_HomeGenie, "LoadModules()", ex.Message, "Exception.StackTrace", ex.StackTrace ); } try { // Reset Parameter.Watts, /*Status Level,*/ Sensor.Generic values for (int m = 0; m < systemModules.Count; m++) { // cleanup stuff for unwanted xsi:nil="true" empty params systemModules[m].Properties.RemoveAll(p => p == null); ModuleParameter parameter = systemModules[m].Properties.Find(mp => mp.Name == Properties.MeterWatts /*|| mp.Name == Properties.STATUS_LEVEL || mp.Name == Properties.SENSOR_GENERIC */); if (parameter != null) parameter.Value = "0"; } } catch (Exception ex) { LogError( Domains.HomeAutomation_HomeGenie, "LoadModules()", ex.Message, "Exception.StackTrace", ex.StackTrace ); } // Force re-generation of Modules list modules_RefreshAll(); }
private void SetupLogging() { recentEventsLog = new TsList<LogEntry>(); Console.OutputEncoding = Encoding.UTF8; var outputRedirect = new ConsoleRedirect(); outputRedirect.ProcessOutput = (outputLine) => { LogBroadcastEvent(Domains.HomeGenie_System, "Console", "StdOut/StdErr redirect", "Console.Output", outputLine); }; Console.SetOut(outputRedirect); Console.SetError(outputRedirect); }
private void LoadModules() { try { var serializer = new XmlSerializer(typeof(HomeGenie.Service.TsList<Module>)); var reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "modules.xml")); HomeGenie.Service.TsList<Module> modules = (HomeGenie.Service.TsList<Module>)serializer.Deserialize(reader); // foreach (var module in modules) { foreach (var parameter in module.Properties) { try { if (!String.IsNullOrEmpty(parameter.Value)) parameter.Value = StringCipher.Decrypt( parameter.Value, systemConfiguration.GetPassPhrase() ); } catch { } } } // reader.Close(); // modulesGarbage.Clear(); systemModules.Clear(); systemModules = modules; } catch (Exception ex) { HomeGenieService.LogEvent( Domains.HomeAutomation_HomeGenie, "LoadModules()", ex.Message, "Exception.StackTrace", ex.StackTrace ); } try { // // reset Parameter.Watts, /*Status Level,*/ Sensor.Generic values // for (int m = 0; m < systemModules.Count; m++) { // cleanup stuff for unwanted xsi:nil="true" empty params systemModules[m].Properties.RemoveAll(p => p == null); // ModuleParameter parameter = null; parameter = systemModules[m].Properties.Find(delegate(ModuleParameter mp) { return mp.Name == ModuleParameters.MODPAR_METER_WATTS /*|| mp.Name == ModuleParameters.MODPAR_STATUS_LEVEL*/ || mp.Name == ModuleParameters.MODPAR_SENSOR_GENERIC; }); if (parameter != null) { parameter.Value = "0"; //parameter.UpdateTime = DateTime.UtcNow; } } } catch (Exception ex) { HomeGenieService.LogEvent( Domains.HomeAutomation_HomeGenie, "LoadModules()", ex.Message, "Exception.StackTrace", ex.StackTrace ); } // // force re-generation of Modules list modules_RefreshAll(); }
public HomeGenieService() { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); // TODO: all the following initialization stuff should go async // // initialize recent log list recentEventsLog = new TsList<LogEntry>(); #region MIG Service initialization and startup // // initialize MIGService, interfaces (hw controllers drivers), webservice migService = new MIG.MIGService(); migService.InterfaceModulesChanged += migService_InterfaceModulesChanged; migService.InterfacePropertyChanged += migService_InterfacePropertyChanged; migService.ServiceRequestPreProcess += migService_ServiceRequestPreProcess; migService.ServiceRequestPostProcess += migService_ServiceRequestPostProcess; // // load system configuration systemConfiguration = new SystemConfiguration(); systemConfiguration.HomeGenie.ServicePort = 8080; systemConfiguration.OnUpdate += systemConfiguration_OnUpdate; LoadSystemConfig(); // // setup web service handlers wshConfig = new Handlers.Config(this); wshAutomation = new Handlers.Automation(this); wshInterconnection = new Handlers.Interconnection(this); wshStatistics = new Handlers.Statistics(this); wshLogging = new Handlers.Logging(this); // // Try to start WebGateway, if default HTTP port is busy, then it will try from 8080 to 8090 bool serviceStarted = false; int bindAttempts = 0; int port = systemConfiguration.HomeGenie.ServicePort; while (!serviceStarted && bindAttempts <= 10) { // TODO: this should be done like this _services.Gateways["WebService"].Configure(....) migService.ConfigureWebGateway( port, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "html"), "/hg/html", systemConfiguration.HomeGenie.UserPassword ); if (migService.StartGateways()) { systemConfiguration.HomeGenie.ServicePort = port; serviceStarted = true; } else { if (port < 8080) port = 8080; else port++; bindAttempts++; } } #endregion MIG Service initialization and startup // // If we successfully bound to port, then initialize the database. if (serviceStarted) { LogBroadcastEvent( Domains.HomeAutomation_HomeGenie, "SystemInfo", "HomeGenie service ready", "HTTP.PORT", port.ToString() ); systemConfiguration.HomeGenie.ServicePort = port; InitializeSystem(); } else { LogBroadcastEvent( Domains.HomeAutomation_HomeGenie, "SystemInfo", "Http port bind failed.", "HTTP.PORT", port.ToString() ); Program.Quit(false); } updateChecker = new UpdateChecker(this); updateChecker.ArchiveDownloadUpdate += (object sender, ArchiveDownloadEventArgs args) => { LogBroadcastEvent( Domains.HomeGenie_UpdateChecker, "0", "HomeGenie Update Checker", "InstallProgress.Message", "= " + args.Status + ": " + args.ReleaseInfo.DownloadUrl ); }; updateChecker.UpdateProgress += (object sender, UpdateProgressEventArgs args) => { LogBroadcastEvent( Domains.HomeGenie_UpdateChecker, "0", "HomeGenie Update Checker", "Update Check", args.Status.ToString() ); }; updateChecker.InstallProgressMessage += (object sender, string message) => { LogBroadcastEvent( Domains.HomeGenie_UpdateChecker, "0", "HomeGenie Update Checker", "InstallProgress.Message", message ); }; // it will check every 24 hours updateChecker.Start(); // statisticsLogger = new StatisticsLogger(this); statisticsLogger.Start(); // // Setup local UPnP device SetupUpnp(); // Start(); }
public Store(string name, string description = "") { this.Name = name; this.Description = description; this.Data = new TsList <ModuleParameter>(); }
public Store() { this.Name = ""; this.Description = ""; this.Data = new TsList <ModuleParameter>(); }
public StoreHelper(TsList <Store> storageList, string storeName) { this.storeList = storageList; this.storeName = storeName; }
public StoreHelper(TsList<Store> storageList, string storeName) { this.storeList = storageList; this.storeName = storeName; }
public Store(string name, string description = "") { this.Name = name; this.Description = description; this.Data = new TsList<ModuleParameter>(); }
public Store() { this.Name = ""; this.Description = ""; this.Data = new TsList<ModuleParameter>(); }