/// <summary> /// Starts the software based PWM on this pin. /// </summary> /// <param name="value">The value.</param> /// <param name="range">The range.</param> /// <exception cref="System.NotSupportedException"></exception> /// <exception cref="System.InvalidOperationException">StartSoftPwm /// or</exception> public void StartSoftPwm(int value, int range) { lock (_syncLock) { if (Capabilities.Contains(PinCapability.GP) == false) { throw new NotSupportedException($"Pin {PinNumber} does not support software PWM"); } if (IsInSoftPwmMode) { throw new InvalidOperationException($"{nameof(StartSoftPwm)} has already been called."); } var startResult = WiringPi.softPwmCreate(PinNumber, value, range); if (startResult == 0) { m_SoftPwmValue = value; m_SoftPwmRange = range; } else { throw new InvalidOperationException($"Could not start software based PWM on pin {PinNumber}. Error code: {startResult}"); } } }
/// <summary> /// Performs a bitwise and to check if the specified /// flag is set on the <see cref="Capabilities"/> property. /// </summary> /// <param name="cap">The <see cref="FtpCapability"/> to check for</param> /// <returns>True if the feature was found, false otherwise</returns> public bool HasFeature(FtpCapability cap) { if (cap == FtpCapability.NONE && Capabilities.Count == 0) { return true; } return Capabilities.Contains(cap); }
/// <summary> /// Return if the type advertises the requested capability (explicitly) /// </summary> /// <param name="capability">Full name of the capability (eg: "SupportsTags")</param> /// <returns>True or False</returns> public bool HasCapability(string capability) { if (string.IsNullOrWhiteSpace(capability)) { throw new ArgumentNullException(nameof(capability)); } return((!string.IsNullOrWhiteSpace(Capabilities)) && Capabilities.Contains(capability, StringComparison.InvariantCultureIgnoreCase)); }
public async Task <SmtpAuthenticator> ConnectAsync(string host, short port) { _tcpClient.Connect(host, port); var stream = _tcpClient.GetStream(); _reader = new StreamReader(stream, Encoding.UTF8, false); _writer = new StreamWriter(stream) { AutoFlush = true }; // Use implicit encryption (SSL). if (Security == SecurityProtocol.Implicit) { await NegotiateEncryptionProtocolsAsync(host); await RequestCapabilitiesAsync(); return(new SmtpAuthenticator(this)); } // Use explicit encryption (TLS). await RequestCapabilitiesAsync(); if (Security == SecurityProtocol.Explicit) { if (Capabilities.Contains(SmtpCommands.StartTls)) { await WriteAsync(SmtpCommands.StartTls); var response = await ReadAsync(); //server returns "2.0.0 SMTP server ready" by success if (response.IsOk | response.IsServiceReady) { await NegotiateEncryptionProtocolsAsync(host); await RequestCapabilitiesAsync(); return(new SmtpAuthenticator(this)); } throw new SmtpException(response.Content); } } // Fail if server supports no encryption. throw new SmtpException(Resources.NoEncryptionNotSupported); }
public async Task PingAsync() { if (Capabilities.Contains(ExtensionCapability.Base)) // If the client does not support pings, treat it as a noop { try { await _handlerStreamUsageLock.WaitAsync(); // Pinging from the handler is safe: the client is waiting for the response and isn't going to send any data await _socket.GetStream().PingUnsafeAsync(); } finally { _handlerStreamUsageLock.Release(); } } }
public bool IsCapapableOf(Capability cap) { return(Capabilities.Contains(cap)); }