/// <summary> /// Initializes a new instance of the <see cref="ZipCompilation" /> class. /// </summary> public ZipCompilation() { //create the inner Compilation InnerCompilation = new XmlCompilation(); Id = Guid.NewGuid(); ExtractionPath = Path.GetTempPath(); //set extraction path for this Compilation }
/// <summary> /// Retrieves the Compilation at the specified url. /// </summary> public override ICompilation Retrieve(String fileName) { XmlSerializer CompilationSerializer = new XmlSerializer(typeof(XmlCompilation)); using (FileStream readFileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { XmlCompilation Compilation = (XmlCompilation)CompilationSerializer.Deserialize(readFileStream); Compilation.Url = readFileStream.Name; //keep the filename of the storage used (use the path from the filestream, because it is absolute; the current directory was applied if no path was available beforehand) Compilation.IsDirty = false; //explicitly set false, since we just have loaded the data return(Compilation); } }
/// <summary> /// Retrieves the stored Compilation from the specified url. /// </summary> public override ICompilation Retrieve(String url) { ZipCompilation retrieved = new ZipCompilation(); retrieved.ExtractionPath = Path.GetTempPath(); //set extraction path for the retrieved Compilation IEnumerable <string> filenames = DecompressFile(url, retrieved.ExtractionPath); //find the Compilation file string CompilationUnzippedFileName = (from unzipfileName in filenames where Path.GetExtension(unzipfileName) .Equals(XmlCompilation.DefaultExtension) select unzipfileName).First(); XmlSerializer CompilationSerializer = new XmlSerializer(typeof(XmlCompilation)); using ( FileStream readFileStream = new FileStream(CompilationUnzippedFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { XmlCompilation xmlCompilation = (XmlCompilation)CompilationSerializer.Deserialize(readFileStream); //now with the retrived XML Compilation, fill the properties of the retrieved instance retrieved.Tracks = xmlCompilation.Tracks; //make sure, the path to the compilation is absolute retrieved.Url = Path.GetFullPath(url); ///set the Compilation media path to the temporary directory, so that the track media ///files are searched and found in there. retrieved.MediaPath = retrieved.ExtractionPath; retrieved.Title = xmlCompilation.Title; } ///remove the path information from the track media files, so that they are not searched with ///that absolute path. foreach (Track item in retrieved.Tracks) { item.Url = Path.GetFileName(item.Url); //remember only filename (with extension) } retrieved.IsDirty = false; //explicitly set false, since we just have loaded the data return(retrieved); }