コード例 #1
0
        /// <summary>
        /// Creates a concrete instance of IXDBroadcast used to broadcast messages to
        /// other processes in one or more modes.
        /// </summary>
        /// <param name="modes">One or more transport mechanisms to use for interprocess communication.</param>
        /// <returns>The concreate instance of IXDBroadcast</returns>
        public static IXDBroadcast CreateBroadcast(params XDTransportMode[] modes)
        {
            if (modes.Length == 0)
            {
                throw new ArgumentException("At least one transport mode must be defined.");
            }
            if (modes.Length == 1)
            {
                switch (modes[0])
                {
                case XDTransportMode.IOStream:
                    return(new XDIOStreamBroadcast());

                case XDTransportMode.MailSlot:
                    return(new XDMailSlotBroadcast(false));

                default:
                    return(new XDWindowsMessaging());
                }
            }
            else
            {
                // ensure only one of each type added
                Dictionary <XDTransportMode, IXDBroadcast> singleItems = new Dictionary <XDTransportMode, IXDBroadcast>();
                foreach (XDTransportMode mode in modes)
                {
                    // only add one of each mode
                    if (!singleItems.ContainsKey(mode))
                    {
                        singleItems.Add(mode, XDBroadcast.CreateBroadcast(mode));
                    }
                }
                return(new XDMultiBroadcast(singleItems.Values));
            }
        }
コード例 #2
0
        /// <summary>
        /// The non-obsolete constructor used internally for creating new instances of XDListener.
        /// </summary>
        /// <param name="nonObsolete"></param>
        internal XDListener(bool nonObsolete)
        {
            // create a top-level native window
            CreateParams p = new CreateParams();

            p.Width   = 0;
            p.Height  = 0;
            p.X       = 0;
            p.Y       = 0;
            p.Caption = string.Concat("TheCodeKing.Net.XDServices.", Guid.NewGuid().ToString());
            p.Parent  = IntPtr.Zero;
            base.CreateHandle(p);

            this.networkRelay = new NetworkRelayListener(XDBroadcast.CreateBroadcast(XDTransportMode.WindowsMessaging),
                                                         XDListener.CreateListener(XDTransportMode.MailSlot));
        }
コード例 #3
0
        /// <summary>
        /// Creates an instance of IXDBroadcast with the otption to propagate over the local network.
        /// </summary>
        /// <param name="mode">The broadcast mode.</param>
        /// <param name="propagateNetwork">true to propagate messages over the local network.</param>
        /// <returns></returns>
        public static IXDBroadcast CreateBroadcast(XDTransportMode mode, bool propagateNetwork)
        {
            // MailSlots can communicate over a network by default, so
            // no need to use the NetworkRelayBroadcast instance for this type.
            if (mode == XDTransportMode.MailSlot)
            {
                return(new XDMailSlotBroadcast(propagateNetwork));
            }
            IXDBroadcast broadcast = CreateBroadcast(mode);

            if (propagateNetwork)
            {
                // create a wrapper to broadcast that will also send messages over network
                return(new NetworkRelayBroadcast(broadcast, XDBroadcast.CreateBroadcast(XDTransportMode.MailSlot, true)));
            }
            else
            {
                return(broadcast);
            }
        }