public static IObservable <TcpClientTermination> CreateService <TSource, TResult>( IPEndPoint endPoint, IRemotingFormatter formatter, Func <IObservable <TSource>, IQbservable <TResult> > service) { return(CreateService <TSource, TResult>(endPoint, () => formatter, QbservableServiceOptions.Default, service)); }
public TcpClientQbservableProvider(Type sourceType, IPEndPoint endPoint, IRemotingFormatter formatter, LocalEvaluator localEvaluator) { this.sourceType = sourceType; this.endPoint = endPoint; this.formatter = formatter; this.localEvaluator = localEvaluator; }
public static IObservable <TcpClientTermination> ServeTcp <TSource>( this IQbservable <TSource> source, IPEndPoint endPoint, IRemotingFormatter formatter) { return(QbservableTcpServer.CreateService <object, TSource>(endPoint, formatter, _ => source)); }
public static IObservable <TcpClientTermination> CreateService <TSource, TResult>( IPEndPoint endPoint, IRemotingFormatter formatter, Func <IObservable <TSource>, IObservable <TResult> > service) { return(CreateService <TSource, TResult>(endPoint, formatter, request => service(request).AsQbservable())); }
public TcpQbservableClient(IPAddress address, int port, IRemotingFormatter formatter, params Type[] knownTypes) : this(new IPEndPoint(address, port), formatter, knownTypes) { Contract.Requires(address != null); Contract.Requires(port >= IPEndPoint.MinPort); Contract.Requires(port <= IPEndPoint.MaxPort); Contract.Requires(formatter != null); }
internal QbservableProtocol(Stream stream, IRemotingFormatter formatter, QbservableServiceOptions serviceOptions, CancellationToken cancel) : this(stream, formatter, cancel) { Contract.Ensures(!IsClient); this.serviceOptions = serviceOptions; this.isClient = false; }
public TcpQbservableClient(IPAddress address, int port, IRemotingFormatter formatter, LocalEvaluator localEvaluator) : this(new IPEndPoint(address, port), formatter, localEvaluator) { Contract.Requires(address != null); Contract.Requires(port >= IPEndPoint.MinPort); Contract.Requires(port <= IPEndPoint.MaxPort); Contract.Requires(formatter != null); Contract.Requires(localEvaluator != null); }
public static IStreamQbservableProtocol CreateServer(Stream stream, IRemotingFormatter formatter, QbservableServiceOptions serviceOptions, CancellationToken cancel) { Contract.Requires(stream != null); Contract.Requires(formatter != null); Contract.Requires(serviceOptions != null); Contract.Ensures(Contract.Result <IStreamQbservableProtocol>() != null); return(new StreamQbservableProtocol(stream, formatter, serviceOptions, cancel)); }
/// <summary> /// 反序列化对象,默认从二进制字符串反序列化为对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="graph"></param> /// <param name="formatterType"></param> /// <returns></returns> public static T DeserializeStringToObject <T>(string graph, FormatterType formatterType) { Byte[] arrGraph = Convert.FromBase64String(graph); using (MemoryStream memoryStream = new MemoryStream(arrGraph)) { IRemotingFormatter formatter = GetFormatter(formatterType); return((T)formatter.Deserialize(memoryStream)); } }
public TcpQbservableClient(IPEndPoint endPoint, IRemotingFormatter formatter, LocalEvaluator localEvaluator) { Contract.Requires(endPoint != null); Contract.Requires(formatter != null); Contract.Requires(localEvaluator != null); this.endPoint = endPoint; this.formatter = formatter; this.localEvaluator = localEvaluator; }
/// <summary> /// 把对象序列化转换成字符串,默认为二进制序列化 /// </summary> /// <param name="graph"></param> /// <param name="formatterType"></param> /// <returns></returns> public static string SerializeObjectToString(object graph, FormatterType formatterType) { using (MemoryStream memoryStream = new MemoryStream()) { IRemotingFormatter formatter = GetFormatter(formatterType); formatter.Serialize(memoryStream, graph); Byte[] arrGraph = memoryStream.ToArray(); return(Convert.ToBase64String(arrGraph)); } }
public WebSocketQbservableClient(Uri uri, IRemotingFormatter formatter, LocalEvaluator localEvaluator) { Contract.Requires(uri != null); Contract.Requires(formatter != null); Contract.Requires(localEvaluator != null); this.uri = uri; this.formatter = formatter; this.localEvaluator = localEvaluator; }
internal QbservableProtocol(Stream stream, IRemotingFormatter formatter, CancellationToken cancel) { Contract.Ensures(IsClient); this.isClient = true; this.stream = stream; this.formatter = formatter; this.cancel = protocolCancellation.Token; cancel.Register(protocolCancellation.Cancel, useSynchronizationContext: false); }
public static IObservable <ClientTermination> CreateService <TSource, TResult>( IPEndPoint endPoint, IRemotingFormatter formatter, Func <IObservable <TSource>, IQbservable <TResult> > service) { Contract.Requires(endPoint != null); Contract.Requires(formatter != null); Contract.Requires(service != null); Contract.Ensures(Contract.Result <IObservable <ClientTermination> >() != null); return(QbservableServer.CreateService(TcpQactiveProvider.Server(endPoint), service)); }
public StreamQbservableProtocol(Stream stream, IRemotingFormatter formatter, QbservableServiceOptions serviceOptions, CancellationToken cancel) : base(stream, serviceOptions, cancel) { Contract.Requires(stream != null); Contract.Requires(formatter != null); Contract.Requires(serviceOptions != null); this.formatter = formatter; sendQ.UnhandledExceptions.Subscribe(AddError); receiveQ.UnhandledExceptions.Subscribe(AddError); }
public static IObservable <ClientTermination> CreateService <TSource, TResult>( Uri uri, IRemotingFormatter formatter, Func <IObservable <TSource>, IQbservable <TResult> > service) { Contract.Requires(uri != null); Contract.Requires(formatter != null); Contract.Requires(service != null); Contract.Ensures(Contract.Result <IObservable <ClientTermination> >() != null); return(QbservableServer.CreateService(WebSocketQactiveProvider.Server(uri), service)); }
public StreamQbservableProtocol(object clientId, Stream stream, IRemotingFormatter formatter, CancellationToken cancel) : base(clientId, stream, cancel) { Contract.Requires(clientId != null); Contract.Requires(stream != null); Contract.Requires(formatter != null); this.formatter = formatter; sendQ.UnhandledExceptions.Subscribe(AddError); receiveQ.UnhandledExceptions.Subscribe(AddError); }
/// <summary> /// 把已序列化为字符串类型的对象反序列化为指定的类型 /// </summary> /// <param name="serializedGraph">已序列化为字符串类型的对象</param> /// <param name="formatterType">消息格式编码类型(Soap或Binary型)</param> /// <param name="binder"></param> /// <returns>串行化转化结果</returns> /// <remarks>调用BinaryFormatter或SoapFormatter的Deserialize方法实现主要转换过程。</remarks> public static object DeserializeStringToObject(this string serializedGraph, SerializationFormatterType formatterType, SerializationBinder binder) { ExceptionHelper.CheckStringIsNullOrEmpty(serializedGraph, "serializedGraph"); Byte[] arrGraph = Convert.FromBase64String(serializedGraph); using (MemoryStream memoryStream = new MemoryStream(arrGraph)) { IRemotingFormatter formatter = GetFormatter(formatterType); formatter.Binder = binder; return(formatter.Deserialize(memoryStream)); } }
/// <summary> /// 把对象序列化转换为字符串 /// </summary> /// <param name="graph">可串行化对象实例</param> /// <param name="formatterType">消息格式编码类型(Soap或Binary型)</param> /// <returns>串行化转化结果</returns> /// <remarks>调用BinaryFormatter或SoapFormatter的Serialize方法实现主要转换过程。 /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Test\Core\SerializationHelperTest.cs" region="TestSerializeAndDeserialize" lang="cs" title="把对象转换为字符串" /> /// </remarks> public static string SerializeObjectToString(this object graph, SerializationFormatterType formatterType) { ExceptionHelper.FalseThrow <ArgumentNullException>(graph != null, "graph"); using (MemoryStream memoryStream = new MemoryStream()) { IRemotingFormatter formatter = GetFormatter(formatterType); formatter.Serialize(memoryStream, graph); Byte[] arrGraph = memoryStream.ToArray(); return(Convert.ToBase64String(arrGraph)); } }
internal static IMessage DeserializeMessage(string mimeType, Stream xstm, bool methodRequest, IMessage msg, Header[] h) { Stream serializationStream = null; object obj2; bool flag = false; bool flag2 = true; if (string.Compare(mimeType, "application/octet-stream", StringComparison.Ordinal) == 0) { flag2 = true; } if (string.Compare(mimeType, "text/xml", StringComparison.Ordinal) == 0) { flag2 = false; } if (!flag) { serializationStream = xstm; } else { long position = xstm.Position; byte[] bytes = ((MemoryStream)xstm).ToArray(); xstm.Position = position; MemoryStream stream3 = new MemoryStream(Convert.FromBase64String(Encoding.ASCII.GetString(bytes, 0, bytes.Length))); serializationStream = stream3; } IRemotingFormatter formatter = MimeTypeToFormatter(mimeType, false); if (flag2) { obj2 = ((BinaryFormatter)formatter).UnsafeDeserializeMethodResponse(serializationStream, null, (IMethodCallMessage)msg); } else if (methodRequest) { MethodCall call = new MethodCall(h); formatter.Deserialize(serializationStream, new HeaderHandler(call.HeaderHandler)); obj2 = call; } else { IMethodCallMessage mcm = (IMethodCallMessage)msg; MethodResponse response = new MethodResponse(h, mcm); formatter.Deserialize(serializationStream, new HeaderHandler(response.HeaderHandler)); obj2 = response; } return((IMessage)obj2); }
public static string SerializeObject(object graph, SerializationFormatterType formatterType) { if (graph == null) { throw new ArgumentNullException("graph"); } if (SerializationFormatterType.Xml == formatterType) { return(XmlSerializeObject(graph)); } using (MemoryStream memoryStream = new MemoryStream()) { IRemotingFormatter formatter = GetFormatter(formatterType); formatter.Serialize(memoryStream, graph); byte[] arrGraph = memoryStream.ToArray(); return(Convert.ToBase64String(arrGraph)); } }
public static bool SerializeObjectToFile(object graph, SerializationFormatterType formatterType, string path) { if (graph == null) { throw new ArgumentNullException("graph"); } if (SerializationFormatterType.Xml == formatterType) { return(XmlSerializeObjectToFile(graph, path)); } using (FileStream fileStream = new FileStream(path, FileMode.Create)) { IRemotingFormatter formatter = GetFormatter(formatterType); formatter.Serialize(fileStream, graph); fileStream.Flush(); return(true); } }
public static T DeserializeObjectFromFile <T>(string path, SerializationFormatterType formatterType, SerializationBinder binder = null) { if (!File.Exists(path)) { throw new FileNotFoundException("path"); } if (SerializationFormatterType.Xml == formatterType) { return(XmlDeserializeObjectFromFile <T>(path)); } using (FileStream fileStream = new FileStream(path, FileMode.Open)) { IRemotingFormatter formatter = GetFormatter(formatterType); if (binder != null) { formatter.Binder = binder; } return((T)formatter.Deserialize(fileStream)); } }
public static T DeserializeObject <T>(string serializedGraph, SerializationFormatterType formatterType, SerializationBinder binder = null) { if (string.IsNullOrEmpty(serializedGraph.Trim())) { throw new ArgumentNullException("serializedGraph"); } if (SerializationFormatterType.Xml == formatterType) { return(XmlDeserializeObject <T>(serializedGraph)); } byte[] arrGraph = Convert.FromBase64String(serializedGraph); using (MemoryStream memoryStream = new MemoryStream(arrGraph)) { IRemotingFormatter formatter = GetFormatter(formatterType); if (binder != null) { formatter.Binder = binder; } return((T)formatter.Deserialize(memoryStream)); } }
public CookieTempDataProvider(IRemotingFormatter formatter) { _formatter = formatter; }
protected QbservableProtocol(NetworkStream stream, IRemotingFormatter formatter, QbservableServiceOptions serviceOptions, CancellationToken cancel) : base(stream, formatter, serviceOptions, cancel) { Contract.Ensures(!IsClient); }
public static async Task <QbservableProtocol> NegotiateServerAsync(Stream stream, IRemotingFormatter formatter, QbservableServiceOptions serviceOptions, CancellationToken cancel) { // TODO: Enable protocol registration and implement actual protocol negotiation var protocol = new DefaultQbservableProtocol(stream, formatter, serviceOptions, cancel); var buffer = new byte[4]; await protocol.ReceiveAsync(buffer, 0, 4).ConfigureAwait(false); await protocol.SendAsync(buffer, 0, 4).ConfigureAwait(false); return(protocol); }
public static async Task <QbservableProtocol> NegotiateClientAsync(Stream stream, IRemotingFormatter formatter, CancellationToken cancel) { // TODO: Enable protocol registration and implement actual protocol negotiation var protocol = new DefaultQbservableProtocol(stream, formatter, cancel); const int ping = 123; var buffer = BitConverter.GetBytes(ping); await protocol.SendAsync(buffer, 0, 4).ConfigureAwait(false); await protocol.ReceiveAsync(buffer, 0, 4).ConfigureAwait(false); Contract.Assume(BitConverter.ToInt32(buffer, 0) == ping); return(protocol); }
public QbservableTcpClient(IPEndPoint endPoint, IRemotingFormatter formatter, LocalEvaluator localEvaluator) { this.endPoint = endPoint; this.formatter = formatter; this.localEvaluator = localEvaluator; }
public QbservableTcpClient(IPEndPoint endPoint, IRemotingFormatter formatter, params Type[] knownTypes) : this(endPoint, formatter, new ImmediateLocalEvaluator(knownTypes)) { }
public QbservableTcpClient(IPEndPoint endPoint, IRemotingFormatter formatter) : this(endPoint, formatter, new ImmediateLocalEvaluator()) { }