예제 #1
0
 private static void Demand(IsolatedStorageScope scope)
 {
     if (SecurityManager.SecurityEnabled)
     {
         IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission(PermissionState.None);
         isfp.UsageAllowed = ScopeToContainment(scope);
         isfp.Demand();
     }
 }
            private void EnsureQuota(long size)
            {
                IsolatedStoragePermission storagePerm = new IsolatedStorageFilePermission(PermissionState.None);

                storagePerm.UserQuota    = size;
                storagePerm.UsageAllowed = _isRoaming? IsolatedStorageContainment.DomainIsolationByRoamingUser :
                                           IsolatedStorageContainment.DomainIsolationByUser;
                storagePerm.Demand();
            }
        public void IndividualMethod()
        {
            ReflectionPermission rp = new ReflectionPermission(ReflectionPermissionFlag.AllFlags);

            rp.Demand();
            IsolatedStorageFilePermission isp = new IsolatedStorageFilePermission(PermissionState.Unrestricted);

            isp.Demand();
        }
예제 #4
0
        private static void DemandAdminPermission()
        {
            // Ok if more than one instance is created, no need to sync.
            if (s_PermAdminUser == null)
            {
                s_PermAdminUser = new IsolatedStorageFilePermission(
                    IsolatedStorageContainment.AdministerIsolatedStorageByUser,
                    0, false);
            }

            s_PermAdminUser.Demand();
        }
예제 #5
0
파일: quota.cs 프로젝트: nobled/mono
	static void Main (string[] args) 
	{
		long quota = 0;
		if (args.Length > 0)
			quota = Convert.ToInt64 (args [0]);

		IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None);
		isfp.UserQuota = quota;
		try {
			isfp.Demand ();
			Console.WriteLine ("Quota accepted for {0}.", quota);
		}
		catch (SecurityException se) {
			Console.WriteLine ("Quota refused for {0}\n{1}", quota, se);
		}
		catch (Exception e) {
			Console.WriteLine ("Error checking quota for {0}\n{1}", quota, e);
		}
	}
예제 #6
0
    static void Main(string[] args)
    {
        long quota = 0;

        if (args.Length > 0)
        {
            quota = Convert.ToInt64(args [0]);
        }

        IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission(PermissionState.None);

        isfp.UserQuota = quota;
        try {
            isfp.Demand();
            Console.WriteLine("Quota accepted for {0}.", quota);
        }
        catch (SecurityException se) {
            Console.WriteLine("Quota refused for {0}\n{1}", quota, se);
        }
        catch (Exception e) {
            Console.WriteLine("Error checking quota for {0}\n{1}", quota, e);
        }
    }
예제 #7
0
        private static void DemandPermission(IsolatedStorageScope scope)
        {
            IsolatedStorageFilePermission ip = null;

            // Ok to create more than one instnace of s_PermXXX, the last one
            // will be shared. No need to synchronize.

            // First check for permissions

            switch (scope)
            {
            case c_App:

                if (s_PermApp == null)
                {
                    s_PermApp = new IsolatedStorageFilePermission(
                        IsolatedStorageContainment.DomainIsolationByUser,
                        0, false);
                }
                ip = s_PermApp;
                break;

            case c_Assembly:
                if (s_PermAssem == null)
                {
                    s_PermAssem = new IsolatedStorageFilePermission(
                        IsolatedStorageContainment.AssemblyIsolationByUser,
                        0, false);
                }
                ip = s_PermAssem;
                break;

            case c_AppRoaming:
                if (s_PermAppRoaming == null)
                {
                    s_PermAppRoaming = new IsolatedStorageFilePermission(
                        IsolatedStorageContainment.DomainIsolationByRoamingUser,
                        0, false);
                }
                ip = s_PermAppRoaming;
                break;

            case c_AssemblyRoaming:
                if (s_PermAssemRoaming == null)
                {
                    s_PermAssemRoaming = new IsolatedStorageFilePermission(
                        IsolatedStorageContainment.AssemblyIsolationByRoamingUser,
                        0, false);
                }
                ip = s_PermAssemRoaming;
                break;

#if _DEBUG
            default:
                BCLDebug.Assert(false, "Invalid scope");
                break;
#endif
            }

            ip.Demand();
        }
예제 #8
0
        private static void DemandPermission(IsolatedStorageScope scope)
        {
            IsolatedStorageFilePermission storageFilePermission = (IsolatedStorageFilePermission)null;

            if (scope <= (IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly | IsolatedStorageScope.Roaming))
            {
                if (scope <= (IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly))
                {
                    if (scope != (IsolatedStorageScope.User | IsolatedStorageScope.Assembly))
                    {
                        if (scope == (IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly))
                        {
                            if (System.IO.IsolatedStorage.IsolatedStorage.s_PermDomain == null)
                            {
                                System.IO.IsolatedStorage.IsolatedStorage.s_PermDomain = new IsolatedStorageFilePermission(IsolatedStorageContainment.DomainIsolationByUser, 0L, false);
                            }
                            storageFilePermission = System.IO.IsolatedStorage.IsolatedStorage.s_PermDomain;
                        }
                    }
                    else
                    {
                        if (System.IO.IsolatedStorage.IsolatedStorage.s_PermAssem == null)
                        {
                            System.IO.IsolatedStorage.IsolatedStorage.s_PermAssem = new IsolatedStorageFilePermission(IsolatedStorageContainment.AssemblyIsolationByUser, 0L, false);
                        }
                        storageFilePermission = System.IO.IsolatedStorage.IsolatedStorage.s_PermAssem;
                    }
                }
                else if (scope != (IsolatedStorageScope.User | IsolatedStorageScope.Assembly | IsolatedStorageScope.Roaming))
                {
                    if (scope == (IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly | IsolatedStorageScope.Roaming))
                    {
                        if (System.IO.IsolatedStorage.IsolatedStorage.s_PermDomainRoaming == null)
                        {
                            System.IO.IsolatedStorage.IsolatedStorage.s_PermDomainRoaming = new IsolatedStorageFilePermission(IsolatedStorageContainment.DomainIsolationByRoamingUser, 0L, false);
                        }
                        storageFilePermission = System.IO.IsolatedStorage.IsolatedStorage.s_PermDomainRoaming;
                    }
                }
                else
                {
                    if (System.IO.IsolatedStorage.IsolatedStorage.s_PermAssemRoaming == null)
                    {
                        System.IO.IsolatedStorage.IsolatedStorage.s_PermAssemRoaming = new IsolatedStorageFilePermission(IsolatedStorageContainment.AssemblyIsolationByRoamingUser, 0L, false);
                    }
                    storageFilePermission = System.IO.IsolatedStorage.IsolatedStorage.s_PermAssemRoaming;
                }
            }
            else if (scope <= (IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly | IsolatedStorageScope.Machine))
            {
                if (scope != (IsolatedStorageScope.Assembly | IsolatedStorageScope.Machine))
                {
                    if (scope == (IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly | IsolatedStorageScope.Machine))
                    {
                        if (System.IO.IsolatedStorage.IsolatedStorage.s_PermMachineDomain == null)
                        {
                            System.IO.IsolatedStorage.IsolatedStorage.s_PermMachineDomain = new IsolatedStorageFilePermission(IsolatedStorageContainment.DomainIsolationByMachine, 0L, false);
                        }
                        storageFilePermission = System.IO.IsolatedStorage.IsolatedStorage.s_PermMachineDomain;
                    }
                }
                else
                {
                    if (System.IO.IsolatedStorage.IsolatedStorage.s_PermMachineAssem == null)
                    {
                        System.IO.IsolatedStorage.IsolatedStorage.s_PermMachineAssem = new IsolatedStorageFilePermission(IsolatedStorageContainment.AssemblyIsolationByMachine, 0L, false);
                    }
                    storageFilePermission = System.IO.IsolatedStorage.IsolatedStorage.s_PermMachineAssem;
                }
            }
            else if (scope != (IsolatedStorageScope.User | IsolatedStorageScope.Application))
            {
                if (scope != (IsolatedStorageScope.User | IsolatedStorageScope.Roaming | IsolatedStorageScope.Application))
                {
                    if (scope == (IsolatedStorageScope.Machine | IsolatedStorageScope.Application))
                    {
                        if (System.IO.IsolatedStorage.IsolatedStorage.s_PermAppMachine == null)
                        {
                            System.IO.IsolatedStorage.IsolatedStorage.s_PermAppMachine = new IsolatedStorageFilePermission(IsolatedStorageContainment.ApplicationIsolationByMachine, 0L, false);
                        }
                        storageFilePermission = System.IO.IsolatedStorage.IsolatedStorage.s_PermAppMachine;
                    }
                }
                else
                {
                    if (System.IO.IsolatedStorage.IsolatedStorage.s_PermAppUserRoaming == null)
                    {
                        System.IO.IsolatedStorage.IsolatedStorage.s_PermAppUserRoaming = new IsolatedStorageFilePermission(IsolatedStorageContainment.ApplicationIsolationByRoamingUser, 0L, false);
                    }
                    storageFilePermission = System.IO.IsolatedStorage.IsolatedStorage.s_PermAppUserRoaming;
                }
            }
            else
            {
                if (System.IO.IsolatedStorage.IsolatedStorage.s_PermAppUser == null)
                {
                    System.IO.IsolatedStorage.IsolatedStorage.s_PermAppUser = new IsolatedStorageFilePermission(IsolatedStorageContainment.ApplicationIsolationByUser, 0L, false);
                }
                storageFilePermission = System.IO.IsolatedStorage.IsolatedStorage.s_PermAppUser;
            }
            storageFilePermission.Demand();
        }
        private static void DemandPermission(IsolatedStorageScope scope)
        {
            IsolatedStorageFilePermission permission = null;

            switch (scope)
            {
            case (IsolatedStorageScope.Assembly | IsolatedStorageScope.User):
                if (s_PermAssem == null)
                {
                    s_PermAssem = new IsolatedStorageFilePermission(IsolatedStorageContainment.AssemblyIsolationByUser, 0L, false);
                }
                permission = s_PermAssem;
                break;

            case (IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain | IsolatedStorageScope.User):
                if (s_PermDomain == null)
                {
                    s_PermDomain = new IsolatedStorageFilePermission(IsolatedStorageContainment.DomainIsolationByUser, 0L, false);
                }
                permission = s_PermDomain;
                break;

            case (IsolatedStorageScope.Roaming | IsolatedStorageScope.Assembly | IsolatedStorageScope.User):
                if (s_PermAssemRoaming == null)
                {
                    s_PermAssemRoaming = new IsolatedStorageFilePermission(IsolatedStorageContainment.AssemblyIsolationByRoamingUser, 0L, false);
                }
                permission = s_PermAssemRoaming;
                break;

            case (IsolatedStorageScope.Roaming | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain | IsolatedStorageScope.User):
                if (s_PermDomainRoaming == null)
                {
                    s_PermDomainRoaming = new IsolatedStorageFilePermission(IsolatedStorageContainment.DomainIsolationByRoamingUser, 0L, false);
                }
                permission = s_PermDomainRoaming;
                break;

            case (IsolatedStorageScope.Machine | IsolatedStorageScope.Assembly):
                if (s_PermMachineAssem == null)
                {
                    s_PermMachineAssem = new IsolatedStorageFilePermission(IsolatedStorageContainment.AssemblyIsolationByMachine, 0L, false);
                }
                permission = s_PermMachineAssem;
                break;

            case (IsolatedStorageScope.Machine | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain):
                if (s_PermMachineDomain == null)
                {
                    s_PermMachineDomain = new IsolatedStorageFilePermission(IsolatedStorageContainment.DomainIsolationByMachine, 0L, false);
                }
                permission = s_PermMachineDomain;
                break;

            case (IsolatedStorageScope.Application | IsolatedStorageScope.User):
                if (s_PermAppUser == null)
                {
                    s_PermAppUser = new IsolatedStorageFilePermission(IsolatedStorageContainment.ApplicationIsolationByUser, 0L, false);
                }
                permission = s_PermAppUser;
                break;

            case (IsolatedStorageScope.Application | IsolatedStorageScope.Roaming | IsolatedStorageScope.User):
                if (s_PermAppUserRoaming == null)
                {
                    s_PermAppUserRoaming = new IsolatedStorageFilePermission(IsolatedStorageContainment.ApplicationIsolationByRoamingUser, 0L, false);
                }
                permission = s_PermAppUserRoaming;
                break;

            case (IsolatedStorageScope.Application | IsolatedStorageScope.Machine):
                if (s_PermAppMachine == null)
                {
                    s_PermAppMachine = new IsolatedStorageFilePermission(IsolatedStorageContainment.ApplicationIsolationByMachine, 0L, false);
                }
                permission = s_PermAppMachine;
                break;
            }
            permission.Demand();
        }