Exemplo n.º 1
0
        private bool ExecuteFile(GCInterface gcInterface, DeviceFileType type, bool wait)
        {
            switch (type)
            {
            case DeviceFileType.StartScript:
                return(ServiceControl.SetServiceStatus(gcInterface.InterfaceName, AdapterStatus.Running));

            case DeviceFileType.StopScript:
                return(ServiceControl.SetServiceStatus(gcInterface.InterfaceName, AdapterStatus.Stopped));
            }

            // map type
            DeviceFileType t = type;

            if (type == DeviceFileType.InstallScript ||
                type == DeviceFileType.UninstallScript)
            {
                t = DeviceFileType.ServiceAssembly;
            }

            // find script
            DeviceFile file = gcInterface.Directory.Files.FindFirstFile(t);

            if (file == null)
            {
                GCError.SetLastError("Cannot find file : " + t.ToString() + " in " + gcInterface.ToString());
                return(false);
            }

            // find installer
            DeviceFile installer = gcInterface.Directory.Files.FindFirstFile(DeviceFileType.Installer);

            if (installer == null)
            {
                GCError.SetLastError("Cannot find installer in " + gcInterface.ToString());
                return(false);
            }

            ProcessControl pc              = new ProcessControl();
            string         exefilename     = ConfigHelper.GetFullPath(gcInterface.FolderPath + "\\" + file.Location);
            string         installfilename = ConfigHelper.GetFullPath(gcInterface.FolderPath + "\\" + installer.Location);

            switch (type)
            {
            case DeviceFileType.ConfigAssembly:
                return(ProcessControl.ExecuteAssemblyDirectly(exefilename, AdapterConfigArgument.InIMWizard));

            case DeviceFileType.MonitorAssembly:
                return(ProcessControl.ExecuteAssemblyDirectly(exefilename, ""));

            case DeviceFileType.InstallScript:
                return(pc.ExecuteAssembly(installfilename, "\"" + exefilename + "\"", true));

            case DeviceFileType.UninstallScript:
                return(pc.ExecuteAssembly(installfilename, "-u \"" + exefilename + "\"", true));
            }

            return(false);
        }