public object GetWidgetData(Widget widget, WidgetParameter[] parameters, ISession session, Logger logger)
		{
			var wChannel = parameters.First(p => p.Name == PARAM_CHANNEL).ValueInt;
			return new
			{
				channel = wChannel
			};
		}
		public object GetWidgetData(Widget widget, WidgetParameter[] parameters, ISession session, Logger logger)
		{
			var sensorId = parameters.First(p => p.Name == PARAM_SENSOR_ID).ValueGuid;
			var sensor = session.Get<TemperatureSensor>(sensorId);

			return new
			{
				id = sensorId, 
				timestamp = sensor.Timestamp,
				t = sensor.CurrentTemperature,
				h = sensor.CurrentHumidity,
				showHumidity = sensor.ShowHumidity
			};
		}
Exemplo n.º 3
0
 public object GetWidgetData(Widget widget, WidgetParameter[] parameters, ISession session, Logger logger)
 {
     return null;
 }
        private object GetWidgetModel(IWidgetDefinition def, Widget widget, WidgetParameter[] parameters, ISession session)
        {
            try
            {
                var data = def.GetWidgetData(widget, parameters, session, Logger);

                var model = new
                {
                    id = widget.Id,
                    type = widget.TypeAlias,
                    displayName = widget.DisplayName,
                    sortOrder = widget.SortOrder,
                    data
                };

                return model;
            }
            catch (Exception ex)
            {
                var message = string.Format(
                    "UI widget error (id: {0}, type:{1})", widget.Id, widget.TypeAlias);
                Logger.ErrorException(message, ex);

                return null;
            }
        }
        private object[] GetWidgetListModel(Widget[] allWidgets, WidgetParameter[] allParameters, ISession session)
        {
            var list = new List<object>();

            foreach (var widget in allWidgets)
            {
                var def = defs.GetValueOrDefault(widget.TypeAlias);

                if (def != null)
                {
                    var parameters = allParameters.Where(p => p.Widget.Id == widget.Id).ToArray();

                    var model = GetWidgetModel(def, widget, parameters, session);

                    if (model != null)
                    {
                        list.Add(model);
                    }
                }
            }
            return list.ToArray();
        }
		private object[] GetPanelListModel(Panel[] allPanels, Widget[] allWidgets, WidgetParameter[] allParameters, ISession session)
		{
			var list = new List<object>();

			foreach (var panel in allPanels)
			{
				var panelWidgets = allWidgets.Where(w => w.Panel.Id == panel.Id).ToArray();
				var widgetListModel = GetWidgetListModel(panelWidgets, allParameters, session);

				var model = new {
					id = panel.Id,
					title = panel.Title,
					widgets = widgetListModel,
					sortOrder = panel.SortOrder
				};

				list.Add(model);
			}

			return list.ToArray();
		}
		private void FillEditorModel(Tuple<EditorModel, EditorParameterModel[]> model, Widget widget, WidgetParameter[] parameters)
		{
			model.Item1.id = widget.Id;
			model.Item1.displayName = widget.DisplayName;

			foreach (var parameter in parameters)
			{
				var pmodel = model.Item2.FirstOrDefault(p => p.name == parameter.Name);

				if (pmodel != null)
				{
					switch (pmodel.type)
					{
						case "guid":
							pmodel.value = parameter.ValueGuid;
							break;
						case "int32":
							pmodel.value = parameter.ValueInt;
							break;
						case "string":
							pmodel.value = parameter.ValueString;
							break;
					}
				}
			}
		}
		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);
		}