/// <summary> /// Releases unmanaged resources used by the <see cref="BatchClient"/>, and optionally disposes of managed resources. /// </summary> /// <param name="disposing">Indicates whether the object is being disposed or finalized. If true, the object is /// being disposed and can dispose managed resource. If false, the object is being finalized and should only /// release unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { // IDisposable only section lock (this._closeLocker) { if (this._disposableStateBox != null) { IProtocolLayer localProto = this.ProtocolLayer; localProto.Dispose(); this._disposableStateBox = null; // null state box signals that the instance is closed } } } _disposed = true; }
/// <summary> /// Establish a serial connection to COM-Port /// </summary> public void ConnectSerial(string comPort) { if (!string.IsNullOrEmpty(comPort)) this.ComPort = comPort; IProtocolLayer<object, object> protocolLayer = new PresentationLayer( new SessionLayer( new TransportLayer(this.ComPort) ) ); this.protocol = protocolLayer; }
/// <summary> /// Initializes a new instance of the <see cref="ProtocolHandshakeConductor"/> class. /// </summary> /// <param name="potentialEndpoints">The collection of endpoints that have been discovered.</param> /// <param name="discoveryChannel">The object that provides the information about the entry discovery channel for the application.</param> /// <param name="discoverySources">The object that handles the discovery of remote endpoints.</param> /// <param name="layer">The object responsible for sending messages with remote endpoints.</param> /// <param name="descriptions">The object that stores information about the available communication descriptions.</param> /// <param name="connectionApprovers"> /// The collection that contains all the objects that are able to approve connections between the current endpoint and a remote endpoint. /// </param> /// <param name="allowedChannelTypes">The collection that contains all the channel types for which a channel should be opened.</param> /// <param name="configuration">The object that stores the configuration values for the application.</param> /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="potentialEndpoints"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="discoveryChannel"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="discoverySources"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="layer"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="descriptions"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="connectionApprovers"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="allowedChannelTypes"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="configuration"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="systemDiagnostics"/> is <see langword="null" />. /// </exception> public ProtocolHandshakeConductor( IStoreEndpointApprovalState potentialEndpoints, IProvideLocalConnectionInformation discoveryChannel, IEnumerable <IDiscoverOtherServices> discoverySources, IProtocolLayer layer, IStoreProtocolSubjects descriptions, IEnumerable <IApproveEndpointConnections> connectionApprovers, IEnumerable <ChannelTemplate> allowedChannelTypes, IConfiguration configuration, SystemDiagnostics systemDiagnostics) { { Lokad.Enforce.Argument(() => potentialEndpoints); Lokad.Enforce.Argument(() => discoveryChannel); Lokad.Enforce.Argument(() => discoverySources); Lokad.Enforce.Argument(() => layer); Lokad.Enforce.Argument(() => descriptions); Lokad.Enforce.Argument(() => connectionApprovers); Lokad.Enforce.Argument(() => allowedChannelTypes); Lokad.Enforce.Argument(() => configuration); Lokad.Enforce.Argument(() => systemDiagnostics); } m_PotentialEndpoints = potentialEndpoints; // Also handle the case where the endpoint signs out while it is trying to // connect to us m_PotentialEndpoints.OnEndpointDisconnected += HandleEndpointSignedOut; m_DiscoveryChannel = discoveryChannel; m_DiscoverySources = discoverySources; m_Layer = layer; m_Descriptions = descriptions; m_AllowedChannelTypes = allowedChannelTypes; m_Diagnostics = systemDiagnostics; m_SendTimeout = configuration.HasValueFor(CommunicationConfigurationKeys.WaitForResponseTimeoutInMilliSeconds) ? TimeSpan.FromMilliseconds(configuration.Value <int>(CommunicationConfigurationKeys.WaitForResponseTimeoutInMilliSeconds)) : TimeSpan.FromMilliseconds(CommunicationConstants.DefaultWaitForResponseTimeoutInMilliSeconds); foreach (var approver in connectionApprovers) { m_ConnectionApprovers.Add(approver.ProtocolVersion, approver); } foreach (var source in m_DiscoverySources) { source.OnEndpointBecomingAvailable += HandleEndpointSignIn; source.OnEndpointBecomingUnavailable += HandleEndpointSignedOut; } }
/// <summary> /// Starts an asynchronous operation to close the current instance of <see cref="Microsoft.Azure.Batch.BatchClient"/>. /// Closed instances of <see cref="Microsoft.Azure.Batch.BatchClient"/> are unable to make calls to the Batch Service and the behavior and values of any other methods or properties are undefined. /// These restrictions also apply immediately to any objects that can trace instantation back to this <see cref="Microsoft.Azure.Batch.BatchClient"/>. /// This method is threadsafe and can be called any number of times. /// </summary> /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns> public System.Threading.Tasks.Task CloseAsync() { lock (this._closeLocker) { if (this._disposableStateBox != null) { IProtocolLayer localProto = this.ProtocolLayer; localProto.Dispose(); this._disposableStateBox = null; // null state box signals that the instance is closed } } return(Utils.Async.CompletedTask); }
/// <summary> /// Initializes a new instance of the <see cref="DataDownloadProcessAction"/> class. /// </summary> /// <param name="uploads">The object that stores the files that need uploading.</param> /// <param name="layer">The object that handles the communication with remote endpoints.</param> /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param> /// <param name="scheduler">The scheduler that is used to run the tasks on.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="uploads"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="layer"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="systemDiagnostics"/> is <see langword="null" />. /// </exception> public DataDownloadProcessAction( IStoreUploads uploads, IProtocolLayer layer, SystemDiagnostics systemDiagnostics, TaskScheduler scheduler = null) { { Lokad.Enforce.Argument(() => uploads); Lokad.Enforce.Argument(() => layer); Lokad.Enforce.Argument(() => systemDiagnostics); } m_Uploads = uploads; m_Layer = layer; m_Diagnostics = systemDiagnostics; m_Scheduler = scheduler; }
/// <summary> /// Holds the protocol layer to be used for this client instance. /// This enables "mock"ing the protocol layer for testing. /// </summary> internal BatchClient(IProtocolLayer protocolLayer) : this() { this.ProtocolLayer = protocolLayer; }
/// <summary> /// Constructor /// </summary> /// <param name="lower"></param> public PresentationLayer(IProtocolLayer<object, object> lower) : base(lower) { }
public SessionLayer(IProtocolLayer<object, object> lower) : base(lower) { }