示例#1
0
        /// <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);
            }
        }
示例#2
0
        /// <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));
        }