public void SendToChannel(string channelName, string message)
 {
     if (string.IsNullOrEmpty(channelName))
     {
         throw new ArgumentNullException(channelName, "The channel name must be defined");
     }
     if (message == null)
     {
         throw new ArgumentNullException(message, "The messsage packet cannot be null");
     }
     if (string.IsNullOrEmpty(channelName))
     {
         throw new ArgumentException("The channel name may not contain the ':' character.", "channelName");
     }
     // create a DataGram instance, and ensure memory is freed
     using (DataGram dataGram = new DataGram(channelName, message))
     {
         // Allocate the DataGram to a memory address contained in COPYDATASTRUCT
         Native.COPYDATASTRUCT dataStruct = dataGram.ToStruct();
         // Use a filter with the EnumWindows class to get a list of windows containing
         // a property name that matches the destination channel. These are the listening
         // applications.
         WindowEnumFilter filter  = new WindowEnumFilter(XDListener.GetChannelKey(channelName));
         WindowsEnum      winEnum = new WindowsEnum(filter.WindowFilterHandler);
         foreach (IntPtr hWnd in winEnum.Enumerate())
         {
             IntPtr outPtr = IntPtr.Zero;
             // For each listening window, send the message data. Return if hang or unresponsive within 1 sec.
             Native.SendMessageTimeout(hWnd, Native.WM_COPYDATA, IntPtr.Zero, ref dataStruct, Native.SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 1000, out outPtr);
         }
     }
 }
Exemplo n.º 2
0
        public IXDListener CreateListener(XDListener.XDMessageHandler handler)
        {
            IXDListener listener = XDListener.CreateListener(Mode, !Propagate);

            listener.RegisterChannel(Name);
            listener.MessageReceived += handler;
            return(listener);
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        internal XDIOStreamListener()
        {
            this.watcherList = new Dictionary <string, FileSystemWatcher>(StringComparer.InvariantCultureIgnoreCase);

            // ensure there is a network watcher for this mode, the implementation ensures only one is active at
            // any one time
            this.networkRelay = new NetworkRelayListener(XDBroadcast.CreateBroadcast(XDTransportMode.IOStream),
                                                         XDListener.CreateListener(XDTransportMode.MailSlot));
        }
 public static void StartPrcMessaging()
 {
     if (_broadcast != null)
     {
         return;
     }
     _broadcast = XDBroadcast.CreateBroadcast(XDTransportMode.WindowsMessaging, false);
     _listener  = XDListener.CreateListener(XDTransportMode.WindowsMessaging);
     _listener.MessageReceived += Listener_MessageReceived;
     _listener.RegisterChannel(channel);
 }
        /// <summary>
        /// Default constructor.
        /// </summary>
        public TestService()
        {
            InitializeComponent();
            this.ServiceName = "Test Service";

            //only the following mode is supported in windows services
            broadcast = XDBroadcast.CreateBroadcast(XDTransportMode.IOStream);
            listener  = XDListener.CreateListener(XDTransportMode.IOStream);
            listener.MessageReceived += new XDListener.XDMessageHandler(OnMessageReceived);
            listener.RegisterChannel("Status");
            listener.RegisterChannel("Channel1");
            listener.RegisterChannel("Channel2");
        }
Exemplo n.º 6
0
        public CommManager()
        {
            this.otherInstances = new List <LogViewerInstance>();

            this.listener  = XDListener.CreateListener(XDTransportMode.WindowsMessaging);
            this.broadcast = XDBroadcast.CreateBroadcast(XDTransportMode.WindowsMessaging, false);

            this.listener.RegisterChannel(myID.ToString());  //Channel only for me
            this.listener.RegisterChannel(ChannelBroadcast); //Channel for everyone

            listener.MessageReceived += new XDListener.XDMessageHandler(listener_MessageReceived);
            this.MainWindowHandle     = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initialize the broadcast and listener mode.
        /// </summary>
        /// <param name="mode">The new mode.</param>
        public static void InitializeMode(XDTransportMode mode)
        {
            if (listener != null)
            {
                // ensure we dispose any previous listeners, dispose should aways be
                // called on IDisposable objects when we are done with it to avoid leaks
                listener.Dispose();
            }
            listener = XDListener.CreateListener(mode);

            // attach the message handler
            listener.MessageReceived += OnMessageReceived;

            listener.RegisterChannel(CHANNEL_NAME);

            // create an instance of IXDBroadcast using the given mode,
            // note IXDBroadcast does not implement IDisposable
            broadcast = XDBroadcast.CreateBroadcast(mode, false);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initialize the broadcast and listener mode.
        /// </summary>
        /// <param name="mode">The new mode.</param>
        private void InitializeMode(XDTransportMode mode)
        {
            if (listener != null)
            {
                // ensure we dispose any previous listeners, dispose should aways be
                // called on IDisposable objects when we are done with it to avoid leaks
                listener.Dispose();
            }

            // creates an instance of the IXDListener object using the given implementation
            listener = XDListener.CreateListener(mode);

            // attach the message handler
            listener.MessageReceived += new XDListener.XDMessageHandler(OnMessageReceived);

            // register the channels we want to listen on
            if (statusCheckBox.Checked)
            {
                listener.RegisterChannel("Status");
            }

            // register if checkbox is checked
            if (channel1Check.Checked)
            {
                listener.RegisterChannel("Channel1");
            }

            // register if checkbox is checked
            if (channel2Check.Checked)
            {
                listener.RegisterChannel("Channel2");
            }

            // if we already have a broadcast instance
            if (broadcast != null)
            {
                broadcast.SendToChannel("Status", string.Format("{0} is changing mode to {1}", this.Handle, mode));
            }

            // create an instance of IXDBroadcast using the given mode,
            // note IXDBroadcast does not implement IDisposable
            broadcast = XDBroadcast.CreateBroadcast(mode, propagateCheck.Checked);
        }
        public ProfilerWindow()
        {
            InitializeComponent();

            InitSkinGallery();

            if (!DesignMode)
            {
                // creates an instance of the IXDListener object using the given implementation
                listener = XDListener.CreateListener(XDTransportMode.IOStream);
                listener.MessageReceived += new XDListener.XDMessageHandler(OnMessageReceived);

                listener.RegisterChannel(Channels.Channel_1);
                listener.RegisterChannel(Channels.Channel_2);
                listener.RegisterChannel(Channels.Channel_3);
                listener.RegisterChannel(Channels.Channel_4);
                listener.RegisterChannel(Channels.Channel_5);
                listener.RegisterChannel(Channels.Channel_6);
                listener.RegisterChannel(Channels.Channel_7);
                listener.RegisterChannel(Channels.Channel_8);
                listener.RegisterChannel(Channels.Channel_9);
                listener.RegisterChannel(Channels.Channel_10);

                navChannel1.Tag  = channel_1;
                navChannel2.Tag  = channel_2;
                navChannel3.Tag  = channel_3;
                navChannel4.Tag  = channel_4;
                navChannel5.Tag  = channel_5;
                navChannel6.Tag  = channel_6;
                navChannel7.Tag  = channel_7;
                navChannel8.Tag  = channel_8;
                navChannel9.Tag  = channel_9;
                navChannel10.Tag = channel_10;

                channel_1.NavBarItem  = navChannel1;
                channel_2.NavBarItem  = navChannel2;
                channel_3.NavBarItem  = navChannel3;
                channel_4.NavBarItem  = navChannel4;
                channel_5.NavBarItem  = navChannel5;
                channel_6.NavBarItem  = navChannel6;
                channel_7.NavBarItem  = navChannel7;
                channel_8.NavBarItem  = navChannel8;
                channel_9.NavBarItem  = navChannel9;
                channel_10.NavBarItem = navChannel10;

                currentChannel = channel_1;
                this.Text      = "EntitySpaces Profiler - " + currentChannel.Name;
                esTracePacketBindingSource.DataSource = currentChannel.ChannelData;

                clock = new System.Threading.Timer(TimerCallback, null, 2000, 1500);

                //define color of user customized token
                lzbasetype.gFmtOpt.HighlightingElements[(int)TLzHighlightingElement.sfkUserCustomized].SetForegroundInRGB("#FF00FF");

                foreach (var obj in lzbasetype.gFmtOpt.HighlightingElements)
                {
                    if (obj.Foreground.ToString().ToLower() == "12632256")
                    {
                        obj.SetForegroundInRGB("#000000");
                    }
                }
                lzbasetype.gFmtOpt.AlignAliasInSelectList = false;

                //this.gridView1.BestFitColumns();
            }
        }
Exemplo n.º 10
0
        //--------------------------  form  ---------------------------//

        void FrmMainLoad(object sender, EventArgs e)
        {
            Debug.WriteLine("Main start: ");
            listener = new XDListener();
            listener.MessageReceived += new XDListener.XDMessageHandler(listener_MessageReceived);
            listener.RegisterChannel("NVMessage");

            bool kShift = (Control.ModifierKeys == Keys.Shift);

            bool created;

            s_event = new EventWaitHandle(false, EventResetMode.ManualReset, "Next-View", out created); //  instead of mutex
            if (created || kShift)                                                                      // 1st instance or shift key
            {
                if (Properties.Settings.Default.UpgradeRequired)
                {
                    Settings.Default.Upgrade();
                    Settings.Default.UpgradeRequired = false;
                    Settings.Default.Save( );
                }
                int wX;
                int wY;
                int wW = Settings.Default.MainW;
                int wH = Settings.Default.MainH;

                Multi.MainLoad(out wX, out wY);
                //Debug.WriteLine("open main 1 y: {0} ", wY);
                bool visible;
                // menu bar visible
                Rectangle screenRectangle = RectangleToScreen(this.ClientRectangle);
                int       titleHeight     = screenRectangle.Top - this.Top;
                Multi.FormShowVisible(out visible, ref wX, ref wY, wW, titleHeight);
                if (!visible)
                {
                    this.Left = wX;
                    this.Top  = wY;
                    //Debug.WriteLine("open main 2 y: {0} ", wY);
                }
                else
                {
                    Multi.FormShowVisible(out visible, ref wX, ref wY, wW, wH);
                    this.Left = wX;
                    this.Top  = wY;
                    //Debug.WriteLine("open main 3 y: {0} ", wY);
                }
                this.Width  = wW;
                this.Height = wH;

                string curDir     = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                string moPath     = curDir + @"\language\";
                string cultureStr = Settings.Default.Language;
                if (cultureStr == "")
                {
                    cultureStr = CultureInfo.InstalledUICulture.ToString();
                    Settings.Default.Language = cultureStr;
                }
                //Debug.WriteLine("Culture: " + cultureStr);
                T.SetCatalog(moPath, cultureStr);
                TranslateMainForm();
                tbNoGif();

                string recentPath = Settings.Default.RecentImgs;
                this.recentItem1.LoadList(recentPath);
                this.recentItem1.UpdateList();
                this.recentItem1.MaxItems   = 5;
                this.recentItem1.ItemClick += new System.EventHandler(recentItem_Click);
                this.recentItem1.UpdateList();

                //Debug.WriteLine("open main y: {0} ", Settings.Default.MainY);
            }
            else                            // 2nd instance, give image path to 1st instance and end this 2nd
            {
                string[] args        = Environment.GetCommandLineArgs();
                string   commandLine = "S";
                if (args.Length > 1)
                {
                    commandLine = args[1];
                }
                //Debug.WriteLine("send message:");
                XDBroadcast.SendToChannel("NVMessage", commandLine);                   // receive: listener_MessageReceived    // send is to itself as well, before exit
                // NvSendMsg();  does not work for strings,
                ExitApp();
            }
        }
Exemplo n.º 11
0
        public ProfilerWindow()
        {
            InitializeComponent();

            InitSkinGallery();

            bool canRunOffline = false;
            int  result;

            if (!DesignMode)
            {
                proxySettings.Load();

#if !PROFILER_TRIAL
                RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\EntitySpaces 2012", true);

                Crypto crypto = new Crypto();

                string id           = licensing.getUniqueID("C");
                string serialNumber = ""; // b69e3783-9f56-47a7-82e0-6eee6d0779bf

                if (key != null)
                {
                    try
                    {
                        serialNumber = (string)key.GetValue("Profiler_Number");
                    }
                    catch { }
                }


                string offlinePath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
                offlinePath += @"\EntitySpaces\ES2012\Interop.ADODB64X.dll";

                // See if we have registered our license
                result = licensing.ValidateLicense("profiler", serialNumber, System.Environment.MachineName, id, version, proxySettings);

                switch (result)
                {
                case 0:

                    // Try Registering it ...
                    int newResult = licensing.RegisterLicense("profiler", serialNumber, System.Environment.MachineName, id, version, proxySettings);

                    if (newResult == 1)
                    {
                        licensing.CreateSerialNumber2Key(key, "Profiler_Number2", id, false);
                        result = 1;
                    }
                    else
                    {
                        result = 0;
                    }
                    break;

                case 1:

                    licensing.CreateSerialNumber2Key(key, "Profiler_Number2", id, false);
                    try
                    {
                        File.Delete(offlinePath);
                    }
                    catch { }

                    break;

                case -1:

                    bool     isOffLine   = false;
                    DateTime offLineDate = DateTime.MinValue;
                    if (licensing.ReadSerialNumber2Key(key, "Profiler_Number2", id, out isOffLine, out offLineDate))
                    {
                        if (isOffLine)
                        {
                            if (File.Exists(offlinePath))
                            {
                                DateTime fileDate = licensing.OpenOfflineFile(offlinePath);

                                if (DateTime.Now > offLineDate)
                                {
                                    TimeSpan ts = DateTime.Now.Subtract(offLineDate);
                                    if (ts.Days < licensing.DaysTheyCanRunOffline)
                                    {
                                        if (fileDate < DateTime.Now)
                                        {
                                            canRunOffline = true;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            licensing.CreateSerialNumber2Key(key, "Profiler_Number2", id, true);
                            licensing.CreateOfflineFile(offlinePath);
                            canRunOffline = true;
                        }
                    }
                    break;
                }
#else
                Licensing license = new Licensing();
                string    id      = license.getUniqueID("C");

                result = licensing.ValidateLicense("trial", "b69e3783-9f56-47a7-82e0-6eee6d0779bf", System.Environment.MachineName, id, version, proxySettings);

                if (1 != result)
                {
                    result = licensing.RegisterLicense("trial", "b69e3783-9f56-47a7-82e0-6eee6d0779bf", System.Environment.MachineName, id, version, proxySettings);
                }
#endif

                if (result == 1 || (canRunOffline && result == -1))
                {
                    // creates an instance of the IXDListener object using the given implementation
                    listener = XDListener.CreateListener(XDTransportMode.IOStream);
                    listener.MessageReceived += new XDListener.XDMessageHandler(OnMessageReceived);

                    listener.RegisterChannel(Channels.Channel_1);
                    listener.RegisterChannel(Channels.Channel_2);
                    listener.RegisterChannel(Channels.Channel_3);
                    listener.RegisterChannel(Channels.Channel_4);
                    listener.RegisterChannel(Channels.Channel_5);
                    listener.RegisterChannel(Channels.Channel_6);
                    listener.RegisterChannel(Channels.Channel_7);
                    listener.RegisterChannel(Channels.Channel_8);
                    listener.RegisterChannel(Channels.Channel_9);
                    listener.RegisterChannel(Channels.Channel_10);

                    navChannel1.Tag  = channel_1;
                    navChannel2.Tag  = channel_2;
                    navChannel3.Tag  = channel_3;
                    navChannel4.Tag  = channel_4;
                    navChannel5.Tag  = channel_5;
                    navChannel6.Tag  = channel_6;
                    navChannel7.Tag  = channel_7;
                    navChannel8.Tag  = channel_8;
                    navChannel9.Tag  = channel_9;
                    navChannel10.Tag = channel_10;

                    channel_1.NavBarItem  = navChannel1;
                    channel_2.NavBarItem  = navChannel2;
                    channel_3.NavBarItem  = navChannel3;
                    channel_4.NavBarItem  = navChannel4;
                    channel_5.NavBarItem  = navChannel5;
                    channel_6.NavBarItem  = navChannel6;
                    channel_7.NavBarItem  = navChannel7;
                    channel_8.NavBarItem  = navChannel8;
                    channel_9.NavBarItem  = navChannel9;
                    channel_10.NavBarItem = navChannel10;

                    currentChannel = channel_1;
                    this.Text      = "EntitySpaces Profiler - " + currentChannel.Name;
                    esTracePacketBindingSource.DataSource = currentChannel.ChannelData;

                    clock = new System.Threading.Timer(TimerCallback, null, 2000, 1500);

                    //define color of user customized token
                    lzbasetype.gFmtOpt.HighlightingElements[(int)TLzHighlightingElement.sfkUserCustomized].SetForegroundInRGB("#FF00FF");

                    foreach (var obj in lzbasetype.gFmtOpt.HighlightingElements)
                    {
                        if (obj.Foreground.ToString().ToLower() == "12632256")
                        {
                            obj.SetForegroundInRGB("#000000");
                        }
                    }
                    lzbasetype.gFmtOpt.AlignAliasInSelectList = false;
                }


                //this.gridView1.BestFitColumns();
            }
        }