Ejemplo n.º 1
0
        /// <summary>
        ///     Adds the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="service">The service.</param>
        /// <param name="outputGateway">The output gateway.</param>
        public void Add(SubscriptionKey key, Identification service, IOutputGateway <byte[]> outputGateway)
        {
            LoggerManager.Instance.Info(string.Format("Add Type {0}", key.Key));
            bool lockTaken = false;

            _lockKeys.Enter(ref lockTaken);
            if (lockTaken)
            {
                try
                {
                    if (!_keyDictionary.ContainsKey(key))
                    {
                        _keyDictionary.Add(key, new List <IOutputGateway <byte[]> >());
                    }
                    _keyDictionary[key].Add(outputGateway);

                    ReloadAssignableTypes(key, service, outputGateway);
                }
                catch (Exception exception)
                {
                    LoggerManager.Instance.Error(string.Format("Error al añadir suscriptor {0}", key.Key), exception);
                }
                finally
                {
                    LoggerManager.Instance.Info(string.Format("Se libera el lock {0}", key.Key));
                    _lockKeys.Exit();
                }
            }
        }
        public async Task <SubscriptionOnStateValue> Subscribe(string sentinelHost, string packageHost, string stateValueName)
        {
            using (var client = new HomeConnectionClient(HomeHubConnection))
            {
                var stateValueKey = new StateValueKey(sentinelHost, packageHost, stateValueName);
                await SubscribeOnValueChanged(stateValueKey);

                var subscriptionKeyValue = await client.PostAsJson <string>("subscription",
                                                                            new Subscription(SentinelHost.GetName(), sentinelHost, packageHost, stateValueName));

                if (!string.IsNullOrEmpty(subscriptionKeyValue))
                {
                    var subscriptionKey = new SubscriptionKey(subscriptionKeyValue);
                    if (subscriptionKey.IsValid())
                    {
                        var subscriptionOnStateValue = new SubscriptionOnStateValue(subscriptionKey, stateValueKey);
                        AddSubscriptionInStore(stateValueKey, subscriptionOnStateValue);

                        return(subscriptionOnStateValue);
                    }
                }
                else
                {
                    await UnSubscribeOnValueChanged(new StateValueKey(sentinelHost, packageHost, stateValueName));
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
		public void UnsubscribeCandles(CandleSeries series)
		{
			var key = new SubscriptionKey(series.Security.Id, (TimeSpan) series.Arg);
			var subscription = _candleSubscriptions.TryGetValue(key);
			if(subscription == null)
				return;

			subscription.RemoveSubscriber(series);
			if(subscription.NumSubscribers > 0)
				return;

			subscription.CandleBuilder.Candle -= CandleBuilderOnCandle;
			_candleSubscriptions.Remove(key);

			var msg = new MarketDataMessage().FillSecurityInfo(this, series.Security);
			msg.TransactionId = TransactionIdGenerator.GetNextId();
			msg.OriginalTransactionId = subscription.SubscribeTransactionId;
			msg.SecurityId = GetSecurityId(series.Security);
			msg.DataType = MarketDataTypes.CandleTimeFrame;
			msg.IsSubscribe = false;
			msg.From = subscription.From;
			msg.Arg = subscription.TimeFrame;

			SendInMessage(msg);

			UnSubscribeMarketData(series.Security, MarketDataTypes.CandleTimeFrame);
		}
Ejemplo n.º 4
0
 public override int GetHashCode()
 {
     return(ModelID.GetHashCode()
            ^ SubscriptionKey.GetHashCode()
            ^ UriBase.GetHashCode()
            ^ ApiVersion.GetHashCode());
 }
Ejemplo n.º 5
0
        public void return_true_when_2_subscription_key_arent_equals()
        {
            var subscriptionKey1 = new SubscriptionKey(Guid.NewGuid().ToString());
            var subscriptionKey2 = new SubscriptionKey(Guid.NewGuid().ToString());

            Check.That(subscriptionKey1 != subscriptionKey2).IsEqualTo(true);
        }
Ejemplo n.º 6
0
        public void SetUp()
        {
            _subscriptorsRepository = new Mock <ISubscriptorsRepository>(MockBehavior.Strict);
            _subscriptorPersister   = new Mock <ISubscriptorsPersister>(MockBehavior.Strict);
            _controller             = new Mock <IRouterController>(MockBehavior.Strict);
            _processor            = new Mock <IProcessorFake>(MockBehavior.Strict);
            _outputControlGateway = new Mock <IOutputGateway <IControlMessage> >(MockBehavior.Strict);
            _outputGateway        = new Mock <IOutputGateway <byte[]> >(MockBehavior.Strict);

            _controller.SetupGet(c => c.Processor).Returns(_processor.Object);
            _identification = new Identification {
                Id = "Test", Type = "Test_Type"
            };
            _subscriptionKey = new SubscriptionKey
            {
                Key = string.Format("{0},{1}", typeof(string).FullName, typeof(string).Assembly.GetName().Name)
            };

            _subscriptor = new Subscriptor()
            {
                Service = new Identification {
                    Id = "Service", Type = "Service"
                },
                ServiceInputControlGateway = _outputControlGateway.Object,
                ServiceInputGateway        = _outputGateway.Object,
                SubcriptionTypes           = new List <SubscriptionKey> {
                    _subscriptionKey
                }
            };

            _subscriptorsRepository.Setup(r => r.Dispose());
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Unsubscribes the specified type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="service"></param>
        /// <param name="sender">The sender.</param>
        public void Unsubscribe(SubscriptionKey type, Identification service, IOutputGateway <byte[]> sender)
        {
            bool lockTaken = false;

            _lockSubcriptorsList.Enter(ref lockTaken);
            if (lockTaken)
            {
                try
                {
                    if (_subcriptorsList.ContainsKey(service))
                    {
                        _subcriptorsList.Remove(service);
                    }
                }
                catch (Exception exception)
                {
                    LoggerManager.Instance.Error(string.Format("Error al añadir suscriptor {0}", service.Id), exception);
                }
                finally
                {
                    LoggerManager.Instance.Info(string.Format("Se libera el lock {0}", service.Id));
                    _lockSubcriptorsList.Exit();
                }
            }

            _gatewaysRepository.RemoveSender(type, service, sender);
        }
        public void Construct_GetNoParams_ExpectAbsoluteURI()
        {
            var key     = new SubscriptionKey("01234567890123456789012345678901");
            var request = new Request(HttpMethod.Get, key, Domain.EssentialsV2);

            Assert.True(request.GetUri().IsAbsoluteUri);
        }
        public void Construct_GetWithParams_ExpectParams()
        {
            var key            = new SubscriptionKey("01234567890123456789012345678901");
            var expected_value = @"ParamValue";
            var request        = new Request(HttpMethod.Get, key, Domain.EssentialsV2, queryParam: expected_value);

            Assert.Equal(expected_value, request.QueryParam);
        }
Ejemplo n.º 10
0
        public void return_true_when_2_subscription_key_are_equals_with_override_equals_method()
        {
            var id = Guid.NewGuid().ToString();
            var subscriptionKey1 = new SubscriptionKey(id);
            var subscriptionKey2 = new SubscriptionKey(id);

            Check.That(subscriptionKey1.Equals(subscriptionKey2)).IsEqualTo(true);
        }
        public void Equals_NotEqual_ExpectFalse()
        {
            var key  = new SubscriptionKey("01234567890123456789012345678901");
            var req1 = new Request(HttpMethod.Get, key, Domain.EssentialsV2, "PostParams", "QueryParams");
            var req2 = new Request(HttpMethod.Get, key, Domain.EssentialsV2, "PostParams2", "QueryParams2");

            Assert.NotEqual(req1, req2);
        }
        /// <summary>
        /// Toes the subscriptor key.
        /// </summary>
        /// <param name="subscriptionType">Type of the subscription.</param>
        /// <returns></returns>
        public static SubscriptionKey ToSubscriptorKey(this SubscriptionType subscriptionType)
        {
            var subscriptionKey = new SubscriptionKey
            {
                Key        = subscriptionType.Key,
                ParentKeys = subscriptionType.ParentKeys.Select(pK => ToSubscriptorKey(pK)).ToList()
            };

            return(subscriptionKey);
        }
        /// <summary>
        /// Toes the type of the subscriptor.
        /// </summary>
        /// <param name="subscriptionKey">The subscription key.</param>
        /// <returns></returns>
        public static SubscriptionType ToSubscriptorType(this SubscriptionKey subscriptionKey)
        {
            var subscriptionType = new SubscriptionType
            {
                Key        = subscriptionKey.Key,
                ParentKeys = subscriptionKey.ParentKeys.Select(pK => pK.ToSubscriptorType()).ToList()
            };

            return(subscriptionType);
        }
        public void AddPostParam_KeyValue_ExpectInDictionary()
        {
            var key     = new SubscriptionKey("01234567890123456789012345678901");
            var request = new Request(HttpMethod.Post, key, Domain.EssentialsV2);

            request.AddPostParam("key", "value");

            Assert.True(request.PostParamsDict.ContainsKey("key"));
            Assert.Equal("value", request.PostParamsDict["key"]);
        }
Ejemplo n.º 15
0
        /// <inheritdoc />
        public Task Subscribe(IEndpoint endpoint, TopicName topicName, TimeSpan ttl, CancellationToken cancellationToken = default(CancellationToken))
        {
            CheckDisposed();

            var publisherUri          = endpoint.Address;
            var subscriptionQueueName = _baseUri.GetSubscriptionQueueName(topicName);
            var subscriptionKey       = new SubscriptionKey(publisherUri, subscriptionQueueName);

            _subscriptions.GetOrAdd(subscriptionKey, _ => BindSubscriptionQueue(topicName, publisherUri, subscriptionQueueName, cancellationToken));
            return(Task.FromResult(true));
        }
 public void SetUp()
 {
     _identification = new Identification {
         Id = "Test", Type = "Test_Type"
     };
     _senderMessageFake  = new Mock <IOutputGateway <byte[]> >();
     _senderIMessage     = new Mock <IOutputGateway <byte[]> >();
     _senderIMessageFake = new Mock <IOutputGateway <byte[]> >();
     _subscriptionKey    = SubscriptionKeyMessageFactory.CreateFromType(typeof(MessageFake)).ToSubscriptorKey();
     _key = string.Format("{0},{1}", typeof(MessageFake).FullName, typeof(MessageFake).Assembly.GetName().Name);
 }
        public void GetHashCode_KnownValues_ExpectEqual()
        {
            var key     = new SubscriptionKey("01234567890123456789012345678901");
            var request = new Request(HttpMethod.Get, key, Domain.EssentialsV2, "PostParams", "QueryParams");

            var expected_result = HttpMethod.Get.GetHashCode()
                                  ^ request.GetUri().GetHashCode()
                                  ^ "PostParams".GetHashCode()
                                  ^ "QueryParams".GetHashCode();

            Assert.Equal(expected_result, request.GetHashCode());
        }
Ejemplo n.º 18
0
 public bool Equals(SubscriptionKey other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.MessageName, MessageName) && Equals(other.CorrelationId, CorrelationId));
 }
Ejemplo n.º 19
0
        public bool RemoveSubscription(SentinelKey sentinelKey, SubscriptionKey subscriptionId)
        {
            if (_subscriptions.Any(s => s.Key == sentinelKey))
            {
                _subscriptions[sentinelKey].RemoveAll(s => s.Id == subscriptionId);

                RemoveSubscriptionSentinelKeyEntryIfEmpty(sentinelKey);
                return(true);
            }
            else
            {
                throw new NoSubscriptionFoundException();
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        ///     Removes the specified output gateway.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="service"></param>
        /// <param name="outputGateway">The output gateway.</param>
        public void Remove(SubscriptionKey key, Identification service, IOutputGateway <byte[]> outputGateway)
        {
            LoggerManager.Instance.Info(string.Format("Remove Type {0}", key.Key));
            bool lockTaken = false;

            _lockKeys.Enter(ref lockTaken);
            if (lockTaken)
            {
                try
                {
                    if (_keyDictionary.ContainsKey(key))
                    {
                        _keyDictionary[key].Remove(outputGateway);
                        if (_keyDictionary[key].Count == 0)
                        {
                            _keyDictionary.Remove(key);
                        }
                    }
                }
                finally
                {
                    _lockKeys.Exit();
                }
            }

            lockTaken = false;
            _lockAsignableTypes.Enter(ref lockTaken);
            if (lockTaken)
            {
                try
                {
                    SpinWait.SpinUntil(() => _numThreadsRunning == 0);

                    foreach (var assignableType in _assignableTypesList)
                    {
                        assignableType.Value.Remove(service.Type, outputGateway);
                    }

                    foreach (var assignableType in _assignableTypesList.Where(pair => pair.Value.Count == 0).ToList())
                    {
                        _assignableTypesList.Remove(assignableType);
                    }
                }
                finally
                {
                    _lockAsignableTypes.Exit();
                }
            }
        }
        public void Construct_Post_ExpectPostParams()
        {
            var key = new SubscriptionKey("01234567890123456789012345678901");

            // Set up parameters
            var parms = new Dictionary <string, string>();

            parms.Add("one", "two");
            parms.Add("three", "four");

            var request        = new Request(HttpMethod.Post, key, Domain.EssentialsV2, null, parms);
            var expected_value = "one=two&three=four";

            Assert.NotEmpty(request.PostParamsDict);
            Assert.Equal(expected_value, Encoding.UTF8.GetString(request.EncodePostParams()));
        }
        protected override void Execute(CodeActivityContext context)
        {
            // From Local - manual entries
            //  var jsonResult = GetInvoiceDetailsfromSample();


            // From Azure Form Recognizer
            SetupDictionaryMapping();
            string subscriptionKey        = SubscriptionKey.Get(context);
            string formRecognizerEndPoint = FormRecognizerEndPoint.Get(context);
            string formRecognizerModelId  = FormRecognizerModelId.Get(context);
            string filePath = FilePath.Get(context);

            string jsonResult = GetInvoiceDetailsfromAzureFormRecognizer(subscriptionKey, formRecognizerEndPoint,
                                                                         formRecognizerModelId, filePath);

            // Set the output
            InvoiceJson.Set(context, jsonResult);
        }
Ejemplo n.º 23
0
		public void SubscribeCandles(CandleSeries series)
		{
			if (!IsConnected)
			{
				_subscribersBuffer.Add(series);
				return;
			}

			var key = new SubscriptionKey(series.Security.Id, (TimeSpan) series.Arg);
			var transId = TransactionIdGenerator.GetNextId();
			
			var subscription = _candleSubscriptions.TryGetValue(key);

			if (subscription != null)
			{
				Candles?.Invoke(series, subscription.CandleBuilder.AllCandles);
				subscription.AddSubscriber(series);

				return;
			}

			subscription = new CandleSubscription(series.Security, series.From, (TimeSpan) series.Arg, transId);
			subscription.AddSubscriber(series);
			_candleSubscriptions.Add(key, subscription);

			subscription.CandleBuilder.Candle += CandleBuilderOnCandle;

			var msg = new MarketDataMessage().FillSecurityInfo(this, series.Security);
			msg.TransactionId = transId;
			msg.SecurityId = GetSecurityId(series.Security);
			msg.DataType = MarketDataTypes.CandleTimeFrame;
			msg.IsSubscribe = true;
			msg.From = series.From;
			msg.Arg = series.Arg;

			SendInMessage(msg);

			SubscribeMarketData(series.Security, MarketDataTypes.CandleTimeFrame);
		}
Ejemplo n.º 24
0
        /// <summary>
        ///     Reloads the assignable types.
        /// </summary>
        /// <param name="subscriptionKey">The subscription key.</param>
        /// <param name="service">The service.</param>
        /// <param name="outputGateway">The output gateway.</param>
        private void ReloadAssignableTypes(SubscriptionKey subscriptionKey, Identification service,
                                           IOutputGateway <byte[]> outputGateway)
        {
            //Recargamos la lista de tipos asignables
            bool lockTaken = false;

            _lockAsignableTypes.Enter(ref lockTaken);
            if (lockTaken)
            {
                SpinWait.SpinUntil(() => _numThreadsRunning == 0);

                foreach (var assignableType in _assignableTypesList)
                {
                    KeyValuePair <SubscriptionKey, List <IOutputGateway <byte[]> > > key =
                        _keyDictionary.FirstOrDefault(pair => pair.Key.Key == assignableType.Key);

                    if (key.Key != null && key.Key.IsAssignableKey(subscriptionKey.Key))
                    {
                        if (!assignableType.Value.Exists(outputGateway))
                        {
                            assignableType.Value.Add(service.Type, outputGateway);
                        }
                    }
                }

                if (!_assignableTypesList.ContainsKey(subscriptionKey.Key))
                {
                    var loadBalancerController = new LoadBalancerController <string, IOutputGateway <byte[]> >();
                    _assignableTypesList.Add(subscriptionKey.Key, loadBalancerController);

                    loadBalancerController.Add(service.Type, outputGateway);
                }

                _lockAsignableTypes.Exit();
            }
        }
Ejemplo n.º 25
0
 public SubscriptionOnStateValue(SubscriptionKey key, StateValueKey stateValueKey)
 {
     Key           = key;
     StateValueKey = stateValueKey;
 }
Ejemplo n.º 26
0
 /// <summary>
 ///     Adds the sender.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="service"></param>
 /// <param name="sender">The sender.</param>
 public override void AddSender(SubscriptionKey type, Identification service, IOutputGateway <byte[]> sender)
 {
     LoggerManager.Instance.Debug(string.Format("Add Sender: {0}", type.Key));
     HierarchicalKeyEngine.Add(type, service, sender);
 }
Ejemplo n.º 27
0
 public bool Equals(SubscriptionKey other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.MessageName, MessageName) && Equals(other.CorrelationId, CorrelationId);
 }
Ejemplo n.º 28
0
        public void return_false_when_second_subscription_key_is_null_on_equal()
        {
            var subscriptionKey = new SubscriptionKey(Guid.NewGuid().ToString());

            Check.That(null == subscriptionKey).IsFalse();
        }
Ejemplo n.º 29
0
 private SubscriptionOnStateValue(SubscriptionKey id, StateValueKey stateValueKey)
 {
     Id            = id;
     StateValueKey = stateValueKey;
 }
Ejemplo n.º 30
0
 /// <summary>
 ///     Unsubscribes the specified message type.
 /// </summary>
 /// <param name="messageType">Type of the message.</param>
 /// <param name="service"></param>
 /// <param name="outputGateway">The message sender.</param>
 public void Unsubscribe(SubscriptionKey messageType, Identification service,
                         IOutputGateway <byte[]> outputGateway)
 {
     _routerOutputHelper.Unsubscribe(messageType, service, outputGateway);
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Removes the sender.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="service"></param>
 /// <param name="sender">The sender.</param>
 public abstract void RemoveSender(SubscriptionKey type, Identification service, IOutputGateway <byte[]> sender);
Ejemplo n.º 32
0
        public void return_true_when_second_subscription_key_is_null_on_diffrent()
        {
            var subscriptionKey = new SubscriptionKey(Guid.NewGuid().ToString());

            Check.That(null != subscriptionKey).IsTrue();
        }
Ejemplo n.º 33
0
 /// <summary>
 ///     Removes the sender.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="service"></param>
 /// <param name="sender">The sender.</param>
 public override void RemoveSender(SubscriptionKey type, Identification service, IOutputGateway <byte[]> sender)
 {
     HierarchicalKeyEngine.Remove(type, service, sender);
 }
Ejemplo n.º 34
0
			public CandleSubscription(Security sec, DateTimeOffset from, TimeSpan tf, long transId)
			{
				Security = sec;
				From = from;
				TimeFrame = tf;
				Key = new SubscriptionKey(sec.Id, tf);
				SubscribeTransactionId = transId;
				CandleBuilder = new TerminalCandleBuilder(Security, TimeFrame);
			}
Ejemplo n.º 35
0
		protected override void OnProcessMessage(Message message)
		{
			switch(message.Type)
			{
				case MessageTypes.CandleTimeFrame:
					var msg = (TimeFrameCandleMessage)message;
					var key = new SubscriptionKey(msg.SecurityId.ToStringId(), msg.TimeFrame);

					var subscription = _candleSubscriptions.TryGetValue(key);
					if(subscription == null)
						return;

					subscription.CandleBuilder.ProcessMessage(msg);

					break;
			}

			base.OnProcessMessage(message);
		}
Ejemplo n.º 36
0
		public IEnumerable<TimeFrameCandle> GetSubscribedCandles(CandleSeries subscriber)
		{
			var key = new SubscriptionKey(subscriber.Security.Id, (TimeSpan) subscriber.Arg);
			var subscription = _candleSubscriptions.TryGetValue(key);

			return subscription == null ? Enumerable.Empty<TimeFrameCandle>() : subscription.CandleBuilder.AllCandles;
		}