Getting id after inserting - c#

I'm working with windows phone apps using windows azure as database and is there any windows azure script to return back to my windows phone apps an id that created automatically by windows azure? so i can catch the id value and use it in my windows phone? instead of calling these method that I think maybe slow
addressItem = await addressTable
.Where(table => table.placeId == hereRestDetail.placeId)
.ToCollectionAsync();

When inserting data to a Table with autogenerated Id in Azure, once insertion finished the Id is sent back to client application. So you can simply get the Id from the same object model used for insert operation :
.....
await addressTable.InsertAsync(addressModel);
var generatedId = addressModel.Id;
.....
[Reference]

Related

Why an installed app is not listed by Ms Graph API?

I am trying to upgrade an app which belongs to a chat. If the app is not installed, below code successfully install it:
await graph.Chats["19:7f...3#thread.v2"].InstalledApps
.Request()
.AddAsync(teamsAppInstallation);
But once the app is added, below code shows zero entries:
var installedApps = await graph.Chats["19:7f...3#thread.v2"].InstalledApps.Request().GetAsync();
I was expecting to see my app there. My target is to call Upgrade() for the app, because it should allow me to add ConversationReferences in one of the event functions (e.g. OnTurnAsync), that will allow me to send proactive message to the chat. Am I doing something wrong?
Permissions for an application are set:
TeamsAppInstallation.ReadWriteSelfForChat.All
TeamsAppInstallation.ReadWriteForUser.All
The authentication with the Graph API is done successfully, as I can create a chat, list channels etc.
https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
data:
grant_type=client_credentials&client_id={ MS_APP_ID_ENC }&client_secret={ MS_APP_PASS_ENC }&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
I was adding the app to the chat both manually and with C# request:
var teamsAppInstallation = new TeamsAppInstallation {
AdditionalData = new Dictionary<string, object>()
{
{
"teamsApp#odata.bind", "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/0c...68/"}
}
};
var installedApp = await graph.Chats["19:7f...3#thread.v2"].InstalledApps. Request().AddAsync(teamsAppInstallation);
And the app was added. It can be used in the chat.
It turned out that I've used wrong application permissions. Even though TeamsAppInstallation.ReadWriteSelfForChat.Al is listed in the docs, I needed to add TeamsAppInstallation.ReadWriteForChat.All to make it working.

Unable to publish advertising data for BLE in wpf application

I am working on a wpf application where I need it to work as a publisher. So I want to publish some data and there will be other devices listening to this data. I am trying to send this data with advertisement and have been following This Link but I am not able to even detect this application in my iPhone app who is supposed to read this published data.
I am trying to add the data as following:
private BluetoothLEAdvertisementPublisher publisher;
this.publisher = new BluetoothLEAdvertisementPublisher();
ushort id = 0x1234;
var manufacturerDataWriter = new DataWriter();
manufacturerDataWriter.WriteUInt16(id);
var manufacturerData = new BluetoothLEManufacturerData
{
CompanyId = 0xFFFE,
Data = manufacturerDataWriter.DetachBuffer()
};
publisher.Advertisement.ManufacturerData.Add(manufacturerData);
publisher.Start();
Edit:
Do I need to create some characteristics too? I found a tutorial on MSDN about this and using smaple code I am able to send the characteristics but I am still not able to advertise my custom data to other devices.

Xamarin Realtime Database

How can I use realtime database in lock mode ? auth!=null ?
My app uses Xamarin.Firebase.Auth , I can create user and login also update realtime database childs but when I switch to auth=true, i can t update realtime database anymore.
I used this to work with realtime database:
var toUpdateUser = (await firebase
.Child("One")
.OnceAsync<One>()).Where(a => a.Object.Email == email).FirstOrDefault();
await firebase
.Child("One")
.Child(toUpdateUser.Key)
.PatchAsync(new Users() { Status = 0 });
For Locked mode, it denies all reads and writes from mobile and web clients. Your authenticated application servers can still access your database.
You could use the Test Mode instead.
For more details, please check the link below. https://firebase.google.com/docs/database/android/start
Sorry I meant to say auth users are allowed, not lock mode:
All authenticated users
While we don't recommend leaving your data accessible to any user that's signed in, it might be useful to set access to any authenticated user while you're developing your app.
Cloud Firestore
Realtime Database
Cloud Storage
{
"rules": {
".read": "auth.uid != null",
".write": "auth.uid != null"
}
}
If i use those rules, Firebase realtime database does not update.
If i use below rules all is fine.
{
"rules": {
".read": "auth.uid != null",
".write": "auth.uid != null"
}
}
I do login in my app with users created with Xamarin.Firebase.auth users that can be found in Firebaseconsole under Authentication but i need to callback something from Firebase i think to be able to useenter code here Realtime Database

Retrieve Data from IMobileServiceTable in a backend application

I have a backend application which serves data for windows and android mobile applications, The Service application is hosted as a MobileService on Azure, I have a table named 'todoitem' that is associated to this Mobile service . Now I want to query this table in my controller to check if a particular id is already present in the table if not I will insert it into the table and also send a push notification to the client application. However I am able to insert the data into the table but have no clue of how to retrieve it.
This is the code for insertion
public MobileServiceClient mClient1;
public IMobileServiceTable mToDoTable;
mClient1 = new MobileServiceClient("MobileServiceName", "Key");
mToDoTable = mClient1.GetTable("todoItem");
public void Add()
{
JObject jo = new JObject();
jo.Add("Text", "Hello World");
jo.Add("Complete", false);
jo.Add("id", "123456");
jo.Add("title", "New LED");
var inserted = mToDoTable.InsertAsync(jo);
}
what I want to do now is , I want to query the todoitem table of my mobile service , for example select * from todoitem where id="1234"
Any Help is much Appreciated
Per your other question, here is the link you need: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-how-to-use-client-library/
Also, consider upgrading to Azure Mobile Apps!

Send notifications to inactive users using Azure Mobile Services. Where to save the "lastLoginDate" and filter on it?

I have always been using Parse to manage my backend but switched to Azure due to the better integration with ASP.NET and Xamarin. In Parse I created a PFInstallation object and associated whatever property I needed to filter on before sending push notifications.
In Azure Mobile Services I am using the following code (in Xamarin iOS) to register the device:
public override void RegisteredForRemoteNotifications (UIApplication application, NSData deviceToken)
{
try {
var languageCode = NSLocale.PreferredLanguages [0];
ServiceClient.GetPush ().RegisterNativeAsync (deviceToken, new []{ languageCode }).ContinueWith ((t) => {
Console.WriteLine ("Device registration successful!");
});
} catch (Exception e) {
Console.WriteLine ("Could not register device for push notifications: {0}", e.Message);
}
}
I would like to have a way to remind my inactive users that they should play again. In Parse I just associated a "lastLoginDate" attribute to the PFInstallation object. How can I achieve the same with Azure Mobile Services?
As of now I am only able to filter based on the user's device language (because I save it as a tag) but not on the "lastLoginDate".
PS: in my backend I would like to have a code like this
var users = registrations.Where(u => u.LastLoginDate <= testDate);
SendNotificationToUsers(users);
UPDATE
I read on this page that you can use Tag Expressions to filter registrations but in the article it's not specified if you can use boolean expressions involving a date comparison. Any help on this?
Thank you.
One approach would be to have the device register with a tag with the current date each time the user opens the app. So today I use the app, I register my token for the tag "last-use-2015-03-02". Tomorrow if I use the app again I will reregister with the tag "last-use-2015-03-03", replacing the device registration for 2015-03-02.
Then each day have a scheduler that sends a message to the tag for a week ago (for example). So a week from now on March 9, I can send a notification to all devices with the tag "last-use-2015-03-02" reminding them to come back.

Categories

Resources