/// <summary> /// ServiceType: 1: XDagger 2: Eth /// </summary> /// <param name="serviceType"></param> /// <returns></returns> public static ServiceProvider GetServiceProvider(MinerConfig.InstanceTypes serviceType) { switch (serviceType) { case MinerConfig.InstanceTypes.XDagger: return(new XDaggerServiceProvider()); case MinerConfig.InstanceTypes.Eth: return(new EthServiceProvider()); default: return(null); } }
private bool CheckAndCleanupPreviousService() { if (minerConfig.UpdatedInstanceType == null) { // Nothing to be updated. logger.Trace("UpdatedInstanceType is null, no need to update."); return(false); } // Uninstall the previous service instance MinerConfig.InstanceTypes instanceType = minerConfig.InstanceType; int instanceId = minerConfig.InstanceId; logger.Trace($"Try to find service with InstanceType=[{instanceType}] InstanceId=[{instanceId}]."); ServiceProvider serviceProvider = ComposeServiceProvider(minerConfig.InstanceType); ServiceInstance serviceInstance = serviceProvider.AquaireInstance(minerConfig.InstanceId); if (serviceInstance.IsServiceExist()) { logger.Trace("IsServiceExist is true, try uninstalling the previous service."); try { serviceProvider.UninstallService(instanceId); } catch (Exception ex) { // Will continue when uninstalling is failed. logger.Error("Got error while uninstalling: " + ex.ToString()); } } // If the uninsallation is successful, update the config file minerConfig.InstanceType = minerConfig.UpdatedInstanceType.Value; minerConfig.InstanceId = minerConfig.UpdatedInstanceId ?? 0; minerConfig.UpdatedInstanceType = null; minerConfig.UpdatedInstanceId = null; minerConfig.SaveToFile(); logger.Trace("Updated miner config file."); return(true); }