コード例 #1
0
        public bool DeleteDevice(GCDevice device)
        {
            GCError.ClearLastError();

            //validate device
            if (device == null || device.DeviceID < 0)
            {
                GCError.SetLastError("Invalid device.");
                return(false);
            }

            //delete record from database
            if (!DeviceTable.DeleteDevice(device.DeviceID))
            {
                GCError.SetLastError("Delete device from database failed.");
                return(false);
            }

            //delete device folder
            if (!FolderControl.DeleteDevice(device.FolderPath))
            {
                GCError.SetLastError("Delete device folder " + device.FolderPath + " failed.");
                return(false);
            }

            return(true);
        }
コード例 #2
0
        public bool DeleteInterfaceFromFolder(GCInterface gcInterface)
        {
            GCError.ClearLastError();

            // validation
            if (gcInterface == null)
            {
                GCError.SetLastError("Invalid gcInterface object.");
                return(false);
            }

            // delete folder
            string folderPath = gcInterface.FolderPath;
            bool   result     = FolderControl.DeleteDevice(folderPath);

            if (!result)
            {
                GCError.SetLastError("Delete folder " + folderPath + "  failed.");
            }

            return(result);
        }
コード例 #3
0
        public GCInterface AddInterfaceToFolder(GCDevice gcDevice, string interfaceName, string interfacDesc)
        {
            GCError.ClearLastError();

            // validation
            if (gcDevice == null || gcDevice.Directory == null)
            {
                GCError.SetLastError("Invalid device object.");
                return(null);
            }

            int progCount = 0;
            int fileCount = gcDevice.Directory.Files.Count;

            NotifyStart(fileCount + 2, 0, progCount++, "Create interface folder...");

            // create interface folder
            string targetFolder = InterfacesFolder + "\\" + interfaceName;

            try
            {
                if (Directory.Exists(targetFolder))
                {
                    GCError.SetLastError("Folder " + targetFolder + " have already exist, please try another name.");
                    NotifyComplete(false, "");
                    return(null);
                }

                if (Directory.CreateDirectory(targetFolder) == null)
                {
                    GCError.SetLastError("Cannot create folder " + targetFolder + ", please try another name.");
                    NotifyComplete(false, "");
                    return(null);
                }
            }
            catch (Exception e)
            {
                GCError.SetLastError("Cannot create folder " + targetFolder);
                GCError.SetLastError(e);
                NotifyComplete(false, "");
                return(null);
            }

            // copy device files
            DeviceDir dir          = gcDevice.Directory;
            string    sourceFolder = gcDevice.FolderPath;
            string    sourceFile   = sourceFolder + "\\" + DeviceDirManager.IndexFileName;
            string    targetFile   = targetFolder + "\\" + DeviceDirManager.IndexFileName;

            try
            {
                NotifyGoing(progCount++, "Copying files... ");
                File.Copy(sourceFile, targetFile);
                foreach (DeviceFile f in dir.Files)
                {
                    NotifyGoing(progCount++, "Copying files...");
                    sourceFile = sourceFolder + "\\" + f.Location;
                    targetFile = targetFolder + "\\" + f.Location;

                    // support sub folder in device dir
                    string path = Path.GetDirectoryName(targetFile);
                    if (!Directory.Exists(path))
                    {
                        if (Directory.CreateDirectory(path) == null)
                        {
                            GCError.SetLastError("Cannot create folder " + path);
                            NotifyComplete(false, "");
                            return(null);
                        }
                    }

                    File.Copy(sourceFile, targetFile);
                }
            }
            catch (Exception e)
            {
                GCError.SetLastError("Cannot copy file from " + sourceFile + " to " + targetFile);
                GCError.SetLastError(e);
                NotifyComplete(false, "");

                // roll back...
                FolderControl.DeleteDevice(targetFolder);
                return(null);
            }

            NotifyGoing(progCount++, "Updating files...");

            // update DeviceDir: save interface name, which will be used by interface installation program
            GCDevice device = FolderControl.LoadDevice(targetFolder);

            device.Directory.Header.RefDeviceName = gcDevice.DeviceName;
            device.Directory.Header.RefDeviceID   = gcDevice.DeviceID.ToString();
            device.Directory.Header.Description   = interfacDesc;
            device.Directory.Header.Name          = interfaceName;
            if (!FolderControl.SaveDevice(device))
            {
                GCError.SetLastError("Update device index file failed.");
                NotifyComplete(false, "");

                // roll back...
                FolderControl.DeleteDevice(targetFolder);
                return(null);
            }

            // create interface object
            GCInterface i = new GCInterface();

            i.Directory     = device.Directory;
            i.InterfaceName = interfaceName;
            i.FolderPath    = targetFolder;
            i.Device        = gcDevice;

            NotifyComplete(true, "");

            return(i);
        }
コード例 #4
0
        public GCDevice AddDevice(string folder)
        {
            GCError.ClearLastError();

            // check if the folder contains a device
            if (!FolderControl.IsDevicePath(folder))
            {
                GCError.SetLastError("Invalid device folder.");
                return(null);
            }

            // load device information from DeviceDir file
            GCDevice device = FolderControl.LoadDevice(folder);

            if (device == null)
            {
                GCError.SetLastError("Invalid device index file.");
                return(null);
            }

            // check whether a same device has already been installed
            // (if we do not do this, license control on max interface count will be useless.
            if (DeviceTable.HasSameDevice(device))
            {
                GCError.SetLastError("Device (Type: " + device.Directory.Header.Type.ToString()
                                     + ", Direction: " + device.Directory.Header.Direction.ToString()
                                     + ") has already been installed.");
                return(null);
            }

            // insert device information into database
            if (!DeviceTable.InsertDevice(device))
            {
                GCError.SetLastError("Insert database failed.");
                return(null);
            }

            // get device id for return;
            device.DeviceID = DeviceTable.GetMaxID();
            if (device.DeviceID < 1)
            {
                GCError.SetLastError("Invalid device ID.");
                return(null);
            }

            // create device folder
            string folderName = DevicesFolder + "\\" + device.DeviceName;

            try
            {
                FolderControl.DeleteDevice(folderName);     //according to defect EK_HI00045030 , 2006/11/20
                Directory.CreateDirectory(folderName);
            }
            catch (Exception err)
            {
                GCError.SetLastError(err);
                GCError.SetLastError("Cannot create directory " + folderName);
                DeviceTable.DeleteDevice(device.DeviceID);
                return(null);
            }

            // copy device files
            string sourceFile = "";
            string targetFile = "";

            try
            {
                sourceFile = device.FolderPath + "\\" + DeviceDirManager.IndexFileName;
                targetFile = folderName + "\\" + DeviceDirManager.IndexFileName;
                File.Copy(sourceFile, targetFile);

                foreach (DeviceFile f in device.Directory.Files)
                {
                    sourceFile = device.FolderPath + "\\" + f.Location;
                    targetFile = folderName + "\\" + f.Location;

                    // support sub folder in device dir
                    string path = Path.GetDirectoryName(targetFile);
                    if (!Directory.Exists(path))
                    {
                        if (Directory.CreateDirectory(path) == null)
                        {
                            GCError.SetLastError("Cannot create folder " + path);
                            return(null);
                        }
                    }

                    File.Copy(sourceFile, targetFile);
                }
            }
            catch (Exception err)
            {
                GCError.SetLastError(err);
                GCError.SetLastError("Cannot copy file from " + sourceFile + " to " + targetFile);
                DeviceTable.DeleteDevice(device.DeviceID);
                return(null);
            }

            // update DeviceDir: save device id
            GCDevice newDevice = FolderControl.LoadDevice(folderName);

            newDevice.Directory.Header.ID = device.DeviceID.ToString();
            if (!FolderControl.SaveDevice(newDevice))
            {
                GCError.SetLastError("Update device index file failed.");
                return(null);
            }

            // update device record
            device.FolderPath = folderName;
            if (!DeviceTable.UpdateDevice(device))
            {
                GCError.SetLastError("Update database failed.");
                return(null);
            }

            return(device);
        }