protected static SqlCommand LoadEntryCommand(RFCatalogKey itemKey, int version, SqlConnection connection, SqlTransaction transaction = null) { if (itemKey.StoreType != RFStoreType.Document) { throw new Exception(String.Format("Unrecognized store type {0}", itemKey.StoreType)); } SqlCommand sqlCommand = null; if (transaction != null) { sqlCommand = CreateCommand("[RIFF].[GetDocument]", connection, transaction); } else { sqlCommand = CreateCommand("[RIFF].[GetDocument]", connection); } var keyString = itemKey.ToString(); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@KeyType", itemKey.GetType().FullName); sqlCommand.Parameters.AddWithValue("@SerializedKey", keyString); sqlCommand.Parameters.AddWithValue("@KeyHash", RFStringHelpers.QuickHash(keyString)); sqlCommand.Parameters.AddWithValue("@Version", version); return(sqlCommand); }
public override RFCatalogKeyMetadata GetKeyMetadata(RFCatalogKey key) { var keyType = key.GetType().FullName; var keyString = key.ToString(); var keyHash = RFStringHelpers.QuickHash(keyString); //Log.Debug(this, "GetKeyMetadata {0}", keyType); try { var dataTable = new DataTable(); using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (var getCommand = CreateCommand("[RIFF].[GetKeyMetadata]", connection)) { getCommand.CommandType = CommandType.StoredProcedure; getCommand.Parameters.AddWithValue("@KeyType", keyType); getCommand.Parameters.AddWithValue("@SerializedKey", keyString); getCommand.Parameters.AddWithValue("@KeyHash", keyHash); using (var reader = getCommand.ExecuteReader(System.Data.CommandBehavior.SingleResult)) { dataTable.Load(reader); } } } if (dataTable != null && dataTable.Rows != null && dataTable.Rows.Count > 0) { var dataRow = dataTable.Rows[0]; return(new RFCatalogKeyMetadata { ContentType = dataRow["ContentType"].ToString(), KeyType = dataRow["KeyType"].ToString(), Key = RFXMLSerializer.DeserializeContract(dataRow["KeyType"].ToString(), dataRow["SerializedKey"].ToString()) as RFCatalogKey, KeyReference = (long)dataRow["CatalogKeyID"], Metadata = RFMetadata.Deserialize(dataRow["Metadata"].ToString()), UpdateTime = (DateTimeOffset)dataRow["UpdateTime"], IsValid = (bool)dataRow["IsValid"], DataSize = (long)dataRow["DataSize"] }); } } catch (Exception ex) { Log.Exception(this, "Error retrieving key metadata", ex); } return(null); }
public override Dictionary <RFGraphInstance, RFCatalogKey> GetKeyInstances(RFCatalogKey key) { var t = key.GetType(); var keys = new Dictionary <RFGraphInstance, RFCatalogKey>(); string keyType = t.FullName; Log.Debug(this, "GetKeyInstances {0}", keyType); try { var dataTable = new DataTable(); using (var connection = new SqlConnection(_connectionString)) { connection.Open(); string getKeysSQL = "RIFF.GetKeyInstances"; using (var getCommand = CreateCommand(getKeysSQL, connection)) { var rootHash = RFStringHelpers.QuickHash(key.RootKey().ToString()); getCommand.CommandType = CommandType.StoredProcedure; getCommand.Parameters.AddWithValue("@KeyType", keyType); getCommand.Parameters.AddWithValue("@SerializedKey", RFXMLSerializer.SerializeContract(key)); getCommand.Parameters.AddWithValue("@RootHash", rootHash); using (var reader = getCommand.ExecuteReader(System.Data.CommandBehavior.SingleResult)) { dataTable.Load(reader); } } } if (dataTable != null && dataTable.Rows != null && dataTable.Rows.Count > 0) { // cache deserializer if key is explicit foreach (DataRow dataRow in dataTable.Rows) { try { var catalogKeyID = (long)dataRow["CatalogKeyID"]; var retrievedKeyType = dataRow["KeyType"].ToString(); var serializedKey = dataRow["SerializedKey"].ToString(); var graphInstanceName = dataRow["GraphInstanceName"].ToString(); var graphInstanceDate = new RFDate((int)dataRow["GraphInstanceDate"]); var deserializedKey = RFXMLSerializer.DeserializeContract(retrievedKeyType, serializedKey); keys.Add( new RFGraphInstance { Name = graphInstanceName, ValueDate = graphInstanceDate }, deserializedKey as RFCatalogKey); } catch (Exception ex) { Log.Exception(this, ex, "Error deserializing key {0}", dataRow["SerializedKey"].ToString()); } } } } catch (Exception ex) { Log.Exception(this, "Error retrieving key instances", ex); } return(keys); }