Exemplo n.º 1
0
        public static List <object> ChangeParam(string message, string deviceType)
        {
            Propities     propities = new Propities();
            ServerMessage m         = ServerMessageConvert(message);

            switch (deviceType)
            {
            case "tv.json":
                List <TVDevicePropities> tVDevicePropities = propities.GetTVDevicePropities();
                TVDevicePropities        currentTv         = tVDevicePropities.Find(tVDevicePropities => tVDevicePropities.deviceId == m.deviceid);



                if (currentTv != null)
                {
                    currentTv.ParamChange(m.param, m.val);
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + " (WARNING): Device not found in tv.json-----------------------");
                }


                List <object> listTv = new List <object>();
                foreach (TVDevicePropities cur in tVDevicePropities)
                {
                    listTv.Add((object)cur);
                }
                return(listTv);

            case "projector.json":
                List <ProjectorDevicePropities> projectorDevicePropities = propities.GetProjectorDevicePropities();
                ProjectorDevicePropities        currentProj = projectorDevicePropities.Find(projectorDevicePropities => projectorDevicePropities.deviceId == m.deviceid);
                //for projector here

                if (currentProj != null)
                {
                    currentProj.ParamChange(m.param, m.val);
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + " (WARNING): Device not found in projector.json");
                }

                List <object> listProj = new List <object>();
                foreach (ProjectorDevicePropities cur in projectorDevicePropities)
                {
                    listProj.Add((object)cur);
                }
                return(listProj);

            default:
                Console.WriteLine(DateTime.Now.ToShortTimeString() + " (WARNING): Device with recived token not found in devices");
                return(null);
            }
        }
Exemplo n.º 2
0
        private List <ProjectorDevicePropities> ReadProjectorDevicePropities()
        {
            List <ProjectorDevicePropities> projectorDevicePropities = new List <ProjectorDevicePropities>();
            List <object> list = JsonWorker.ReadDevices(Path.Combine(path, "projector.json"));

            foreach (object current in list)
            {
                projectorDevicePropities.Add(ProjectorDevicePropities.ConvertFromJObject(current));
            }
            return(projectorDevicePropities);
        }
Exemplo n.º 3
0
        public static ProjectorDevicePropities ConvertFromJObject(object?currentObject)
        {
            JObject jObject = (JObject)currentObject;
            ProjectorDevicePropities device = new ProjectorDevicePropities();

            device.deviceId     = jObject.GetValue("deviceId").ToString();
            device.status       = Convert.ToBoolean(jObject.GetValue("status").ToString());
            device.errorCode    = (ErrorCode)Enum.Parse(typeof(ErrorCode), jObject.GetValue("errorCode").ToString());
            device.errorMessage = jObject.GetValue("errorMessage").ToString();
            device._lamphours   = Convert.ToInt32(jObject.GetValue("lamphours").ToString());
            device.lampStatus   = (LampStatus)Enum.Parse(typeof(LampStatus), jObject.GetValue("lampStatus").ToString());
            device.input        = (Input)Enum.Parse(typeof(Input), jObject.GetValue("input").ToString());
            device.power        = (Power)Enum.Parse(typeof(Power), jObject.GetValue("power").ToString());

            return(device);
        }
Exemplo n.º 4
0
        public static string ChangeParamSending(string message, string deviceType)
        {
            string        json;
            Propities     propities         = new Propities();
            ServerMessage m                 = ServerMessageConvert(deviceType);
            string        currentDeviceType = FindDevice(deviceType);

            //change param analog here
            switch (currentDeviceType)
            {
            case "tv.json":
                List <TVDevicePropities> tVDevicePropities = propities.GetTVDevicePropities();
                TVDevicePropities        curentTv          = tVDevicePropities.Find(tVDevicePropities => tVDevicePropities.deviceId == m.deviceid);

                if (curentTv != null)
                {
                    curentTv.ParamChange(m.param, m.val);
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + " (WARNING): Device not found in tv.json");
                }

                return(propities.DeviceToServerMessage(curentTv, currentDeviceType));

            case "projector.json":

                List <ProjectorDevicePropities> projectorDevicePropities = propities.GetProjectorDevicePropities();
                ProjectorDevicePropities        currentProj = projectorDevicePropities.Find(projectorDevicePropities => projectorDevicePropities.deviceId == m.deviceid);

                if (currentProj != null)
                {
                    currentProj.ParamChange(m.param, m.val);
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + " (WARNING): Device not found in projector.json");
                }

                return(propities.DeviceToServerMessage(currentProj, currentDeviceType));

            default:
                return(null);
            }
        }