void Send()
        {
            bool SendAsync = false;

            if (Interlocked.CompareExchange(ref _SendLocked, 1, 0) != 1)
            {
                while (_SendStream.DataAvailable)
                {
                    int bytes = _SendStream.Peek(_SendBuffer, 0, _SendBuffer.Length);
                    if (bytes <= 0)
                    {
                        break;
                    }
                    SendEventArgs.SetBuffer(_SendBuffer, 0, bytes);
                    if (!_ChannelSocket.SendAsync(SendEventArgs))
                    {//Send同步完成
                        _SendStream.Skip(SendEventArgs.BytesTransferred);
                    }
                    else
                    {
                        SendAsync = true;
                        break;
                    }
                }
            }
            if (!SendAsync)
            {
                Interlocked.Exchange(ref _SendLocked, 0);
            }
        }
Beispiel #2
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            this.labelLoadingTime.Visible = false;
            this.labelLoadingTime.Text    = string.Empty;
            this.labelStatus.Visible      = false;
            this.labelStatus.Text         = string.Empty;
            this.requestResponseMessages.ResponseMessage = string.Empty;

            if (this.RaiseSendButton != null)
            {
                try
                {
                    SendEventArgs eventArgs = null;
                    this.InvokeEx(delegate()
                    {
                        HttpRequestMessage hrm = new HttpRequestMessage(this.method, this.textBoxUrl.Text);

                        string payload = this.requestResponseMessages.RequestPayload.Replace("$DateTime.UtcNow", DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture));

                        if (this.method != HttpMethod.Get)
                        {
                            hrm.Content = new StringContent(JRaw.Parse(payload).ToString(), Encoding.UTF8, "application/json");
                        }

                        string hdrsText = this.requestResponseMessages.RequestHeaders;
                        if (string.IsNullOrEmpty(hdrsText) == false)
                        {
                            string[] lines = hdrsText.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string line in lines)
                            {
                                var parts      = line.Split(new char[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries);
                                string hdrname = parts.First().Trim();
                                hrm.Headers.TryAddWithoutValidation(parts.First().Trim(), parts.Last().Trim());
                            }
                            if (hrm.Headers.Contains("x-ms-continuation") == false && this.checkBoxNext.Visible && this.checkBoxNext.Checked && this.checkBoxNext.Tag != null)
                            {
                                hrm.Headers.TryAddWithoutValidation("x-ms-continuation", Convert.ToString(this.checkBoxNext.Tag));
                            }
                        }
                        this.checkBoxNext.Visible = false;
                        this.checkBoxNext.Checked = false;
                        this.checkBoxNext.Tag     = null;
                        eventArgs = new SendEventArgs()
                        {
                            Request = hrm
                        };
                    });

                    this.RaiseSendButton(sender, eventArgs);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.InnerMessage(), "Send HttpRequest failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    this.InvokeEx(delegate() { this.buttonSend.Enabled = true; });
                }
            }
        }
        /// <summary>
        /// 检查队列里是否有要发送的数据,如果有则进行发送处理
        /// </summary>
        private void PeekSend()
        {
            if (isClose)
            {
                return;
            }

#if !UNITY_IPHONE
            lock (m_PendingBuffer)
#endif
            {
                if (isSending || m_PendingBuffer.Count == 0)
                {
                    return;
                }

                //  TODO 这里要不要考虑进行并报发送处理
                isSending = true;

                DogBuffer buff;
                buff = m_PendingBuffer.Dequeue();
                SendEventArgs.UserToken = buff;
                SendEventArgs.SetBuffer(buff.Bytes, 0, buff.Length);
                Socket.SendAsync(SendEventArgs);
            }
        }
Beispiel #4
0
        public bool SendAsync(byte[] bytes)
        {
            SendBuffer.StartPacket();
            // 写入包头
            SendBuffer.Buffer.WriteInt16(Packet.HEAD);
            // 写入包长
            SendBuffer.Buffer.WriteInt32(bytes.Length);
            // 写入数据
            SendBuffer.Buffer.WriteBytes(bytes, 0, bytes.Length);
            SendBuffer.EndPacket();
            bool result = true;

            if (!mSendAsync)
            {
                int count  = 0;
                int offset = 0;
                if (SendBuffer.GetFirstPacket(ref offset, ref count))
                {
                    mSendAsync = true;
                    SendEventArgs.SetBuffer(SendBuffer.Buffer.Bytes, offset, count);
                    result = AsyncNet.SendAsync(this);
                }
            }
            return(result);
        }
Beispiel #5
0
 public void Dispose()
 {
     _DisConnect();
     Clear();
     ReceiveEventArgs.Dispose();
     SendEventArgs.Dispose();
 }
        /// <summary>
        /// 发送数据,按照以下格式发送数据:
        /// |数据长度n|需要发送的数据
        ///    4字节        n字节
        /// </summary>
        /// <param name="data">需要发送的数据</param>
        /// <param name="offset">需要发送数据的偏移量</param>
        /// <param name="size">需要发送数据的长度</param>
        public void Send(Byte[] data, int offset, int size)
        {
            if (!IsConnecting)
            {
                throw new Exception("没有连接,无法发送数据!");
            }

            lock (m_lockobject)
            {
                if (data == null || data.Length == 0)
                {
                    return;
                }
                //计算数据的长度,并转换成字节数组,作为本次发送的头部
                //byte[] length = BitConverter.GetBytes(size);
                //Byte[] buffer = new Byte[size + length.Length];

                //Array.Copy(length, 0, buffer, 0, length.Length);
                //Array.Copy(data, offset, buffer, length.Length, size);
                //设置发送Buffer
                SendEventArgs.SetBuffer(data, 0, data.Length);

                SendResetEvent.Reset();
                Client.SendAsync(SendEventArgs);
                //等待发送成功的信息,只有收到该信息,才退出lock锁,
                //这样,确保只有当前面得数据发送完后,才发送下一段数据
                SendResetEvent.WaitOne();
            }
        }
        public void ToStringOfEventArgs()
        {
            var e = new SendEventArgs {
                Message = "hallo", Topic = "Int32"
            };

            Assert.Equal(@"Topic:    Int32
  Message:  hallo", e.ToString());
        }
Beispiel #8
0
        private void OnSendCompleted(SendEventArgs args)
        {
            SendCompletedHandler handler = SendCompleted;

            if (handler != null)
            {
                handler(this, args);
            }
        }
Beispiel #9
0
        /// <summary>
        /// 检查队列里是否有要发送的数据,如果有则进行发送处理
        /// </summary>
        public void PeekSend()
        {
            lock (m_PendingBuffer)
            {
                if (isSending || m_PendingBuffer.Count == 0)
                {
                    return;
                }

                //  TODO 这里要不要考虑进行并报发送处理
                isSending = true;

                if (m_PendingBuffer.Count > 1)
                {
                    //   2 个包以上,进行拼包后再发送
                    var buffs = m_PendingBuffer.ToArray();
                    m_PendingBuffer.Clear();

                    int offSet = 0;
                    foreach (var b in buffs)
                    {
                        offSet += b.Length;
                    }

                    DogBuffer sendBuff;

                    if (offSet < 4000)
                    {
                        sendBuff = DogBuffer.GetFromPool4K();
                    }
                    else
                    {
                        sendBuff = DogBuffer.GetFromPool32K();
                    }

                    foreach (var buff in buffs)
                    {
                        Buffer.BlockCopy(buff.Bytes, 0, sendBuff.Bytes, sendBuff.Length, buff.Length);
                        sendBuff.Length += buff.Length;
                        buff.Release();
                    }

                    SendEventArgs.UserToken = sendBuff;
                    SendEventArgs.SetBuffer(sendBuff.Bytes, 0, sendBuff.Length);
                    Socket.SendAsync(SendEventArgs);
                }
                else
                {
                    DogBuffer buff;
                    buff = m_PendingBuffer.Dequeue();
                    SendEventArgs.UserToken = buff;
                    SendEventArgs.SetBuffer(buff.Bytes, 0, buff.Length);
                    Socket.SendAsync(SendEventArgs);
                }
            }
        }
Beispiel #10
0
 private void Controller_Robot2Sended(object sender, SendEventArgs e)
 {
     LogConsole.AsyncInvoke(x =>
     {
         if (!x.IsDisposed)
         {
             x.AppendText($"[{DateTime.Now}][NETWORK] : {e.BytesSent} Bytes Sended to Robot 2 as {e.IP}{Environment.NewLine}");
         }
     });
 }
Beispiel #11
0
        protected SendResult SendData(SendEventArgs args)
        {
            if (args == null)
            {
                args = _sendPool.PopFront();
                if (args.Socket != null)
                    throw new InvalidOperationException($"{nameof(ReceiveEventArgs)} was not released correctly");

                args.Socket = this;

                //Create the buffer list that we use to store our queued data.
                if (args.BufferList == null)
                    args.BufferList = new List<ArraySegment<byte>>();
            }

            //Ensure our operation collections are reset
            if (args.BufferList.Count > 0) args.BufferList.Clear();
            if (args.Confirmations.Count > 0) args.Confirmations.Clear();

            try
            {
                lock (_txSyncRoot)
                {
                    if (_txQueue.Count == 0)
                    {
                        args.Socket = null;
                        _sendPool.PushBack(args);
                        return SendResult.NotQueued;
                    }
                    
                    //Let our data list be sent out
                    args.BufferList = _txQueue;
                    _txQueue = new List<ArraySegment<byte>>();
                    
                    //Place all callbacks into this operation
                    while (_sendQueue.Count > 0)
                        args.Confirmations.Add(_sendQueue.Dequeue());

                    if (!sending) sending = true;
                    var sent = _socket.SendAsync(args);
                    if (!sent)
                    {
                        OnSendComplete(args);
                    }

                    if (sent) return SendResult.Queued;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception in {this.GetType().FullName}.{nameof(SendData)}\n{ex}");
            }

            return SendResult.NotQueued;
        }
Beispiel #12
0
 private void Server_Sended(object sender, SendEventArgs e)
 {
     if (e.IP == Robot1IpAddress)
     {
         Robot1Sended?.Invoke(sender, e);
     }
     else if (e.IP == Robot2IpAddress)
     {
         Robot2Sended?.Invoke(sender, e);
     }
 }
Beispiel #13
0
 public void OnSendMove(object sender, SendEventArgs e)
 {
     if (IsLeft(e))
     {
         MovePlatformsLeft();
     }
     if (IsRight(e))
     {
         MovePlatformsRight();
     }
 }
Beispiel #14
0
        private bool SendData()
        {
            int count  = 0;
            int offset = 0;

            if (SendBuffer.GetFirstPacket(ref offset, ref count))
            {
                isSending = true;
                SendEventArgs.SetBuffer(SendBuffer.Buffer.Bytes, offset, count);
                return(AsyncSocket.SendAsync(this));
            }
            return(true);
        }
Beispiel #15
0
 protected virtual void OnDispose()
 {
     try
     {
         object data = DequeueSendMessage();
         while (data != null)
         {
             if (data is IBuffer buffer)
             {
                 BeetleX.Buffers.Buffer.Free(buffer);
                 //((IBuffer)data).Free();
             }
             data = DequeueSendMessage();
         }
         if (SendEventArgs != null)
         {
             SendEventArgs.Dispose();
         }
         if (ReceiveEventArgs != null)
         {
             ReceiveEventArgs.Dispose();
         }
         mReceiveArgs.Server  = null;
         mReceiveArgs.Session = null;
         mBaseNetStream.Dispose();
         if (mSslStream != null)
         {
             mSslStream.Dispose();
         }
         Server.CloseSession(this);
         Server            = null;
         ReceiveDispatcher = null;
         if (Packet != null)
         {
             Packet.Dispose();
         }
         mProperties.Clear();
         if (SendBufferPool is PrivateBufferPool sendPool)
         {
             sendPool.Dispose();
         }
         if (ReceiveBufferPool is PrivateBufferPool receivePool)
         {
             receivePool.Dispose();
         }
     }
     catch
     {
     }
 }
Beispiel #16
0
        private static void Expo_SendCallback(object sender, SendEventArgs e)
        {
            // Store the tickets for querying later
            _Tickets.AddRange(e.Tickets);

            // Output to screen so we can see what we're receiving
            Console.WriteLine();
            Console.WriteLine("Send Callback...");
            foreach (var Ticket in e.Tickets)
            {
                Console.WriteLine(JsonConvert.SerializeObject(Ticket));
            }
            Console.WriteLine();
        }
Beispiel #17
0
 protected virtual void OnDispose()
 {
     try
     {
         object data = DequeueSendMessage();
         while (data != null)
         {
             if (data is IBuffer buffer)
             {
                 BeetleX.Buffers.Buffer.Free(buffer);
             }
             data = DequeueSendMessage();
         }
         SendEventArgs?.Dispose();
         SendEventArgs?.Clear();
         ReceiveEventArgs?.Dispose();
         ReceiveEventArgs?.Clear();
         mReceiveArgs.Server  = null;
         mReceiveArgs.Session = null;
         mBaseNetStream.Dispose();
         if (mSslStream != null)
         {
             mSslStream.Dispose();
         }
         Server.CloseSession(this);
         ListenHandler     = null;
         ReceiveDispatcher = null;
         if (Packet != null)
         {
             Packet.Dispose();
         }
         ((IDisposable)Tag)?.Dispose();
         OnDisposeProperties();
         ((IDisposable)mToken)?.Dispose();
     }
     catch
     {
     }
     finally
     {
         Tag    = null;
         mToken = null;
     }
 }
        async Task EmailClient_Error(SendEventArgs e)
        {
            try
            {
                var msg = $"Could not send an e-mail. The message has been requeued.";
                var err = $"{msg }\r\n{e.Error.GetType().FullName}: {e.Error.Message}";

                if (!_emailClientErrorSet)
                {
                    Logger.LogError(e.Error, msg);
                    _emailClientErrorSet = true;
                }

                foreach (var m in e.Messages)
                {
                    var mid = m.MessageId;
                    if (FindContainer(mid, out var container))
                    {
                        Enqueue(container);

                        if (!_failedMessages.Contains(mid))
                        {
                            await LogEmailFailure(msg, container);

                            var notif = CreateNotification(err
                                                           , container.UserId
                                                           , SysEventType.EmailSendFailed
                                                           , severity: MessageType.Error
                                                           , messageId: mid);

                            Enqueue(notif);

                            _failedMessages.Add(mid);
                        }
                    }
                }

                await _sysRepo.SaveChangesAsync(CancellationTokenSource.Token);
            }
            catch
            {
            }
        }
Beispiel #19
0
        public bool SendAsyncCompleted()
        {
            ActiveDateTime = DateTime.UtcNow;
            mSendAsync     = false;
            SendBuffer.ClearFirstPacket(); //清除已发送的包
            int offset = 0;
            int count  = 0;

            if (SendBuffer.GetFirstPacket(ref offset, ref count))
            {
                mSendAsync = true;
                // 设置发送的数据包
                SendEventArgs.SetBuffer(SendBuffer.Buffer.Bytes, offset, count);
                return(AsyncNet.SendAsync(this));
            }
            else
            {
                return(true);
            }
        }
Beispiel #20
0
 protected virtual void Dispose(bool disposing)
 {
     if (m_disposed)
     {
         return;
     }
     if (disposing)
     {
         //释放托管资源
         m_connectSocket            = null;
         m_asyncReceiveBuffer       = null;
         ReceiveEventArgs.UserToken = null;
         SendEventArgs.UserToken    = null;
     }
     //释放非托管资源
     ReceiveEventArgs.Dispose();
     SendEventArgs.Dispose();
     SendEvent.Dispose();
     m_disposed = true;
 }
        /// <summary>
        /// 关闭连接
        /// </summary>
        public void Close()
        {
            if (Socket != null)
            {
                if (Socket.Connected)
                {
                    Socket.Close();
                }

                Socket.Dispose();
                Socket = null;
            }

            if (SendEventArgs != null)
            {
                SendEventArgs.Completed -= OnSendCompleted;
                SendEventArgs.UserToken  = null;
                SendEventArgs.Dispose();
            }

            SendEventArgs = null;

            if (ReceiveEventArgs != null)
            {
                ReceiveEventArgs.UserToken = null;
                ReceiveEventArgs.Dispose();
            }

            ReceiveEventArgs = null;

            //  清理发送缓冲区
            if (m_PendingBuffer.Count > 0)
            {
                foreach (var buff in m_PendingBuffer)
                {
                    buff.Release();
                }

                m_PendingBuffer.Clear();
            }
        }
Beispiel #22
0
 protected virtual void OnDispose()
 {
     try
     {
         object data = DequeueSendMessage();
         while (data != null)
         {
             if (data is IBuffer)
             {
                 ((IBuffer)data).Free();
             }
             data = DequeueSendMessage();
         }
         if (SendEventArgs != null)
         {
             SendEventArgs.Dispose();
         }
         if (ReceiveEventArgs != null)
         {
             ReceiveEventArgs.Dispose();
         }
         mReceiveArgs.Server  = null;
         mReceiveArgs.Session = null;
         mBaseNetStream.Dispose();
         if (mSslStream != null)
         {
             mSslStream.Dispose();
         }
         Server.CloseSession(this);
         Server            = null;
         ReceiveDispatcher = null;
         if (Packet != null)
         {
             Packet.Dispose();
         }
         mProperties.Clear();
     }
     catch
     {
     }
 }
Beispiel #23
0
 public void DisConnect()
 {
     OnDisConnect(this);
     if (ConnectSocket != null)
     {
         try
         {
             ConnectSocket.Shutdown(SocketShutdown.Both);
         }
         catch (Exception e)
         {
             //日志记录
             loger.Fatal(string.Format("CloseClientSocket Disconnect client {0} error, message: {1}", ConnectSocket, e.Message));
         }
         ConnectSocket.Dispose();
         ConnectSocket = null;
     }
     Clear();
     ReceiveEventArgs.Dispose();
     SendEventArgs.Dispose();
 }
Beispiel #24
0
 protected virtual void OnDispose()
 {
     try
     {
         object data = DequeueSendMessage();
         while (data != null)
         {
             if (data is IBuffer buffer)
             {
                 BeetleX.Buffers.Buffer.Free(buffer);
                 //((IBuffer)data).Free();
             }
             data = DequeueSendMessage();
         }
         SendEventArgs?.Dispose();
         SendEventArgs?.Clear();
         ReceiveEventArgs?.Dispose();
         ReceiveEventArgs?.Clear();
         mReceiveArgs.Server  = null;
         mReceiveArgs.Session = null;
         mBaseNetStream.Dispose();
         if (mSslStream != null)
         {
             mSslStream.Dispose();
         }
         Server.CloseSession(this);
         //Server = null;
         ListenHandler     = null;
         ReceiveDispatcher = null;
         if (Packet != null)
         {
             Packet.Dispose();
         }
         mProperties.Clear();
     }
     catch
     {
     }
 }
Beispiel #25
0
        /// <summary>
        /// 비동기 전송을 시작한다.
        /// </summary>
        private void StartSend()
        {
            byte[] buffer;
            lock (_lockSendingQueue)
            {
                // 전송이 아직 완료된 상태가 아니므로 데이터만 가져오고 큐에서 제거하진 않는다.
                buffer = _sendingQueue.Peek();
            }

            // 이번에 보낼 패킷 사이즈 만큼 버퍼 크기를 설정하고
            // 패킷 내용을 SocketAsyncEventArgs버퍼에 복사한다.
            SendEventArgs.SetBuffer(SendEventArgs.Offset, buffer.Length);
            Array.Copy(buffer, 0, SendEventArgs.Buffer, SendEventArgs.Offset, buffer.Length);


            // 비동기 전송 시작.
            bool pending = Socket.SendAsync(SendEventArgs);

            if (pending == false)
            {
                ProcessSend(SendEventArgs);
            }
        }
        async Task EmailClient_Success(SendEventArgs e)
        {
            try
            {
                foreach (var m in e.Messages)
                {
                    var id = m.MessageId;

                    if (_failedMessages.Contains(id))
                    {
                        _failedMessages.Remove(id);
                    }

                    await RemoveLog(id);

                    if (FindContainer(id, out var container))
                    {
                        _workingSet.Remove(container);
                    }

                    var notif = CreateNotification("E-mail envoyé avec succès."
                                                   , container?.UserId
                                                   , SysEventType.EmailSendSuccess
                                                   , severity: MessageType.Success
                                                   , messageId: id);

                    Enqueue(notif);
                }

                await _sysRepo.SaveChangesAsync(CancellationTokenSource.Token);
            }
            catch (Exception ex)
            {
                Logger.LogWarning(ex, "Could not remove failed e-mail log entry.");
            }
        }
Beispiel #27
0
 public void Dispose()
 {
     if (ConnectDateTime != null)
     {
         lock (closeLock)
         {
             if (ConnectDateTime != null)
             {
                 Clear();
                 ConnectDateTime = null;
                 ActiveDateTime  = null;
                 if (Pool != null)
                 {
                     Pool.Push(this);
                 }
                 else
                 {
                     ReceiveEventArgs.Dispose();
                     SendEventArgs.Dispose();
                 }
             }
         }
     }
 }
Beispiel #28
0
        protected virtual void OnSendComplete(SendEventArgs arg)
        {
            if (arg.SocketError != System.Net.Sockets.SocketError.Success)
            {
                //Release back to the pool
                arg.Socket = null;
                _sendPool.PushBack(arg);
                sending = false;

                Close();
            }
            else if (arg.BytesTransferred == 0)
            {
                //Release back to the pool
                arg.Socket = null;
                _sendPool.PushBack(arg);
                sending = false;

                Close();
            }
            else
            {
                foreach (var msg in arg.Confirmations)
                    msg.callback(msg.state);

                if (SendData(arg) == SendResult.NotQueued)
                {
                    sending = false;
                }
            }
        }
Beispiel #29
0
        public void SendSMS(PlainSMS sms)
        {
            try
            {
                string post = "";


                string send = string.Join(",", sms.Number);

                string content = sms.Signature + sms.Content;
                post = "act=sendmsg&unitid=" + _config.UserId + "&username="******"&passwd=" + _config.Password + "&phone=" + send + "&msg=" + content + "&port=&sendtime=" + DateTime.Now.ToString();
                string t = HTTPRequest.PostWebRequest(sendUrl, post, Encoding.GetEncoding("GBK"));

                Console.WriteLine("发送字符串 " + post);
                //状态,批号,说明
                bool   ok   = true;
                string rmsg = "短信提交成功";

                string[] rt  = t.Split(',');
                int      rok = 0;
                int      r   = 1;//原来默认0 ,应为1  by lmw  1 代表已发送
                if (int.TryParse(rt[0], out rok) && rok == 1)
                {
                }
                else
                {
                    rmsg = GetErrorMsg(rok);
                    Console.WriteLine(rmsg);
                    LogClient.LogHelper.LogInfo("JCSY", "Connect Error ->", rmsg);
                    ok = false;
                    r  = 99;
                }

                int i = 0;
                foreach (string number in sms.Number)
                {
                    SMS s = new SMS();

                    s.Account = sms.Account;
                    s.Audit   = sms.Audit;
                    s.Channel = sms.Channel;
                    s.Content = sms.Content;
                    s.Filter  = sms.Filter;
                    s.Level   = sms.Level;
                    s.Number  = new List <string> {
                        number
                    };
                    s.SendTime     = sms.SendTime;
                    s.SerialNumber = sms.SerialNumber;
                    s.StatusReport = sms.StatusReport;
                    s.Signature    = sms.Signature;
                    s.SPNumber     = sms.SPNumber;
                    s.WapURL       = sms.WapURL;
                    i++;
                    SendEventArgs se = new SendEventArgs(s, rt[1] + i.ToString().PadLeft(5, '0'), ok, (ushort)(2000 + r), rmsg, 1, 1);

                    if (SendEvent != null)
                    {
                        SendEvent(this, se);
                    }
                    //string result = JsonSerialize.Instance.Serialize<SendEventArgs>(se);
                    //Console.WriteLine("短信发送结果:" + result);
                    ExSendEventArgs ese = new ExSendEventArgs(se);
                    if (ok)
                    {
                        lock (locker)
                        {
                            sends.Add(se.SerialNumber, ese);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                LogClient.LogHelper.LogInfo("JCSY", "SendSMS Error ->", ex.Message);
            }
        }
Beispiel #30
0
 public ExSendEventArgs(SendEventArgs sendEventArgs)
 {
     _sendEventArgs = sendEventArgs;
     _time          = DateTime.Now;
 }
Beispiel #31
0
        private void _cm_ExpireCache(List <List <SMS> > caches)
        {
            if (sendProcess)
            {
                return;
            }
            sendProcess = true;
            Console.WriteLine("缓存过期条数 " + caches.Count);

            try
            {
                string post = "";
                for (int i = 0; i < caches.Count; i++)
                {
                    List <string> ss = new List <string>();
                    foreach (SMS s in caches[i])
                    {
                        ss.AddRange(s.Number);
                    }
                    Console.WriteLine("第 " + i + " 条包含短信数量 " + caches[i].Count);
                    string send = "";
                    foreach (string s in ss)
                    {
                        send += s + ",";
                    }
                    send = send.Substring(0, send.Length - 1);
                    string content = caches[i][0].Content + caches[i][0].Signature;
                    post = "act=sendmsg&unitid=" + _config.UserId + "&username="******"&passwd=" + _config.Password + "&phone=" + send + "&msg=" + content + "&port=&sendtime=" + DateTime.Now.ToString();
                    string t = HTTPRequest.PostWebRequest(sendUrl, post, Encoding.UTF8);

                    Console.WriteLine("发送字符串 " + post);
                    //状态,批号,说明
                    bool   ok   = true;
                    string rmsg = "短信提交成功";

                    string[] rt  = t.Split(',');
                    int      rok = 0;
                    int.TryParse(rt[0], out rok);
                    if (rok < 0)
                    {
                        rmsg = GetErrorMsg(rok);
                        Console.WriteLine(rmsg);
                        LogClient.LogHelper.LogInfo("JCSY", "Connect Error ->", rmsg);
                        ok = false;
                    }
                    int r = 1;//原来默认0 ,应为1  by lmw  1 代表已发送
                    if (!ok)
                    {
                        // r = 101;
                        r = 99;//提交失败 错误码应该在100以内吧   by lmw
                    }

                    foreach (SMS s in caches[i])
                    {
                        SendEventArgs se = new SendEventArgs(s, rt[1] + s.Number[0], ok, (ushort)(2000 + r), rmsg, 1, 1);
                        //string result = JsonSerialize.Instance.Serialize<SendEventArgs>(se);
                        //Console.WriteLine("短信发送结果:" + result);
                        ExSendEventArgs ese = new ExSendEventArgs(se);
                        if (ok)
                        {
                            sends.Add(se.SerialNumber, ese);
                            //LogClient.LogHelper.LogInfo("JCSY", "SendSMS OK ->", result);
                        }
                        else
                        {
                            //LogClient.LogHelper.LogInfo("JCSY", "SendSMS Fail ->", result);
                        }
                        if (SendEvent != null)
                        {
                            SendEvent(this, se);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                LogClient.LogHelper.LogInfo("JCSY", "SendSMS Error ->", ex.Message);
            }
            sendProcess = false;
        }
 /// <summary>
 /// Bitcoin has been sent from a user's primary wallet account.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void onSendSuccess(object sender, SendEventArgs e)
 {
     WriteToConsole("onSendSuccess: " + "Transaction: " + e.TransactionId + " Bitcoin: " + e.BitcoinAmount + " Destination: " + e.Destination);
 }
Beispiel #33
0
 void Events_Sending(object sender, SendEventArgs e)
 {
     Send(e.RawStream.ToArray());
 }
Beispiel #34
0
 private void Sensor2_Sended(object sender, SendEventArgs e) => Sensor2Sended?.Invoke(sender, e);
Beispiel #35
0
 void Events_Sending(object sender, SendEventArgs e)
 {
     Send(_panelLibrary.WorkSocket, e.RawStream.ToArray());
 }