示例#1
0
        static void Main(string[] args)
        {
            Client client = null;

            try
            {
                Assembly assembly = Assembly.GetExecutingAssembly();
                System.Diagnostics.FileVersionInfo fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
                Console.WriteLine(string.Concat("TestClient Version - ", fileVersionInfo.FileVersion));
                CoAP.Log.LogManager.Level = CoAP.Log.LogLevel.None;
                client = new Client(55863);
                client.LoadResources();
                client.Start();
                Command.RegisterCommand(new PSKCommand(client));
                Command.RegisterCommand(new CertificateFileCommand(client));
                BootstrapCommand bootstrapCommand = new BootstrapCommand(client);
                Command.RegisterCommand(bootstrapCommand);
                ConnectCommand connectCommand = new ConnectCommand(client);
                Command.RegisterCommand(connectCommand);
                Command.RegisterCommand(new EchoCommand());
                Command.RegisterCommand(new FCAPCommand(client));
                Command.RegisterCommand(new HelpCommand());
                Command.RegisterCommand(new SaveCommand(client));
                Command.RegisterCommand(new SetResourceCommand(client));
                Command.RegisterCommand(new DisplayResourceCommand(client));
                Command.RegisterCommand(new Command()
                {
                    Name = "quit"
                });
                Command.RegisterCommand(new Command()
                {
                    Name = "exit"
                });

                bool bootstrap = true;
                if (client.HaveBootstrap())
                {
                    Console.Write("Connect to server (");
                    if (client.ConnectToServer())
                    {
                        Console.WriteLine("Complete");
                        bootstrap = false;
                    }
                    else
                    {
                        Console.WriteLine("Failed");
                    }
                }
                if (bootstrap)
                {
                    //bootstrapCommand.Parameters.Add("coap://delmet-hp.we.imgtec.org:15685");
                    //bootstrapCommand.Parameters.Add("coap://we-dev-lwm2m1.we.imgtec.org:15685");
                    //bootstrapCommand.Execute();
                }
                Console.WriteLine("Type quit to stop the LWM2M client (type help to see other commmands).");
                while (true)
                {
                    Console.Write('>');
                    Command command = Command.Parse(Console.ReadLine());
                    if (command != null)
                    {
                        if ((string.Compare(command.Name, "quit", true) == 0) || (string.Compare(command.Name, "exit", true) == 0))
                        {
                            break;
                        }
                        else
                        {
                            command.Execute();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
            }
            finally
            {
                if (client != null)
                {
                    client.Stop();
                    client.SaveResources();
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            Client client = null;
            try
            {
                Assembly assembly = Assembly.GetExecutingAssembly();
                System.Diagnostics.FileVersionInfo fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
                Console.WriteLine(string.Concat("TestClient Version - ", fileVersionInfo.FileVersion));
                CoAP.Log.LogManager.Level = CoAP.Log.LogLevel.None;
                client = new Client(55863);
                client.LoadResources();
                client.Start();
                Command.RegisterCommand(new PSKCommand(client));
                Command.RegisterCommand(new CertificateFileCommand(client));
                BootstrapCommand bootstrapCommand = new BootstrapCommand(client);
                Command.RegisterCommand(bootstrapCommand);
                ConnectCommand connectCommand = new ConnectCommand(client);
                Command.RegisterCommand(connectCommand);
                Command.RegisterCommand(new EchoCommand());
                Command.RegisterCommand(new FCAPCommand(client));
                Command.RegisterCommand(new HelpCommand());
                Command.RegisterCommand(new SaveCommand(client));
                Command.RegisterCommand(new SetResourceCommand(client));
                Command.RegisterCommand(new DisplayResourceCommand(client));
                Command.RegisterCommand(new Command() { Name = "quit" });
                Command.RegisterCommand(new Command() { Name = "exit" });

                bool bootstrap = true;
                if (client.HaveBootstrap())
                {
                    Console.Write("Connect to server (");
                    if (client.ConnectToServer())
                    {
                        Console.WriteLine("Complete");
                        bootstrap = false;
                    }
                    else
                        Console.WriteLine("Failed");
                }
                if (bootstrap)
                {
                    //bootstrapCommand.Parameters.Add("coap://delmet-hp.we.imgtec.org:15685");
                    //bootstrapCommand.Parameters.Add("coap://we-dev-lwm2m1.we.imgtec.org:15685");
                    //bootstrapCommand.Execute();
                }
                Console.WriteLine("Type quit to stop the LWM2M client (type help to see other commmands).");
                while (true)
                {
                    Console.Write('>');
                    Command command = Command.Parse(Console.ReadLine());
                    if (command != null)
                    {
                        if ((string.Compare(command.Name, "quit", true) == 0) || (string.Compare(command.Name, "exit", true) == 0))
                            break;
                        else
                        {
                            command.Execute();
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
            }
            finally
            {
                if (client != null)
                {
                    client.Stop();
                    client.SaveResources();
                }
            }
        }