Esempio n. 1
0
        private void _startTimer_Elapsed(object sender, timer.ElapsedEventArgs e)
        {
            foreach (var connectionString in _connectionStrings)
            {
                Log.WriteErrorLog("Processing connection :");

                List <ProcessJob> jobs = null;

                try
                {
                    //get new or pending extraction template
                    jobs = _dataManager.GetNewOrPendingProcessJobs(connectionString);

                    Log.WriteErrorLog("Job found :" + jobs.Count().ToString());

                    foreach (var job in jobs)
                    {
                        Log.WriteErrorLog("Processing job :" + job.Code);

                        var service = ServiceExist(job.Code);

                        if (job.Status == PackageStatus.New)
                        {
                            if (service == null)
                            {
                                string svcName     = job.Code;
                                string svcDispName = "Fintrak " + job.Code + " " + " Service";

                                //get username and password
                                string userName = null;
                                string password = null;

                                if (Account == ServiceAccount.User)
                                {
                                    userName = UserName;
                                    password = Password;
                                }

                                CustomServiceInstaller c = new CustomServiceInstaller();
                                c.InstallService(_servicePath, svcName, svcDispName, userName, password, connectionString);

                                //Update job to running
                                job.Status = PackageStatus.Running;
                                job.Remark = "Job running...";
                                _dataManager.UpdateProcessJob(connectionString, job);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteErrorLog(ex);
                }
            }
        }
Esempio n. 2
0
 public CustomInstaller()
 {
     _installProcess = new ServiceProcessInstaller {
         Account = ServiceAccount.NetworkService
     };
     _installService = new CustomServiceInstaller(typeof(ServiceImplementation));
     //  Remove built-in EventLogInstaller:
     _installService.Installers.Clear();
     Installers.Add(_installProcess);
     Installers.Add(_installService);
 }
Esempio n. 3
0
        public static bool UnInstall()
        {
            CustomServiceInstaller si = new CustomServiceInstaller();

            if (si.UnInstallService(UO98Service.UniqueServiceName))
            {
                Console.WriteLine("The {0} service has been uninstalled. You may need to reboot to remove it completely.", UO98Service.UniqueServiceName);
                return(true);
            }
            else
            {
                Console.WriteLine("An error occurred during service removal.");
                return(false);
            }
        }
Esempio n. 4
0
        public static bool Install()
        {
            CustomServiceInstaller si = new CustomServiceInstaller();

            if (si.InstallService(Assembly.GetExecutingAssembly().Location + " -service", UO98Service.UniqueServiceName, "UO:98 Ultima Online Server", true))
            {
                Console.WriteLine("The {0} service has been installed.", UO98Service.UniqueServiceName);
                return(true);
            }
            else
            {
                Console.WriteLine("An error occurred during service installation.");
                return(false);
            }
        }
Esempio n. 5
0
        private void UninstallService()
        {
            foreach (var connectionString in _connectionStrings)
            {
                List <ProcessJob> jobs = null;

                try
                {
                    //get new or pending extraction template
                    jobs = _dataManager.GetProcessJobsToStop(connectionString);

                    lock (jobs)
                    {
                        foreach (var job in jobs)
                        {
                            if (job.Status == PackageStatus.Stop || job.Status == PackageStatus.Done || job.Status == PackageStatus.Fail)
                            {
                                var service = ServiceExist(job.Code);
                                if (service != null)
                                {
                                    CustomServiceInstaller c = new CustomServiceInstaller();
                                    c.UnInstallService(job.Code);

                                    //Update job to running
                                    job.Status = PackageStatus.Removed;
                                    job.Remark = "Job done...";
                                    _dataManager.UpdateProcessJob(connectionString, job);

                                    Log.WriteErrorLog(string.Format("Package service for {0} has now been un-installed", job.Code));
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteErrorLog(ex);
                }
            }
        }
        /// <summary>
        /// This method is used to actually install the service.  The service is installed with the 
        /// specified dependency included.  If the dependency parameter is null, no dependency is
        /// created.
        /// </summary>
        /// <param name="customInstaller">The installer object.</param>
        /// <param name="dependencies">The specified dependency.</param>
        static void Install(CustomServiceInstaller customInstaller, string dependencies)
        {
            //	Make sure that the service does not already exist as an installed service
            //if (customInstaller.DoesServiceExists(WindowsServiceConstants.SERVICE_NAME) == false)
            if (customInstaller.DoesServiceExists(ServiceName) == false)
            {
                //	Build the path to the executable
                var sServiceExe = Environment.CurrentDirectory + "\\" + WindowsServiceConstants.SERVICE_EXECUTABLE;

                //	Attempts to install the service.
                var bSuccess = customInstaller.InstallService(sServiceExe, ServiceName, DisplayName, ServiceDescription,
                    CustomServiceInstaller.SERVICE_START_TYPE.SERVICE_AUTO_START,
                    dependencies);

                if (bSuccess == false)
                    throw new Exception("Unable to install the service successfully.");
            }
            else
                throw new Exception("The service already exists as an installed service.");
        }
 /// <summary>
 /// This method is used to install the service without a dependency.  This would need 
 /// to be the case if the dependency doesn't actually exist.
 /// </summary>
 /// <param name="customInstaller">The custom installer.</param>
 static void Install(CustomServiceInstaller customInstaller)
 {
     Install(customInstaller, null);
 }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        /// <returns>S_OK (0) if no error has occurred, otherwise the error number.</returns>
        static int Main(string[] args)
        {
            var nResult = S_OK;

            //  Setup your default properties
            ConfigurationFilePath = VirtualServiceStore.VIRTUAL_SERVICE_CONFIG_FOLDER;

            try
            {
                //	Declare variables
                ServiceController scController = null;
                CustomServiceInstaller cusInstaller = new CustomServiceInstaller();
                var bSuccess = false;

                //  Look in the application settings of the configuration file.
                if (String.IsNullOrEmpty(ConfigurationManager.AppSettings["ServiceName"]) == false)
                    ServiceName = ConfigurationManager.AppSettings["ServiceName"];
                else
                    ServiceName = WindowsServiceConstants.SERVICE_NAME;

                //  Parse out the command line parameters
                ParseCommandLineArguments(args);

                //  Parse out the registry items.
                ParseRegistry();

                //  Create your service controller
                scController = new ServiceController(ServiceName);

                //  Determine how many command line arguments accompanied the executable
                if (args.Length > 0)
                {
                    switch (args[0].ToUpper())
                    {
                        case "-INSTALL":
                            {
                                //  Install the service
                                Install(cusInstaller);

                                //	Write a success message out
                                Console.WriteLine("The service was installed successfully.");

                                break;
                            }
                        case "-UNINSTALL":
                        case "-REMOVE":
                            {
                                //	Make sure that the service is not already uninstalled (never installed)
                                if (cusInstaller.DoesServiceExists(ServiceName) == true)
                                {
                                    //	Attempt to uninstall the service.
                                    bSuccess = cusInstaller.UnInstallService(ServiceName,
                                                                                WindowsServiceConstants.TIMEOUT,
                                                                                WindowsServiceConstants.POLLDELAY);
                                    if (bSuccess == false)
                                        throw new Exception("Unable to uninstall the service successfully.");

                                    //	Write out a success message
                                    Console.WriteLine("The service was uninstalled successfully.");
                                }
                                else
                                    throw new Exception("The service does not exist as an installed service.");

                                break;
                            }
                        case "-STATUS":
                            {
                                //	Write the status of the service to the console
                                Console.WriteLine("Service Status:" + scController.Status.ToString() + Environment.NewLine);
                                break;
                            }
                        case "-START":
                            {
                                //  Make sure that the service is stopped
                                if (scController.Status == ServiceControllerStatus.Stopped)
                                {
                                    //  Attempt to start the service
                                    scController.Start();
                                    Console.WriteLine("The service was started successfully.");
                                }
                                else
                                    Console.WriteLine("Current Service State:" + scController.Status.ToString() +
                                                        Environment.NewLine +
                                                        "The service is not in a state which can be started.");
                                break;
                            }
                        case "-STOP":
                            {
                                //  Make sure that the service is stopped
                                if (scController.Status == ServiceControllerStatus.Running)
                                {
                                    //  Attempt to start the service
                                    scController.Stop();
                                    Console.WriteLine("The service was stopped successfully.");
                                }
                                else
                                    Console.WriteLine("Current Service State:" + scController.Status.ToString() +
                                                        Environment.NewLine +
                                                        "The service is not in a state which can be stopped.");
                                break;
                            }
                        case "-PAUSE":
                            {
                                //  Make sure that the service is stopped
                                if (scController.Status == ServiceControllerStatus.Running)
                                {
                                    //  Attempt to start the service
                                    scController.Pause();
                                    Console.WriteLine("The service was paused successfully.");
                                }
                                else
                                    Console.WriteLine("Current Service State:" + scController.Status.ToString() +
                                                        Environment.NewLine +
                                                        "The service is not in a state which can be paused.");
                                break;
                            }
                        case "-CONTINUE":
                        case "-RESUME":
                            {
                                //  Make sure that the service is stopped
                                if (scController.Status == ServiceControllerStatus.Paused)
                                {
                                    //  Attempt to start the service
                                    scController.Continue();
                                    Console.WriteLine("The service was resumed successfully.");
                                }
                                else
                                    Console.WriteLine("Current Service State:" + scController.Status.ToString() +
                                                        Environment.NewLine +
                                                        "The service is not in a state which can be resumed.");
                                break;
                            }
                        case "-CONSOLEHOST":
                            {
                                //  Create the console host service controller
                                var svcConsoleHostCtrl = new ServicesManagerConsoleHostContoller();

                                if (String.IsNullOrEmpty(ConfigurationFilePath) == false)
                                    svcConsoleHostCtrl.ConfigurationFolder = ConfigurationFilePath;

                                svcConsoleHostCtrl.Start();
                                break;
                            }
                        default:
                            {
                                //  Output the message telling them about the valid arguments
                                Console.WriteLine(CMDLINE_ARG_MSG);
                                throw new InvalidOperationException("Command line arguments not recognized.");
                            }
                    }
                }
                else
                {
                    //  Since no arguments were passed, just attempt to start the service as a normal
                    //  windows service (The windows service control manager calls this methods)
                    ServiceBase[] ServicesToRun;
                    ServicesToRun = new ServiceBase[]
                    {
                        new VSFWinServ(ConfigurationFilePath)
                    };
                    ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                    Debugger.Break();
                Trace.WriteLine(ex);
                Console.WriteLine("\nUnable to perform the selected action\n\nSource: " + ex.Source + "\nDescription: " + ex.Message);
                nResult = 69;
            }

            return nResult;
        }