Esempio n. 1
0
        public void TakeDroneInfo(byte[] infoBytes)
        {
            string    deviceId = Encoding.Default.GetString(infoBytes);
            DroneInfo dInfo    = DroneList.GetDroneInfo(mainForm, deviceId);
            string    ap       = dInfo.GetAPName();

            if (ap.Length == 0)
            {
                server.DeleteClient(this.id);
            }

            server.WriteData(this.id, Encoding.UTF8.GetBytes(ap));
            this.isGetSpec = true;
        }
Esempio n. 2
0
        public static bool AddDroneInfo(MainForm mainForm, string id, DroneInfo dInfo)
        {
            BinaryFormatter binFmt = new BinaryFormatter();

            lock (droneListLocker)
            {
                FileStream fs = new FileStream(DRONE_LIST_NAME, FileMode.OpenOrCreate);
                Dictionary <string, DroneInfo> droneList;

                if (fs.Length != 0)
                {
                    object droneListObj = binFmt.Deserialize(fs);
                    try
                    {
                        droneList = (Dictionary <string, DroneInfo>)droneListObj;
                    }
                    catch (InvalidCastException e)
                    {
                        // When list file is wrong format.
                        mainForm.ShowMessageBox("Drone list file has wrong format.");
                        fs.Close();
                        return(false);
                    }
                }
                else
                {
                    droneList = new Dictionary <string, DroneInfo>();
                }
                fs.Close();

                if (droneList.ContainsKey(id))
                {
                    mainForm.ShowMessageBox("Device ID is already exist in the table.");
                    fs.Close();
                    return(false);
                }

                fs = new FileStream(DRONE_LIST_NAME, FileMode.Create);
                droneList.Add(id, dInfo);
                binFmt.Serialize(fs, droneList);
                fs.Close();
            }

            return(true);
        }