Exemple #1
0
    public void GetOnnInfo()
    {
        byte[] hex       = Encoding.Default.GetBytes(keyPair.addr);
        var    hexString = Utils.Byte2HexStr(hex);

        StartCoroutine(NHttp.Get(onnReq.Get("getInfo", hexString), GetInfo));
    }
Exemple #2
0
    public void BuyOnnCalcPower()
    {
        var arg  = Utils.Str2HexStr("null");
        var para = onnReq.Post("BuyHash", arg);

        Debug.Log(para);
        StartCoroutine(NHttp.Post(httpAddr, para));
    }
Exemple #3
0
    public void WithDrawal(string addr, float amount)
    {
        var arg = Utils.Str2HexStr(addr + "?" + amount);

        Debug.Log(arg);
        var para = onnReq.Post("withDrawal", arg);

        Debug.Log(para);
        StartCoroutine(NHttp.Post(httpAddr, para));
    }
        private void handleDownloadRequest(NHttp.HttpOutputStream o)
        {
            try
            {
                using (var writer = new StreamWriter(o))
                {
                    DataTable dt = edb.getAllEmployeeData();
                    StringBuilder sb = new StringBuilder();

                    foreach (DataRow row in dt.Rows)
                    {
                        IEnumerable<string> fields = row.ItemArray.Select(field =>
                           field.ToString().Replace(",", " "));
                        sb.AppendLine(string.Join(",", fields));
                    }
                    writer.Write(sb.ToString());
                }
            }
            catch (Exception ex)
            {
                Logger.log(ex.ToString());
            }
        }
Exemple #5
0
        // ==========================================
        //  HANDLE HTTPSERVER
        // ==========================================
        public virtual bool HandleCustomRequest(NHttp.HttpRequestEventArgs e, StreamWriter writer)
        {
            // Status
              String status = e.Request.Params.Get("status");
              if (status != null) {
            if (WSRSpeakerManager.GetInstance().Speaking)
              writer.Write("speaking");
              }

              // Askme
              var values = System.Web.HttpUtility.ParseQueryString(e.Request.Url.Query);
              var mgr = WSRSpeechManager.GetInstance();
              String[] grammar = values.GetValues("grammar");
              String[] tags = values.GetValues("tags");
              WSRSpeechManager.GetInstance().DynamicGrammar(grammar,tags);

              // Stop Music
              String pause = e.Request.Params.Get("pause");
              if (pause != null) {
            WSRSpeakerManager.GetInstance().Stop(pause);
              }

              // Play Music
              String mp3 = e.Request.Params.Get("play");
              if (mp3 != null) {
            WSRSpeakerManager.GetInstance().Play(mp3, e.Request.Params.Get("sync") == null);
              }

              // Recognize
              String audio = e.Request.Params.Get("recognize");
              if (audio != null) {
            WSRSpeechManager.GetInstance().RecognizeFile(audio);
              }

              // Listening
              String listen = e.Request.Params.Get("listen");
              if (listen != null) {
            WSRSpeechManager.GetInstance().Listening = bool.Parse(listen);
              }

              // Recognize File
              NHttp.HttpPostedFile file = e.Request.Files.Get("recognize");
              if (file != null) {
            byte[] data = null;
            using (var reader = new BinaryReader(file.InputStream)) {
              data = reader.ReadBytes(file.ContentLength);
            }
            var path = WSRConfig.GetInstance().audio+"/"+file.FileName;
            if (File.Exists(path)) { File.Delete(path); }
            File.WriteAllBytes(path, data);
              }

              // Text To Speech
              String tts = e.Request.Params.Get("tts");
              if (tts != null) {
            tts = e.Server.HtmlDecode(tts);
            WSRSpeakerManager.GetInstance().Speak(tts, e.Request.Params.Get("sync") == null);
              }

              // Text To Speech - Stop
              String notts = e.Request.Params.Get("notts");
              if (notts != null) {
            WSRSpeakerManager.GetInstance().ShutUp();
              }

              // Text To Speech - Stop
              String restart = e.Request.Params.Get("restart");
              if (restart != null) {
            Restart();
              }

              // Set Context
              String ctxt = e.Request.Params.Get("context");
              if (ctxt != null) {
            WSRSpeechManager.GetInstance().SetContext(new List<string>(ctxt.Split(',')));
            WSRSpeechManager.GetInstance().SetContextTimeout();
            WSRSpeechManager.GetInstance().ForwardContext();
              }

              // Process
              String activate = e.Request.Params.Get("activate");
              if (activate != null) {
            WSRKeyboard.GetInstance().ActivateApp(activate);
              }

              String run   = e.Request.Params.Get("run");
              String param = e.Request.Params.Get("runp");
              if (run != null) {
            WSRKeyboard.GetInstance().RunApp(run, param);
              }

              // Keyboard
              String keyMod = e.Request.Params.Get("keyMod");
              String key    = e.Request.Params.Get("keyPress");
              if (key != null) {
            WSRKeyboard.GetInstance().SimulateKey(key, 0, keyMod);
              }

              key = e.Request.Params.Get("keyDown");
              if (key != null) {
            WSRKeyboard.GetInstance().SimulateKey(key, 1, keyMod);
              }

              key = e.Request.Params.Get("keyUp");
              if (key != null) {
            WSRKeyboard.GetInstance().SimulateKey(key, 2, keyMod);
              }

              String keyText  = e.Request.Params.Get("keyText");
              if (keyText != null) {
            WSRKeyboard.GetInstance().SimulateTextEntry(keyText);
              }

              // Recognize String
              String emulate = e.Request.Params.Get("emulate");
              if (emulate != null) {
            WSRSpeechManager.GetInstance().RecognizeString(emulate);
            writer.Write(WSRSpeakerManager.GetInstance().SpeechBuffer);
              }
              return false;
        }
Exemple #6
0
    // ==========================================
    //  HANDLE HTTPSERVER
    // ==========================================

    public override bool HandleCustomRequest(NHttp.HttpRequestEventArgs e, StreamWriter writer) {

      if (base.HandleCustomRequest(e, writer)) {
        return true;
      }

      // Parse Result's Photo
      if (e.Request.Params.Get("picture") != null) {

        String path = ActiveSensor().TakePicture("medias/");
        e.Response.ContentType = "image/jpeg";
        Bitmap bmp = (Bitmap) Bitmap.FromFile(path);
        bmp.Save(e.Response.OutputStream, ImageFormat.Jpeg);

        return true;
      }

      // Return Last Height Active Sensor
      var height = e.Request.Params.Get("height");
      if (height != null) {
        double h = WSRProfileManager.GetInstance().Heigth;
        if (height == "tts") {
          WSRSpeakerManager.GetInstance().Speak(h + " mètres", false);
        }
        else {
          writer.Write("" + h);
        }
        return true;
      }

      // Face recognition
      String facereco = e.Request.Params.Get("face");
      if (facereco != null) {
        facereco = e.Server.HtmlDecode(facereco);
        if ("start".Equals(facereco)) {
          WSRConfig.GetInstance().StandByFace = false;
        }
        else if ("stop".Equals(facereco)) {
          WSRConfig.GetInstance().StandByFace = true;
        }
      }

      // Gesture recognition
      String gesture = e.Request.Params.Get("gesture");
      if (gesture != null) {
        gesture = e.Server.HtmlDecode(gesture);
        if ("start".Equals(gesture)) {
          WSRConfig.GetInstance().StandByGesture = false;
        }
        else if ("stop".Equals(gesture)) {
          WSRConfig.GetInstance().StandByGesture = true;
        }
      }
      return false;
    }
Exemple #7
0
        // ==========================================
        //  WSRMacro REQUEST
        // ==========================================
        public override bool HandleCustomRequest(NHttp.HttpRequestEventArgs e)
        {
            if (base.HandleCustomRequest(e)) {
            return true;
              }

              // Parse Result's Photo
              if (e.Request.Params.Get("picture") != null) {
            String path = TakePicture("medias/");
            using (var writer = new StreamWriter(e.Response.OutputStream)) {
              e.Response.ContentType = "image/jpeg";
              Bitmap bmp = (Bitmap)Bitmap.FromFile(path);
              bmp.Save(e.Response.OutputStream, ImageFormat.Jpeg);
            }
            return true;
              }

              // Face recognition
              String facereco = e.Request.Params.Get("face");
              if (facereco != null) {
            facereco = e.Server.HtmlDecode(facereco);
            if ("start".Equals(facereco)) {
              WSRCamera.Recognize(true);
            }
            else if ("stop".Equals(facereco)) {
              WSRCamera.Recognize(false);
            }
            else if ("train".Equals(facereco)) {
              WSRCamera.Train();
            }
              }

              // Gesture recognition
              String gesture = e.Request.Params.Get("gesture");
              if (gesture != null && gestureMgr != null) {
            gesture = e.Server.HtmlDecode(gesture);
            if ("start".Equals(gesture)) {
              gestureMgr.Recognize(true);
            }
            else if ("stop".Equals(gesture)) {
              gestureMgr.Recognize(false);
            }
              }

              return false;
        }
Exemple #8
0
        // ==========================================
        //  WSRMacro HTTPSERVER
        // ==========================================
        public virtual bool HandleCustomRequest(NHttp.HttpRequestEventArgs e)
        {
            // Stop Music
              String pause = e.Request.Params.Get("pause");
              if (pause != null) {
            WSRSpeaker.GetInstance().StopMP3(pause);
              }

              // Play Music
              String mp3 = e.Request.Params.Get("play");
              if (mp3 != null) {
            WSRSpeaker.GetInstance().PlayMP3(mp3);
              }

              // Text To Speech
              String tts = e.Request.Params.Get("tts");
              if (tts != null) {
            tts = e.Server.HtmlDecode(tts);
            WSRSpeaker.GetInstance().Speak(tts);
              }

              // Set Context
              String ctxt = e.Request.Params.Get("context");
              if (ctxt != null) {
            SetContext(new List<string>(ctxt.Split(',')));
              }

              // Process
              String activate = e.Request.Params.Get("activate");
              if (activate != null) {
            WSRKeyboard.GetInstance().ActivateApp(activate);
              }

              String run   = e.Request.Params.Get("run");
              String param = e.Request.Params.Get("runp");
              if (run != null) {
            WSRKeyboard.GetInstance().RunApp(run, param);
              }

              // Keyboard
              String keyMod = e.Request.Params.Get("keyMod");
              String key    = e.Request.Params.Get("keyPress");
              if (key != null) {
            WSRKeyboard.GetInstance().SimulateKey(key, 0, keyMod);
              }

              key = e.Request.Params.Get("keyDown");
              if (key != null) {
            WSRKeyboard.GetInstance().SimulateKey(key, 1, keyMod);
              }

              key = e.Request.Params.Get("keyUp");
              if (key != null) {
            WSRKeyboard.GetInstance().SimulateKey(key, 2, keyMod);
              }

              String keyText  = e.Request.Params.Get("keyText");
              if (keyText != null) {
            WSRKeyboard.GetInstance().SimulateTextEntry(keyText);
              }

              return false;
        }
Exemple #9
0
 public void GetOnnLadder()
 {
     StartCoroutine(NHttp.Get(onnReq.Get("getLadderInfo"), GetLadder));
 }
        // ==========================================
        //  HANDLE HTTPSERVER
        // ==========================================
        public virtual bool HandleCustomRequest(NHttp.HttpRequestEventArgs e)
        {
            // Stop Music
              String pause = e.Request.Params.Get("pause");
              if (pause != null) {
            WSRSpeaker.GetInstance().Stop(pause);
              }

              // Play Music
              String mp3 = e.Request.Params.Get("play");
              if (mp3 != null) {
            WSRSpeaker.GetInstance().Play(mp3);
              }

              // Recognize
              String audio = e.Request.Params.Get("recognize");
              if (audio != null) {
            WSRSpeech.GetInstance().Recognize(audio);
              }

              // Listening
              String listen = e.Request.Params.Get("listen");
              if (listen != null) {
            WSRSpeech.GetInstance().Listening = bool.Parse(listen);
              }

              // Recognize File
              NHttp.HttpPostedFile file = e.Request.Files.Get("recognize");
              if (file != null) {
            byte[] data = null;
            using (var reader = new BinaryReader(file.InputStream)) {
              data = reader.ReadBytes(file.ContentLength);
            }
            var path = WSRConfig.GetInstance().audioWatcher+"/"+file.FileName;
            if (File.Exists(path)) { File.Delete(path); }
            File.WriteAllBytes(path, data);
              }

              // Text To Speech
              String tts = e.Request.Params.Get("tts");
              if (tts != null) {
            tts = e.Server.HtmlDecode(tts);
            WSRSpeaker.GetInstance().Speak(tts, e.Request.Params.Get("sync") == null);
              }

              // Text To Speech - Stop
              String notts = e.Request.Params.Get("notts");
              if (notts != null) {
            WSRSpeaker.GetInstance().ShutUp();
              }

              // Text To Speech - Stop
              String restart = e.Request.Params.Get("restart");
              if (restart != null) {
            Restart();
              }

              // Set Context
              String ctxt = e.Request.Params.Get("context");
              if (ctxt != null) {
            WSRSpeech.GetInstance().SetContext(new List<string>(ctxt.Split(',')));
            WSRSpeech.GetInstance().SetContextTimeout();
            WSRSpeech.GetInstance().ForwardContext();
              }

              // Process
              String activate = e.Request.Params.Get("activate");
              if (activate != null) {
            WSRKeyboard.GetInstance().ActivateApp(activate);
              }

              String run   = e.Request.Params.Get("run");
              String param = e.Request.Params.Get("runp");
              if (run != null) {
            WSRKeyboard.GetInstance().RunApp(run, param);
              }

              // Keyboard
              String keyMod = e.Request.Params.Get("keyMod");
              String key    = e.Request.Params.Get("keyPress");
              if (key != null) {
            WSRKeyboard.GetInstance().SimulateKey(key, 0, keyMod);
              }

              key = e.Request.Params.Get("keyDown");
              if (key != null) {
            WSRKeyboard.GetInstance().SimulateKey(key, 1, keyMod);
              }

              key = e.Request.Params.Get("keyUp");
              if (key != null) {
            WSRKeyboard.GetInstance().SimulateKey(key, 2, keyMod);
              }

              String keyText  = e.Request.Params.Get("keyText");
              if (keyText != null) {
            WSRKeyboard.GetInstance().SimulateTextEntry(keyText);
              }

              return false;
        }