/// <summary> /// Saves the project to disk. /// </summary> public void Save() { if (!Directory.Exists(ROOT_FOLDER)) { Directory.CreateDirectory(ROOT_FOLDER); } if (!Directory.Exists(ProjectFolder)) { Directory.CreateDirectory(ProjectFolder); } XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Indent = true; using (FileStream stream = File.Open(ProjectFile, FileMode.Create)) { using (XmlWriter xml = XmlWriter.Create(stream, xmlSettings)) { xml.WriteStartDocument(); xml.WriteStartElement("project"); xml.WriteStartElement("credential"); CryptoContainer <SalesForceCredential> cryptoCredential = new CryptoContainer <SalesForceCredential>(Credential, PROJECT_PASSWORD); cryptoCredential.WriteXml(xml); xml.WriteEndElement(); xml.WriteStartElement("repository"); CryptoContainer <SimpleRepository> cryptoRepository = new CryptoContainer <SimpleRepository>(Repository, PROJECT_PASSWORD); cryptoRepository.WriteXml(xml); xml.WriteEndElement(); xml.WriteEndElement(); xml.WriteEndDocument(); xml.Close(); } stream.Close(); } }
/// <summary> /// Open the project with the given name. /// </summary> /// <param name="projectName">The name of the project to open.</param> /// <returns>The project with the given name.</returns> public static Project OpenProject(string projectName) { if (String.IsNullOrWhiteSpace(projectName)) { throw new ArgumentException("projectName is null or whitespace.", "projectName"); } string fileName = Path.Combine(ROOT_FOLDER, projectName); fileName = Path.Combine(fileName, String.Format("{0}.sfdcProject", projectName)); if (!File.Exists(fileName)) { throw new Exception("Couldn't find project: " + projectName); } XmlReaderSettings xmlSettings = new XmlReaderSettings(); xmlSettings.IgnoreComments = true; xmlSettings.IgnoreWhitespace = true; Project project = null; using (FileStream stream = File.OpenRead(fileName)) { using (XmlReader xml = XmlReader.Create(stream, xmlSettings)) { if (!xml.ReadToFollowing("project")) { throw new Exception("Invalid xml. No 'project' element found."); } if (!xml.ReadToDescendant("credential")) { throw new Exception("Invalid xml. No 'credential' element found."); } CryptoContainer <SalesForceCredential> cryptoCredential = new CryptoContainer <SalesForceCredential>(); cryptoCredential.ReadXml(xml); SalesForceCredential credential = cryptoCredential.GetData(PROJECT_PASSWORD); SimpleRepository repository = null; if (xml.IsStartElement("repository")) { CryptoContainer <SimpleRepository> cryptoRepository = new CryptoContainer <SimpleRepository>(); cryptoRepository.ReadXml(xml); repository = cryptoRepository.GetData(PROJECT_PASSWORD); } xml.Close(); project = new Project(credential); if (repository != null) { repository.WorkingPath = project.RepositoryFolder; project.Repository = repository; } } stream.Close(); } return(project); }