/// <summary> /// Tags the single file fiSource and writes it to fiDest. /// </summary> /// <param name="fiSource"></param> /// <param name="fiDest"></param> public void TagFile(FileInfo fiSource, FileInfo fiDest) { if (OnPreTagFile != null) { TagFileEventHandler tempOnPreTagFile = OnPreTagFile; TagFileEventArgs args = new TagFileEventArgs(fiSource, fiDest); tempOnPreTagFile(args); if (args.Handled) { fiDest = args.DstFile; } } if (fiDest.FullName == fiSource.FullName && !mbAllowSourceEqualDest) { throw new NotSupportedException("Source and destination is equal. See the AllowlSourceEqualDest property.\r\nSource:" + fiSource.FullName); } if (fiDest.Exists && !mbAllowOverwrite) { throw new NotSupportedException("Destination file already exists. See the AllowOverwrite property.\r\nDest:" + fiDest.FullName); } StreamReader sr = new StreamReader(fiSource.FullName); string sTaggedData = sr.ReadToEnd(); sr.Close(); if (fiDest.Exists) { fiDest.Delete(); } StreamWriter sw = new StreamWriter(fiDest.FullName); sw.Write(TagString(ref sTaggedData)); sw.Flush(); sw.Close(); if (OnPostTagFile != null) { TagFileEventHandler tempOnPostTagFile = OnPostTagFile; TagFileEventArgs args = new TagFileEventArgs(fiSource, fiDest); tempOnPostTagFile(args); } }
/// <summary> /// Tags the single file fiSource and writes it to fiDest. /// </summary> /// <param name="fiSource"></param> /// <param name="fiDest"></param> public void TagFile(FileInfo fiSource, FileInfo fiDest) { if (OnPreTagFile != null) { TagFileEventHandler tempOnPreTagFile = OnPreTagFile; TagFileEventArgs args = new TagFileEventArgs(fiSource, fiDest); tempOnPreTagFile(args); if (args.Handled) fiDest = args.DstFile; } if (fiDest.FullName == fiSource.FullName && !mbAllowSourceEqualDest) throw new NotSupportedException("Source and destination is equal. See the AllowlSourceEqualDest property.\r\nSource:" + fiSource.FullName); if (fiDest.Exists && !mbAllowOverwrite) throw new NotSupportedException("Destination file already exists. See the AllowOverwrite property.\r\nDest:" + fiDest.FullName); StreamReader sr = new StreamReader(fiSource.FullName); string sTaggedData = sr.ReadToEnd(); sr.Close(); if (fiDest.Exists) fiDest.Delete(); StreamWriter sw = new StreamWriter(fiDest.FullName); sw.Write(TagString(ref sTaggedData)); sw.Flush(); sw.Close(); if (OnPostTagFile != null) { TagFileEventHandler tempOnPostTagFile = OnPostTagFile; TagFileEventArgs args = new TagFileEventArgs(fiSource, fiDest); tempOnPostTagFile(args); } }