本文整理汇总了C#中System.IO.Pipes.NamedPipeClientStream.WriteByte方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeClientStream.WriteByte方法的具体用法?C# NamedPipeClientStream.WriteByte怎么用?C# NamedPipeClientStream.WriteByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Pipes.NamedPipeClientStream
的用法示例。
在下文中一共展示了NamedPipeClientStream.WriteByte方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
using (Mutex mutex = new Mutex(false, @"Global\simpledlnaguilock")) {
#if !DEBUG
if (!mutex.WaitOne(0, false)) {
using (var pipe = new NamedPipeClientStream(".", "simpledlnagui", PipeDirection.Out)) {
try {
pipe.Connect(10000);
pipe.WriteByte(1);
}
catch (Exception) {
}
return;
}
}
GC.Collect();
#endif
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (var main = new FormMain()) {
try {
Application.Run(main);
}
catch (Exception ex) {
log4net.LogManager.GetLogger(typeof(Program)).Fatal("Encountered fatal unhandled exception", ex);
throw;
}
}
}
}
示例2: Main
private static void Main()
{
using (var mutex = new Mutex(false, @"Global\simpledlnaguilock")) {
#if !DEBUG
if (!mutex.WaitOne(0, false)) {
using (var pipe = new NamedPipeClientStream(
".", "simpledlnagui", PipeDirection.Out)) {
try {
pipe.Connect(10000);
pipe.WriteByte(1);
}
catch (Exception) {
}
return;
}
}
GC.Collect();
#endif
using (var main = new FormMain()) {
try {
Application.Run(main);
}
catch (Exception ex) {
log4net.LogManager.GetLogger(typeof(Program)).Fatal(
"Encountered fatal unhandled exception", ex);
MessageBox.Show(
string.Format(
"Encountered an unhandled error. Will exit now.\n\n{0}\n{1}",
ex.Message, ex.StackTrace),
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
throw;
}
}
}
}
示例3: SendDataMessage
private static void SendDataMessage(NamedPipeClientStream pipe, String xml)
{
try
{
// Write data length, string and null
_logger.LogMsg(Level.Debug, String.Format("Getting byte array from XML string for sending (data pipe)."));
{
// Write data length to stream. This is a 32-bit integer in big endian byte order.
int data_len = xml.Length + 1;
byte[] ar_bytes = BitConverter.GetBytes(data_len);
for (int ii = 0; ii < 4; ii++)
{
pipe.WriteByte(ar_bytes[3 - ii]);
}
Debug.WriteLine(String.Format("Writing XML to stream: {0} chars", xml.Length.ToString()));
Byte[] xml_buf = GetBytes(xml);
for (int ii = 0; ii < xml_buf.Length; ii++)
{
if (xml_buf[ii] != 0x00)
{
pipe.WriteByte(xml_buf[ii]);
}
}
Debug.WriteLine("Writing 0x00 to stream.");
pipe.WriteByte(0x00);
pipe.Flush();
}
}
catch (System.Exception ex)
{
Debug.WriteLine("Error in SendDateMessage(): " + ex.Message);
throw ex;
}
}
示例4: SendCommandMessage
private static void SendCommandMessage(NamedPipeClientStream pipe, String xml)
{
try
{
// Write data length (4 byte integer in big-endian byte order), xml message (string) and final null byte.
_logger.LogMsg(Level.Debug, String.Format("Sending Command Response message:\r\n{0}", xml));
int data_len = xml.Length + 1;
byte[] ar_bytes = BitConverter.GetBytes(data_len);
//Array.Reverse(ar_bytes);
// Write the length out in reverse (big-endian byte order).
for (int ii = 0; ii < 4; ii++)
{
pipe.WriteByte(ar_bytes[3-ii]);
}
// Write the XML string 1 byte at a time - no nulls.
Debug.WriteLine(String.Format("Writing XML to stream: total {0} chars", xml.Length.ToString()));
Byte[] xml_buf = GetBytes(xml);
for (int ii = 0; ii < xml_buf.Length; ii++)
{
if (xml_buf[ii] != 0x00)
{
pipe.WriteByte(xml_buf[ii]);
}
}
// Write the final null byte that QlikView is expecting.
pipe.WriteByte(0x00);
// TO DO: is this Flush() necessary?
pipe.Flush();
// Wait for QlikView to read from the pipe.
// _logger.LogMsg(Level.Debug, "Waiting for pipe drain on command pipe.");
// pipe.WaitForPipeDrain();
// _logger.LogMsg(Level.Debug, "Pipe drain complete.");
}
catch (System.Exception ex)
{
Debug.WriteLine("Error in ReadNextCommandMessage(): " + ex.Message);
throw ex;
}
}
示例5: ProcessReadFromLog
protected void ProcessReadFromLog(NamedPipeClientStream pipe, CancellationToken token)
{
//Just doing this to clear the stream for the next command.
ReadToEnd(pipe);
string path = Path.Combine(VM_SelfManager.LogPath, VMName + ".log");
FileStream Log = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read);
// This is only complicated in order to handle cases of WAY oversized log files.
int reps = (int)(Log.Length / int.MaxValue);
byte[] data = new byte[(reps==0 ? (int)(Log.Length % int.MaxValue) : int.MaxValue)];
//read the log
Log.Seek(0, SeekOrigin.Begin);
for (int i = 0; i <= reps; i++)
{
Log.Read(data, 0, (i == reps ? (int) (Log.Length%int.MaxValue) : int.MaxValue));
//write it immediately so we can grab the next set if needed...
pipe.Write(data, 0, (i == reps ? (int) (Log.Length%int.MaxValue) : int.MaxValue));
}
pipe.WriteByte(0x1A); // writes an 'end of stream' character so the client knows that all has been sent.
}
示例6: GetResponse
private Response GetResponse(Request request)
{
_pipeClient = CreateClientPipe();
TryConnect(_pipeClient);
_pipeClient.WriteByte((byte)request);
_pipeClient.WriteByte((byte)_pos);
_pipeClient.WaitForPipeDrain();
Response response = (Response)_pipeClient.ReadByte();
return response;
}
示例7: Main
public static void Main(string[] Args)
{
if (Args.Length > 0)
{
if (Args[0] == "spawnclient")
{
NamedPipeClientStream pipeClient =
new NamedPipeClientStream(".", "testpipe",
PipeDirection.InOut, PipeOptions.None,
TokenImpersonationLevel.Impersonation);
Console.WriteLine("Connecting to server...\n");
pipeClient.Connect();
SampleModel.SampleObject obj = new SampleObject() { PDFURL = "star" };
BinaryFormatter bf = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream())
{
bf.Serialize(ms, obj);
pipeClient.WriteByte(ms.ToArray());
//pipeClient.Write(, 0, ms.ToArray().Length);
}
//StreamWriter sw = new StreamWriter(pipeClient);
//sw.WriteLine("시작");
//sw.Flush();
//StreamString ss = new StreamString(pipeClient);
//// Validate the server's signature string
//if (ss.ReadString() == "I am the one true server!")
//{
// // The client security token is sent with the first write.
// // Send the name of the file whose contents are returned
// // by the server.
// ss.WriteString("c:\\textfile.txt");
// // Print the file to the screen.
// Console.Write(ss.ReadString());
//}
//else
//{
// Console.WriteLine("Server could not be verified.");
//}
//pipeClient.Close();
// Give the client process some time to display results before exiting.
Thread.Sleep(4000);
pipeClient.Close();
}
}
else
{
Console.WriteLine("\n*** Named pipe client stream with impersonation example ***\n");
StartClients();
}
}