projects/wms-framework/src/lib/wcfserviceinvocationsupport/CommunicationSupport.ts
Provides a base implementation for managing the default timeouts that are associated with channel and listener factories.
import { IAsyncResult, AsyncCallback } from './AsyncResultSupport';
import { Debugger } from '../diagnostics/Debugger';
import { BindingElementCollection } from './channels';
import { WcfMessage } from './WcfMessage';
import { HttpClient } from '@angular/common/http';
import { TimeRange } from '../baseframework';
import { Message } from './Message';
/**
* Contains the binding elements that specify the protocols, transports, and message
* encoders used for communication between clients and services.
*
* @export
* @abstract
* @class CommunicationBinding
* @wType System.ServiceModel.Channels.Binding
*/
export abstract class CommunicationBinding {
public SendTimeout: any = null;
public OpenTimeout: any = null;
public ReceiveTimeout: any = null;
public CloseTimeout: any = null;
/**
* UsePost property
*
* @type {boolean}
* @memberof CommunicationBinding
* @wIgnore
*/
public UsePost: boolean;
/**
* EndpointSuffix property
*
* @type {string}
* @memberof CommunicationBinding
* @wIgnore
*/
public EndpointSuffix: string;
public abstract CreateBindingElements(): BindingElementCollection;
/**
* CreateMessage method
*
* @abstract
* @param {string} baseUrl
* @param {string} methodName
* @param {any[]} args
* @return {*} {Message}
* @memberof CommunicationBinding
* @wIgnore
*/
public abstract CreateMessage(
baseUrl: string,
methodName: string,
args: any[]
): Message;
/**
* CreateResponseMessage method
*
* @abstract
* @param {*} result
* @param {*} [classConstructor]
* @return {*} {Message}
* @memberof CommunicationBinding
* @wIgnore
*/
public abstract CreateResponseMessage(
result: any,
classConstructor?: any
): Message;
}
/**
* Defines the contract for the basic state machine for all communication-oriented
* objects in the system
*
* @export
* @interface ICommunicationObject
* @wInterface System.ServiceModel.ICommunicationObject
*/
export interface ICommunicationObject {
EndClose(result: IAsyncResult): any;
/**
* Begins close method
*
* @param {AsyncCallback} callback
* @param {*} asyncState
* @returns {IAsyncResult}
* @memberof ICommunicationObject
* @wIgnore
*/
BeginClose(callback: AsyncCallback, asyncState: any): IAsyncResult;
/**
* Begins an asynchronous operation to close a communication object with a specified time-out.
*
* @param {TimeRange} timeout
* @param {AsyncCallback} callback
* @param {*} asyncState
* @return {*} {IAsyncResult}
* @memberof ICommunicationObject
* @wIgnore
*/
BeginCloseWithTimeout(
timeout: TimeRange,
callback: AsyncCallback,
asyncState: any
): IAsyncResult;
EndOpen(result: IAsyncResult): any;
/**
* Begins open method
*
* @param {AsyncCallback} callback
* @param {*} asyncState
* @returns {IAsyncResult}
* @memberof ICommunicationObject
* @wIgnore
*/
BeginOpen(callback: AsyncCallback, asyncState: any): IAsyncResult;
/**
* Begins an asynchronous operation to open a communication object within a specified interval of time.
*
* @param {TimeRange} timeout
* @param {AsyncCallback} callback
* @param {*} asyncState
* @return {*} {IAsyncResult}
* @memberof ICommunicationObject
* @wIgnore
*/
BeginOpenWithTimeout(
timeout: TimeRange,
callback: AsyncCallback,
asyncState: any
): IAsyncResult;
Abort(): void;
/**
* Causes a communication object to transition from the created state into the opened
* state within a specified interval of time.
*
* @param {TimeRange} timeout
* @memberof ICommunicationObject
* @wIgnore
*/
OpenWithTimeout(timeout: TimeRange): void;
/**
* Causes a communication object to transition from its current state into the closed state.
*
* @param {TimeRange} timeout
* @memberof ICommunicationObject
* @wIgnore
*/
CloseWithTimeout(timeout: TimeRange): void;
EndClose(result: IAsyncResult);
}
/**
* Provides a common base implementation for the basic state machine common to all
* communication-oriented objects in the system, including channels and the channel
* factories.
*
* @export
* @abstract
* @class WcfCommunicationObject
* @implements {ICommunicationObject}
* @wType System.ServiceModel.Channels.CommunicationObject
*/
export abstract class WcfCommunicationObject implements ICommunicationObject {
/**
* Completes an asynchronous operation to close a communication object.
*
* @param {*} result
* @memberof WcfCommunicationObject
* @wNoMap
*/
EndClose(result: IAsyncResult);
EndClose(result: any) {
Debugger.Throw('Method not implemented.');
}
/**
* Begins an asynchronous operation to close a communication object.
*
* @param {AsyncCallback} callback
* @param {*} asyncState
* @return {*} {IAsyncResult}
* @memberof WcfCommunicationObject
* @wNoMap
*/
BeginClose(callback: AsyncCallback, asyncState: any): IAsyncResult {
Debugger.Throw('Method not implemented.');
return null;
}
/**
* Begins an asynchronous operation to close a communication object with a specified timeout.
*
* @param {TimeRange} timeout
* @param {AsyncCallback} callback
* @param {*} asyncState
* @return {*} {IAsyncResult}
* @memberof WcfCommunicationObject
* @wIgnore
*/
BeginCloseWithTimeout(
timeout: TimeRange,
callback: AsyncCallback,
asyncState: any
): IAsyncResult {
Debugger.Throw('Method not implemented.');
return null;
}
/**
* Completes an asynchronous operation to open a communication object.
*
* @param {IAsyncResult} result
* @memberof WcfCommunicationObject
* @wNoMap
*/
EndOpen(result: IAsyncResult) {
Debugger.Throw('Method not implemented.');
}
/**
* Begins an asynchronous operation to open a communication object.
*
* @param {AsyncCallback} callback
* @param {*} asyncState
* @return {*} {IAsyncResult}
* @memberof WcfCommunicationObject
* @wNoMap
*/
BeginOpen(callback: AsyncCallback, asyncState: any): IAsyncResult {
Debugger.Throw('Method not implemented.');
return null;
}
/**
* Begins an asynchronous operation to close a communication object within a specified interval of time.
*
* @param {TimeRange} timeout
* @param {AsyncCallback} callback
* @param {*} asyncState
* @return {*} {IAsyncResult}
* @memberof WcfCommunicationObject
* @wIgnore
*/
BeginOpenWithTimeout(
timeout: TimeRange,
callback: AsyncCallback,
asyncState: any
): IAsyncResult {
Debugger.Throw('Method not implemented.');
return null;
}
/**
* Causes a communication object to transition immediately from its current state into the closing state.
*
* @memberof WcfCommunicationObject
* @wNoMap
*/
Abort(): void {
Debugger.Throw('Method not implemented.');
}
/**
* Causes a communication object to transition from the created state into the opened state.
*
* @memberof WcfCommunicationObject
* @wNoMap
*/
Open() {
Debugger.Throw('Method not implemented.');
}
/**
* Causes a communication object to transition from the created state into the opened
* state within a specified interval of time.
*
* @param {TimeRange} timeout
* @memberof WcfCommunicationObject
* @wIgnore
*/
OpenWithTimeout(timeout: TimeRange): void {
Debugger.Throw('Method not implemented.');
}
/**
* Causes a communication object to transition from its current state into the closed state.
*
* @memberof WcfCommunicationObject
* @wNoMap
*/
Close() {
Debugger.Throw('Method not implemented.');
}
/**
* Causes a communication object to transition from its current state into the closed
* state within a specified interval of time.
*
* @param {TimeRange} timeout
* @memberof WcfCommunicationObject
* @wIgnore
*/
CloseWithTimeout(timeout: TimeRange): void {
Debugger.Throw('Method not implemented.');
}
/**
* Gets a value that indicates the current state of the communication object.
*
* @readonly
* @type {CommunicationState}
* @memberof WcfCommunicationObject
* @wNoMap
*/
get State(): CommunicationState {
Debugger.Throw('Method not implemented.');
return null;
}
protected abstract OnBeginClose(
timeout: any,
callback: AsyncCallback,
state: object
): IAsyncResult;
protected abstract OnBeginOpen(
timeout: any,
callback: AsyncCallback,
state: object
): IAsyncResult;
}
/**
* Provides the base implementation for custom channels.
*
* @export
* @abstract
* @class WcfChannelBase
* @extends {WcfCommunicationObject}
* @wType System.ServiceModel.Channels.ChannelBase
*/
export abstract class WcfChannelBase extends WcfCommunicationObject {
/**
* Optional angular HttpClient instance to use with this object
*
* @type {HttpClient}
* @memberof HttpChannel
* @wIgnore
*/
public HttpClient: HttpClient = null;
/**
* Flag to determine if this channel is going to perform the requests using POST or GET
*
* @memberof HttpChannel
* @wIgnore
*/
protected UsePost = true;
DefaultSendTimeout: TimeRange = new TimeRange();
constructor(manager: any) {
super();
}
/**
* BeginRequestWithTimeout method
*
* @abstract
* @param {Message} message
* @param {TimeRange} timeout
* @param {AsyncCallback} callback
* @param {*} state
* @return {*} {IAsyncResult}
* @memberof WcfChannelBase
* @wIgnore
*/
public abstract BeginRequestWithTimeout(
message: Message,
timeout: TimeRange,
callback: AsyncCallback,
state: any
): IAsyncResult;
/**
* BeginRequest method
*
* @abstract
* @param {Message} message
* @param {AsyncCallback} callback
* @param {*} state
* @return {*} {IAsyncResult}
* @memberof WcfChannelBase
* @wIgnore
*/
public abstract BeginRequest(
message: Message,
callback: AsyncCallback,
state: any
): IAsyncResult;
/**
* EndRequest method
*
* @abstract
* @param {IAsyncResult} result
* @return {*} {WcfMessage}
* @memberof WcfChannelBase
* @wIgnore
*/
public abstract EndRequest(result: IAsyncResult): WcfMessage;
/**
* Returns the typed object requested, if present, from the appropriate layer in the channel stack.
*
* @template T
* @return {*} {T}
* @memberof WcfChannelBase
* @wNoMap
*/
GetProperty<T>(): T {
Debugger.Throw('Not implemented');
return null;
}
}
/**
* Provides a base implementation for managing the default timeouts that are associated
* with channel and listener factories.
*
* @export
* @class WcfChannelManagerBase
* @wType System.ServiceModel.Channels.ChannelManagerBase
*/
export class WcfChannelManagerBase {}
/**
* Defines the states in which an System.ServiceModel.ICommunicationObject can exist.
*
* @export
* @enum {number}
* @wEnum System.ServiceModel.CommunicationState
*/
export enum CommunicationState {
Created,
Opening,
Opened,
Closing,
Closed,
Faulted,
}