本文整理汇总了C#中AppServiceConnection.SendMessageAsync方法的典型用法代码示例。如果您正苦于以下问题:C# AppServiceConnection.SendMessageAsync方法的具体用法?C# AppServiceConnection.SendMessageAsync怎么用?C# AppServiceConnection.SendMessageAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppServiceConnection
的用法示例。
在下文中一共展示了AppServiceConnection.SendMessageAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeService
private async void InitializeService()
{
_appServiceConnection = new AppServiceConnection
{
PackageFamilyName = "ConnectionService-uwp_5gyrq6psz227t",
AppServiceName = "App2AppComService"
};
// Send a initialize request
var res = await _appServiceConnection.OpenAsync();
if (res == AppServiceConnectionStatus.Success)
{
var message = new ValueSet {{"Command", "Connect"}};
var response = await _appServiceConnection.SendMessageAsync(message);
if (response.Status == AppServiceResponseStatus.Success)
{
InitializeSerialBridge();
//InitializeBluetoothBridge();
_appServiceConnection.RequestReceived += _serialBridge.OnCommandRecived;
//_appServiceConnection.RequestReceived += _bluetoothBridge.OnCommandRecived;
//_appServiceConnection.RequestReceived += _appServiceConnection_RequestReceived;
}
}
}
示例2: GetEmployeeById
private async void GetEmployeeById(object sender, RoutedEventArgs e)
{
appServiceConnection = new AppServiceConnection
{
AppServiceName = "EmployeeLookupService",
PackageFamilyName = "3598a822-2b34-44cc-9a20-421137c7511f_4frctqp64dy5c"
};
var status = await appServiceConnection.OpenAsync();
switch (status)
{
case AppServiceConnectionStatus.AppNotInstalled:
await LogError("The EmployeeLookup application is not installed. Please install it and try again.");
return;
case AppServiceConnectionStatus.AppServiceUnavailable:
await LogError("The EmployeeLookup application does not have the available feature");
return;
case AppServiceConnectionStatus.AppUnavailable:
await LogError("The package for the app service to which a connection was attempted is unavailable.");
return;
case AppServiceConnectionStatus.Unknown:
await LogError("Unknown Error.");
return;
}
var items = this.EmployeeId.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
var message = new ValueSet();
for (int i = 0; i < items.Length; i++)
{
message.Add(i.ToString(), items[i]);
}
var response = await appServiceConnection.SendMessageAsync(message);
switch (response.Status)
{
case AppServiceResponseStatus.ResourceLimitsExceeded:
await LogError("Insufficient resources. The app service has been shut down.");
return;
case AppServiceResponseStatus.Failure:
await LogError("Failed to receive response.");
return;
case AppServiceResponseStatus.Unknown:
await LogError("Unknown error.");
return;
}
foreach (var item in response.Message)
{
this.Items.Add(new Employee
{
Id = item.Key,
Name = item.Value.ToString()
});
}
}
示例3: GetBeersByFilter
public async Task<IEnumerable<Beer>> GetBeersByFilter(string filter)
{
AppServiceConnection connection = new AppServiceConnection();
connection.AppServiceName = "PlainConcepts-appservicesdemo";
connection.PackageFamilyName = "cff6d46b-5839-4bb7-a1f2-e59246de63b3_cb1hhkscw5m06";
AppServiceConnectionStatus connectionStatus = await connection.OpenAsync();
if (connectionStatus == AppServiceConnectionStatus.Success)
{
//Send data to the service
var message = new ValueSet();
message.Add("Command", "GetBeersByFilter");
message.Add("Filter", filter);
//Send message and wait for response
AppServiceResponse response = await connection.SendMessageAsync(message);
if (response.Status == AppServiceResponseStatus.Success)
{
var resultJson = (string)response.Message["Result"];
var list = JsonConvert.DeserializeObject<IEnumerable<Beer>>(resultJson);
return list;
}
}
else
{
//Drive the user to store to install the app that provides the app service
new MessageDialog("Service not installed").ShowAsync();
}
return null;
}
示例4: OnNavigatedTo
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
Loading.IsActive = true;
AppServiceConnection connection = new AppServiceConnection();
connection.PackageFamilyName = Package.Current.Id.FamilyName;
connection.AppServiceName = "FeedParser";
var status = await connection.OpenAsync();
if (status == AppServiceConnectionStatus.Success)
{
ValueSet data = new ValueSet();
data.Add("FeedUrl", "http://blog.qmatteoq.com/feed/");
var response = await connection.SendMessageAsync(data);
if (response.Status == AppServiceResponseStatus.Success)
{
string items = response.Message["FeedItems"].ToString();
var result = JsonConvert.DeserializeObject<List<FeedItem>>(items);
News.ItemsSource = result;
}
}
Loading.IsActive = false;
}
示例5: InitializeAppSvc
private async void InitializeAppSvc()
{
string WebServerStatus = "PoolWebServer failed to start. AppServiceConnectionStatus was not successful.";
// Initialize the AppServiceConnection
appServiceConnection = new AppServiceConnection();
appServiceConnection.PackageFamilyName = "PoolWebServer_hz258y3tkez3a";
appServiceConnection.AppServiceName = "App2AppComService";
// Send a initialize request
var res = await appServiceConnection.OpenAsync();
if (res == AppServiceConnectionStatus.Success)
{
var message = new ValueSet();
message.Add("Command", "Initialize");
var response = await appServiceConnection.SendMessageAsync(message);
if (response.Status != AppServiceResponseStatus.Success)
{
WebServerStatus = "PoolWebServer failed to start.";
throw new Exception("Failed to send message");
}
appServiceConnection.RequestReceived += OnMessageReceived;
WebServerStatus = "PoolWebServer started.";
}
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
txtWebServerStatus.Text = WebServerStatus;
});
}
示例6: LaunchAppService
private async Task LaunchAppService(string cmd)
{
var connection = new AppServiceConnection
{
AppServiceName = "uwpdeepdive-appservice",
PackageFamilyName = "11fc3805-6c54-417b-916c-a4f6e89876b2_2eqywga5gg4gm"
};
var appServiceConnectionStatus = await connection.OpenAsync();
if (appServiceConnectionStatus != AppServiceConnectionStatus.Success)
{
_resultsTextBox.Text = appServiceConnectionStatus.ToString();
return;
}
var msg = new ValueSet {["cmd"] = cmd};
var appServiceResponse = await connection.SendMessageAsync(msg);
if (appServiceResponse.Status != AppServiceResponseStatus.Success)
{
_resultsTextBox.Text = appServiceResponse.Status.ToString();
return;
}
var time = appServiceResponse.Message[cmd] as string;
_resultsTextBox.Text = time ?? "";
//note - communication is two-way! can send/receive as needed
//connection.RequestReceived += delegate(
// AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) { /* ... */ };
}
示例7: SendMessageAsync
private async Task<string> SendMessageAsync(ValueSet message)
{
using (var connection = new AppServiceConnection())
{
connection.AppServiceName = BookServiceName;
connection.PackageFamilyName = BooksPackageName;
AppServiceConnectionStatus status = await connection.OpenAsync();
if (status == AppServiceConnectionStatus.Success)
{
AppServiceResponse response = await connection.SendMessageAsync(message);
if (response.Status == AppServiceResponseStatus.Success && response.Message.ContainsKey("result"))
{
string result = response.Message["result"].ToString();
return result;
}
else
{
await ShowServiceErrorAsync(response.Status);
}
}
else
{
await ShowConnectionErrorAsync(status);
}
return string.Empty;
}
}
示例8: GetNewsAsync
public async Task<IEnumerable<FeedItem>> GetNewsAsync(string url)
{
AppServiceConnection connection = new AppServiceConnection();
connection.PackageFamilyName = "637bc306-acb1-4e73-bbe0-70ecc919ca1c_e8f4dqfvn1be6";
connection.AppServiceName = "FeedParser";
var status = await connection.OpenAsync();
if (status == AppServiceConnectionStatus.Success)
{
ValueSet data = new ValueSet();
data.Add("FeedUrl", url);
var response = await connection.SendMessageAsync(data);
if (response.Status == AppServiceResponseStatus.Success)
{
string items = response.Message["FeedItems"].ToString();
var result = JsonConvert.DeserializeObject<List<FeedItem>>(items);
return result;
}
else
{
return null;
}
}
else
{
return null;
}
}
示例9: SendOnceAsync
// single request/response
public static async Task<ValueSet> SendOnceAsync(string appServiceName, string packageFamilyName, ValueSet request)
{
using (var connection = new AppServiceConnection() { AppServiceName = appServiceName, PackageFamilyName = packageFamilyName })
{
var status = await connection.OpenAsync();
if (status == AppServiceConnectionStatus.Success)
{
var response = await connection.SendMessageAsync(request);
if (response.Status == AppServiceResponseStatus.Success)
return response.Message;
}
}
return null;
}
示例10: SendOnceAsync
// single request/response
public static async Task<ValueSet> SendOnceAsync(RemoteSystem selectedDevice, string appServiceName, string packageFamilyName, ValueSet request)
{
if (selectedDevice != null)
{
using (AppServiceConnection connection = new AppServiceConnection { AppServiceName = appServiceName, PackageFamilyName = packageFamilyName })
{
var status = await connection.OpenRemoteAsync(new RemoteSystemConnectionRequest(selectedDevice));
if (status == AppServiceConnectionStatus.Success)
{
var response = await connection.SendMessageAsync(request);
if (response.Status == AppServiceResponseStatus.Success)
return response.Message;
}
}
}
return null;
}
示例11: InitAppSvc
private async void InitAppSvc()
{
// Initialize the AppServiceConnection
appServiceConnection = new AppServiceConnection();
appServiceConnection.PackageFamilyName = "WebServer_hz258y3tkez3a";
appServiceConnection.AppServiceName = "App2AppComService";
// Send a initialize request
var res = await appServiceConnection.OpenAsync();
if (res == AppServiceConnectionStatus.Success)
{
var message = new ValueSet();
message.Add("Command", "Initialize");
var response = await appServiceConnection.SendMessageAsync(message);
if (response.Status != AppServiceResponseStatus.Success)
{
throw new Exception("Failed to send message");
}
appServiceConnection.RequestReceived += OnMessageReceived;
}
}
示例12: CallAppService
private async void CallAppService()
{
connection = new AppServiceConnection();
connection.AppServiceName = "demoqueenservice102040";
connection.PackageFamilyName = "19a28e63-2fa8-42f6-8af2-27376190cf89_e7qah2kqbxs60";
AppServiceConnectionStatus connectionStatus = await connection.OpenAsync();
var message = new ValueSet();
message.Add("cmd", "toUpper");
message.Add("txt", tb.Text);
AppServiceResponse response = await connection.SendMessageAsync(message);
if (response.Status == AppServiceResponseStatus.Success)
{
var res = response.Message["result"] as string;
new MessageDialog(res).ShowAsync();
}
connection.Dispose();
connection = null;
}
示例13: ButtonBase_OnClick
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
var connection = new AppServiceConnection
{
AppServiceName = "andyhammar-appServiceLib",
PackageFamilyName = "3cdc12ed-94be-4768-ad67-6029b9dd2c5a_2eqywga5gg4gm"
};
var appServiceConnectionStatus = await connection.OpenAsync();
if (appServiceConnectionStatus != AppServiceConnectionStatus.Success)
{
AppServiceResult = appServiceConnectionStatus.ToString();
return;
}
var msg = new ValueSet {["cmd"] = "time" };
var appServiceResponse = await connection.SendMessageAsync(msg);
if (appServiceResponse.Status != AppServiceResponseStatus.Success)
{
AppServiceResult = appServiceResponse.ToString();
return;
}
var time = appServiceResponse.Message["time"] as string;
AppServiceResult = time;
}
示例14: OnUseAppServiceClicked
private async void OnUseAppServiceClicked(object sender, RoutedEventArgs e)
{
AppServiceConnection connection = new AppServiceConnection();
connection.PackageFamilyName = Package.Current.Id.FamilyName;
connection.AppServiceName = "SumService";
var status = await connection.OpenAsync();
if (status == AppServiceConnectionStatus.Success)
{
ValueSet data = new ValueSet();
data.Add("num1", 10);
data.Add("num2", 5);
var response = await connection.SendMessageAsync(data);
if (response.Status == AppServiceResponseStatus.Success)
{
int sum = (int) response.Message["result"];
MessageDialog dialog = new MessageDialog($"The sum is {sum}");
await dialog.ShowAsync();
}
}
}
示例15: CallService_Click
private async void CallService_Click(object sender, RoutedEventArgs e)
{
var connection = new AppServiceConnection();
connection.PackageFamilyName = "0df93276-6bbb-46fa-96b7-ec223e226505_cb1hhkscw5m06"; // Windows.ApplicationModel.Package.Current.Id.FamilyName;
connection.AppServiceName = "CalculatorService";
var status = await connection.OpenAsync();
if (status != AppServiceConnectionStatus.Success)
{
var dialog = new MessageDialog("Sorry, I can't connect to the service right now :S");
await dialog.ShowAsync();
return;
}
var message = new ValueSet();
message.Add("service", OperatorCombo.Items[OperatorCombo.SelectedIndex]);
message.Add("a", Convert.ToInt32(ValueABox.Text));
message.Add("b", Convert.ToInt32(ValueBBox.Text));
AppServiceResponse response = await connection.SendMessageAsync(message);
if (response.Status == AppServiceResponseStatus.Success)
{
if (response.Message.ContainsKey("result"))
{
ResultBlock.Text = response.Message["result"] as string;
}
}
else
{
var dialog = new MessageDialog(string.Format("Opps, I just get an error :S ({0})", response.Status));
await dialog.ShowAsync();
}
}