Exemplo n.º 1
0
        private void FileSystemWatcher_Renamed(object sender, RenamedEventArgs e)
        {
            if (ActivityEvent != null)
            {
                NodeType nodeType;

                if (!e.FullPath.StartsWith(((LocalNodeAddress)this.RootAddress).AbsoluteNativePath))
                {
                    return;
                }

                nodeType = (sender == this.fileSystemWatcherFile) ? NodeType.File : NodeType.Directory;

                OnActivityEvent(new FileSystemRenamedActivityEventArgs(FileSystemActivity.Renamed,
                                                                       nodeType,
                                                                       Path.GetFileName(e.OldName),
                                                                       StringUriUtils.NormalizePath(
                                                                           e.OldFullPath.Substring(
                                                                               this.fileSystemWatcherFile.Path.Length - 1)),
                                                                       Path.GetFileName(e.Name),
                                                                       StringUriUtils.NormalizePath(
                                                                           e.FullPath.Substring(
                                                                               ((LocalNodeAddress)this.RootAddress).AbsoluteNativePath.
                                                                               Length - 1))));
            }
        }
        public virtual INodeAddress ResolveAddress(string name, AddressScope scope)
        {
            int x;
            var query = "";

            if (name.Length == 0 || (name.Length > 0 && name[0] != FileSystemManager.RootChar))
            {
                // Path is relative.

                if (this.IsRoot)
                {
                    name = FileSystemManager.RootChar + name;
                }
                else
                {
                    name = this.absolutePath + FileSystemManager.SeperatorChar + name;
                }
            }

            if ((x = name.IndexOf('?')) >= 0)
            {
                query = name.Substring(x + 1);
                name  = name.Substring(0, x);
            }

            name = StringUriUtils.NormalizePath(name);

            if (!CheckPathScope(this.AbsolutePath, name, scope))
            {
                throw new AddressScopeValidationException(name, scope);
            }

            return(CreateAddress(name, query));
        }
Exemplo n.º 3
0
        private void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            if (ActivityEvent != null)
            {
                NodeType nodeType;

                if (!e.FullPath.StartsWith(((LocalNodeAddress)this.RootAddress).AbsoluteNativePath))
                {
                    return;
                }

                /*
                 * There is a race here between when the watcher sees the event and when it is processed
                 * which may mean that a changed event meant for a dir goes to a file (or vice versa).
                 * There's nothing we can do about it but since the Changed event is pretty opaque
                 * (users will have to figure what has changed anyway) it doesn't matter too much.
                 */

                nodeType = GetNodeType(e.FullPath.Substring(((LocalNodeAddress)this.RootAddress).AbsoluteNativePath.Length - 1));

                if (nodeType == NodeType.None)
                {
                    OnActivityEvent(new FileSystemActivityEventArgs(FileSystemActivity.Changed, NodeType.File, e.Name,
                                                                    StringUriUtils.NormalizePath(
                                                                        e.FullPath.Substring(
                                                                            ((LocalNodeAddress)this.RootAddress).AbsoluteNativePath.Length -
                                                                            1))));

                    OnActivityEvent(new FileSystemActivityEventArgs(FileSystemActivity.Changed, NodeType.Directory, e.Name,
                                                                    StringUriUtils.NormalizePath(
                                                                        e.FullPath.Substring(
                                                                            ((LocalNodeAddress)this.RootAddress).AbsoluteNativePath.Length -
                                                                            1))));

                    return;
                }
                else
                {
                    OnActivityEvent(new FileSystemActivityEventArgs(FileSystemActivity.Changed, nodeType, e.Name,
                                                                    StringUriUtils.NormalizePath(
                                                                        e.FullPath.Substring(
                                                                            ((LocalNodeAddress)this.RootAddress).AbsoluteNativePath.Length -
                                                                            1))));
                }
            }
        }
        public static LocalNodeAddress Parse(string uri)
        {
            Group  group;
            Match  match = null;
            string root, scheme, query;

            // Often Parse will be called with the exact same URI reference that was last passed
            // to CanParse.  If this is the case then use the results cached by the last call to
            // CanParse from this thread.

            if ((object)uri == (object)lastCanParseUri)
            {
                match = lastCanParseMatch;
            }

            while (true)
            {
                if (match == null)
                {
                    match = localFileNameRegEx.Match(uri);
                }

                if (!match.Success)
                {
                    throw new MalformedUriException(uri);
                }

                bool schemeExplicitlyProvided;

                group = match.Groups["scheme"];

                if (group.Value == "")
                {
                    scheme = "file";
                    schemeExplicitlyProvided = false;
                }
                else
                {
                    scheme = group.Value;
                    schemeExplicitlyProvided = true;
                }

                group = match.Groups["uncserver"];

                if (group.Success)
                {
                    string path;
                    Pair <string, string> result;

                    path = match.Groups["path1"].Value;

                    result = path.SplitAroundCharFromLeft(1, PredicateUtils.ObjectEqualsAny('\\', '/'));

                    root = "//" + group.Value + result.Left.Replace('\\', '/');
                    path = "/" + result.Right;

                    if (path == "")
                    {
                        path = "/";
                    }

                    query = match.Groups["query"].Value;

                    return(new LocalNodeAddress(scheme, root, true, StringUriUtils.NormalizePath(path), query));
                }
                else
                {
                    string path;

                    group = match.Groups["root"];

                    if (group.Captures.Count > 0)
                    {
                        //
                        // Windows path specification
                        //

                        root = group.Value;

                        path = match.Groups["path2"].Value;

                        if (path.Length == 0)
                        {
                            path = FileSystemManager.SeperatorString;
                        }

                        query = match.Groups["query"].Value;

                        path = StringUriUtils.NormalizePath(path);

                        if (schemeExplicitlyProvided)
                        {
                            //
                            // Explicitly provided scheme means
                            // special characters are hexcoded
                            //

                            path  = TextConversion.FromEscapedHexString(path);
                            query = TextConversion.FromEscapedHexString(query);
                        }

                        return(new LocalNodeAddress(scheme, root, true, path, query));
                    }
                    else if (match.Groups["path3"].Value != "")
                    {
                        //
                        // Unix path specification
                        //

                        path  = match.Groups["path3"].Value;
                        query = match.Groups["query"].Value;

                        path = StringUriUtils.NormalizePath(path);

                        if (schemeExplicitlyProvided)
                        {
                            //
                            // Explicitly provided scheme means
                            // special characters are hexcoded
                            //

                            path  = TextConversion.FromEscapedHexString(path);
                            query = TextConversion.FromEscapedHexString(query);
                        }

                        return(new LocalNodeAddress(scheme, "", true, path, query));
                    }
                    else
                    {
                        //
                        // Relative path specification
                        //

                        path  = match.Groups["path4"].Value;
                        query = match.Groups["query"].Value;

                        path = StringUriUtils.Combine(Environment.CurrentDirectory, path);
                        path = StringUriUtils.NormalizePath(path);

                        if (!string.IsNullOrEmpty(query))
                        {
                            query = "?" + query;
                        }
                        else
                        {
                            query = "";
                        }

                        if (schemeExplicitlyProvided)
                        {
                            uri = scheme + "://" + path + "query";
                        }
                        else
                        {
                            uri = path + query;
                        }

                        match = null;
                    }
                }
            }
        }