/// <summary> /// Iterates through the given path and returns the existing valid parent folder /// </summary> /// <param name="path"></param> /// <returns></returns> public static String GetExistingAncestor(String path) { AppAssert.AssertNotNull(path, "path"); // Check if the path exists if (Directory.Exists(path)) { SetupLogger.LogInfo("InstallLocationPage.SetPathInBrowserDialog : The path {0} exists, returning", path); return(path); } String ancestor = null; int index = path.LastIndexOf(Path.DirectorySeparatorChar); while (index >= 0) { ancestor = path.Substring(0, index); SetupLogger.LogInfo("InstallLocationPage.SetPathInBrowserDialog : Check if the ancestor {0} exists", ancestor); if (Directory.Exists(ancestor)) { SetupLogger.LogInfo("InstallLocationPage.SetPathInBrowserDialog : The ancestor {0} exists, returning", ancestor); return(ancestor + Path.DirectorySeparatorChar); } index = ancestor.LastIndexOf(Path.DirectorySeparatorChar); } return(null); }
protected void LoadEnumValuesForCurrentCulture() { CultureInfo currentCulture = Thread.CurrentThread.CurrentUICulture; Dictionary <EnumType, string> enumStringTable = new Dictionary <EnumType, string>(); string[] enumNames = Enum.GetNames(typeof(EnumType)); EnumType[] enumValues = (EnumType[])Enum.GetValues(typeof(EnumType)); for (int i = 0; i < enumNames.Length; ++i) { //as long as the value has a name, we're okay. //(we can't tell the difference between two enums with the same value) if (!enumStringTable.ContainsKey(enumValues[i])) { string key = typeof(EnumType).Name + enumNames[i] + this.suffix; string localizedName = this.localResourceManager.GetString(key); AppAssert.AssertNotNull(localizedName, string.Format("Each enum in {0} must have a localizable string name. Resource {1} in {2} for value {3} undefined", typeof(EnumType).FullName, key, this.localResourceManager.BaseName, enumNames[i])); enumStringTable.Add(enumValues[i], localizedName); } } this.PopulateAdditionalCombinedValues(enumStringTable); lock (this.syncObject) { this.cultureToEnumTableLookup[currentCulture] = enumStringTable; } }
public void SetInputValue(object inputValue) { AppAssert.AssertNotNull(inputValue, "inputValue"); Validate(inputValue); this.inputValue = inputValue; this.valid = true; }
public void LoadInputValue(String file) { AppAssert.AssertNotNull(file, "file"); object inputValue = LoadInputValueFromFile(file); if (inputValue != null) { SetInputValue(inputValue); } }
/// <summary> /// Edits the value of a parameter /// </summary> /// <param name="parameter"></param> /// <param name="value"></param> virtual public void EditItem(String parameter, object value) { AppAssert.AssertNotNull(parameter, "parameter"); AppAssert.Assert(this.parameterList.Contains(parameter), "Parameter List does not contain this parameter", parameter); AppAssert.AssertNotNull(value, "value"); InputParameter inputParameter = PropertyBagDictionary.Instance.GetProperty <InputParameter>(parameter); inputParameter.SetInputValue(value); }
/// <summary> /// Given a path, return the root of the path /// </summary> /// <param name="path"></param> /// <returns>"\" terminated root</returns> public static String GetPathRoot(String path) { AppAssert.AssertNotNull(path, "path"); AppAssert.Assert(path.Length > 0, "Path is empty"); AppAssert.Assert(path[0] != Path.DirectorySeparatorChar, "Path starts with \\"); if (IsPathRooted(path)) { return(path.Substring(0, 3)); } else { throw new ArgumentException("path"); } }
/// <summary> /// Given a path, return the root of the path /// </summary> /// <param name="path"></param> /// <returns>true, if path has a root, false if path does not have a root</returns> public static bool IsPathRooted(String path) { AppAssert.AssertNotNull(path, "path"); AppAssert.Assert(path.Length > 0, "Path is empty"); if (path.Length > 1 && path[1] == Path.VolumeSeparatorChar) { if (path.Length > 2 && path[2] == Path.DirectorySeparatorChar) { return(true); } } return(false); }
/// <summary> /// Loads input values from a file /// </summary> /// <param name="file"></param> /// <param name="parameterList"></param> public void LoadFrom(String file, StringCollection parameterList) { AppAssert.AssertNotNull(file, "file"); AppAssert.AssertNotNull(parameterList, "parameterList"); this.LoadParameterList(parameterList); InputParameter inputParameter = null; foreach (String parameter in parameterList) { inputParameter = this.FindItem(parameter); inputParameter.LoadInputValue(file); } }
public void CheckForDirectoryAttributes(String path, bool forDB) { AppAssert.AssertNotNull(path, "path"); try { FileAttributes attributes = File.GetAttributes(path); if ((int)attributes == -1) { throw new Exception(String.Format("The attributes of directory {0} cannot be acquired", path)); } if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden || (attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly || (attributes & FileAttributes.System) == FileAttributes.System) { ThrowInvalidLocationException(path); } if (forDB) { if ((attributes & FileAttributes.Compressed) == FileAttributes.Compressed) { throw new Exception( String.Format("The selected location {0} is on a compressed volume", path)); } } } catch (DirectoryNotFoundException directoryNotFoundException) { // Do nothing } catch (FileNotFoundException fileNotFoundException) { // Do nothing } catch (UnauthorizedAccessException unauthorizedAccessException) { // Setup was denied access to the folder, ask user to choose other location. ThrowInvalidLocationException(path); } catch (IOException ioException) { // IO error while accessing the install location, ask user to choose other location. ThrowInvalidLocationException(path); } }
/// <summary> /// Loads input values from a file /// </summary> /// <param name="file"></param> /// <param name="parameterList"></param> public void LoadFrom(String file, StringCollection parameterList) { AppAssert.AssertNotNull(file, "file"); AppAssert.AssertNotNull(parameterList, "parameterList"); Tracer.Trace.TraceMessage(CallSite.New(), TraceFlag.DbgNormal, "Load inputs from file {0}", file); this.LoadParameterList(parameterList); InputParameter inputParameter = null; foreach (String parameter in parameterList) { inputParameter = this.FindItem(parameter); inputParameter.LoadInputValue(file); } }
/// <summary> /// Returns a parameter /// </summary> /// <param name="parameter"></param> /// <returns></returns> virtual public InputParameter FindItem(String parameter) { AppAssert.AssertNotNull(parameter, "parameter"); return(PropertyBagDictionary.Instance.GetProperty <InputParameter>(parameter)); }