Ejemplo n.º 1
0
        public void TestSend()
        {
            string q         = "me";
            string appKey    = "3c0a72612269ebac";
            string from      = "zh-CHS";
            string to        = "en";
            string salt      = DateTime.Now.Millisecond.ToString();
            string appSecret = "tJN4pmDy34ET8aLZmADUjCIs2YLx0OaS";
            MD5    md5       = new MD5CryptoServiceProvider();
            string md5Str    = appKey + q + salt + appSecret;

            byte[] output = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(md5Str));
            string sign   = BitConverter.ToString(output).Replace("-", "");

            string url = string.Format("http://openapi.youdao.com/api?appKey={0}&q={1}&from={2}&to={3}&sign={4}&salt={5}",
                                       appKey, System.Web.HttpUtility.UrlDecode(q, System.Text.Encoding.GetEncoding("UTF-8")), from, to, sign, salt);
            WebRequest translationWebRequest = WebRequest.Create(url);

            WebResponse response = null;

            response = translationWebRequest.GetResponse();
            Stream stream = response.GetResponseStream();

            Encoding encode = Encoding.GetEncoding("utf-8");

            StreamReader reader = new StreamReader(stream, encode);
            string       result = reader.ReadToEnd();

            //result = GetJsonNode(result, "basic");

            ReceiveEvent?.Invoke(Json.ConvertJsonString(result));
            //Debug.WriteLine(result);
        }
        async Task Receive()
        {
            var s = await _client.ReceiveAsync();

            ReceiveEvent?.Invoke(s.Buffer);
            Receive();
        }
Ejemplo n.º 3
0
 private void Receive(string message)
 {
     if (verbose)
     {
         Debug.Log($"ZeroMQApi Receiving {subscriberIp}: {message}");
     }
     ReceiveEvent?.Invoke(message);
 }
Ejemplo n.º 4
0
        private void ReceiveCallback(IAsyncResult asyncResult)
        {
            byte[]           receiveBytes = SNMPListener.EndReceive(asyncResult, ref ipEnPoint);
            ReceiveEventArgs receiveArgs  = new ReceiveEventArgs(receiveBytes, ipEnPoint);

            ReceiveEvent.Invoke(this, receiveArgs);
            SNMPListener.BeginReceive(ReceiveCallback, new SNMPState(SNMPListener, ipEnPoint));
        }
        /// <summary>
        /// Handle received IP addresses
        /// </summary>
        IEnumerator ProcessReceived()
        {
            while (true)
            {
                yield return(new WaitUntil(() => received.Count > 0));

                OnReceive?.Invoke(received.Dequeue());
            }
        }
Ejemplo n.º 6
0
 // Update is called once per frame
 void Update()
 {
     while (receiveBufferQueue.Count > 0)
     {
         byte[] _receiveBuffer = receiveBufferQueue.Dequeue();
         if (ReceiveEvent != null)
         {
             ReceiveEvent.Invoke(_receiveBuffer);
         }
     }
 }
        /// <summary>
        /// Sets up the notifications;
        /// Will call Status
        /// </summary>
        /// <param name="notifyType"></param>
        /// <returns>true if the notify was set up. </returns>

        public async Task <bool> NotifyReceiveAsync(GattClientCharacteristicConfigurationDescriptorValue notifyType = GattClientCharacteristicConfigurationDescriptorValue.Notify)
        {
            if (!await EnsureCharacteristicAsync())
            {
                return(false);
            }
            var ch = Characteristics[4];

            if (ch == null)
            {
                return(false);
            }
            GattCommunicationStatus result = GattCommunicationStatus.ProtocolError;

            try
            {
                result = await ch.WriteClientCharacteristicConfigurationDescriptorAsync(notifyType);

                if (!NotifyReceive_ValueChanged_Set)
                {
                    // Only set the event callback once
                    NotifyReceive_ValueChanged_Set = true;
                    ch.ValueChanged += (sender, args) =>
                    {
                        var datameaning = "STRING|ASCII^LONG|Data";
                        var parseResult = BluetoothDeviceController.BleEditor.ValueParser.Parse(args.CharacteristicValue, datameaning);

                        Receive = parseResult.ValueList.GetValue("Data").AsString;

                        ReceiveEvent?.Invoke(parseResult);
                    };
                }
            }
            catch (Exception e)
            {
                Status.ReportStatus($"NotifyReceive: {e.Message}", result);
                return(false);
            }
            Status.ReportStatus($"NotifyReceive: set notification", result);

            return(true);
        }
Ejemplo n.º 8
0
 private void RaiseReceiveEvent(string message, IPEndPoint ipep)
 {
     ReceiveEvent?.Invoke(message, ipep);
 }
Ejemplo n.º 9
0
 protected virtual void OnReceiveEvent(MessageEventArgs e)
 {
     ReceiveEvent?.Invoke(this, e);
 }
 //イベントの発火
 protected void RunReceiveEvent(object sender, ReceiveData data)
 {
     ReceiveEvent?.Invoke(sender, data);
 }
Ejemplo n.º 11
0
        public void Send(string query)
        {
            Regex regChina = new Regex("^[^\x00-\xFF]");

            Regex regEnglish = new Regex("^[a-zA-Z]");

            string from, to;

            if (regChina.IsMatch(query))
            {
                from = "zh-CHS";
                to   = "en";
            }
            else
            {
                from = "en";
                to   = "zh-CHS";
            }

            string salt      = DateTime.Now.Millisecond.ToString();
            string appSecret = "tJN4pmDy34ET8aLZmADUjCIs2YLx0OaS";
            MD5    md5       = new MD5CryptoServiceProvider();
            string md5Str    = APPKey + query + salt + appSecret;

            byte[] output = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(md5Str));
            string sign   = BitConverter.ToString(output).Replace("-", "");

            string urlDecode = System.Web.HttpUtility.UrlDecode(query, System.Text.Encoding.GetEncoding("UTF-8"));

            string url = string.Format("{0}={1}&q={2}&from={3}&to={4}&sign={5}&salt={6}",
                                       API_Http, APPKey, urlDecode, from, to, sign, salt);

            WebRequest translationWebRequest = WebRequest.Create(url);

            WebResponse response = null;

            response = translationWebRequest.GetResponse();
            Stream stream = response.GetResponseStream();

            Encoding encode = Encoding.GetEncoding("utf-8");

            StreamReader reader = new StreamReader(stream, encode);
            string       result = reader.ReadToEnd();

            string errorCode = GetJsonNode(result, ErrorCodeString);

            if (errorCode != "0")
            {
                ReceiveEvent?.Invoke("查询失败");
            }
            else
            {
                string str = Json.ConvertJsonString(result);
                File.WriteAllText("./Tst.txt", str);
                //result = GetJsonNode(result, "basic", "explains");
                result = GetJsonNode(result);
                //ReceiveEvent?.Invoke(Json.ConvertJsonString(result));
                ReceiveEvent?.Invoke(result);
                //File.WriteAllText("./Test.text", Json.ConvertJsonString(result));
            }
        }
Ejemplo n.º 12
0
 public static void OnReceiveEvent(IEventType eventObject)
 {
     ReceiveEvent.Invoke(null, eventObject);
 }