Пример #1
0
 private void PrepareFiles(CommandContext context, params FileDescriptor[] files)
 {
     foreach (FileDescriptor file in files)
     {
         MountedFileCache.Cache.AddFile(file);
     }
 }
Пример #2
0
        public bool HandlesCommand(CommandContext context)
        {
            foreach (string command in _acceptedCommands)
            {
                if (context.Command.Trim().StartsWith(command))
                {
                    _usedCommand = command;

                    if (
                        context.Command.Trim() == _usedCommand ||
                            (_allowsArguments && context.Command.ToCharArray()[_usedCommand.Length] == ' ')
                        )
                    {
                        if (_allowsArguments)
                        {
                            _args = context.Command.Trim() == command ? "" : context.Command.Trim().Substring(_usedCommand.Length + 1);
                        }

                        return true;
                    }
                }
            }

            return false;
        }
Пример #3
0
        internal CommandContext Clone()
        {
            CommandContext clone = new CommandContext();

            clone.CurrentPath = CurrentPath;
            clone.Server = Server;
            clone.LocalClient = LocalClient;
            clone.Command = Command;

            return clone;
        }
Пример #4
0
        private bool PrepareFilesFromWildCards(CommandContext context, string searchPattern)
        {
            bool found = false;

            DirectoryInfo info = new DirectoryInfo(context.CurrentPath);

            foreach (FileInfo file in info.GetFiles(searchPattern))
            {
                found = true;
                PrepareFiles(context, FileDescriptor.Create(file, false));
            }

            return found;
        }
Пример #5
0
        public override bool HandleCommand(CommandContext context)
        {
            string files = string.IsNullOrEmpty(Arguments) ? "*.*" : Arguments;

            if (UsedCommand == "prepf" || UsedCommand == "mountf")
            {
                foreach (string fileName in (files).Split(','))
                {
                    string fullName = Path.Combine(context.CurrentPath, fileName.Trim());

                    if (File.Exists(fullName))
                    {
                        PrepareFiles(context, FileDescriptor.Create(fullName, false));
                    }
                    else if (File.Exists(fileName.Trim()))
                    {
                        PrepareFiles(context, FileDescriptor.Create(fileName.Trim(), false));
                    }
                    else if (PrepareFilesFromWildCards(context, fileName))
                    {

                    }
                    else
                    {
                        Console.WriteLine("Unknown File: \"{0}\"", fileName);
                    }
                }

                return true;
            }
            else
            {
                foreach (string fileName in (files).Split(','))
                {
                    if (fileName.Contains("*"))
                    {
                        RemoveFilesByWildCards(context, fileName);
                    }
                    else
                    {
                        string fullName = new FileInfo(Path.Combine(context.CurrentPath, fileName.Trim())).FullName;

                        RemoveFiles(context, fullName);
                    }
                }

                return true;
            }
        }
Пример #6
0
        static void ParseCommand(string line)
        {
            CommandContext context = new CommandContext();

            context.Command = line ;

            context.CurrentPath = CurrentPath;
            context.LocalClient = _localClient;
            context.Server = _server;

            List<ICommand> valid = _commands.Where(c => c.HandlesCommand(context)).ToList();

            if (valid.Count == 1)
            {
                valid[0].HandleCommand(context);
                return;
            }
            else if (valid.Count > 1)
            {
                valid[valid.Max(c => c.Priority)].HandleCommand(context);

                return;
            }

            if (line.Trim().StartsWith("dir") || line.Trim().StartsWith("ls"))
            {
                ListCurrentDirectory(line.Substring(
                                 line.Trim().StartsWith("dir")?3:2
                                                    ));
            }
            else if (line.Trim().StartsWith("cd "))
            {
                SwapPath(line.Trim().Substring(3));
            }
            else if (line.Trim()=="fsi")
            {
                ListFileSystemInfo();
            }
            else if (line.Trim()=="path" || line.Trim() =="pwd")
            {
                EchoPath();
            }
            else
            {
                Console.WriteLine("Bad command {0}", line);
            }
        }
Пример #7
0
        private void RemoveFilesByWildCards(CommandContext context, string searchPattern)
        {
            bool found = false;

            DirectoryInfo info = new DirectoryInfo(context.CurrentPath);

            foreach (FileInfo file in info.GetFiles(searchPattern))
            {
                found = true;
                RemoveFiles(context, new string[] { file.FullName });
            }

            if (!found)
            {
                Console.WriteLine("No file found for pattern {0}", searchPattern);
            }
        }
Пример #8
0
        private void RemoveFiles(CommandContext context, params string[] files)
        {
            foreach (string file in files)
            {
                FileDescriptor descriptor = MountedFileCache.Cache.GetFileDescriptor(file);

                if (descriptor == null)
                {
                    Console.WriteLine("{0} not mounted. Ignoring", file);
                    continue;
                }

                bool fileRemoved = false;

                EventHandler<FileListModificationEventArgs> handler = delegate(object sender, FileListModificationEventArgs e)
                {
                    StringBuilder builder = new StringBuilder();

                    foreach (FileModificationDescriptor item in e.Modifications)
                    {
                        if (item.Mode == FileModificationMode.Remove)
                        {
                            builder.AppendFormat("Removing File: \"{0}\"{1}", item.FileFullName, Environment.NewLine);
                        }
                    }

                    Console.Write(builder.ToString());

                    fileRemoved = true;
                };

                context.LocalClient.FileListUpdateReceived += new EventHandler<FileListModificationEventArgs>(handler);

                context.LocalClient.RemoveFiles(new FileDescriptor[] { descriptor });

                while (!fileRemoved)
                {
                    Thread.Sleep(100);
                }

                context.LocalClient.FileListUpdateReceived -= new EventHandler<FileListModificationEventArgs>(handler);
            }
        }
Пример #9
0
 public abstract bool HandleCommand(CommandContext context);