Пример #1
0
 public static TestService <TSource> Create <TSource>(QbservableServiceOptions options, TestQactiveProvider provider, IObservable <TSource> source)
 => new TestService <TSource>(options, provider, source);
        internal RxService EnsureObservableListening(string agentId, string propertyName)
        {
            if (string.IsNullOrEmpty(agentId))
            {
                throw new ArgumentNullException("agentId");
            }
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }

            Lazy <LocalAgentInformation> lazyLocal;

            if (_localAgents.TryGetValue(agentId, out lazyLocal))
            {
                var local = lazyLocal.Value;

                var lazyService = new Lazy <RxService>(
                    () =>
                {
                    //TODO: add support for HttpListener to TCP Qbservable Provider (based on QbservableTcpServer)
                    // see https://rxx.codeplex.com/workitem/25850
                    // setup procedure to follow to give permissions to service if HttpListener is used:
                    // https://stackoverflow.com/questions/169904/can-i-listen-on-a-port-using-httplistener-or-other-net-code-on-vista-without

                    // for now, use a different port for each Qbservable
                    var rxPort = Interlocked.Increment(ref _nextRxPort);

                    //var source = local.<propertyName>;
                    var piDataSource = local.Agent.GetType().GetProperty(propertyName);
                    var dataSource   = piDataSource.GetValue(local.Agent);

                    var dataType = piDataSource.PropertyType.GetGenericArguments().First();

                    var knownTypes = new List <Type>();
                    knownTypes.Add(dataType);
                    if (dataType.IsGenericType)
                    {
                        knownTypes.AddRange(dataType.GenericTypeArguments);
                    }

                    var qbservableOptions = new QbservableServiceOptions {
                        AllowExpressionsUnrestricted = true, EnableDuplex = true, SendServerErrorsToClients = true
                    };
                    foreach (var type in knownTypes)
                    {
                        qbservableOptions.EvaluationContext.AddKnownType(type);
                    }

                    Log.Debug().Message("Creation of a Qbservable server at '{0}:{1}' for the property '{2}'.", this.LocalPeerNode.Host, rxPort, propertyName).WithAgent(agentId).Write();

                    //var service = source.ServeQbservableTcp(new IPEndPoint(IPAddress.Parse(this.LocalPeerNode.Host), rxPort), new QbservableServiceOptions { AllowExpressionsUnrestricted = true, EnableDuplex = true, SendServerErrorsToClients = true });
                    var miServeQbservableTcp = _miServeQbservableTcp.MakeGenericMethod(dataType);
                    var service = (IObservable <TcpClientTermination>)miServeQbservableTcp
                                  .Invoke(null, new object[] { dataSource, new IPEndPoint(this.LocalPeerNode.Host, rxPort), qbservableOptions });

                    return(new RxService(service, rxPort,
                                         service.Subscribe(
                                             termination =>
                    {
                        LogLevel logLevel;
                        switch (termination.Reason)
                        {
                        case QbservableProtocolShutDownReason.None:
                        case QbservableProtocolShutDownReason.ProtocolTerminated:
                        case QbservableProtocolShutDownReason.ObservableTerminated:
                        case QbservableProtocolShutDownReason.ClientTerminated:
                            logLevel = LogLevel.Debug;
                            break;

                        default:
                            logLevel = LogLevel.Warn;
                            break;
                        }

                        var logBuilder = Log.Level(logLevel).Message("Qbservable server located at '{0}' for property '{1}' has terminated with the reason '{2}'.", termination.LocalEndPoint, propertyName, termination.Reason);

                        if (termination.Exceptions.Count > 0)
                        {
                            logBuilder = logBuilder.Exception(new AggregateException(termination.Exceptions.Select(info => info.SourceException)));
                        }

                        logBuilder.WithAgent(agentId).Write();
                    })));
                });

                return(local.RxServices.GetOrAdd(propertyName, lazyService).Value);
            }
            else
            {
                throw new ArgumentException(string.Format("Local agent '{0}' cannot be found.", agentId));
            }
        }
Пример #3
0
 public static TestService <TSource> Create <TSource>(QbservableServiceOptions options, IObservable <TSource> source)
 => new TestService <TSource>(options, (Type[])null, source);
Пример #4
0
 public static TestService <TSource> Create <TSource>(QbservableServiceOptions options, Type[] knownTypes, IObservable <TSource> source)
 => new TestService <TSource>(options, knownTypes, source);
Пример #5
0
 public static TestService <TSource> Create <TSource>(QbservableServiceOptions options, Type[] knownTypes, params Notification <TSource>[] notifications)
 => new TestService <TSource>(options, knownTypes, notifications);
Пример #6
0
 public static TestService <TSource> Create <TSource>(QbservableServiceOptions options, TestQactiveProvider provider, params Notification <TSource>[] notifications)
 => new TestService <TSource>(options, provider, notifications);
Пример #7
0
 public TestService(QbservableServiceOptions options, TestQactiveProvider provider, IObservable <TSource> source)
     : base(source)
 {
     this.options = options;
     provider     = TestQactiveProvider.Create <TSource>();
 }
Пример #8
0
 public static TcpTestService <TSource> Create <TSource>(QbservableServiceOptions options, params Notification <TSource>[] notifications)
 => new TcpTestService <TSource>(options, (Type[])null, notifications);
Пример #9
0
 public TestService(QbservableServiceOptions options, TestQactiveProvider provider, params Notification <TSource>[] notifications)
     : base(notifications)
 {
     this.options = options;
     provider     = TestQactiveProvider.Create <TSource>();
 }
Пример #10
0
 public WebSocketTestService(QbservableServiceOptions options, Type[] knownTypes, IObservable <TSource> source)
     : this(DefaultUri, options, knownTypes, source)
 {
 }
Пример #11
0
 public WebSocketTestService(QbservableServiceOptions options, Type[] knownTypes, params Notification <TSource>[] notifications)
     : this(DefaultUri, options, knownTypes, notifications)
 {
 }
Пример #12
0
 public TcpTestService(QbservableServiceOptions options, Type[] knownTypes, IObservable <TSource> source)
     : this(DefaultEndPoint, options, knownTypes, source)
 {
 }
Пример #13
0
 public TcpTestService(QbservableServiceOptions options, Type[] knownTypes, params Notification <TSource>[] notifications)
     : this(DefaultEndPoint, options, knownTypes, notifications)
 {
 }