Example #1
0
        /// <summary>
        /// Used to inform manager about the addition of another file or diretory which should be monitored by the manager (and which should eventually be pruned).
        /// This method may also be used to inform the manager that the file contents might have changed.
        /// </summary>
        public void NotePathAdded(string pathToAdd, Logging.IMesgEmitter issueEmitter)
        {
            try
            {
                string fullPathToAdd   = System.IO.Path.GetFullPath(pathToAdd);
                string workingRootPath = treeRootEntry.Path;

                string   relativePathPart     = String.Empty;
                string[] relativePathSegments = null;

                if (fullPathToAdd.StartsWith(workingRootPath))
                {
                    // convert the full path into a relative path
                    relativePathPart = @".{0}".CheckedFormat(fullPathToAdd.Substring(workingRootPath.Length));

                    relativePathSegments = relativePathPart.Split(new char[] { System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar }).Skip(1).ToArray();
                }

                string regeneratedFullPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(workingRootPath, relativePathPart));

                if (!String.IsNullOrEmpty(relativePathPart) && (regeneratedFullPath == fullPathToAdd))
                {
                    treeRootEntry.AddRelativePath(relativePathSegments, issueEmitter);
                }
                else
                {
                    issueEmitter.Emit("NotePathAdded '{0}' failed: given path is a proper subpath under under the monitored path '{1}'", pathToAdd, workingRootPath);
                }

                treeRootEntry.UpdateTree(issueEmitter);
            }
            catch (System.Exception ex)
            {
                issueEmitter.Emit("NotePathAdded '{0}' failed: error:'{1}'", pathToAdd, ex);
            }
        }