当前位置: 首页>>代码示例>>C#>>正文


C# AppDomain.SetAppDomainPolicy方法代码示例

本文整理汇总了C#中System.AppDomain.SetAppDomainPolicy方法的典型用法代码示例。如果您正苦于以下问题:C# AppDomain.SetAppDomainPolicy方法的具体用法?C# AppDomain.SetAppDomainPolicy怎么用?C# AppDomain.SetAppDomainPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.AppDomain的用法示例。


在下文中一共展示了AppDomain.SetAppDomainPolicy方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartInAppDomain

        /// <summary>
        /// Start the script up in its own application domain.
        /// </summary>
        /// <returns>True if the script was started successfully.</returns>
        private bool StartInAppDomain()
        {
            m_appDomain = AppDomain.CreateDomain(Name, null, m_domainSetup);
            if (m_policy != null)
                m_appDomain.SetAppDomainPolicy(m_policy);

            Root.Unloader unloader = new Root.Unloader(this);
            unloader.UnloadRequest += (message) => new Thread(() => {
                ErrorString = message;
                NotifyProblem("Problem while running " + Name + ".");
                Stop();
            }).Start();

            Type rootT = typeof(Root);
            m_root = (Root)m_appDomain.CreateInstanceAndUnwrap(rootT.Assembly.FullName, rootT.FullName);
            string outcome = m_root.Start(m_assembly, m_class, m_host, m_world, ID, Name, unloader, m_args);
            if (outcome != null) {
                KillAppDomain();
                ErrorString = outcome;
                Console.WriteLine("Problem. Outcome = " + outcome);
                return false;
            }
            return true;
        }
开发者ID:sanyaade-research-hub,项目名称:XMRM,代码行数:28,代码来源:Script.cs

示例2: SetAppDomainPolicy_Unloaded

		public void SetAppDomainPolicy_Unloaded ()
		{
			ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Unloaded");
			AppDomain.Unload (ad);
			ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:6,代码来源:AppDomainTest.cs

示例3: SetSecurityPolicy

        /// <summary>
        /// Deliver full trust unto the Application Domain.
        /// </summary>
        /// <param name="ad">The application Domain to apply the security level to.</param>
        public static void SetSecurityPolicy(AppDomain ad)
        {
            PolicyLevel pLevel = PolicyLevel.CreateAppDomainLevel();
            PermissionSet ps = new PermissionSet( PermissionState.Unrestricted );
            UnionCodeGroup rootCodeGroup = new UnionCodeGroup( new AllMembershipCondition(),
                new PolicyStatement( ps, PolicyStatementAttribute.Nothing ) );

            pLevel.RootCodeGroup = rootCodeGroup;
            ad.SetAppDomainPolicy( pLevel );
        }
开发者ID:aarondl,项目名称:Project-2Q,代码行数:14,代码来源:IModule.cs

示例4: SetAppDomainPolicy_Dual

		public void SetAppDomainPolicy_Dual ()
		{
			ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Dual");
			PolicyLevel pl = PolicyLevel.CreateAppDomainLevel ();
			PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
			pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
			ad.SetAppDomainPolicy (pl);

			// only one time!
			pl = PolicyLevel.CreateAppDomainLevel ();
			ps = new PermissionSet (PermissionState.None);
			pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
			ad.SetAppDomainPolicy (pl);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:14,代码来源:AppDomainTest.cs

示例5: SetAppDomainPolicy_Null

		public void SetAppDomainPolicy_Null ()
		{
			ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
			ad.SetAppDomainPolicy (null);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:5,代码来源:AppDomainTest.cs

示例6: SetAppDomainPolicy

		public void SetAppDomainPolicy ()
		{
			ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
			ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
			// not much to see
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:6,代码来源:AppDomainTest.cs

示例7: initialize_GridThreadExecutor

        //-----------------------------------------------------------------------------------------------
        // private methods
        //-----------------------------------------------------------------------------------------------
        /// <summary>
        /// Written by Abhishek Kumar on March 05, 2007
        /// purpose: to initiate the central Application Domain that
        /// all Grid Threads will be run on.
        /// 
        /// Police and permissions will also be set.
        /// ADV: a crash in this App Domain(because of poor code in GThread)
        /// does not affect eduGRID's Framework i.e. the Alchemi executor is maintained steady even in error
        /// 
        /// initially Alchemi created separate app domains for each Gthread it received.
        /// now, instead, we create 1 appdomain and run all gthreads on it
        /// the Bot Logic resides in this app domain.
        /// (this saves the overhead of initializing bot logic for every Gthread (or every query))
        /// </summary>
        private void initialize_GridThreadExecutor()
        {
            if (GridThreadExecutor == null)
            {
                string appDir = GetApplicationDirectory(_CurTi.ApplicationId);
                AppDomainSetup info = new AppDomainSetup();
                info.PrivateBinPath = appDir;
                GridThreadApplicationDomain = AppDomain.CreateDomain("Central_AppDomain", null, info);

                // ***
                // http://www.dotnetthis.com/Articles/DynamicSandboxing.htm
                PolicyLevel domainPolicy = PolicyLevel.CreateAppDomainLevel();
                AllMembershipCondition allCodeMC = new AllMembershipCondition();
                // TODO: 'FullTrust' in the following line needs to be replaced with something like 'AlchemiGridThread'
                //        This permission set needs to be defined and set automatically as part of the installation.
                PermissionSet internetPermissionSet = domainPolicy.GetNamedPermissionSet("FullTrust");
                PolicyStatement internetPolicyStatement = new PolicyStatement(internetPermissionSet);
                CodeGroup allCodeInternetCG = new UnionCodeGroup(allCodeMC, internetPolicyStatement);
                domainPolicy.RootCodeGroup = allCodeInternetCG;
                GridThreadApplicationDomain.SetAppDomainPolicy(domainPolicy);

                GridThreadExecutor = (AppDomainExecutor) GridThreadApplicationDomain.CreateInstanceFromAndUnwrap(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Alchemi.Executor.dll"), "Alchemi.Executor.AppDomainExecutor");
            }

            if (!GridThreadExecutor.Initialized)
            {
                try
                {
                    GridThreadExecutor.initialize();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error during initialization of GridThreadExecutor");
                }
            }
        }
开发者ID:abhishek-kumar,项目名称:AIGA,代码行数:53,代码来源:GExecutor.cs

示例8: StartInAppDomain

        /// <summary>
        /// Start the script up in its own application domain.
        /// </summary>
        /// <returns>True if the script was started successfully.</returns>
        private bool StartInAppDomain()
        {
            m_appDomain = AppDomain.CreateDomain(Name, null, m_domainSetup);
            if (m_policy != null)
                m_appDomain.SetAppDomainPolicy(m_policy);

            Root.Unloader unloader = new Root.Unloader(this);
            unloader.UnloadRequest += (message) => new Thread(() => {
                ErrorString = message;
                NotifyProblem("Problem while running " + Name + ".");
                Stop();
            }).Start();

            try {
                Type rootT = typeof(Root);
                m_log.Debug("[" + Type + "] Creating sandboxed script.");
                m_root = (Root)m_appDomain.CreateInstanceAndUnwrap(rootT.Assembly.FullName, rootT.FullName);
                m_log.Debug("[" + Type + "] Starting sandboxed script.");
                string outcome = m_root.Start(m_assembly, m_class, m_host, m_world, ID, Name, unloader, m_args);
                if (outcome != null) {
                    KillAppDomain();
                    ErrorString = outcome;
                    return false;
                }
                return true;
            } catch (Exception e) {
                KillAppDomain();
                ErrorString = "Unable to start MRM." + e.Message + "\n" + e.StackTrace;
                while (e.InnerException != null) {
                    e = e.InnerException;
                    ErrorString += "\n\nInner Exception: " + e.Message + "\n" + e.StackTrace;
                }
                return false;
            }
        }
开发者ID:JohnMcCaffery,项目名称:XMRM,代码行数:39,代码来源:Script.cs


注:本文中的System.AppDomain.SetAppDomainPolicy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。