Permalink
Browse files

moved around some code from issues #28 and #30 and used DateTimePreci…

…se in other locations in the project

moved around some methods because they were on the wrong object
  • Loading branch information...
nberardi committed May 23, 2012
1 parent ee8650a commit f4b065bafb1443fb1cb8d80f4dac18668fe18feb
View
@@ -79,6 +79,16 @@ Global
{9DAF7022-5820-4214-B13E-AC0A1B37691F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{9DAF7022-5820-4214-B13E-AC0A1B37691F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{9DAF7022-5820-4214-B13E-AC0A1B37691F}.Release|x86.ActiveCfg = Release|Any CPU
+ {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|x86.ActiveCfg = Debug|x86
+ {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|x86.Build.0 = Debug|x86
+ {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|Any CPU.ActiveCfg = Release|x86
+ {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|Mixed Platforms.Build.0 = Release|x86
+ {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|x86.ActiveCfg = Release|x86
+ {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|x86.Build.0 = Release|x86
{CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
@@ -90,6 +100,26 @@ Global
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+ {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|x86.ActiveCfg = Debug|x86
+ {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|x86.Build.0 = Debug|x86
+ {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|Any CPU.ActiveCfg = Release|x86
+ {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|Mixed Platforms.Build.0 = Release|x86
+ {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|x86.ActiveCfg = Release|x86
+ {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|x86.Build.0 = Release|x86
+ {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AC3818E2-E260-4193-A3D1-6E3FF87383F6} = {1A88B962-9A09-4692-80D3-E88712A9E516}
@@ -121,4 +151,10 @@ Global
$6.inheritsSet = Mono
version = 1.0.0
EndGlobalSection
+ GlobalSection(TestCaseManagementSettings) = postSolution
+ CategoryFile = FluentCassandra.vsmdi
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
EndGlobal
@@ -44,7 +44,7 @@ public static void InsertColumn(this CassandraColumnFamily family, CassandraObje
public static void InsertColumn(this CassandraColumnFamily family, CassandraObject key, CassandraObject columnName, BytesType columnValue)
{
- InsertColumn(family, key, columnName, columnValue, DateTimeOffset.UtcNow, null);
+ InsertColumn(family, key, columnName, columnValue, DateTimePrecise.UtcNow, null);
}
public static void InsertColumn(this CassandraColumnFamily family, CassandraObject key, CassandraObject columnName, BytesType columnValue, DateTimeOffset timestamp, int? timeToLive)
@@ -56,7 +56,7 @@ public static void InsertColumn(this CassandraSuperColumnFamily family, Cassandr
public static void InsertColumn(this CassandraSuperColumnFamily family, CassandraObject key, CassandraObject superColumnName, CassandraObject name, BytesType value)
{
- InsertColumn(family, key, superColumnName, name, value, DateTimeOffset.UtcNow, null);
+ InsertColumn(family, key, superColumnName, name, value, DateTimePrecise.UtcNow, null);
}
public static void InsertColumn(this CassandraSuperColumnFamily family, CassandraObject key, CassandraObject superColumnName, CassandraObject name, BytesType value, DateTimeOffset timestamp, int? timeToLive)
@@ -28,7 +28,7 @@ internal Connection(Server server, ConnectionBuilder builder)
_connectionType = builder.ConnectionType;
_bufferSize = builder.BufferSize;
- Created = DateTime.Now;
+ Created = DateTime.UtcNow;
Server = server;
var socket = new TSocket(server.Host, server.Port, server.Timeout * 1000);
@@ -106,7 +106,7 @@ public void Cleanup()
/// <returns>True if alive; otherwise false.</returns>
private bool IsAlive(IConnection connection)
{
- if (ConnectionLifetime > TimeSpan.Zero && connection.Created.Add(ConnectionLifetime) < DateTime.Now)
+ if (ConnectionLifetime > TimeSpan.Zero && connection.Created.Add(ConnectionLifetime) < DateTime.UtcNow)
return false;
return connection.IsOpen;
@@ -119,6 +119,7 @@
<Compile Include="Connections\TimedLock.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="System\DateTimePrecise.cs" />
<Compile Include="FluentCassandraException.cs" />
<Compile Include="FluentColumn.cs">
<SubType>Code</SubType>
View
@@ -32,7 +32,7 @@ public FluentColumn(CassandraColumnSchema schema = null)
{
SetSchema(schema);
- ColumnTimestamp = DateTimeOffset.UtcNow;
+ ColumnTimestamp = DateTimePrecise.UtcNow;
ColumnSecondsUntilDeleted = null;
ColumnTimeUntilDeleted = null;
}
@@ -46,7 +46,7 @@ public CassandraObject ColumnName
set
{
_name = value.GetValue(GetSchema().NameType);
- ColumnTimestamp = DateTimeOffset.UtcNow;
+ ColumnTimestamp = DateTimePrecise.UtcNow;
}
}
@@ -59,7 +59,7 @@ public CassandraObject ColumnValue
set
{
_value = value.GetValue(GetSchema().ValueType);
- ColumnTimestamp = DateTimeOffset.UtcNow;
+ ColumnTimestamp = DateTimePrecise.UtcNow;
}
}
View
@@ -9,7 +9,7 @@ public class FluentMutation
/// </summary>
internal FluentMutation()
{
- Timestamp = DateTimeOffset.UtcNow;
+ ColumnTimestamp = DateTimePrecise.UtcNow;
}
/// <summary>
@@ -25,6 +25,6 @@ internal FluentMutation()
/// <summary>
///
/// </summary>
- public DateTimeOffset Timestamp { get; private set; }
+ public DateTimeOffset ColumnTimestamp { get; private set; }
}
}
View
@@ -3,7 +3,7 @@
namespace FluentCassandra
{
- public static class GuidGenerator
+ public static partial class GuidGenerator
{
// number of bytes in guid
public const int ByteArraySize = 16;
@@ -77,7 +77,7 @@ public static DateTime GetUtcDateTime(Guid guid)
public static Guid GenerateTimeBasedGuid()
{
- return GenerateTimeBasedGuid(new DateTimePrecise(5).UtcNow, RandomNode);
+ return GenerateTimeBasedGuid(DateTimePrecise.UtcNowOffset, RandomNode);
}
public static Guid GenerateTimeBasedGuid(DateTime dateTime)
@@ -121,110 +121,5 @@ public static Guid GenerateTimeBasedGuid(DateTimeOffset dateTime, byte[] node)
return new Guid(guid);
}
-
- /// DateTimePrecise class in C# -- an improvement to DateTime.Now
- /// By jamesdbrock
- /// http://www.codeproject.com/KB/cs/DateTimePrecise.aspx
- /// Licensed via The Code Project Open License (CPOL) 1.02
- /// http://www.codeproject.com/info/cpol10.aspx
- ///
- /// DateTimePrecise provides a way to get a DateTime that exhibits the
- /// relative precision of
- /// System.Diagnostics.Stopwatch, and the absolute accuracy of DateTime.Now.
- private class DateTimePrecise
- {
- /// Creates a new instance of DateTimePrecise.
- /// A large value of synchronizePeriodSeconds may cause arithmetic overthrow
- /// exceptions to be thrown. A small value may cause the time to be unstable.
- /// A good value is 10.
- /// synchronizePeriodSeconds = The number of seconds after which the
- /// DateTimePrecise will synchronize itself with the system clock.
- public DateTimePrecise(long synchronizePeriodSeconds)
- {
- Stopwatch = Stopwatch.StartNew();
- this.Stopwatch.Start();
-
- DateTime t = DateTime.UtcNow;
- _immutable = new DateTimePreciseSafeImmutable(t, t, Stopwatch.ElapsedTicks,
- Stopwatch.Frequency);
-
- _synchronizePeriodSeconds = synchronizePeriodSeconds;
- _synchronizePeriodStopwatchTicks = synchronizePeriodSeconds *
- Stopwatch.Frequency;
- _synchronizePeriodClockTicks = synchronizePeriodSeconds *
- _clockTickFrequency;
- }
-
- /// Returns the current date and time, just like DateTime.UtcNow.
- public DateTime UtcNow
- {
- get
- {
- long s = this.Stopwatch.ElapsedTicks;
- DateTimePreciseSafeImmutable immutable = _immutable;
-
- if (s < immutable._s_observed + _synchronizePeriodStopwatchTicks)
- {
- return immutable._t_base.AddTicks(((
- s - immutable._s_observed) * _clockTickFrequency) / (
- immutable._stopWatchFrequency));
- }
- else
- {
- DateTime t = DateTime.UtcNow;
-
- DateTime t_base_new = immutable._t_base.AddTicks(((
- s - immutable._s_observed) * _clockTickFrequency) / (
- immutable._stopWatchFrequency));
-
- _immutable = new DateTimePreciseSafeImmutable(
- t,
- t_base_new,
- s,
- ((s - immutable._s_observed) * _clockTickFrequency * 2)
- /
- (t.Ticks - immutable._t_observed.Ticks + t.Ticks +
- t.Ticks - t_base_new.Ticks - immutable._t_observed.Ticks)
- );
-
- return t_base_new;
- }
- }
- }
-
- /// Returns the current date and time, just like DateTime.Now.
- public DateTime Now
- {
- get
- {
- return this.UtcNow.ToLocalTime();
- }
- }
-
- /// The internal System.Diagnostics.Stopwatch used by this instance.
- public Stopwatch Stopwatch;
-
- private long _synchronizePeriodStopwatchTicks;
- private long _synchronizePeriodSeconds;
- private long _synchronizePeriodClockTicks;
- private const long _clockTickFrequency = 10000000;
- private DateTimePreciseSafeImmutable _immutable;
- }
-
- internal sealed class DateTimePreciseSafeImmutable
- {
- internal DateTimePreciseSafeImmutable(DateTime t_observed, DateTime t_base,
- long s_observed, long stopWatchFrequency)
- {
- _t_observed = t_observed;
- _t_base = t_base;
- _s_observed = s_observed;
- _stopWatchFrequency = stopWatchFrequency;
- }
- internal readonly DateTime _t_observed;
- internal readonly DateTime _t_base;
- internal readonly long _s_observed;
- internal readonly long _stopWatchFrequency;
- }
}
}
View
@@ -291,7 +291,7 @@ public static IEnumerable<Mutation> CreateDeletedColumnMutation(IEnumerable<Flue
foreach (var col in mutation)
{
var deletion = new Deletion {
- Timestamp = col.Timestamp.ToTimestamp(),
+ Timestamp = col.ColumnTimestamp.ToTimestamp(),
Predicate = CreateSlicePredicate(new[] { col.Column.ColumnName })
};
@@ -308,7 +308,7 @@ public static IEnumerable<Mutation> CreateDeletedSuperColumnMutation(IEnumerable
var superColumn = col.Column.GetPath().SuperColumn.ColumnName.TryToBigEndian();
var deletion = new Deletion {
- Timestamp = col.Timestamp.ToTimestamp(),
+ Timestamp = col.ColumnTimestamp.ToTimestamp(),
Super_column = superColumn,
Predicate = CreateSlicePredicate(new[] { col.Column.ColumnName })
};
View
@@ -31,7 +31,7 @@ public override Void Execute()
Session.GetClient().remove(
Key,
path,
- DateTimeOffset.Now.ToTimestamp(),
+ DateTimePrecise.UtcNow.ToTimestamp(),
Session.WriteConsistency
);
Oops, something went wrong.

0 comments on commit f4b065b

Please sign in to comment.