public static void Execute(ICommInterface commInterface)
        {
            // Specifies the amount of entries you want to have in the telephonebook.
            int telephoneBookEntryAmount = Convert.ToInt32(commInterface.ReadLine());

            Dictionary <string, int> TelephoneBook = new Dictionary <string, int>(telephoneBookEntryAmount);

            // Iterate through the entry amount and describe each entry in the form of 2 space-separated values on a single line.
            for (int i = 0; i < telephoneBookEntryAmount; i++)
            {
                string[] telephoneBookEntry = commInterface.ReadLine().Split(' ');
                int      digitLength        = 8;
                if (telephoneBookEntry[1].Length == digitLength)
                {
                    TelephoneBook.Add(telephoneBookEntry[0], Convert.ToInt32(telephoneBookEntry[1]));
                }
                else
                {
                    commInterface.WriteLine("This is not a 8 digit phone number!");
                    return;
                }
            }

            // Iterate through the entry amount and search for any key in the dictionary.
            // If found then print the query as name=phonenumber.
            while (true)
            {
                string entrySearch = commInterface.ReadLine();

                if (!string.IsNullOrWhiteSpace(entrySearch))
                {
                    if (TelephoneBook.ContainsKey(entrySearch) && entrySearch.Length != 0)
                    {
                        commInterface.WriteLine($"{entrySearch}={TelephoneBook[entrySearch]}");
                    }
                    else
                    {
                        commInterface.WriteLine("Not found");
                    }
                }
                else
                {
                    break;
                }
            }
        }
Example #2
0
        private void Root_CoreLoaded(object sender, EventArgs e)
        {
            ICommInterface commInterface = root.GetInterface(ecsServerNameTextBox.Text);

            if (commInterface == null)
            {
                Console.WriteLine("No Interface named " + ecsServerNameTextBox.Text + " exists within the tool model");
            }
            else if (!(commInterface is ECSInterface))
            {
                Console.WriteLine("The Interface " + ecsServerNameTextBox.Text + " is not an ECS Interface");
            }
            else
            {
                ecsServerNameTextBox.Enabled = false;
                Text = "Sample OO ECS - Connected";

                ecsInterface = (ECSInterface)commInterface;
                alarmService = ecsInterface.AlarmsService;
                clockService = ecsInterface.ClockService;
                if (clockService != null)
                {
                    clockService.MessageHandler = this;
                }
                commandService = ecsInterface.CommandsService;
                if (commandService != null)
                {
                    commandService.MessageHandler = this;
                }
                customMessageService = ecsInterface.CustomMessages;
                if (customMessageService != null)
                {
                    customMessageService.MessageHandler = this;
                }
                eptService         = ecsInterface.E116EptService;
                eventsService      = ecsInterface.EventsService;
                maintenanceService = ecsInterface.MaintenanceService;
                if (maintenanceService != null)
                {
                    maintenanceService.MessageHandler = this;
                }
                recipeService = ecsInterface.RecipeService;
                if (recipeService != null)
                {
                    recipeService.MessageHandler = this;
                }
                terminalService = ecsInterface.TerminalServices;
                if (terminalService != null)
                {
                    terminalService.MessageHandler = this;
                }
                variableService = ecsInterface.VariablesService;
                if (variableService != null)
                {
                    variableService.MessageHandler = this;
                }

                // Update form controls
                if (alarmService != null)
                {
                    alarmButton.Enabled = true;
                }

                //alarmService.AlarmStore.GetAlarm("aaa").TargetObject.Enabled

                if (eventsService != null)
                {
                    eventButton.Enabled = true;
                }

                if (variableService != null)
                {
                    variableButton.Enabled            = true;
                    btnEquipmentConstant.Enabled      = true;
                    btnEibValue.Enabled               = true;
                    btnTransitionStateMachine.Enabled = true;
                    btnSetStateMachineState.Enabled   = true;
                }

                if (maintenanceService != null)
                {
                    btnEnableInterface.Enabled     = true;
                    btnDisableInterface.Enabled    = true;
                    btnShutdownEib.Enabled         = true;
                    btnShutdownApplication.Enabled = true;
                    btnECSLogMessage.Enabled       = true;
                }

                if (commandService != null)
                {
                    btnOperatorCommand.Enabled = true;
                }
                if (terminalService != null)
                {
                    btnTerminalRequest.Enabled   = true;
                    btnMessageRecognized.Enabled = true;
                }

                if (recipeService != null)
                {
                    btnRecipeSend.Enabled    = true;
                    btnRequestRecipe.Enabled = true;
                    btnRecipeSelect.Enabled  = true;
                    btnRecipeChanged.Enabled = true;
                    btnRecipesSelect.Enabled = true;
                    btnDownloadFormattedRecipeVerification.Enabled   = true;
                    btnDownloadUnformattedRecipeVerification.Enabled = true;
                }

                if (clockService != null)
                {
                    setClockFromSourceButton.Enabled = true;
                }
            }
        }