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
			};
		}
Ejemplo 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();
        }
Ejemplo n.º 6
0
		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);
		}
		private void SaveWidgetFields(Widget widget, HttpRequestParams request, ISession session)
		{
			var def = defs.GetValueOrDefault(widget.TypeAlias);

			if (def != null)
			{
				session.Query<WidgetParameter>()
					.Where(p => p.Widget.Id == widget.Id)
					.ForEach(session.Delete);

				session.Flush();

				var fields = def.GetWidgetMetaData(session, Logger) 
					?? new WidgetParameterMetaData[0];

				var json = request.GetRequiredString("json");
				var values = Extensions.FromJson<Dictionary<string, string>>(json);

				foreach (var field in fields)
				{
					var value = values.GetValueOrDefault(field.Name);

					CreateParameter(session, widget, field, value);
				}

				session.Flush();
			}
		}
		private Widget CreateWidget(HttpRequestParams request, ISession session)
		{
			var type = request.GetRequiredString("type");
			var panelId = request.GetRequiredGuid("panelId");

			var panel = session.Query<Panel>().Single(x => x.Id == panelId);

			var created = new Widget
			{
				Id = Guid.NewGuid(),
				Panel = panel,
				TypeAlias = type,
				SortOrder = int.MaxValue
			};

			return created;
		}
Ejemplo n.º 11
0
		private object GetWidgetModel(Widget widget) 
		{
			var typeDisplayName = defs.ContainsKey(widget.TypeAlias)
				? defs[widget.TypeAlias].DisplayName
				: string.Format("[{0}]", widget.TypeAlias);

			var displayName = string.IsNullOrEmpty(widget.DisplayName) ? "[no name]" : widget.DisplayName;

			var widgetModel = new
			{
				id = widget.Id,
				type = widget.TypeAlias,
				sortOrder = widget.SortOrder,
				displayName,
                typeDisplayName
			};

			return widgetModel;
		}
        private Widget CreateWidget(HttpRequestParams request, ISession session)
        {
            var type = request.GetRequiredString("type");
            var dashboardId = request.GetRequiredGuid("dashboardId");

            var dashboard = session.Query<Dashboard>().Single(x => x.Id == dashboardId);

            var created = new Widget
            {
                Id = Guid.NewGuid(),
                Dashboard = dashboard,
                TypeAlias = type,
                SortOrder = int.MaxValue
            };

            return created;
        }