Beispiel #1
0
 /// <summary>
 /// Adds a changed file.
 /// </summary>
 public void AddChangedPath(string changedPath, PathChanges changes)
 {
     if (m_samples.Count < SampleSize)
     {
         m_samples.Add((changedPath, changes, null));
     }
 }
Beispiel #2
0
        public void AssertAllChanges(string filePath, PathChanges changes)
        {
            var changesForPath = ChangesForPath(filePath);

            if (changesForPath.HasFlag(changes))
            {
                XAssert.Fail(GetChangeReport($"Expected to find ALL of {changes} changes for '{filePath}'; instead, found {changesForPath}"));
            }
        }
Beispiel #3
0
        public PathChanges AssertAnyChange(string filePath, PathChanges changes)
        {
            var changesForPath = ChangesForPath(filePath);

            if ((changesForPath & changes) == 0)
            {
                XAssert.Fail(GetChangeReport($"Expected to find at least ONE of {changes} changes for '{filePath}'; instead, found {changesForPath}"));
            }
            return(changesForPath);
        }
Beispiel #4
0
 /// <summary>
 /// Checks if path changes are excatly newly present.
 /// </summary>
 public static bool IsNewlyPresent(this PathChanges pathChanges)
 {
     return(pathChanges == PathChanges.NewlyPresentAsFile || pathChanges == PathChanges.NewlyPresentAsDirectory || pathChanges == PathChanges.NewlyPresent);
 }
Beispiel #5
0
 /// <summary>
 /// Checks if path changes include newly present.
 /// </summary>
 public static bool ContainsNewlyPresent(this PathChanges pathChanges)
 {
     return((pathChanges & (PathChanges.NewlyPresent | PathChanges.NewlyPresentAsDirectory | PathChanges.NewlyPresentAsFile)) != 0);
 }
Beispiel #6
0
 /// <summary>
 /// Creates an instance of <see cref="ChangedPathInfo"/>.
 /// </summary>
 public ChangedPathInfo(string path, PathChanges pathChanges)
 {
     Path        = path;
     PathChanges = pathChanges;
 }
Beispiel #7
0
        /// <summary>
        /// Tries to parse input line.
        /// </summary>
        /// <remarks>
        /// Input line must be of the form:
        ///   full path
        /// or
        ///   full path|comma separated <see cref="PathChanges"/>
        /// The former assumes that changes are <see cref="PathChanges.DataOrMetadataChanged"/>.
        /// </remarks>
        private static bool TryParseInput(
            LoggingContext loggingContext,
            string input,
            string filePath,
            int lineNo,
            out ChangedPathInfo changedPathInfo,
            string sourceRoot = null,
            DirectoryTranslator directoryTranslator = null)
        {
            Contract.Requires(loggingContext != null);
            Contract.Requires(!string.IsNullOrEmpty(input));

            changedPathInfo = default;
            string[] splitInput = input.Split(s_inputSeparator);

            if (splitInput.Length > 2)
            {
                Logger.Log.InvalidFormatOfInputChange(loggingContext, input, filePath, lineNo);
                return(false);
            }

            string changedPath = splitInput[0].Trim();
            string changesStr  = null;

            if (splitInput.Length == 2)
            {
                changesStr = splitInput[1].Trim();
            }

            // Assume data or metadata change if unspecified.
            PathChanges changes = PathChanges.DataOrMetadataChanged;

            try
            {
                if (!Path.IsPathRooted(changedPath))
                {
                    if (string.IsNullOrEmpty(sourceRoot))
                    {
                        Logger.Log.InvalidChangedPathOfInputChange(loggingContext, changedPath, filePath, lineNo);
                        return(false);
                    }

                    changedPath = Path.GetFullPath(Path.Combine(sourceRoot, changedPath));
                }

                if (directoryTranslator != null)
                {
                    changedPath = directoryTranslator.Translate(changedPath);
                }

                if (!string.IsNullOrEmpty(changesStr))
                {
                    if (!Enum.TryParse(changesStr, true, out changes))
                    {
                        string validKinds = string.Join(", ", ((PathChanges[])Enum.GetValues(typeof(PathChanges))).Select(c => c.ToString()));
                        Logger.Log.InvalidChangeKindsOfInputChange(loggingContext, changesStr, filePath, lineNo, validKinds);
                        return(false);
                    }
                }
            }
            catch (ArgumentException argumentException)
            {
                Logger.Log.InvalidInputChange(loggingContext, input, filePath, lineNo, argumentException.ToString());
                return(false);
            }

            changedPathInfo = new ChangedPathInfo(changedPath, changes);
            return(true);
        }
Beispiel #8
0
 /// <summary>
 /// Adds a changed to dynamically observed file or directory.
 /// </summary>
 public void AddChangedDynamicallyObservedArtifact(string changedDynamicallyObservedFile, PathChanges changes, DynamicObservationType dynamicObservationType)
 {
     if (m_samples.Count < SampleSize)
     {
         m_samples.Add((changedDynamicallyObservedFile, changes, dynamicObservationType));
     }
 }
Beispiel #9
0
 public void AssertExactChanges(string filePath, PathChanges changes)
 {
     XAssert.AreEqual(changes, ChangesForPath(filePath), "\nChanges for file '{0}' disagree", filePath);
 }