Ejemplo n.º 1
0
 /// <summary>
 /// Gets the value of the given attribute or string.Empty if the attribute is
 /// not present
 /// </summary>
 public string this[FileAttributeName key]
 {
     get
     {
         var attribute = this.Attributes.FirstOrDefault(a => a.Name == key);
         return(attribute?.Value ?? string.Empty);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Format and write a ELO attribute line
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        private void WriteEloAttribute(StreamWriter stream, FileAttributeName name, string value)
        {
            var line = string.IsNullOrEmpty(value)
                ? $"{name.GetDescription()}"
                : $"{name.GetDescription(),-25} = {value}";

            stream.WriteLine(line);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new instance of the <see cref="FileAttribute"/> class
 /// </summary>
 /// <param name="name">Name of the attribute</param>
 /// <param name="rawValue">Raw value of the attribute</param>
 /// <param name="value">Processed value of the attribute</param>
 public FileAttribute(FileAttributeName name, string rawValue, string value)
 {
     this.Name     = name;
     this.RawValue = rawValue;
     if (name == FileAttributeName.Haupttitel || name == FileAttributeName.Untertitel)
     {
         value = value
                 .Replace("%%c", "Ø")
                 .Replace("%%C", "Ø");
     }
     this.Value = value;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Validate a ordernumber. required format is
        /// - RFQ_123456789
        /// - RFQ_123456
        /// - nicht 9 Zeichen lang
        /// - nicht 1- oder 1-...
        /// </summary>
        /// <param name="file">Attribute file</param>
        /// <param name="name">name of the attribute to check</param>
        /// <param name="required">Indicates if a date is required or not</param>
        private void ValidateOrderNumber(AttributeFile file, FileAttributeName name, bool required)
        {
            if (!required && string.IsNullOrEmpty(file[name]))
            {
                return;
            }

            if (string.IsNullOrEmpty(file[name]))
            {
                throw new InvalidOperationException($"{Strings.TXT_MISSING_ORDER_NUMBER}");
            }

            var regexOrderNumber = "(^RFQ_.{0,5}$)|(^RFQ_.{7,8}$)|(^RFQ_.{10,99}$)|(^1-$)|(^1-[.]+)|(^[0-9]{9}$)";

            if (Regex.IsMatch(file[name], regexOrderNumber))
            {
                throw new InvalidOperationException($"{Strings.TXT_INVALID_ORDER_NUMBER}");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Validate a date. required format is yyyy-mm-dd
        /// </summary>
        /// <param name="file">Attribute file</param>
        /// <param name="name">name of the attribute to check</param>
        /// <param name="required">Indicates if a date is required or not</param>
        private void ValidateDate(AttributeFile file, FileAttributeName name, bool required)
        {
            if (!required && string.IsNullOrEmpty(file[name]))
            {
                return;
            }

            if (string.IsNullOrEmpty(file[name]))
            {
                throw new InvalidOperationException($"{Strings.TXT_MISSING_DATE}: {name}");
            }

            if (!Regex.IsMatch(file[name], "\\d{4}-\\d{2}-\\d{2}"))
            {
                throw new InvalidOperationException($"{Strings.TXT_INVALID_DATE}: {name}");
            }

            if (!DateTime.TryParse(file[name], out _))
            {
                throw new InvalidOperationException($"{Strings.TXT_INVALID_DATE}: {name}");
            }
        }