Example #1
0
        /// <summary>
        /// Runs the assembly with the specified arguments.xit
        /// </summary>
        /// <param name="workingDirectory">The working directory.</param>
        /// <param name="environmentVariables">The environment variables.</param>
        /// <param name="args">The main arguments.</param>
        /// <param name="shadowCache">If [true], use shadow cache.</param>
        /// <param name="logger">The logger.</param>
        /// <returns>System.Int32.</returns>
        public int Run(string workingDirectory, Dictionary <string, string> environmentVariables, string[] args, bool shadowCache, IServerLogger logger)
        {
            lock (disposingLock)
            {
                if (isDisposed)
                {
                    logger.OnLog("Error, server is being shutdown, cannot run Compiler", ConsoleColor.Red);
                    return(1);
                }
            }


            AppDomainShadow shadowDomain = null;

            try
            {
                shadowDomain = GetOrNew(shadowCache, IsCachingAppDomain);
                return(shadowDomain.Run(workingDirectory, environmentVariables, args, logger));
            }
            finally
            {
                if (shadowDomain != null)
                {
                    shadowDomain.EndRun();
                    if (!IsCachingAppDomain)
                    {
                        shadowDomain.Dispose();
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Get or create a new <see cref="AppDomainShadow"/>.
        /// </summary>
        /// <returns></returns>
        private AppDomainShadow GetOrNew(bool shadowCache, bool appdomainCache)
        {
            lock (appDomainShadows)
            {
                foreach (var appDomainShadow in appDomainShadows)
                {
                    if (appDomainShadow.ShadowCache == shadowCache && appDomainShadow.TryLock())
                    {
                        Console.WriteLine("Use cached AppDomain {0}", appDomainShadow.Name);
                        return(appDomainShadow);
                    }
                }

                var newAppDomainName = Path.GetFileNameWithoutExtension(mainAssemblyPath) + "#" + appDomainShadows.Count;
                Console.WriteLine("Create new AppDomain {0}", newAppDomainName);
                var newAppDomain = new AppDomainShadow(newAppDomainName, entryAssemblyPath, mainAssemblyPath, shadowCache, nativeDllsPathOrFolderList.ToArray());
                newAppDomain.TryLock();

                if (appdomainCache)
                {
                    appDomainShadows.Add(newAppDomain);
                }
                return(newAppDomain);
            }
        }