private void SetMode() { if (IsFileSelector) { ButtonText = "\uF15C"; ButtonCommand = new RelayCommand(() => { var dlg = new OpenFileDialog(); if (!string.IsNullOrEmpty(OpenFileFilter)) { dlg.Filter = OpenFileFilter; } if (dlg.ShowDialog() == true) { ConfigItemValue = new SDPath(dlg.FileName); } }, true); } else { ButtonText = "\uF07C"; ButtonCommand = new RelayCommand(() => { var dlg = new System.Windows.Forms.FolderBrowserDialog(); dlg.ShowNewFolderButton = true; dlg.ShowDialog(); if (!string.IsNullOrEmpty(dlg.SelectedPath)) { ConfigItemValue = new SDPath(dlg.SelectedPath); } }, true); } }
public void FallsBackToFullPathsIfRelativePathsAreMissing() { var path = new SDPath("c:\\source\\someproject\\output", null); var resolvedPath = path.ResolvePath("c:\\buildagent\\CI_WS\\1234"); Assert.AreEqual("c:\\source\\someproject\\output", resolvedPath); }
public void CanResolveRelativePaths() { var path = new SDPath(); path.UpdatePath("c:\\source\\someproject\\output", "c:\\source\\someproject"); var resolvedPath = path.ResolvePath("c:\\buildagent\\CI_WS\\1234"); Assert.AreEqual("c:\\buildagent\\CI_WS\\1234\\output", resolvedPath); }
private void GetAndSetConfigValue(IConfigSection config, XElement item) { var propertyName = string.Empty; var keyAttribute = item.Attribute("key"); if (keyAttribute != null) { propertyName = keyAttribute.Value; } else { propertyName = item.Name.LocalName; } var property = config.GetType().GetProperty(propertyName); if (property != null) { var excludeAttribute = (ExcludeAttribute)Attribute.GetCustomAttribute(property, typeof(ExcludeAttribute)); if (excludeAttribute == null) { if (property.PropertyType.Name == "Boolean") { property.SetValue(config, item.Attribute("value").Value.ToLower() == "true", null); } else if (property.PropertyType.Name == "ObservableCollection`1") { property.SetValue(config, new ObservableCollection <string>(item.Attribute("value").Value.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList()), null); } else if (property.PropertyType == typeof(SDPath) && item.Element("Full") != null) { var fullPath = item.Element("Full").Value; var relativePath = item.Element("Relative").Value; var path = new SDPath(fullPath, relativePath); property.SetValue(config, path, null); } else if (property.PropertyType == typeof(SDPath)) { // Backwards compatibility code var fullPath = item.Attribute("value").Value; var path = new SDPath(fullPath); property.SetValue(config, path, null); } else { property.SetValue(config, item.Attribute("value").Value, null); } } } }
public void SaveTo(string fileToSave) { if (!string.IsNullOrEmpty(fileToSave)) { Environment.CurrentDirectory = Path.GetDirectoryName(fileToSave); CurrentConfigPath = new SDPath(fileToSave); _coreConfigSection.ConfigFileName = Path.GetFileNameWithoutExtension(fileToSave); var xml = _configSerializer.GetSerializedConfigs(_configSections); xml.Save(fileToSave); _coreConfigSection.IsSaved = true; AddRecentConfig(_coreConfigSection.ConfigFileName, CurrentConfigPath); } }
public void Load(string fileToLoad) { if (File.Exists(fileToLoad)) { Environment.CurrentDirectory = Path.GetDirectoryName(fileToLoad); ResetConfigs(); _configSerializer.SetDeserializedConfigs(XDocument.Load(fileToLoad), _configSections); CurrentConfigPath = new SDPath(fileToLoad); _coreConfigSection.ConfigFileName = Path.GetFileNameWithoutExtension(fileToLoad); _coreConfigSection.IsSaved = true; AddRecentConfig(_coreConfigSection.ConfigFileName, CurrentConfigPath); } }
public void CorrectlyUpdatesThePaths() { var path = new SDPath(); path.UpdatePath("c:\\source\\someproject\\output", "c:\\source\\someproject"); Assert.AreEqual("c:\\source\\someproject\\output", path.FullPath); Assert.AreEqual("output", path.RelativePath); path.UpdatePath("c:\\completelydifferent\\output", "c:\\source\\someproject"); Assert.AreEqual("c:\\completelydifferent\\output", path.FullPath); Assert.AreEqual("..\\..\\completelydifferent\\output", path.RelativePath); var resolvedPath = path.ResolvePath("c:\\source\\someproject\\superdeepdirectory"); Assert.AreEqual("c:\\source\\completelydifferent\\output", resolvedPath); }
private void AddRecentConfig(string name, SDPath pathToConfig) { var keyValue = RecentProjects.SingleOrDefault(s => s.Key == pathToConfig.FullPath); if (keyValue.Equals(null) || keyValue.Value != name) { RecentProjects.Insert(0, new KeyValuePair <string, string>(pathToConfig.FullPath, name)); } if (RecentProjects.Count > 5) { RecentProjects.RemoveAt(5); } _recentConfigs = new XmlDocument(); var root = _recentConfigs.CreateElement("recentprojects"); foreach (var recentFile in RecentProjects) { var file = _recentConfigs.CreateElement("projectfile"); var nameAttr = _recentConfigs.CreateAttribute("name"); nameAttr.Value = recentFile.Value; var pathAttr = _recentConfigs.CreateAttribute("path"); pathAttr.Value = recentFile.Key; file.Attributes.Append(nameAttr); file.Attributes.Append(pathAttr); root.AppendChild(file); } _recentConfigs.AppendChild(root); _recentConfigs.Save(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "recent.xml")); ExecuteOnRecentProjectsChanged(); }