Наследование: AbstractDirectory, IRemoteDirectoryItem
Пример #1
0
        internal void UpdateFromInfo(SharedDirectoryInfo info)
        {
            var newDirectories = new RemoteDirectory[info.Directories.Length];

            for (int x = 0; x < info.Directories.Length; x++)
            {
                RemoteDirectory dir = (RemoteDirectory)GetSubdirectory(info.Directories[x]);
                if (dir == null)
                {
                    dir = new RemoteDirectory(PathUtil.Join(m_FullPath, info.Directories[x]));
                }
                newDirectories[x] = dir;
            }

            var newFiles = new RemoteFile[info.Files.Length];

            for (int x = 0; x < info.Files.Length; x++)
            {
                RemoteFile file = (RemoteFile)GetFile(info.Files[x].Name);
                if (file == null)
                {
                    file = new RemoteFile(this, info.Files[x]);
                }
                else
                {
                    file.UpdateFromInfo(info.Files[x]);
                }
                newFiles[x] = file;
            }

            m_SubDirectories = newDirectories;
            m_Files          = newFiles;

            m_State = RemoteDirectoryState.ContentsReceived;
        }
Пример #2
0
        public void ProcessRespondDirListingMessage(Network network, Node messageFrom, SharedDirectoryInfo info)
        {
            string fullPath = PathUtil.Join(messageFrom.Directory.FullPath, info.FullPath);

            var node = PathUtil.GetNode(fullPath);

            if (node != messageFrom)
            {
                throw new Exception("Directory was for a different node");
            }

            RemoteDirectory remoteDirectory = GetOrCreateRemoteDirectory(fullPath);

            remoteDirectory.UpdateFromInfo(info);

            lock (remoteDirectoryCallbacks)
            {
                if (remoteDirectoryCallbacks.ContainsKey(fullPath))
                {
                    foreach (var callback in remoteDirectoryCallbacks[fullPath])
                    {
                        callback(remoteDirectory);
                    }
                    remoteDirectoryCallbacks.Remove(fullPath);
                }
            }

            network.RaiseReceivedDirListing(messageFrom, remoteDirectory);
        }
Пример #3
0
        internal RemoteFile(RemoteDirectory parent, SharedFileListing listing)
        {
            m_Parent = parent;

            m_Name = listing.Name;
            UpdateFromInfo(listing);
        }
Пример #4
0
        internal RemoteFile(RemoteDirectory parent, SharedFileListing listing)
        {
            m_Parent = parent;

            m_Name = listing.Name;
            UpdateFromInfo(listing);
        }
Пример #5
0
        internal RemoteDirectory CreateSubdirectory(string name)
        {
            var dir = new RemoteDirectory(PathUtil.Join(m_FullPath, name));

            var newDirectories = new RemoteDirectory[m_SubDirectories.Length + 1];

            Array.Copy(m_SubDirectories, newDirectories, m_SubDirectories.Length);
            newDirectories[newDirectories.Length - 1] = dir;

            m_SubDirectories = newDirectories;

            return(dir);
        }
Пример #6
0
        public bool BeginGetDirectory(string path, DirectoryCallback callback)
        {
            path = PathUtil.CleanPath(path);

            // LocalDirectory and NetworkDirectory objects can always be returned immediately.
            string[] parts = path.Split('/');
            if ((parts.Length > 1 && parts[1] == "local") || parts.Length < 3)
            {
                var directory = GetDirectory(path);
                callback(directory);
                return(true);
            }
            else
            {
                RemoteDirectory directory = (RemoteDirectory)GetDirectory(path);
                if (directory != null)
                {
                    if (directory.State != RemoteDirectoryState.ContentsUnrequested)
                    {
                        callback(directory);
                        return(true);
                    }
                }

                lock (remoteDirectoryCallbacks)
                {
                    if (!remoteDirectoryCallbacks.ContainsKey(path))
                    {
                        remoteDirectoryCallbacks.Add(path, new List <DirectoryCallback>());
                    }
                    var list = remoteDirectoryCallbacks[path];
                    list.Add(callback);
                }

                var network = PathUtil.GetNetwork(path);
                network.RequestDirectoryListing(path);
                return(false);
            }
        }
Пример #7
0
        internal void UpdateFromInfo(SharedDirectoryInfo info)
        {
            var newDirectories = new RemoteDirectory[info.Directories.Length];
            for (int x = 0; x < info.Directories.Length; x++) {
                RemoteDirectory dir = (RemoteDirectory) GetSubdirectory(info.Directories[x]);
                if (dir == null)
                    dir = new RemoteDirectory(PathUtil.Join(m_FullPath, info.Directories[x]));
                newDirectories[x] = dir;
            }

            var newFiles = new RemoteFile[info.Files.Length];
            for (int x = 0; x < info.Files.Length; x++) {
                RemoteFile file = (RemoteFile) GetFile(info.Files[x].Name);
                if (file == null)
                    file = new RemoteFile(this, info.Files[x]);
                else
                    file.UpdateFromInfo(info.Files[x]);
                newFiles[x] = file;
            }

            m_SubDirectories = newDirectories;
            m_Files          = newFiles;

            m_State = RemoteDirectoryState.ContentsReceived;
        }
Пример #8
0
        internal RemoteDirectory CreateSubdirectory(string name)
        {
            var dir = new RemoteDirectory(PathUtil.Join(m_FullPath, name));

            var newDirectories = new RemoteDirectory[m_SubDirectories.Length + 1];
            Array.Copy(m_SubDirectories, newDirectories, m_SubDirectories.Length);
            newDirectories[newDirectories.Length - 1] = dir;

            m_SubDirectories = newDirectories;

            return dir;
        }
Пример #9
0
 internal void RaiseReceivedDirListing(Node node, RemoteDirectory directory)
 {
     if (ReceivedDirListing != null)
         ReceivedDirListing(this, node, directory);
 }