// Summary: // Initialize CompanionConnectionManager public virtual async System.Threading.Tasks.Task <bool> Initialize(CompanionDevice LocalDevice, CompanionConnectionManagerInitializeArgs InitArgs) { LocalCompanionDevice = LocalDevice; ApplicationUri = InitArgs.ApplicationUri; AppServiceName = InitArgs.AppServiceName; PackageFamilyName = InitArgs.PackageFamilyName; if (listCompanionDevices == null) { listCompanionDevices = new Dictionary <string, CompanionDevice>(); } if (listRemoteSystems == null) { listRemoteSystems = new Dictionary <string, RemoteSystem>(); } //Set up a new app service connection if (receiveConnection != null) { receiveConnection.ServiceClosed -= ReceiveConnection_ServiceClosed; receiveConnection.RequestReceived -= ReceiveConnection_RequestReceived; receiveConnection = null; } receiveConnection = new AppServiceConnection(); if (receiveConnection != null) { receiveConnection.AppServiceName = AppServiceName; receiveConnection.PackageFamilyName = PackageFamilyName; receiveConnection.RequestReceived += ReceiveConnection_RequestReceived; receiveConnection.ServiceClosed += ReceiveConnection_ServiceClosed; Windows.ApplicationModel.AppService.AppServiceConnectionStatus status = await receiveConnection.OpenAsync(); if (status == Windows.ApplicationModel.AppService.AppServiceConnectionStatus.Success) { // Connection established with the background task var inputs = new ValueSet(); inputs.Add(CompanionServiceMessage.ATT_TYPE, CompanionServiceMessage.TYPE_INIT); AppServiceResponse response = await receiveConnection.SendMessageAsync(inputs); if ((response != null) && (response.Status == AppServiceResponseStatus.Success)) { if ((response.Message != null) && (response.Message.ContainsKey(CompanionServiceMessage.ATT_TYPE))) { string s = (string)response.Message[CompanionServiceMessage.ATT_TYPE]; if (string.Equals(s, CompanionServiceMessage.TYPE_RESULT)) { return(true); } } } } } return(false); }
public override async System.Threading.Tasks.Task <bool> Initialize(CompanionDevice LocalDevice, CompanionConnectionManagerInitializeArgs InitArgs) { await base.Initialize(LocalDevice, InitArgs); MulticastCompanionConnectionManagerInitializeArgs mInitArgs = InitArgs as MulticastCompanionConnectionManagerInitializeArgs; if (mInitArgs != null) { MulticastIPAddress = mInitArgs.MulticastIPAddress; MulticastUDPPort = mInitArgs.MulticastUDPPort; UnicastUDPPort = mInitArgs.UnicastUDPPort; UDPTransport = mInitArgs.UDPTransport; MulticastDiscovery = mInitArgs.MulticastDiscovery; SendInterfaceAddress = mInitArgs.SendInterfaceAddress; if (await InitializeMulticastRecv()) { if (await InitializeUnicastRecv()) { if (await InitializeSend()) { var searchDevice = listCompanionDevices.FirstOrDefault(device => string.Equals(device.Value.IPAddress, MulticastIPAddress)); if (searchDevice.Value == null) { CompanionDevice d = new CompanionDevice(); d.Id = "0"; d.IsRemoteSystemDevice = false; d.IPAddress = MulticastIPAddress; d.Name = CompanionProtocol.MulticastDeviceName; d.Kind = CompanionProtocol.MulticastDeviceKind; d.IsMulticast = true; if (listCompanionDevices.ContainsKey(d.Id)) { listCompanionDevices.Remove(d.Id); } listCompanionDevices.Add(d.Id, d); OnDeviceAdded(this, d); } return(true); } } } } return(false); }