You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by di...@apache.org on 2011/05/03 21:45:21 UTC
[Lucene.Net] svn commit: r1099214 - in
/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core:
Lucene.Net.Test.csproj PartiallyTrustedAppDomain.cs
Author: digy
Date: Tue May 3 19:45:21 2011
New Revision: 1099214
URL: http://svn.apache.org/viewvc?rev=1099214&view=rev
Log:
[LUCENENET-412] Test Env. for medium-trust
Added:
incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/PartiallyTrustedAppDomain.cs
Modified:
incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Lucene.Net.Test.csproj
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Lucene.Net.Test.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Lucene.Net.Test.csproj?rev=1099214&r1=1099213&r2=1099214&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Lucene.Net.Test.csproj (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Lucene.Net.Test.csproj Tue May 3 19:45:21 2011
@@ -288,6 +288,7 @@
</Compile>
<Compile Include="Messages\MessagesTestBundle.cs" />
<Compile Include="Messages\TestNLS.cs" />
+ <Compile Include="PartiallyTrustedAppDomain.cs" />
<Compile Include="QueryParser\TestMultiAnalyzer.cs">
<SubType>Code</SubType>
</Compile>
Added: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/PartiallyTrustedAppDomain.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/PartiallyTrustedAppDomain.cs?rev=1099214&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/PartiallyTrustedAppDomain.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/PartiallyTrustedAppDomain.cs Tue May 3 19:45:21 2011
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+using System;
+using System.IO;
+using System.Security;
+using System.Security.Permissions;
+using System.Security.Policy;
+
+using System.Reflection;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Lucene.Net.Test
+{
+ public class PartiallyTrustedAppDomain
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="clazz">class to create</param>
+ /// <param name="methodName">method to invoke</param>
+ /// <param name="constructorArgs">constructor's parameters</param>
+ /// <param name="methodArgs">method's parameters</param>
+ public static void Run(Type clazz, string methodName, object[] constructorArgs, object[] methodArgs)
+ {
+ try
+ {
+ AppDomainSetup setup = new AppDomainSetup { ApplicationBase = Environment.CurrentDirectory };
+
+ PermissionSet permissions = new PermissionSet(null);
+ permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
+ permissions.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess));
+
+ AppDomain appDomain = AppDomain.CreateDomain("PartiallyTrustedAppDomain", null, setup, permissions);
+
+ object p = appDomain.CreateInstanceAndUnwrap(
+ clazz.Assembly.FullName,
+ clazz.FullName,
+ false,
+ BindingFlags.CreateInstance,
+ null,
+ constructorArgs,
+ System.Globalization.CultureInfo.CurrentCulture,
+ null);
+ p.GetType().InvokeMember(methodName, BindingFlags.InvokeMethod, null, p, methodArgs);
+ }
+ catch (TypeLoadException tlex)
+ {
+ throw tlex;
+ }
+ catch (TargetInvocationException tiex)
+ {
+ throw tiex.InnerException;
+ }
+ catch (SecurityException secex)
+ {
+ throw secex;
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+ }
+ }
+}
+