Permalink
Browse files

added the new types introduced in Cassandra 1.0.0

  • Loading branch information...
1 parent 3bca32c commit 2b76325c61c66894650a15f5a0e88a1a754a754f @nberardi nberardi committed Jan 29, 2012
Showing with 1,308 additions and 586 deletions.
  1. BIN lib/Ionic.Zip.dll
  2. BIN lib/Ionic.Zip.shadow
  3. BIN lib/LINQPad.exe
  4. +2 −2 src/Connections/ConnectionBuilder.cs
  5. +19 −0 src/FluentCassandra.csproj
  6. BIN src/FluentCassandra.snk
  7. +27 −2 src/FluentColumn.cs
  8. +2 −2 src/FluentColumnFamily.cs
  9. +2 −2 src/FluentSuperColumn.cs
  10. +2 −2 src/FluentSuperColumnFamily.cs
  11. +1 −1 src/Operations/CassandraIndexClauseBuilder.cs
  12. +1 −1 src/Operations/ExecuteCqlQuery.cs
  13. +4 −4 src/Operations/Helper.cs
  14. +1 −1 src/Operations/MultiGetColumnFamilySlice.cs
  15. +1 −1 src/Operations/MultiGetSuperColumnFamilySlice.cs
  16. +96 −0 src/Types/BooleanType.cs
  17. +42 −0 src/Types/BooleanTypeConverter.cs
  18. +44 −7 src/Types/CassandraType.cs
  19. +1 −1 src/Types/CassandraTypeConverter.cs
  20. +7 −7 src/Types/CassandraTypeExtensions.cs
  21. +2 −2 src/Types/CompositeType.cs
  22. +1 −1 src/Types/CompositeTypeConverter.cs
  23. +104 −0 src/Types/DateType.cs
  24. +104 −0 src/Types/DateTypeConverter.cs
  25. +96 −0 src/Types/DecimalType.cs
  26. +42 −0 src/Types/DecimalTypeConverter.cs
  27. +96 −0 src/Types/DoubleType.cs
  28. +42 −0 src/Types/DoubleTypeConverter.cs
  29. +2 −2 src/Types/DynamicCompositeType.cs
  30. +1 −1 src/Types/DynamicCompositeTypeConverter.cs
  31. +96 −0 src/Types/FloatType.cs
  32. +42 −0 src/Types/FloatTypeConverter.cs
  33. +96 −0 src/Types/Int32Type.cs
  34. +42 −0 src/Types/Int32TypeConverter.cs
  35. +3 −1 test/FluentCassandra.Tests/Linq/LinqToCassandraTests.cs
  36. +0 −6 utility/FluentCassandra.LinqPad/App.xaml
  37. +0 −30 utility/FluentCassandra.LinqPad/CassandraConectionDialog.xaml.cs
  38. +6 −43 utility/FluentCassandra.LinqPad/CassandraConnectionInfo.cs
  39. +44 −0 utility/FluentCassandra.LinqPad/CassandraContext.cs
  40. +0 −102 utility/FluentCassandra.LinqPad/CassandraDriver.cs
  41. +0 −78 utility/FluentCassandra.LinqPad/CassandraDriverContext.cs
  42. +117 −0 utility/FluentCassandra.LinqPad/CassandraStaticDriver.cs
  43. +17 −17 utility/FluentCassandra.LinqPad/{CassandraConectionDialog.xaml → ConnectionDialog.xaml}
  44. +34 −0 utility/FluentCassandra.LinqPad/ConnectionDialog.xaml.cs
  45. +1 −1 utility/FluentCassandra.LinqPad/DevDeploy.bat
  46. +19 −35 utility/FluentCassandra.LinqPad/FluentCassandra.LinqPad.csproj
  47. BIN utility/FluentCassandra.LinqPad/FluentCassandra.snk
  48. +1 −0 utility/FluentCassandra.LinqPad/README.txt
  49. +0 −125 utility/FluentCassandra.LinqPad/RavenLinqpadDriver.csproj
  50. +0 −13 utility/FluentCassandra.LinqPad/Utility.cs
  51. +0 −34 utility/FluentCassandra.LinqPad/ViewModel/MainViewModel.cs
  52. +0 −58 utility/FluentCassandra.LinqPad/ViewModel/ViewModelLocator.cs
  53. +48 −0 utility/FluentCassandra.LinqPad/package for release.linq
  54. +0 −4 utility/FluentCassandra.LinqPad/packages.config
View
BIN lib/Ionic.Zip.dll
Binary file not shown.
View
BIN lib/Ionic.Zip.shadow
Binary file not shown.
View
BIN lib/LINQPad.exe
Binary file not shown.
View
4 src/Connections/ConnectionBuilder.cs
@@ -319,11 +319,11 @@ private string GetConnectionString()
b.AppendFormat(format, "Keyspace", Keyspace);
b.AppendFormat(format, "Server", String.Join(",", Servers));
- b.AppendFormat(format, "Connection Timeout", ConnectionTimeout);
+ b.AppendFormat(format, "Connection Timeout", Convert.ToInt32(ConnectionTimeout.TotalSeconds));
b.AppendFormat(format, "Pooling", Pooling);
b.AppendFormat(format, "Min Pool Size", MinPoolSize);
b.AppendFormat(format, "Max Pool Size", MaxPoolSize);
- b.AppendFormat(format, "Connection Lifetime", ConnectionLifetime);
+ b.AppendFormat(format, "Connection Lifetime", Convert.ToInt32(ConnectionLifetime.TotalSeconds));
b.AppendFormat(format, "Connection Type", ConnectionType);
b.AppendFormat(format, "Buffer Size", BufferSize);
View
19 src/FluentCassandra.csproj
@@ -39,6 +39,12 @@
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
+ <PropertyGroup>
+ <SignAssembly>true</SignAssembly>
+ </PropertyGroup>
+ <PropertyGroup>
+ <AssemblyOriginatorKeyFile>FluentCassandra.snk</AssemblyOriginatorKeyFile>
+ </PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
@@ -258,6 +264,18 @@
</Compile>
<Compile Include="Types\CompositeTypeConverter.cs" />
<Compile Include="Types\CompositeType`1.cs" />
+ <Compile Include="Types\BooleanType.cs" />
+ <Compile Include="Types\BooleanTypeConverter.cs" />
+ <Compile Include="Types\DateType.cs" />
+ <Compile Include="Types\DateTypeConverter.cs" />
+ <Compile Include="Types\Int32Type.cs" />
+ <Compile Include="Types\Int32TypeConverter.cs" />
+ <Compile Include="Types\FloatType.cs" />
+ <Compile Include="Types\FloatTypeConverter.cs" />
+ <Compile Include="Types\DoubleType.cs" />
+ <Compile Include="Types\DoubleTypeConverter.cs" />
+ <Compile Include="Types\DecimalType.cs" />
+ <Compile Include="Types\DecimalTypeConverter.cs" />
<Compile Include="Types\DynamicCompositeType.cs" />
<Compile Include="Types\DynamicCompositeTypeConverter.cs" />
<Compile Include="Types\CassandraTypeExtensions.cs" />
@@ -287,6 +305,7 @@
<None Include="FluentCassandra.nuspec">
<SubType>Designer</SubType>
</None>
+ <None Include="FluentCassandra.snk" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
View
BIN src/FluentCassandra.snk
Binary file not shown.
View
29 src/FluentColumn.cs
@@ -19,6 +19,7 @@ public FluentColumn()
{
ColumnTimestamp = DateTimeOffset.UtcNow;
ColumnSecondsUntilDeleted = null;
+ ColumnTimeUntilDeleted = null;
}
/// <summary>
@@ -72,14 +73,38 @@ internal set
get { return _ttl; }
set
{
- if (value.HasValue && value <= 0)
- throw new CassandraException("ColumnSecondsUntilDeleted needs to be set to a postive value that is greater than zero");
+ if (value.HasValue && value < 1)
+ throw new CassandraException("ColumnSecondsUntilDeleted needs to be set to a postive value that is greater than zero.");
_ttl = value;
}
}
/// <summary>
+ ///
+ /// </summary>
+ public TimeSpan? ColumnTimeUntilDeleted
+ {
+ get
+ {
+ if (ColumnSecondsUntilDeleted.HasValue)
+ return TimeSpan.FromSeconds(ColumnSecondsUntilDeleted.Value);
+
+ return null;
+ }
+ set
+ {
+ if (value.HasValue && value.Value < TimeSpan.FromSeconds(1))
+ throw new CassandraException("ColumnTimeUntilDeleted needs to be set to a postive TimeSpan that is greater than or equal to 1 second.");
+
+ if (value.HasValue)
+ ColumnSecondsUntilDeleted = Convert.ToInt32(value.Value.TotalSeconds);
+
+ ColumnSecondsUntilDeleted = null;
+ }
+ }
+
+ /// <summary>
/// Gets the path.
/// </summary>
/// <returns></returns>
View
4 src/FluentColumnFamily.cs
@@ -150,15 +150,15 @@ public override bool TrySetColumn(object name, object value)
mutationType = MutationType.Added;
col = new FluentColumn<CompareWith>();
- ((FluentColumn<CompareWith>)col).ColumnName = CassandraType.GetType<CompareWith>(name);
+ ((FluentColumn<CompareWith>)col).ColumnName = CassandraType.GetTypeFromObject<CompareWith>(name);
_columns.SupressChangeNotification = true;
_columns.Add(col);
_columns.SupressChangeNotification = false;
}
// set the column value
- col.ColumnValue = CassandraType.GetType<BytesType>(value);
+ col.ColumnValue = CassandraType.GetTypeFromObject<BytesType>(value);
// notify the tracker that the column has changed
OnColumnMutated(mutationType, col);
View
4 src/FluentSuperColumn.cs
@@ -143,15 +143,15 @@ public override bool TrySetColumn(object name, object value)
mutationType = MutationType.Added;
col = new FluentColumn<CompareSubcolumnWith>();
- ((FluentColumn<CompareSubcolumnWith>)col).ColumnName = CassandraType.GetType<CompareSubcolumnWith>(name);
+ ((FluentColumn<CompareSubcolumnWith>)col).ColumnName = CassandraType.GetTypeFromObject<CompareSubcolumnWith>(name);
_columns.SupressChangeNotification = true;
_columns.Add(col);
_columns.SupressChangeNotification = false;
}
// set the column value
- col.ColumnValue = CassandraType.GetType<BytesType>(value);
+ col.ColumnValue = CassandraType.GetTypeFromObject<BytesType>(value);
// notify the tracker that the column has changed
OnColumnMutated(mutationType, col);
View
4 src/FluentSuperColumnFamily.cs
@@ -109,7 +109,7 @@ public FluentColumnParent GetSelf()
public override bool TryGetColumn(object name, out object result)
{
var col = Columns.FirstOrDefault(c => c.ColumnName == name);
- result = (col == null) ? CreateSuperColumn(CassandraType.GetType<CompareWith>(name)) : col;
+ result = (col == null) ? CreateSuperColumn(CassandraType.GetTypeFromObject<CompareWith>(name)) : col;
return true;
}
@@ -129,7 +129,7 @@ public override bool TrySetColumn(object name, object value)
var mutationType = col == null ? MutationType.Added : MutationType.Changed;
col = (FluentSuperColumn<CompareWith, CompareSubcolumnWith>)value;
- ((FluentSuperColumn<CompareWith, CompareSubcolumnWith>)col).ColumnName = CassandraType.GetType<CompareWith>(name);
+ ((FluentSuperColumn<CompareWith, CompareSubcolumnWith>)col).ColumnName = CassandraType.GetTypeFromObject<CompareWith>(name);
int index = Columns.IndexOf(col);
View
2 src/Operations/CassandraIndexClauseBuilder.cs
@@ -118,7 +118,7 @@ private static Cassandra.IndexExpression VisitRelationalExpression(BinaryExpress
Cassandra.IndexExpression indexExpression;
var columnName = GetColumnName(exp.Left);
- var value = CassandraType.GetType<BytesType>(Expression.Lambda(exp.Right).Compile().DynamicInvoke());
+ var value = CassandraType.GetTypeFromObject<BytesType>(Expression.Lambda(exp.Right).Compile().DynamicInvoke());
indexExpression = new Cassandra.IndexExpression {
Column_name = columnName,
View
2 src/Operations/ExecuteCqlQuery.cs
@@ -53,7 +53,7 @@ private IEnumerable<ICqlRow<CompareWith>> GetRows(Apache.Cassandra.CqlResult res
var familyName = TryGetFamilyName();
foreach (var row in result.Rows)
yield return new FluentColumnFamily<CompareWith>(
- CassandraType.FromBigEndian<BytesType>(row.Key),
+ CassandraType.GetTypeFromDatabaseValue<BytesType>(row.Key),
familyName,
GetColumns(row));
}
View
8 src/Operations/Helper.cs
@@ -110,7 +110,7 @@ public static byte[] TryToBigEndian(this CassandraType value)
public static long ToTimestamp(this DateTimeOffset dt)
{
// this was changed from .NET Ticks to the Unix Epoch to be compatible with other cassandra libraries
- return Convert.ToInt64((DateTimeOffset.UtcNow - UnixStart).TotalMilliseconds);
+ return Convert.ToInt64((dt - UnixStart).TotalMilliseconds);
}
public static IFluentBaseColumn<CompareWith> ConvertToFluentBaseColumn<CompareWith, CompareSubcolumnWith>(ColumnOrSuperColumn col)
@@ -134,8 +134,8 @@ public static FluentColumn<CompareWith> ConvertColumnToFluentColumn<CompareWith>
{
var fcol = new FluentColumn<CompareWith> {
- ColumnName = CassandraType.FromBigEndian<CompareWith>(col.Name),
- ColumnValue = CassandraType.FromBigEndian<BytesType>(col.Value),
+ ColumnName = CassandraType.GetTypeFromDatabaseValue<CompareWith>(col.Name),
+ ColumnValue = CassandraType.GetTypeFromDatabaseValue<BytesType>(col.Value),
ColumnTimestamp = new DateTimeOffset(col.Timestamp, TimeSpan.Zero),
};
@@ -150,7 +150,7 @@ public static FluentColumn<CompareWith> ConvertColumnToFluentColumn<CompareWith>
where CompareSubcolumnWith : CassandraType
{
var superCol = new FluentSuperColumn<CompareWith, CompareSubcolumnWith> {
- ColumnName = CassandraType.FromBigEndian<CompareWith>(col.Name)
+ ColumnName = CassandraType.GetTypeFromDatabaseValue<CompareWith>(col.Name)
};
foreach (var xcol in col.Columns)
View
2 src/Operations/MultiGetColumnFamilySlice.cs
@@ -35,7 +35,7 @@ public override IEnumerable<IFluentColumnFamily<CompareWith>> Execute()
foreach (var result in output)
{
- var key = CassandraType.FromBigEndian<BytesType>(result.Key);
+ var key = CassandraType.GetTypeFromDatabaseValue<BytesType>(result.Key);
var r = new FluentColumnFamily<CompareWith>(key, ColumnFamily.FamilyName, result.Value.Select(col => {
return Helper.ConvertColumnToFluentColumn<CompareWith>(col.Column);
View
2 src/Operations/MultiGetSuperColumnFamilySlice.cs
@@ -36,7 +36,7 @@ public class MultiGetSuperColumnFamilySlice<CompareWith, CompareSubcolumnWith> :
foreach (var result in output)
{
- var key = CassandraType.FromBigEndian<BytesType>(result.Key);
+ var key = CassandraType.GetTypeFromDatabaseValue<BytesType>(result.Key);
var superColumns = result.Value.Select(col => {
var superCol = Helper.ConvertSuperColumnToFluentSuperColumn<CompareWith, CompareSubcolumnWith>(col.Super_column);
View
96 src/Types/BooleanType.cs
@@ -0,0 +1,96 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ public class BooleanType : CassandraType
+ {
+ private static readonly BooleanTypeConverter Converter = new BooleanTypeConverter();
+
+ #region Implimentation
+
+ public override object GetValue(Type type)
+ {
+ return GetValue(_value, type, Converter);
+ }
+
+ public override void SetValue(object obj)
+ {
+ _value = SetValue(obj, Converter);
+ }
+
+ public override byte[] ToBigEndian()
+ {
+ return Converter.ToBigEndian(_value);
+ }
+
+ public override void SetValueFromBigEndian(byte[] value)
+ {
+ _value = Converter.FromBigEndian(value);
+ }
+
+ protected override TypeCode TypeCode
+ {
+ get { return TypeCode.String; }
+ }
+
+ public override string ToString()
+ {
+ return _value.ToString();
+ }
+
+ #endregion
+
+ private bool _value;
+
+ #region Equality
+
+ public override bool Equals(object obj)
+ {
+ if (obj is BooleanType)
+ return _value == ((BooleanType)obj)._value;
+
+ return _value == CassandraType.GetValue<bool>(obj, Converter);
+ }
+
+ public override int GetHashCode()
+ {
+ return _value.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion
+
+ public static implicit operator bool(BooleanType type)
+ {
+ return type._value;
+ }
+
+ public static implicit operator BooleanType(bool o)
+ {
+ return new BooleanType {
+ _value = o
+ };
+ }
+
+ public static implicit operator BooleanType(byte[] o) { return ConvertFrom(o); }
+ public static implicit operator byte[](BooleanType o) { return ConvertTo<byte[]>(o); }
+
+ private static T ConvertTo<T>(BooleanType type)
+ {
+ if (type == null)
+ return default(T);
+
+ return type.GetValue<T>();
+ }
+
+ private static BooleanType ConvertFrom(object o)
+ {
+ var type = new BooleanType();
+ type.SetValue(o);
+ return type;
+ }
+
+ #endregion
+ }
+}
View
42 src/Types/BooleanTypeConverter.cs
@@ -0,0 +1,42 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ internal class BooleanTypeConverter : CassandraTypeConverter<bool>
+ {
+ public override bool CanConvertFrom(Type sourceType)
+ {
+ if (Type.GetTypeCode(sourceType) != TypeCode.Object)
+ return true;
+
+ return sourceType == typeof(byte[]);
+ }
+
+ public override bool CanConvertTo(Type destinationType)
+ {
+ if (Type.GetTypeCode(destinationType) != TypeCode.Object)
+ return true;
+
+ return destinationType == typeof(byte[]);
+ }
+
+ public override bool ConvertFrom(object value)
+ {
+ if (value is byte[])
+ return ((byte[])value).FromBytes<bool>();
+
+ return (bool)Convert.ChangeType(value, typeof(bool));
+ }
+
+ public override object ConvertTo(bool value, Type destinationType)
+ {
+ if (!(value is string))
+ return null;
+
+ if (destinationType == typeof(byte[]))
+ return value.ToBytes();
+
+ return Convert.ChangeType(value, destinationType);
+ }
+ }
+}
View
51 src/Types/CassandraType.cs
@@ -12,7 +12,7 @@ public T GetValue<T>()
return (T)GetValue(typeof(T));
}
- protected object GetValue<T>(T value, Type type, CassandraTypeConverter<T> converter)
+ internal object GetValue<T>(T value, Type type, CassandraTypeConverter<T> converter)
{
if (type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
{
@@ -26,7 +26,7 @@ protected object GetValue<T>(T value, Type type, CassandraTypeConverter<T> conve
return converter.ConvertTo(value, type);
}
- protected T SetValue<T>(object obj, CassandraTypeConverter<T> converter)
+ internal T SetValue<T>(object obj, CassandraTypeConverter<T> converter)
{
if (!converter.CanConvertFrom(obj.GetType()))
throw new InvalidCastException(String.Format("{0} cannot be cast to {1}", obj.GetType(), TypeCode));
@@ -89,7 +89,6 @@ private static T Convert<T>(CassandraType type)
}
public static implicit operator byte[](CassandraType o) { return Convert<byte[]>(o); }
-
public static implicit operator char[](CassandraType o) { return Convert<char[]>(o); }
public static implicit operator byte(CassandraType o) { return Convert<byte>(o); }
@@ -167,15 +166,15 @@ object IConvertible.ToType(Type conversionType, IFormatProvider provider)
#endregion
- internal static T FromBigEndian<T>(byte[] value)
+ public static T GetTypeFromDatabaseValue<T>(byte[] value)
where T : CassandraType
{
T type = Activator.CreateInstance<T>();
type.SetValueFromBigEndian(value);
return type;
}
- internal static CassandraType FromBigEndian(byte[] value, Type cassandraType)
+ public static CassandraType GetTypeFromDatabaseValue(byte[] value, Type cassandraType)
{
CassandraType type = Activator.CreateInstance(cassandraType) as CassandraType;
@@ -186,15 +185,20 @@ internal static CassandraType FromBigEndian(byte[] value, Type cassandraType)
return type;
}
- internal static T GetType<T>(object obj)
+ public static CassandraType GetTypeFromDatabaseValue(byte[] value, string type)
+ {
+ return GetTypeFromDatabaseValue(value, GetCassandraType(type));
+ }
+
+ public static T GetTypeFromObject<T>(object obj)
where T : CassandraType
{
T type = Activator.CreateInstance<T>();
type.SetValue(obj);
return type;
}
- internal static CassandraType GetType(object obj, Type cassandraType)
+ public static CassandraType GetTypeFromObject(object obj, Type cassandraType)
{
CassandraType type = Activator.CreateInstance(cassandraType) as CassandraType;
@@ -205,6 +209,39 @@ internal static CassandraType GetType(object obj, Type cassandraType)
return type;
}
+ public static CassandraType GetTypeFromObject(object obj, string type)
+ {
+ return GetTypeFromObject(obj, GetCassandraType(type));
+ }
+
+ public static Type GetCassandraType(string type)
+ {
+ if (type == null || type.Length == 0)
+ throw new ArgumentNullException("type");
+
+ Type cassandraType;
+ switch (type.Substring(type.LastIndexOf('.') + 1).ToLower())
+ {
+ case "asciitype": cassandraType = typeof(AsciiType); break;
+ case "booleantype": cassandraType = typeof(BooleanType); break;
+ case "bytestype": cassandraType = typeof(BytesType); break;
+ case "datetype": cassandraType = typeof(DateType); break;
+ case "decimaltype": cassandraType = typeof(DecimalType); break;
+ case "doubletype": cassandraType = typeof(DoubleType); break;
+ case "floattype": cassandraType = typeof(FloatType); break;
+ case "int32type": cassandraType = typeof(Int32Type); break;
+ case "integertype": cassandraType = typeof(IntegerType); break;
+ case "lexicaluuidtype": cassandraType = typeof(LexicalUUIDType); break;
+ case "longtype": cassandraType = typeof(LongType); break;
+ case "timeuuidtype": cassandraType = typeof(TimeUUIDType); break;
+ case "utf8type": cassandraType = typeof(UTF8Type); break;
+ case "uuidtype": cassandraType = typeof(UUIDType); break;
+ default: throw new CassandraException("Type '" + type + "' not found.");
+ }
+
+ return cassandraType;
+ }
+
internal static T GetValue<T>(object obj, CassandraTypeConverter<T> converter)
{
if (obj is CassandraType)
View
2 src/Types/CassandraTypeConverter.cs
@@ -3,7 +3,7 @@
namespace FluentCassandra.Types
{
- public abstract class CassandraTypeConverter<T>
+ internal abstract class CassandraTypeConverter<T>
{
public abstract bool CanConvertFrom(Type sourceType);
View
14 src/Types/CassandraTypeExtensions.cs
@@ -7,37 +7,37 @@ public static class CassandraTypeExtensions
{
public static AsciiType ToAsciiType(this object o)
{
- return CassandraType.GetType<AsciiType>(o);
+ return CassandraType.GetTypeFromObject<AsciiType>(o);
}
public static BytesType ToBytesType(this object o)
{
- return CassandraType.GetType<BytesType>(o);
+ return CassandraType.GetTypeFromObject<BytesType>(o);
}
public static IntegerType ToIntegerType(this object o)
{
- return CassandraType.GetType<IntegerType>(o);
+ return CassandraType.GetTypeFromObject<IntegerType>(o);
}
public static LexicalUUIDType ToLexicalUUIDType(this object o)
{
- return CassandraType.GetType<LexicalUUIDType>(o);
+ return CassandraType.GetTypeFromObject<LexicalUUIDType>(o);
}
public static LongType ToLongType(this object o)
{
- return CassandraType.GetType<LongType>(o);
+ return CassandraType.GetTypeFromObject<LongType>(o);
}
public static UTF8Type ToUTF8Type(this object o)
{
- return CassandraType.GetType<UTF8Type>(o);
+ return CassandraType.GetTypeFromObject<UTF8Type>(o);
}
public static UUIDType ToUUIDType(this object o)
{
- return CassandraType.GetType<UUIDType>(o);
+ return CassandraType.GetTypeFromObject<UUIDType>(o);
}
public static void AddAscii(this DynamicCompositeType type, AsciiType value)
View
4 src/Types/CompositeType.cs
@@ -180,12 +180,12 @@ public override int GetHashCode()
public static implicit operator CompositeType(object[] s)
{
- return new CompositeType { _value = new List<CassandraType>(s.Select(o => CassandraType.GetType<BytesType>(o))) };
+ return new CompositeType { _value = new List<CassandraType>(s.Select(o => CassandraType.GetTypeFromObject<BytesType>(o))) };
}
public static implicit operator CompositeType(List<object> s)
{
- return new CompositeType { _value = new List<CassandraType>(s.Select(o => CassandraType.GetType<BytesType>(o))) };
+ return new CompositeType { _value = new List<CassandraType>(s.Select(o => CassandraType.GetTypeFromObject<BytesType>(o))) };
}
public static implicit operator byte[](CompositeType o) { return ConvertTo<byte[]>(o); }
View
2 src/Types/CompositeTypeConverter.cs
@@ -161,7 +161,7 @@ public List<CassandraType> FromBigEndian(byte[] value, List<Type> hints)
var typeHint = (hints.Count >= (hintIndex + 1)) ? hints[hintIndex++] : typeof(BytesType);
bytes.Read(buffer, 0, length);
- var component = CassandraType.FromBigEndian(buffer, typeHint);
+ var component = CassandraType.GetTypeFromDatabaseValue(buffer, typeHint);
components.Add(component);
// end of component
View
104 src/Types/DateType.cs
@@ -0,0 +1,104 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ public class DateType : CassandraType
+ {
+ private static readonly DateTypeConverter Converter = new DateTypeConverter();
+
+ #region Implimentation
+
+ public override object GetValue(Type type)
+ {
+ return GetValue(_value, type, Converter);
+ }
+
+ public override void SetValue(object obj)
+ {
+ _value = SetValue(obj, Converter);
+ }
+
+ public override byte[] ToBigEndian()
+ {
+ return Converter.ToBigEndian(_value);
+ }
+
+ public override void SetValueFromBigEndian(byte[] value)
+ {
+ _value = Converter.FromBigEndian(value);
+ }
+
+ protected override TypeCode TypeCode
+ {
+ get { return TypeCode.String; }
+ }
+
+ public override string ToString()
+ {
+ return _value.ToString();
+ }
+
+ #endregion
+
+ private DateTimeOffset _value;
+
+ #region Equality
+
+ public override bool Equals(object obj)
+ {
+ if (obj is DateType)
+ return _value == ((DateType)obj)._value;
+
+ return _value == CassandraType.GetValue<DateTimeOffset>(obj, Converter);
+ }
+
+ public override int GetHashCode()
+ {
+ return _value.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion
+
+ public static implicit operator DateTimeOffset(DateType type)
+ {
+ return type._value;
+ }
+
+ public static implicit operator DateType(DateTimeOffset o)
+ {
+ return new DateType {
+ _value = o
+ };
+ }
+
+ public static implicit operator DateType(byte[] o) { return ConvertFrom(o); }
+ public static implicit operator DateType(DateTime o) { return ConvertFrom(o); }
+ public static implicit operator DateType(long o) { return ConvertFrom(o); }
+ public static implicit operator DateType(ulong o) { return ConvertFrom(o); }
+
+ public static implicit operator byte[](DateType o) { return ConvertTo<byte[]>(o); }
+ public static implicit operator DateTime(DateType o) { return ConvertTo<DateTime>(o); }
+ public static implicit operator long(DateType o) { return ConvertTo<long>(o); }
+ public static implicit operator ulong(DateType o) { return ConvertTo<ulong>(o); }
+ public static implicit operator string(DateType o) { return ConvertTo<string>(o); }
+
+ private static T ConvertTo<T>(DateType type)
+ {
+ if (type == null)
+ return default(T);
+
+ return type.GetValue<T>();
+ }
+
+ private static DateType ConvertFrom(object o)
+ {
+ var type = new DateType();
+ type.SetValue(o);
+ return type;
+ }
+
+ #endregion
+ }
+}
View
104 src/Types/DateTypeConverter.cs
@@ -0,0 +1,104 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ internal class DateTypeConverter : CassandraTypeConverter<DateTimeOffset>
+ {
+ private static readonly DateTimeOffset UnixStart = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
+
+ public static long ToDate(DateTimeOffset dt)
+ {
+ // this was changed from .NET Ticks to the Unix Epoch to be compatible with other cassandra libraries
+ return Convert.ToInt64((dt - UnixStart).TotalMilliseconds);
+ }
+
+ public override bool CanConvertFrom(Type sourceType)
+ {
+ if (sourceType == typeof(DateTimeOffset))
+ return true;
+
+ if (sourceType == typeof(byte[]))
+ return true;
+
+ switch (Type.GetTypeCode(sourceType))
+ {
+ case TypeCode.DateTime:
+ case TypeCode.Int64:
+ case TypeCode.UInt64:
+ return true;
+
+ default:
+ return false;
+ }
+ }
+
+ public override bool CanConvertTo(Type destinationType)
+ {
+ if (destinationType == typeof(DateTimeOffset))
+ return true;
+
+ if (destinationType == typeof(byte[]))
+ return true;
+
+ switch (Type.GetTypeCode(destinationType))
+ {
+ case TypeCode.DateTime:
+ case TypeCode.Int64:
+ case TypeCode.UInt64:
+ case TypeCode.String:
+ return true;
+
+ default:
+ return false;
+ }
+ }
+
+ public override DateTimeOffset ConvertFrom(object value)
+ {
+ if (value is DateTimeOffset)
+ return (DateTimeOffset)value;
+
+ if (value is byte[])
+ return UnixStart.AddMilliseconds(((byte[])value).FromBytes<long>());
+
+ if (value is long)
+ return UnixStart.AddMilliseconds((long)value);
+
+ if (value is ulong)
+ return UnixStart.AddMilliseconds((ulong)value);
+
+ if (value is DateTime)
+ {
+ var dt = (DateTime)value;
+ var utc = dt.Kind == DateTimeKind.Utc;
+
+ return new DateTimeOffset(dt, utc ? TimeSpan.Zero : (DateTimeOffset.Now.Offset));
+ }
+
+ return default(DateTimeOffset);
+ }
+
+ public override object ConvertTo(DateTimeOffset value, Type destinationType)
+ {
+ if (destinationType == typeof(DateTimeOffset))
+ return value;
+
+ if (destinationType == typeof(byte[]))
+ return ToDate(value).ToBytes();
+
+ if (destinationType == typeof(long))
+ return ToDate(value);
+
+ if (destinationType == typeof(ulong))
+ return (ulong)ToDate(value);
+
+ if (destinationType == typeof(DateTime))
+ return value.LocalDateTime;
+
+ if (destinationType == typeof(string))
+ return value.ToString("u");
+
+ return null;
+ }
+ }
+}
View
96 src/Types/DecimalType.cs
@@ -0,0 +1,96 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ public class DecimalType : CassandraType
+ {
+ private static readonly DecimalTypeConverter Converter = new DecimalTypeConverter();
+
+ #region Implimentation
+
+ public override object GetValue(Type type)
+ {
+ return GetValue(_value, type, Converter);
+ }
+
+ public override void SetValue(object obj)
+ {
+ _value = SetValue(obj, Converter);
+ }
+
+ public override byte[] ToBigEndian()
+ {
+ return Converter.ToBigEndian(_value);
+ }
+
+ public override void SetValueFromBigEndian(byte[] value)
+ {
+ _value = Converter.FromBigEndian(value);
+ }
+
+ protected override TypeCode TypeCode
+ {
+ get { return TypeCode.String; }
+ }
+
+ public override string ToString()
+ {
+ return _value.ToString();
+ }
+
+ #endregion
+
+ private decimal _value;
+
+ #region Equality
+
+ public override bool Equals(object obj)
+ {
+ if (obj is DecimalType)
+ return _value == ((DecimalType)obj)._value;
+
+ return _value == CassandraType.GetValue<decimal>(obj, Converter);
+ }
+
+ public override int GetHashCode()
+ {
+ return _value.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion
+
+ public static implicit operator decimal(DecimalType type)
+ {
+ return type._value;
+ }
+
+ public static implicit operator DecimalType(decimal o)
+ {
+ return new DecimalType {
+ _value = o
+ };
+ }
+
+ public static implicit operator DecimalType(byte[] o) { return ConvertFrom(o); }
+ public static implicit operator byte[](DecimalType o) { return ConvertTo<byte[]>(o); }
+
+ private static T ConvertTo<T>(DecimalType type)
+ {
+ if (type == null)
+ return default(T);
+
+ return type.GetValue<T>();
+ }
+
+ private static DecimalType ConvertFrom(object o)
+ {
+ var type = new DecimalType();
+ type.SetValue(o);
+ return type;
+ }
+
+ #endregion
+ }
+}
View
42 src/Types/DecimalTypeConverter.cs
@@ -0,0 +1,42 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ internal class DecimalTypeConverter : CassandraTypeConverter<decimal>
+ {
+ public override bool CanConvertFrom(Type sourceType)
+ {
+ if (Type.GetTypeCode(sourceType) != TypeCode.Object)
+ return true;
+
+ return sourceType == typeof(byte[]);
+ }
+
+ public override bool CanConvertTo(Type destinationType)
+ {
+ if (Type.GetTypeCode(destinationType) != TypeCode.Object)
+ return true;
+
+ return destinationType == typeof(byte[]);
+ }
+
+ public override decimal ConvertFrom(object value)
+ {
+ if (value is byte[])
+ return ((byte[])value).FromBytes<decimal>();
+
+ return (decimal)Convert.ChangeType(value, typeof(decimal));
+ }
+
+ public override object ConvertTo(decimal value, Type destinationType)
+ {
+ if (!(value is string))
+ return null;
+
+ if (destinationType == typeof(byte[]))
+ return value.ToBytes();
+
+ return Convert.ChangeType(value, destinationType);
+ }
+ }
+}
View
96 src/Types/DoubleType.cs
@@ -0,0 +1,96 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ public class DoubleType : CassandraType
+ {
+ private static readonly DoubleTypeConverter Converter = new DoubleTypeConverter();
+
+ #region Implimentation
+
+ public override object GetValue(Type type)
+ {
+ return GetValue(_value, type, Converter);
+ }
+
+ public override void SetValue(object obj)
+ {
+ _value = SetValue(obj, Converter);
+ }
+
+ public override byte[] ToBigEndian()
+ {
+ return Converter.ToBigEndian(_value);
+ }
+
+ public override void SetValueFromBigEndian(byte[] value)
+ {
+ _value = Converter.FromBigEndian(value);
+ }
+
+ protected override TypeCode TypeCode
+ {
+ get { return TypeCode.String; }
+ }
+
+ public override string ToString()
+ {
+ return _value.ToString();
+ }
+
+ #endregion
+
+ private Double _value;
+
+ #region Equality
+
+ public override bool Equals(object obj)
+ {
+ if (obj is DoubleType)
+ return _value == ((DoubleType)obj)._value;
+
+ return _value == CassandraType.GetValue<Double>(obj, Converter);
+ }
+
+ public override int GetHashCode()
+ {
+ return _value.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion
+
+ public static implicit operator Double(DoubleType type)
+ {
+ return type._value;
+ }
+
+ public static implicit operator DoubleType(Double o)
+ {
+ return new DoubleType {
+ _value = o
+ };
+ }
+
+ public static implicit operator DoubleType(byte[] o) { return ConvertFrom(o); }
+ public static implicit operator byte[](DoubleType o) { return ConvertTo<byte[]>(o); }
+
+ private static T ConvertTo<T>(DoubleType type)
+ {
+ if (type == null)
+ return default(T);
+
+ return type.GetValue<T>();
+ }
+
+ private static DoubleType ConvertFrom(object o)
+ {
+ var type = new DoubleType();
+ type.SetValue(o);
+ return type;
+ }
+
+ #endregion
+ }
+}
View
42 src/Types/DoubleTypeConverter.cs
@@ -0,0 +1,42 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ internal class DoubleTypeConverter : CassandraTypeConverter<Double>
+ {
+ public override bool CanConvertFrom(Type sourceType)
+ {
+ if (Type.GetTypeCode(sourceType) != TypeCode.Object)
+ return true;
+
+ return sourceType == typeof(byte[]);
+ }
+
+ public override bool CanConvertTo(Type destinationType)
+ {
+ if (Type.GetTypeCode(destinationType) != TypeCode.Object)
+ return true;
+
+ return destinationType == typeof(byte[]);
+ }
+
+ public override Double ConvertFrom(object value)
+ {
+ if (value is byte[])
+ return ((byte[])value).FromBytes<Double>();
+
+ return (Double)Convert.ChangeType(value, typeof(Double));
+ }
+
+ public override object ConvertTo(Double value, Type destinationType)
+ {
+ if (!(value is string))
+ return null;
+
+ if (destinationType == typeof(byte[]))
+ return value.ToBytes();
+
+ return Convert.ChangeType(value, destinationType);
+ }
+ }
+}
View
4 src/Types/DynamicCompositeType.cs
@@ -123,12 +123,12 @@ public override int GetHashCode()
public static implicit operator DynamicCompositeType(object[] s)
{
- return new DynamicCompositeType { _value = new List<CassandraType>(s.Select(o => CassandraType.GetType<BytesType>(o))) };
+ return new DynamicCompositeType { _value = new List<CassandraType>(s.Select(o => CassandraType.GetTypeFromObject<BytesType>(o))) };
}
public static implicit operator DynamicCompositeType(List<object> s)
{
- return new DynamicCompositeType { _value = new List<CassandraType>(s.Select(o => CassandraType.GetType<BytesType>(o))) };
+ return new DynamicCompositeType { _value = new List<CassandraType>(s.Select(o => CassandraType.GetTypeFromObject<BytesType>(o))) };
}
public static implicit operator byte[](DynamicCompositeType o) { return ConvertTo<byte[]>(o); }
View
2 src/Types/DynamicCompositeTypeConverter.cs
@@ -50,7 +50,7 @@ public override List<CassandraType> ConvertFrom(object value)
var buffer = new byte[length];
bytes.Read(buffer, 0, length);
- components.Add(CassandraType.GetType(buffer, type));
+ components.Add(CassandraType.GetTypeFromObject(buffer, type));
// end of component
if (bytes.ReadByte() != 0)
View
96 src/Types/FloatType.cs
@@ -0,0 +1,96 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ public class FloatType : CassandraType
+ {
+ private static readonly FloatTypeConverter Converter = new FloatTypeConverter();
+
+ #region Implimentation
+
+ public override object GetValue(Type type)
+ {
+ return GetValue(_value, type, Converter);
+ }
+
+ public override void SetValue(object obj)
+ {
+ _value = SetValue(obj, Converter);
+ }
+
+ public override byte[] ToBigEndian()
+ {
+ return Converter.ToBigEndian(_value);
+ }
+
+ public override void SetValueFromBigEndian(byte[] value)
+ {
+ _value = Converter.FromBigEndian(value);
+ }
+
+ protected override TypeCode TypeCode
+ {
+ get { return TypeCode.String; }
+ }
+
+ public override string ToString()
+ {
+ return _value.ToString();
+ }
+
+ #endregion
+
+ private float _value;
+
+ #region Equality
+
+ public override bool Equals(object obj)
+ {
+ if (obj is FloatType)
+ return _value == ((FloatType)obj)._value;
+
+ return _value == CassandraType.GetValue<float>(obj, Converter);
+ }
+
+ public override int GetHashCode()
+ {
+ return _value.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion
+
+ public static implicit operator float(FloatType type)
+ {
+ return type._value;
+ }
+
+ public static implicit operator FloatType(float o)
+ {
+ return new FloatType {
+ _value = o
+ };
+ }
+
+ public static implicit operator FloatType(byte[] o) { return ConvertFrom(o); }
+ public static implicit operator byte[](FloatType o) { return ConvertTo<byte[]>(o); }
+
+ private static T ConvertTo<T>(FloatType type)
+ {
+ if (type == null)
+ return default(T);
+
+ return type.GetValue<T>();
+ }
+
+ private static FloatType ConvertFrom(object o)
+ {
+ var type = new FloatType();
+ type.SetValue(o);
+ return type;
+ }
+
+ #endregion
+ }
+}
View
42 src/Types/FloatTypeConverter.cs
@@ -0,0 +1,42 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ internal class FloatTypeConverter : CassandraTypeConverter<float>
+ {
+ public override bool CanConvertFrom(Type sourceType)
+ {
+ if (Type.GetTypeCode(sourceType) != TypeCode.Object)
+ return true;
+
+ return sourceType == typeof(byte[]);
+ }
+
+ public override bool CanConvertTo(Type destinationType)
+ {
+ if (Type.GetTypeCode(destinationType) != TypeCode.Object)
+ return true;
+
+ return destinationType == typeof(byte[]);
+ }
+
+ public override float ConvertFrom(object value)
+ {
+ if (value is byte[])
+ return ((byte[])value).FromBytes<float>();
+
+ return (float)Convert.ChangeType(value, typeof(float));
+ }
+
+ public override object ConvertTo(float value, Type destinationType)
+ {
+ if (!(value is string))
+ return null;
+
+ if (destinationType == typeof(byte[]))
+ return value.ToBytes();
+
+ return Convert.ChangeType(value, destinationType);
+ }
+ }
+}
View
96 src/Types/Int32Type.cs
@@ -0,0 +1,96 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ public class Int32Type : CassandraType
+ {
+ private static readonly Int32TypeConverter Converter = new Int32TypeConverter();
+
+ #region Implimentation
+
+ public override object GetValue(Type type)
+ {
+ return GetValue(_value, type, Converter);
+ }
+
+ public override void SetValue(object obj)
+ {
+ _value = SetValue(obj, Converter);
+ }
+
+ public override byte[] ToBigEndian()
+ {
+ return Converter.ToBigEndian(_value);
+ }
+
+ public override void SetValueFromBigEndian(byte[] value)
+ {
+ _value = Converter.FromBigEndian(value);
+ }
+
+ protected override TypeCode TypeCode
+ {
+ get { return TypeCode.String; }
+ }
+
+ public override string ToString()
+ {
+ return _value.ToString();
+ }
+
+ #endregion
+
+ private Int32 _value;
+
+ #region Equality
+
+ public override bool Equals(object obj)
+ {
+ if (obj is Int32Type)
+ return _value == ((Int32Type)obj)._value;
+
+ return _value == CassandraType.GetValue<Int32>(obj, Converter);
+ }
+
+ public override int GetHashCode()
+ {
+ return _value.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion
+
+ public static implicit operator Int32(Int32Type type)
+ {
+ return type._value;
+ }
+
+ public static implicit operator Int32Type(Int32 o)
+ {
+ return new Int32Type {
+ _value = o
+ };
+ }
+
+ public static implicit operator Int32Type(byte[] o) { return ConvertFrom(o); }
+ public static implicit operator byte[](Int32Type o) { return ConvertTo<byte[]>(o); }
+
+ private static T ConvertTo<T>(Int32Type type)
+ {
+ if (type == null)
+ return default(T);
+
+ return type.GetValue<T>();
+ }
+
+ private static Int32Type ConvertFrom(object o)
+ {
+ var type = new Int32Type();
+ type.SetValue(o);
+ return type;
+ }
+
+ #endregion
+ }
+}
View
42 src/Types/Int32TypeConverter.cs
@@ -0,0 +1,42 @@
+using System;
+
+namespace FluentCassandra.Types
+{
+ internal class Int32TypeConverter : CassandraTypeConverter<Int32>
+ {
+ public override bool CanConvertFrom(Type sourceType)
+ {
+ if (Type.GetTypeCode(sourceType) != TypeCode.Object)
+ return true;
+
+ return sourceType == typeof(byte[]);
+ }
+
+ public override bool CanConvertTo(Type destinationType)
+ {
+ if (Type.GetTypeCode(destinationType) != TypeCode.Object)
+ return true;
+
+ return destinationType == typeof(byte[]);
+ }
+
+ public override Int32 ConvertFrom(object value)
+ {
+ if (value is byte[])
+ return ((byte[])value).FromBytes<Int32>();
+
+ return (Int32)Convert.ChangeType(value, typeof(Int32));
+ }
+
+ public override object ConvertTo(Int32 value, Type destinationType)
+ {
+ if (!(value is string))
+ return null;
+
+ if (destinationType == typeof(byte[]))
+ return value.ToBytes();
+
+ return Convert.ChangeType(value, destinationType);
+ }
+ }
+}
View
4 test/FluentCassandra.Tests/Linq/LinqToCassandraTests.cs
@@ -19,13 +19,15 @@ public void TestInit()
var keyspaceName = "Testing";
var server = new Server("localhost");
+ try { CassandraSession.DropKeyspace(server, keyspaceName); }
+ catch { }
+
var keyspace = new CassandraKeyspace(keyspaceName);
keyspace.TryCreateSelf(server);
_db = new CassandraContext(keyspace: keyspaceName, server: server);
_db.ThrowErrors = true;
- _db.ExecuteNonQuery(@"DROP COLUMNFAMILY Users;");
_db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Users (
KEY int PRIMARY KEY,
View
6 utility/FluentCassandra.LinqPad/App.xaml
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="FluentCassandra.LinqPad.App" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:vm="clr-namespace:FluentCassandra.LinqPad.ViewModel">
- <Application.Resources>
- <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
- </Application.Resources>
-</Application>
View
30 utility/FluentCassandra.LinqPad/CassandraConectionDialog.xaml.cs
@@ -1,30 +0,0 @@
-using System;
-using System.Windows;
-
-namespace FluentCassandra.LinqPad
-{
- public partial class CassandraConectionDialog : Window
- {
- private CassandraConnectionInfo _connInfo;
-
- public CassandraConectionDialog(CassandraConnectionInfo conn)
- {
- if (conn == null)
- throw new ArgumentNullException("conn", "conn is null.");
-
- InitializeComponent();
-
- DataContext = _connInfo = conn;
- PasswordValue.Password = conn.Password;
- }
- private void OkButton_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = true;
- }
-
- private void PasswordValue_PasswordChanged(object sender, RoutedEventArgs e)
- {
- _connInfo.Password = PasswordValue.Password;
- }
- }
-}
View
49 utility/FluentCassandra.LinqPad/CassandraConnectionInfo.cs
@@ -1,27 +1,18 @@
using System;
-using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
-using System.IO;
using System.Linq;
-using System.Net;
-using System.Reflection;
using System.Xml.Linq;
-using GalaSoft.MvvmLight;
-using GalaSoft.MvvmLight.Command;
-using LINQPad.Extensibility.DataContext;
using FluentCassandra.Connections;
+using LINQPad.Extensibility.DataContext;
namespace FluentCassandra.LinqPad
{
- public class CassandraConnectionInfo : ViewModelBase
+ public class CassandraConnectionInfo
{
public const string CassandraConnectionInfoKey = "CassandraConnectionInfo";
public IConnectionInfo ConntectionInfo { get; set; }
- public RelayCommand SaveCommand { get; set; }
-
- public const string HostPropertyName = "Host";
private string _host = "127.0.0.1";
[Required]
public string Host
@@ -39,12 +30,9 @@ public string Host
}
_host = value;
-
- RaisePropertyChanged(HostPropertyName);
}
}
- public const string PortPropertyName = "Port";
private int _port = Server.DefaultPort;
[Required]
public int Port
@@ -62,12 +50,9 @@ public int Port
}
_port = value;
-
- RaisePropertyChanged(PortPropertyName);
}
}
- public const string TimeoutPropertyName = "Timeout";
private int _timeout = Server.DefaultTimeout;
public int Timeout
{
@@ -83,12 +68,9 @@ public int Timeout
return;
}
_timeout = value;
-
- RaisePropertyChanged(TimeoutPropertyName);
}
}
- public const string KeyspacePropertyName = "Keyspace";
private string _keyspace = null;
public string Keyspace
{
@@ -105,12 +87,9 @@ public string Keyspace
}
_keyspace = value;
-
- RaisePropertyChanged(KeyspacePropertyName);
}
}
- public const string UsernamePropertyName = "Username";
private string _username = null;
public string Username
{
@@ -127,12 +106,9 @@ public string Username
}
_username = value;
-
- RaisePropertyChanged(UsernamePropertyName);
}
}
- public const string PasswordPropertyName = "Password";
private string _password = null;
public string Password
{
@@ -147,22 +123,11 @@ public string Password
return;
_password = value;
-
- RaisePropertyChanged(PasswordPropertyName);
}
}
- public CassandraConnectionInfo()
- {
- SaveCommand = new RelayCommand(Save, CanSave);
- }
-
public void Save()
{
- string pw = Password;
- if (!Password.IsNullOrWhitespace())
- Password = ConntectionInfo.Encrypt(Password);
-
var builder = new ConnectionBuilder(
keyspace: Keyspace,
host: Host,
@@ -172,19 +137,17 @@ public void Save()
password: Password);
ConntectionInfo.DriverData.SetElementValue(CassandraConnectionInfoKey, builder.ConnectionString);
-
- Password = pw;
}
public bool CanSave()
{
- return !Host.IsNullOrWhitespace()
- && !Keyspace.IsNullOrWhitespace();
+ return !String.IsNullOrWhiteSpace(Host)
+ && !String.IsNullOrWhiteSpace(Keyspace);
}
- public CassandraContext CreateContext()
+ public FluentCassandra.CassandraContext CreateContext()
{
- return new CassandraContext(
+ return new FluentCassandra.CassandraContext(
keyspace: Keyspace,
host: Host,
port: Port,
View
44 utility/FluentCassandra.LinqPad/CassandraContext.cs
@@ -0,0 +1,44 @@
+using System;
+using System.IO;
+using System.Linq;
+
+namespace FluentCassandra.LinqPad
+{
+ public class CassandraContext : IDisposable
+ {
+ public FluentCassandra.CassandraContext Context { get; private set; }
+ public FluentCassandra.CassandraSession Session { get; private set; }
+ internal TextWriter LogWriter { get; set; }
+
+ public CassandraContext(CassandraConnectionInfo connInfo)
+ {
+ if (connInfo == null)
+ throw new ArgumentNullException("conn", "conn is null.");
+
+ InitContext(connInfo);
+ InitSession();
+ }
+
+ private void InitContext(CassandraConnectionInfo conn)
+ {
+ if (conn == null)
+ throw new ArgumentNullException("conn", "conn is null.");
+
+ Context = conn.CreateContext();
+ }
+
+ private void InitSession()
+ {
+ Session = new CassandraSession(FluentCassandra.CassandraContext.CurrentConnectionBuilder);
+ }
+
+ public void Dispose()
+ {
+ if (Session != null)
+ Session.Dispose();
+
+ if (Context != null && !Context.WasDisposed)
+ Context.Dispose();
+ }
+ }
+}
View
102 utility/FluentCassandra.LinqPad/CassandraDriver.cs
@@ -1,102 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using LINQPad.Extensibility.DataContext;
-
-namespace FluentCassandra.LinqPad
-{
- /// <seealso href="https://github.com/ronnieoverby/RavenDB-Linqpad-Driver">Inspired by RavenDB LINQPad Driver</seealso>
- public class CassandraDriver : StaticDataContextDriver
- {
- CassandraConnectionInfo _connInfo;
-
- public override string Author
- {
- get { return "Nick Berardi"; }
- }
-
- public override string GetConnectionDescription(IConnectionInfo cxInfo)
- {
- _connInfo = CassandraConnectionInfo.Load(cxInfo);
- return string.Format("Cassandra: {0}", _connInfo.Host);
- }
-
- public override string Name
- {
- get { return "Cassandra Driver"; }
- }
-
- public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection)
- {
- CassandraConnectionInfo conn;
- conn = isNewConnection
- ? new CassandraConnectionInfo { ConntectionInfo = cxInfo }
- : CassandraConnectionInfo.Load(cxInfo);
-
- var win = new CassandraConectionDialog(conn);
- var result = win.ShowDialog() == true;
-
- if (result)
- {
- conn.Save();
- cxInfo.CustomTypeInfo.CustomAssemblyPath = Assembly.GetAssembly(typeof(CassandraDriverContext)).Location;
- cxInfo.CustomTypeInfo.CustomTypeName = "FluentCassandra.LinqPad.CassandraContext";
- }
-
- return result;
- }
-
- public override ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo cxInfo)
- {
- return new[] { new ParameterDescriptor("connInfo", "FluentCassandra.LinqPad.CassandraConnectionInfo") };
- }
-
- public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo)
- {
- CassandraConnectionInfo connInfo = CassandraConnectionInfo.Load(cxInfo);
- return new[] { connInfo };
- }
-
- public override IEnumerable<string> GetAssembliesToAdd()
- {
- return new[] {
- "FluentCassandra"
- };
- }
-
- public override IEnumerable<string> GetNamespacesToRemove()
- {
- // linqpad uses System.Data.Linq by default, which isn't needed
- return new[] { "System.Data.Linq" };
- }
-
- public override IEnumerable<string> GetNamespacesToAdd()
- {
- return base.GetNamespacesToAdd().Union(new[] {
- "FluentCassandra",
- "FluentCassandra.Types",
- "FluentCassandra.Connections"
- });
- }
-
- public override List<ExplorerItem> GetSchema(IConnectionInfo cxInfo, Type customType)
- {
- return new List<ExplorerItem>();
- }
-
- public override void InitializeContext(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager)
- {
- var rc = context as CassandraDriverContext;
- rc.LogWriter = executionManager.SqlTranslationWriter;
- }
-
- public override void TearDownContext(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager, object[] constructorArguments)
- {
- base.TearDownContext(cxInfo, context, executionManager, constructorArguments);
- var rc = context as CassandraDriverContext;
- if (rc != null)
- rc.Dispose();
- }
- }
-}
View
78 utility/FluentCassandra.LinqPad/CassandraDriverContext.cs
@@ -1,78 +0,0 @@
-using System;
-using System.IO;
-using System.Linq;
-
-namespace FluentCassandra.LinqPad
-{
- public class CassandraDriverContext : IDisposable
- {
- public CassandraContext Context { get; private set; }
- public CassandraSession Session { get; private set; }
- internal TextWriter LogWriter { get; set; }
-
- public CassandraDriverContext(CassandraConnectionInfo connInfo)
- {
- if (connInfo == null)
- throw new ArgumentNullException("conn", "conn is null.");
-
- InitContext(connInfo);
- SetupLogWriting();
- InitSession();
- }
-
- private void SetupLogWriting()
- {
-// // The following code is evil
-// // DocumentStore: private HttpJsonRequestFactory jsonRequestFactory;
-// var type = typeof(DocumentStore);
-// var field = type.GetField("jsonRequestFactory", BindingFlags.NonPublic | BindingFlags.Instance);
-// var jrf = (HttpJsonRequestFactory)field.GetValue(Context);
-// jrf.LogRequest += new EventHandler<RequestResultArgs>(LogRequest);
-// }
-
-// void LogRequest(object sender, RequestResultArgs e)
-// {
-// if (LogWriter == null) return;
-
-// LogWriter.WriteLine(string.Format(@"
-//{0} - {1}
-//Url: {2}
-//Duration: {3} milliseconds
-//Method: {4}
-//Posted Data: {5}
-//Http Result: {6}
-//Result Data: {7}
-//",
-// e.At, // 0
-// e.Status, // 1
-// e.Url, // 2
-// e.DurationMilliseconds, // 3
-// e.Method, // 4
-// e.PostedData, // 5
-// e.HttpResult, // 6
-// e.Result)); // 7
- }
-
- private void InitContext(CassandraConnectionInfo conn)
- {
- if (conn == null)
- throw new ArgumentNullException("conn", "conn is null.");
-
- Context = conn.CreateContext();
- }
-
- private void InitSession()
- {
- Session = new CassandraSession();
- }
-
- public void Dispose()
- {
- if (Session != null)
- Session.Dispose();
-
- if (Context != null && !Context.WasDisposed)
- Context.Dispose();
- }
- }
-}
View
117 utility/FluentCassandra.LinqPad/CassandraStaticDriver.cs
@@ -0,0 +1,117 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using FluentCassandra.Types;
+using LINQPad.Extensibility.DataContext;
+using FluentCassandra.Connections;
+
+namespace FluentCassandra.LinqPad
+{
+ /// <summary>
+ /// This static driver let users query any data source that looks like a Data Context - in other words,
+ /// that exposes properties of type IEnumerable of T.
+ /// </summary>
+ public class CassandraStaticDriver : StaticDataContextDriver
+ {
+ public override string Name { get { return "Cassandra"; } }
+
+ public override string Author { get { return "Nick Berardi"; } }
+
+ /// <summary>Returns the text to display in the root Schema Explorer node for a given connection info.</summary>
+ public override string GetConnectionDescription(IConnectionInfo cxInfo)
+ {
+ var connInfo = CassandraConnectionInfo.Load(cxInfo);
+ return String.Format("{0}/{1} - {2}", connInfo.Host, connInfo.Port, connInfo.Keyspace);
+ }
+
+ /// <summary>Displays a dialog prompting the user for connection details. The isNewConnection
+ /// parameter will be true if the user is creating a new connection rather than editing an
+ /// existing connection. This should return true if the user clicked OK. If it returns false,
+ /// any changes to the IConnectionInfo object will be rolled back.</summary>
+ public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection)
+ {
+ CassandraConnectionInfo conn;
+ conn = isNewConnection
+ ? new CassandraConnectionInfo { ConntectionInfo = cxInfo }
+ : CassandraConnectionInfo.Load(cxInfo);
+
+ var win = new ConnectionDialog(conn);
+ var result = win.ShowDialog() == true;
+
+ if (result)
+ {
+ conn.Save();
+ cxInfo.CustomTypeInfo.CustomAssemblyPath = Assembly.GetAssembly(typeof(CassandraContext)).Location;
+ cxInfo.CustomTypeInfo.CustomTypeName = "FluentCassandra.LinqPad.CassandraContext";
+ }
+
+ return result;
+ }
+
+ public override void InitializeContext(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager)
+ {
+ base.InitializeContext(cxInfo, context, executionManager);
+ }
+
+ public override ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo cxInfo)
+ {
+ return new[] { new ParameterDescriptor("connInfo", "FluentCassandra.LinqPad.CassandraConnectionInfo") };
+ }
+
+ public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo)
+ {
+ CassandraConnectionInfo connInfo = CassandraConnectionInfo.Load(cxInfo);
+ return new[] { connInfo };
+ }
+
+ public override IEnumerable<string> GetAssembliesToAdd()
+ {
+ return new[] {
+ "FluentCassandra"
+ };
+ }
+
+ public override IEnumerable<string> GetNamespacesToRemove()
+ {
+ // linqpad uses System.Data.Linq by default, which isn't needed
+ return new[] { "System.Data.Linq" };
+ }
+
+ public override IEnumerable<string> GetNamespacesToAdd()
+ {
+ return base.GetNamespacesToAdd().Union(new[] {
+ "FluentCassandra",
+ "FluentCassandra.Types",
+ "FluentCassandra.Connections"
+ });
+ }
+
+ public override List<ExplorerItem> GetSchema(IConnectionInfo cxInfo, Type customType)
+ {
+ var connInfo = CassandraConnectionInfo.Load(cxInfo);
+ var server = new Server(connInfo.Host, connInfo.Port, connInfo.Timeout);
+ var keyspace = new CassandraKeyspace(connInfo.Keyspace);
+
+ var description = keyspace.Describe(server);
+ var families = new List<ExplorerItem>();
+
+ foreach (var familyDef in description.Cf_defs)
+ {
+ var family = new ExplorerItem(familyDef.Name, ExplorerItemKind.QueryableObject, ExplorerIcon.Table);
+ family.Children = new List<ExplorerItem>();
+ family.Children.Add(new ExplorerItem("Key", ExplorerItemKind.Property, ExplorerIcon.Key));
+
+ foreach (var colDef in familyDef.Column_metadata)
+ {
+ var col = new ExplorerItem(CassandraType.GetTypeFromDatabaseValue(colDef.Name, colDef.Validation_class).GetValue<string>(), ExplorerItemKind.Property, ExplorerIcon.Column);
+ family.Children.Add(col);
+ }
+
+ families.Add(family);
+ }
+
+ return families;
+ }
+ }
+}
View
34 ...dra.LinqPad/CassandraConectionDialog.xaml → ...ntCassandra.LinqPad/ConnectionDialog.xaml
@@ -1,11 +1,11 @@
-<Window x:Class="FluentCassandra.LinqPad.CassandraConectionDialog"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:local="clr-namespace:FluentCassandra.LinqPad"
- mc:Ignorable="d" Title="Cassandra Connection" Height="345" Width="574">
-
+<Window x:Class="FluentCassandra.LinqPad.ConnectionDialog"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ Title="Cassandra Connection"
+ Background="{x:Static SystemColors.ControlBrush}"
+ SizeToContent="Height"
+ Width="336"
+ WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
@@ -16,30 +16,30 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
-
+
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="281*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Text="Keyspace *" Margin="6" VerticalAlignment="Center" />
- <TextBox Grid.Row="0" Grid.Column="1" Name="KeyspaceValue" Margin="6" Text="{Binding Keyspace, Mode=TwoWay,ValidatesOnDataErrors=True,ValidatesOnExceptions=True,NotifyOnValidationError=True,UpdateSourceTrigger=PropertyChanged}" />
+ <TextBox Grid.Row="0" Grid.Column="1" Name="KeyspaceValue" Margin="6" Text="{Binding Keyspace, Mode=TwoWay}" />
<TextBlock Grid.Row="1" Text="Host *" Margin="6" VerticalAlignment="Center" />
- <TextBox Grid.Row="1" Grid.Column="1" Name="HostValue" Margin="6" Text="{Binding Host, Mode=TwoWay,ValidatesOnDataErrors=True,ValidatesOnExceptions=True,NotifyOnValidationError=True,UpdateSourceTrigger=PropertyChanged}" />
+ <TextBox Grid.Row="1" Grid.Column="1" Name="HostValue" Margin="6" Text="{Binding Host, Mode=TwoWay}" />
<TextBlock Grid.Row="2" Text="Port" Margin="6" VerticalAlignment="Center" />
- <TextBox Grid.Row="2" Grid.Column="1" Name="PortValue" Margin="6" Text="{Binding Port, Mode=TwoWay,ValidatesOnDataErrors=True,ValidatesOnExceptions=True,NotifyOnValidationError=True}" />
-
+ <TextBox Grid.Row="2" Grid.Column="1" Name="PortValue" Margin="6" Text="{Binding Port, Mode=TwoWay}" />
+
<TextBlock Grid.Row="3" Text="Timeout" Margin="6" VerticalAlignment="Center" />
- <TextBox Grid.Row="3" Grid.Column="1" Name="TimeoutValue" Margin="6" Text="{Binding Timeout, Mode=TwoWay,ValidatesOnDataErrors=True,ValidatesOnExceptions=True,NotifyOnValidationError=True}" />
+ <TextBox Grid.Row="3" Grid.Column="1" Name="TimeoutValue" Margin="6" Text="{Binding Timeout, Mode=TwoWay}" />
<TextBlock Grid.Row="4" Text="Username" Margin="6" VerticalAlignment="Center" />
- <TextBox Grid.Row="4" Grid.Column="1" Name="UsernameValue" Margin="6" Text="{Binding Username, Mode=TwoWay,ValidatesOnDataErrors=True,ValidatesOnExceptions=True,NotifyOnValidationError=True}" />
-
+ <TextBox Grid.Row="4" Grid.Column="1" Name="UsernameValue" Margin="6" Text="{Binding Username, Mode=TwoWay}" />
+
<TextBlock Grid.Row="5" Text="Password" Margin="6" VerticalAlignment="Center" />
<PasswordBox Grid.Row="5" Grid.Column="1" Name="PasswordValue" Margin="6" PasswordChanged="PasswordValue_PasswordChanged" />
<Button Grid.Row="9" Grid.Column="1" Content="OK" Name="OkButton" HorizontalAlignment="Right" Margin="6" Width="60" Click="OkButton_Click" Command="{Binding SaveCommand}" />
</Grid>
-</Window>
+</Window>
View
34 utility/FluentCassandra.LinqPad/ConnectionDialog.xaml.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Linq;
+using System.Windows;
+
+namespace FluentCassandra.LinqPad
+{
+ /// <summary>
+ /// Interaction logic for ConnectionDialog.xaml
+ /// </summary>
+ public partial class ConnectionDialog : Window
+ {
+ private CassandraConnectionInfo _connInfo;
+
+ public ConnectionDialog(CassandraConnectionInfo conn)
+ {
+ if (conn == null)
+ throw new ArgumentNullException("conn", "conn is null.");
+
+ InitializeComponent();
+
+ DataContext = _connInfo = conn;
+ PasswordValue.Password = conn.Password;
+ }
+ private void OkButton_Click(object sender, RoutedEventArgs e)
+ {
+ DialogResult = true;
+ }
+
+ private void PasswordValue_PasswordChanged(object sender, RoutedEventArgs e)
+ {
+ _connInfo.Password = PasswordValue.Password;
+ }
+ }
+}
View
2 utility/FluentCassandra.LinqPad/DevDeploy.bat
@@ -1 +1 @@
-robocopy "C:\Code\RavenLinqpadDriver\RavenLinqpadDriver\bin\Debug" "C:\ProgramData\LINQPad\Drivers\DataContext\4.0\RavenLinqpadDriver (585b2b0c3c4c2d89)" /mir
+robocopy "C:\development\projects\FluentCassandra\utility\FluentCassandra.LinqPad\bin\Debug" "C:\ProgramData\LINQPad\Drivers\DataContext\4.0\FluentCassandra.LinqPad (94b0de35caac94d0)" /mir
View
54 utility/FluentCassandra.LinqPad/FluentCassandra.LinqPad.csproj
@@ -35,34 +35,26 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
- <SignAssembly>false</SignAssembly>
+ <SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
- <AssemblyOriginatorKeyFile>
- </AssemblyOriginatorKeyFile>
+ <AssemblyOriginatorKeyFile>FluentCassandra.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition=" '$(TargetFrameworkVersion)' == 'v3.5' ">$(DefineConstants);NET35</DefineConstants>
</PropertyGroup>
<ItemGroup>
- <Reference Include="GalaSoft.MvvmLight.Extras.WPF4">
- <HintPath>..\..\packages\MvvmLight.3.1.1\lib\net40\GalaSoft.MvvmLight.Extras.WPF4.dll</HintPath>
- </Reference>
- <Reference Include="GalaSoft.MvvmLight.WPF4">
- <HintPath>..\..\packages\MvvmLight.3.1.1\lib\net40\GalaSoft.MvvmLight.WPF4.dll</HintPath>
- </Reference>
<Reference Include="LINQPad">
<HintPath>..\..\lib\LINQPad.exe</HintPath>
+ <Private>False</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
- <Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
- <HintPath>..\..\packages\MvvmLight.3.1.1\lib\net40\System.Windows.Interactivity.dll</HintPath>
- </Reference>
+ <Reference Include="System.Numerics" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />