GetNetwork() public static method

public static GetNetwork ( string path ) : Network
path string
return Network
Example #1
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);
            }
        }
Example #2
0
        public bool BeginGetFileDetails(string path, FileCallback callback)
        {
            path = PathUtil.CleanPath(path);

            IFile file = GetFile(path);

            if (file != null)
            {
                callback(file);
                return(true);
            }

            // If file is local and wasn't found, throw error.
            string[] parts = path.Split('/');
            if (parts.Length > 1 && parts[1] == "local")
            {
                throw new Exception("File does not exist");
            }

            // If remote file, request it!

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

            var network = PathUtil.GetNetwork(path);

            network.RequestFileDetails(path);
            return(false);
        }