// use funcBeforeSend to populate message. protected virtual bool SendMessage(Action <IMessage> funcBeforeSend) { Guard.ThrowIfNull("funcBeforeSend", funcBeforeSend); if (_peer == null) { return(false); } var host = ServiceContainer.GetService <IHostApplication>(); if (host == null) { return(false); } var msg = host.CreateMessage(); if (msg != null) { funcBeforeSend(msg); var result = _peer.Notify(msg); return(TResult.Succeeded(result)); } return(false); }
public override int Read(byte[] buffer, int offset, int count) { IntPtr unmanaged = GetUnmanagedBuffer(ref count); try { int readBytes = 0; if (TResult.Succeeded(BaseStream.Read(unmanaged, count, ref readBytes))) { for (int i = 0; i < readBytes; i++) { buffer[offset + i] = Marshal.ReadByte(unmanaged, i); } return(readBytes); } } finally { ReleaseUnmanagedBuffer(unmanaged); } return(0); }
public override long Seek(long offset, SeekOrigin origin) { long pos = 0; if (TResult.Succeeded(BaseStream.Seek(offset, SeekOriginSeekMode(origin), ref pos))) { return(pos); } return(-1); }
public static IMessage CreateMessage(this IHostApplication host) { Guard.ThrowIfNull("host", host); var msgType = typeof(IMessage); var iid = msgType.GUID; IntPtr ptr = IntPtr.Zero; var result = host.CreateInstance(ref iid, ref iid, ref ptr); if (TResult.Succeeded(result)) { return((IMessage)Marshal.GetTypedObjectForIUnknown(ptr, msgType)); } return(null); }