コード例 #1
0
 private void Send(GaCmdIn toSend)
 {
     lock (WriteLock)
     {
         toSend.WriteDelimitedTo(Stream);
         Stream.Flush();
     }
 }
コード例 #2
0
        private void SendClipboardData(ClipboardType type)
        {
            if (type == ClipboardType.None)
            {
                var types = (IEnumerable <ClipboardType>)MainForm.Invoke(new Func <IEnumerable <ClipboardType> >(MainForm.GetClipboardTypes));

                var message = new GaCmdIn
                {
                    Clipboard = new ClipboardMessage
                    {
                        ContentTypes = new ClipboardTypes
                        {
                        }
                    }
                };

                message.Clipboard.ContentTypes.Types_.AddRange(types);
                Send(message);

                return;
            }
            else if (type == ClipboardType.Text)
            {
                var clipboardText = (string)MainForm.Invoke(new Func <string>(MainForm.GetClipboardText));
                if (clipboardText != null)
                {
                    var message = new GaCmdIn();
                    message.Clipboard = new ClipboardMessage();
                    message.Clipboard.ClipboardContents = ByteString.CopyFromUtf8(clipboardText.Replace(Environment.NewLine, "\n"));
                    Send(message);
                }
            }
            else if (type == ClipboardType.Image)
            {
                var image = (byte[])MainForm.Invoke(new Func <byte[]>(MainForm.GetClipboardImage));
                if (image != null)
                {
                    var message = new GaCmdIn();
                    message.Clipboard = new ClipboardMessage();
                    message.Clipboard.ClipboardContents = ByteString.CopyFrom(image);
                    Send(message);
                }
            }
        }