Example #1
0
 /// <summary>
 /// Ends the send data.
 /// </summary>
 /// <param name="result">The result.</param>
 public void EndSendData(IAsyncResult result)
 {
     try
     {
         _stream.EndWrite(result);
     } catch (Exception e)
     {
         // Error, for example stream has already been Disposed
         _logger.DebugException("Error during end send (can be ignored)", e);
         result = null;
     }
 }
Example #2
0
 /// <summary>
 /// 检查是否有敏感字符
 /// </summary>
 /// <param name="content">短信内容</param>
 /// <param name="message">错误信息</param>
 /// <returns>true:有敏感字符</returns>
 public static bool CheckSensitiveWords(string content, out string message)
 {
     message = "";
     try
     {
         MessageSendManage mm = new MessageSendManage();
         message = mm.CheckSensitiveWords(content);
         if (string.IsNullOrEmpty(message) || message.Split('|')[0] == "1")
         {
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         //message = "敏感字符检测失败!";
         Logger.DebugException(message, ex);
         return(true);
     }
 }
Example #3
0
        /// <summary>Connected successfully to the server, send login data.</summary>
        private void HandleConnected(IAsyncResult result)
        {
            lock (this)
            {
                if (_tcp == null)
                {
                    return;
                }
                try
                {
                    Logger.Debug("Connected to host, sending actual join request.");
                    _tcp.EndConnect(result);
                    _stream =
                        new EncryptedPacketStream(new CompressedPacketStream(new NetworkPacketStream(_tcp.GetStream())));
                    using (var packet = new Packet())
                    {
                        using (var packetInner = new Packet())
                        {
                            packetInner.
                            Write(_playerName).
                            Write(_playerData);
                            packet.
                            Write((byte)SessionMessage.JoinRequest).
                            Write((IWritablePacket)packetInner);
                            var written = _stream.Write(packet);

                            // Statistics.
                            Info.PutOutgoingTraffic(written, TrafficTypes.Protocol);
                            Info.PutOutgoingPacketSize(written);
                            Info.PutOutgoingPacketCompression((packet.Length / (float)written) - 1f);
                        }
                    }
                }
                catch (SocketException ex)
                {
                    // Connection failed.
                    Logger.DebugException("Join failed.", ex);
                    _resetRequested = true;
                }
            }
        }
 public void Debug(string message, Exception ex)
 {
     wrappedLogger.DebugException(message, ex);
 }
 public void DebugException(string message, Exception exception)
 {
     _nlogger.DebugException(message, exception);
 }
Example #6
0
 /// <summary>
 /// Logs a Debug message and exception.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="exception">The exception.</param>
 public void Debug(object message, Exception exception)
 {
     log.DebugException(message.ToString(), exception);
 }
Example #7
0
        /// <summary>
        /// Parses the ofx file data and turns it into valid xml.
        /// </summary>
        /// <param name="rawOfx">The ofx data.</param>
        /// <returns>An xml representation of the ofx data.</returns>
        public XElement Parse()
        {
            XElement root = new XElement("OFX");

            try {
                if (string.IsNullOrEmpty(m_rawOfx))
                {
                    throw new OfxParseException("rawOfx is empty.");
                }

                // add additional returns to allow for parsing
                // ofx files that are all on one line
                string data = m_rawOfx.Replace("<", "\n\r<").Replace("\t", string.Empty);

                string[] lines = data.Split(
                    new string[] { "\n", "\r" },
                    StringSplitOptions.RemoveEmptyEntries);

                List <string> statusTags   = new List <string> ();
                bool          isStatusLine = false;
                foreach (string line in lines)
                {
                    if (line.Contains("<STATUS>") || line.Contains("</STATUS>") || isStatusLine)
                    {
                        if (!string.IsNullOrEmpty(line) && !line.Contains("</STATUS>"))
                        {
                            statusTags.Add(line);
                        }

                        isStatusLine = !line.Contains("</STATUS>");
                    }
                    else
                    {
                        continue;
                    }
                }

                var balanceTags = from line in lines
                                  where line.Contains("<LEDGERBAL") ||
                                  line.Contains("<AVAILBAL>") ||
                                  line.Contains("<DTASOF>") ||
                                  line.Contains("<BALAMT>")
                                  select line;

                if (balanceTags.Count() == 0)
                {
                    throw new OfxParseException("No balance tags found.");
                }

                List <string> transactionTags   = new List <string> ();
                bool          isTransactionLine = false;
                foreach (string line in lines)
                {
                    if (line.Contains("STMTTRN>") || isTransactionLine)
                    {
                        if (!line.Contains("</STMTTRN>"))
                        {
                            transactionTags.Add(line);
                        }

                        isTransactionLine = !line.Contains("</STMTTRN>");
                    }
                    else
                    {
                        continue;
                    }
                }

                List <string> accountInfoTags = new List <string> ();
                bool          isAcctInfoLine  = false;
                foreach (string line in lines)
                {
                    if (line.Contains("ACCTINFO>") || isAcctInfoLine)
                    {
                        if (line.Contains("<CCACCTINFO"))
                        {
                            //CCACCTINFO does not contain ACCTTYPE but we will add it for easier parsing
                            accountInfoTags.Add("<ACCTTYPE>" + DTO.AccountType.CREDITCARD.ToString());
                        }
                        else if (line.Contains("<ACCTINFO>") ||
                                 line.Contains("<DESC") ||
                                 line.Contains("<BANKID") ||
                                 line.Contains("<ACCTID") ||
                                 line.Contains("<ACCTTYPE"))
                        {
                            accountInfoTags.Add(line);
                        }

                        isAcctInfoLine = !line.Contains("</ACCTINFO>");
                    }
                    else
                    {
                        continue;
                    }
                }

                XElement child = null;

                // parse status
                if (statusTags.Count > 0)
                {
                    XElement statusesElement = new XElement("STATUSES");
                    root.Add(statusesElement);

                    foreach (var line in statusTags)
                    {
                        if (line.Contains("<STATUS>"))
                        {
                            child = new XElement("STATUS");
                            statusesElement.Add(child);
                        }
                        else if (!line.Contains("</STATUS>"))
                        {
                            var tagName      = GetTagName(line);
                            var elementChild = new XElement(tagName)
                            {
                                Value = GetTagValue(line)
                            };

                            child.Add(elementChild);
                        }
                    }

                    foreach (XElement status in statusesElement.Descendants("STATUS"))
                    {
                        var    code           = status.Element("CODE");
                        string message        = string.Empty;
                        var    messageElement = status.Element("MESSAGE");
                        if (messageElement != null &&
                            messageElement.Value != null)
                        {
                            message = messageElement.Value;
                        }

                        if (code != null &&
                            (!string.IsNullOrEmpty(code.Value)) &&
                            code.Value != STATUS_CODE_SUCCESS)
                        {
                            throw new OfxStatusException(code.Value, message);
                        }
                    }
                }

                // parse transactions
                if (transactionTags.Count > 0)
                {
                    //balances
                    foreach (var line in balanceTags)
                    {
                        if (line.Contains("<LEDGERBAL") || line.Contains("<AVAILBAL"))
                        {
                            child = new XElement(GetTagName(line));
                            root.Add(child);
                        }
                        else
                        {
                            var tagName      = GetTagName(line);
                            var elementChild = new XElement(tagName)
                            {
                                Value = GetTagValue(line)
                            };

                            child.Add(elementChild);
                        }
                    }

                    XElement transactions = new XElement("BANKTRANLIST");
                    root.Add(transactions);

                    foreach (var line in transactionTags)
                    {
                        if (line.Contains("<STMTTRN>"))
                        {
                            child = new XElement("STMTTRN");
                            transactions.Add(child);
                        }
                        else if (!line.Contains("</STMTTRN>"))
                        {
                            var tagName      = GetTagName(line);
                            var elementChild = new XElement(tagName)
                            {
                                Value = GetTagValue(line)
                            };

                            child.Add(elementChild);
                        }
                    }
                }

                // parse account list
                if (accountInfoTags.Count > 0)
                {
                    XElement accounts = new XElement("ACCTINFORS");
                    root.Add(accounts);

                    foreach (var line in accountInfoTags)
                    {
                        if (line.Contains("<ACCTINFO>"))
                        {
                            child = new XElement("ACCTINFO");
                            accounts.Add(child);
                        }
                        else if (!line.Contains("</ACCTINFO>"))
                        {
                            var tagName      = GetTagName(line);
                            var elementChild = new XElement(tagName)
                            {
                                Value = GetTagValue(line)
                            };

                            child.Add(elementChild);
                        }
                    }
                }
            } catch (OfxStatusException) {
                throw;
            } catch (OfxParseException) {
                throw;
            } catch (Exception ex) {
                s_logger.DebugException("Error parsing OFX", ex);
                throw new OfxParseException(ex.Message, ex);
            }

            return(root);
        }
Example #8
0
        /// <summary>
        /// Logs the given message.
        /// Output depends on the associated NLog configuration.
        /// </summary>
        /// <param name="item">A <see cref="LogItem"/> which encapsulates information to be logged.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="item"/> is a null reference.</exception>
        public override void Write(LogItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            string message = FormatItem(item);

            if (item.Exception != null)
            {
                switch (item.LogLevel)
                {
                case LogLevel.Fatal:
                    log.FatalException(message, item.Exception);
                    break;

                case LogLevel.Error:
                    log.ErrorException(message, item.Exception);
                    break;

                case LogLevel.Warn:
                    log.WarnException(message, item.Exception);
                    break;

                case LogLevel.Info:
                    log.InfoException(message, item.Exception);
                    break;

                case LogLevel.Debug:
                    log.DebugException(message, item.Exception);
                    break;

                default:
                    log.InfoException(message, item.Exception);
                    break;
                }
            }
            else
            {
                switch (item.LogLevel)
                {
                case LogLevel.Fatal:
                    log.Fatal(message);
                    break;

                case LogLevel.Error:
                    log.Error(message);
                    break;

                case LogLevel.Warn:
                    log.Warn(message);
                    break;

                case LogLevel.Info:
                    log.Info(message);
                    break;

                case LogLevel.Debug:
                    log.Debug(message);
                    break;

                default:
                    log.Info(message);
                    break;
                }
            }
        }
Example #9
0
        void Log(LogItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (item.LogException != null)
            {
                switch (item.Level)
                {
                case LogLevel.Fatal:
                    _logger.FatalException(item.Text, item.LogException);
                    break;

                case LogLevel.Error:
                    _logger.ErrorException(item.Text, item.LogException);
                    break;

                case LogLevel.Warn:
                    _logger.WarnException(item.Text, item.LogException);
                    break;

                case LogLevel.Info:
                    _logger.InfoException(item.Text, item.LogException);
                    break;

                case LogLevel.Debug:
                    _logger.DebugException(item.Text, item.LogException);
                    break;

                default:
                    _logger.InfoException(item.Text, item.LogException);
                    break;
                }
            }
            else
            {
                switch (item.Level)
                {
                case LogLevel.Fatal:
                    _logger.Fatal(item.Text);
                    break;

                case LogLevel.Error:
                    _logger.Error(item.Text);
                    break;

                case LogLevel.Warn:
                    _logger.Warn(item.Text);
                    break;

                case LogLevel.Info:
                    _logger.Info(item.Text);
                    break;

                case LogLevel.Debug:
                    _logger.Debug(item.Text);
                    break;

                default:
                    _logger.Info(item.Text);
                    break;
                }
            }
        }