/// <summary> /// Remove metadata from the media found in the input stream. /// </summary> public MetaRemoval(MediaCoordinator coordinator, Stream input, Stream output, IAction <MetaRemoval> onComplete, bool removeTempFile = true) { _coordinator = coordinator; _removeTempFile = removeTempFile; // create a name for the media Path = Fs.Combine(_coordinator.MediaPath, Guid.NewGuid().ToString()); Output = output; OnComplete = onComplete; OnComplete.ArgA = this; try { // open a stream to the file FileStream file = new FileStream(Path, FileMode.Create, FileAccess.Write, FileShare.Read); // copy the stream into a temporary file WriteTemporaryFile(file, input); } catch (IOException ex) { // if the file is still being used if (ex.HResult == -2147024864) { // try twice more ManagerUpdate.Iterant.AddSingle(TryWriteTemporaryFile, input, 0); return; } } }
/// <summary> /// Remove metadata from the media found in the input stream. /// </summary> public MetaRetrieval(MediaCoordinator coordinator, Stream input, IAction <MetaRetrieval> onComplete, bool removeTempFile = true) { _coordinator = coordinator; _removeTempFile = removeTempFile; // create a name for the media Path = Fs.Combine(_coordinator.MediaPath, Guid.NewGuid().ToString()); OnComplete = onComplete; OnComplete.ArgA = this; // open a stream to the file FileStream file = new FileStream(Path, FileMode.Create); // add a task to copy the stream into a temporary file // this then triggers the metadata retrieval WriteTemporaryFile(file, input); }
/// <summary> /// Remove metadata from the media found in the input stream. /// </summary> public MetaRetrieval(MediaCoordinator coordinator, string path, IAction <MetaRetrieval> onComplete, bool removeFile = true) { _coordinator = coordinator; _removeTempFile = removeFile; // create a name for the media Path = path; OnComplete = onComplete; OnComplete.ArgA = this; var process = _coordinator.Process.TakeItem(); process.StandardInput.BaseStream.Write(_bytesGetMetadata, 0, _bytesGetMetadata.Length); byte[] pathBytes = System.Text.Encoding.ASCII.GetBytes(Path); process.StandardInput.BaseStream.Write(pathBytes, 0, pathBytes.Length); process.StandardInput.BaseStream.Write(_coordinator.BytesExecute, 0, _coordinator.BytesExecute.Length); process.StandardInput.BaseStream.Flush(); _coordinator.Process.Release(); _coordinator.Add(this); }