Пример #1
0
        /// <summary>
        /// Loads a dynamic wrapper of a specified library assembly.
        /// </summary>
        /// <returns>The dynamic wrapper assembly.</returns>
        /// <remarks>Thread safe.</remarks>
        public void LoadDynamicWrapper()
        {
            if (dynamicWrapper != null)
            {
                return;
            }

            Assembly real_assembly = PhpLibraryAssembly.RealAssembly;

            if (PhpLibraryAssembly.Properties.ContainsDynamicStubs)
            {
                dynamicWrapper = real_assembly;
                return;
            }

#if SILVERLIGHT
            this.dynamicWrapper = LibraryBuilder.CreateDynamicWrapper(real_assembly);
#else
            if (!Configuration.IsLoaded && !Configuration.IsBeingLoaded)
            {
                return;
            }                                                                        // continue without wrappers !! (VS Integration does not need it)
            string wrappers_dir = Configuration.GetPathsNoLoad().DynamicWrappers;

            // determine wrapper file name,
            // we are looking for an up-to-date wrapper or a writable location:
            string wrapper_file     = DetermineDynamicWrapperFileName(wrappers_dir, real_assembly);
            string wrapper_fullfile = Path.Combine(wrappers_dir, wrapper_file);

            //
            try
            {
                // builds wrapper if it doesn't exist:
                if (!IsDynamicWrapperUpToDate(real_assembly, wrapper_fullfile))
                {
                    Mutex mutex = new Mutex(false, String.Concat(@"Global\", wrapper_fullfile.ToLowerInvariant().Replace('\\', '/').Replace(':', '+')));   // do not use \ and : characters, to not confuse Mutex with file system which may not be accessible in this moment
                    mutex.WaitOne();
                    try
                    {
                        // if the file still does not exist, we are in charge!
                        if (!IsDynamicWrapperUpToDate(real_assembly, wrapper_fullfile))
                        {
                            LibraryBuilder.CreateDynamicWrapper(real_assembly, wrappers_dir, wrapper_file);
                        }
                    }
                    finally
                    {
                        mutex.ReleaseMutex();
                    }
                }

                // loads wrapper:
                this.dynamicWrapper = System.Reflection.Assembly.LoadFrom(wrapper_fullfile);
            }
            catch (Exception e)
            {
                throw new DynamicWrapperLoadException(wrapper_fullfile, e);
            }
#endif
        }
Пример #2
0
        /// <summary>
        /// The entry point.
        /// </summary>
        static void Main(string[] args)
        {
            Environment.ExitCode = 1;

            Logo();

            if (!ProcessArguments(args))
            {
                return;
            }

            Type attr = null;

            if (resolve)
            {
                try
                {
                    Assembly coreAsm = Assembly.LoadFrom("PhpNetCore.dll");
                    attr = coreAsm.GetType("PHP.Core.ImplementsFunctionAttribute");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Dynamic resolution of the 'ImplementsFunctionAttribute' failed: ", e.Message);
                    return;
                }
            }

            Assembly assembly;

            try
            {
                assembly = Assembly.LoadFrom(assemblyName);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occured while loading assembly: {0}", e.Message);
                return;
            }

            string dynamic_assembly_path;

            try
            {
                dynamic_assembly_path = LibraryBuilder.CreateDynamicWrapper(attr, assembly, directory, PHP.Core.Reflection.PhpLibraryModule.DynamicWrapperFileName(assembly, 0));
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occured while generating wrapper: {0}", e.Message);
                return;
            }

            Console.WriteLine("The dynamic wrapper '{0}' has been generated.", Path.GetFullPath(dynamic_assembly_path));
            Environment.ExitCode = 0;
        }