/// <summary> /// 添加一个 ExtractItem 项。 /// </summary> /// <param name="mode">提取模式。</param> /// <param name="path">提取所在路径。</param> /// <param name="owner">拥有该提取项的设备。</param> /// <returns>ExtractItem 类型实例。</returns> public ExtractItem AddExtract(String mode, String path, DeviceExtraction owner) { ExtractItem item = ExtractItem.New(mode, path, owner); AddExtract(item, owner); return(item); }
/// <summary> /// 添加设备提取。 /// </summary> /// <param name="type">设备类型。</param> /// <param name="fileNameWithoutExtension">配置文件名(不含扩展名)。</param> /// <param name="directory">保存目录的路径。如果为null表示在案例所在目录创建。</param> /// <returns></returns> public DeviceExtraction CreateDeviceExtraction(String name, String type, String fileNameWithoutExtension = null, String directory = null) { ThrowExceptionIfNotExisted(); String directoryName = $"{name}_{DateTime.Now.ToString("yyyyMMdd[hhmmss]")}"; DeviceExtraction de = null; //在当前案例所在目录创建设备目录 if (String.IsNullOrWhiteSpace(directory)) { //使用相对路径记录设备目录 de = DeviceExtraction.Create(type, directoryName, fileNameWithoutExtension, true, this); }//不在当前案例所在目录创建,并且没有提供绝对路径的情况下抛异常 else if (!System.IO.Path.IsPathRooted(directory)) { throw new ArgumentException("The directory must be absolute path."); }//不在当前案例所在目录创建,提供了绝对路径,表示在指定的路径下创建目录 else { directory = System.IO.Path.Combine(directory, directoryName); //使用绝对路径记录设备目录 de = DeviceExtraction.Create(type, directory, fileNameWithoutExtension, false, this); } if (de != null) { Configuration.AddReference(de.Reference); if (Configuration.Save(ProjectFile)) { return(de); } de.Delete(); } return(null); }
/// <summary> /// 获取配置中ItemGroup的所有Extract节点。 /// </summary> /// <param name="owner">拥有该提取项的设备。</param> /// <returns>提取项配置。</returns> public IEnumerable <ExtractItem> GetAllExtractItems(DeviceExtraction owner) { if (_itemGroup == null) { return(new ExtractItem[0]); } return(_itemGroup.Elements().Select(x => new ExtractItem(x, owner))); }
/// <summary> /// 将一个提取设备与当前案例分离。 /// </summary> /// <param name="de">提取设备。</param> public void Detach(DeviceExtraction de) { if (de == null) { return; } if (Configuration.RemoveReference(de.Reference)) { Configuration.Save(ProjectFile); } }
internal ExtractItem(XElement element, DeviceExtraction owner) { _element = element; Owner = owner; if (_element.Attribute("Mode") == null) { _element.Add(new XAttribute("Mode", null)); } if (_element.Attribute("Path") == null) { _element.Add(new XAttribute("Path", null)); } Case.RegisterPath(Token, Path, () => Delete(true)); }
/// <summary> /// 移除一个 ExtractItem 项。 /// </summary> /// <param name="item">提取项。</param> /// <param name="owner">拥有该提取项的设备。</param> /// <returns>如果该提取项并不存在,则忽略并返回false;否则移除并返回true。</returns> public Boolean RemoveExtract(ExtractItem item, DeviceExtraction owner) { if (item == null) { return(false); } IEnumerable <ExtractItem> extractItems = GetAllExtractItems(owner); ExtractItem found = extractItems.SingleOrDefault(x => x == item); if (found == null) { return(false); } item.Element.Remove(); return(true); }
/// <summary> /// 添加一个 ExtractItem 项。 /// </summary> /// <param name="item">提取项。</param> /// <param name="owner">拥有该提取项的设备。</param> /// <returns>如果已存在相同的提取项,则忽略并返回false;否则添加并返回true。</returns> public Boolean AddExtract(ExtractItem item, DeviceExtraction owner) { if (item == null) { return(false); } if (!item.IsValid) { return(false); } IEnumerable <ExtractItem> extractItems = GetAllExtractItems(owner); ExtractItem found = extractItems.SingleOrDefault(x => x == item); if (found != null) { return(false); } _itemGroup.Add(item.Element); return(true); }
/// <summary> /// 获取所有的设备提取。 /// </summary> /// <param name="references">案例引用的设备提取。</param> /// <returns>设备提取列表。</returns> private IEnumerable <DeviceExtraction> GetAllDeviceExtractions() { return(Configuration.ReferenceItems.Where(x => x.IsValid).Select(x => DeviceExtraction.Open(x, this)).Where(x => x != null)); }