Beispiel #1
0
        public static void Main(string[] args)
        {
            Callback      callback = new Callback();
            NetTcpBinding binding  = new NetTcpBinding();

            binding.MaxReceivedMessageSize = int.MaxValue;
            binding.Security.Mode          = SecurityMode.None;
            string address = "net.tcp://localhost:8080/Perfmon/";
            DuplexChannelFactory <IPerfmonService> factory = new DuplexChannelFactory <IPerfmonService>(callback, binding, address);
            IPerfmonService service = factory.CreateChannel();

            service.Join();

            CategoryList categories = service.List();

            categories.Sort((a, b) => a.Name.CompareTo(b.Name));

            /*
             * foreach (Category category in categories)
             * {
             *  Console.WriteLine(category.Name);
             * }
             */

            service.Subscribe("Processor", "% Processor Time");
            //service.Subscribe("Memory", "Available MBytes");
            Console.ReadLine();

            service.Leave();
        }
Beispiel #2
0
        public void OnFault(object sender, EventArgs e)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                var mainWindow = (MainWindow)Application.Current.MainWindow;

                ((IClientChannel)service).Abort();

                string message;
                if (hasConnectedOnce)
                {
                    message = "Lost connection to {0}:{1}. Try reconnecting?";
                }
                else
                {
                    message = "Couldn't connect to {0}:{1}. Try reconnecting?";
                }

                if (MessageBox.Show(string.Format(message, Host, Port), "Performance Monitor for WCF",
                                    MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    service = factory.CreateChannel();
                    ((IClientChannel)service).Faulted += OnFault;

                    try
                    {
                        service.Join();

                        foreach (CategoryItem categoryItem in MachineItem.CategoryItems)
                        {
                            foreach (CounterItem counterItem in categoryItem.CounterItems)
                            {
                                if (counterItem.IsChecked == true)
                                {
                                    if (!TrySubscribe(categoryItem.Name, counterItem.Name))
                                    {
                                        counterItem.IsChecked = false;
                                    }
                                }
                            }
                        }
                    }
                    catch (CommunicationException) { }
                }
                else
                {
                    ClearTreeView();
                    mainWindow.Connections.Remove(this);
                }
            });
        }
Beispiel #3
0
        public void Open()
        {
            try
            {
                service.Join();
                hasConnectedOnce = true;

                using (new WaitCursor())
                {
                    PopulateTreeView();
                }
            }
            catch (CommunicationException) { }
        }