Ejemplo n.º 1
0
Archivo: Test.cs Proyecto: sjmeijer/sdk
        static void test_LuaConsole(String host, int port)
        {
            try
              {
            Client client = new Client(host, port);

            Console.WriteLine("Connected to " + host + ":" + port);

            String chunk =
              "if not node.is_reading() then" +
              "   node.close()" +
              "   node.scan()" +
              "   node.start()" +
              " end" +
              " if node.is_reading() then" +
              "   print('Reading from ' .. node.num_reading() .. ' device(s)')" +
              " else" +
              "   print('Failed to start reading')" +
              " end";

            LuaConsole.ResultType result =
              LuaConsole.SendChunk(client, chunk);

            if (LuaConsole.ResultCode.Success == result.first)
            {
              Console.WriteLine(result.second);
            }
            else if (LuaConsole.ResultCode.Continue == result.first)
            {
              Console.WriteLine("incomplete Lua chunk: " + result.second);
            }
            else
            {
              Console.WriteLine("command failed: " + result.second);
            }
              }
              catch (Exception e)
              {
            Console.WriteLine(e.ToString());
              }
        }
Ejemplo n.º 2
0
Archivo: Test.cs Proyecto: sjmeijer/sdk
        static void test_Client(String host, int port)
        {
            try
              {
            Client client = new Client(host, port);

            Console.WriteLine("Connected to " + host + ":" + port);

            // The Configurable data service requires that we specify a list of channels
            // that we would like to receive.
            if (PortConfigurable == port)
            {
              // Access the global quaternion and calibrated accelerometer streams.
              String xml_definition =
              "<?xml version=\"1.0\"?>" +
              "<configurable>" +
              "<preview><Gq/></preview>" +
              "<sensor><a/></sensor>" +
              "</configurable>";

              if (client.writeData(xml_definition))
              {
            Console.WriteLine("Sent active channel definition to Configurable service");
              }
            }

            if (client.waitForData())
            {
              int sample_count = 0;
              while (true)
              {
            byte[] data = client.readData();
            if ((null == data) || (sample_count++ >= NSample))
            {
              break;
            }

            if (PortPreview == port)
            {
              IDictionary<int, Format.PreviewElement> container = Format.Preview(data);
              foreach (KeyValuePair<int, Format.PreviewElement> itr in container)
              {
                float[] q = itr.Value.getQuaternion(false);
                Console.WriteLine("q(" + itr.Key + ") = (" + q[0] + ", " + q[1] + "i, " + q[2] + "j, " + q[3] + "k)");
              }
            }

            if (PortSensor == port)
            {
              IDictionary<int, Format.SensorElement> container = Format.Sensor(data);
              foreach (KeyValuePair<int, Format.SensorElement> itr in container)
              {
                float[] a = itr.Value.getAccelerometer();
                Console.WriteLine("a(" + itr.Key + ") = (" + a[0] + ", " + a[1] + ", " + a[2] + ") g");
              }
            }

            if (PortRaw == port)
            {
              IDictionary<int, Format.RawElement> container = Format.Raw(data);
              foreach (KeyValuePair<int, Format.RawElement> itr in container)
              {
                short[] a = itr.Value.getAccelerometer();
                Console.WriteLine("a(" + itr.Key + ") = (" + a[0] + ", " + a[1] + ", " + a[2] + ") g");
              }
            }

            if (PortConfigurable == port)
            {
              IDictionary<int, Format.ConfigurableElement> container = Format.Configurable(data);
              foreach (KeyValuePair<int, Format.ConfigurableElement> itr in container)
              {
                Console.Write("data(" + itr.Key + ") = (");
                for (int i=0; i<itr.Value.size(); i++)
                {
                  if (i > 0)
                  {
                    Console.Write(", ");
                  }
                  Console.Write(itr.Value.value(i));
                }
                Console.WriteLine(")");
              }
            }

              }
            }
              }
              catch (Exception e)
              {
            Console.WriteLine(e.ToString());
              }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Loads clients' list from storage.
 /// </summary>
 /// <returns>A list of all warehouse clients.</returns>
 public IEnumerable<Client> LoadClients()
 {
     var client = new Client(0, null, null, null, null, null, null, null);
     return this.LoadData(PathToClientsFile, client).Cast<Client>();
 }
Ejemplo n.º 4
0
 public override void Quit(int timeout, string comment)
 {
     base.Quit(timeout, comment);
     Client.Shutdown(HandleClientDisconnected);
 }
Ejemplo n.º 5
0
 protected override void WriteMessage(string line, object token)
 {
     Client.Write(TextEncoding, line + Environment.NewLine, (ex) => {
         OnRawMessageSent(token as IrcRawMessageEventArgs);
     });
 }
Ejemplo n.º 6
0
 public void Close()
 {
     Client.Close();
 }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("starting...");
            var version       = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();//"1.0.0.0";
            var programFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

            //var version_file = Path.Combine(programFolder, "version.txt");
            //if (File.Exists(version_file))
            //{
            //    var lines = File.ReadAllLines(version_file);
            //    version = lines[0];
            //}

            var cl = new Client("test", version, "http://mt2007-cat.ru/downloads/siinformer/version1.txt", false); // указываем неправильный адрес

            cl.HasUpdateEvent += (s, e) =>
            {
                Console.WriteLine("Has updates!\r\n" + ((HasUpdateEventArgs)e).UpdateInfo);
                Console.WriteLine("Downloading...");
                cl.DownloadUpdate();
            };
            cl.HasNoUpdateEvent += (s, e) =>
            {
                Console.WriteLine("No updates!");
            };
            cl.UpdateDownloadedEvent += (s, e) =>
            {
                Console.WriteLine("downloaded.");
                Console.WriteLine("need to restart program...");
                var me = System.Reflection.Assembly.GetEntryAssembly().Location;
                cl.ApplyUpdate(me);
                Process.GetCurrentProcess().Kill();
            };
            cl.DownloadProgressEvent += (s, e) =>
            {
                var par = (DownloadProgressChangedEventArgs)e;
                Console.Write(par.ProgressPercentage.ToString() + "%...");
            };
            cl.ErrorDownloadingEvent += (s, e) =>
            {
                var par = (DownloadEventArgs)e;
                Console.WriteLine(par.Exception.Message);
            };
            if (cl.IsErrorUpdating())
            {
                Console.WriteLine("Last update error occured");
                Console.WriteLine(cl.GetLog());
            }
            if (cl.IsPendingUpdate())
            {
                Console.WriteLine("need to restart program...");
                var me = System.Reflection.Assembly.GetEntryAssembly().Location;
                cl.ApplyUpdate(me);
                Process.GetCurrentProcess().Kill();
            }

            cl.StartChecking();

            cl.VersionFileUrl = "http://mt2007-cat.ru/downloads/siinformer/version.txt"; // ставим правильный адрес и перезапускаем проверку. (Отработка некорретных ситуаций)
            cl.StartChecking();
            Console.WriteLine("waiting...");
            Console.ReadKey();
        }