public void ToUnixTimeInMilliseconds_DateTimeOffset_ShouldMatch()
        {
            var offset = new DateTimeOffset(2016, 1, 8, 4, 11, 28, TimeSpan.FromHours(7));
            var expected = offset.ToUnixTimeMilliseconds();
            var actual = offset.ToUnixTimeInMilliseconds();

            Assert.AreEqual(expected, actual);
        }
Example #2
0
		/// <summary>
		/// Schedules an alarm.
		/// </summary>
		/// <param name="alarm">The alarm to be scheduled.</param>
		public void ScheduleAlarm (Alarm alarm)
		{
			var intent = new Intent (context, typeof (AlarmIntentService));
			// intent.PutExtra (AlarmIntentService.ALARM_KEY, alarm);
			// TODO - workaround https://github.com/googlesamples/android-DirectBoot/issues/4
			intent.PutExtra ("id", alarm.Id);
			intent.PutExtra ("year", alarm.Year);
			intent.PutExtra ("month", alarm.Month);
			intent.PutExtra ("day", alarm.Day);
			intent.PutExtra ("hour", alarm.Hour);
			intent.PutExtra ("minute", alarm.Minute);
			var pendingIntent = PendingIntent.GetService (context, alarm.Id, intent, PendingIntentFlags.UpdateCurrent);
			var triggerOffset = new DateTimeOffset (alarm.GetTriggerTime ());
			var alarmClockInfo = new AlarmManager.AlarmClockInfo (triggerOffset.ToUnixTimeMilliseconds (), pendingIntent);
			alarmManager.SetAlarmClock (alarmClockInfo, pendingIntent);
			Log.Info (TAG, $"Alarm scheduled at {alarm.Hour}:{alarm.Minute} {alarm.Year}-{alarm.Month}-{alarm.Day}");
		}
Example #3
0
        ///<summary>
        /// HookCallback function
        /// 
        /// Called each time a Hook Event is fired. If the type of event is a KeyPress append the keypress and metadata to a keypress log.
        /// This function calls the next hook in the hook chain.
        ///</summary>
        private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if ((client != null) && (client.Channel.State != ChannelState.FatalFailure)){
                if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
                {
                    // Create a KeyPress object and get keypress metadata.
                    KeyPress ks = new KeyPress();
                    DateTimeOffset x = new DateTimeOffset(DateTime.Now);
                    ks.Key = Marshal.ReadInt32(lParam);
                    ks.Timestamp = x.ToUnixTimeMilliseconds();
                    ks.ActiveProgram = GetActiveWindowName();

                    // Un-Comment these lines to write the KeyStrokes in the JSON human readable format. C# proto
                    // implementation lacks support for the Text encoding, the json encoding is the most human readable format.
                    //StreamWriter o = new StreamWriter(log+".json");
                    //o.WriteLine(ks.ToString());
                    //o.Close();
                    try {
                        client.PutKeyPressAsync(ks);
                    }
                    catch (RpcException e)
                    {
                        //Console.WriteLine("RPC Failed: " + e);
                    }
                }
            }

            return CallNextHookEx(_hookID, nCode, wParam, lParam);
        }
 public static string BeaconEventStateToString(string pid, BeaconEventType type, DateTimeOffset now)
 {
     return string.Format("{0},{1},{2}", pid, (int)type, now.ToUnixTimeMilliseconds());
 }
 public static string DelayedActionToString(string action, DateTimeOffset dueTime, bool executed, string guid, string location)
 {
     return string.Format("{0},{1},{2},{3},{4}\n", guid, dueTime.ToUnixTimeMilliseconds(), executed, action, location);
 }
 internal static string ActionToString(string uuid, string beaconPid, DateTimeOffset timestamp, int beaconEventType, bool delivered, bool background, string location)
 {
     return string.Format("{0},{1},{2},{3},{4},{5},{6}\n", uuid, beaconPid, timestamp.ToUnixTimeMilliseconds(), beaconEventType, delivered, background, location);
 }
Example #7
0
 private static DateTimeOffset StripMicroSeconds(DateTimeOffset t)
 {
     // We can't use DateTimeOffsets to compare since the resolution of a ulid is milliseconds, and DateTimeOffset
     // has microseconds and more. So we drop that part by converting to UnixTimeMilliseconds and then back to
     // a DateTimeOffset.
     return DateTimeOffset.FromUnixTimeMilliseconds(t.ToUnixTimeMilliseconds());
 }