/// <summary> /// Read the xml /// </summary> /// <param name="reader"></param> public void ReadXml(System.Xml.XmlReader reader) { bool empty = reader.IsEmptyElement; reader.Read(); if (empty) { return; } reader.MoveToContent(); reader.ReadStartElement("Components"); Components = VersionImport.Load <List <VersionDefItem> >(reader, _supportedTypes); reader.ReadEndElement(); //Read Closing Element reader.ReadEndElement(); }
/// <summary> /// Accept or reject the arguments supplied on the command line. /// </summary> /// <param name="args"></param> /// <returns></returns> public override BoolMessageItem <Args> AcceptArgs(string[] args) { BoolMessageItem <Args> result = base.AcceptArgs(args, "-", "="); if (result.Success) { string definitionFile = result.Item.NamedArgs["definition"]; if (!File.Exists(definitionFile)) { string error = string.Format("Definition file '{0}' does not exist.", definitionFile); Console.WriteLine(Environment.NewLine + error); return(new BoolMessageItem <Args>(result.Item, false, error)); } // Create context and load definition from file. _ctx = new VersionContext(); _ctx.Definition = VersionImport.Load <VersionDefinition>(result.Item.NamedArgs["definition"]); _ctx.Definition.Name = result.Item.NamedArgs["name"]; } return(result); }
/// <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(); }
/// <summary> /// Get all the derived types of versiondefitem. /// </summary> static VersionDefinition() { _supportedTypes = VersionImport.GetVersionTypes().ToArray(); }