PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync hangs app forever - windows

I have gone through many tutorials to get the method below working but when it is executed, the app hangs forever because the method never finishes.
PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync
The method does not throw any exceptions and I cant debug the cause either, I'm not sure what I'm doing wrong so please correct me on my code and app capabilities. Thanks.
Notification Initialization Method:
private async Task InitNotificationsAsync()
{
try
{
Constants.NotificationChannel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
Constants.NotifyHub = new NotificationHub("hub name", "access key");
Constants.NotificationHubRegistration = await Constants.NotifyHub.RegisterNativeAsync(Constants.NotificationChannel.Uri);
if (!(Constants.NotificationHubRegistration != null) || !(Constants.NotificationHubRegistration.RegistrationId != null)) await new MessageDialog("Microsoft Azure Push Notification Services are unavailable!", "Problem!?").ShowAsync();
} catch (Exception e)
{
await new MessageDialog("Microsoft Azure Push Notification Services are unavailable!\n\n" + e.Message, "Problem!?").ShowAsync();
}
}
App Capabilities:
Internet (Client & Server)
Internet (Client)
Location
User Account Information

Related

Apollo GraphQL - Handling onConnect and OnDisconnect events

I'm developing a real-time chat app using Apollo GraphQL, and I want to keep the clients updated about the other client's status.
Mean that I need to do something with the onConnect and OnDisconnect events from the subscriptions object (which defined in app.js) and send a subscription event to the clients whenever a user connected or disconnected.
I could not find an explanation on how to do this, and I would appreciate any help.
you have to use onDisconnect property with context.initPromise like this:
onDisconnect: async (webSocket, context) => {
console.log('what is the context?: ', context);
try {
const initialContext = await context.initPromise;
if (
initialContext &&
typeof initialContext === 'object' &&
Reflect.has(initialContext, 'user')
) {
console.log('initialContext: ', initialContext);
}
} catch (err) {
console.log('error', err); // TypeError:
}
}
},
link and link2 for reference.
warning: this is currently working on my local build but not on my heroku production build

How to run localhost webapi on xamarin forms

I have a xamarin forms app and a web api.
when I run the web api, on the browser I have http://localhost:53089/api/values
and inside the xamarin app I have the following method
public async Task<object> GetRestfull()
{
try
{
using (var client = new HttpClient())
{
var content = await client.GetStringAsync("http://10.0.2.2:53089/api/values");
var postt = JsonConvert.DeserializeObject<List<Post>>(content);
post = new ObservableCollection<Post>(postt);
}
return post.FirstOrDefault();
}
catch (HttpRequestException e)
{
Console.WriteLine(e.GetBaseException().Message);
throw;
}
}
I'm using the android avd emulator.
and the above code throws an exception : 400 bad request
if I remove the port number it throws : 404 not found.
I have checked my firewall settings and world wide web is enabled.. so what is it that I'm missing here? any help is appreciated.
try replace localhost with 127.0.0.1

Await signalr message in client

Is it possible for a SignalR client send a message to the server and then to await for a seperate message (not a return value) from the server?
The theory;
Client1 send message1 to Server and "waits" for the response.
Server processes some logic
Server sends message2 to Client1 and Client1 executes the waiting code.
Call to the server:
$.connection.myhub.server.myRequest(id).done(()==>{
// myRequest is done;
// the server has received the request but hasn't processed it yet.
// I want put some *async* code here to do something when the server has triggered $.connection.myhub.client.myResponse(id, someParam);
});
Callback to the client:
$.connection.myhub.client.myResponse(originalId, somePassedBackValue);
Can I use Async/Await, or wrap this in a Promise somehow?
If this isn't acheivable in SignalR are there anyother socket libraries that might be used instead?
You can do something, like the following:
Imagine you have a client that joins a group, updates a table and then notifies the client that it has joined.
Client
msgHub.server.joinGroup(id).done(function () {
console.log("Joined Group");
serverCallFinished = true;
})
msgHub.client.displayTable = function (table) {
display(table);
}
Hub
public async Task JoinGroup(string practiceId)
{
try
{
await Groups.Add(Context.ConnectionId, practiceId);
//Add new table
var table = new Table(practiceId)
await UpdateTable("SomeGroup", table);
}
catch (Exception e)
{
throw;
}
}
public async Task UpdateInfo(string groupName, string table)
{
//await some logic
Clients.Group(groupName).updateTable(table);
}
Update info will call the client with message2 in this case a table that it wants to display to the client. When it finishes the it will return from its awaited state by JoinGroup which will return and alert that a new user has joined a group.

How to Handle NoResumeHandler exception in Microsoft bot framework?

How to handle exception in chatbot using Microsoft Bot Framework. I am getting the exception below since I have given a wrong LUIS subscripion key but I would like to handle the exception and provide a custom message instead of the below one!
NoResumeHandlerException: IDialog method execution finished with no resume handler specified through IDialogStack.
Here is the code follows of the MessageController..
if (activity.Type == ActivityTypes.Message)
{
//await Microsoft.Bot.Builder.Dialogs.Conversation.SendAsync(activity, () => new ContactOneDialog());
//Implementation of typing indication
//ConnectorClient connector = new ConnectorClient(new System.Uri(activity.ServiceUrl));
//Activity isTypingReply = activity.CreateReply("Shuttlebot is typing...");
//isTypingReply.Type = ActivityTypes.Typing;
//await connector.Conversations.ReplyToActivityAsync(isTypingReply);
logger.Debug("The User's local timeStamp is: " + activity.LocalTimestamp + "and service timeStamp is: " + activity.Timestamp);
await Conversation.SendAsync(activity, () =>
new ExceptionHandlerDialog<object>(new ShuttleBusDialog(), displayException: true));
}
else
{
HandleSystemMessage(activity);
}

Monolog with Bot Framework

We are using the Microsoft Bot Framework for our chat bot. Our Message Controller is standard :
public async Task<HttpResponseMessage> Post([FromBody] Activity activity)
{
HttpResponseMessage response;
try
{
if (activity.Type == ActivityTypes.Message)
{
//do some stuff
await Conversation.SendAsync(activity, () => new RootDialog());
}
else
{
HandleSystemMessage(activity);
}
response = this.Request.CreateResponse(HttpStatusCode.OK);
}
catch (Exception ex)
{
//do some catching
}
return response;
}
Sometimes, the bot needs to have long monologs. If it takes too long, we receive a 502 Bad Gateway error.
Any solution for that ?
Bot Framework calls time out after 15 seconds. Your bot must return a successful HTTP status code within 15 seconds for Direct Line to consider the message successfully sent.
If your bot does a lot of offline work or sends multiple messages, you should move that work to a background thread so the incoming request completes within 15 seconds.
Here's a snippet that correctly handles loads hosted inside ASP.Net and other hosting environments.
if (HostingEnvironment.IsHosted)
{
HostingEnvironment.QueueBackgroundWorkItem(c => DoWorkAsync());
}
else
{
Task.Run(() => DoWorkAsync());
}
...
private async Task DoWorkAsync()
{
// do some stuff
}
Task.Run is simpler but HostingEnvironment.QueueBackgroundWorkItem prevents ASP.Net from tearing down your process before this work is complete.

Resources