/// <summary> /// Returns a <see cref="string" /> that represents this instance. /// </summary> /// <typeparam name="TDesiccate">The type being desiccated</typeparam> /// <param name="item">The item.</param> /// <param name="desiccationMedia">The desiccation media.</param> /// <returns> /// A <see cref="string" /> that represents this instance. /// </returns> public string ToString <TDesiccate>(TDesiccate item, TypeOfMedia desiccationMedia) where TDesiccate : class { var convert = GetConverterFor(desiccationMedia); return(convert.ToString(item)); }
//constructor public MediaAsset(string sPath) { m_sFilePath = sPath; FileInfo m_flFile = new FileInfo(sPath); m_sFileName = m_flFile.Name; m_lSize = m_flFile.Length; m_MediaType = GetMediaType(m_flFile.Extension); }
/// <summary> /// Saves the specified item. /// </summary> /// <param name="item">The item.</param> /// <param name="fileName">Name of the file.</param> /// <param name="desiccationMedia">The desiccation media.</param> public void Save(TFileContract item, string fileName, TypeOfMedia desiccationMedia) { if (It.Has(fileName)) { using (var file = File.CreateText(fileName)) { file.Write(Converter.ToString(item as TFileContent, desiccationMedia)); file.Close(); } } }
//Check personal holds/loans /*public static Media holdsInfo (int accountNumber) * { * var account = accounts.SingleOrDefault(a => a.AccountNumber == accountNumber); * if (account == null) * { * //throw not found * return null; * } * List<Media> holds = account.Holds; * return holds; * }*/ //Inventory_Add public static Media AddInv(/*uint id,*/ string title, int totalCopies, TypeOfMedia type, Categories category, string author, DateTime orginDate) { var newMedia = new Media { //ID = id, Title = title, TotalCopies = totalCopies, Type = type, Category = category, Author = author, OrginDate = orginDate }; medias.Add(newMedia); return(newMedia); }
//returns hashtable containing pat of assets from project directory // Parameter should be of extension of file e.g. ".wav" public Hashtable GetAssets(TypeOfMedia assetType) { IDictionaryEnumerator en = m_htAssetList.GetEnumerator(); Hashtable htTemp = new Hashtable(); MediaAsset m; //find the path from hash table using key while (en.MoveNext()) { m = en.Value as MediaAsset; if (m.MediaType.Equals(assetType)) { htTemp.Add(en.Key, en.Value); } } return(htTemp); }
//create local asset from some external asset public IMediaAsset AddAsset(TypeOfMedia assetType, string assetPath) { string sTemp = null; if (assetType.Equals(TypeOfMedia.Audio)) { sTemp = GenerateFileName(".wav", m_sDirPath); } if (sTemp != null) { try { //File.Create (sTemp) ; File.Copy(assetPath, sTemp, true); } catch { MessageBox.Show("Exeption! file could not be created in add asset in asset manager"); } AudioMediaAsset am = new AudioMediaAsset(sTemp); try { m_htAssetList.Add(am.Name, am); } catch { MessageBox.Show("Exeption! can not add duplicate in hash table"); } return(am); } else { MessageBox.Show("Asset could not be created and added. A null exeption will be thrown"); return(null); } // end of function }
//string type must contain valid extension like .wav // Parameter changed to enum TypeOfMedia public IMediaAsset NewAsset(TypeOfMedia assetType) { string sTemp = null; if (assetType.Equals(TypeOfMedia.Audio)) { sTemp = GenerateFileName(".wav", m_sDirPath); } if (sTemp != null) { //File.Create (sTemp) ; BinaryWriter bw = new BinaryWriter(File.Create(sTemp)); bw.BaseStream.Position = 0; byte b = Convert.ToByte(1); for (int i = 0; i < 44; i++) { bw.Write(b); } b = Convert.ToByte(44); bw.BaseStream.Position = 7; bw.Write(b); bw.Close(); AudioMediaAsset am = new AudioMediaAsset(sTemp); m_htAssetList.Add(am.Name, am); return(am); } else { MessageBox.Show("File could not be created and newAsset will throw a null exeption"); return(null); } }
/// <summary> /// Gets the converter for.. /// </summary> /// <param name="thisMediaType">this media type</param> /// <returns>the converter for the required media type</returns> public ISerialiseTypes GetConverterFor(TypeOfMedia thisMediaType) => thisMediaType == TypeOfMedia.JSON ? (ISerialiseTypes)JsonConverter : XmlConverter;