Server.ScriptCompiler.CompileVBScripts C# (CSharp) Méthode

CompileVBScripts() public static méthode

public static CompileVBScripts ( bool debug, bool cache, Assembly &assembly ) : bool
debug bool
cache bool
assembly System.Reflection.Assembly
Résultat bool
		public static bool CompileVBScripts( bool debug, bool cache, out Assembly assembly )
		{
			Console.Write( "Scripts: Compiling VB.NET scripts..." );
			string[] files = GetScripts( "*.vb" );

			if( files.Length == 0 )
			{
				Console.WriteLine( "no files found." );
				assembly = null;
				return true;
			}

			if( File.Exists( "Scripts/Output/Scripts.VB.dll" ) )
			{
				if( cache && File.Exists( "Scripts/Output/Scripts.VB.hash" ) )
				{
					byte[] hashCode = GetHashCode( "Scripts/Output/Scripts.VB.dll", files, debug );

					try
					{
						using( FileStream fs = new FileStream( "Scripts/Output/Scripts.VB.hash", FileMode.Open, FileAccess.Read, FileShare.Read ) )
						{
							using( BinaryReader bin = new BinaryReader( fs ) )
							{
								byte[] bytes = bin.ReadBytes( hashCode.Length );

								if( bytes.Length == hashCode.Length )
								{
									bool valid = true;

									for( int i = 0; i < bytes.Length; ++i )
									{
										if( bytes[i] != hashCode[i] )
										{
											valid = false;
											break;
										}
									}

									if( valid )
									{
										assembly = Assembly.LoadFrom( "Scripts/Output/Scripts.VB.dll" );

										if( !m_AdditionalReferences.Contains( assembly.Location ) )
										{
											m_AdditionalReferences.Add( assembly.Location );
										}

										Console.WriteLine( "done (cached)" );

										return true;
									}
								}
							}
						}
					}
					catch
					{
					}
				}
			}

			DeleteFiles( "Scripts.VB*.dll" );

			using ( VBCodeProvider provider = new VBCodeProvider() )
			{
				string path = GetUnusedPath( "Scripts.VB" );

				CompilerParameters parms = new CompilerParameters( GetReferenceAssemblies(), path, debug );

				string options = GetCompilerOptions( debug );

				if( options != null )
					parms.CompilerOptions = options;

				if( Core.HaltOnWarning )
					parms.WarningLevel = 4;

				CompilerResults results = provider.CompileAssemblyFromFile( parms, files );
				m_AdditionalReferences.Add( path );

				Display( results );

				if( results.Errors.Count > 0 )
				{
					assembly = null;
					return false;
				}

				if( cache && Path.GetFileName( path ) == "Scripts.VB.dll" )
				{
					try
					{
						byte[] hashCode = GetHashCode( path, files, debug );

						using( FileStream fs = new FileStream( "Scripts/Output/Scripts.VB.hash", FileMode.Create, FileAccess.Write, FileShare.None ) )
						{
							using( BinaryWriter bin = new BinaryWriter( fs ) )
							{
								bin.Write( hashCode, 0, hashCode.Length );
							}
						}
					}
					catch
					{
					}
				}

				assembly = results.CompiledAssembly;
				return true;
			}
		}

Same methods

ScriptCompiler::CompileVBScripts ( Assembly &assembly ) : bool
ScriptCompiler::CompileVBScripts ( bool debug, Assembly &assembly ) : bool

Usage Example

Exemple #1
0
        public static bool Compile(bool debug)
        {
            int       num1;
            ArrayList list1;

            Type[]     typeArray1;
            int        num2;
            MethodInfo info1;
            int        num3;

            Type[]     typeArray2;
            int        num4;
            MethodInfo info2;
            int        num5;

            ScriptCompiler.EnsureDirectory("Scripts/");
            ScriptCompiler.EnsureDirectory("Scripts/Output/");
            ScriptCompiler.DeleteFiles("Scripts.CS*.dll");
            ScriptCompiler.DeleteFiles("Scripts.VB*.dll");
            ScriptCompiler.DeleteFiles("Scripts*.dll");
            if (ScriptCompiler.m_AdditionalReferences.Count > 0)
            {
                ScriptCompiler.m_AdditionalReferences.Clear();
            }
            CompilerResults results1 = null;
            CompilerResults results2 = null;

            results1 = ScriptCompiler.CompileCSScripts(debug);
            if ((results1 == null) || !results1.Errors.HasErrors)
            {
                results2 = ScriptCompiler.CompileVBScripts(debug);
            }
            if ((((results1 == null) || !results1.Errors.HasErrors) && ((results2 == null) || !results2.Errors.HasErrors)) && ((results2 != null) || (results1 != null)))
            {
                num1 = 0;
                if ((results1 == null) || (results2 == null))
                {
                    ScriptCompiler.m_Assemblies = new Assembly[1];
                }
                else
                {
                    ScriptCompiler.m_Assemblies = new Assembly[2];
                }
                if (results1 != null)
                {
                    ScriptCompiler.m_Assemblies[num1++] = results1.CompiledAssembly;
                }
                if (results2 != null)
                {
                    ScriptCompiler.m_Assemblies[num1++] = results2.CompiledAssembly;
                }
                Console.Write("Scripts: Verifying...");
                Core.VerifySerialization();
                Console.WriteLine("done ({0} items, {1} mobiles)", Core.ScriptItems, Core.ScriptMobiles);
                list1 = new ArrayList();
                num1  = 0;
                while ((num1 < ScriptCompiler.m_Assemblies.Length))
                {
                    typeArray1 = ScriptCompiler.m_Assemblies[num1].GetTypes();
                    for (num2 = 0; (num2 < typeArray1.Length); ++num2)
                    {
                        info1 = typeArray1[num2].GetMethod("Configure", (BindingFlags.Public | BindingFlags.Static));
                        if (info1 != null)
                        {
                            list1.Add(info1);
                        }
                    }
                    ++num1;
                }
                list1.Sort(new CallPriorityComparer());
                for (num3 = 0; (num3 < list1.Count); ++num3)
                {
                    ((MethodInfo)list1[num3]).Invoke(null, null);
                }
                list1.Clear();
                World.Load();
                for (num1 = 0; (num1 < ScriptCompiler.m_Assemblies.Length); ++num1)
                {
                    typeArray2 = ScriptCompiler.m_Assemblies[num1].GetTypes();
                    for (num4 = 0; (num4 < typeArray2.Length); ++num4)
                    {
                        info2 = typeArray2[num4].GetMethod("Initialize", (BindingFlags.Public | BindingFlags.Static));
                        if (info2 != null)
                        {
                            list1.Add(info2);
                        }
                    }
                }
                list1.Sort(new CallPriorityComparer());
                for (num5 = 0; (num5 < list1.Count); ++num5)
                {
                    ((MethodInfo)list1[num5]).Invoke(null, null);
                }
                return(true);
            }
            return(false);
        }
All Usage Examples Of Server.ScriptCompiler::CompileVBScripts