/// <summary> /// Creates a resource, given a metadata block of values. /// </summary> /// <param name="attribs"></param> /// <returns></returns> public static MediaResource CreateResource(ResourceAttributes attribs) { MediaResource newRes = new MediaResource(); SetCommonAttributes(newRes, attribs); return newRes; }
/// <summary> /// Creates a resource, given the contentUri and protocolInfo. /// </summary> /// <param name="contentUri"></param> /// <param name="protocolInfo"></param> /// <returns></returns> public static MediaResource CreateResource (string contentUri, string protocolInfo) { ResourceAttributes attribs = new ResourceAttributes(); attribs.contentUri = contentUri; attribs.protocolInfo = CdsMetadataCaches.ProtocolInfoStrings.CacheThis(protocolInfo); MediaResource newRes = new MediaResource(); SetCommonAttributes(newRes, attribs); return newRes; }
public static MediaItem PopulateMetaData(MediaResource R, FileInfo F) { MediaItem RetVal; MediaBuilder.item Item = null; DText parser = new DText(); parser.ATTRMARK = "-"; parser.MULTMARK = "."; switch(F.Extension.ToUpper()) { case ".MP3": Item = ParseMP3_V1(F); if(Item==null) { parser[0] = F.Name; if(parser.DCOUNT()==2) { Item = new MediaBuilder.musicTrack(parser[2,1].Trim()); Item.creator = parser[1].Trim(); ((MediaBuilder.musicTrack)Item).artist = new PersonWithRole[1]{new PersonWithRole()}; ((MediaBuilder.musicTrack)Item).artist[0].Name = Item.creator; ((MediaBuilder.musicTrack)Item).artist[0].Role = null; } } break; } if(Item!=null) { RetVal = MediaBuilder.CreateItem(Item); RetVal.AddResource(R); return(RetVal); } else { // Create a Generic Item string fname = F.Name; int fnameidx = fname.IndexOf("."); if(fnameidx!=-1) fname=fname.Substring(0,fnameidx); MediaBuilder.item genericItem = new MediaBuilder.item(fname); RetVal = MediaBuilder.CreateItem(genericItem); RetVal.AddResource(R); return(RetVal); } }
/// <summary> /// Constructors use this method to set the properties of a resource. /// Programmers can use this method also, but the method is not /// guaranteed to be thread safe. As a general rule, programmers shouldn't /// be changing the values of resources after they've instantiated them. /// </summary> /// <param name="res"></param> /// <param name="attribs"></param> public static void SetCommonAttributes(MediaResource res, ResourceAttributes attribs) { res.ProtocolInfo = attribs.protocolInfo; res.ContentUri = attribs.contentUri.Trim(); if ((attribs.importUri != null) && (attribs.importUri != "")) { res[T[_RESATTRIB.importUri]] = attribs.importUri; } TransferValue("bitrate", res, attribs); TransferValue("bitsPerSample", res, attribs); TransferValue("colorDepth", res, attribs); TransferValue("duration", res, attribs); TransferValue("nrAudioChannels", res, attribs); TransferValue("protection", res, attribs); TransferValue("resolution", res, attribs); TransferValue("sampleFrequency", res, attribs); TransferValue("size", res, attribs); }
/// <summary> /// <para> /// This method allows a generalized implementation of transfering /// a value from a /// <see cref="ResourceBuilder.ResourceAttributes"/> /// to a /// <see cref="MediaResource"/> /// object. /// </para> /// /// <para> /// Classes derived from the /// <see cref="ResourceBuilder.ResourceAttributes"/> /// class have fields, with names that match against fields in a /// <see cref="MediaResource"/> /// object. /// </para> /// </summary> /// <param name="attribName">name of the attribute to transfer</param> /// <param name="res">The /// <see cref="MediaResource"/> /// object to transfer to. /// </param> /// <param name="attribs"> /// The /// <see cref="ResourceBuilder.ResourceAttributes"/> /// object to transfer from. /// </param> private static void TransferValue(string attribName, MediaResource res, ResourceAttributes attribs) { object val = null; System.Type type = attribs.GetType(); FieldInfo info = type.GetField(attribName); if (info != null) { val = info.GetValue(attribs); if (val != null) { IValueType ivt = val as IValueType; bool ok = true; if (ivt != null) { ok = ivt.IsValid; } if (ok) { //res.m_Attributes[attribName] = val; res[attribName] = val; } } } }