private void IssueMessage(string issuingNodeAnswer, string procedureAnswer, string messageTypeAnswer, string parameterAnswer, string addressTypeAnswer, string addressAnswer)
        {
            var message = new BaseRequest();

            Enum.TryParse(procedureAnswer, out Procedure procedure);
            message.Procedure = procedure;

            Enum.TryParse(messageTypeAnswer, out MessageType messageType);
            message.MessageType = messageType;
            message.Parameters  = Convert.ToInt32(parameterAnswer);

            Enum.TryParse(addressAnswer, out AddressType addressType);
            int addressValue = 0;

            switch (addressType)
            {
            case AddressType.Unassigned:
                break;

            case AddressType.Unicast:
                addressValue = Convert.ToInt32(addressAnswer);
                message.DST  = mesh.Nodes.Select(x => x.Address).FirstOrDefault(x => x.Value == addressValue);
                break;

            case AddressType.Virtual:
                var a = mesh.Nodes.SelectMany(x => x.Elements.Values);
                addressValue = Convert.ToInt32(addressAnswer);
                message.DST  = mesh.Nodes.Select(x => x.Address).FirstOrDefault(x => x.Value == addressValue);
                break;

            case AddressType.Group:
                addressValue = Convert.ToInt32(addressAnswer);
                message.DST  = GroupAddressesProvider.Dictionary.Values.FirstOrDefault(x => x.Value == addressValue);
                break;

            default:
                break;
            }

            int  issuingNode = Int32.Parse(issuingNodeAnswer);
            Node issuer      = GetNodeById(issuingNode);

            issuer.StatusFlag = 1;
            bearer            = mesh.NodeServers.ToList().FirstOrDefault(x => x.Node.Id == issuingNode);
            serverModel.SendMessage(bearer, message);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Container = BuildContainer();

            var context = Container.Resolve <IBluetoothMeshContext>();

            Node clientNode = context.Nodes.ToList()[0];
            var  bearer     = context.NodeServers[0];
            ConfigurationClientModel serverModel = (ConfigurationClientModel)clientNode.Elements[ElementType.primary].Models[ModelType.ConfigurationClient];

            while (true)
            {
                Console.WriteLine("-------------MENU:--------------\n" +
                                  "1) Display all nodes\n" +
                                  "2) Send message");

                switch (Convert.ToInt32(Console.ReadLine()))
                {
                case 1:
                    foreach (var node in context.Nodes)
                    {
                        Console.WriteLine($"\n-Node nr {node.Id}");
                        Console.WriteLine($"-Node features:");
                        if (node.ConfigurationServerModel.CompositionData.IsRelay)
                        {
                            Console.WriteLine($"--Relay");
                        }

                        if (node.ConfigurationServerModel.CompositionData.IsFriend)
                        {
                            Console.WriteLine($"--Friend");
                        }

                        if (node.ConfigurationServerModel.CompositionData.IsProxy)
                        {
                            Console.WriteLine($"--Proxy");
                        }

                        Console.WriteLine("---Node elements:");
                        foreach (var elemnt in node.Elements)
                        {
                            Console.WriteLine($"---Element nr {elemnt.Value.Address} --- ");
                            Console.WriteLine($"---Element type {elemnt.Key.ToString()}");
                            foreach (var model in elemnt.Value.Models)
                            {
                                //Console.WriteLine($"-----Model nr {model.Value.Address} --- ");
                                Console.WriteLine($"-----Model type {model.Key.ToString()}");
                                Console.WriteLine($"-----Model procedures:");

                                model.Value.Procedures.ForEach(p => Console.WriteLine($"------{p.ToString()}"));
                            }
                        }
                    }
                    break;

                case 2:
                    var message = new BaseRequest();
                    Console.WriteLine("\nWhat type of procedure\n");
                    foreach (string volume in Enum.GetNames(typeof(Procedure)))
                    {
                        Console.Write($"{volume} ");
                    }
                    Console.Write(":\n");
                    Enum.TryParse(Console.ReadLine(), out Procedure procedure);
                    message.Procedure = procedure;

                    Console.WriteLine("\nWhat type of message");
                    foreach (string volume in Enum.GetNames(typeof(MessageType)))
                    {
                        Console.Write($"{volume} ");
                    }
                    string messsageTyoeAnswer = Console.ReadLine();
                    Enum.TryParse(messsageTyoeAnswer, out MessageType messageType);
                    message.MessageType = messageType;
                    if (MessageType.SET == messageType)
                    {
                        Console.WriteLine("Parameter:");
                        message.Parameters = Convert.ToInt32(Console.ReadLine());
                    }

                    Console.WriteLine("\nWhat type of address\n");
                    foreach (string volume in Enum.GetNames(typeof(AddressType)))
                    {
                        Console.Write($"{volume} ");
                    }
                    string addressAnswer = Console.ReadLine();
                    Console.WriteLine(addressAnswer);
                    Enum.TryParse(addressAnswer, out AddressType addressType);
                    int addressValue = 0;
                    switch (addressType)
                    {
                    case AddressType.Unassigned:
                        break;

                    case AddressType.Unicast:
                        Console.WriteLine("\nWhich one:\n");
                        foreach (var node in context.Nodes)
                        {
                            Console.WriteLine($"- {node.Id} : {node.Address.Value}");
                        }
                        addressValue = Convert.ToInt32(Console.ReadLine());
                        message.DST  = context.Nodes.Select(x => x.Address).FirstOrDefault(x => x.Value == addressValue);
                        break;

                    case AddressType.Virtual:
                        //Console.WriteLine("\n  gl :V   \n");
                        //var a = context.Nodes.SelectMany(x => x.Elements.Values);
                        //foreach (var model in context.Nodes.SelectMany(x => x.Elements.Values).SelectMany(x => x.Models.Values))
                        //{
                        //    Console.WriteLine($"- {model.Address.GuidId} : {model.Address.Value}");
                        //}
                        //addressValue = Convert.ToInt32(Console.ReadLine());
                        //message.DST = context.Nodes.Select(x => x.Address).FirstOrDefault(x => x.Value == addressValue);
                        break;

                    case AddressType.Group:
                        Console.WriteLine("\nWhich one:\n");
                        foreach (var address in GroupAddressesProvider.Dictionary)
                        {
                            Console.WriteLine($"- {address.Key} : {address.Value.Value}");
                        }
                        addressValue = Convert.ToInt32(Console.ReadLine());
                        message.DST  = GroupAddressesProvider.Dictionary.Values.FirstOrDefault(x => x.Value == addressValue);
                        break;

                    default:
                        break;
                    }
                    Console.WriteLine(message.ToString());


                    serverModel.SendMessage(bearer, message);

                    break;
                }

                //finish all threads
                Process thisProc = Process.GetCurrentProcess();
                ProcessThreadCollection mythreads = thisProc.Threads;
            }
        }