/// <summary> /// 创建新的案例项目文件。 /// </summary> /// <param name="caseInfo">案例信息。</param> /// <returns>CPConfiguration 类型实例。</returns> public static CPConfiguration Create(CaseInfo caseInfo) { XDocument doc = XmlEmbeddedResourceResolver.GetXmlTemplate("CaseProjectTemplate.cp"); XElement propertyGroup = doc.Root.Element("PropertyGroup"); propertyGroup.Element("Id").Value = caseInfo.Id; propertyGroup.Element("Name").Value = caseInfo.Name ?? String.Empty; propertyGroup.Element("Number").Value = caseInfo.Number ?? String.Empty; propertyGroup.Element("Type").Value = caseInfo.Type ?? String.Empty; propertyGroup.Element("Author").Value = caseInfo.Author ?? String.Empty; caseInfo.Timestamp = DateTime.Now; propertyGroup.Element("Timestamp").Value = caseInfo.Timestamp.ToString("s"); try { return(new CPConfiguration(doc, true)); } catch (FormatException) { return(null); } catch (Exception) { return(null); } }
/// <summary> /// 创建新的案例项目文件。 /// </summary> /// <param name="caseInfo">案例信息。</param> /// <returns>CPConfiguration 类型实例。</returns> internal static CPConfiguration Create(CaseInfo caseInfo) { XDocument doc = GetTemplate(); XElement propertyGroup = doc.Root.Element("PropertyGroup"); propertyGroup.Element("Id").Value = caseInfo.Id; propertyGroup.Element("Name").Value = caseInfo.Name ?? String.Empty; propertyGroup.Element("Number").Value = caseInfo.Number ?? String.Empty; propertyGroup.Element("Type").Value = caseInfo.Type ?? String.Empty; propertyGroup.Element("Author").Value = caseInfo.Author ?? String.Empty; caseInfo.Timestamp = DateTime.Now; propertyGroup.Element("Timestamp").Value = caseInfo.Timestamp.ToString("s"); try { return(new CPConfiguration(doc, Path.Combine(caseInfo.Path, caseInfo.GetDirectoryName()), false)); } catch (FormatException) { return(null); } catch (Exception) { return(null); } }
/// <summary> /// 更新案例信息。 /// </summary> /// <returns>成功返回true;否则返回false。</returns> public Boolean Update() { ThrowExceptionIfNotExisted(); _configuration.SetCaseInfo(CaseInfo); if (_configuration.Save(ProjectFile)) { CaseInfo.Commit(); Updated?.Invoke(this, EventArgs.Empty); return(true); } return(false); }
/// <summary> /// 获取案例信息。 /// </summary> /// <returns>案例信息。</returns> public RestrictedCaseInfo GetCaseInfo(String path) { XElement propertyGroup = _doc.Root.Element("PropertyGroup"); CaseInfo caseInfo = new CaseInfo(); caseInfo.Id = propertyGroup.Element("Id").Value; caseInfo.Name = propertyGroup.Element("Name").Value; caseInfo.Number = propertyGroup.Element("Number").Value; caseInfo.Type = propertyGroup.Element("Type").Value; caseInfo.Author = propertyGroup.Element("Author").Value; caseInfo.Timestamp = DateTime.Parse(propertyGroup.Element("Timestamp").Value); caseInfo.Path = path; return(new RestrictedCaseInfo(caseInfo)); }
private void Save() { CaseInfo ci = CaseInfo; if (String.IsNullOrWhiteSpace(ci.Name) || String.IsNullOrWhiteSpace(ci.Number) || String.IsNullOrWhiteSpace(ci.Type) || String.IsNullOrWhiteSpace(ci.Author) || String.IsNullOrWhiteSpace(ci.Path)) { throw new ArgumentException("Exist invalid value."); } Directory.CreateDirectory(ci.Path); String configFile = Path.Combine(ci.Path, $"{ci.Name}.cp"); }
/// <summary> /// 获取案例信息。 /// </summary> /// <returns>案例信息。</returns> internal RestrictedCaseInfo GetCaseInfo() { XElement propertyGroup = _doc.Root.Element("PropertyGroup"); CaseInfo caseInfo = new CaseInfo(); caseInfo.Id = propertyGroup.Element("Id").Value; caseInfo.Name = propertyGroup.Element("Name").Value; caseInfo.Number = propertyGroup.Element("Number").Value; caseInfo.Type = propertyGroup.Element("Type").Value; caseInfo.Author = propertyGroup.Element("Author").Value; caseInfo.Timestamp = DateTime.Parse(propertyGroup.Element("Timestamp").Value); caseInfo.Path = Path.GetDirectoryName(_directory); return(new RestrictedCaseInfo(caseInfo) { Directory = _directory }); }
/// <summary> /// 创建新的案例。 /// </summary> /// <param name="caseInfo">案例信息。</param> /// <param name="projectFileNameWithoutExtension">不包含扩展名的项目文件名称。</param> /// <returns>新的案例。</returns> public static Case New(CaseInfo caseInfo, String projectFileNameWithoutExtension = null) { if (caseInfo == null) { throw new ArgumentNullException("caseInfo"); } CPConfiguration configuration = CPConfiguration.Create(caseInfo); if (configuration == null) { return(null); } String file = System.IO.Path.Combine(caseInfo.Path, caseInfo.GetDirectoryName(), $"{projectFileNameWithoutExtension ?? DefaultProjectFile}.cp"); if (!configuration.Save(file)) { return(null); } RestrictedCaseInfo rci = configuration.GetCaseInfo(System.IO.Path.GetDirectoryName(file)); return(new Case(rci, configuration, file)); }
/// <summary> /// 创建新的案例。 /// </summary> /// <param name="caseInfo">案例信息。</param> /// <returns>新的案例。</returns> public static Case New(CaseInfo caseInfo) { if (caseInfo == null) { throw new ArgumentNullException("caseInfo"); } CPConfiguration configuration = CPConfiguration.Create(caseInfo); if (configuration == null) { return(null); } if (!configuration.Save()) { return(null); } RestrictedCaseInfo rci = configuration.GetCaseInfo(); return(new Case(rci, configuration) { Existed = true }); }
internal RestrictedCaseInfo(CaseInfo caseInfo) { _caseInfo = caseInfo ?? throw new ArgumentNullException("caseInfo"); Init(caseInfo); }
/// <summary> /// 保存案例。 /// </summary> /// <param name="caseInfo">案例信息。</param> public static Case Save(CaseInfo caseInfo) { Case cm = new Case(caseInfo); return(cm); }
private Case(CaseInfo caseInfo) { }