AddPathList() public method

public AddPathList ( EnvironmentPermissionAccess flag, string pathList ) : void
flag EnvironmentPermissionAccess
pathList string
return void
コード例 #1
0
        /// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
        /// <param name="other">A permission to combine with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="other" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override IPermission Union(IPermission other)
        {
            EnvironmentPermission environmentPermission = this.Cast(other);

            if (environmentPermission == null)
            {
                return(this.Copy());
            }
            if (this.IsUnrestricted() || environmentPermission.IsUnrestricted())
            {
                return(new EnvironmentPermission(PermissionState.Unrestricted));
            }
            if (this.IsEmpty() && environmentPermission.IsEmpty())
            {
                return(null);
            }
            EnvironmentPermission environmentPermission2 = (EnvironmentPermission)this.Copy();
            string pathList = environmentPermission.GetPathList(EnvironmentPermissionAccess.Read);

            if (pathList != null)
            {
                environmentPermission2.AddPathList(EnvironmentPermissionAccess.Read, pathList);
            }
            pathList = environmentPermission.GetPathList(EnvironmentPermissionAccess.Write);
            if (pathList != null)
            {
                environmentPermission2.AddPathList(EnvironmentPermissionAccess.Write, pathList);
            }
            return(environmentPermission2);
        }
コード例 #2
0
        // Methods
        public override IPermission CreatePermission()
        {
#if NET_2_1
            return(null);
#else
            EnvironmentPermission perm = null;
            if (this.Unrestricted)
            {
                perm = new EnvironmentPermission(PermissionState.Unrestricted);
            }
            else
            {
                perm = new EnvironmentPermission(PermissionState.None);
                if (read != null)
                {
                    perm.AddPathList(EnvironmentPermissionAccess.Read, read);
                }
                if (write != null)
                {
                    perm.AddPathList(EnvironmentPermissionAccess.Write, write);
                }
            }
            return(perm);
#endif
        }
コード例 #3
0
        public override IPermission Union(IPermission other)
        {
            EnvironmentPermission ep = Cast(other);

            if (ep == null)
            {
                return(Copy());
            }

            if (IsUnrestricted() || ep.IsUnrestricted())
            {
                return(new EnvironmentPermission(PermissionState.Unrestricted));
            }

            if (IsEmpty() && ep.IsEmpty())
            {
                return(null);
            }

            EnvironmentPermission result = (EnvironmentPermission)Copy();
            string path = ep.GetPathList(EnvironmentPermissionAccess.Read);

            if (path != null)
            {
                result.AddPathList(EnvironmentPermissionAccess.Read, path);
            }
            path = ep.GetPathList(EnvironmentPermissionAccess.Write);
            if (path != null)
            {
                result.AddPathList(EnvironmentPermissionAccess.Write, path);
            }
            return(result);
        }
コード例 #4
0
        /// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns>
        /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override IPermission Intersect(IPermission target)
        {
            EnvironmentPermission environmentPermission = this.Cast(target);

            if (environmentPermission == null)
            {
                return(null);
            }
            if (this.IsUnrestricted())
            {
                return(environmentPermission.Copy());
            }
            if (environmentPermission.IsUnrestricted())
            {
                return(this.Copy());
            }
            int num = 0;
            EnvironmentPermission environmentPermission2 = new EnvironmentPermission(PermissionState.None);
            string pathList = environmentPermission.GetPathList(EnvironmentPermissionAccess.Read);

            if (pathList != null)
            {
                string[] array = pathList.Split(new char[]
                {
                    ';'
                });
                foreach (string text in array)
                {
                    if (this.readList.Contains(text))
                    {
                        environmentPermission2.AddPathList(EnvironmentPermissionAccess.Read, text);
                        num++;
                    }
                }
            }
            string pathList2 = environmentPermission.GetPathList(EnvironmentPermissionAccess.Write);

            if (pathList2 != null)
            {
                string[] array3 = pathList2.Split(new char[]
                {
                    ';'
                });
                foreach (string text2 in array3)
                {
                    if (this.writeList.Contains(text2))
                    {
                        environmentPermission2.AddPathList(EnvironmentPermissionAccess.Write, text2);
                        num++;
                    }
                }
            }
            return((num <= 0) ? null : environmentPermission2);
        }
コード例 #5
0
        public override IPermission Intersect(IPermission target)
        {
            EnvironmentPermission ep = Cast(target);

            if (ep == null)
            {
                return(null);
            }

            if (IsUnrestricted())
            {
                return(ep.Copy());
            }
            if (ep.IsUnrestricted())
            {
                return(Copy());
            }

            int n = 0;
            EnvironmentPermission result = new EnvironmentPermission(PermissionState.None);
            string readTarget            = ep.GetPathList(EnvironmentPermissionAccess.Read);

            if (readTarget != null)
            {
                string[] targets = readTarget.Split(';');
                foreach (string t in targets)
                {
                    if (readList.Contains(t))
                    {
                        result.AddPathList(EnvironmentPermissionAccess.Read, t);
                        n++;
                    }
                }
            }

            string writeTarget = ep.GetPathList(EnvironmentPermissionAccess.Write);

            if (writeTarget != null)
            {
                string[] targets = writeTarget.Split(';');
                foreach (string t in targets)
                {
                    if (writeList.Contains(t))
                    {
                        result.AddPathList(EnvironmentPermissionAccess.Write, t);
                        n++;
                    }
                }
            }
            return((n > 0) ? result : null);
        }
コード例 #6
0
		// Methods
		public override IPermission CreatePermission ()
		{
#if NET_2_1
			return null;
#else
			EnvironmentPermission perm = null;
			if (this.Unrestricted)
				perm = new EnvironmentPermission (PermissionState.Unrestricted);
			else {
				perm = new EnvironmentPermission (PermissionState.None);
				if (read != null)
					perm.AddPathList (EnvironmentPermissionAccess.Read, read);
				if (write != null)
					perm.AddPathList (EnvironmentPermissionAccess.Write, write);
			}
			return perm;
#endif
		}
コード例 #7
0
		public override IPermission Intersect (IPermission target)
		{
			EnvironmentPermission ep = Cast (target);
			if (ep == null)
				return null;

			if (IsUnrestricted ())
				return ep.Copy ();
			if (ep.IsUnrestricted ())
				return Copy ();

			int n = 0;
			EnvironmentPermission result = new EnvironmentPermission (PermissionState.None);
			string readTarget = ep.GetPathList (EnvironmentPermissionAccess.Read);
			if (readTarget != null) {
				string[] targets = readTarget.Split (';');
				foreach (string t in targets) {
					if (readList.Contains (t)) {
						result.AddPathList (EnvironmentPermissionAccess.Read, t);
						n++;
					}
				}
			}

			string writeTarget = ep.GetPathList (EnvironmentPermissionAccess.Write);
			if (writeTarget != null) {
				string[] targets = writeTarget.Split (';');
				foreach (string t in targets) {
					if (writeList.Contains (t)) {
						result.AddPathList (EnvironmentPermissionAccess.Write, t);
						n++;
					}
				}
			}
			return ((n > 0) ? result : null);
		}
コード例 #8
0
		public void GetPathList () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
#if NET_2_0
			AssertEquals ("GetPathList-Read-Empty", String.Empty, ep.GetPathList (EnvironmentPermissionAccess.Read));
			AssertEquals ("GetPathList-Write-Empty", String.Empty, ep.GetPathList (EnvironmentPermissionAccess.Write));
#else
			AssertNull ("GetPathList-Read-Empty", ep.GetPathList (EnvironmentPermissionAccess.Read));
			AssertNull ("GetPathList-Write-Empty", ep.GetPathList (EnvironmentPermissionAccess.Write));
#endif
			ep.AddPathList (EnvironmentPermissionAccess.Read, "UID");
			ep.AddPathList (EnvironmentPermissionAccess.Write, "PROMPT");
			AssertEquals ("GetPathList-Read", "UID", ep.GetPathList (EnvironmentPermissionAccess.Read));
			AssertEquals ("GetPathList-Write", "PROMPT", ep.GetPathList (EnvironmentPermissionAccess.Write));
		}
コード例 #9
0
		public void GetPathListNoAccess () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
			ep.AddPathList (EnvironmentPermissionAccess.Read, "UID");
			ep.AddPathList (EnvironmentPermissionAccess.Write, "PROMPT");
			AssertEquals ("GetPathList-NoAccess", "", ep.GetPathList (EnvironmentPermissionAccess.NoAccess));
		}
コード例 #10
0
		public void AddPathList () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
			ep.AddPathList (EnvironmentPermissionAccess.AllAccess, envVariables);
			// LAMESPEC NoAccess do not remove the TMP from AllAccess
			ep.AddPathList (EnvironmentPermissionAccess.NoAccess, "TMP");
			ep.AddPathList (EnvironmentPermissionAccess.Read, "UID");
			ep.AddPathList (EnvironmentPermissionAccess.Write, "PROMPT");
			SecurityElement se = ep.ToXml ();
			// Note: Debugger can mess results (try to run without stepping)
			AssertEquals ("AddPathList-ToXml-Read", "TMP;TEMP;UID", (se.Attributes ["Read"] as string));
			AssertEquals ("AddPathList-ToXml-Write", "TMP;TEMP;PROMPT", (se.Attributes ["Write"] as string));
		}
コード例 #11
0
		public void GetPathListAllAccess () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
			ep.AddPathList (EnvironmentPermissionAccess.Read, "UID");
			ep.AddPathList (EnvironmentPermissionAccess.Write, "PROMPT");
			Assert.AreEqual ("", ep.GetPathList (EnvironmentPermissionAccess.AllAccess), "GetPathList-AllAccess");
		}
コード例 #12
0
 protected override IStackWalk CreateStackWalk()
 {
     EnvironmentPermission permission = new EnvironmentPermission(PermissionState.Unrestricted);
     permission.AddPathList(attribute.Flag, attribute.PathList);
     return permission;
 }
コード例 #13
0
		public void GetPathList () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
			Assert.AreEqual (String.Empty, ep.GetPathList (EnvironmentPermissionAccess.Read), "GetPathList-Read-Empty");
			Assert.AreEqual (String.Empty, ep.GetPathList (EnvironmentPermissionAccess.Write), "GetPathList-Write-Empty");
			ep.AddPathList (EnvironmentPermissionAccess.Read, "UID");
			ep.AddPathList (EnvironmentPermissionAccess.Write, "PROMPT");
			Assert.AreEqual ("UID", ep.GetPathList (EnvironmentPermissionAccess.Read), "GetPathList-Read");
			Assert.AreEqual ("PROMPT", ep.GetPathList (EnvironmentPermissionAccess.Write), "GetPathList-Write");
		}