コード例 #1
0
        private void WritePassword(MyCatPacket packet)
        {
            bool   secure   = (Flags & ClientFlags.SECURE_CONNECTION) != 0;
            object password = GetPassword();

            if (password is string)
            {
                if (secure)
                {
                    packet.WriteLenString((string)password);
                }
                else
                {
                    packet.WriteString((string)password);
                }
            }
            else if (password == null)
            {
                packet.WriteByte(0);
            }
            else if (password is byte[])
            {
                packet.Write(password as byte[]);
            }
            else
            {
                throw new MyCatException("Unexpected password format: " + password.GetType());
            }
        }
コード例 #2
0
 void IMyCatValue.WriteValue(MyCatPacket packet, bool binary, object val, int length)
 {
   decimal v = (val is decimal) ? (decimal)val : Convert.ToDecimal(val);
   string valStr = v.ToString(CultureInfo.InvariantCulture);
   if (binary)
     packet.WriteLenString(valStr);
   else
     packet.WriteStringNoNull(valStr);
 }
コード例 #3
0
        void IMyCatValue.WriteValue(MyCatPacket packet, bool binary, object val, int length)
        {
            Guid   guid        = Guid.Empty;
            string valAsString = val as string;

            byte[] valAsByte = val as byte[];

            if (val is Guid)
            {
                guid = (Guid)val;
            }
            else
            {
                try
                {
                    if (valAsString != null)
                    {
                        guid = new Guid(valAsString);
                    }
                    else if (valAsByte != null)
                    {
                        guid = new Guid(valAsByte);
                    }
                }
                catch (Exception ex)
                {
                    throw new MyCatException(Resources.DataNotInSupportedFormat, ex);
                }
            }

            if (OldGuids)
            {
                WriteOldGuid(packet, guid, binary);
            }
            else
            {
                guid.ToString("D");

                if (binary)
                {
                    packet.WriteLenString(guid.ToString("D"));
                }
                else
                {
                    packet.WriteStringNoNull("'" + MyCatHelper.EscapeString(guid.ToString("D")) + "'");
                }
            }
        }
コード例 #4
0
        void IMyCatValue.WriteValue(MyCatPacket packet, bool binary, object val, int length)
        {
            string v = val.ToString();

            if (length > 0)
            {
                length = Math.Min(length, v.Length);
                v      = v.Substring(0, length);
            }

            if (binary)
            {
                packet.WriteLenString(v);
            }
            else
            {
                packet.WriteStringNoNull("'" + MyCatHelper.EscapeString(v) + "'");
            }
        }