Specify time of events sent with AppInsights? - reactjs

Is there a way to set the time of events manually sent in App Insights? I'm using the ApplicationInsights package from #microsoft/applicationinsights-web in a react app. As an example, I want to execute something like this at 6:00pm ETC Apr 26, 2022:
appInsights.trackEvent({
name: "my cool event",
properties: {
greeting: "hello world"
},
});
But have it logged in my azure portal as happening at 5:00pm ETC Apr 26, 2022. I figured there would be a time property or something I could set on the parameter object, but that doesn't seem to be the case.

AFAIK, We have trackDependencyData, which is the IDependencyTelemetry interface, which has startTime as a parameter to know the telemetry event start time.
Sample code:-
var success = false;
var startTime = new Date().getTime();
try
{
success = dependency.Call();
}
finally
{
var elapsed = new Date() - startTime;
telemetry.trackDependency({
dependencyTypeName: "myDependency",
name: "myCall",
duration: elapsed,
success: success
});
}
For more information please refer the below links:-
MICROSOFT DOCUMENT| trackDependency , API SUMMARY
SO THREAD | Azure Application Insight JavaScript SDK trackEvent Timestamp

Related

Receiving an incorrect time in SQL

I'm interested in getting a full date in SQL this way 2021/02/02 20:12:36
And the date is kept in such a way 2021/02/02 00:00:00
On the server side I get a correct date like this 2021/02/02 20:12:36
On the client side I get this way 2021/02/02 03:00:00
This is the format I get in React
I don't know why:(
Maybe here's the problem
const FormatDate = (date) => {
try {
console.log(date);
return format(date, "yyyy/MM/dd hh:mm:ss");
} catch (e) {
return "";
}
};
I think this is error of browser auto add offset at client
You can try this code to show right time at client
new Date(DATE_REPONSE_FROM_SERVER).getTime() - new Date().getTimezoneOffset() * 60 * 1000
But you need add offset at server if you send this time to server
Other way, I this you convert time to string and response this string
Hope this help for you

How To Repeat Notifications React Native

I'm using this library for local notifications but for some reason, I can't get the notifications to repeat each day. Even with having "repeatType: day" in the object. Does anyone know how to repeat local notifications for iOS using this library?
Here's the code I currently wrote to do this:
var trigger = new Date();
trigger.setDate(trigger.getDate()+1);
trigger.setHours(7);
trigger.setMinutes(0);
trigger.setMilliseconds(0);
PushNotification.localNotificationSchedule({
message: "Your Daily Schedule is Ready.", // (required)
date: trigger, // in 60 secs
allowWhileIdle: false, // (optional) set notification to work while on doze, default: false
repeatType: "day", // (optional) Repeating interval. Check 'Repeating Notifications' section for more info.
});
trigger = new Date();
trigger.setDate(trigger.getDate());
trigger.setHours(22);
trigger.setMinutes(30);
trigger.setMilliseconds(0);
PushNotification.localNotificationSchedule({
message: "Your Evening Schedule is Ready.", // (required)
date: trigger, // in 60 secs
allowWhileIdle: false, // (optional) set notification to work while on doze, default: false
repeatType: "day", // (optional) Repeating interval. Check 'Repeating Notifications' section for more info.
});

How to extract JSON object in a Google Apps Script web app?

Can someone point out why this function would not work?
function doPost(e) {
var contents = JSON.parse(e.postData.contents);
var data = JSON.stringify(contents,null,4);
var x = data["inboundSMSMessageList"];
var y= x.inboundSMSMessage[0].senderAddress;
GmailApp.sendEmail("sample.email#gmail.com", "test5", y);
}
It takes an event listener, e, parses its contents and then stringily the contents using JSON.parse() and JSON.stringify() respectively. This is a sample stringified data:
var data = {
"inboundSMSMessageList": {
"inboundSMSMessage": [
{
"dateTime": "Sun Jan 03 2021 01:25:03 GMT+0000 (UTC)",
"destinationAddress": "tel:21585789",
"messageId": "5ff11cef73cf74588ab2a735",
"message": "Yes",
"resourceURL": null,
"senderAddress": "tel:+63917xxxxx"
}
],
"numberOfMessagesInThisBatch": 1,
"resourceURL": null,
"totalNumberOfPendingMessages": 0
}
}
The script seems to fail on the second to the last line (var y); but when I run it on the sample data, I'm able to access the key and value pair Im targeting- which is the sender address (it sends "tel:+63917xxxxx: to my email). Anybody has an idea why it's failing when it's ran as a web app?
I thought that in your script, var contents = JSON.parse(e.postData.contents); can be used as the parsed object. I thought that the reason of your error is due to that the object is converted to the string by var data = JSON.stringify(contents,null,4). So how about the following modification?
From:
var contents = JSON.parse(e.postData.contents);
var data = JSON.stringify(contents,null,4);
To:
var data = JSON.parse(e.postData.contents);
In this modification, y is tel:+63917xxxxx.
Note:
When you modified the script of Web Apps, please redeploy the Web Apps as new version. By this, the latest script is reflected to the Web Apps. Please be careful this.

Background Geolocation Plugin: Track location and update database every 5 minutes

I'm currently developing a mobile app using AngularJS / Ionic 3.
I need to track at all time, if my users are within a radius of 100m of a certain geolocation (let's call it "Home Location". I need to know at all time which user is at his home location, and who is not (even when the app is running in background or is closed/ terminated).
I thought to realize this, using the Ionic Native Background-Geolocation plugin and the cordova-plugin-background-geolocation. My plan was, to check the users geolocation every 5 minutes and compare it to the home.
Case 1) If the distance between the two locations is < 100m I know the user is "at home". I would then update the user node in my database (Firebase) to mark the user as isAtHome: true and add a current timestamp.
Case 2) If the user is not within 100m of his home location I would mark him as isAtHome: false and add a current timestamp.
I need to update my database even in case the user didn't move, because I need to know that I received a current signal. Otherwise I don't know if he didn't move or turned off his smartphone, for example.
If I want to know, who of my users is at his home location, I would check the isAtHome-attributes and if they are set to true, I would check the timestamp to be sure that I have up-to-date data and the data was written within the last 15 minutes.
I tried many different things, but I'm not sure how to realize this with the Cordova Background Geolocation Plugin and if it's even possible.
My question is:
Is it possible to check the users geolocation every 5 minutes (even in background / terminated state) and call a function that updates my firebase DB accordingly? As described, I need to receive the location even if the user didn't move within the last 5 minutes.
If it isn't possible: Does anybody have an idea, of how to approach the requirements on another way?
Thank you very much for your help!
As described in the cordova-plugin-background-geolocation says, you can configure an interval in milliseconds for the plugin to get the location, see this example from the plugin github page:
backgroundGeolocation.configure(callbackFn, failureFn, {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
url: 'http://192.168.81.15:3000/locations',
httpHeaders: { 'X-FOO': 'bar' },
maxLocations: 1000,
// Android only section
locationProvider: backgroundGeolocation.provider.ANDROID_ACTIVITY_PROVIDER,
interval: 60000, // <-- here
fastestInterval: 5000,
activitiesInterval: 10000,
notificationTitle: 'Background tracking',
notificationText: 'enabled',
notificationIconColor: '#FEDD1E',
notificationIconLarge: 'mappointer_large',
notificationIconSmall: 'mappointer_small'
});
The case is this interval property works only for Android. I would sugest a workaround like this:
public getLocation: boolean = true; // CREATE A BOOLEAN TO KNOW IF YOU CAN GET LOCATION
backgroundGeolocation.start( // i've never used this plugin, so i'm assuming this is what starts de background watcher
() => {
if(getLocation == true){
this.getLocation = false; // SET TO FALSE SO IT DON'T DO YOUR FUNCTION THE NEXT TIME IT GETS THE LOCATION
// DO YOUR CODE TO SAVE AND CHECK YOUR DATA
// IT'S BETTER IF YOU USE A PROMISE, ASYNC/AWAIT FOR THE SAVING CODE
yourSavingCodeFunction().then(() => {
setTimeout(()=>{
// AFTER 5 MINUTES, SET THE GETLOCATION TO TRUE SO IT CAN DO YOUR FUNCTION AGAIN
this.getLocation = true;
}, 500000);
});
}
},
(error) => {
// Tracking has not started because of error
// you should adjust your app UI for example change switch element to indicate
// that service is not running
}
);
If you haven't thought about your cases 1 and 2 we can work on this too. Hope this helps or can give you some ideas :D

Office 365 Calendar API retrieving only 10 records

I am getting an Issue when trying to fetch the events from Office 365 Calendar
The issue is that I am able to fetch only 10 Events and eventsResult.MorePagesAvailable is always false
I have more than 50 meetings in a month and the eventsResult is fetching only 10
Code to fetch Events :-
var eventSource = service.Me.Calendar.Events;
if (!String.IsNullOrEmpty(calendarId))
{
eventSource = service.Me.Calendars[calendarId].GetCalendarView(lowerBounday, upperBoundary);
// lowerBounday - Start Date for fetching events from calendar
// upperBoundary - End Date for fetching events from calendar
var eventsResult = await (from i in eventSource orderby i.Start select i).ExecuteAsync();
}
Same issue is coming for fetching all Calendars
I have more the 10 calendars in Office 365 but still getting only 10 with MorePagesAvailable as false.
Code to fetch All Calendars :-
var allCalendars = await service.Me.Calendars.ExecuteAsync();
bool checkNextPage = false;
do
{
if (checkNextPage && allCalendars.MorePagesAvailable)
{
allCalendars = await allCalendars.GetNextPageAsync();
}
foreach (ICalendar calendar in allCalendars.CurrentPage)
{
lock (calendars)
{
calendars.Add(new CalendarData(calendar.Name, calendar.Id)
{
HasWriteAccess = true,
IsFreeBusy = true
});
}
}
if(!checkNextPage)
checkNextPage = true;
} while(allCalendars.MorePagesAvailable)
We are using Microsoft.Office365 DLL's version 1.0.35 for this code.
It was working fine till 10-sept-2015. Is there anything changed with API or we are missing something?
Any help would be really appreciated.
Turns out this is a know issue that our engineers are working on. Sorry for the inconvenience!
UPDATE: The fix is in the pipeline. I'm seeing the #odata.nextLink in responses on my tenants, so it looks like it's hitting servers in production.
10 is the default number. You need to use somthing like this https://outlook.office.com/api/v1.0/me/messages?$top=number number= 5, 10...how many events you want. More details:https://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#UseODataqueryparametersPageresults

Resources