/// <summary> /// Execute the check. /// </summary> public override BoolMessageItem Execute() { try { bool useFileSize = Convert.ToBoolean(_parsedArgs.NamedArgs["useSize"]); string[] files = Directory.GetFiles(_parsedArgs.NamedArgs["directory"]); List <VersionDefItem> definitionComponents = new List <VersionDefItem>(); foreach (string filename in files) { FileInfo file = new FileInfo(filename); if (IsPartOfDefinition(file)) { VersionDefFile fileDef = new VersionDefFile(); fileDef.Path = file.FullName; fileDef.IsRequired = true; fileDef.IsWritable = false; fileDef.Match = VersionMatch.Equal; fileDef.VersionReq = FileUtils.GetVersion(filename); if (useFileSize) { fileDef.SizeReq = file.Length.ToString(); } fileDef.Requirement = VersionRequirement.Required; fileDef.FailOnError = false; fileDef.DateReq = file.LastWriteTime.ToShortDateString(); definitionComponents.Add(fileDef); } } var def = new VersionDefinition(); def.Name = _parsedArgs.NamedArgs["name"]; def.Components = definitionComponents; VersionImport.Save <VersionDefinition>(_parsedArgs.NamedArgs["definition"], def); } catch (Exception ex) { _checkResult = new BoolMessageItem(null, false, ex.Message + Environment.NewLine + ex.StackTrace); } return(_checkResult); }
/// <summary> /// Write the components. /// </summary> /// <param name="writer"></param> public void WriteXml(System.Xml.XmlWriter writer) { writer.WriteStartElement("Components"); VersionImport.Save <List <VersionDefItem> >(Components, writer, _supportedTypes); writer.WriteEndElement(); }