コード例 #1
0
		private string GetCacheFileName(DslEngine engine, string[] urls)
		{
			string fileName = storage.GetChecksumForUrls(engine.GetType(), urls) + ".boocache";
            string engineName = engine.EngineName;
            if (engineName != null)
            {
                fileName = string.Format("{0}_{1}", engineName, fileName);
            }
			return Path.Combine(Path.GetTempPath(), fileName);
		}
コード例 #2
0
ファイル: DslFactory.cs プロジェクト: jjchiw/rhino-dsl
        private string[] GetUrlsFromDslEngine(DslEngine engine, ref string path)
        {
            string[]      matchingUrls = engine.Storage.GetMatchingUrlsIn(BaseDirectory, ref path);
            List <string> urls         = new List <string>(matchingUrls ?? new string[0]);

            // even if the path is in the cache, we still return the it
            // so we will get a new version
            if (urls.Exists(GetMatchPathPredicate(path)) == false &&
                engine.Storage.IsValidScriptUrl(path))
            {
                urls.Add(path);
            }
            return(urls.ToArray());
        }
コード例 #3
0
ファイル: DslFactory.cs プロジェクト: jjchiw/rhino-dsl
        /// <summary>
        /// Creates instances of all the DSL that are located directly under the parent URL.
        /// </summary>
        /// <typeparam name="TDslBase">The type of the DSL base.</typeparam>
        /// <param name="parentUrl">The parent URL.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public TDslBase[] CreateAll <TDslBase>(string parentUrl, params object[] parameters)
        {
            DslEngine engine = GetEngine <TDslBase>();

            List <TDslBase> instances = new List <TDslBase>();

            engine.Cache.ReadLock(delegate
            {
                foreach (string dsl in GetUrlsFromDslEngine(engine, ref parentUrl))
                {
                    instances.Add(Create <TDslBase>(dsl, parameters));
                }
            });
            return(instances.ToArray());
        }
コード例 #4
0
ファイル: DslFactory.cs プロジェクト: jjchiw/rhino-dsl
        private TDslBase CreateInternal <TDslBase>(ScriptNotFoundBehavior notFoundBehavior, string url, object[] parameters)
        {
            DslEngine engine = GetEngine <TDslBase>();
            Type      type   = null;

            engine.Cache.ReadLock(delegate
            {
                type = engine.Cache.Get(engine.CanonizeUrl(url));
                if (type == null)
                {
                    bool recompilation;
                    string[] urls      = GetUrls(engine, ref url, out recompilation);
                    bool existsInArray = engine.Storage.IsUrlIncludeIn(urls, BaseDirectory, url);
                    if (existsInArray == false)
                    {
                        if (notFoundBehavior == ScriptNotFoundBehavior.Throw)
                        {
                            throw new InvalidOperationException("Could not find DSL script: " + url);
                        }
                        return;
                    }
                    CompilerContext compilerContext;
                    try
                    {
                        compilerContext = engine.Compile(urls);
                    }
                    catch (Exception)
                    {
                        // if we fail to compile with batch, we will try just the current url
                        urls            = new string[] { url };
                        compilerContext = engine.Compile(urls);
                    }
                    Assembly assembly = compilerContext.GeneratedAssembly;
                    RegisterBatchInCache(engine, urls, assembly);
                    //find the type that we searched for
                    //we may have a race condition with the cache, so we force
                    //it to go through the assemly instead of the cache
                    type = engine.GetTypeForUrl(assembly, url);
                    RaiseCompilationEvent(recompilation);
                }
            });
            if (type == null)
            {
                return(default(TDslBase));
            }
            return((TDslBase)engine.CreateInstance(type, parameters));
        }
コード例 #5
0
		/// <summary>
		/// Returns cached instance if any, or null if none
		/// </summary>
		/// <param name="engine"></param>
		/// <param name="urls"></param>
		/// <returns></returns>
		public CompilerContext GetCached(DslEngine engine, string[] urls)
		{
			if (urls == null || urls.Length == 0) throw new ArgumentNullException("urls");

			string cacheFileName = GetCacheFileName(engine, urls);
			CompilerContext context = LoadCompilerContext(cacheFileName);

			if (context == null)
			{
				context = engine.ForceCompile(urls,cacheFileName);
				WriteLock(delegate
				{
					assemblyCache[cacheFileName] = context.GeneratedAssembly;
					AssemblyLoaded(cacheFileName, context.GeneratedAssembly, false);
				});
			}

			return context;
		}
コード例 #6
0
ファイル: DslFactory.cs プロジェクト: jjchiw/rhino-dsl
 private string[] GetUrls(DslEngine engine, ref string url, out bool recompilation)
 {
     string[] urls;
     // we need to compile this separatedly, instead of
     // in a batch. This is usually happening when a script
     // has changed
     recompilation = false;
     if (standAloneCompilation.Contains(url))
     {
         standAloneCompilation.Remove(url);
         urls          = new string[] { url };
         recompilation = true;
     }
     else
     {
         urls = GetUrlsFromDslEngine(engine, ref url);
     }
     return(urls);
 }
コード例 #7
0
ファイル: DslFactory.cs プロジェクト: jjchiw/rhino-dsl
 private void RegisterBatchInCache(DslEngine engine, IEnumerable <string> urls, Assembly compiledAssembly)
 {
     engine.Cache.WriteLock(delegate
     {
         foreach (string batchUrl in urls)
         {
             Type type = engine.GetTypeForUrl(compiledAssembly, batchUrl);
             if (type == null)
             {
                 throw new InvalidOperationException("Could not find the generated type for: " + batchUrl);
             }
             engine.Cache.Set(batchUrl, type);
         }
         engine.Storage.NotifyOnChange(urls, delegate(string invalidatedUrl)
         {
             engine.Cache.Remove(invalidatedUrl);
             standAloneCompilation.Add(invalidatedUrl);
         });
     });
 }
コード例 #8
0
        /// <summary>
        /// Returns cached instance if any, or null if none
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="urls"></param>
        /// <returns></returns>
        public CompilerContext GetCached(DslEngine engine, string[] urls)
        {
            if (urls == null || urls.Length == 0)
            {
                throw new ArgumentNullException("urls");
            }

            string          cacheFileName = GetCacheFileName(engine, urls);
            CompilerContext context       = LoadCompilerContext(cacheFileName);

            if (context == null)
            {
                context = engine.ForceCompile(urls, cacheFileName);
                WriteLock(delegate
                {
                    assemblyCache[cacheFileName] = context.GeneratedAssembly;
                    AssemblyLoaded(cacheFileName, context.GeneratedAssembly, false);
                });
            }

            return(context);
        }
コード例 #9
0
		private string GetCacheFileName(DslEngine engine, string[] urls)
		{
			string fileName = storage.GetChecksumForUrls(engine.GetType(), urls) + ".boocache";
			return Path.Combine(Path.GetTempPath(), fileName);
		}
コード例 #10
0
ファイル: DslFactory.cs プロジェクト: jjchiw/rhino-dsl
 ///<summary>
 /// Register a new DSL engine that is tied to a specific base type
 ///</summary>
 public void Register <TDslBase>(DslEngine engine)
 {
     typeToDslEngine.Add(typeof(TDslBase), engine);
 }
コード例 #11
0
        private string GetCacheFileName(DslEngine engine, string[] urls)
        {
            string fileName = storage.GetChecksumForUrls(engine.GetType(), urls) + ".boocache";

            return(Path.Combine(Path.GetTempPath(), fileName));
        }