public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = (SecurityCode != null
                                 ? SecurityCode.GetHashCode()
                                 : 0);
         hashCode = (hashCode * 397) ^ (OptionNumber != null
                                 ? OptionNumber.GetHashCode()
                                 : 0);
         hashCode = (hashCode * 397) ^ (OptionCode != null
                                 ? OptionCode.GetHashCode()
                                 : 0);
         hashCode = (hashCode * 397) ^ Bid.GetHashCode();
         hashCode = (hashCode * 397) ^ BidVolume.GetHashCode();
         hashCode = (hashCode * 397) ^ Ask.GetHashCode();
         hashCode = (hashCode * 397) ^ AskVolume.GetHashCode();
         hashCode = (hashCode * 397) ^ Volume.GetHashCode();
         hashCode = (hashCode * 397) ^ Bid2.GetHashCode();
         hashCode = (hashCode * 397) ^ BidVolume2.GetHashCode();
         hashCode = (hashCode * 397) ^ Ask2.GetHashCode();
         hashCode = (hashCode * 397) ^ AskVolume2.GetHashCode();
         hashCode = (hashCode * 397) ^ Bid3.GetHashCode();
         hashCode = (hashCode * 397) ^ BidVolume3.GetHashCode();
         hashCode = (hashCode * 397) ^ Ask3.GetHashCode();
         hashCode = (hashCode * 397) ^ AskVolume3.GetHashCode();
         hashCode = (hashCode * 397) ^ Bid4.GetHashCode();
         hashCode = (hashCode * 397) ^ BidVolume4.GetHashCode();
         hashCode = (hashCode * 397) ^ Ask4.GetHashCode();
         hashCode = (hashCode * 397) ^ AskVolume4.GetHashCode();
         hashCode = (hashCode * 397) ^ Bid5.GetHashCode();
         hashCode = (hashCode * 397) ^ BidVolume5.GetHashCode();
         hashCode = (hashCode * 397) ^ Ask5.GetHashCode();
         hashCode = (hashCode * 397) ^ AskVolume5.GetHashCode();
         hashCode = (hashCode * 397) ^ (Greeks != null
                                 ? Greeks.GetHashCode()
                                 : 0);
         hashCode = (hashCode * 397) ^ OpenInterest.GetHashCode();
         hashCode = (hashCode * 397) ^ Turnover.GetHashCode();
         hashCode = (hashCode * 397) ^ UncoveredPositionQuantity.GetHashCode();
         hashCode = (hashCode * 397) ^ PreviousSettlementPrice.GetHashCode();
         hashCode = (hashCode * 397) ^ OpeningPrice.GetHashCode();
         hashCode = (hashCode * 397) ^ AuctionReferencePrice.GetHashCode();
         hashCode = (hashCode * 397) ^ AuctionReferenceQuantity.GetHashCode();
         hashCode = (hashCode * 397) ^ HighestPrice.GetHashCode();
         hashCode = (hashCode * 397) ^ LowestPrice.GetHashCode();
         hashCode = (hashCode * 397) ^ LatestTradedPrice.GetHashCode();
         hashCode = (hashCode * 397) ^ Change.GetHashCode();
         hashCode = (hashCode * 397) ^ ChangePercentage.GetHashCode();
         hashCode = (hashCode * 397) ^ PreviousClose.GetHashCode();
         hashCode = (hashCode * 397) ^ (Name != null
                                 ? Name.GetHashCode()
                                 : 0);
         return(hashCode);
     }
 }
Beispiel #2
0
        private void btnSendMessage_Click(object sender, RoutedEventArgs e)
        {
            if (_channelCollection.Count <= 0)
            {
                MessageBox.Show("No channel!");
            }

            try
            {
                TextMessageRequest textMsg = new TextMessageRequest();
                textMsg._msg      = "test"; // tbSendText.Text;
                textMsg._targetID = 20;     // (uint)int.Parse(tbTargetID.Text);

                OptionCode messageOpcode = new OptionCode();
                //if (cboxCallType.SelectedIndex == 0)
                //{
                //    //发送呼叫消息,均需要回复。
                //    messageOpcode = OptionCode.TMP_PRIVATE_NEED_ACK_REQUEST;
                //}
                //else
                //{
                //    messageOpcode = OptionCode.TMP_GROUP_REQUEST;
                //}
                messageOpcode = OptionCode.TMP_PRIVATE_NEED_ACK_REQUEST;

                uint channelId = GetChannel(1).channelId;

                int requestID = _adk.GetService(ServiceType.TMP).SendCommand(textMsg, messageOpcode, channelId);
                if (requestID == -1)
                {
                    return;
                }

                if (_msgRequesetIdMsgItemInfoDict.ContainsKey((uint)requestID))
                {
                    return;
                }

                _msgRequesetIdMsgItemInfoDict.Add((uint)requestID, textMsg._targetID.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "UTech", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #3
0
 public override int GetHashCode()
 {
     return(OptionCode != null ? OptionCode.GetHashCode() : 0);
 }
Beispiel #4
0
        private Task <bool> FetchEmailsAndForward()
        {
            List <Message> msg_list = null;

            try
            {
                msg_list = email_service.FetchUnseenMessages(PopServerHost, port, true, username, password, seenUids);
                //List<Message> msg_list = email_service.FetchUnseenMessages(PopServerHost, port, true, username, password, seenUids);
                //List<Message> msg_list = email_service.FetchAllMessages();
                //lvSendLog.Items.Clear();

                //log file info
                string fpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                string fname = "email.log";
                // This file will have a new line at the end.
                FileInfo info = new FileInfo(fpath + "\\" + fname);

                if (msg_list.Count == 0)
                {
                    return(Task <bool> .Factory.StartNew(() => false));
                }
                foreach (Message msg in msg_list)
                {
                    FromUserEmail = msg.Headers.From.Address;
                    if (!(msg.Headers.From.Address.Contains("@hyt.com") ||
                          msg.Headers.From.Address.Equals("*****@*****.**")))
                    {
                        continue;
                    }
                    StringBuilder builder      = new StringBuilder();
                    string        strEmailInfo = string.Empty;
                    strEmailInfo += msg.Headers.Date;
                    strEmailInfo += CRLF;
                    strEmailInfo += msg.Headers.From.Address;
                    strEmailInfo += CRLF;
                    strEmailInfo += msg.MessagePart.Body;
                    strEmailInfo += CRLF;

                    MessagePart plainText = msg.FindFirstPlainTextVersion();
                    if (plainText != null)
                    {
                        // We found some plaintext!
                        builder.Append(plainText.GetBodyAsText());
                    }
                    else
                    {
                        // Might include a part holding html instead
                        MessagePart html = msg.FindFirstHtmlVersion();
                        if (html != null)
                        {
                            // We found some html!
                            builder.Append(html.GetBodyAsText());
                        }
                    }

                    //save email into log file
                    using (StreamWriter writer = info.AppendText())
                    {
                        //writer.WriteLine(tbSendText.Text);
                        writer.WriteLine(strEmailInfo);
                    }

                    sendlog_items.Add(new SendLog()
                    {
                        FromName         = msg.Headers.From.DisplayName + msg.Headers.From.Address,
                        ReceivedDatetime = msg.Headers.Date,
                        MailSubject      = msg.Headers.Subject,
                        MailBody         = Regex.Replace(builder.ToString(), @"^\s*$\n|\r", "", RegexOptions.Multiline).TrimEnd()
                                           //MailBody = msg.MessagePart.Body == null ? "" : msg.MessagePart.Body.ToString()
                    });


                    AddSendItem(new SendLog()
                    {
                        FromName = msg.Headers.From.ToString(),
                        //FromName = msg.Headers.Sender == null ? "" : msg.Headers.Sender.ToString(),
                        ReceivedDatetime = msg.Headers.Date,
                        MailSubject      = msg.Headers.Subject,
                        MailBody         = Regex.Replace(builder.ToString(), @"^\s*$\n|\r", "", RegexOptions.Multiline).TrimEnd()
                    });
                    string tmp = builder.ToString();
                    FromUserEmail = tmp.Substring(tmp.IndexOf("Email:") + 7, tmp.IndexOf("Telephone") - tmp.IndexOf("Email:") - 8);
                }
                // delete message loop doesn't overlap with message handling loop
                // in order to avoid read/delete conflict on server
                foreach (Message msg in msg_list)
                {
                    //delete email after fetch, otherwise will be fetched next time
                    if (email_service.DeleteMessageByMessageId(msg.Headers.MessageId))
                    {
                        //MessageBox.Show("The message " + msg.Headers.MessageId + " has been deleted");
                    }
                }
            }
            // Catch these exceptions but don't do anything
            catch (PopServerLockedException psle)
            {
                return(Task <bool> .Factory.StartNew(() => false));
            }
            catch (PopServerNotAvailableException psnae)
            {
                return(Task <bool> .Factory.StartNew(() => false));
            }
            catch (PopServerException psle)
            {
                return(Task <bool> .Factory.StartNew(() => false));
            }


            //send to mobile
            #region send_to_mobile
            if (_channelCollection.Count <= 0)
            {
                //MessageBox.Show("No channel!");
                AutoClosingMessageBox msgBox = new AutoClosingMessageBox("No channel available!", "UTech Demo", 2000);
                return(Task <bool> .Factory.StartNew(() => false));
            }

            try
            {
                foreach (Message msg in msg_list)
                {
                    TextMessageRequest textMsg   = new TextMessageRequest();
                    StringBuilder      builder   = new StringBuilder();
                    MessagePart        plainText = msg.FindFirstPlainTextVersion();
                    if (plainText != null)
                    {
                        // We found some plaintext!
                        builder.Append(plainText.GetBodyAsText());
                    }
                    else
                    {
                        // Might include a part holding html instead
                        MessagePart html = msg.FindFirstHtmlVersion();
                        if (html != null)
                        {
                            // We found some html!
                            builder.Append(html.GetBodyAsText());
                        }
                    }
                    textMsg._msg      = builder.ToString(); //should be from email somewhere
                    textMsg._targetID = 20;                 //hardcode
                    OptionCode messageOpcode = new OptionCode();
                    messageOpcode = OptionCode.TMP_PRIVATE_NEED_ACK_REQUEST;
                    uint channelId = GetChannel(1).channelId;

                    int requestID = _adk.GetService(ServiceType.TMP).SendCommand(textMsg, messageOpcode, channelId);
                    if (requestID == -1)
                    {
                        return(Task <bool> .Factory.StartNew(() => false));
                    }
                    if (_msgRequesetIdMsgItemInfoDict.ContainsKey((uint)requestID))
                    {
                        return(Task <bool> .Factory.StartNew(() => false));
                    }
                    _msgRequesetIdMsgItemInfoDict.Add((uint)requestID, textMsg._targetID.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "UTech Demo", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            #endregion

            return(Task <bool> .Factory.StartNew(() => true));
        }
Beispiel #5
0
        private Task <bool> FetchEmailsAndForward()
        {
            //send to mobile
            #region send_to_mobile
            if (_channelCollection.Count <= 0)
            {
                //MessageBox.Show("No channel!");
                AutoClosingMessageBox msgBox = new AutoClosingMessageBox("Retrying ...", "Not connected!", 2000);
                return(Task <bool> .Factory.StartNew(() => false));
            }

            List <Message> msg_list = null;
            try
            {
                msg_list = email_service.FetchUnseenMessages(seenUids);
                if (msg_list.Count == 0)
                {
                    return(Task <bool> .Factory.StartNew(() => false));
                }
            }
            // Catch these exceptions but don't do anything
            catch (PopServerLockedException psle)
            {
                return(Task <bool> .Factory.StartNew(() => false));
            }
            catch (PopServerNotAvailableException psnae)
            {
                return(Task <bool> .Factory.StartNew(() => false));
            }
            catch (PopServerException psle)
            {
                return(Task <bool> .Factory.StartNew(() => false));
            }

            try
            {
                //log file info
                //string fpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                string fpath = Directory.GetCurrentDirectory();
                string fname = "email.log";
                // This file will have a new line at the end.
                FileInfo info = new FileInfo(fpath + "\\" + fname);

                foreach (Message msg in msg_list)
                {
                    var    to_addr = msg.Headers.To[0].Address;
                    Person p       = contactList.Find(x => x.Email.TrimEnd().Equals(to_addr));
                    if (p == null)
                    {
                        if (email_service.DeleteMessageByMessageId(msg.Headers.MessageId))
                        {
                            //MessageBox.Show("The message " + msg.Headers.MessageId + " has been deleted");
                            WriteMessageLog(info, msg);
                        }
                        continue;
                    }

                    TextMessageRequest textMsg = new TextMessageRequest();
                    StringBuilder      builder = new StringBuilder();
                    builder.Append(msg.Headers.Subject);

                    textMsg._msg      = builder.ToString().TrimEnd() + CRLF;
                    textMsg._targetID = uint.Parse(p.TargetID);
                    OptionCode messageOpcode = new OptionCode();
                    messageOpcode = OptionCode.TMP_PRIVATE_NEED_ACK_REQUEST;
                    uint channelId = GetChannel(1).channelId;

                    int requestID = _adk.GetService(ServiceType.TMP).SendCommand(textMsg, messageOpcode, channelId);
                    if (requestID == -1)
                    {
                        continue;                  // return Task<bool>.Factory.StartNew(() => false);
                    }
                    if (_msgRequesetIdMsgItemInfoDict.ContainsKey((uint)requestID))
                    {
                        return(Task <bool> .Factory.StartNew(() => false));
                    }
                    _msgRequesetIdMsgItemInfoDict.Add((uint)requestID, textMsg._targetID.ToString());


                    sendlog_items.Add(new SendLog()
                    {
                        ID               = requestID,
                        EmailID          = msg.Headers.MessageId,
                        FromName         = (string.IsNullOrEmpty(msg.Headers.From.DisplayName) ? "" : "<" + msg.Headers.From.DisplayName + ">") + msg.Headers.From.Address,
                        ReceivedDatetime = DateTime.Now.ToString(), //msg.Headers.Date,
                        MailSubject      = msg.Headers.Subject,
                        MailBody         = Regex.Replace(builder.ToString(), @"^\s*$\n|\r", "", RegexOptions.Multiline).TrimEnd()
                    });
                    WriteMessageLog(info, msg);
                    //string strEmailInfo = string.Empty;
                    //strEmailInfo += "Date: " + DateTime.Now; // msg.Headers.Date;
                    //strEmailInfo += CRLF;
                    //string display_name = msg.Headers.From.DisplayName == null ? "" : "<" + msg.Headers.From.DisplayName + ">";
                    //strEmailInfo += "From: " + display_name + msg.Headers.From.Address;
                    //strEmailInfo += CRLF;
                    //display_name = msg.Headers.To.FirstOrDefault().DisplayName == null ? "" : "<" + msg.Headers.To.FirstOrDefault().DisplayName + ">";
                    //strEmailInfo += "To: " + display_name + msg.Headers.To.FirstOrDefault().Address;
                    //strEmailInfo += CRLF;
                    //strEmailInfo += "Subject: " + msg.Headers.Subject;
                    //strEmailInfo += CRLF;
                    //string mail_body = msg.FindFirstPlainTextVersion() != null ? msg.FindFirstPlainTextVersion().GetBodyAsText() : msg.FindFirstHtmlVersion().GetBodyAsText();
                    //strEmailInfo += "Body: " + mail_body;
                    //strEmailInfo += CRLF;

                    ////save email into log file
                    //using (StreamWriter writer = info.AppendText())
                    //{
                    //    //writer.WriteLine(tbSendText.Text);
                    //    writer.WriteLine(strEmailInfo);
                    //}
                }
            }
            catch (Exception ex)
            {
                AutoClosingMessageBox msgBox = new AutoClosingMessageBox(ex.Message, "UTech Email Gateway", 5000);
                //MessageBox.Show(ex.Message, "UTech Demo", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            #endregion

            return(Task <bool> .Factory.StartNew(() => true));
        }