private object ConvertTicksToDateTime(
            SensorDataTableEntity source,
            SensorData destination,
            string destMember,
            ResolutionContext context)
        {
            if (string.IsNullOrWhiteSpace(source.RowKey))
            {
                return(null);
            }

            context.Items.TryGetValue("DateTimeZone", out var ianaTimeZone);

            var dateTimeZone = ianaTimeZone as DateTimeZone;

            if (dateTimeZone == null)
            {
                return(null);
            }

            var      rowTicks = source.RowKey;
            DateTime dateTime = new DateTime();

            if (long.TryParse(rowTicks, out var ticks))
            {
                dateTime = new DateTime(ticks, DateTimeKind.Utc);
            }

            var zonedDateTime =
                ZonedDateTime.FromDateTimeOffset(new DateTimeOffset(dateTime, TimeSpan.Zero));

            return(zonedDateTime.ToOffsetDateTime().ToString());
        }
Ejemplo n.º 2
0
        public async Task <bool> SaveDataAsync(SensorData data)
        {
            try
            {
                var table = _client.GetTableReference(AppSettings.StorageTableName);
                await table.CreateIfNotExistsAsync();

                var entity    = new SensorDataTableEntity(AppSettings.StoragePartitionKey, data.Temperature, data.Humidity);
                var operation = TableOperation.InsertOrReplace(entity);
                var result    = await table.ExecuteAsync(operation);

                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);

                return(false);
            }
        }