Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagec#
using Connexion.Core;
using System.Threading.Tasks;
using System.Windows.Input;
namespace ProxySample1
{
  public class ProxySample1UIViewModel : ViewModelBase
  {
    private ProxySample1Configuration m_Config;
    private IDeviceUIParams m_DeviceUIParams;
    private IDiagnostics m_Proxy;
    public ProxySample1UIViewModel(ProxySample1Configuration config, IDeviceUIParams deviceUIParams)
    {
      m_Config = config;
      m_DeviceUIParams = deviceUIParams;
      m_Proxy = deviceUIParams.GetServerDeviceProxy<IDiagnostics>(); // <-- creation of the proxy
    }
    public ProxySample1Configuration Configuration
    {
      get { return m_Config; }
    }
    private RelayCommand m_GetDiagnosticsCommand;
    public ICommand GetDiagnosticsCommand
    {
      get { return m_GetDiagnosticsCommand ?? (m_GetDiagnosticsCommand = new RelayCommand(async p => await GetDiagnostics())); }
    }
    private async Task GetDiagnostics()
    {
      await Task.Run(() =>
      {
        DiagnosticResult = m_Proxy.GetDiagnostics();	// <-- Calling the server
      });
    }    
    private string m_DiagnosticResult = "Click to run the diagnostics";
    public string DiagnosticResult
    {
      get { return m_DiagnosticResult; }
      set
      {
        if(m_DiagnosticResult != value)
        {
          m_DiagnosticResult = value;
          RaisePropertyChanged();
        }
      }
    }
  }
}

Now we'll create the button and text box on the UI:

Code Block
languagexml
<UserControl x:Class="ProxySample1.ProxySample1UI"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             Padding="6">
    <Border Margin="10">
        <StackPanel>
            <Button Command="{Binding GetDiagnosticsCommand}"
                    Content="Get Diagnostics" />

            <TextBox Text="{Binding DiagnosticResult, Mode=OneWay}"
                     IsReadOnly="True"
                     Margin="0,10,0,0"
                     MinHeight="200"
                     VerticalContentAlignment="Top"/>
        </StackPanel>
    </Border>
</UserControl>

When clicking the button, we now get the following result: