예제 #1
0
        internal static DynamicTableEntity CreateChannelTableEntity(IStorageChannel channel)
        {
            var dictionary = new Dictionary <string, EntityProperty>();

            dictionary.Add("SensorType", new EntityProperty(channel.SensorType));
            dictionary.Add("Name", new EntityProperty(channel.Name));
            dictionary.Add("Description", new EntityProperty(channel.Description));
            dictionary.Add("Alerts", new EntityProperty(JsonConvert.SerializeObject(channel.Alerts)));
            return(new DynamicTableEntity(channel.Id.ToUrn(), channel.Id.ToUrn(), channel.ETag,
                                          dictionary));
        }
예제 #2
0
        internal IStorageChannel ChannelEntityResolver(string partitionKey, string rowKey,
                                                       DateTimeOffset timestamp, IDictionary <string, EntityProperty> properties, string etag)
        {
            IStorageChannel channel = new IStorageChannel();

            channel.Id          = Guid.ParseExact(partitionKey, "D");
            channel.ETag        = etag;
            channel.Name        = properties["Name"].StringValue;
            channel.SensorType  = properties["SensorType"].StringValue;
            channel.Description = properties.Keys.Contains("Description") ?
                                  properties["Description"].StringValue : null;
            channel.Alerts = properties.Keys.Contains("Alerts") ?
                             JsonConvert.DeserializeObject <IList <IStorageAlert> >(properties["Alerts"].StringValue) : null;
            return(channel);
        }
예제 #3
0
        public IStorageChannel AddChannel(string channel_name, string channel_description,
                                          string sensor_type, string channel_units, List <IStorageAlert> alerts)
        {
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindDevice);
            IStorageDevice device = this.GetCurrentDevice();

            IStorageChannel channel = new IStorageChannel()
            {
                Id          = Guid.NewGuid(),
                Name        = channel_name,
                Description = channel_description,
                SensorType  = sensor_type,
                Alerts      = alerts
            };

            try
            {
                TableOperation insert_channel_operation = TableOperation
                                                          .Insert(AzureStorage.CreateChannelTableEntity(channel));
                TableResult result;
                result = this.ChannelsTable.Execute(insert_channel_operation);
                Log.WriteTableSuccess(string.Format("Added Channel entity: {0}, Id: {1}.",
                                                    channel.Name, channel.Id.ToUrn()));
                return(channel);
            }
            catch (Exception e)
            {
                Log.WriteTableFailure(string.Format("Failed to add Channel entity: {0}, Id: {1}.", channel.Name,
                                                    channel.Id), e);
                throw;
            }
            finally
            {
                OverlordIdentity.DeleteClaim(Resource.Storage, StorageAction.AddChannel);
            }
        }