Exemple #1
0
        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 static void Main(string[] args)
        {
            string ns,
                   scheme;
            var runClient             = true;
            var thingId               = new Guid(ConfigurationManager.AppSettings[THING_ID]);
            var thingCommandTopic     = int.Parse(ConfigurationManager.AppSettings[THING_COMMAND_TOPIC]);
            var thingConnectionString = ConfigurationManager.AppSettings[THING_CONNECTION_STRING];

            ProcessCommandLineParameters(args, ref thingId, ref thingCommandTopic, ref thingConnectionString);
            ServiceBusConnection.ToIssuer(thingConnectionString, out scheme, out ns);

            do
            {
                FormatConsole(ns, thingCommandTopic);
                Console.Clear();

                Console.WriteLine("Internet Of Things - Device '{0}'", thingId);
                Console.WriteLine();

                Console.WriteLine("a. Send Message To Ingestion Topic");
                Console.WriteLine("b. Receive Message From Command Topic");
                Console.WriteLine("x. Enter Thing Connection Parameter");

                Console.WriteLine();
                Console.WriteLine("0. Exit Application");
                Console.WriteLine();

                try
                {
                    switch (Console.ReadKey(true).KeyChar)
                    {
                    case 'a':
                        SendMessageToIngestionTopic(thingId, thingCommandTopic, thingConnectionString);
                        break;

                    case 'b':
                        ReceiveMessageFromCommandTopic(thingId, thingCommandTopic, thingConnectionString);
                        break;

                    case 'x':
                        EnterThingConnectionParameters(out thingId, out thingCommandTopic, out thingConnectionString);
                        break;

                    case '0':
                        runClient = false;
                        break;

                    default:
                        Console.WriteLine("Key ignored!");
                        break;
                    }

                    if (runClient)
                    {
                        Console.WriteLine("Operation completed!");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\n\nCaught exception: {0}.\n\n", ex);
                }

                if (runClient)
                {
                    Console.ReadKey(true);
                }
            } while (runClient);
        }