/// <summary>
        /// Configure the permitted actions and their result for a given initiat state.
        /// </summary>
        /// <param name="initialState"></param>
        /// <returns>A builder to allow fluent configuration.</returns>
        private static ConfigurationBuilder Configure(FileSystemChangeType initialState)
        {
            if (Matrix.ContainsKey(initialState))
                throw new InvalidOperationException(string.Format(@"Initiate state ""{0}"" has already been configured", initialState));

            return new ConfigurationBuilder(Matrix[initialState] = new Dictionary<FileSystemChangeType, FileSystemChangeType>());
        }
示例#2
0
 // Save the filesystem on every filesystem change except full reloading.
 private void OnChange(FileSystemChangeType type, IPath _1, IPath?_2, IPath?_3)
 {
     if (type != FileSystemChangeType.Reload)
     {
         Save();
     }
 }
示例#3
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;
                //}
            }
        }
示例#4
0
        static FileSystemChange CreateSystemFileChange(FileSystemChangeType fileChangeType, string relativePath, string absolutePath)
        {
            var fileSystemChange = new FileSystemChange
            {
                FileSystemChangeType   = fileChangeType,
                RelativePathComponents = relativePath.Split(Path.DirectorySeparatorChar),
                FileSystemEntityType   = FileSystemEntityType.Unknown
            };

            try
            {
                fileSystemChange.FileSystemEntityType = File.GetAttributes(absolutePath).HasFlag(FileAttributes.Directory)
                    ? FileSystemEntityType.Directory : FileSystemEntityType.File;
            }
            catch (Exception)
            {
                // Not enough info to set the FileSystemEntityType to something known
            }

            return(fileSystemChange);
        }
        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);
        }
 private static FileSystemChangeType Transition(FileSystemChangeType initial, FileSystemChangeType action)
 {
     return FileSystemChangeStateMachine.Get(initial, action);
 }
 /// <summary>
 /// Get the resultant file system change from the given initial state and action to apply.
 /// </summary>
 public static FileSystemChangeType Get(FileSystemChangeType initial, FileSystemChangeType action)
 {
     return Matrix[initial][action];
 }
 public ConfigurationBuilder Permit(FileSystemChangeType action, FileSystemChangeType result)
 {
     _config.Add(action, result);
     return this;
 }
 public FileSystemChangeEventArgs(string newName, string newPath, FileSystemChangeType changeType)
 {
     this.Name       = newName;
     this.Path       = newPath;
     this.ChangeType = changeType;
 }