private async Task <ResponseInfo> GetConnectionInfo(JToken parameters) { Guid deviceId = Guid.Parse(parameters["deviceId"].ToString()); this.accessToken = this.library.RemoteAccessControl.RegisterRemoteAccessToken(deviceId); this.Log().Info("Registering new mobile client with access token {0}", this.accessToken); if (this.library.RemoteAccessControl.IsRemoteAccessReallyLocked) { var password = parameters["password"].Value <string>(); if (password != null) { try { this.library.RemoteAccessControl.UpgradeRemoteAccess(this.accessToken, password); } catch (WrongPasswordException) { return(CreateResponse(ResponseStatus.WrongPassword)); } } } AccessPermission accessPermission = await this.library.RemoteAccessControl.ObserveAccessPermission(this.accessToken).FirstAsync(); // This is stupid NetworkAccessPermission permission = accessPermission == AccessPermission.Admin ? NetworkAccessPermission.Admin : NetworkAccessPermission.Guest; int?remainingVotes = await this.library.RemoteAccessControl.ObserveRemainingVotes(this.accessToken).FirstAsync(); var guestSystemInfo = new GuestSystemInfo { IsEnabled = remainingVotes.HasValue, }; if (remainingVotes.HasValue) { guestSystemInfo.RemainingVotes = remainingVotes.Value; } var connectionInfo = new ConnectionInfo { AccessPermission = permission, ServerVersion = AppInfo.Version, GuestSystemInfo = guestSystemInfo }; this.SetupPushNotifications(); return(CreateResponse(ResponseStatus.Success, null, JObject.FromObject(connectionInfo))); }
private Task PushGuestSystemInfo(int?remainingVotes) { var guestSystemInfo = new GuestSystemInfo { IsEnabled = remainingVotes.HasValue, }; if (remainingVotes.HasValue) { guestSystemInfo.RemainingVotes = remainingVotes.Value; } NetworkMessage message = CreatePushMessage(PushAction.UpdateGuestSystemInfo, JObject.FromObject(guestSystemInfo)); return(this.SendMessage(message)); }