Exemplo n.º 1
0
        /// <summary>
        /// Connects to the dotNetify hub server.
        /// </summary>
        /// <param name="vmId">Identifies the view model to request.</param>
        /// <param name="viewState">View state manager.</param>
        /// <param name="options">View model initialization options.</param>
        public async Task ConnectAsync(string vmId, IViewState viewState, VMConnectOptions options = null)
        {
            if (!string.IsNullOrEmpty(_vmId))
            {
                Logger.LogWarning($"The instance was already connected to '{_vmId}'. Call Dispose to disconnect.");
                await DisposeAsync();
            }

            _vmId      = vmId;
            _viewState = viewState;

            await _hubProxy.StartAsync();

            _hubProxy.Response_VM += OnResponseReceived;

            Dictionary <string, object> data = null;

            if (options?.VMArg != null)
            {
                data = new Dictionary <string, object>();
                data.Add(TOKEN_VMARG, options.VMArg);
                if (options?.Headers != null)
                {
                    data.Add(TOKEN_HEADERS, options.Headers);
                }
            }

            await _hubProxy.Request_VM(vmId, data);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Connects to the dotNetify hub server.
 /// </summary>
 /// <param name="vmId">Identifies the view model to request.</param>
 /// <param name="view">The connecting view; must implement changed notification.</param>
 /// <param name="options">View model initialization options.</param>
 public async Task ConnectAsync(string vmId, INotifyPropertyChanged view, VMConnectOptions options = null)
 {
     await ConnectAsync(vmId, new ViewState(view, _dispatcher), options);
 }