예제 #1
0
		public static void CompileToAssembly
			(RegexCompilationInfo[] regexes, AssemblyName aname,
			 CustomAttributeBuilder[] attribs, string resourceFile)
		{
			throw new NotImplementedException ();
			// TODO : Make use of attribs and resourceFile parameters
			/*
			AssemblyBuilder asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (aname, AssemblyBuilderAccess.RunAndSave);
			ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule("InnerRegexModule",aname.Name);
			Parser psr = new Parser ();	
			
			System.Console.WriteLine("CompileToAssembly");
			       
			for(int i=0; i < regexes.Length; i++)
				{
					System.Console.WriteLine("Compiling expression :" + regexes[i].Pattern);
					RegularExpression re = psr.ParseRegularExpression (regexes[i].Pattern, regexes[i].Options);
					
					// compile
										
					CILCompiler cmp = new CILCompiler (modBuilder, i);
					bool reverse = (regexes[i].Options & RegexOptions.RightToLeft) !=0;
					re.Compile (cmp, reverse);
					cmp.Close();
					
				}
		       

			// Define a runtime class with specified name and attributes.
			TypeBuilder builder = modBuilder.DefineType("ITest");
			builder.CreateType();
			asmBuilder.Save(aname.Name);
			*/
		}
예제 #2
0
		public void Constructor ()
		{
			RegexCompilationInfo info =  new RegexCompilationInfo (String.Empty, RegexOptions.None, "name", String.Empty, false);
			Assert.AreEqual (String.Empty, info.Pattern, "Pattern");
			Assert.AreEqual (RegexOptions.None, info.Options, "Options");
			Assert.AreEqual ("name", info.Name, "Name");
			Assert.AreEqual (String.Empty, info.Namespace, "Namespace");
			Assert.IsFalse (info.IsPublic, "IsPublic");
		}
예제 #3
0
		public void Constructor_InvalidRegexOptions ()
		{
			RegexOptions options = (RegexOptions) Int32.MinValue;
			RegexCompilationInfo info = new RegexCompilationInfo ("pattern", options, "name", "fullnamespace", true);
			Assert.AreEqual ("pattern", info.Pattern, "Pattern");
			Assert.AreEqual (options, info.Options, "Options");
			Assert.AreEqual ("name", info.Name, "Name");
			Assert.AreEqual ("fullnamespace", info.Namespace, "Namespace");
			Assert.IsTrue (info.IsPublic, "IsPublic");
		}
예제 #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="assmName"></param>
        public static void CreateRegExDLL(string assmName)
        {
            RegexCompilationInfo[] RE = new RegexCompilationInfo[2]
            {new RegexCompilationInfo("PATTERN", RegexOptions.Compiled,
                                  "CompiledPATTERN", "Chapter_Code", true),
             new RegexCompilationInfo("NAME", RegexOptions.Compiled,
                                  "CompiledNAME", "Chapter_Code", true)};

            System.Reflection.AssemblyName aName =
                 new System.Reflection.AssemblyName();
            aName.Name = assmName;

            Regex.CompileToAssembly(RE, aName);
        }
 public RegexCompiledToAssemblySplitLines()
 {
     RegexCompilationInfo SentencePattern =
                    new RegexCompilationInfo("\r\n|\r|\n",
                                             RegexOptions.Multiline,
                                             "SentencePattern",
                                             "Utilities.RegularExpressions",
                                             true);
     RegexCompilationInfo[] regexes = { SentencePattern };
     AssemblyName assemName = new AssemblyName("RegexLib, Version=1.0.0.1001, Culture=neutral, PublicKeyToken=null");
     Regex.CompileToAssembly(regexes, assemName);
     var asm = Assembly.Load(assemName);
     var type = asm.GetType("Utilities.RegularExpressions.SentencePattern");
     _regex = (Regex) Activator.CreateInstance(type);
 }
예제 #6
0
 public static void Compile(Type enumType, string assemblyName, string assemblyVersion)
 {
     var compilationList = new List<RegexCompilationInfo>();
     foreach (var name in Enum.GetNames(enumType))
     {
         try
         {
             var field = enumType.GetField(
             name, BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public)
             .GetCustomAttributes(true).OfType<RegExpressionAttribute>().First();
             var expr = new RegexCompilationInfo(
                 field.Pattern,
                 RegexOptions.CultureInvariant | field.Options,
                 name,
                 assemblyName,
                 true);
             compilationList.Add(expr);
         }
         catch
         {
             Console.WriteLine("Не найден шаблон регулярного выражения для элемента " + name);
         }
     }
     if (compilationList.Count == 0)
         throw new Exception(string.Format(
             "Перечисление '{0}' не содержит ни одного регулярного выражения", enumType.Name));
     try
     {
         var ctor = typeof(AssemblyTitleAttribute).GetConstructor(new[] { typeof(string) });
         var attBuilder = new[] { new CustomAttributeBuilder(ctor, new[] { assemblyName }) };
         var assemName = new AssemblyName(
             string.Format("{0}, Version={1}, Culture=neutral, PublicKeyToken=null",
             assemblyName, assemblyVersion));
         Regex.CompileToAssembly(compilationList.ToArray(), assemName, attBuilder);
     }
     catch (Exception ex)
     {
         throw new Exception("Ошибка компиляции сборки с регулярными выражениями", ex);
     }
 }
    static bool Regex_CompileToAssembly__RegexCompilationInfo_Array__AssemblyName__CustomAttributeBuilder_Array__String(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 4)
        {
            System.Text.RegularExpressions.RegexCompilationInfo[] arg0 = JSDataExchangeMgr.GetJSArg <System.Text.RegularExpressions.RegexCompilationInfo[]>(() =>
            {
                int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg);
                int length  = JSApi.getArrayLength(jsObjID);
                var ret     = new System.Text.RegularExpressions.RegexCompilationInfo[length];
                for (var i = 0; i < length; i++)
                {
                    JSApi.getElement(jsObjID, i);
                    ret[i] = (System.Text.RegularExpressions.RegexCompilationInfo)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove);
                }
                return(ret);
            });
            System.Reflection.AssemblyName arg1 = (System.Reflection.AssemblyName)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            System.Reflection.Emit.CustomAttributeBuilder[] arg2 = JSDataExchangeMgr.GetJSArg <System.Reflection.Emit.CustomAttributeBuilder[]>(() =>
            {
                int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg);
                int length  = JSApi.getArrayLength(jsObjID);
                var ret     = new System.Reflection.Emit.CustomAttributeBuilder[length];
                for (var i = 0; i < length; i++)
                {
                    JSApi.getElement(jsObjID, i);
                    ret[i] = (System.Reflection.Emit.CustomAttributeBuilder)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove);
                }
                return(ret);
            });
            System.String arg3 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg);
            System.Text.RegularExpressions.Regex.CompileToAssembly(arg0, arg1, arg2, arg3);
        }

        return(true);
    }
예제 #8
0
				// Although this method does not access any instance data, DO NOT MARK IT STATIC!
				// It needs to remain an instance method so that the call to it is remoted into the separate AppDomain.
				public void CompileToAssembly(RegexCompilationInfo[] regexCompilationInfos, AssemblyName assemblyName)
				{
					string currentDirectory = Directory.GetCurrentDirectory();
					try
					{
						Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyName.CodeBase));
						Regex.CompileToAssembly(regexCompilationInfos, assemblyName);
					}
					finally
					{
						Directory.SetCurrentDirectory(currentDirectory);
					}
				}
예제 #9
0
			public void CompileToAssembly(RegexCompilationInfo[] regexCompilationInfos, AssemblyName assemblyName)
			{
				this._regexCompilationProxy.CompileToAssembly(regexCompilationInfos, assemblyName);
			}
예제 #10
0
		private void CreateAssemblyFile(object sender, EventArgs e)
		{
			RegexOptions options = RegexOptions.Compiled;
			
			if(compileErrorProvider != null) {
				compileErrorProvider.Dispose();
				compileErrorProvider = null;
			}
			compileErrorProvider = new ErrorProvider();
			
			// validate input
			
			bool error = false;
			
			if(((TextBox)ControlDictionary["ClassNameCompileTextBox"]).Text == "") {
				compileErrorProvider.SetError((TextBox)ControlDictionary["ClassNameCompileTextBox"], ResourceService.GetString("RegExpTk.Messages.ClassNameMissing"));
				error = true;
			}
			
			if(ControlDictionary["RegularExpressionCompileTextBox"].Text == "") {
				compileErrorProvider.SetError((TextBox)ControlDictionary["RegularExpressionCompileTextBox"], ResourceService.GetString("RegExpTk.Messages.RegexMissing"));
				error = true;
			}
			
			if(((TextBox)ControlDictionary["AssemblyFileCompileFileTextBox"]).Text == "") {
				compileErrorProvider.SetError((TextBox)ControlDictionary["AssemblyFileCompileFileTextBox"], ResourceService.GetString("RegExpTk.Messages.FilenameMissing"));
				error = true;
			}
			
			string file_ = ((TextBox)ControlDictionary["AssemblyFileCompileFileTextBox"]).Text;
			
			if(! FileUtility.IsValidPath(((TextBox)ControlDictionary["AssemblyFileCompileFileTextBox"]).Text)) {
				compileErrorProvider.SetError((TextBox)ControlDictionary["AssemblyFileCompileFileTextBox"], ResourceService.GetString("RegExpTk.Messages.FilenameInvalid"));
				error = true;
			}
			
			if(error) return;
			
			// set options
			if(((CheckBox)ControlDictionary["IgnoreCaseCompileCheckBox"]).Checked)
				options = options | RegexOptions.IgnoreCase;
			
			if(((CheckBox)ControlDictionary["SingleLineCompileCheckBox"]).Checked)
				options = options | RegexOptions.Singleline;
			
			if(((CheckBox)ControlDictionary["IgnoreWhitespaceCompileCheckBox"]).Checked)
				options = options | RegexOptions.IgnorePatternWhitespace;
			
			if(((CheckBox)ControlDictionary["ExplicitCaptureCompileCheckBox"]).Checked)
				options = options | RegexOptions.ExplicitCapture;
			
			if(((CheckBox)ControlDictionary["EcmaScriptCompileCheckBox"]).Checked)
				options = options | RegexOptions.ECMAScript;
			
			if(((CheckBox)ControlDictionary["MultilineCompileCheckBox"]).Checked)
				options = options | RegexOptions.Multiline;
			
			if(((CheckBox)ControlDictionary["RightToLeftCompileCheckBox"]).Checked)
				options = options | RegexOptions.RightToLeft;
			
			try {
				Regex re = new Regex(((TextBox)ControlDictionary["RegularExpressionCompileTextBox"]).Text, options);
			} catch (ArgumentException ae) {
				MessageService.ShowError(ResourceService.GetString("RegExpTk.Messages.CreationError") + " " + ae.Message);
				return;
			}
			
			RegexCompilationInfo rci = new RegexCompilationInfo(((TextBox)ControlDictionary["RegularExpressionCompileTextBox"]).Text,
			                                                     options,
			                                                     ((TextBox)ControlDictionary["ClassNameCompileTextBox"]).Text,
			                                                     ((TextBox)ControlDictionary["NamespaceCompileTextBox"]).Text,
			                                                     ((CheckBox)ControlDictionary["PublibVisibleCompileCheckBox"]).Checked);
			
			AssemblyName asmName = new AssemblyName();
			asmName.Name = Path.GetFileNameWithoutExtension(((TextBox)ControlDictionary["AssemblyFileCompileFileTextBox"]).Text);
			
			RegexCompilationInfo[] rciArray = new RegexCompilationInfo[] { rci };
			
			try {
				Regex.CompileToAssembly(rciArray, asmName);
			} catch (ArgumentException ae) {
				MessageService.ShowError(ResourceService.GetString("RegExpTk.Messages.CompilationError") + " " + ae.Message);
				return;
			}
			
			string aboluteFileName = FileUtility.NormalizePath(((TextBox)ControlDictionary["AssemblyFileCompileFileTextBox"]).Text);
			((StatusBar)ControlDictionary["StatusBar"]).Text = ResourceService.GetString("RegExpTk.Messages.FileCreated") + " " + aboluteFileName;
		}
예제 #11
0
파일: RegexCas.cs 프로젝트: nlhepler/mono
		public void CompileToAssembly_Deny_FileIOPermission ()
		{
			RegexCompilationInfo info = new RegexCompilationInfo (String.Empty, RegexOptions.None, "name", String.Empty, false);
			Regex.CompileToAssembly (new RegexCompilationInfo[1] { info }, aname, null, null);
		}
예제 #12
0
		public void Options_Invalid ()
		{
			RegexCompilationInfo info = new RegexCompilationInfo ("pattern", RegexOptions.None, "name", "fullnamespace", true);
			info.Options = (RegexOptions) Int32.MinValue;
		}
 private static void CompileToAssemblyInternal(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname, CustomAttributeBuilder[] attributes, string resourceFile)
 {
     if (assemblyname == null)
     {
         throw new ArgumentNullException("assemblyname");
     }
     if (regexinfos == null)
     {
         throw new ArgumentNullException("regexinfos");
     }
     RegexCompiler.CompileToAssembly(regexinfos, assemblyname, attributes, resourceFile);
 }
 public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname)
 {
     CompileToAssemblyInternal(regexinfos, assemblyname, null, null);
 }
 internal static void CompileToAssembly(RegexCompilationInfo[] regexes, AssemblyName an, CustomAttributeBuilder[] attribs, string resourceFile)
 {
     RegexTypeCompiler compiler = new RegexTypeCompiler(an, attribs, resourceFile);
     for (int i = 0; i < regexes.Length; i++)
     {
         string name;
         if (regexes[i] == null)
         {
             throw new ArgumentNullException("regexes", SR.GetString("ArgumentNull_ArrayWithNullElements"));
         }
         string pattern = regexes[i].Pattern;
         RegexOptions op = regexes[i].Options;
         if (regexes[i].Namespace.Length == 0)
         {
             name = regexes[i].Name;
         }
         else
         {
             name = regexes[i].Namespace + "." + regexes[i].Name;
         }
         RegexTree t = RegexParser.Parse(pattern, op);
         RegexCode code = RegexWriter.Write(t);
         new ReflectionPermission(PermissionState.Unrestricted).Assert();
         try
         {
             Type factory = compiler.FactoryTypeFromCode(code, op, name);
             compiler.GenerateRegexType(pattern, op, name, regexes[i].IsPublic, code, t, factory);
         }
         finally
         {
             CodeAccessPermission.RevertAssert();
         }
     }
     compiler.Save();
 }
예제 #16
0
		public void Pattern_Null ()
		{
			RegexCompilationInfo info = new RegexCompilationInfo ("pattern", RegexOptions.None, "name", "fullnamespace", true);
			info.Pattern = null;
		}
예제 #17
0
 public void generateBuff()
 {
     string code = @"";
     Regex r;
     LambdaExpression l;
     RegexCompilationInfo rr = new RegexCompilationInfo("", RegexOptions.None, "", "", false);
 }
예제 #18
0
		/// <summary>See <see cref="Task.Execute"/>.</summary>
		public override bool Execute()
		{
			TaskLoggingHelper log = base.Log;
			ITaskItem[] regexCompilationInfoFiles = this.RegexCompilationInfoFiles;
			RegexCompilationInfo[] regexCompilationInfos = new RegexCompilationInfo[regexCompilationInfoFiles.Length];
			for (int i = 0; i < regexCompilationInfoFiles.Length; i++)
			{
				regexCompilationInfos[i] = RegexCompiler.LoadRegexCompilationInfo(log, regexCompilationInfoFiles[i].GetMetadata("FullPath"));
			}

			AssemblyName assemblyName = new AssemblyName(this.AssemblyName);
			string relativeAssemblyCodeBase = Path.Combine(this.IntermediateOutputPath, assemblyName.Name + ".dll");
			assemblyName.CodeBase = Path.GetFullPath(relativeAssemblyCodeBase);
			string strongNameKeySource;
			if (!string.IsNullOrEmpty(strongNameKeySource = this.KeyContainer))
			{
				assemblyName.KeyPair = new StrongNameKeyPair(strongNameKeySource);
			}
			else if (!string.IsNullOrEmpty(strongNameKeySource = this.KeyFile))
			{
				using (FileStream fileStream = new FileStream(strongNameKeySource, FileMode.Open, FileAccess.Read, FileShare.Read, 8192, FileOptions.SequentialScan))
				{
					assemblyName.KeyPair = new StrongNameKeyPair(fileStream);
				}
			}

			log.LogMessage("{0} regex assembly will be created with AssemblyName \"{1}\" and CodeBase \"{2}\".", assemblyName.KeyPair != null ? "Signed" : "Unsigned", assemblyName.FullName, relativeAssemblyCodeBase);

			using (RegexCompilationProxyWrapper regexCompilationProxyWrapper = new RegexCompilationProxyWrapper(this.AlwaysCompileRegexInSeparateDomain))
			{
				regexCompilationProxyWrapper.CompileToAssembly(regexCompilationInfos, assemblyName);
			}

			this._outputAssembly = new TaskItem(relativeAssemblyCodeBase);

			return !log.HasLoggedErrors;
		}
 public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, System.Reflection.AssemblyName assemblyname, System.Reflection.Emit.CustomAttributeBuilder[] attributes, string resourceFile)
 {
 }
예제 #20
0
		private static RegexCompilationInfo LoadRegexCompilationInfo(TaskLoggingHelper log, string regexFilePath)
		{
			log.LogMessage("Loading RegexCompilationInfo from \"{0}\".", regexFilePath);
			bool isPublic = false;
			string name = null;
			string @namespace = null;
			string pattern = null;
			RegexOptions regexOptions = RegexOptions.Compiled;

			FileInfo fileInfo = new FileInfo(regexFilePath);
			using (FileStream fileStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete, (int)fileInfo.Length, FileOptions.SequentialScan))
			{
				using (XmlReader xmlReader = XmlReader.Create(fileStream, XmlReaderSettings))
				{
					while (xmlReader.MoveToNextAttribute() || xmlReader.Read())
					{
						switch (xmlReader.NodeType)
						{
							case XmlNodeType.Element:
							case XmlNodeType.Attribute:
								switch (xmlReader.LocalName)
								{
									case "IsPublic":
										isPublic = xmlReader.ReadContentAsBoolean();
										break;
									case "Name":
										name = xmlReader.ReadContentAsString();
										break;
									case "Namespace":
										@namespace = xmlReader.ReadContentAsString();
										break;
									case "CultureInvariant":
										regexOptions |= RegexOptions.CultureInvariant;
										break;
									case "ECMAScript":
										regexOptions |= RegexOptions.ECMAScript;
										break;
									case "ExplicitCapture":
										regexOptions |= RegexOptions.ExplicitCapture;
										break;
									case "IgnoreCase":
										regexOptions |= RegexOptions.IgnoreCase;
										break;
									case "IgnorePatternWhitespace":
										regexOptions |= RegexOptions.IgnorePatternWhitespace;
										break;
									case "Multiline":
										regexOptions |= RegexOptions.Multiline;
										break;
									case "RightToLeft":
										regexOptions |= RegexOptions.RightToLeft;
										break;
									case "Singleline":
										regexOptions |= RegexOptions.Singleline;
										break;
									case "Pattern":
										pattern = xmlReader.ReadElementContentAsString();
										break;
								}
								break;
						}
					}
				}
			}

			RegexCompilationInfo regexCompilationInfo = new RegexCompilationInfo(pattern, regexOptions, name, @namespace, isPublic);
			log.LogMessage("RegexCompilationInfo loaded with settings:", null);
			log.LogMessage("\tNamespace:\t\t{0}", regexCompilationInfo.Namespace);
			log.LogMessage("\tName:\t\t\t{0}", regexCompilationInfo.Name);
			log.LogMessage("\tIsPublic:\t\t{0}", regexCompilationInfo.IsPublic);
			log.LogMessage("\tRegexOptions:\t{0}", regexCompilationInfo.Options);
			return regexCompilationInfo;
		}
예제 #21
0
		public void Name_Empty ()
		{
			RegexCompilationInfo info = new RegexCompilationInfo ("pattern", RegexOptions.None, "name", "fullnamespace", true);
			info.Name = String.Empty;
		}
 public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname, CustomAttributeBuilder[] attributes, string resourceFile)
 {
     CompileToAssemblyInternal(regexinfos, assemblyname, attributes, resourceFile);
 }
예제 #23
0
 public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname) {
 
     CompileToAssemblyInternal(regexinfos, assemblyname, null, null, Assembly.GetCallingAssembly().Evidence);
 }
 public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, System.Reflection.AssemblyName assemblyname)
 {
 }
예제 #25
0
 public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname, CustomAttributeBuilder[] attributes) {
     CompileToAssemblyInternal(regexinfos, assemblyname, attributes, null, Assembly.GetCallingAssembly().Evidence);
 }
 internal static void CompileToAssembly(RegexCompilationInfo[] regexes, AssemblyName an, CustomAttributeBuilder[] attribs, String resourceFile, Evidence evidence) {
     RegexTypeCompiler c = new RegexTypeCompiler(an, attribs, resourceFile, evidence);
 
     for (int i=0; i<regexes.Length; i++) {
         String pattern = regexes[i].Pattern;
         RegexOptions options = regexes[i].Options;
         String fullname;
         if (regexes[i].Namespace.Length == 0)
             fullname = regexes[i].Name;
         else
             fullname = regexes[i].Namespace + "." + regexes[i].Name;
 
         RegexTree tree = RegexParser.Parse(pattern, options);
         RegexCode code = RegexWriter.Write(tree);
 
         Type factory;
 
         new ReflectionPermission(PermissionState.Unrestricted).Assert();
         try {
             factory = c.FactoryTypeFromCode(code, options, fullname);
             c.GenerateRegexType(pattern, options, fullname, regexes[i].IsPublic, code, tree, factory);
         }
         finally {
             CodeAccessPermission.RevertAssert();
         }
     }
 
     c.Save();
 }
예제 #27
0
		public static void CompileToAssembly
			(RegexCompilationInfo[] regexes, AssemblyName aname,
			 CustomAttributeBuilder[] attribs)
		{
			Regex.CompileToAssembly(regexes, aname, attribs, null);
		}
예제 #28
0
파일: RegexCas.cs 프로젝트: nlhepler/mono
		public void CompileToAssembly_PermitOnly_ControlEvidence ()
		{
			RegexCompilationInfo info = new RegexCompilationInfo (String.Empty, RegexOptions.None, "name", String.Empty, false);
			Regex.CompileToAssembly (new RegexCompilationInfo[1] { info }, aname, null, null);
		}
예제 #29
0
파일: regex.cs 프로젝트: ArildF/masters
 /// <include file='doc\Regex.uex' path='docs/doc[@for="Regex.CompileToAssembly1"]/*' />
 /// <devdoc>
 /// </devdoc>
 public static void CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname, CustomAttributeBuilder[] attributes) {
     CompileToAssembly(regexinfos, assemblyname, attributes, null);
 }