示例#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();
        }
示例#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);
                }
            });
        }
示例#3
0
        public Connection(string host, int port)
        {
            Host        = host;
            Port        = port;
            MachineItem = new MachineItem(host, port);

            hasConnectedOnce   = false;
            ignoreCheckedEvent = false;

            NetTcpBinding binding = new NetTcpBinding();

            binding.MaxReceivedMessageSize = int.MaxValue;
            binding.Security.Mode          = SecurityMode.None;
            string address = string.Format("net.tcp://{0}:{1}/Perfmon/", host, port);

            factory = new DuplexChannelFactory <IPerfmonService>(this, binding, address);

            service = factory.CreateChannel();
            ((IClientChannel)service).Faulted += OnFault;
        }