예제 #1
0
        public override DashboardJSONValues GetResponse(System.Collections.Generic.Dictionary <string, string[]> requestAttributes)
        {
            var keys = MonitoringManager.DashboardDeviceKeys;

            if (requestAttributes.ContainsKey("keys"))
            {
                var requestedKeys = requestAttributes ["keys"].ToString().Split("|".ToCharArray());
                keys = keys.Where(k => requestedKeys.Contains(k));
            }

            return(new DashboardJSONValues(keys.Select(k => new DashboardJSONValue(k, MonitoringManager.ReadDevice(k), MonitoringManager.Min(k), MonitoringManager.Max(k), MonitoringManager.Name(k), MonitoringManager.Suffix(k)))));
        }
예제 #2
0
        public override JSONObject GetResponse(Dictionary <string, string[]> requestAttributes)
        {
            bool          _parseSuccess    = true;
            List <string> _tempSensorNames = new List <string> ();

            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format("DeviceType = {0}", (int)DeviceType.Temperature));

            if (requestAttributes.ContainsKey("names"))
            {
                bool firstName = true;
                if (sb.Length > 0)
                {
                    sb.Append(" AND ");
                }
                sb.Append("(");

                foreach (string name in requestAttributes["names"].ToString().Split("|".ToCharArray()))
                {
                    if (firstName)
                    {
                        firstName = false;
                    }
                    else
                    {
                        sb.Append(" OR ");
                    }

                    sb.Append(string.Format("Name like '{0}'", name));
                }

                sb.Append(")");
            }

            var conn = ORM.CreateConnection();
            DeviceLogJSONResponse resp = null;

            try
            {
                conn.Open();

                var maps = ORM.Select <DeviceMap> ("DeviceMap", sb.ToString(), ref conn);
                var logs = new List <DeviceLog>();
                foreach (var map in maps)
                {
                    MonitoringManager.ReadDevice(map.DeviceKey);
                }
                resp = new DeviceLogJSONResponse(logs, maps);
            }
            catch (Exception ex) {
                LogWriter.WriteLog(string.Format("An error was encountered while attempting to get temperature logs for the filter '{0}'", sb.ToString()), ex);
            }
            conn.Close();

            if (!_parseSuccess)
            {
                return(null);
            }
            else
            {
                return(resp);
            }
        }