private void RevertChanges(EnvironmentVariableData p_data) { //important to force lost focus, otherwise the last field will stay with new value GUIUtility.keyboardControl = 0; Type __classType = typeof(EnvironmentVariables); foreach (EnvironmentType envType in Enum.GetValues(typeof(EnvironmentType))) { string __varName = envType + "_" + p_data.variableName; FieldInfo __field = __classType.GetField(__varName); //original id dictOfEnvVariablesByID[p_data.variableName].id = p_data.variableName; //original type VariableType __originalFieldType = GetVariableEnumType(__field.FieldType); dictOfEnvVariablesByID[p_data.variableName].type = __originalFieldType; //original dic env value dictOfEnvVariablesByID[p_data.variableName].dictOfValuebyEnvironment[envType] = __field.GetValue(null); //not edited dictOfEnvVariablesByID[p_data.variableName].wasModified = false; } AssetDatabase.Refresh(); }
private void DeleteVariable(EnvironmentVariableData p_data) { //find file in path and delete string __Path = Application.dataPath + VariablesPath + p_data.variableName + "_EnvVariable.cs"; File.Delete(__Path); AssetDatabase.Refresh(); }
public async Task InvalidEnvironmentalVariableXmlIsNotAccepted(string data) { using (var session = await StartSession(TestIsolationLevel.CompletelyIsolated)) { var client = await session.GetClient(ApiPortals.Developer); Application firstApp = null; Version firstVer = null; Component comp = null; var apps = await client.GetApplications(); foreach (var app in apps) { var versions = await client.GetVersionsForApplication(app.Alias); firstVer = versions.FirstOrDefault(); if (firstVer != null) { var components = await client.GetComponents(app.Alias, firstVer.Alias); comp = components.FirstOrDefault(i => i.Type == "wcfsvc"); if (comp != null) { firstApp = app; break; } } } if (comp != null) { var envVariables = await client.GetEnvironmentVariables(firstApp.Alias, firstVer.Alias, comp.Alias); Assert.NotNull(envVariables); Assert.False(string.IsNullOrWhiteSpace(envVariables.Data)); var updated = new EnvironmentVariableData { Data = data }; var threw = false; try { await client.SetEnvironmentVariable(firstApp.Alias, firstVer.Alias, comp.Alias, updated); } catch (Exception) { threw = true; } Assert.True(threw); } } }
private void LoadData() { Type __classType = typeof(EnvironmentVariables); FieldInfo[] __fields = __classType.GetFields(BindingFlags.NonPublic | BindingFlags.Static); foreach (FieldInfo field in __fields) { if (Attribute.IsDefined(field, typeof(IgnoreEnvironmentVariableAttribute))) { continue; } string __id = field.Name.Split('_')[1]; if (dictOfEnvVariablesByID.ContainsKey(__id) == false) { EnvironmentVariableData __variable = new EnvironmentVariableData(); __variable.id = field.Name.Split('_')[1]; //important to get the real name on revert __variable.variableName = __variable.id; __variable.dictOfValuebyEnvironment = new Dictionary <EnvironmentType, object>(); VariableType __variableTypeEnum = GetVariableEnumType(field.FieldType); __variable.type = __variableTypeEnum; if (__variableTypeEnum == VariableType.ENUM) { __variable.enumType = Type.GetType((field.FieldType.Name + ",Assembly-CSharp").Replace(".", "+")); } foreach (EnvironmentType __environmentType in Enum.GetValues(typeof(EnvironmentType))) { if (__variable.type == VariableType.ENUM) { __variable.dictOfValuebyEnvironment.Add(__environmentType, 0); } else { __variable.dictOfValuebyEnvironment.Add(__environmentType, GetDefaultValueForType(__variableTypeEnum)); } } dictOfEnvVariablesByID.Add(__variable.variableName, __variable); } string __environmentTypeName = field.Name.Split('_')[0]; EnvironmentType __environmentTypeEnum = (EnvironmentType)Enum.Parse(typeof(EnvironmentType), __environmentTypeName); dictOfEnvVariablesByID[__id].dictOfValuebyEnvironment[__environmentTypeEnum] = field.GetValue((null)); } }
private void SaveAllVariables() { foreach (string key in dictOfEnvVariablesByID.Keys) { EnvironmentVariableData __variable = dictOfEnvVariablesByID[key]; if (__variable.wasModified) { __variable.wasModified = false; SaveEnvironmentVariable(__variable, true); } } }
private void DrawValue(EnvironmentVariableData p_fieldData) { foreach (EnvironmentType __environmentType in Enum.GetValues(typeof(EnvironmentType))) { switch (p_fieldData.type) { case VariableType.BOOL: p_fieldData.dictOfValuebyEnvironment[__environmentType] = (object)EditorGUILayout.Toggle(__environmentType.ToString() + " value", (bool)p_fieldData.dictOfValuebyEnvironment[__environmentType]); break; case VariableType.INT: p_fieldData.dictOfValuebyEnvironment[__environmentType] = (object)EditorGUILayout.IntField(__environmentType.ToString() + " value", (int)p_fieldData.dictOfValuebyEnvironment[__environmentType]); break; case VariableType.FLOAT: p_fieldData.dictOfValuebyEnvironment[__environmentType] = (object)EditorGUILayout.FloatField(__environmentType.ToString() + " value", (float)p_fieldData.dictOfValuebyEnvironment[__environmentType]); break; case VariableType.STRING: p_fieldData.dictOfValuebyEnvironment[__environmentType] = (object)EditorGUILayout.TextField(__environmentType.ToString() + " value", (string)p_fieldData.dictOfValuebyEnvironment[__environmentType]); break; case VariableType.ENUM: GUILayout.BeginHorizontal(); { GUILayout.Label(__environmentType.ToString() + " value", GUILayout.Width(150f)); p_fieldData.dictOfValuebyEnvironment[__environmentType] = (object)EditorGUILayout.Popup((int)p_fieldData.dictOfValuebyEnvironment[__environmentType], Enum.GetNames(p_fieldData.enumType)); } GUILayout.EndHorizontal(); break; } } }
public Task <bool> SetEnvironmentVariable(string appAlias, string versionAlias, string componentAlias, EnvironmentVariableData data) { return(PutVoid(GetAppVersionStartPoint(appAlias, versionAlias, DEV) + $"components/{componentAlias}/environmentvariables", data, DEV)); }
public async Task GetAndSetEnvironmentVariablesInXmlForComponent(string data) { using (var session = await StartSession(TestIsolationLevel.CompletelyIsolated)) { var client = await session.GetClient(ApiPortals.Developer); Application firstApp = null; Version firstVer = null; Component comp = null; var apps = await client.GetApplications(); foreach (var app in apps) { var versions = await client.GetVersionsForApplication(app.Alias); firstVer = versions.FirstOrDefault(); if (firstVer != null) { var components = await client.GetComponents(app.Alias, firstVer.Alias); comp = components.FirstOrDefault(i => i.Type == "wcfsvc"); if (comp != null) { firstApp = app; break; } } } if (comp != null) { var envVariables = await client.GetEnvironmentVariables(firstApp.Alias, firstVer.Alias, comp.Alias); Assert.NotNull(envVariables); Assert.False(string.IsNullOrWhiteSpace(envVariables.Data)); var updated = new EnvironmentVariableData { Data = data }; var posted = await client.SetEnvironmentVariable(firstApp.Alias, firstVer.Alias, comp.Alias, updated); Assert.True(posted); var reget = await client.GetEnvironmentVariables(firstApp.Alias, firstVer.Alias, comp.Alias); Assert.NotNull(reget); var cleanSource = data.Replace(" ", "").Replace("\t", "").Replace(Environment.NewLine, "") .ToLower(); var cleanRes = reget.Data.Replace(" ", "").Replace("\t", "").Replace(Environment.NewLine, "") .ToLower(); Assert.Equal(cleanSource, cleanRes); //set it back to original value var repost = await client.SetEnvironmentVariable(firstApp.Alias, firstVer.Alias, comp.Alias, envVariables); Assert.True(repost); } } }
public async Task GetAndSetEnvironmentVariablesInXmlOverwritesExisting() { using (var session = await StartSession(TestIsolationLevel.CompletelyIsolated)) { var client = await session.GetClient(ApiPortals.Developer); Application firstApp = null; Version firstVer = null; Component comp = null; var apps = await client.GetApplications(); foreach (var app in apps) { var versions = await client.GetVersionsForApplication(app.Alias); firstVer = versions.FirstOrDefault(); if (firstVer != null) { var components = await client.GetComponents(app.Alias, firstVer.Alias); comp = components.FirstOrDefault(i => i.Type == "wcfsvc"); if (comp != null) { firstApp = app; break; } } } if (comp != null) { var envVariables = await client.GetEnvironmentVariables(firstApp.Alias, firstVer.Alias, comp.Alias); Assert.NotNull(envVariables); Assert.False(string.IsNullOrWhiteSpace(envVariables.Data)); var updated = new EnvironmentVariableData { Data = "<environmentVariables><variable name=\"exists\" value=\"existVal\"/></environmentVariables>" }; var posted = await client.SetEnvironmentVariable(firstApp.Alias, firstVer.Alias, comp.Alias, updated); Assert.True(posted); var reget = await client.GetEnvironmentVariables(firstApp.Alias, firstVer.Alias, comp.Alias); Assert.NotNull(reget); Assert.Contains("exists", reget.Data); Assert.Contains("existVal", reget.Data); //set again updated = new EnvironmentVariableData { Data = "<environmentVariables><variable name=\"new\" value=\"newVal\"/></environmentVariables>" }; posted = await client.SetEnvironmentVariable(firstApp.Alias, firstVer.Alias, comp.Alias, updated); Assert.True(posted); reget = await client.GetEnvironmentVariables(firstApp.Alias, firstVer.Alias, comp.Alias); Assert.NotNull(reget); Assert.DoesNotContain("exists", reget.Data); Assert.DoesNotContain("existVal", reget.Data); Assert.Contains("new", reget.Data); Assert.Contains("newVal", reget.Data); //set it back to original value var repost = await client.SetEnvironmentVariable(firstApp.Alias, firstVer.Alias, comp.Alias, envVariables); Assert.True(repost); } } }
private void SaveEnvironmentVariable(EnvironmentVariableData p_data, bool p_replaceValue = false) { string __type = ""; bool __nameChanged = p_data.variableName != p_data.id; if (__nameChanged) { string __oldName = Application.dataPath + VariablesPath + p_data.variableName + "_EnvVariable.cs"; string __newName = Application.dataPath + VariablesPath + p_data.id + "_EnvVariable.cs"; File.Move(__oldName, __newName); } string __name = __nameChanged ? p_data.id : p_data.variableName; string __file = Application.dataPath + VariablesPath + __name + "_EnvVariable.cs"; string __code = "using System;\n"; __code += "public static partial class EnvironmentVariables\n{\n"; string __getField = ""; switch (p_data.type) { case VariableType.BOOL: case VariableType.FLOAT: case VariableType.INT: case VariableType.STRING: __type = p_data.type.ToString().ToLower(); __getField = "\tpublic static " + __type + " " + p_data.id + "\n\t{\n\t\tget\n\t\t{\n\t\t\tswitch(currentEnvironment)\n\t\t\t{\n"; break; case VariableType.ENUM: __type = p_data.type.ToString().ToLower(); __getField = "\tpublic static " + p_data.enumType + " " + p_data.id + "\n\t{\n\t\tget\n\t\t{\n\t\t\tswitch(currentEnvironment)\n\t\t\t{\n"; break; } foreach (EnvironmentType __environmentType in Enum.GetValues(typeof(EnvironmentType))) { FindDefaultValueForType(p_data.type); string __value = _defaultEmptyValue; if (p_replaceValue) { if (p_data.type == VariableType.STRING) { __value = " \"" + p_data.dictOfValuebyEnvironment[__environmentType] + "\""; } else if (p_data.type == VariableType.BOOL) { __value = p_data.dictOfValuebyEnvironment[__environmentType].ToString().ToLower(); } else if (p_data.type == VariableType.ENUM) { __value = p_data.dictOfValuebyEnvironment[__environmentType].ToString(); } else { __value = p_data.dictOfValuebyEnvironment[__environmentType].ToString(); } } switch (p_data.type) { case VariableType.BOOL: case VariableType.FLOAT: case VariableType.INT: case VariableType.STRING: __code += String.Format("\tprivate static readonly {0} {1} = {2};\n", __type, __environmentType + "_" + p_data.id, __value); __getField += "\t\t\t\tcase EnvironmentType." + __environmentType + ": \n" + "\t\t\t\t\treturn " + __environmentType + "_" + p_data.id + ";\n\n"; break; case VariableType.ENUM: string[] __enumValues = (string[])Enum.GetNames(p_data.enumType); __code += String.Format("\tprivate static readonly {0} {1} = {2};\n", p_data.enumType, __environmentType + "_" + p_data.id, p_data.enumType.Name + "." + __enumValues[int.Parse(__value)]); __getField += "\t\t\t\tcase EnvironmentType." + __environmentType + ": \n" + "\t\t\t\t\treturn " + __environmentType + "_" + p_data.id + ";\n\n"; break; } } __getField += "\t\t\t\tdefault: \n" + "\t\t\t\t\treturn " + GetDefaultValueForType(p_data.type).ToString().ToLower() + ";\n"; __getField += "\t\t\t}\n\t\t}\n\t}\n"; //case EnvironmentType:\n return SANDBOX_dataURIPath;\n\n case EnvironmentType.PRODUCTION:\n return PRODUCTION_dataURIPath;\n\n case EnvironmentType.TEST:\n return TEST_dataURIPath;\n\n default:\n return null;\n }\n }\n }"); __code += __getField; __code += "}"; System.IO.File.WriteAllText(__file, __code); Debug.Log("Created " + __file); AssetDatabase.Refresh(); }
private void DrawVariables() { GUILayout.BeginVertical(EditorStyles.helpBox); { GUILayout.BeginHorizontal(); { GUILayout.Label("Variables", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); if (HasModifications()) { GUI.color = NewColors.PaleGreen; if (GUILayout.Button("Save all", GUILayout.Width(100))) { SaveAllVariables(); } } GUI.color = Color.white; GUI.color = Color.green; // Color myColor = new Color(); // ColorUtility.TryParseHtmlString ("#99ccff", out myColor); GUI.color = NewColors.PowderBlue; if (GUILayout.Button("Add Variable")) { _environmentEditorState = EnvironmentVariablesEditorState.ADDING_VARIABLE; } } GUILayout.EndHorizontal(); GUI.color = Color.white; if (dictOfEnvVariablesByID.Keys.Count == 0) { GUILayout.Label("No Variables To Display"); } else { _scrollPosition = GUILayout.BeginScrollView(_scrollPosition); foreach (string key in dictOfEnvVariablesByID.Keys) { EnvironmentVariableData __variable = dictOfEnvVariablesByID[key]; GUI.backgroundColor = __variable.wasModified ? NewColors.FireBrick : Color.white;// new Color(0.8f, 0.1f, 0.1f, 0.4f) : Color.white; GUILayout.BeginVertical(EditorStyles.helpBox); { GUI.backgroundColor = Color.white; GUILayout.BeginHorizontal(); { __variable.isUnfolded = EditorGUILayout.Foldout(__variable.isUnfolded, string.Empty); GUILayout.Space(-40); GUILayout.Label("<b><size=12><color=#0066ff> " + __variable.type.ToString().ToLower() + ": </color></size></b>", _styleHtml); GUILayout.Label("<b><size=12>" + __variable.id + "</size></b>", _styleHtml); GUILayout.FlexibleSpace(); if (__variable.wasModified) { GUI.color = NewColors.SpringGreen; if (GUILayout.Button("Save changes", GUILayout.Width(100))) { if (__variable.wasModified) { __variable.wasModified = false; } SaveEnvironmentVariable(__variable, true); } GUI.color = NewColors.Orange; if (GUILayout.Button("Revert changes", GUILayout.Width(100))) { RevertChanges(__variable); } GUI.color = Color.white; } GUI.color = Color.red; if (GUILayout.Button("X", GUILayout.Width(40))) { if (EditorUtility.DisplayDialog("Deleting variable!", "Do you want to delete it now?", "Yes", "No")) { DeleteVariable(__variable); } } GUI.color = Color.white; } GUILayout.EndHorizontal(); GUILayout.Space(4); if (__variable.isUnfolded) { EditorGUI.BeginChangeCheck(); GUI.color = Color.white; DrawValue(__variable); if (EditorGUI.EndChangeCheck()) { __variable.wasModified = true; } } } GUILayout.EndVertical(); } GUILayout.EndScrollView(); } } GUILayout.EndVertical(); }
private void DrawNewVariableCreationWindow() { GUILayout.Label("Create New Variable", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); _newVariableName = EditorGUILayout.TextField("Name", _newVariableName); if (EditorGUI.EndChangeCheck()) { Regex rgx = new Regex(VariablesNameAcceptedCharacters, RegexOptions.IgnoreCase); MatchCollection matches = rgx.Matches(_newVariableName); if (matches.Count > 0) { foreach (Match match in matches) { _newVariableName = match.Value; } } } EditorGUI.BeginChangeCheck(); _newVariabletype = (VariableType)EditorGUILayout.EnumPopup("Type", _newVariabletype); bool __canCreateIfEnumerator = false; if (_newVariabletype == VariableType.ENUM) { _enumTypeStr = EditorGUILayout.TextField("Enumerator Type", _enumTypeStr); string __enumTypeStrConvertedToAssembly = (_enumTypeStr + ",Assembly-CSharp").Replace(".", "+"); if (Type.GetType(__enumTypeStrConvertedToAssembly) != null) { __canCreateIfEnumerator = true; GUILayout.Label("It is a valid enumerator."); } else { GUILayout.Label("Not a valid enumerator."); } } if (EditorGUI.EndChangeCheck()) { FindDefaultValueForType(_newVariabletype); } GUILayout.BeginHorizontal(); { GUI.color = Color.white; if (string.IsNullOrEmpty(_newVariableName) == false) { GUI.color = Color.green; } if (GUILayout.Button("Create")) { Action __createCallback = () => { if (!string.IsNullOrEmpty(_newVariableName)) { EnvironmentVariableData newVar = new EnvironmentVariableData(); _newVariableName = _newVariableName.Substring(0, 1).ToUpper() + _newVariableName.Remove(0, 1); newVar.variableName = _newVariableName; newVar.id = _newVariableName; newVar.type = _newVariabletype; if (_newVariabletype == VariableType.ENUM) { string __enumTypeStrConvertedToAssembly = (_enumTypeStr + ",Assembly-CSharp").Replace(".", "+"); Type __enumType = Type.GetType(__enumTypeStrConvertedToAssembly); if (__enumType != null) { newVar.enumType = __enumType; } } newVar.dictOfValuebyEnvironment.Add(EnvironmentType.Test, _defaultEmptyValue); SaveEnvironmentVariable(newVar); _newVariableName = string.Empty; _environmentEditorState = EnvironmentVariablesEditorState.EDITING; } }; if (_newVariabletype == VariableType.ENUM) { if (__canCreateIfEnumerator == true) { __createCallback(); } else { if (EditorUtility.DisplayDialog("Warning", "The typed enum type does not exist", "Ok")) { _enumTypeStr = string.Empty; } } } else { __createCallback(); } } GUI.color = Color.white; if (GUILayout.Button("Cancel")) { _environmentEditorState = EnvironmentVariablesEditorState.EDITING; } } }