예제 #1
0
        /// <summary>Begins an asynchronous write operation.</summary>
        /// <returns>An <see cref="T:System.IAsyncResult" /> object that represents the asynchronous write, which could still be pending.</returns>
        /// <param name="array">The buffer to write data from.</param>
        /// <param name="offset">The byte offset in <paramref name="buffer" /> to begin writing from.</param>
        /// <param name="count">The maximum number of bytes to write.</param>
        /// <param name="asyncCallback">An optional asynchronous callback, to be called when the write is complete.</param>
        /// <param name="asyncState">A user-provided object that distinguishes this particular asynchronous write request from other requests.</param>
        /// <exception cref="T:System.IO.IOException">An asynchronous write past the end of the stream was attempted, or a disk error occurred.</exception>
        /// <exception cref="T:System.ArgumentException">One or more of the arguments is invalid.</exception>
        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.</exception>
        /// <exception cref="T:System.NotSupportedException">The current <see cref="T:System.IO.Compression.DeflateStream" /> implementation does not support the write operation.</exception>
        /// <exception cref="T:System.InvalidOperationException">The write operation cannot be performed because the stream is closed.</exception>
        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback cback, object state)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (!CanWrite)
            {
                throw new InvalidOperationException("This stream does not support writing");
            }
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", "Must be >= 0");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", "Must be >= 0");
            }
            if (count + offset > buffer.Length)
            {
                throw new ArgumentException("Buffer too small. count/offset wrong.");
            }
            WriteMethod writeMethod = WriteInternal;

            return(writeMethod.BeginInvoke(buffer, offset, count, cback, state));
        }
예제 #2
0
        private string Write(string content, IEnumerable <NextResult> executionPath, WriteMethod writeMethod = WriteMethod.UseStreamWriter)
        {
            foreach (NextResult next in executionPath)
            {
                switch (writeMethod)
                {
                case WriteMethod.UseStreamWriter:
                {
                    StreamWriter writer = next.Value.FileHandle.CreateStreamWriter();
                    writer.Write(content);
                    writer.Flush();
                    return(content);
                }

                case WriteMethod.AppendProperty:
                {
                    next.Value.FileHandle.Append = content;
                    return(content);
                }

                case WriteMethod.AppendLineProperty:
                {
                    next.Value.FileHandle.AppendLine = content;
                    return(content + Environment.NewLine);
                }
                }
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// Writes the specified matches to <see cref="OutputFile" />.
        /// </summary>
        /// <param name="matches">The collection of matches to write.</param>
        private void WriteMatches(MatchCollection matches)
        {
            WriteMethod writeMethod = new WriteMethod(this.WriteXml);

            using (StreamWriter writer = new StreamWriter(OutputFile.FullName)) {
                writeMethod(matches, writer);
            }
        }
예제 #4
0
        public string Run(Method method)
        {
            WriteMethod  writeMethod = provider.GetRequiredService <WriteMethod>();
            StringWriter writer      = new StringWriter();

            writer.Run(writeMethod, method);
            return(writer.ToString().RemoveCarriageReturn());
        }
예제 #5
0
        private AccountingPolicy CreateAccountingPolicyItem(Warehouse warehouse, WriteMethod writeMethod)
        {
            var accountingPolicy = new AccountingPolicy();

            accountingPolicy.Warehouse   = warehouse;
            accountingPolicy.WriteMethod = writeMethod;


            return(accountingPolicy);
        }
예제 #6
0
        public void Run(Method method, string expected)
        {
            WriteMethod  writeMethod = host.Provider.GetRequiredService <WriteMethod>();
            StringWriter writer      = new StringWriter();

            writer.Run(writeMethod, method);
            string actual = writer.ToString().RemoveCarriageReturn();

            Assert.Equal(expected, actual);
        }
예제 #7
0
        public void TestFileDoesExistAndOverwriteFile([Values(WriteMethod.UseStreamWriter, WriteMethod.AppendProperty, WriteMethod.AppendLineProperty)] WriteMethod writeMethod)
        {
            Directory.CreateDirectory(defaultFolderPath);
            System.IO.File.WriteAllText(defaultFilePath, "!@#", Encoding.UTF7);

            var result = Execute(defaultFilePath, DoesNotExistOptions.CreateFile, ExistOptions.OverwriteFile, codepage: TextCodepage.UTF7);

            Assert.AreEqual(defaultFilePath, result.Value);
            AssertExecutionPath(defaultFilePath, result.ExecutionPathResult);
            string expectedOutput = Write("↨ₐᾗ", result.ExecutionPathResult, writeMethod);

            Assert.AreEqual(expectedOutput, System.IO.File.ReadAllText(defaultFilePath, Encoding.UTF7));
        }
예제 #8
0
        public void EX2_1()
        {
            WriteMethod methodCall = SendToFile;

            if (methodCall())
            {
                Console.WriteLine("Success!");
            }
            else
            {
                Console.WriteLine("File write operation failed.");
            }
        }
    public static void Main()
    {
        OutputTarget output     = new OutputTarget();
        WriteMethod  methodCall = output.SendToFile;

        if (methodCall())
        {
            Console.WriteLine("Success!");
        }
        else
        {
            Console.WriteLine("File write operation failed.");
        }
    }
예제 #10
0
        public static void WriteToTarget()
        {
            WriteMethod methodCall = OutputTarget.WriteToConsole;

            if (methodCall())
            {
                Console.WriteLine("success");
            }

            Func <bool> func = (() => OutputTarget.WriteToConsole());

            if (func())
            {
                Console.WriteLine("success");
            }
        }
예제 #11
0
        /// <summary>Ends an asynchronous write operation.</summary>
        /// <param name="asyncResult">A reference to the outstanding asynchronous I/O request.</param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="asyncResult" /> is null.</exception>
        /// <exception cref="T:System.ArgumentException">
        ///   <paramref name="asyncResult" /> did not originate from a <see cref="M:System.IO.Compression.DeflateStream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)" /> method on the current stream.</exception>
        /// <exception cref="T:System.Exception">An exception was thrown during a call to <see cref="M:System.Threading.WaitHandle.WaitOne" />.</exception>
        /// <exception cref="T:System.InvalidOperationException">The stream is null.</exception>
        /// <exception cref="T:System.InvalidOperationException">The end write call is invalid.</exception>
        public override void EndWrite(IAsyncResult async_result)
        {
            if (async_result == null)
            {
                throw new ArgumentNullException("async_result");
            }
            AsyncResult asyncResult = async_result as AsyncResult;

            if (asyncResult == null)
            {
                throw new ArgumentException("Invalid IAsyncResult", "async_result");
            }
            WriteMethod writeMethod = asyncResult.AsyncDelegate as WriteMethod;

            if (writeMethod == null)
            {
                throw new ArgumentException("Invalid IAsyncResult", "async_result");
            }
            writeMethod.EndInvoke(async_result);
        }
예제 #12
0
파일: GZipper.cs 프로젝트: Vidilin/Gzipper
 public GZipper(string sourceFileName, string destinationFileName, WorkMode mode, bool needProcessInfo = false)
     : base(sourceFileName, destinationFileName, needProcessInfo)
 {
     lastWritedBlockId = 0;
     this.mode         = mode;
     this.modeMessage  = mode.ToString();
     if (mode == WorkMode.Compress)
     {
         this.reader = new CompressReader(sourceFileName, blockSize);
         work        = CompressWork;
         write       = CompressWrite;
     }
     else if (mode == WorkMode.Decompress)
     {
         this.reader = new DecompressReader(sourceFileName, blockSize);
         work        = DecompressWork;
         write       = DecompressWrite;
     }
     else
     {
         throw new InvalidOperationException("Unknown work mode");
     }
 }
예제 #13
0
        public override void EndWrite(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }

            AsyncResult ares = asyncResult as AsyncResult;

            if (ares == null)
            {
                throw new ArgumentException("Invalid IAsyncResult", "asyncResult");
            }

            WriteMethod w = ares.AsyncDelegate as WriteMethod;

            if (w == null)
            {
                throw new ArgumentException("Invalid IAsyncResult", "asyncResult");
            }

            w.EndInvoke(asyncResult);
            return;
        }
예제 #14
0
		public override IAsyncResult BeginWrite (byte [] buffer, int offset, int count,
							AsyncCallback cback, object state)
		{
			if (disposed)
				throw new ObjectDisposedException (GetType ().FullName);

			if (!CanWrite)
				throw new InvalidOperationException ("This stream does not support writing");

			if (buffer == null)
				throw new ArgumentNullException ("buffer");

			if (count < 0)
				throw new ArgumentOutOfRangeException ("count", "Must be >= 0");

			if (offset < 0)
				throw new ArgumentOutOfRangeException ("offset", "Must be >= 0");

			if (count + offset > buffer.Length)
				throw new ArgumentException ("Buffer too small. count/offset wrong.");

			WriteMethod w = new WriteMethod (WriteInternal);
			return w.BeginInvoke (buffer, offset, count, cback, state);			
		}
예제 #15
0
        /// <summary>
        /// Sets the mode.
        /// </summary>
        /// <param name="mode">The mode.</param>
        /// <returns></returns>
        public bool SetMode(byte mode)
        {
            switch (mode)
            {
            case 4: { WriteSettings(VGA320x200x4); width = 320; height = 200; colors = 4; writeMethod = WriteMethod.Pixel2; return(true); }

            case 5: { WriteSettings(VGA320x200x4); width = 320; height = 200; colors = 4; writeMethod = WriteMethod.Pixel2; return(true); }

            //case 11: { WriteSettings(VGA640x480x2); width = 640; height = 480; colors = 2; writeMethod = WriteMethod.xxx; return true; }
            //case 12: { WriteSettings(VGA640x480x16); width = 640; height = 480; colors = 16; writeMethod = WriteMethod.xxx; return true; }
            case 13: { WriteSettings(VGA320x200x256); width = 320; height = 200; colors = 256; writeMethod = WriteMethod.Pixel8; return(true); }

            // Custom Standard Modes:
            //case 99: { WriteSettings(VGA720x480x16); width = 720; height = 480; colors = 16; writeMethod = WriteMethod.xxx; return true; }
            default: { return(false); }
            }
        }
예제 #16
0
 /// <summary>
 /// Writes the specified matches to <see cref="OutputFile" />.
 /// </summary>
 /// <param name="matches">The collection of matches to write.</param>
 private void WriteMatches(MatchCollection matches) {
     WriteMethod writeMethod = new WriteMethod(this.WriteXml);
     using (StreamWriter writer = new StreamWriter(OutputFile.FullName)) {
         writeMethod(matches, writer);
     }
 }
예제 #17
0
        public void Write(WriteMethod method, int pin, int value)
        {
            var message = new byte[] { MESSAGE, (byte)method, (byte)pin, (byte)value };

            _port.Write(message, 0, message.Length);
        }
예제 #18
0
파일: GenericVGA.cs 프로젝트: hj1980/Mosa
 /// <summary>
 /// Sets the mode.
 /// </summary>
 /// <param name="mode">The mode.</param>
 /// <returns></returns>
 public bool SetMode(byte mode)
 {
     switch (mode) {
         case 4: { WriteSettings(VGA320x200x4); width = 320; height = 200; colors = 4; writeMethod = WriteMethod.Pixel2; return true; }
         case 5: { WriteSettings(VGA320x200x4); width = 320; height = 200; colors = 4; writeMethod = WriteMethod.Pixel2; return true; }
         //case 11: { WriteSettings(VGA640x480x2); width = 640; height = 480; colors = 2; writeMethod = WriteMethod.xxx; return true; }
         //case 12: { WriteSettings(VGA640x480x16); width = 640; height = 480; colors = 16; writeMethod = WriteMethod.xxx; return true; }
         case 13: { WriteSettings(VGA320x200x256); width = 320; height = 200; colors = 256; writeMethod = WriteMethod.Pixel8; return true; }
         // Custom Standard Modes:
         //case 99: { WriteSettings(VGA720x480x16); width = 720; height = 480; colors = 16; writeMethod = WriteMethod.xxx; return true; }
         default: { return false; }
     }
 }