static public void FailCopyInByWriting() { cs = new CountStream(); cs.FailAt = 2; cs.WrapStream = new FileStream("test_copy.cs", FileMode.Open, FileAccess.Read); cin = new NpgsqlCopyIn("COPY copy1 FROM STDIN", conn); cin.Start(); if (!cin.IsActive) { throw new Exception("Copy started inactive"); } byte[] buf = new byte[8]; int i; try { while ((i = cs.Read(buf, 0, buf.Length)) > 0) { cin.CopyStream.Write(buf, 0, i); } } catch (Exception e) { if (("" + e).Contains("Test Exception handling")) { try { cin.Cancel("Test whether copy in fails correctly"); } catch (Exception e2) { if (("" + e2).Contains("Test whether copy in fails correctly")) { Console.Out.WriteLine("Copy from writing failed as requested."); return; } throw e2; } throw new Exception("CopyIn.Cancel() didn't throw up the expected exception"); } throw e; } finally { cs.Close(); cin.End(); // should do nothing } throw new Exception("Copy from writing did not fail as requested"); }
static long InSum = 0; // this really is a SUM of the bytes! comparison depends on that. #endregion Fields #region Methods public static void CopyInByWriting() { cs = new CountStream(); cs.WrapStream = new FileStream("test_copy.cs", FileMode.Open, FileAccess.Read); cin = new NpgsqlCopyIn( "COPY copy1 FROM STDIN DELIMITER '\b'", conn ); cin.Start(); if(! cin.IsActive) { throw new Exception("Copy started inactive"); } byte[] buf = new byte[8]; int i; while( (i = cs.Read(buf,0,buf.Length)) > 0 ) { cin.CopyStream.Write(buf, 0, i); } cin.End(); InLength += cs.BytesPassed; InSum += cs.CheckSum; cs.Close(); Console.Out.WriteLine("Copy from writing ok"); }
static public void CopyInByWriting() { cs = new CountStream(); cs.WrapStream = new FileStream("test_copy.cs", FileMode.Open, FileAccess.Read); cin = new NpgsqlCopyIn("COPY copy1 FROM STDIN DELIMITER '\b'", conn); cin.Start(); if (!cin.IsActive) { throw new Exception("Copy started inactive"); } byte[] buf = new byte[8]; int i; while ((i = cs.Read(buf, 0, buf.Length)) > 0) { cin.CopyStream.Write(buf, 0, i); } cin.End(); InLength += cs.BytesPassed; InSum += cs.CheckSum; cs.Close(); Console.Out.WriteLine("Copy from writing ok"); }
public static void FailCopyInByWriting() { cs = new CountStream(); cs.FailAt = 2; cs.WrapStream = new FileStream("test_copy.cs", FileMode.Open, FileAccess.Read); cin = new NpgsqlCopyIn( "COPY copy1 FROM STDIN", conn ); cin.Start(); if(! cin.IsActive) { throw new Exception("Copy started inactive"); } byte[] buf = new byte[8]; int i; try { while( (i = cs.Read(buf,0,buf.Length)) > 0 ) { cin.CopyStream.Write(buf, 0, i); } } catch(Exception e) { if( (""+e).Contains("Test Exception handling") ) { try { cin.Cancel("Test whether copy in fails correctly"); } catch(Exception e2) { if( (""+e2).Contains("Test whether copy in fails correctly") ) { Console.Out.WriteLine("Copy from writing failed as requested."); return; } throw e2; } throw new Exception("CopyIn.Cancel() didn't throw up the expected exception"); } throw e; } finally { cs.Close(); cin.End(); // should do nothing } throw new Exception("Copy from writing did not fail as requested"); }