/// <summary> /// Starts the connection to the target server. /// </summary> public async Task StartAsync() { if (_hubProxy.ConnectionState == HubConnectionState.Disconnected) { await _hubProxy.StartAsync(); } }
/// <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)) { throw new Exception($"The instance was connected to '{_vmId}'. Call Dispose to disconnect."); } _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); }