public RelayEvent(RelayState eventType, bool success, DateTime time)
 {
     EventType = eventType;
     Success   = success;
     Time      = time;
     Summary   = $"{eventType} at {time.ToShortTimeString()}";
 }
Пример #2
0
        // Process a successful SAML response.
        private void ProcessSuccessSAMLResponse(SAMLResponse samlResponse, string relayState)
        {
            Trace.Write("SP", "Processing successful SAML response");

            // Extract the asserted identity from the SAML response.
            SAMLAssertion samlAssertion = (SAMLAssertion)samlResponse.Assertions[0];

            // Get the subject name identifier.
            string userName = samlAssertion.Subject.NameID.NameIdentifier;

            // Get the originally requested resource URL from the relay state.
            RelayState cachedRelayState = RelayStateCache.Remove(relayState);

            if (cachedRelayState == null)
            {
                Trace.Write("SP", "Nothing in cache");

                return;
            }

            // Create a login context for the asserted identity.
            FormsAuthentication.SetAuthCookie(userName, false);

            // Redirect to the originally requested resource URL.
            Response.Redirect(cachedRelayState.ResourceURL, false);

            Trace.Write("SP", "Processed successful SAML response");
        }
Пример #3
0
        //Relay Status
        public override bool GetRelayState(int Number, out RelayState State, out string ErrorString)
        {
            ErrorString = string.Empty;
            State       = ZR_RelayCard.RelayState.Undef;
            if ((Number < 1) || (Number > this.MaxOutputs))
            {
                ErrorString = "Wrong relay number (" + Number.ToString() + ") Valid numbers: from 1 to " + this.MaxOutputs.ToString() + "!";
                return(false);
            }

            if (!this.CardListIsBuild)
            {
                ErrorString = "Card is not initialized!";
                return(false);
            }

            if (RelayIsOn[Number - 1])
            {
                State = ZR_RelayCard.RelayState.On;
            }
            else
            {
                State = ZR_RelayCard.RelayState.Off;
            }
            return(true);
        }
Пример #4
0
 /// <summary>
 /// Gets the inverse of the specified state.
 /// </summary>
 /// <returns>
 /// The inverse of the specified state.
 /// </returns>
 /// <param name="state">
 /// The relay state to invert.
 /// </param>
 public static RelayState GetInverseState(RelayState state)
 {
     if (state == RelayState.Open)
     {
         return(RelayState.Closed);
     }
     return(RelayState.Open);
 }
Пример #5
0
        // Process a successful SAML response.
        private void ProcessSuccessSAMLResponse(SAMLResponse samlResponse, string relayState)
        {
            Trace.Write("SP", "Processing successful SAML response");

            // Load the decryption key.
            X509Certificate2 x509Certificate = (X509Certificate2)Application[Global.SPX509Certificate];

            // Extract the asserted identity from the SAML response.
            SAMLAssertion samlAssertion = null;

            if (samlResponse.GetUnsignedAssertions().Count > 0)
            {
                samlAssertion = samlResponse.GetUnsignedAssertions()[0];
            }
            else if (samlResponse.GetEncryptedAssertions().Count > 0)
            {
                Trace.Write("SP", "Decrypting assertion");
                samlAssertion = samlResponse.GetEncryptedAssertions()[0].Decrypt(x509Certificate.PrivateKey, null, null);
            }
            else
            {
                throw new ArgumentException("No assertions in response");
            }

            // Get the subject name identifier.
            string userName = null;

            if (samlAssertion.Subject.NameID != null)
            {
                userName = samlAssertion.Subject.NameID.NameIdentifier;
            }
            else if (samlAssertion.Subject.EncryptedID != null)
            {
                Trace.Write("SP", "Decrypting ID");
                NameID nameID = samlAssertion.Subject.EncryptedID.Decrypt(x509Certificate.PrivateKey, null, null);
                userName = nameID.NameIdentifier;
            }
            else
            {
                throw new ArgumentException("No name in subject");
            }

            // Get the originally requested resource URL from the relay state.
            RelayState cachedRelayState = RelayStateCache.Remove(relayState);

            if (cachedRelayState == null)
            {
                throw new ArgumentException("Invalid relay state");
            }

            // Create a login context for the asserted identity.
            FormsAuthentication.SetAuthCookie(userName, false);

            // Redirect to the originally requested resource URL.
            Response.Redirect(cachedRelayState.ResourceURL, false);

            Trace.Write("SP", "Processed successful SAML response");
        }
Пример #6
0
 public static string ToString(RelayState rs)
 {
     switch (rs)
     {
         case RelayState.ACTION:
             return "开";
         case RelayState.RESET:
             return "关";
         default:
             return "未知";
     }
 }
        public async Task GetDeviceTwin()
        {
            var twin = await _registryManager.GetTwinAsync(DeviceId);

            AppCenterHelper.Track(nameof(GetDeviceTwin));

            // Update DeviceTwin
            _deviceTwin.ApplianceConnected = twin.ConnectionState == DeviceConnectionState.Connected;

            try
            {
                var        reportedPropertyForRelayState = twin.Properties.Reported["RelayState"];
                RelayState relayState = JsonConvert.DeserializeObject <RelayState>(reportedPropertyForRelayState.ToJson());
                _deviceTwin.LightsGarden = relayState.LightsGarden;
                _deviceTwin.AlarmStrobe  = relayState.AlarmStrobe;
                _deviceTwin.AlarmSiren   = relayState.AlarmSiren;
            }
            catch (Exception ex)
            {
                AppCenterHelper.Error("Error updating RelayState", ex);
            }

            try
            {
                var reportedPropertyOccupantState = twin.Properties.Reported[nameof(_deviceTwin.Occupant)];
                var occupant = JsonConvert.DeserializeObject <OccupantState>(reportedPropertyOccupantState.ToJson());
                _deviceTwin.Occupant = occupant;
            }
            catch (Exception ex)
            {
                AppCenterHelper.Error("Error updating Occupant", ex);
            }

            try
            {
                var reportedPropertyArmedState = twin.Properties.Reported[nameof(ArmedState)];
                var armedState = JsonConvert.DeserializeObject <ArmedState>(reportedPropertyArmedState.ToJson());
                _deviceTwin.ArmedState = armedState;
            }
            catch (Exception ex)
            {
                AppCenterHelper.Error("Error updating ArmedState", ex);
            }

            try
            {
                _deviceTwin.GarageDoorOpen = (bool)twin.Properties.Reported["GarageDoorOpen"];
            }
            catch (Exception ex)
            {
                AppCenterHelper.Error("Error updating GarageDoorOpen", ex);
            }
        }
Пример #8
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Devices.Fireplace.FireplaceDevice"/>
		/// class with the relay used to control the fireplace, the
		/// relay state used to consider the fireplace to be "on", the
		/// sensor used to detect the pilot light, and the sensor state
		/// in which to consider the pilot light to be "on".
		/// </summary>
		/// <param name="controlRelay">
		/// The control relay.
		/// </param>
		/// <param name="onRelayState">
		/// The relay state used to consider the fireplace to be "on".
		/// </param>
		/// <param name="pilotLightSensor">
		/// The pilot light sensor.
		/// </param>
		/// <param name="pilotOnState">
		/// The pilot light state used to consider the pilot light to be "on".
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="controlRelay"/> cannot be null.
		/// </exception>
		public FireplaceDevice(IRelay controlRelay, RelayState onRelayState, ISensor pilotLightSensor, SensorState pilotOnState)
			: base() {
			if (controlRelay == null) {
				throw new ArgumentNullException("controlRelay");
			}

			this._controlRelay = controlRelay;
			this._fireplaceOnRelayState = onRelayState;
			this._pilotLightSensor = pilotLightSensor;
			this._pilotLightOnSensorState = pilotOnState;
			this._controlRelay.StateChanged += this.InternalHandleRelayStateChange;
			if (this._pilotLightSensor != null) {
				this._pilotLightSensor.StateChanged += this.InternalHandleSensorStateChange;
			}
		}
        public override void DataHandler(string rx)
        {
            if (rx.ToLower().Contains("is on")) // && _relayState != RelayState.TurnedOn
            {
                _relayState = RelayState.TurnedOn;
            }
            else if (rx.ToLower().Contains("is off")) //  && _relayState != RelayState.TurnedOff
            {
                _relayState = RelayState.TurnedOff;
            }
            else if (rx.ToLower().Contains("error"))
            {
                _relayState = RelayState.Error;
            }

            FeedbackChanged?.Invoke(this, new ValueEventArgs <RelayState>(_relayState));
        }
Пример #10
0
 public void SetRelayState(int channel, RelayState state)
 {
     byte x;
     switch (state)
     {
         case RelayState.Forward:
             x = 1;
             break;
         case RelayState.Reverse:
             x = 2;
             break;
         case RelayState.Neutral:
         default:
             x = 0;
             break;
     }
     relay[channel - 1] = x;
 }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Devices.Fireplace.FireplaceDevice"/>
        /// class with the relay used to control the fireplace, the
        /// relay state used to consider the fireplace to be "on", the
        /// sensor used to detect the pilot light, and the sensor state
        /// in which to consider the pilot light to be "on".
        /// </summary>
        /// <param name="controlRelay">
        /// The control relay.
        /// </param>
        /// <param name="onRelayState">
        /// The relay state used to consider the fireplace to be "on".
        /// </param>
        /// <param name="pilotLightSensor">
        /// The pilot light sensor.
        /// </param>
        /// <param name="pilotOnState">
        /// The pilot light state used to consider the pilot light to be "on".
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="controlRelay"/> cannot be null.
        /// </exception>
        public FireplaceDevice(IRelay controlRelay, RelayState onRelayState, ISensor pilotLightSensor, SensorState pilotOnState)
            : base()
        {
            if (controlRelay == null)
            {
                throw new ArgumentNullException("controlRelay");
            }

            this._controlRelay               = controlRelay;
            this._fireplaceOnRelayState      = onRelayState;
            this._pilotLightSensor           = pilotLightSensor;
            this._pilotLightOnSensorState    = pilotOnState;
            this._controlRelay.StateChanged += this.InternalHandleRelayStateChange;
            if (this._pilotLightSensor != null)
            {
                this._pilotLightSensor.StateChanged += this.InternalHandleSensorStateChange;
            }
        }
Пример #12
0
        //process feedback
        private void SetRelayState(RelayState state)
        {
            if (_consoleDebuggingEnabled)
            {
                CrestronConsole.PrintLine($"SetRelayState {state}");
            }
            switch (state)
            {
            case RelayState.TurnedOn:
                _relayStateProperty.Value     = TurnedOnLabel;
                _relayStateIconProperty.Value = _onIcon;
                RaiseTurnedOnEvent();
                break;

            case RelayState.TurningOn:
                _relayStateProperty.Value     = TurningOnLabel;
                _relayStateIconProperty.Value = SpinnerIcon;
                _relayProtocol.SendCustomCommandByName("PowerOn");
                break;

            case RelayState.TurnedOff:
                _relayStateProperty.Value     = TurnedOffLabel;
                _relayStateIconProperty.Value = _offIcon;
                RaiseTurnedOffEvent();
                break;

            case RelayState.TurningOff:
                _relayStateProperty.Value     = TurningOffLabel;
                _relayStateIconProperty.Value = SpinnerIcon;
                _relayProtocol.SendCustomCommandByName("PowerOff");
                break;

            case RelayState.Error:
                _relayStateProperty.Value     = ErrorLabel;
                _relayStateIconProperty.Value = ErrorIcon;
                RaiseErrorEvent();
                break;
            }
        }
Пример #13
0
        /// <summary>
        /// Röleyi kontrol eder.
        /// </summary>
        /// <param name="relayCh">Röle kanalı</param>
        /// <param name="relayState">Röle durumu</param>
        public void SetRelay(RelayCh relayCh, RelayState relayState)
        {
            switch (relayCh)
            {
            case RelayCh.Ch1:
                relay1.Write(relayState == RelayState.On ? GpioPinValue.High : GpioPinValue.Low);
                break;

            case RelayCh.Ch2:
                relay2.Write(relayState == RelayState.On ? GpioPinValue.High : GpioPinValue.Low);
                break;

            case RelayCh.Ch3:
                relay3.Write(relayState == RelayState.On ? GpioPinValue.High : GpioPinValue.Low);
                break;

            case RelayCh.Ch4:
                relay4.Write(relayState == RelayState.On ? GpioPinValue.High : GpioPinValue.Low);
                break;

            default:
                break;
            }
        }
Пример #14
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Devices.Fireplace.FireplaceDevice"/>
		/// class with the relay used to control the fireplace and
		/// the relay state used to consider the fireplace to be "on".
		/// </summary>
		/// <param name="controlRelay">
		/// The control relay.
		/// </param>
		/// <param name="onRelayState">
		/// The relay state used to consider the fireplace to be "on".
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="controlRelay"/> cannot be null.
		/// </exception>
		public FireplaceDevice(IRelay controlRelay, RelayState onRelayState)
			: this(controlRelay, onRelayState, null, SensorState.Closed) {
		}
        // Process a successful SAML response.
        private void ProcessSuccessSAMLResponse(SAMLResponse samlResponse, string relayState)
        {
            Trace.Write("SP", "Processing successful SAML response");

            // Extract the asserted identity from the SAML response.
            // The SAML assertion may be signed or encrypted and signed.
            SAMLAssertion samlAssertion = null;

            if (samlResponse.GetUnsignedAssertions().Count > 0)
            {
                samlAssertion = samlResponse.GetUnsignedAssertions()[0];
            }
            else if (samlResponse.GetSignedAssertions().Count > 0)
            {
                Trace.Write("SP", "Verifying assertion signature");

                XmlElement samlAssertionXml = samlResponse.GetSignedAssertions()[0];

                // Verify the assertion signature. The embedded signing certificate is used.
                if (!SAMLAssertionSignature.Verify(samlAssertionXml))
                {
                    throw new ArgumentException("The SAML assertion signature failed to verify.");
                }

                samlAssertion = new SAMLAssertion(samlAssertionXml);
            }
            else if (samlResponse.GetEncryptedAssertions().Count > 0)
            {
                Trace.Write("SP", "Decrypting assertion");

                // Load the decryption key.
                X509Certificate2 x509Certificate = (X509Certificate2)Application[Global.SPX509Certificate];

                // Decrypt the encrypted assertion.
                XmlElement samlAssertionXml = samlResponse.GetEncryptedAssertions()[0].DecryptToXml(x509Certificate.PrivateKey, null, null);

                if (SAMLAssertionSignature.IsSigned(samlAssertionXml))
                {
                    Trace.Write("SP", "Verifying assertion signature");

                    // Verify the assertion signature. The embedded signing certificate is used.
                    if (!SAMLAssertionSignature.Verify(samlAssertionXml))
                    {
                        throw new ArgumentException("The SAML assertion signature failed to verify.");
                    }
                }

                samlAssertion = new SAMLAssertion(samlAssertionXml);
            }
            else
            {
                throw new ArgumentException("No assertions in response");
            }

            // Get the subject name identifier.
            string userName = null;

            if (samlAssertion.Subject.NameID != null)
            {
                userName = samlAssertion.Subject.NameID.NameIdentifier;
            }

            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentException("The SAML assertion doesn't contain a subject name.");
            }

            // Create a login context for the asserted identity.
            Trace.Write("SP", "Automatically logging in user " + userName);
            FormsAuthentication.SetAuthCookie(userName, false);

            // Get the originally requested resource URL from the relay state, if any.
            string redirectURL = "~/";

            RelayState cachedRelayState = RelayStateCache.Remove(relayState);

            if (cachedRelayState != null)
            {
                redirectURL = cachedRelayState.ResourceURL;
            }

            // Redirect to the originally requested resource URL, if any, or the default page.
            Trace.Write("SP", "Redirecting to " + redirectURL);
            Response.Redirect(redirectURL, false);

            Trace.Write("SP", "Processed successful SAML response");
        }
Пример #16
0
		/// <summary>
		/// Gets the inverse of the specified state.
		/// </summary>
		/// <returns>
		/// The inverse of the specified state.
		/// </returns>
		/// <param name="state">
		/// The relay state to invert.
		/// </param>
		public static RelayState GetInverseState(RelayState state) {
			if (state == RelayState.Open) {
				return RelayState.Closed;
			}
			return RelayState.Open;
		}
 public RelayStateService(RelayInfoBuilder.Factory relayInfoBuilderFactory)
 {
     _relayInfoBuilderFactory = relayInfoBuilderFactory;
     _state = RelayState.OpenForPublic;
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Relays.RelayStateChangedEventArgs"/>
		/// class with the previous and current states.
		/// </summary>
		/// <param name="oldState">
		/// The previous relay state.
		/// </param>
		/// <param name="newState">
		/// The current relay state.
		/// </param>
		public RelayStateChangedEventArgs(RelayState oldState, RelayState newState)
			: base() {
			this._oldState = oldState;
			this._newState = newState;
		}
        private void CreateNewRelayEvent(RelayState eventType, bool success, DateTime time)
        {
            var relayEvent = new RelayEvent(eventType, success, time);

            StateChangedEvent?.Invoke(this, new StateChangeEventArgs(EventType.RelayEvent, relayEvent));
        }
Пример #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Devices.Fireplace.FireplaceDevice"/>
 /// class with the relay used to control the fireplace and
 /// the relay state used to consider the fireplace to be "on".
 /// </summary>
 /// <param name="controlRelay">
 /// The control relay.
 /// </param>
 /// <param name="onRelayState">
 /// The relay state used to consider the fireplace to be "on".
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="controlRelay"/> cannot be null.
 /// </exception>
 public FireplaceDevice(IRelay controlRelay, RelayState onRelayState)
     : this(controlRelay, onRelayState, null, SensorState.Closed)
 {
 }
Пример #21
0
		/// <summary>
		/// Determines whether this relay's state matches the specified state.
		/// </summary>
		/// <returns>
		/// <c>true</c> if this relay's state matches the specified state; otherwise, <c>false</c>.
		/// </returns>
		/// <param name="state">
		/// The state to check for.
		/// </param>
		public Boolean IsState(RelayState state) {
			return (this.State == state);
		}
Пример #22
0
 public void UpdateStatus(RelayState state)
 {
     Clients.All.updateStatus(state);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Relays.RelayStateChangedEventArgs"/>
 /// class with the previous and current states.
 /// </summary>
 /// <param name="oldState">
 /// The previous relay state.
 /// </param>
 /// <param name="newState">
 /// The current relay state.
 /// </param>
 public RelayStateChangedEventArgs(RelayState oldState, RelayState newState)
     : base()
 {
     this._oldState = oldState;
     this._newState = newState;
 }
Пример #24
0
 /// <summary>
 /// Determines whether this relay's state matches the specified state.
 /// </summary>
 /// <returns>
 /// <c>true</c> if this relay's state matches the specified state; otherwise, <c>false</c>.
 /// </returns>
 /// <param name="state">
 /// The state to check for.
 /// </param>
 public Boolean IsState(RelayState state)
 {
     return(this.State == state);
 }
Пример #25
0
 internal void SetRelayValue(int channel, RelayState state)
 {
     packet.SetRelayState(channel, state);
 }