internal static void DoCopyTo(INode thisNode, INode target, Func <INode, bool, INode> baseCall, bool overwrite)
        {
            DoCopyOrMove
            (
                thisNode,
                target,
                overwrite,
                baseCall,
                delegate(NetworkFileSystem.FreeClientContext clientContext)
            {
                return(clientContext.NetworkFileSystemClient.Copy);
            }
            );

            ((NetworkNodeAndFileAttributes)target.Attributes).SetValue <bool>("exists", true);

            List <KeyValuePair <string, object> > attributes;

            attributes = new List <KeyValuePair <string, object> >();

            // Copy attributes to target node

            lock (thisNode.Attributes.SyncLock)
            {
                foreach (string name in thisNode.Attributes.Names)
                {
                    attributes.Add(new KeyValuePair <string, object>(name, thisNode.Attributes[name]));
                }
            }

            lock (target.Attributes.SyncLock)
            {
                ((NetworkNodeAndFileAttributes)target.Attributes).SetValue <bool>("exists", true);

                foreach (KeyValuePair <string, object> attribute in attributes)
                {
                    target.Attributes[attribute.Key] = attribute.Value;
                }
            }

            if (target.ParentDirectory is NetworkDirectory)
            {
                ((NetworkDirectory)target.ParentDirectory).AddChild(target);
            }

            if (((NetworkFileSystem)thisNode.FileSystem).ShouldSupportSynthesizedActivityEvents)
            {
                NetworkFileSystem.RaiseActivityEvent((NetworkFileSystem)target.FileSystem, new FileSystemActivityEventArgs(FileSystemActivity.Created, target.NodeType, target.Name, target.Address.AbsolutePath));
                NetworkFileSystem.RaiseActivityEvent((NetworkFileSystem)target.FileSystem, new FileSystemActivityEventArgs(FileSystemActivity.Changed, target.NodeType, target.Name, target.Address.AbsolutePath));
            }
        }
        internal static void DoCreate(INode thisNode, bool createParent)
        {
            using (NetworkFileSystem.FreeClientContext clientContext = ((NetworkFileSystem)thisNode.FileSystem).GetFreeClientContext())
            {
                clientContext.NetworkFileSystemClient.Create(((NetworkNodeAddress)thisNode.Address).RemoteUri, thisNode.NodeType, createParent);

                lock (thisNode.Attributes.SyncLock)
                {
                    ((NetworkNodeAndFileAttributes)thisNode.Attributes).SetValue <bool>("exists", true);
                }

                if (((NetworkFileSystem)thisNode.FileSystem).ShouldSupportSynthesizedActivityEvents)
                {
                    NetworkFileSystem.RaiseActivityEvent((NetworkFileSystem)thisNode.FileSystem, new FileSystemActivityEventArgs(FileSystemActivity.Created, thisNode.NodeType, thisNode.Name, thisNode.Address.AbsolutePath));
                }
            }
        }
Example #3
0
        protected override Stream DoOpenStream(string contentName, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
        {
            Stream stream = null;

            NetworkFileSystem.FreeClientContext clientContext = null;

            // Get a new client context optimised for binary access

            clientContext = this.FileSystem.GetFreeClientContext(true);

            try
            {
                // Create a new RandomAcessStream based on the client

                stream = clientContext.NetworkFileSystemClient.OpenRandomAccessStream(this.Address.RemoteUri, fileMode, fileAccess, fileShare);

                // Make sure the client context is disposed after the stream is closed

                ((IStreamWithEvents)stream).AfterClose += delegate
                {
                    clientContext.Dispose();

                    if (fileAccess == FileAccess.ReadWrite || fileAccess == FileAccess.Write)
                    {
                        ((NetworkNodeAndFileAttributes)this.Attributes).SetValue <bool>("exists", true);
                        ((NetworkNodeAndFileAttributes)this.Attributes).SetValue <long>("length", stream.Length);

                        ((NetworkDirectory)this.ParentDirectory).AddChild(this);

                        NetworkFileSystem.RaiseActivityEvent((NetworkFileSystem)this.FileSystem, new FileSystemActivityEventArgs(FileSystemActivity.Changed, this.NodeType, this.Name, this.Address.AbsolutePath));
                    }
                };
            }
            finally
            {
                if (stream == null)
                {
                    // Explicitly dispose the client context because the
                    // stream can't do it cause it doesn't exist

                    clientContext.Dispose();
                }
            }

            return(stream);
        }
        public virtual void Update()
        {
            lock (this.SyncLock)
            {
                var networkFileSystem = (NetworkFileSystem)this.node.FileSystem;

                using (var clientContext = networkFileSystem.GetFreeClientContext())
                {
                    clientContext.NetworkFileSystemClient.SetAttributes
                    (
                        ((NetworkNodeAddress)this.node.Address).RemoteUri,
                        this.node.NodeType,
                        GetAttributesPairs()
                    );
                }

                NetworkFileSystem.RaiseActivityEvent((NetworkFileSystem)this.node.FileSystem, new FileSystemActivityEventArgs(FileSystemActivity.Changed, this.node.NodeType, this.node.Name, this.node.Address.AbsolutePath));
            }
        }
        internal static void DoDelete(INode thisNode, bool recursive)
        {
            using (NetworkFileSystem.FreeClientContext clientContext = ((NetworkFileSystem)thisNode.FileSystem).GetFreeClientContext())
            {
                clientContext.NetworkFileSystemClient.Delete(((NetworkNodeAddress)thisNode.Address).RemoteUri, thisNode.NodeType, recursive);

                lock (thisNode.Attributes)
                {
                    ((NetworkNodeAndFileAttributes)thisNode.Attributes).Clear();
                    ((NetworkNodeAndFileAttributes)thisNode.Attributes).SetValue <bool>("exists", false, false);
                }

                if (((NetworkFileSystem)thisNode.FileSystem).ShouldSupportSynthesizedActivityEvents)
                {
                    NetworkFileSystem.RaiseActivityEvent((NetworkFileSystem)thisNode.FileSystem, new FileSystemActivityEventArgs(FileSystemActivity.Deleted, thisNode.NodeType, thisNode.Name, thisNode.Address.AbsolutePath));

                    if (!thisNode.Address.IsRoot && thisNode.ParentDirectory is NetworkDirectory)
                    {
                        ((NetworkDirectory)thisNode.ParentDirectory).RemoveChild(thisNode);
                    }
                }
            }
        }