/// <summary>
        /// 根据程序集获取日志记录器配置信息。
        /// </summary>
        /// <param name="assembly">程序集。</param>
        /// <returns>日志配置。</returns>
        public object GetLoggingConfiguration(Assembly assembly)
        {
            if (assembly == null)
                throw new ArgumentNullException("assembly");

            return _cacheManager.Get(assembly.GetHashCode(), ctx =>
            {
                var stream = GetLoggingConfigurationStream(assembly);

                if (stream == null)
                    return new XmlLoggingConfiguration(_defaultConfigurationPath);

                using (stream)
                {
                    var document = XDocument.Load(stream);

                    var nlogElement = document.Element(XName.Get("nlog", "http://www.nlog-project.org/schemas/NLog.xsd"));

                    //组合规则。
                    CombineRules(assembly, document);

                    //组合目标。
                    CombineTargets(nlogElement);
                    using (var stringReader = new StringReader(document.ToString()))
                    {
                        var xmlReader = XmlReader.Create(stringReader);
                        return new XmlLoggingConfiguration(xmlReader, null);
                    }
                }
            });
        }
 /// <devdoc>
 ///     Create a cache key for the UrlCache.  
 ///
 ///     requirement:  If assembly1 and assembly2 represent the same assembly, 
 ///     then they must be the same object; otherwise this method will fail to generate 
 ///     a unique cache key.
 /// </devdoc>
 private static int CreateWebResourceUrlCacheKey(Assembly assembly, string resourceName,
     bool htmlEncoded, bool forSubstitution, bool enableCdn, bool debuggingEnabled, bool secureConnection) {
     int hashCode = HashCodeCombiner.CombineHashCodes(
         assembly.GetHashCode(),
         resourceName.GetHashCode(),
         htmlEncoded.GetHashCode(),
         forSubstitution.GetHashCode(),
         enableCdn.GetHashCode());
     return HashCodeCombiner.CombineHashCodes(hashCode,
         debuggingEnabled.GetHashCode(),
         secureConnection.GetHashCode());
 }
Esempio n. 3
0
        private static string GetAssemblyName(Assembly asm)
        {
            var key = asm.GetHashCode();
            lock (AssemblyNameCache)
            {
                string name;
                if (!AssemblyNameCache.TryGetValue(key, out name))
                {
                    name = asm.GetName().Name;
                    AssemblyNameCache[key] = name;
                }

                return name;
            }
        }
Esempio n. 4
0
		static string CreateResourceUrl (Assembly assembly, string resourceName, bool notifyScriptLoaded)
		{

			string aname = assembly == currAsm ? "s" : assembly.GetName ().FullName;
			string apath = assembly.Location;
			string atime = String.Empty;
			string extra = String.Empty;
#if SYSTEM_WEB_EXTENSIONS
			extra = String.Concat (QueryParamSeparator, "n=", notifyScriptLoaded ? "t" : "f");
#endif

#if TARGET_JVM
			atime = String.Format ("{0}t={1}", QueryParamSeparator, assembly.GetHashCode ());
#else
			if (apath != String.Empty)
				atime = String.Concat (QueryParamSeparator, "t=", File.GetLastWriteTimeUtc (apath).Ticks);
#endif
			string href = HandlerFileName + "?d=" + EncryptAssemblyResource (aname, resourceName) + atime + extra;

			HttpContext ctx = HttpContext.Current;
			if (ctx != null && ctx.Request != null) {
				string appPath = VirtualPathUtility.AppendTrailingSlash (ctx.Request.ApplicationPath);
				href = appPath + href;
			}
			
			return href;
		}
        /// <summary>
        /// Get the info about the resource that in the assembly
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="resourceName"></param>
        /// <returns></returns>
        private static Quadruplet<bool, bool, string, bool> GetResourceInfo(Assembly assembly, string resourceName)
        {
            // Create a unique cache key
            int cacheKey = Util.CombineHashCodes(assembly.GetHashCode(), resourceName.GetHashCode());

            Quadruplet<bool, bool, string, bool> resourceInfo = _webResourceCache[cacheKey] as Quadruplet<bool, bool, string, bool>;

            // Assembly info was not in the cache
            if (resourceInfo == null)
            {
                bool first = false;
                bool second = false;
                string third = string.Empty;
                bool forth = false;

                object[] customAttributes = assembly.GetCustomAttributes(false);
                for (int j = 0; j < customAttributes.Length; j++)
                {
                    WebResourceAttribute attribute = customAttributes[j] as WebResourceAttribute;
                    if ((attribute != null) && string.Equals(attribute.WebResource, resourceName, StringComparison.Ordinal))
                    {
                        first = true;
                        second = attribute.PerformSubstitution;
                        third = attribute.ContentType;
                        forth = Util.IsContentTypeCompressible(attribute.ContentType);
                        break;
                    }
                }
                resourceInfo = new Quadruplet<bool, bool, string, bool>(first, second, third, forth);
                _webResourceCache[cacheKey] = resourceInfo;
            }
            return resourceInfo;
        }
        /// <summary>
        /// Get the info about the resource that in the assembly
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="resourceName"></param>
        /// <returns></returns>
        protected static Quadruplet<bool, bool, string, bool> GetResourceInfo(Assembly assembly, string resourceName)
        {
            // Create a unique cache key
            var cacheKey = CombineHashCodes(assembly.GetHashCode(), resourceName.GetHashCode());

            var resourceInfo = WebResourceCache[cacheKey] as Quadruplet<bool, bool, string, bool>;

            // Assembly info was not in the cache
            if (resourceInfo == null)
            {
                var first = false;
                var second = false;
                var third = string.Empty;
                var forth = false;

                var customAttributes = assembly.GetCustomAttributes(false);
                for (var j = 0; j < customAttributes.Length; j++)
                {
                    var attribute = customAttributes[j] as WebResourceAttribute;
                    if ((attribute == null) || !string.Equals(attribute.WebResource, resourceName, StringComparison.Ordinal)) continue;

                    first = true;
                    second = attribute.PerformSubstitution;
                    third = attribute.ContentType;
                    forth = CompressionModuleHelper.IsContentTypeCompressible(attribute.ContentType);
                    break;
                }
                resourceInfo = new Quadruplet<bool, bool, string, bool>(first, second, third, forth);
                WebResourceCache[cacheKey] = resourceInfo;
            }
            return resourceInfo;
        }
Esempio n. 7
0
        internal static void SetScriptReflection(Assembly assembly, string location)
        {
            Environment.SetEnvironmentVariable("location:" + assembly.GetHashCode(), location);

            string source = null;
            //Note assembly can contain only single AssemblyDescriptionAttribute
            foreach (AssemblyDescriptionAttribute attribute in assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), true))
                source = attribute.Description;

            //check if executing the primary script and not hosted execution ("CSScriptRuntime" == null)
            if (Environment.GetEnvironmentVariable("CSScriptRuntime") != null && source == Environment.GetEnvironmentVariable("EntryScript"))
                Environment.SetEnvironmentVariable("EntryScriptAssembly", location);
        }
Esempio n. 8
0
        // Recursively check for types with GTypeNameAttribute and put them in TypeCache,
        // but only if gstreamer-sharp is in the chain of referenced assemblies.
        private static void PutAssemblyTypesInCache(Assembly asm)
        {
            // If already visited, return immediately
              if (AssemblyTypesInCache.ContainsKey(asm.GetHashCode ()))
            return;

              // Add with false to avoid chasing circular dependencies
              AssemblyTypesInCache.Add (asm.GetHashCode (), false);

              // Result is true for gstreamer-sharp or if a referenced assembly results in true
              bool result = asm.GetName().Name.Equals("gstreamer-sharp");

              foreach (AssemblyName ref_name in asm.GetReferencedAssemblies ()) {
            try {
              Assembly ref_asm = Assembly.Load (ref_name);
              PutAssemblyTypesInCache (ref_asm);
              result = result | AssemblyTypesInCache[ref_asm.GetHashCode ()];
            } catch {
              /* Failure to load a referenced assembly is not an error */
            }
              }

              // Add types with GTypeNameAttribute in TypeCache
              if (result) {
            AssemblyTypesInCache[asm.GetHashCode ()] = true;
            Type[] ts;
            try {
              ts = asm.GetTypes ();
            } catch (ReflectionTypeLoadException e) {
              ts = e.Types;
            }
            foreach (Type t in ts) {
              if (t != null && t.IsDefined (typeof (GTypeNameAttribute), false)) {
            GTypeNameAttribute gattr = (GTypeNameAttribute) Attribute.GetCustomAttribute (t, typeof (GTypeNameAttribute), false);
            TypeCache[gattr.TypeName] = t;
              }
            }
              }
        }