Beispiel #1
0
 public LoggerEvent(Module module, ModuleParameter parameter)
 {
     this.Domain      = module.Domain;
     this.Address     = module.Address;
     this.Description = module.Name;
     this.Parameter   = parameter.Name;
     this.Value       = parameter.GetData(); // get the raw object value
     this.Date        = parameter.UpdateTime;
 }
Beispiel #2
0
        public ModuleParameter Parameter(string parameter)
        {
            var systemParameter = homegenie.Parameters.Find(delegate(ModuleParameter mp) { return mp.Name == parameter; });
            // create parameter if does not exists
            if (systemParameter == null)
            {
                systemParameter = new ModuleParameter() { Name = parameter };
                homegenie.Parameters.Add(systemParameter);
            }

            return systemParameter;
        }
Beispiel #3
0
        private void migService_InterfacePropertyChanged(object sender, InterfacePropertyChangedEventArgs args)
        {
            // look for module associated to this event
            Module module = Modules.Find(o => o.Domain == args.EventData.Domain && o.Address == args.EventData.Source);
            if (module != null && args.EventData.Property != "")
            {
                // clear RoutingNode property since the event was locally generated
                //if (module.RoutingNode != "")
                //{
                //    module.RoutingNode = "";
                //}
                // we found associated module in HomeGenie.Modules

                // Update/Add the module parameter as needed
                ModuleParameter parameter = null;
                try
                {
                    // Lookup for the existing module parameter
                    parameter = Utility.ModuleParameterGet(module, args.EventData.Property);
                    if (parameter == null)
                    {
                        parameter = new ModuleParameter() {
                            Name = args.EventData.Property,
                            Value = args.EventData.Value.ToString()
                        };
                        module.Properties.Add(parameter);
                        //parameter = Utility.ModuleParameterGet(module, args.EventData.Property);
                    }
                    else
                    {
                        parameter.Value = args.EventData.Value.ToString();
                    }
                }
                catch (Exception ex)
                {
                    LogError(ex);
                }
                // Prevent event pump from blocking on other worker tasks
                if (masterControlProgram != null)
                Utility.RunAsyncTask(() =>
                {
                    masterControlProgram.SignalPropertyChange(sender, module, args.EventData);
                });
            }
            else
            {
                if (args.EventData.Domain == Domains.MigService_Interfaces)
                {
                    modules_RefreshInterface(migService.GetInterface(args.EventData.Source));
                }
                /*
                LogBroadcastEvent(
                    args.EventData.Domain,
                    args.EventData.Source,
                    args.EventData.Description,
                    args.EventData.Property,
                    args.EventData.Value != null ? args.EventData.Value.ToString() : ""
                );
                */
            }
        }
Beispiel #4
0
        public void SignalModulePropertyChange(object sender, Module module, InterfacePropertyChangedAction propertyChangedAction)
        {
            // ROUTE THE EVENT TO AUTOMATION PROGRAMS, BEFORE COMMITTING THE CHANGE
            if (masterControlProgram != null)
            {
                ModuleParameter tempParam = new ModuleParameter() {
                    Name = propertyChangedAction.Path,
                    Value = propertyChangedAction.Value.ToString()
                };
                RoutedEvent eventData = new RoutedEvent() {
                    Sender = sender,
                    Module = module,
                    Parameter = tempParam
                };
                RouteParameterBeforeChangeEvent(eventData);
                // If the value has been manipulated by an automation program
                // so the event has to be updated as well
                if (tempParam.Value != propertyChangedAction.Value.ToString())
                {
                    HomeGenieService.LogEvent(Domains.HomeAutomation_HomeGenie, "ModuleParameterIsChanging(...)", "Parameter value manipulated by automation program", tempParam.Name, propertyChangedAction.Value.ToString() + " => " + tempParam.Value);
                    propertyChangedAction.Value = tempParam.Value;
                }
            }

            ModuleParameter parameter = null;
            try
            {
                // Lookup for the existing module parameter
                parameter = Utility.ModuleParameterGet(module, propertyChangedAction.Path);
                if (parameter == null)
                {
                    module.Properties.Add(new ModuleParameter() {
                        Name = propertyChangedAction.Path,
                        Value = propertyChangedAction.Value.ToString()
                    });
                    parameter = Utility.ModuleParameterGet(module, propertyChangedAction.Path);
                }
                else
                {
                    parameter.Value = propertyChangedAction.Value.ToString();
                }
            }
            catch (Exception ex)
            {
                //HomeGenieService.LogEvent(Domains.HomeAutomation_HomeGenie, "SignalModulePropertyChange(...)", ex.Message, "Exception.StackTrace", ex.StackTrace);
            }

            string eventValue = (propertyChangedAction.Value.GetType() == typeof(String) ? propertyChangedAction.Value.ToString() : JsonConvert.SerializeObject(propertyChangedAction.Value));
            LogBroadcastEvent(
                propertyChangedAction.Domain,
                propertyChangedAction.SourceId,
                propertyChangedAction.SourceType,
                propertyChangedAction.Path,
                eventValue
            );

            // ROUTE EVENT TO LISTENING AutomationPrograms
            if (masterControlProgram != null)
            {
                RoutedEvent eventData = new RoutedEvent() {
                    Sender = sender,
                    Module = module,
                    Parameter = parameter
                };
                //RouteParameterChangedEvent(eventData);
                ThreadPool.QueueUserWorkItem(new WaitCallback(RouteParameterChangedEvent), eventData);
            }
        }
Beispiel #5
0
 public ModuleEvent(Module module, ModuleParameter parameter)
 {
     this.Module    = module;
     this.Parameter = parameter;
 }
Beispiel #6
0
        public void SignalPropertyChange(object sender, Module module, MigEvent eventData)
        {
            // ROUTE THE EVENT TO AUTOMATION PROGRAMS, BEFORE COMMITTING THE CHANGE
            var tempParam = new ModuleParameter() {
                Name = eventData.Property,
                Value = eventData.Value.ToString()
            };
            var routedEvent = new RoutedEvent() {
                Sender = sender,
                Module = module,
                Parameter = tempParam
            };

            // Route event to Programs->ModuleIsChangingHandler
            RoutePropertyBeforeChangeEvent(routedEvent);

            // If the value has been manipulated by an automation program
            // so the event has to be updated as well
            if (tempParam.Value != eventData.Value.ToString())
            {
                MigService.Log.Debug("Parameter value manipulated by automation program (Name={0}, OldValue={1}, NewValue={2})", tempParam.Name, eventData.Value.ToString(), tempParam.Value);
                // Update the event value to the new value
                eventData.Value = tempParam.Value;
            }

            // Route event to Programs->ModuleIsChangingHandler
            ThreadPool.QueueUserWorkItem(new WaitCallback(RoutePropertyChangedEvent), routedEvent);
        }
Beispiel #7
0
        private bool VerifyCondition(ProgramCondition c)
        {
            bool returnValue = false;
            string comparisonValue = c.ComparisonValue;
            //
            if (c.Domain == Domains.HomeAutomation_HomeGenie && c.Target == "Automation" && (c.Property == "Scheduler.TimeEvent" || c.Property == "Scheduler.CronEvent"))
            {
                return homegenie.ProgramManager.SchedulerService.IsScheduling(c.ComparisonValue);
            }
            //
            // if the comparison value starts with ":", then the value is read from another module property
            // eg: ":HomeAutomation.X10/B3/Level"
            if (comparisonValue.StartsWith(":"))
            {
                string[] propertyPath = comparisonValue.Substring(1).Split('/');
                comparisonValue = "";
                if (propertyPath.Length >= 3)
                {
                    string domain = propertyPath[0];
                    string address = propertyPath[1];
                    string propertyName = propertyPath[2];
                    var targetModule = homegenie.Modules.Find(m => m.Domain == domain && m.Address == address);
                    if (targetModule == null)
                    {
                        // abbreviated path, eg: ":X10/B3/Level"
                        targetModule = homegenie.Modules.Find(m => m.Domain.EndsWith("." + domain) && m.Address == address);
                    }
                    //
                    if (targetModule != null)
                    {
                        var mprop = Utility.ModuleParameterGet(targetModule, propertyName);
                        if (mprop != null)
                        {
                            comparisonValue = mprop.Value;
                        }
                    }
                }
            }
            //
            // the following "Programs.*" parameters are deprecated, just left for compatibility with HG < r340
            // Also the target "Automation" is deprecated and left for compatibility with HG < 499
            //
            ModuleParameter parameter = null;
            if (c.Domain == Domains.HomeAutomation_HomeGenie && (c.Target == SourceModule.Scheduler || c.Target == "Automation"))
            {
                parameter = new ModuleParameter();
                parameter.Name = c.Property;
                switch (parameter.Name)
                {
                case "Programs.DateDay":
                case "Scheduler.DateDay":
                    parameter.Value = DateTime.Now.Day.ToString();
                    break;
                case "Programs.DateMonth":
                case "Scheduler.DateMonth":
                    parameter.Value = DateTime.Now.Month.ToString();
                    break;
                case "Programs.DateDayOfWeek":
                case "Scheduler.DateDayOfWeek":
                    parameter.Value = ((int)DateTime.Now.DayOfWeek).ToString();
                    break;
                case "Programs.DateYear":
                case "Scheduler.DateYear":
                    parameter.Value = DateTime.Now.Year.ToString();
                    break;
                case "Programs.DateHour":
                case "Scheduler.DateHour":
                    parameter.Value = DateTime.Now.Hour.ToString();
                    break;
                case "Programs.DateMinute":
                case "Scheduler.DateMinute":
                    parameter.Value = DateTime.Now.Minute.ToString();
                    break;
                case "Programs.Date":
                case "Scheduler.Date":
                    parameter.Value = DateTime.Now.ToString("YY-MM-dd");
                    break;
                case "Programs.Time":
                case "Scheduler.Time":
                    parameter.Value = DateTime.Now.ToString("HH:mm:ss");
                    break;
                case "Programs.DateTime":
                case "Scheduler.DateTime":
                    parameter.Value = DateTime.Now.ToString("YY-MM-dd HH:mm:ss");
                    break;
                //default:
                //    Module module = homegenie.Modules.Find(m => m.Address == c.Target && m.Domain == c.Domain);
                //    if (module != null)
                //        parameter = module.Properties.Find(mp => mp.Name == c.Property);
                //    break;
                }
            }
            else
            {
                Module module = homegenie.Modules.Find(m => m.Address == c.Target && m.Domain == c.Domain);
                if (module != null)
                    parameter = module.Properties.Find(mp => mp.Name == c.Property);
            }

            if (parameter != null)
            {
                IComparable lvalue = parameter.Value;
                IComparable rvalue = comparisonValue;
                //
                double dval = 0;
                DateTime dtval = new DateTime();
                //
                if (double.TryParse(parameter.Value.Replace(",", "."), NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out dval))
                {
                    lvalue = dval;
                    rvalue = double.Parse(comparisonValue.Replace(",", "."), NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                }
                else if (DateTime.TryParse(parameter.Value, out dtval))
                {
                    lvalue = dtval;
                    rvalue = DateTime.Parse(comparisonValue);
                }
                //
                int comparisonresult = lvalue.CompareTo(rvalue);
                if (c.ComparisonOperator == ComparisonOperator.LessThan && comparisonresult < 0)
                {
                    returnValue = true;
                }
                else if (c.ComparisonOperator == ComparisonOperator.Equals && comparisonresult == 0)
                {
                    returnValue = true;
                }
                else if (c.ComparisonOperator == ComparisonOperator.GreaterThan && comparisonresult > 0)
                {
                    returnValue = true;
                }
            }
            return returnValue;
        }
Beispiel #8
0
 //TODO: add autodoc comment (HG Event forwarding)
 public NetHelper SignalModuleEvent(string hgAddress, ModuleHelper module, ModuleParameter parameter)
 {
     string eventRouteUrl = "http://" + hgAddress + "/api/" + Domains.HomeAutomation_HomeGenie + "/Interconnection/Events.Push/" + homegenie.GetHttpServicePort();
     // propagate event to remote hg endpoint
     Utility.RunAsyncTask(() =>
     {
         this.WebService(eventRouteUrl)
         .Put(JsonConvert.SerializeObject(new ModuleEvent(module.SelectedModules[0], parameter), new JsonSerializerSettings(){ Culture = System.Globalization.CultureInfo.InvariantCulture }))
         .Call();
     });
     return this;
 }
        public void SignalPropertyChange(object sender, Module module, MigEvent eventData)
        {
            ModuleParameter parameter = null;
            try
            {
                // Lookup for the existing module parameter
                parameter = Utility.ModuleParameterGet(module, eventData.Property);
                if (parameter == null)
                {
                    parameter = new ModuleParameter() {
                        Name = eventData.Property,
                        Value = eventData.Value.ToString()
                    };
                    module.Properties.Add(parameter);
                }
                else
                {
                    parameter.Value = eventData.Value.ToString();
                }
            }
            catch (Exception ex)
            {
                HomeGenieService.LogError(ex);
            }

            var routedEvent = new RoutedEvent() {
                Sender = sender,
                Module = module,
                Parameter = parameter
            };

            // Route event to Programs->ModuleIsChangingHandler
            if (RoutePropertyBeforeChangeEvent(routedEvent))
            {
                // Route event to Programs->ModuleChangedHandler
                ThreadPool.QueueUserWorkItem(new WaitCallback(RoutePropertyChangedEvent), routedEvent);
            }
        }
Beispiel #10
0
 public ModuleEvent(Module module, ModuleParameter parameter)
 {
     this.Module = module;
     this.Parameter = parameter;
 }
 public ModuleEvent(Module m, ModuleParameter p)
 {
     this.Module    = m;
     this.Parameter = p;
 }
Beispiel #12
0
 public NetHelper SignalModuleEvent(string hgAddress, ModuleHelper module, ModuleParameter parameter)
 {
     string eventRouteUrl = "http://" + hgAddress + "/api/HomeAutomation.HomeGenie/Interconnection/Events.Push/" + homegenie.GetHttpServicePort();
     // propagate event to remote hg endpoint
     this.WebService(eventRouteUrl)
       .Put(JsonConvert.SerializeObject(new ModuleEvent(module.SelectedModules[0], parameter)))
       .CallAsync();
     return this;
 }