本文整理汇总了C#中MediaPortal.Common.MediaManagement.MediaItemAspectMetadata.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# MediaItemAspectMetadata.Serialize方法的具体用法?C# MediaItemAspectMetadata.Serialize怎么用?C# MediaItemAspectMetadata.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MediaPortal.Common.MediaManagement.MediaItemAspectMetadata
的用法示例。
在下文中一共展示了MediaItemAspectMetadata.Serialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddMediaItemAspectStorage
public bool AddMediaItemAspectStorage(MediaItemAspectMetadata miam)
{
lock (_syncObj)
{
if (_managedMIATypes.ContainsKey(miam.AspectId))
return false;
_managedMIATypes.Add(miam.AspectId, null);
}
ISQLDatabase database = ServiceRegistration.Get<ISQLDatabase>();
ITransaction transaction = database.BeginTransaction();
ServiceRegistration.Get<ILogger>().Info("MIA_Management: Adding media library storage for media item aspect '{0}' (id '{1}')",
miam.Name, miam.AspectId);
try
{
// Register metadata first - generated aliases will reference to the new MIA type row
using (IDbCommand command = MediaLibrary_SubSchema.CreateMediaItemAspectMetadataCommand(transaction, miam.AspectId, miam.Name, miam.Serialize()))
command.ExecuteNonQuery();
// Create main table for new MIA type
string miaTableName = GenerateMIATableName(transaction, miam);
StringBuilder mainStatementBuilder = new StringBuilder("CREATE TABLE " + miaTableName + " (" +
MIA_MEDIA_ITEM_ID_COL_NAME + " " + database.GetSQLType(typeof(Guid)) + ", ");
IList<string> terms = new List<string>();
IList<string> additionalAttributesConstraints = new List<string>();
string collectionAttributeTableName;
string pkConstraintName;
// Attributes: First run
foreach (MediaItemAspectMetadata.AttributeSpecification spec in miam.AttributeSpecifications.Values)
{
string sqlType = spec.AttributeType == typeof(string) ? database.GetSQLVarLengthStringType(spec.MaxNumChars) :
database.GetSQLType(spec.AttributeType);
string attributeColumnName = GenerateMIAAttributeColumnName(transaction, spec);
switch (spec.Cardinality)
{
case Cardinality.Inline:
terms.Add(attributeColumnName + " " + sqlType);
break;
case Cardinality.OneToMany:
GenerateMIACollectionAttributeTableName(transaction, spec);
break;
case Cardinality.ManyToOne:
// Create foreign table - the join attribute will be located in the main MIA table
// We need to create the "One" table first because the main table references on it
collectionAttributeTableName = GenerateMIACollectionAttributeTableName(transaction, spec);
pkConstraintName = GenerateDBObjectName(transaction, miam.AspectId, collectionAttributeTableName + "_PK", "PK");
using (IDbCommand command = transaction.CreateCommand())
{
command.CommandText = "CREATE TABLE " + collectionAttributeTableName + " (" +
FOREIGN_COLL_ATTR_ID_COL_NAME + " " + database.GetSQLType(typeof(Guid)) + ", " +
COLL_ATTR_VALUE_COL_NAME + " " + sqlType + ", " +
"CONSTRAINT " + pkConstraintName + " PRIMARY KEY (" + FOREIGN_COLL_ATTR_ID_COL_NAME + ")" +
")";
ServiceRegistration.Get<ILogger>().Debug("MIA_Management: Creating MTO table '{0}' for attribute '{1}' in media item aspect '{2}'",
collectionAttributeTableName, spec.AttributeName, miam.AspectId);
command.ExecuteNonQuery();
}
// Create foreign table - the join attribute will be located in the main MIA table
string fkMediaItemConstraintName = GenerateDBObjectName(transaction, miam.AspectId, "MIA_" + collectionAttributeTableName + "_FK", "FK");
terms.Add(attributeColumnName + " " + database.GetSQLType(typeof(Guid)));
additionalAttributesConstraints.Add("CONSTRAINT " + fkMediaItemConstraintName +
" FOREIGN KEY (" + attributeColumnName + ")" +
" REFERENCES " + collectionAttributeTableName + " (" + FOREIGN_COLL_ATTR_ID_COL_NAME + ") ON DELETE SET NULL");
break;
case Cardinality.ManyToMany:
GenerateMIACollectionAttributeTableName(transaction, spec);
break;
default:
throw new NotImplementedException(string.Format("Cardinality '{0}' for attribute '{1}.{2}' is not implemented",
spec.Cardinality, miam.AspectId, spec.AttributeName));
}
}
// Main table
foreach (string term in terms)
{
mainStatementBuilder.Append(term);
mainStatementBuilder.Append(", ");
}
string pkConstraintName1 = GenerateDBObjectName(transaction, miam.AspectId, miaTableName + "_PK", "PK");
string fkMediaItemConstraintName1 = GenerateDBObjectName(transaction, miam.AspectId, miaTableName + "_MEDIA_ITEMS_FK", "FK");
mainStatementBuilder.Append(
"CONSTRAINT " + pkConstraintName1 + " PRIMARY KEY (" + MIA_MEDIA_ITEM_ID_COL_NAME + "), " +
"CONSTRAINT " + fkMediaItemConstraintName1 +
" FOREIGN KEY (" + MIA_MEDIA_ITEM_ID_COL_NAME + ") REFERENCES " +
MediaLibrary_SubSchema.MEDIA_ITEMS_TABLE_NAME + " (" + MediaLibrary_SubSchema.MEDIA_ITEMS_ITEM_ID_COL_NAME + ") ON DELETE CASCADE");
if (additionalAttributesConstraints.Count > 0)
{
mainStatementBuilder.Append(", ");
mainStatementBuilder.Append(StringUtils.Join(", ", additionalAttributesConstraints));
}
mainStatementBuilder.Append(")");
using (IDbCommand command = transaction.CreateCommand())
{
command.CommandText = mainStatementBuilder.ToString();
ServiceRegistration.Get<ILogger>().Debug(
"MIA_Management: Creating main table '{0}' for media item aspect '{1}'", miaTableName, miam.AspectId);
//.........这里部分代码省略.........