Exemplo n.º 1
0
        private static void ChooseActivePartition(int partitionAreaLength, ref int activePartition, ref ThingsWorker thingsWorker)
        {
            int tempPartition;

            Console.Write("Active Partition: ");
            tempPartition = int.Parse(Console.ReadLine());

            if (tempPartition < 0 || tempPartition >= partitionAreaLength)
            {
                Console.WriteLine("Value ignored!");
            }
            else
            {
                if (thingsWorker != null)
                {
                    thingsWorker.UnregisterReceiver();
                    thingsWorker.Dispose();
                    thingsWorker = null;
                }

                activePartition = tempPartition;
            }
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            var          runClient       = true;
            var          activePartition = 0;
            var          thingProcesses  = new List <Process>();
            ThingsWorker thingsWorker    = null;

            var thingPath                  = ConfigurationManager.AppSettings[THING_PATH];
            var partitionArea              = ConfigurationManager.AppSettings[PARTITION_AREA].Split(SEPARATOR_VALUES);
            var commandTopics              = int.Parse(ConfigurationManager.AppSettings[COMMAND_TOPICS]);
            var commandSubscriptions       = int.Parse(ConfigurationManager.AppSettings[COMMAND_SUBSCRIPTIONS]);
            var serviceNamespace           = ConfigurationManager.AppSettings[SERVICE_NAMESPACE].Split(SEPARATOR_VALUES);
            var serviceOwner               = ConfigurationManager.AppSettings[SERVICE_OWNER];
            var serviceOwnerSecret         = ConfigurationManager.AppSettings[SERVICE_OWNER_SECRET].Split(SEPARATOR_VALUES);
            var eventStore                 = ConfigurationManager.AppSettings[EVENT_STORE];
            var storageWriterConnection    = ConfigurationManager.AppSettings[STORAGE_WRITER_CONNECTION];
            var acsManagementServiceName   = ConfigurationManager.AppSettings[ACS_MANAGEMENT_SERVICE_NAME];
            var acsManagementServiceSecret = ConfigurationManager.AppSettings[ACS_MANAGEMENT_SERVICE_SECRET].Split(SEPARATOR_VALUES);

            ProcessCommandLineParameters(args, partitionArea.Length, ref activePartition);

            do
            {
                FormatConsole(serviceNamespace[activePartition], commandTopics, commandSubscriptions);
                Console.Clear();

                Console.WriteLine("Internet Of Things - Area '{0}'", partitionArea[activePartition]);
                Console.WriteLine();

                Console.WriteLine("a. Allocate Partition");
                Console.WriteLine("b. Register Thing");
                Console.WriteLine("c. Register Ingestion Topic Receiver");
                Console.WriteLine("x. Choose Active Partition");

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

                try
                {
                    switch (Console.ReadKey(true).KeyChar)
                    {
                    case 'a':
                        AllocatePartition(commandTopics, commandSubscriptions,
                                          partitionArea[activePartition], serviceNamespace[activePartition], eventStore,
                                          serviceOwner, serviceOwnerSecret[activePartition], storageWriterConnection,
                                          acsManagementServiceName, acsManagementServiceSecret[activePartition]);

                        break;

                    case 'b':
                        thingProcesses.Add(RegisterThing(thingPath,
                                                         commandTopics, commandSubscriptions, partitionArea[activePartition]));
                        break;

                    case 'c':
                        thingsWorker = RegisterIngestionTopicReceiver(thingsWorker,
                                                                      serviceNamespace[activePartition],
                                                                      serviceOwner, serviceOwnerSecret[activePartition],
                                                                      storageWriterConnection);
                        break;

                    case 'x':
                        ChooseActivePartition(partitionArea.Length, ref activePartition, ref thingsWorker);
                        break;

                    case '0':
                        StopThingProcesses(thingProcesses);

                        if (thingsWorker != null)
                        {
                            thingsWorker.Dispose();
                        }

                        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);
        }