示例#1
0
        public async void ConnectAsync()
        {
            await Task.Delay(100);

            string BaseUri = ConfigurationManager.AppSettings.Get("host");

            connection = new HubConnection(BaseUri);
            hubProxy   = connection.CreateHubProxy("hubtrireksa");
            //  hubProxy.On<dynamic>("broadcastCustomer", (u) => OnUpdateCUstomer?.Invoke(u));
            hubProxy.On <dynamic>("onAddCustomer", (u) => OnAddCustomer?.Invoke(u));
            hubProxy.On <dynamic>("onAddCity", (u) => OnAddCity?.Invoke(u));
            hubProxy.On <dynamic>("onAddAgent", (u) => OnAddAgent?.Invoke(u));
            hubProxy.On <dynamic>("onAddPort", (u) => OnAddPort?.Invoke(u));

            connection.Reconnecting += Reconnecting;
            connection.Reconnected  += Reconnected;
            connection.Closed       += Disconnected;

            ServicePointManager.DefaultConnectionLimit = 10;
            try
            {
                //await connection.Start();
            }
            catch (Exception ex)
            {
                if (ResourcesBase.HomeVM != null)
                {
                    ResourcesBase.HomeVM.BarMessage = ex.Message;
                }
                else
                {
                    Console.WriteLine(ex.Message); //throw new SystemException(ex.Message);
                }
            }
        }
        public CustomersForm()
        {
            InitializeComponent();

            Load += (sender, args) => OnLoad?.Invoke();

            customersDgv.SelectionChanged += (sender, args) => OnCustomerSelectionChanged?.Invoke(Convert.ToInt32(customersDgv.CurrentRow.Cells["Id"].Value));

            customersDgv.CellEndEdit += (sender, args) =>
            {
                var currentCustomerId = Convert.ToInt32(customersDgv.CurrentRow.Cells["Id"].Value);
                var customer          = new Customer(
                    customersDgv.CurrentRow.Cells["Name"].Value.ToString(),
                    (float)customersDgv.CurrentRow.Cells["Rating"].Value);
                OnUpdateCustomer?.Invoke(currentCustomerId, customer);
            };

            addCustomerButton.Click += (sender, args) =>
            {
                var name     = customerNameTextBox.Text.Trim();
                var customer = new Customer(name);
                OnAddCustomer?.Invoke(customer);
            };
        }