public static void DeleteSetting(RegistryParam registryParam) { using (var regKey = GetRegistryKey(registryParam, true)) { regKey?.DeleteValue(registryParam.Name, false); } }
public static Result <T> GetSettings <T>(RegistryParam registryParam) { T regValue; using (var regKey = GetRegistryKey(registryParam)) { if (regKey == null) { return(Result <T> .Fail <T>("Registry Key is not found")); } if (registryParam.Name != null) { var value = regKey.GetValue(registryParam.Name, registryParam.Value); if (value == null) { return(Result <T> .Fail <T>("Registry Parameter is not found")); } regValue = (T)value; } else { var type = typeof(T).Name.ToLowerInvariant() == "string"; regValue = (T)(object)registryParam.Section; } } return(Result <T> .Ok(regValue)); }
public RegistryChangedEventArgs(RegChangeNotifyFilter regChangeNotifyFilter, RegistryParam previous, RegistryParam current, string[] subKeys) { RegChangeNotifyFilter = regChangeNotifyFilter; Previous = previous; Current = current; NewSubKeys = subKeys; }
public Task <ReturnT> RegistryRemove(RegistryParam registryParam) { return(InvokeRpcService("registryRemove", new List <object> { new JavaClass { Name = "com.xxl.job.core.biz.model.RegistryParam" } }, registryParam, true)); }
private static RegistryKey RegistryKeyLocalMachineX(RegistryParam registryParam, bool writable, bool create, RegistryView registryView) { var localMachineKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView); return(create ? localMachineKey.CreateSubKey(registryParam.RegistrySubKey, writable) : localMachineKey.OpenSubKey(registryParam.RegistrySubKey, writable)); }
private static void SaveRegistryEx(ResourceManager resourceManager, RegistryParam registryParam) { var executorRegistryService = new ExecutorRegistryService( resourceManager, registryParam, RegistryAdminAction.set, Guid.NewGuid()); executorRegistryService.Execute(); }
private static RegistryKey GetRegistryKey(RegistryParam registryParam, bool writable = false, bool create = false) { RegistryKey regKey; switch (registryParam.RegistryHive) { case RegistryHive.ClassesRoot: regKey = create ? Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(registryParam.RegistrySubKey, writable) : Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(registryParam.RegistrySubKey, writable); break; case RegistryHive.CurrentUser: regKey = create ? Microsoft.Win32.Registry.CurrentUser.CreateSubKey(registryParam.RegistrySubKey, writable) : Microsoft.Win32.Registry.CurrentUser.OpenSubKey(registryParam.RegistrySubKey, writable); break; case RegistryHive.LocalMachine: regKey = RegistryKeyLocalMachine(registryParam, writable, create); break; case RegistryHive.Users: regKey = create ? Microsoft.Win32.Registry.Users.CreateSubKey(registryParam.RegistrySubKey, writable) : Microsoft.Win32.Registry.Users.OpenSubKey(registryParam.RegistrySubKey, writable); break; case RegistryHive.PerformanceData: regKey = create ? Microsoft.Win32.Registry.PerformanceData.CreateSubKey(registryParam.RegistrySubKey, writable) : Microsoft.Win32.Registry.PerformanceData.OpenSubKey(registryParam.RegistrySubKey, writable); break; case RegistryHive.CurrentConfig: regKey = create ? Microsoft.Win32.Registry.CurrentConfig.CreateSubKey(registryParam.RegistrySubKey, writable) : Microsoft.Win32.Registry.CurrentConfig.OpenSubKey(registryParam.RegistrySubKey, writable); break; case RegistryHive.DynData: regKey = create #pragma warning disable CS0618 ? Microsoft.Win32.Registry.DynData.CreateSubKey(registryParam.RegistrySubKey, writable) : Microsoft.Win32.Registry.DynData.OpenSubKey(registryParam.RegistrySubKey, writable); #pragma warning restore CS0618 break; default: throw new ArgumentOutOfRangeException(nameof(registryParam.RegistryHive), registryParam.RegistryHive, null); } return(regKey); }
public static void SaveSetting(RegistryParam registryParam) { using (var regKey = GetRegistryKey(registryParam, true, true)) { if (regKey == null) { return; } regKey.SetValue(registryParam.Name, registryParam.Value, registryParam.RegistryValueKind); } }
public static IEnumerable <string> GetSubKeys(RegistryParam registryParam) { string[] regValue = { }; using (var regKey = GetRegistryKey(registryParam)) { if (regKey != null) { regValue = regKey.GetSubKeyNames(); } } return(regValue); }
private static RegistryKey RegistryKeyLocalMachine(RegistryParam registryParam, bool writable, bool create) { var regKey = RegistryKeyLocalMachineX(registryParam, writable, create, RegistryView.Registry64); if (regKey != null) { return(regKey); } regKey = RegistryKeyLocalMachineX(registryParam, writable, create, RegistryView.Registry32); return(regKey); }
public static bool ExistsSettings(RegistryParam registryParam) { using (var regKey = GetRegistryKey(registryParam)) { if (regKey == null) { return(false); } if (registryParam.Name == null) { return(true); } var regValue = regKey.GetValue(registryParam.Name, registryParam.Value); return(regValue != null); } }
public static string Registry(string adminaddresses, string executorappname, string executorip, int executorPort, string accessToken) { /* * { * "serverAddress": "http://127.0.0.1:8080/api", * "createMillisTime": 1525923077142, * "accessToken": "", * "className": "com.xxl.job.core.biz.AdminBiz", * "methodName": "registry", * "parameterTypes": [ * "com.xxl.job.core.biz.model.RegistryParam" * ], * "parameters": [ * { * "registGroup": "EXECUTOR", * "registryKey": "xxl-job-executor-sample1", * "registryValue": "172.30.128.33:62347" * } * ] * } */ RegistryParam registryParam = new RegistryParam { registGroup = "EXECUTOR", registryKey = executorappname, registryValue = $"{executorip}:{executorPort}" }; RpcRequest rpcRequest = new RpcRequest { accessToken = accessToken, className = "com.xxl.job.core.biz.AdminBiz", createMillisTime = TimeUtil.CurrentTimeMillis(), methodName = "registry", parameters = new object[] { registryParam }, parameterTypes = new[] { "com.xxl.job.core.biz.model.RegistryParam" }, serverAddress = adminaddresses + "/api", }; var str = Newtonsoft.Json.JsonConvert.SerializeObject(rpcRequest); return(str); }
public async Task RegistryAsync(CancellationToken cancellationToken) { var registryParam = new RegistryParam { RegistryGroup = "EXECUTOR", RegistryKey = _options.AppName, RegistryValue = string.IsNullOrEmpty(_options.SpecialBindUrl)? $"http://{_options.SpecialBindAddress}:{_options.Port}/" : _options.SpecialBindUrl }; _logger.LogInformation(">>>>>>>> start registry to admin <<<<<<<<"); var errorTimes = 0; while (!cancellationToken.IsCancellationRequested) { try { var ret = await _adminClient.Registry(registryParam); _logger.LogDebug("registry last result:{0}", ret?.Code); errorTimes = 0; await Task.Delay(Constants.RegistryInterval, cancellationToken); } catch (TaskCanceledException) { _logger.LogInformation(">>>>> Application Stopping....<<<<<"); } catch (Exception ex) { errorTimes++; await Task.Delay(Constants.RegistryInterval, cancellationToken); _logger.LogError(ex, "registry error:{0},{1} Times", ex.Message, errorTimes); } } _logger.LogInformation(">>>>>>>> end registry to admin <<<<<<<<"); _logger.LogInformation(">>>>>>>> start remove registry to admin <<<<<<<<"); var removeRet = await this._adminClient.RegistryRemove(registryParam); _logger.LogInformation("remove registry last result:{0}", removeRet?.Code); _logger.LogInformation(">>>>>>>> end remove registry to admin <<<<<<<<"); }
public ExecutorRegistryService(ResourceManager resourceManager, RegistryParam registryParam, RegistryAdminAction registryAdminAction, object fileName) { RegistryAdminAction = registryAdminAction; if (fileName is Guid guidFileName) { RegistryFileName = guidFileName.ToString(); } else { RegistryFileName = (string)fileName; } RegistrySaver = new RegistrySaver(registryAdminAction, RegistryFileName) { RegistryParam = registryParam }; Name = NAME; Arguments = RegistrySaver.Arguments; ResourceManager = resourceManager; }
public ReturnT <String> registryRemove(RegistryParam registryParam) { return(PostPackage("registryRemove", new[] { "com.xxl.job.core.biz.model.RegistryParam" }, new[] { registryParam })); }
public Task <ReturnT> RegistryRemove(RegistryParam registryParam) { return(InvokeRpcService("registryRemove", registryParam)); }
private static void SetRegistryValue(ResourceManager resourceManager, RegistryParam registryParam, object value) { registryParam.Value = value; SaveRegistryEx(resourceManager, registryParam); }
public void start(int port, String ip, String appName) { // valid if (appName == null || appName.Trim().Length == 0) { logger.Warn(">>>>>>>>>>>> xxl-job, executor registry config fail, appName is null."); return; } if (XxlJobExecutor.getAdminBizList() == null) { logger.Warn(">>>>>>>>>>>> xxl-job, executor registry config fail, adminAddresses is null."); return; } // executor address (generate addredd = ip:port) String executorAddress; if (ip != null && ip.Trim().Length > 0) { executorAddress = ip.Trim() + (":") + port; } else { executorAddress = IpUtil.getIpPort(port); } registryThread = new Thread( () => { // registry while (!toStop1) { try { RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.ToString(), appName, executorAddress); foreach (AdminBiz adminBiz in XxlJobExecutor.getAdminBizList()) { try { Object registry = adminBiz.registry(registryParam); ReturnT <String> registryResult = adminBiz.registry(registryParam); if (registryResult != null && ReturnT <string> .SUCCESS_CODE == registryResult.code) { registryResult = ReturnT <string> .SUCCESS; logger.Info(string.Format(">>>>>>>>>>> xxl-job registry success, registryParam:{0}, registryResult:{1}", registryParam, registryResult)); break; } else { logger.Info(string.Format(">>>>>>>>>>> xxl-job registry fail, registryParam:{0}, registryResult:{1}", registryParam, registryResult)); } } catch (Exception e) { logger.Info($">>>>>>>>>>> xxl-job registry error, registryParam:{registryParam}", e); } } } catch (Exception e) { logger.Error(e.Message, e); } Thread.Sleep(RegistryConfig.BEAT_TIMEOUT * 1000); } // registry remove try { RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.ToString(), appName, executorAddress); foreach (AdminBiz adminBiz in XxlJobExecutor.getAdminBizList()) { try { ReturnT <String> registryResult = adminBiz.registryRemove(registryParam); if (registryResult != null && ReturnT <string> .SUCCESS_CODE == registryResult.code) { registryResult = ReturnT <string> .SUCCESS; logger.Info(string.Format(">>>>>>>>>>> xxl-job registry-remove success, registryParam:{0}, registryResult:{1}", registryParam, registryResult)); break; } else { logger.Info(string.Format(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{0}, registryResult:{1}", registryParam, registryResult)); } } catch (Exception e) { logger.Info(string.Format(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{0}", registryParam), e); } } } catch (Exception e) { logger.Error(e.Message, e); } logger.Warn(">>>>>>>>>>>> xxl-job, executor registry thread destory."); } ); registryThread.IsBackground = (true); registryThread.Start(); }
public RegistryChangedEventArgs(RegChangeNotifyFilter regChangeNotifyFilter, RegistryParam registryParam) : this(regChangeNotifyFilter, registryParam, registryParam, null) { }
public RegistryChangedEventArgs(RegChangeNotifyFilter regChangeNotifyFilter, RegistryParam registryParam, string[] subKeys) : this(regChangeNotifyFilter, registryParam, registryParam, subKeys) { }
public RegistryChangedEventArgs(RegChangeNotifyFilter regChangeNotifyFilter, RegistryParam previous, RegistryParam current) : this(regChangeNotifyFilter, previous, current, null) { }