Exemplo n.º 1
0
        public WidgetParameterMetaData[] GetWidgetMetaData(ISession session, Logger logger)
        {
            var fldChannel = new WidgetParameterMetaData
            {
                DisplayName = "Channel",
                Name = "channel",
                Type = WidgetParameterType.Int32,
                Items = new WidgetSelectItem[32]
            };

            for (var i = 0; i < 32; i++)
            {
                fldChannel.Items[i] = new WidgetSelectItem(i, i.ToString());
            }

            return new[] { fldChannel };
        }
		public WidgetParameterMetaData[] GetWidgetMetaData(ISession session, Logger logger)
		{
			var sensors = session
				.Query<TemperatureSensor>()
				.Select(s => new WidgetSelectItem(s.Id, s.DisplayName))
				.ToArray();

			var sensorIdParameter = new WidgetParameterMetaData
			{
				Name = PARAM_SENSOR_ID,
				DisplayName = MicroclimateLang.Sensor,
				Type = WidgetParameterType.Guid,
				Items = sensors
			};

			return new[] { sensorIdParameter };
		}
		private EditorParameterModel GetEditorParameterModel(WidgetParameterMetaData parameter)
		{
			var items = parameter.Items == null
				? null
				: parameter.Items
					.Select(i => new { id = i.Id, name = i.DisplayName })
					.ToArray();

			var ptype = parameter.Type.ToString().ToLower();

			var pmodel = new EditorParameterModel
			{
				name = parameter.Name,
				displayName = parameter.DisplayName,
				type = ptype,
				items = items
			};

			return pmodel;
		}
		private static void CreateParameter(ISession session, Widget widget, WidgetParameterMetaData field, string value)
		{
			var p = new WidgetParameter
			{
				Id = Guid.NewGuid(),
				Widget = widget,
				Name = field.Name
			};

			switch (field.Type)
			{
				case WidgetParameterType.String:
					p.ValueString = value;
					break;
				case WidgetParameterType.Guid:
					p.ValueGuid = value.ParseGuid();
					break;
				case WidgetParameterType.Int32:
					p.ValueInt = value.ParseInt();
					break;
			}

			session.Save(p);
		}