Ejemplo n.º 1
0
		public override void Process(Command command)
		{
			var options = (CommandOptions)this.LoadOptions((TextCommand)command);
			var nodeType = NodeType.FromName(options.NodeType);
			var src = this.Connection.FileSystemManager.Resolve(options.Src, nodeType);
			var des = this.Connection.FileSystemManager.Resolve(options.Des, nodeType);

			src.MoveTo(des, options.Overwrite);

			Connection.WriteOk();
			Connection.Flush();
		}
Ejemplo n.º 2
0
        public override void Process(Command command)
        {
            Exception e = null;

            var options  = (CommandOptions)this.LoadOptions((TextCommand)command);
            var nodeType = NodeType.FromName(options.NodeType);
            var node     = this.Connection.FileSystemManager.Resolve(options.Uri, nodeType);

            node.Refresh();

            if (!node.Exists)
            {
                throw new NodeNotFoundException(node.Address);
            }

            if (!NodeTypeSupported(node.NodeType))
            {
                Connection.WriteError(ErrorCodes.INVALID_PARAM);

                return;
            }

            Connection.WriteOk();
            Connection.Flush();

            using (node.Attributes.AquireUpdateContext())
            {
                var lastLineRead = new ValueBox <string>();

                foreach (var attribute in TextNetworkProtocol.ReadAttributes(Connection.ReadTextBlock, lastLineRead))
                {
                    var attributeName  = attribute.Name;
                    var attributeValue = attribute.Value;

                    if (!(attributeName.EqualsIgnoreCase("exists") || attributeName.EqualsIgnoreCase("length")))
                    {
                        e = ActionUtils.IgnoreExceptions(delegate
                        {
                            node.Attributes[attributeName] = attributeValue;
                        });
                    }
                }
            }

            if (e != null)
            {
                throw e;
            }

            this.Connection.WriteOk();
        }
        public static NodeType GetNodeType(string name)
        {
            switch (name)
            {
            case "f":
                return(NodeType.File);

            case "d":
                return(NodeType.Directory);

            default:
                return(NodeType.FromName(name));
            }
        }
        public override void Process(Command command)
        {
            var options = this.LoadOptions <CommandOptions>((TextCommand)command);

            if (StringUtils.IsNullOrEmpty(options.Uri))
            {
                Connection.WriteError(ErrorCodes.INVALID_VALUE, "uri");
            }

            var node = this.Connection.FileSystemManager.Resolve(options.Uri, NodeType.FromName(options.NodeType));

            node.Create(options.CreateParent);

            Connection.WriteOk();
            Connection.Flush();
        }
Ejemplo n.º 5
0
        public override void Process(Command command)
        {
            var options  = (CommandOptions)this.LoadOptions((TextCommand)command);
            var nodeType = NodeType.FromName(options.NodeType);
            var node     = this.Connection.FileSystemManager.Resolve(options.Uri, nodeType);

            if (node.NodeType.Equals(NodeType.Directory))
            {
                ((IDirectory)node).Delete(options.Recursive);
            }
            else
            {
                node.Delete();
            }

            Connection.WriteOk();
        }
Ejemplo n.º 6
0
        public override void Process(Command command)
        {
            var options  = (CommandOptions)this.LoadOptions((TextCommand)command);
            var nodeType = NodeType.FromName(options.NodeType);
            var node     = this.Connection.FileSystemManager.Resolve(options.Uri, nodeType);

            node.Refresh();

            this.Connection.WriteOk();

            foreach (Pair <string, object> attribute in node.Attributes)
            {
                if (attribute.Value != null)
                {
                    Connection.WriteTextBlock(@"{0}=""{1}:{2}""", attribute.Name, ProtocolTypes.GetTypeName(attribute.Value.GetType()), ProtocolTypes.ToEscapedString(attribute.Value));
                }
            }
        }
Ejemplo n.º 7
0
        public override void Process(Command command)
        {
            var options  = (CommandOptions)this.LoadOptions((TextCommand)command);
            var nodeType = NodeType.FromName(options.NodeType);
            var src      = this.Connection.FileSystemManager.Resolve(options.Src, nodeType);
            var des      = this.Connection.FileSystemManager.Resolve(options.Des, nodeType);

            if (options.Monitor)
            {
                var x       = 0;
                var service = (INodeCopyingService)src.GetService(new NodeCopyingServiceType(des, options.Overwrite, options.BufferSize));

                service.Progress.ValueChanged += delegate
                {
                    Connection.WriteTextBlock("{0} {1}", service.Progress.CurrentValue, service.Progress.MaximumValue);

                    if (x % 8 == 0)
                    {
                        Connection.Flush();
                    }

                    x++;
                };

                int okwritten = 0;

                Connection.WriteOk();

                Action routine = delegate
                {
                    service.Run();
                    this.Connection.Flush();

                    //
                    // Only write OK if the main thread hasn't printed OK/CANCEL
                    // in response to an a CANCEL request.
                    //

                    if (System.Threading.Interlocked.CompareExchange(ref okwritten, 1, 0) == 0)
                    {
                        this.Connection.WriteOk();
                        this.Connection.Flush();
                    }
                };

                var result = routine.BeginInvoke(null, null);

                //
                // Read the special CANCEL and READY commands.
                //

                var cancelled = false;

                for (;;)
                {
                    var line = this.Connection.ReadTextBlock();

                    if (line == null)
                    {
                        this.Connection.RunLevel = DisconnectedRunLevel.Default;

                        return;
                    }

                    if (line.StartsWith(ResponseCodes.READY, StringComparison.CurrentCultureIgnoreCase))
                    {
                        //
                        // READY tells us to process new commands.
                        //

                        break;
                    }
                    else if (line.StartsWith(ResponseCodes.CANCEL, StringComparison.CurrentCultureIgnoreCase))
                    {
                        //
                        // CANCEL tells us to cancel the operation.
                        //

                        // Cancel the operation

                        if (cancelled)
                        {
                            continue;
                        }

                        service.Stop();

                        // Write OK/CANCELED if the operation thread hasn't already

                        if (System.Threading.Interlocked.CompareExchange(ref okwritten, 1, 0) == 0)
                        {
                            if (service.TaskState == Platform.TaskState.Finished)
                            {
                                Connection.WriteOk();
                            }
                            else
                            {
                                Connection.WriteError(ErrorCodes.CANCELLED);
                            }

                            Connection.Flush();
                        }

                        // Wait for the operation thread to finish

                        routine.EndInvoke(result);

                        cancelled = true;
                    }
                    else
                    {
                        this.Connection.RunLevel = DisconnectedRunLevel.Default;

                        return;
                    }
                }

                Connection.Flush();
            }
            else
            {
                // Perform the operation

                Connection.WriteOk();

                src.CopyTo(des, options.Overwrite);
            }
        }