internal static void DoCopyOrMove(INode thisNode, INode target, bool overwrite, Func <INode, bool, INode> baseCall, Func <NetworkFileSystem.FreeClientContext, Action <string, string, NodeType, bool> > clientCall)
        {
            IFile targetFile;
            NetworkNodeAddress address1, address2;

            NetworkFileSystem.FreeClientContext clientContext = null;

            targetFile = target.OperationTargetDirectory.ResolveFile(target.Address.Name);

            address1 = (NetworkNodeAddress)targetFile.Address;
            address2 = (NetworkNodeAddress)thisNode.Address;

            if (!(address1.ServerName == address2.ServerName &&
                  address1.Port == address2.Port))
            {
                baseCall(target, overwrite);

                return;
            }

            // Get a new client context

            using (clientContext = ((NetworkFileSystem)thisNode.FileSystem).GetFreeClientContext())
            {
                clientCall(clientContext)(address2.RemoteUri, address1.RemoteUri, NodeType.File, overwrite);
            }
        }
        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));
                }
            }
        }
Пример #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);
        }
Пример #4
0
        protected override IFile DoCreateHardLink(IFile targetFile, bool overwrite)
        {
            NetworkFileSystem.FreeClientContext clientContext = null;

            // Get a new client context

            if (!targetFile.FileSystem.Equals(this.FileSystem))
            {
                throw new NotSupportedException("CreateHardLink/ForiegnFilesystem");
            }

            using (clientContext = this.FileSystem.GetFreeClientContext())
            {
                clientContext.NetworkFileSystemClient.CreateHardLink(((NetworkNodeAddress)this.Address).RemoteUri, ((NetworkNodeAddress)targetFile.Address).RemoteUri, overwrite);
            }

            return(this);
        }
        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);
                    }
                }
            }
        }