Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/05/13 10:50:47 (11 years ago)
Author:
mkommend
Message:

#2081: Updated branches from trunk and implemented all review comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Data Path DataTypes/HeuristicLab.Data/3.3/Path Types/PathValue.cs

    r9680 r9697  
    2121
    2222
    23 using System;
    2423using System.IO;
    2524using HeuristicLab.Common;
     
    3130  [StorableClass]
    3231  public abstract class PathValue : StringValue {
    33     [Storable]
    34     private bool checkExistence;
    35     public bool CheckExistence {
    36       get { return checkExistence; }
    37       set {
    38         if (ReadOnly) throw new NotSupportedException("CheckExistence cannot be set. PathValue is read-only.");
    39         if (value != checkExistence) {
    40           checkExistence = value;
    41           OnCheckExistenceChanged();
    42         }
    43       }
    44     }
    45 
    4632    public override string Value {
    4733      get { return base.Value; }
    4834      set {
    4935        if (value == null) value = string.Empty;
    50         if (checkExistence && !string.IsNullOrEmpty(value) && !File.Exists(value) && !Directory.Exists(value))
    51           throw new ArgumentException(string.Format("The given file {0} does not exists.", value));
    52         if (value[value.Length - 1] == Path.DirectorySeparatorChar)
    53           value = value.TrimEnd(Path.DirectorySeparatorChar);
    54         if (value[value.Length - 1] == Path.AltDirectorySeparatorChar)
    55           value = value.TrimEnd(Path.AltDirectorySeparatorChar);
     36        value = value.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
    5637        base.Value = value;
    5738      }
     
    6041    [StorableConstructor]
    6142    protected PathValue(bool deserializing) : base(deserializing) { }
    62     protected PathValue(PathValue original, Cloner cloner)
    63       : base(original, cloner) {
    64       checkExistence = original.checkExistence;
    65     }
     43    protected PathValue(PathValue original, Cloner cloner) : base(original, cloner) { }
    6644
    6745    protected PathValue()
    68       : base(string.Empty) {
    69       checkExistence = true;
    70     }
     46      : base(string.Empty) { }
    7147
    7248    public abstract bool Exists();
    73 
    74     protected override bool Validate(string value, out string errorMessage) {
    75       if (CheckExistence && !File.Exists(value) && !Directory.Exists(value)) {
    76         errorMessage = string.Format("The given path {0} does not exist.", value);
    77         return false;
    78       }
    79       return base.Validate(value, out errorMessage);
    80     }
    81 
    82     public event EventHandler CheckExistenceChanged;
    83     protected virtual void OnCheckExistenceChanged() {
    84       var handler = CheckExistenceChanged;
    85       if (handler != null)
    86         handler(this, EventArgs.Empty);
    87     }
    8849  }
    8950}
Note: See TracChangeset for help on using the changeset viewer.