private string GetKey(string key,
                       ValueVersion version)
 {
     return(GetKey(key) + "#" +
            version.InstanceId + "/" +
            version.Number);
 }
        public IEnumerable <byte[]> GetReplicationHashes(string key,
                                                         ValueVersion version)
        {
            Api.JetSetCurrentIndex(session, replication, "by_key_and_version");
            Api.MakeKey(session, replication, key, Encoding.Unicode, MakeKeyGrbit.NewKey);
            Api.MakeKey(session, replication, version.Number, MakeKeyGrbit.None);
            Api.MakeKey(session, replication, version.InstanceId.ToByteArray(), MakeKeyGrbit.None);

            if (Api.TrySeek(session, replication, SeekGrbit.SeekEQ) == false)
            {
                yield break;
            }

            Api.MakeKey(session, replication, key, Encoding.Unicode, MakeKeyGrbit.NewKey);
            Api.MakeKey(session, replication, version.Number, MakeKeyGrbit.None);
            Api.MakeKey(session, replication, version.InstanceId.ToByteArray(), MakeKeyGrbit.None);

            Api.JetSetIndexRange(session, replication,
                                 SetIndexRangeGrbit.RangeUpperLimit | SetIndexRangeGrbit.RangeInclusive);

            do
            {
                yield return(Api.RetrieveColumn(session, replication, replicationColumns["sha256_hash"]));
            } while (Api.TryMoveNext(session, replication));
        }
        private Value ReadValueFromDataTable(ValueVersion version,
                                             string key)
        {
            var      expiresAtBinary = Api.RetrieveColumnAsDouble(session, data, dataColumns["expiresAt"]);
            DateTime?expiresAt       = null;

            if (expiresAtBinary.HasValue)
            {
                expiresAt = DateTime.FromOADate(expiresAtBinary.Value);
                if (DateTime.Now > expiresAt)
                {
                    return(null);
                }
            }
            return(new Value
            {
                Version = version,
                Key = key,
                Timestamp = DateTime.FromOADate(Api.RetrieveColumnAsDouble(session, data, dataColumns["timestamp"]).Value),
                ParentVersions = GetParentVersions(data, dataColumns),
                Tag = Api.RetrieveColumnAsInt32(session, data, dataColumns["tag"]),
                Data = Api.RetrieveColumn(session, data, dataColumns["data"]),
                Sha256Hash = Api.RetrieveColumn(session, data, dataColumns["sha256_hash"]),
                ReadOnly = Api.RetrieveColumnAsBoolean(session, data, dataColumns["readonly"]).Value,
                ExpiresAt = expiresAt
            });
        }
        public bool HasReplicationInfo(string key,
                                       ValueVersion version,
                                       byte[] hash)
        {
            Api.JetSetCurrentIndex(session, replication, "pk");
            Api.MakeKey(session, replication, key, Encoding.Unicode, MakeKeyGrbit.NewKey);
            Api.MakeKey(session, replication, version.Number, MakeKeyGrbit.None);
            Api.MakeKey(session, replication, version.InstanceId.ToByteArray(), MakeKeyGrbit.None);
            Api.MakeKey(session, replication, hash, MakeKeyGrbit.None);

            return(Api.TrySeek(session, replication, SeekGrbit.SeekEQ));
        }
예제 #5
0
 public static Protocol.ValueVersion GetVersion(ValueVersion version)
 {
     if (version == null)
     {
         return(Protocol.ValueVersion.DefaultInstance);
     }
     return(new Protocol.ValueVersion.Builder
     {
         InstanceId = ByteString.CopyFrom(version.InstanceId.ToByteArray()),
         Number = version.Number
     }.Build());
 }
        public void AddReplicationRemovalInfo(string key,
                                              ValueVersion version,
                                              byte[] hash)
        {
            using (var update = new Update(session, replicationRemoval, JET_prep.Insert))
            {
                Api.SetColumn(session, replicationRemoval, replicationRemovalColumns["key"], key, Encoding.Unicode);

                Api.SetColumn(session, replicationRemoval, replicationRemovalColumns["version_number"], version.Number);
                Api.SetColumn(session, replicationRemoval, replicationRemovalColumns["version_instance_id"], version.InstanceId.ToByteArray());

                Api.SetColumn(session, replicationRemoval, replicationRemovalColumns["sha256_hash"], hash);

                update.Save();
            }
        }
예제 #7
0
 public static Protocol.ValueVersion GetVersion(ValueVersion version)
 {
     if (version == null)
         return Protocol.ValueVersion.DefaultInstance;
     return new Protocol.ValueVersion.Builder
     {
         InstanceId = ByteString.CopyFrom(version.InstanceId.ToByteArray()),
         Number = version.Number
     }.Build();
 }