Esempio n. 1
0
        public DataList()
        {
            InitializeComponent();
            IList <DeviceCollectionEntity> list = new DeviceCollectionData().GetDeviceCollectionData();

            this.dataGridView1.DataSource = new BindingList <DeviceCollectionEntity>(list);
        }
Esempio n. 2
0
    public static void SaveDeviceCollection(DeviceCollection deviceCollection)
    {
        string path = Application.persistentDataPath + FILE_NAME;
        DeviceCollectionData deviceCollectionData = new DeviceCollectionData(deviceCollection);

        using (StreamWriter stream = new StreamWriter(path))
        {
            string json = JsonUtility.ToJson(deviceCollectionData);
            stream.Write(json);
        }
    }
Esempio n. 3
0
    public void LoadDeviceCollection()
    {
        RegisteredDevices.Clear();                      // just for safety but it's not even neccesary, because LoadDeviceCollection() gets only called when the app starts or when the registeredDevice array is already empty

        DeviceCollectionData deviceCollectionData = SaveAndLoadSystem.LoadDeviceCollection();

        if (deviceCollectionData != null)
        {
            if (deviceCollectionData.DeviceDataList != null)
            {
                for (int i = 0; i < deviceCollectionData.DeviceDataList.Length; i++)
                {
                    DeviceData deviceData = (DeviceData)deviceCollectionData.DeviceDataList[i];
                    IDevice    device     = null;

                    Debug.Log("device type name: " + deviceData.GetType().Name);

                    switch (deviceData.GetType().Name)
                    {
                    case "LampData":
                        device = new Lamp(deviceData.DeviceName, deviceData.Id, deviceData.Name);
                        break;

                    default:
                        Debug.LogError("Unknown Device Data Type");
                        break;
                    }

                    if (device != null)
                    {
                        device.LoadDevice(deviceData);
                        RegisteredDevices.Add(device);
                    }
                }
            }

            AllDevicesOff = deviceCollectionData.AllDevicesOff;
        }
    }