private string GetValue(Column column, object value) { if (value == null) { return("NULL"); } else { switch (Type.GetTypeCode(value.GetType())) { case TypeCode.Empty: break; case TypeCode.Object: if (value is Guid) { return(string.Format("'{0}'", ((Guid)value).ToString("D"))); } byte[] bytes = value as byte[]; if (bytes != null) { return("0x" + ConvertUtilities.ToHexa(bytes)); } break; case TypeCode.DBNull: return("NULL"); case TypeCode.Boolean: return((bool)value ? "1" : "0"); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return(string.Format(CultureInfo.InvariantCulture, "{0}", value)); case TypeCode.DateTime: return(string.Format("'{0:O}'", (DateTime)value)); case TypeCode.Char: case TypeCode.String: return(EscapeStringValue(column, string.Format("{0}", value))); } } throw new InvalidOperationException(); }
private object GetHash(Column column, PasswordFormat format, string password) { using (HashAlgorithm algorithm = CreateAlgorithm(format)) { byte[] buffer = Encoding.UTF8.GetBytes(password); byte[] hash = algorithm.ComputeHash(buffer); if (IsStringDbType(column)) { return(ConvertUtilities.ToHexa(hash)); } return(hash); } }
protected override object GenerateCore(Project project, Column column) { var format = Format; if (format == ColorFormat.Auto) { if (IsNumericDbType(column)) { format = ColorFormat.IntegerARGB; } else { format = ColorFormat.RGB; } } switch (format) { case ColorFormat.Name: if (_colors == null) { _colors = typeof(Colors).GetProperties().Where(_ => typeof(Color).IsAssignableFrom(_.PropertyType)).Select(_ => _.Name).ToArray(); } return(Random.NextFromArray(_colors)); case ColorFormat.IntegerRGB: return(Random.NextInt32(0, 1 << 24)); case ColorFormat.IntegerARGB: return(Random.NextInt32()); case ColorFormat.RGB: return(ConvertUtilities.ToHexa(new[] { Random.NextByte(), Random.NextByte(), Random.NextByte() })); case ColorFormat.HtmlRGB: return("#" + ConvertUtilities.ToHexa(new[] { Random.NextByte(), Random.NextByte(), Random.NextByte() })); case ColorFormat.ARGB: return(ConvertUtilities.ToHexa(new[] { Random.NextByte(), Random.NextByte(), Random.NextByte(), Random.NextByte() })); case ColorFormat.HtmlARGB: return("#" + ConvertUtilities.ToHexa(new[] { Random.NextByte(), Random.NextByte(), Random.NextByte(), Random.NextByte() })); default: throw new ArgumentOutOfRangeException(); } }