Пример #1
0
        private void _HandleChange(
            FileSystemChangeType changeType,
            string newPath,
            string origPath = null)
        {
            bool isDirectory = changeType == FileSystemChangeType.Delete
               ? !Path.HasExtension(newPath) // best we can do since object no longer exists
               : (File.GetAttributes(newPath) & FileAttributes.Directory) == FileAttributes.Directory;

            FileSystemObjectType fsoType = isDirectory
                ? FileSystemObjectType.Directory
                : FileSystemObjectType.File;;

            Console.WriteLine(string.Concat(
                                  changeType.ToString(),
                                  ": ",
                                  newPath,
                                  origPath == null ? "" : ", orig: ",
                                  origPath == null ? "" : origPath,
                                  ", type: ",
                                  fsoType.ToString()));

            if (this.Changed != null)
            {
                //try
                //{
                //this.FileSystemWatcher.EnableRaisingEvents = false;
                this.Changed(this, new FileSystemChangeEventArgs
                {
                    ChangeType           = changeType,
                    FileSystemObjectType = fsoType,
                    FullPath             = newPath,
                    OriginalFullPath     = origPath
                });
                //}
                //finally
                //{
                //    //this.FileSystemWatcher.EnableRaisingEvents = true;
                //}
            }
        }
Пример #2
0
        public string BuildCommandArgs(
            FileSystemChangeType changeType,
            FileSystemObjectType fsoType,
            string watchDirPath,
            string changedFilePath,
            string originalFilePath,
            string filePathToProcess,
            string[] processExeArgs)
        {
            watchDirPath      = this._getFullPath(watchDirPath ?? "");
            changedFilePath   = this._getFullPath(changedFilePath ?? "");
            originalFilePath  = this._getFullPath(originalFilePath ?? "");
            filePathToProcess = this._getFullPath(filePathToProcess ?? "");

            string argTokenStr = string.Concat(
                "\"",
                string.Join("\" \"", processExeArgs),
                "\"");

            IList <string> executableArgsList = new List <string>();

            string argsStr = argTokenStr.Replace(Token.ChangeType, changeType.ToString());

            argsStr = argsStr.Replace(Token.ObjectType, fsoType.ToString());

            argsStr = argsStr.Replace(Token.ChangedPath, changedFilePath);
            argsStr = argsStr.Replace(Token.ChangedPathNoExtension, Path.Combine(Path.GetDirectoryName(changedFilePath), Path.GetFileNameWithoutExtension(changedFilePath)));
            argsStr = argsStr.Replace(Token.ChangedPathRelative, changedFilePath.Substring(watchDirPath.Length + 1));

            argsStr = argsStr.Replace(Token.EachPath, filePathToProcess);
            argsStr = argsStr.Replace(Token.EachPathNoExtension, Path.Combine(Path.GetDirectoryName(filePathToProcess), Path.GetFileNameWithoutExtension(filePathToProcess)));
            argsStr = argsStr.Replace(Token.EachPathRelative, filePathToProcess.Substring(watchDirPath.Length + 1));

            argsStr = argsStr.Replace(Token.OriginalPath, originalFilePath);

            return(argsStr);
        }