コード例 #1
0
        /// <summary>
        /// Retrieves an asset from the provider. If the second parameter
        /// is true and the asset cannot be found, an AssetException is
        /// thrown. Otherwise, this function will return null if it cannot
        /// be found.
        /// </summary>
        public IAsset GetAsset(NodeRef path, bool exceptionIfMissing)
        {
            // Go through the assets
            foreach (IAssetProvider provider in providers)
            {
                try
                {
                    // We always throw an exception to handle the processing
                    return provider.GetAsset(path, true);
                }
                catch {}
            }

            // If we get this far, every asset threw an exception trying to
            // get the asset path.
            if (exceptionIfMissing)
            {
                throw new AssetException("Cannot find " +
                    path + " in " + providers.Count
                    + " providers");
            }
            else
            {
                return null;
            }
        }
コード例 #2
0
ファイル: AssemblyAsset.cs プロジェクト: DF-thangld/web_game
        /// <summary>
        /// Constructs an asset from the given assembly. If the resource
        /// does not exist, this throws an AssetException.
        /// </summary>
        public AssemblyAsset(AssemblyAssetProvider provider, NodeRef path)
        {
            // Save the fields
            this.provider = provider;
            this.path = path.ToString();

            if (provider.StripLeadingSlash)
                this.path = this.path.Substring(1);

            // Make sure it exists
            bool found = false;

            foreach (string name in provider.Assembly.GetManifestResourceNames())
            {
                if (name == this.path)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
                throw new AssetException("Cannot find resource '"
                    + path + "' from assembly '"
                    + provider.Assembly.FullName
                    + "'");
        }
コード例 #3
0
ファイル: AttributeTree.cs プロジェクト: DF-thangld/web_game
        /// <summary>
        /// Creates an empty AttributeTree object.
        /// </summary>
        public AttributeTree()
        {
            // Set our path
            path = new NodeRef("/");

            // Create our children
            children = new AttributeTreeCollection(this);
        }
コード例 #4
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void DoubleDot()
 {
     NodeRef nr = new NodeRef("/a/b/../c");
     Assert.AreEqual("/a/c", nr.Path);
 }
コード例 #5
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void Count2()
 {
     NodeRef nr = new NodeRef("/a");
     Assert.AreEqual(1, nr.Count);
 }
コード例 #6
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void ChildIndex()
 {
     NodeRef up = new NodeRef("/dir1/sub1");
     NodeRef c1 = up["sub2/sub3"];
     Assert.AreEqual("/dir1/sub1/sub2/sub3", c1.Path);
 }
コード例 #7
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void TestNodeCreateChild()
 {
     NodeRef up = new NodeRef("/dir1/sub1");
     NodeRef c1 = up.CreateChild("sub2");
     Assert.AreEqual("/dir1/sub1/sub2", c1.Path);
 }
コード例 #8
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void TestEscapedNone()
 {
     NodeRef nr = new NodeRef("/a/b/c");
     Assert.AreEqual("/a/b/c", nr.ToString(),
         "String comparison");
 }
コード例 #9
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void SubRef4()
 {
     NodeRef nr = new NodeRef("/this/is/a/path");
     NodeRef sr = new NodeRef("/not/a/path");
     Assert.AreEqual("/not/a/path", nr.GetSubRef(sr).Path);
 }
コード例 #10
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void Includes4()
 {
     NodeRef nr = new NodeRef("/this/is");
     NodeRef sr = new NodeRef("/this");
     Assert.AreEqual(false, nr.Includes(sr));
 }
コード例 #11
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void Includes2()
 {
     NodeRef nr = new NodeRef("/this/is");
     NodeRef sr = new NodeRef("/not/in/is/a/path");
     Assert.AreEqual(false, nr.Includes(sr));
 }
コード例 #12
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void Includes1()
 {
     NodeRef nr = new NodeRef("/this/is");
     NodeRef sr = new NodeRef("/this/is/a/path");
     Assert.AreEqual(true, nr.Includes(sr));
 }
コード例 #13
0
ファイル: NodeRef.cs プロジェクト: DF-thangld/web_game
        /// <summary>
        /// This parses the given path and builds up the internal
        /// representation into memory. This representation is used
        /// for path and additional processing.
        /// </summary>
        private void ParsePath(string path, NodeRef context)
        {
            // Perform some sanity checking on the path
            if (path == null)
                throw new InvalidPathException("Cannot create a node "
                    + "ref from a null");

            // Check for absolute path
            if (!path.StartsWith("/"))
            {
                // We don't have an absolute path, so check the context
                if (context == null)
                {
                    throw new NotAbsolutePathException("Cannot create "
                        + "absolute path from '"
                        + path
                        + "'");
                }

                // Construct the new path from this context
                path = context.Path + "/" + path;
            }

            // Save the original
            //string orig = path;

            // Start by escaping the escapes
            path = path.Replace("\\", "\\\\");

            // Normalize the path by adding a trailing "/" and reducing
            // double "//" into single ones. This is done with regexes to
            // make it easier and faster. We add the "/" to simplify our
            // regexes later; we will also remove it as the last bit.
            path += "/";
            path = findDoubleSlashRegex.Replace(path, "/");
            //Debug("Processing 1: {0}", path);

            // Normalize the invalid characters
            //Debug("Processing 2: {0}", path);

            // Normalize the "/./" and the "/../" references. Also remove
            // the "/../" stuff at the beginning, by just deleting it.
            path = findHereRegex.Replace(path, "/");
            path = findRefUpRegex.Replace(path, "/");
            path = findInvalidUpRegex.Replace(path, "/");
            //Debug("Processing: {0} => {1}", orig, path);

            // Finally, remove the leading and trailing slash that we put in.
            //Debug("Processing 1: {0} => {1}", orig, path);
            path = findTrailingSlashesRegex.Replace(path, "");
            path = findLeadingSlashesRegex.Replace(path, "").Trim();
            //Debug("Processing 2: {0} => {1}", orig, path);

            // We need to do is make sure the regex characters are not
            // allowed in the string. We do this by just replacing all
            // the important ones with escaped versions.
            regexable = "/" + path
                .Replace("+", "\\+")
                .Replace("(", "\\(")
                .Replace(")", "\\)")
                .Replace("[", "\\[")
                .Replace("]", "\\]")
                .Replace(".", "\\.")
                .Replace("*", "\\*")
                .Replace("?", "\\?");
            //Debug("Processing 3: {0}", path);

            // We now have a normalized path, without a leading or a
            // trailing slash. If this is a blank string (one with no
            // length), it means that the reference was "/". Otherwise, it
            // represents some sort of path that had at least one
            // element. We also save the entire string version because we
            // are both read-only and we make the assumption that memory can
            // handle it.
            if (path.Equals(""))
            {
                // This is an empty path, which means it was a "/" reference
                parts = new string [] {};
                pref = "/";
            }
            else
            {
                // Split it along the slash characters
                parts = path.Split('/');
                pref = "/" + path;
            }
        }
コード例 #14
0
ファイル: NodeRef.cs プロジェクト: DF-thangld/web_game
 /// <summary>
 /// Returns true if this path includes the given path. This means
 /// that given path is under or part of this node's path.
 /// </summary>
 public bool Includes(NodeRef path)
 {
     // We have a real easy way of finding this
     return Regex.IsMatch(path.ToString(), "^" + regexable);
 }
コード例 #15
0
ファイル: NodeRef.cs プロジェクト: DF-thangld/web_game
        /// <summary>
        /// Returns a NodeRef which has this node's path removed from the
        /// beginning. If the given reference is not included (as per the
        /// Includes), it will be returned completely.
        /// </summary>
        public NodeRef GetSubRef(NodeRef nodeRef)
        {
            // Check for includes
            if (!Includes(nodeRef))
                return nodeRef;

            // Remove the first part. There is an easy method because we are
            // so strict about paths. We use the root context in the case
            // where the leading / is removed.
            string path =
                Regex.Replace(nodeRef.Path, "^" + regexable, "");

            return new NodeRef(path, RootContext);
        }
コード例 #16
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void SubPluses()
 {
     NodeRef nr = new NodeRef("/Test +1/A");
     NodeRef nr2 = new NodeRef("/Test +1");
     NodeRef nr3 = nr2.GetSubRef(nr);
     Assert.AreEqual("/A", nr3.ToString());
 }
コード例 #17
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void SubRef2()
 {
     NodeRef nr = new NodeRef("/this/is");
     NodeRef sr = new NodeRef("/this/is");
     Assert.AreEqual("/", nr.GetSubRef(sr).Path);
 }
コード例 #18
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void InvalidDoubleDot2()
 {
     NodeRef nr = new NodeRef("/../..");
     Assert.AreEqual("/", nr.Path);
 }
コード例 #19
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void TestDoubleStarMatch()
 {
     NodeRef nr = new NodeRef("/a/b/c");
     Assert.IsTrue(nr.IsMatch("/**/c"));
 }
コード例 #20
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void LeadingDotSlash()
 {
     NodeRef context = new NodeRef("/");
     NodeRef nr = new NodeRef("./", context);
     Assert.AreEqual("/", nr.Path);
 }
コード例 #21
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void TestEscapedStar()
 {
     NodeRef nr = new NodeRef("/*/*/*");
     Assert.AreEqual("/*/*/*", nr.ToString(),
         "String comparison");
     Assert.IsTrue(nr.Includes(new NodeRef("/*/*/*/abb")),
         "nr.Includes");
 }
コード例 #22
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void Name()
 {
     NodeRef nr = new NodeRef("/a/b/c");
     Assert.AreEqual("c", nr.Name);
 }
コード例 #23
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void TestSingleStarMatch3()
 {
     NodeRef nr = new NodeRef("/a/b/c");
     Assert.IsFalse(nr.IsMatch("/*/*/*/c"));
 }
コード例 #24
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void ParentPath()
 {
     NodeRef up = new NodeRef("/dir1/sub1");
     string up1 = up.ParentPath;
     Assert.AreEqual("/dir1", up1);
 }
コード例 #25
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void Count1()
 {
     NodeRef nr = new NodeRef("/a/b/c");
     Assert.AreEqual(3, nr.Count);
 }
コード例 #26
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void ParentRef()
 {
     NodeRef up = new NodeRef("/dir1/sub1");
     NodeRef up1 = up.ParentRef;
     Assert.AreEqual("/dir1", up1.Path);
 }
コード例 #27
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void Count3()
 {
     NodeRef nr = new NodeRef("/");
     Assert.AreEqual(0, nr.Count);
 }
コード例 #28
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void ParsePluses()
 {
     NodeRef nr = new NodeRef("/Test/Test +1/Test +2");
     Assert.AreEqual("/Test/Test +1/Test +2", nr.ToString());
     Assert.AreEqual("Test +2", nr.Name);
 }
コード例 #29
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void DoubleDotTop()
 {
     NodeRef nr = new NodeRef("/a/..");
     Assert.AreEqual("/", nr.Path);
 }
コード例 #30
0
ファイル: NodeRefTest.cs プロジェクト: DF-thangld/web_game
 public void Simple()
 {
     NodeRef up = new NodeRef("/dir1/sub1");
     Assert.AreEqual("/dir1/sub1", up.Path);
 }