public InternetOfThings(int commandTopics = PARTITION_DEF_COMMAND_TOPICS, int commandSubscriptions = PARTITION_DEF_COMMAND_SUBSCRIPTIONS) { if (commandTopics <= 0 || _commandTopics > PARTITION_MAX_COMMAND_TOPICS) { throw new ArgumentOutOfRangeException("commandTopics"); } if (commandSubscriptions <= 0 || commandSubscriptions > PARTITION_MAX_COMMAND_SUBSCRIPTIONS) { throw new ArgumentOutOfRangeException("commandSubscriptions"); } _commandTopics = commandTopics; _commandSubscriptions = commandSubscriptions; _maxDeliveryCount = PARTITION_DEF_MAX_DELIVERY_COUNT; _messageTtl = TimeSpan.FromHours(PARTITION_DEF_MESSAGE_TTL); _duplicateDetection = TimeSpan.FromMinutes(PARTITION_DEF_DUPLICATE_DETECTION); _lockDuration = TimeSpan.FromMinutes(PARTITION_DEF_LOCK_DURATION); _tokenLifeTime = TimeSpan.FromMinutes(PARTITION_SECURITY_TOKEN_LIFETIME); _iotRepository = InternetOfThingsRepositoryFactory.CreateInternetOfThingsRepository(); _partitionRepository = _iotRepository as IPartitionRepository; _thingRepository = _iotRepository as IThingRepository; }
private void InitializeObjectMembers(string cloudStorage, string connectionString) { string scheme, ns; _cloudStorage = cloudStorage; _connectionString = connectionString; ServiceBusConnection.ToIssuer(_connectionString, out scheme, out ns); using (var partitionRepository = InternetOfThingsRepositoryFactory.CreatePartitionRepository()) { _eventStore = partitionRepository.GetPartitionByNamespace(ns, false).EventStore; } _catchAllPolicy = new CatchAllPolicy(); _messagingPolicy = new MessagingPolicy(); }
private async Task SendCommandMessageToTargets(BrokeredMessage bm) { var to = string.IsNullOrWhiteSpace(bm.To) ? Guid.Empty : new Guid(bm.To); using (var iotRepository = InternetOfThingsRepositoryFactory.CreateInternetOfThingsRepository()) { if (bm.Properties.Keys.Contains(MessageProperty.BROADCAST)) { foreach (var partition in iotRepository.ActivePartitions) { await BroadcastCommandMessageToPartition(bm.Clone(), partition, iotRepository.GetRelativeIdsByPartition(partition)); } } else if (to != Guid.Empty) { await ForwardCommandMessageToThing(bm.Clone(), iotRepository.GetThingById(to, false)); } } }