Exemplo n.º 1
0
        public bool DeleteDevice(string id)
        {
            string json = File.ReadAllText(devicesJsonPath);
            var    list = JsonConvert.DeserializeObject <List <ServerDevice> >(json);

            ServerDevice deviceToDelete = list.Where(device => device.id == id).FirstOrDefault();
            var          index          = list.IndexOf(deviceToDelete);

            if (index != -1)
            {
                list[index].updated = DateTime.UtcNow.ToString(DateFormat);
                list[index].deleted = true;
                var updatedJson = JsonConvert.SerializeObject(list, Formatting.Indented);
                File.WriteAllText(devicesJsonPath, updatedJson);
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        public bool UpdateDevice(Device updatedDevice)
        {
            string json = File.ReadAllText(devicesJsonPath);
            var    list = JsonConvert.DeserializeObject <List <ServerDevice> >(json);

            ServerDevice deviceToUpdate = list.Where(device => device.id == updatedDevice.id && !device.deleted).FirstOrDefault();
            var          index          = list.IndexOf(deviceToUpdate);

            if (index != -1 && CraneIdValidation(updatedDevice.crane_id))
            {
                updatedDevice.updated = DateTime.UtcNow.ToString(DateFormat);
                var updatedServerDevice = Device.ConvertToServerDevice(updatedDevice, false);
                list[index] = updatedServerDevice;
                var updatedJson = JsonConvert.SerializeObject(list, Formatting.Indented);
                File.WriteAllText(devicesJsonPath, updatedJson);
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        public bool RestoreDevice(Device deviceToRestore)
        {
            string json = File.ReadAllText(devicesJsonPath);
            var    list = JsonConvert.DeserializeObject <List <ServerDevice> >(json);

            ServerDevice serverDeviceToRestore = list.Where(device => device.id == device.id).FirstOrDefault();
            var          index = list.IndexOf(serverDeviceToRestore);

            if (index != -1)
            {
                deviceToRestore.updated = DateTime.UtcNow.ToString(DateFormat);
                var restoreServerDevice = Device.ConvertToServerDevice(deviceToRestore, false);
                list[index] = restoreServerDevice;
                var updatedJson = JsonConvert.SerializeObject(list, Formatting.Indented);
                File.WriteAllText(devicesJsonPath, updatedJson);
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
 public PhotonServerPeer(InitRequest initRequest) : base(initRequest)
 {
     Device = new ServerDevice(new PhotonServerCommunicationInterface(this));
     DeviceFactory.Instance.AddDevice(Device);
 }