Example #1
0
 /// <summary>
 /// Standard constructor, used by configuration loader.
 /// </summary>
 /// <param name="id">Id of the command.</param>
 /// <param name="onFunctionError">True, if command shall be executed in case of an error.</param>
 /// <param name="onFunctionStart">True, if command shall be executed at function start.</param>
 /// <param name="onFunctionEnd">True, if command shall be executed at function end.</param>
 /// <param name="onValidityStart">True, if command shall be executed at validity start.</param>
 /// <param name="onValidityEnd">True, if command shall be executed at validity end.</param>
 /// <param name="onUnix">True, if command shall be exceuted on Unix systems. Default=True</param>
 /// <param name="onWindows">True, if command shall be executed on Windows systems. Default=True</param>
 /// <param name="sourceId">Source Id, on which to play the sound.</param>
 /// <param name="url">URL to play.</param>
 public PlaySoundCommand(SimpleId id, bool onFunctionError, bool onFunctionStart, bool onFunctionEnd, bool onValidityStart, bool onValidityEnd, bool onUnix, bool onWindows,
                         Address sourceId, string url)
     : base(id, eCommand.PlaySound, onFunctionError, onFunctionStart, onFunctionEnd, onValidityStart, onValidityEnd, onUnix, onWindows)
 {
     _sourceId = sourceId;
     _url      = url;
 }
Example #2
0
        public static IParsingResult Parse(ParsingContext context)
        {
            RewindState    rewind = context.RewindState;
            IParsingResult name   = SimpleId.Parse(context);

            if (name != null)
            {
                return(name);
            }
            if (context.Parser.VerifyString("on"))
            {
                IParsingResult operatorName = OperatorName.Parse(context);

                if (operatorName != null)
                {
                    IParsingResult arguments = TemplateArgs.Parse(context);

                    return(new Operator(operatorName, arguments));
                }
                context.Rewind(rewind);
                return(null);
            }
            if (context.Parser.VerifyString("dn"))
            {
                return(DestructorName.Parse(context));
            }
            return(null);
        }
Example #3
0
 /// <summary>
 /// Standard constructor, called by configuration loader (with command section) V2.0
 /// </summary>
 /// <param name="id">The function id.</param>
 /// <param name="zoneId">The address of the zone, which this function is applied for.</param>
 /// <param name="sleepDuration">The duration of the sleep function.</param>
 /// <param name="validFrom">Start time in which a sleep function can be triggered.</param>
 /// <param name="validTo">End time in which a sleep function can be triggered.</param>
 /// <param name="commands">List of commands, to be executed by this function.</param>
 public SleepFunction(SimpleId id, Address zoneId, TimeSpan sleepDuration, TimeSpan validFrom, TimeSpan validTo, List <Command> commands)
     : base(id, zoneId, commands)
 {
     this._sleepDuration = sleepDuration;
     this._validFrom     = validFrom;
     this._validTo       = validTo;
 }
        public void calculateFunctionTest2()
        {
            SleepFunction function = new SleepFunction(SimpleId.NewGuid(), new Address(100, 1),
                                                       new TimeSpan(1, 0, 0), new TimeSpan(0, 0, 0), new TimeSpan(23, 59, 59));
            ZoneServerMock zoneServer = new ZoneServerMock();
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteSleepFunction          target       = new ConcreteSleepFunction(function, zoneServer, audioDrivers);

            /* // not supported anymore; quick-fix, uncomment unit test ->
             *
             * // notify the first time, the update time is set to the current update time
             * ZoneStateEventArgs e1 = new ZoneStateEventArgs(new NuvoControl.Common.ZoneState(new Address(100, 1), true, 20, NuvoControl.Common.ZoneQuality.Online));
             * target.notifyOnZoneUpdate(e1);
             * Assert.AreEqual(e1.ZoneState.LastUpdate, target._lastZoneChangeToON);
             *
             * DateTime aktTime = DateTime.Now;
             * target.calculateFunction(aktTime);
             *
             * DateTime nextTime = DateTime.Now + new TimeSpan(1, 0, 0);
             * target.calculateFunction(nextTime);
             *
             * Assert.AreEqual(1, zoneServer._monitoredZones.Count);   // 1 zone monitored
             * Assert.AreEqual(1, zoneServer.ZoneStates.Count);       // 1 command issued
             * Assert.AreEqual(false, zoneServer.ZoneStates[new Address(100,1)].PowerStatus);   // switch off
             *
             */
        }
Example #5
0
 /// <summary>
 /// Standard constructor, used by configuration loader.
 /// </summary>
 /// <param name="id">Id of the command.</param>
 /// <param name="onFunctionError">True, if command shall be executed in case of an error.</param>
 /// <param name="onFunctionStart">True, if command shall be executed at function start.</param>
 /// <param name="onFunctionEnd">True, if command shall be executed at function end.</param>
 /// <param name="onValidityStart">True, if command shall be executed at validity start.</param>
 /// <param name="onValidityEnd">True, if command shall be executed at validity end.</param>
 /// <param name="onUnix">True, if command shall be exceuted on Unix systems. Default=True</param>
 /// <param name="onWindows">True, if command shall be executed on Windows systems. Default=True</param>
 public StartProcessCommand(SimpleId id, bool onFunctionError, bool onFunctionStart, bool onFunctionEnd, bool onValidityStart, bool onValidityEnd, bool onUnix, bool onWindows,
                            string process_cmd, string process_arg)
     : base(id, eCommand.PlaySound, onFunctionError, onFunctionStart, onFunctionEnd, onValidityStart, onValidityEnd, onUnix, onWindows)
 {
     _process_cmd = process_cmd;
     _process_arg = process_arg;
 }
        public void isFunctionActiveTodayTest3()
        {
            IZoneServer zoneServer = null;

            // (1) Empty day list
            List <DayOfWeek> _dayOfWeeks1 = new List <DayOfWeek>();
            AlarmFunction    function1    = new AlarmFunction(
                SimpleId.NewGuid(),
                new Address(100, 1), new Address(100, 1), 50,
                new TimeSpan(6, 0, 0), new TimeSpan(0, 45, 0),
                _dayOfWeeks1);
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteAlarmFunction          target1      = new ConcreteAlarmFunction(function1, zoneServer, audioDrivers);

            // (2) Full day list
            List <DayOfWeek> _dayOfWeeks2 = new List <DayOfWeek>();

            _dayOfWeeks2.Add(DayOfWeek.Monday);
            _dayOfWeeks2.Add(DayOfWeek.Tuesday);
            _dayOfWeeks2.Add(DayOfWeek.Wednesday);
            _dayOfWeeks2.Add(DayOfWeek.Thursday);
            _dayOfWeeks2.Add(DayOfWeek.Friday);
            _dayOfWeeks2.Add(DayOfWeek.Saturday);
            _dayOfWeeks2.Add(DayOfWeek.Sunday);
            AlarmFunction function2 = new AlarmFunction(
                SimpleId.NewGuid(),
                new Address(100, 1), new Address(100, 1), 50,
                new TimeSpan(6, 0, 0), new TimeSpan(0, 45, 0),
                _dayOfWeeks2);
            ConcreteAlarmFunction target2 = new ConcreteAlarmFunction(function2, zoneServer, audioDrivers);

            // Monday
            Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 7, 12, 0, 0)));
            Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 7, 12, 0, 0)));

            // Tuesday
            Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 8, 12, 0, 0)));
            Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 8, 12, 0, 0)));

            // Wednesday
            Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 9, 12, 0, 0)));
            Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 9, 12, 0, 0)));

            // Thursday
            Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 10, 12, 0, 0)));
            Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 10, 12, 0, 0)));

            // Friday
            Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 11, 12, 0, 0)));
            Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 11, 12, 0, 0)));

            // Saturday
            Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 12, 12, 0, 0)));
            Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 12, 12, 0, 0)));

            // Sunday
            Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 13, 12, 0, 0)));
            Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 13, 12, 0, 0)));
        }
Example #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="id">The function id.</param>
 /// <param name="zoneId">The address of the zone, which this function is applied for.</param>
 public Function(SimpleId id, Address zoneId, List <Command> commands)
 {
     this._id     = id;
     this._zoneId = zoneId;
     if (commands != null)
     {
         this._commands.AddRange(commands);
     }
 }
Example #8
0
 /// <summary>
 /// Standard constructor, called by configuration loader (w/o commands section) V1.0
 /// </summary>
 /// <param name="id">The function id.</param>
 /// <param name="zoneId">The address of the zone, which this function is applied for.</param>
 /// <param name="sourceId">Address of the source to play during the alarm.</param>
 /// <param name="volume">Volume to play the alarm.</param>
 /// <param name="alarmTime">Alarm time.</param>
 /// <param name="alarmDuration">Duration of the alarm.</param>
 /// <param name="validOnDays">The days, on which this alarm is valid.</param>
 public AlarmFunction(SimpleId id, Address zoneId, Address sourceId, int volume, TimeSpan alarmTime, TimeSpan alarmDuration, List <DayOfWeek> validOnDays)
     : base(id, zoneId)
 {
     this._alarmTime     = alarmTime;
     this._alarmDuration = alarmDuration;
     this._sourceId      = sourceId;
     this._volume        = volume;
     this._validOnDays   = validOnDays;
 }
Example #9
0
        public static IParsingResult Parse(ParsingContext context)
        {
            IParsingResult name = UnresolvedType.Parse(context) ?? SimpleId.Parse(context);

            if (name != null)
            {
                return(new DestructorName(name));
            }
            return(null);
        }
 public void ConcreteAlarmFunctionConstructorTest2()
 {
     List <DayOfWeek> _dayOfWeeks = new List <DayOfWeek>();
     AlarmFunction    function    = new AlarmFunction(
         SimpleId.NewGuid(),
         new Address(100, 1), new Address(100, 1), 50,
         new TimeSpan(6, 0, 0), new TimeSpan(0, 45, 0),
         _dayOfWeeks);
     IZoneServer zoneServer = null;
     Dictionary <int, IAudioDriver> audioDrivers = null;
     ConcreteAlarmFunction          target       = new ConcreteAlarmFunction(function, zoneServer, audioDrivers);
 }
Example #11
0
 public SendNuvoCommand(SimpleId id, bool onFunctionError, bool onFunctionStart, bool onFunctionEnd, bool onValidityStart, bool onValidityEnd, bool onUnix, bool onWindows,
                        Address ZoneId, string PowerStatus, string SourceId, int Volume)
     : base(id, eCommand.PlaySound, onFunctionError, onFunctionStart, onFunctionEnd, onValidityStart, onValidityEnd, onUnix, onWindows)
 {
     _zoneId = ZoneId;
     // check source id
     if (SourceId != "")
     {
         _sourceId = new Address(int.Parse(SourceId.Split(new char[] { SystemConfiguration.ID_SEPARATOR })[0]),
                                 int.Parse(SourceId.Split(new char[] { SystemConfiguration.ID_SEPARATOR })[1]));
     }
     _powerStatus = PowerStatus;
     _volume      = Volume;
 }
Example #12
0
 /// <summary>
 /// Standard constructor, used by configuration loader.
 /// </summary>
 /// <param name="id">Id of the command.</param>
 /// <param name="command">Command itself (e.g. SendMail)</param>
 /// <param name="onFunctionError">True, if command shall be executed in case of an error.</param>
 /// <param name="onFunctionStart">True, if command shall be executed at function start.</param>
 /// <param name="onFunctionEnd">True, if command shall be executed at function end.</param>
 /// <param name="onValidityStart">True, if command shall be executed at validity start.</param>
 /// <param name="onValidityEnd">True, if command shall be executed at validity end.</param>
 /// <param name="onUnix">True, if command shall be exceuted on Unix systems. Default=True</param>
 /// <param name="onWindows">True, if command shall be executed on Windows systems. Default=True</param>
 public Command(SimpleId id, eCommand command,
                bool onFunctionError, bool onFunctionStart, bool onFunctionEnd, bool onValidityStart, bool onValidityEnd,
                bool onUnix, bool onWindows)
 {
     _id              = id;
     _command         = command;
     _onFunctionError = onFunctionError;
     _onFunctionStart = onFunctionStart;
     _onFunctionEnd   = onFunctionEnd;
     _onValidityStart = onValidityStart;
     _onValidityEnd   = onValidityEnd;
     _onUnix          = onUnix;
     _onWindows       = onWindows;
 }
        public void calculateFunctionTest3()
        {
            SleepFunction function = new SleepFunction(SimpleId.NewGuid(), new Address(100, 1),
                                                       new TimeSpan(1, 0, 0), new TimeSpan(14, 0, 0), new TimeSpan(18, 00, 00));
            ZoneServerMock zoneServerMock = new ZoneServerMock();
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteSleepFunction          target       = new ConcreteSleepFunction(function, zoneServerMock, audioDrivers);

            Assert.AreEqual(1, zoneServerMock._monitoredZones.Count);   // 1 zone monitored

            // Distribute an 'old status. Simulate that the zone is ON since then.
            ZoneState oldState = new ZoneState(new Address(100, 1), true, 20, NuvoControl.Common.ZoneQuality.Online);

            oldState.LastUpdate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 00, 0);
            zoneServerMock.distributeZoneState(oldState);

            // test 11:00 -> not active, no action
            DateTime simTime1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 11, 00, 0);

            target.calculateFunction(simTime1);
            Assert.AreEqual(0, zoneServerMock.ZoneStates.Count);       // 0 command issued

            // test 14:00 -> just active, switch off.
            DateTime simTime2 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 14, 00, 0);

            target.calculateFunction(simTime2);
            Assert.AreEqual(1, zoneServerMock.ZoneStates.Count);       // 1 command issued
            zoneServerMock.ClearZoneStateList();

            // test 16:00 -> active, switch off.
            DateTime simTime3 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 16, 00, 0);

            target.calculateFunction(simTime3);
            Assert.AreEqual(1, zoneServerMock.ZoneStates.Count);       // 1 command issued
            zoneServerMock.ClearZoneStateList();

            // test 18:00 -> still active, switch off.
            DateTime simTime4 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 18, 00, 0);

            target.calculateFunction(simTime4);
            Assert.AreEqual(1, zoneServerMock.ZoneStates.Count);       // 1 command issued
            zoneServerMock.ClearZoneStateList();

            // test 20:00 -> not active, no action
            DateTime simTime5 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 20, 00, 0);

            target.calculateFunction(simTime5);
            Assert.AreEqual(0, zoneServerMock.ZoneStates.Count);       // 0 command issued
        }
        public void isFunctionActiveTodayTest1()
        {
            List <DayOfWeek> _dayOfWeeks = new List <DayOfWeek>();
            AlarmFunction    function    = new AlarmFunction(
                SimpleId.NewGuid(),
                new Address(100, 1), new Address(100, 1), 50,
                new TimeSpan(6, 0, 0), new TimeSpan(0, 45, 0),
                _dayOfWeeks);
            IZoneServer zoneServer = null;
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteAlarmFunction          target       = new ConcreteAlarmFunction(function, zoneServer, audioDrivers);
            DateTime aktTime = DateTime.Now;
            bool     actual  = target.isFunctionActiveToday(aktTime);

            Assert.AreEqual(false, actual);
        }
        /// <summary>
        /// <see cref="IConfigure"/>
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Function GetFunction(SimpleId id)
        {
            _log.Trace(m => m(String.Format("Configuration Service; GetFunction(Id={0}).", id.ToString())));

            // Search function with the specified Guid
            foreach (Function function in _systemConfiguration.Functions)
            {
                if (function.Id == id)
                {
                    _log.Trace(m => m(String.Format("Function with Id={0} found: {1}.", id.ToString(), function.ToString())));
                    return(function);
                }
            }

            _log.Warn(m => m(String.Format("Function with Id={0} NOT found: {1}.", id.ToString(), _systemConfiguration.Functions.ToString <Function>(" / "))));
            return(null);
        }
Example #16
0
 /// <summary>
 /// Standard constructor, used by configuration loader.
 /// </summary>
 /// <param name="id">Id of the command.</param>
 /// <param name="onFunctionError">True, if command shall be executed in case of an error.</param>
 /// <param name="onFunctionStart">True, if command shall be executed at function start.</param>
 /// <param name="onFunctionEnd">True, if command shall be executed at function end.</param>
 /// <param name="onValidityStart">True, if command shall be executed at validity start.</param>
 /// <param name="onValidityEnd">True, if command shall be executed at validity end.</param>
 /// <param name="onUnix">True, if command shall be exceuted on Unix systems. Default=True</param>
 /// <param name="onWindows">True, if command shall be executed on Windows systems. Default=True</param>
 /// <param name="toAddress"></param>
 /// <param name="ccAddress"></param>
 /// <param name="bccAddress"></param>
 /// <param name="subject"></param>
 /// <param name="body"></param>
 public SendMailCommand(SimpleId id,
                        bool onFunctionError, bool onFunctionStart, bool onFunctionEnd, bool onValidityStart, bool onValidityEnd,
                        bool onUnix, bool onWindows,
                        IEnumerable <MailAddress> toAddress, IEnumerable <MailAddress> ccAddress, IEnumerable <MailAddress> bccAddress,
                        string subject, string body)
     : base(id, eCommand.SendMail, onFunctionError, onFunctionStart, onFunctionEnd, onValidityStart, onValidityEnd, onUnix, onWindows)
 {
     _toAddress = toAddress.ToList <MailAddress>();
     if (ccAddress != null)
     {
         _ccAddress = ccAddress.ToList <MailAddress>();
     }
     if (bccAddress != null)
     {
         _bccAddress = bccAddress.ToList <MailAddress>();
     }
     _configuredSubject = subject;
     _configuredBody    = body;
     Initialize();
 }
        public void isFunctionActiveRightNowTest2()
        {
            SleepFunction function = new SleepFunction(SimpleId.NewGuid(), new Address(100, 1),
                                                       new TimeSpan(1, 0, 0), new TimeSpan(6, 0, 0), new TimeSpan(9, 0, 0));
            IZoneServer zoneServer = null;
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteSleepFunction          target       = new ConcreteSleepFunction(function, zoneServer, audioDrivers);
            bool actual = false;

            // (a) Function is not active, current time is outside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 10, 0, 0));
            Assert.AreEqual(false, actual);

            // (b) Function is not active, current time is outside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 9, 0, 1));
            Assert.AreEqual(false, actual);

            // (c) Function is not active, current time is outside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 5, 59, 59));
            Assert.AreEqual(false, actual);

            // (d) Function is active, current time is inside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 6, 0, 10));
            Assert.AreEqual(true, actual);

            // (e) Function is active, current time is inside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 8, 59, 59));
            Assert.AreEqual(true, actual);

            // (f) Function is not active, current time is outside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 0, 0, 0));
            Assert.AreEqual(false, actual);

            // (g) Function is active, current time is inside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 6, 0, 0));
            Assert.AreEqual(true, actual);

            // (h) Function is active, current time is inside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 9, 0, 0));
            Assert.AreEqual(true, actual);
        }
Example #18
0
 private void initMembers(SimpleId id, Address zoneId, Address sourceId, int volumeThreshold, bool OnStatusChange, bool OnSourceChange, bool OnVolumeChange, bool OnQualityChange, List <DayOfWeek> validOnDays, TimeSpan validFrom, TimeSpan validTo, List <Command> commands)
 {
     this._sourceId        = sourceId;
     this._volumeThreshold = volumeThreshold;
     this._onStatusChange  = OnStatusChange;
     this._onSourceChange  = OnSourceChange;
     this._onVolumeChange  = OnVolumeChange;
     this._onQualityChange = OnQualityChange;
     if (validOnDays != null)
     {
         this._validOnDays = validOnDays;
     }
     if (validFrom != null && validFrom.Ticks > 0)
     {
         this._validFrom = validFrom;
     }
     if (validTo != null && validTo.Ticks > 0)
     {
         this._validTo = validTo;
     }
 }
 /// <summary>
 /// Private method to initialize the members.
 /// Call this method in each constructur at start.
 /// </summary>
 private void initMembers()
 {
     _commandList.Clear();
     _createDateTime = DateTime.Now;
     _id             = SimpleId.NewGuid();
 }
        public void calculateFunctionTest4()
        {
            // (1) Day list: Monday, Wednesday, Friday, Sunday
            // (1) Function: AlarmTime=10:00, AlarmDuration=01:45
            #region Function1
            List <DayOfWeek> _dayOfWeeks1 = new List <DayOfWeek>();
            _dayOfWeeks1.Add(DayOfWeek.Monday);
            _dayOfWeeks1.Add(DayOfWeek.Wednesday);
            _dayOfWeeks1.Add(DayOfWeek.Friday);
            _dayOfWeeks1.Add(DayOfWeek.Sunday);
            AlarmFunction function1 = new AlarmFunction(
                SimpleId.NewGuid(),
                new Address(100, 1), new Address(100, 3), 50,
                new TimeSpan(10, 0, 0), new TimeSpan(1, 45, 0),
                _dayOfWeeks1);
            ZoneServerMock zoneServer1 = new ZoneServerMock();
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteAlarmFunction          target1      = new ConcreteAlarmFunction(function1, zoneServer1, audioDrivers);
            #endregion

            // (2) Day list: Tuesday, Thursday, Saturday, Sunday
            // (2) Function: AlarmTime=10:00, AlarmDuration=01:45
            #region Function2
            List <DayOfWeek> _dayOfWeeks2 = new List <DayOfWeek>();
            _dayOfWeeks2.Add(DayOfWeek.Tuesday);
            _dayOfWeeks2.Add(DayOfWeek.Thursday);
            _dayOfWeeks2.Add(DayOfWeek.Saturday);
            _dayOfWeeks2.Add(DayOfWeek.Sunday);
            AlarmFunction function2 = new AlarmFunction(
                SimpleId.NewGuid(),
                new Address(100, 1), new Address(100, 6), 50,
                new TimeSpan(10, 0, 0), new TimeSpan(1, 45, 0),
                _dayOfWeeks2);
            ZoneServerMock        zoneServer2 = new ZoneServerMock();
            ConcreteAlarmFunction target2     = new ConcreteAlarmFunction(function2, zoneServer2, audioDrivers);
            #endregion

            ZoneState zoneStateOff1 = new ZoneState(new Address(100, 2), false, 20, ZoneQuality.Online);
            zoneStateOff1.LastUpdate = new DateTime(2009, 9, 12, 23, 0, 0);
            ZoneState zoneStateOn = new ZoneState(new Address(100, 2), true, 20, ZoneQuality.Online);
            zoneStateOn.LastUpdate = new DateTime(2009, 9, 12, 23, 5, 0);
            ZoneState zoneStateOff2 = new ZoneState(new Address(100, 2), false, 20, ZoneQuality.Online);
            zoneStateOff2.LastUpdate = new DateTime(2009, 9, 12, 23, 10, 0);

            // Sunday (13.9.2009 11:00)
            zoneServer1.distributeZoneState(zoneStateOff1);
            zoneServer1.distributeZoneState(zoneStateOn);    // sets the member LastChangeToON
            zoneServer1.distributeZoneState(zoneStateOff2);
            target1.calculateFunction(new DateTime(2009, 9, 13, 11, 0, 0));

            zoneServer2.distributeZoneState(zoneStateOff1);
            zoneServer2.distributeZoneState(zoneStateOn);                     // sets the member LastChangeToON
            zoneServer2.distributeZoneState(zoneStateOff2);
            target2.calculateFunction(new DateTime(2009, 9, 13, 11, 44, 59)); // last change before functions ends

            Assert.AreEqual(1, zoneServer1._monitoredZones.Count);
            Assert.AreEqual(1, zoneServer2._monitoredZones.Count);
            Assert.AreEqual(1, zoneServer1.ZoneStates.Count);  // 1 command has been sent
            Assert.AreEqual(true, zoneServer1.ZoneStates[new Address(100, 1)].PowerStatus);
            Assert.AreEqual(new Address(100, 3), zoneServer1.ZoneStates[new Address(100, 1)].Source);
            Assert.AreEqual(1, zoneServer2.ZoneStates.Count);  // 1 command has been sent
            Assert.AreEqual(true, zoneServer2.ZoneStates[new Address(100, 1)].PowerStatus);
            Assert.AreEqual(new Address(100, 6), zoneServer2.ZoneStates[new Address(100, 1)].Source);
            zoneServer1.ClearZoneStateList();
            zoneServer2.ClearZoneStateList();
        }
Example #21
0
 public Function GetFunction(SimpleId id)
 {
     throw new NotImplementedException();
 }
Example #22
0
 public ZoneChangeFunction(SimpleId id, Address zoneId, Address sourceId, int volumeThreshold, List <DayOfWeek> validOnDays, TimeSpan validFrom, TimeSpan validTo, List <Command> commands)
     : base(id, zoneId, commands)
 {
     initMembers(id, zoneId, sourceId, volumeThreshold, false, false, false, false, validOnDays, validFrom, validTo, commands);
 }
Example #23
0
 public ZoneChangeFunction(SimpleId id, Address zoneId, Address sourceId, int volumeThreshold, bool OnStatusChange, bool OnSourceChange, bool OnVolumeChange, bool OnQualityChange, List <DayOfWeek> validOnDays, TimeSpan validFrom, TimeSpan validTo, List <Command> commands)
     : base(id, zoneId, commands)
 {
     initMembers(id, zoneId, sourceId, volumeThreshold, OnStatusChange, OnSourceChange, OnVolumeChange, OnQualityChange, validOnDays, validFrom, validTo, commands);
 }
Example #24
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="id">The function id.</param>
 /// <param name="zoneId">The address of the zone, which this function is applied for.</param>
 public Function(SimpleId id, Address zoneId)
 {
     this._id     = id;
     this._zoneId = zoneId;
 }
Example #25
0
        public TransactionStatus GetStatus(SimpleId transaction, NamedEndpointVisit visit)
        {
            Activity activity = null;

            try
            {
                NodeVisit nodeVisit;
                MakeEndpointActivity(visit, ActivityType.Audit, NodeMethod.GetStatus,
                                     out nodeVisit, out activity);

                if ((transaction == null) || string.IsNullOrEmpty(transaction.Id))
                {
                    throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter,
                                                 "Empty input transaction");
                }

                string            flowId, operation;
                NodeMethod        webMethod;
                TransactionStatus transactionStatus =
                    TransactionManager.GetTransactionStatus(transaction.Id, out flowId,
                                                            out operation, out webMethod);
                if (transactionStatus == null)
                {
                    throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_TransactionId,
                                                 "Transaction not found: \"{0}\"", transaction.Id);
                }

                activity.TransactionId = transaction.Id;

                bool   isFlowProtected;
                string flowCode = FlowManager.GetDataFlowNameById(flowId, out isFlowProtected);
                activity.FlowName  = flowCode;
                activity.Operation = operation;

                if (flowCode == null)
                {
                    throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidDataflow,
                                                 "Flow id not found: \"{0}\" for transaction: \"{1}\"",
                                                 flowId, transaction.Id);
                }

                if (isFlowProtected)
                {
                    ValidateUserPermissions(nodeVisit, flowCode, operation, NodeMethod.GetStatus,
                                            activity);
                }

                activity.AppendFormat("GetStatus request from {0} by {1} for transaction Id {2}. ",
                                      visit.IP, nodeVisit.Account.NaasAccount, transaction.Id);
                activity.AppendFormat("Result: {0}", transactionStatus);

                return(transactionStatus);
            }
            catch (Exception ex)
            {
                if (activity != null)
                {
                    activity.Append(ExceptionUtils.ToShortString(ex));
                    activity.Type = ActivityType.Error;
                }
                if (ex is SoapException)
                {
                    throw;      // Throw directly since already SoapException
                }
                else
                {
                    throw FaultProvider.GetFault(visit.Version, ex);
                }
            }
            finally
            {
                if (activity != null)
                {
                    ActivityManager.Log(activity);
                }
            }
        }
Example #26
0
 public static IParsingResult Parse(ParsingContext context)
 {
     return(SimpleId.Parse(context));
 }
Example #27
0
 public OscEventFunction(SimpleId id, Address oscDevice, string oscEvent, string oscLabel, int oscValue, List <DayOfWeek> validOnDays, TimeSpan validFrom, TimeSpan validTo, List <Command> commands)
     : base(id, new Address(), commands)
 {
     initMembers(oscDevice, oscEvent, oscLabel, oscValue, validOnDays, validFrom, validTo, commands);
 }