private static void Register(string name, IChoProfile profile, bool force) { string typeProfileName = null; MemberInfo memberInfo = null; ChoProfileAttribute memberAttribute = null; ChoProfileAttribute typeAttribute = null; string profileName = GetProfileName(name, out memberInfo, out typeProfileName, out memberAttribute, out typeAttribute); if (force) { MemberProfileCache.AddOrUpdate(profileName, profile); } else { MemberProfileCache.GetOrAdd(profileName, profile); } }
public static IChoProfile GetContext(string name) { string typeProfileName = null; MemberInfo memberInfo = null; ChoProfileAttribute memberAttribute = null; ChoProfileAttribute typeAttribute = null; string profileName = GetProfileName(name, out memberInfo, out typeProfileName, out memberAttribute, out typeAttribute); IChoProfile profile = null; if (MemberProfileCache.TryGetValue(profileName, out profile)) { return(profile); } return(Register(name, profileName, memberInfo, typeProfileName, memberAttribute, typeAttribute)); }
internal static IChoProfile GetContext(StackFrame frame) { string name = null; MemberInfo method = frame.GetMethod(); if (method != null) { name = method.Name; ChoProfileAttribute profileAttribute = ChoType.GetMemberAttributeByBaseType <ChoProfileAttribute>(method); if (profileAttribute == null) { var type = method.DeclaringType; name = type.Name; profileAttribute = ChoType.GetAttribute(type, typeof(ChoProfileAttribute)) as ChoProfileAttribute; } if (profileAttribute != null) { if (_profileAttribute == profileAttribute) { return(_contextProfile); } else { _profileAttribute = profileAttribute; } if (profileAttribute.Name.IsNullOrWhiteSpace()) { profileAttribute.Name = name; } if (profileAttribute.OuterProfileName.IsNullOrWhiteSpace()) { _contextProfile = profileAttribute.ConstructProfile(null, null); } else { _contextProfile = profileAttribute.ConstructProfile(null, GetProfile(profileAttribute.OuterProfileName)); } } } return(_contextProfile); }
private static IChoProfile Register(string name, string profileName, MemberInfo memberInfo, string typeProfileName, ChoProfileAttribute memberProfileAttribute, ChoProfileAttribute typeProfileAttribute) { lock (MemberProfileCache.SyncRoot) { IChoProfile profile = null; if (MemberProfileCache.TryGetValue(profileName, out profile)) { return(profile); } if (!String.IsNullOrEmpty(typeProfileName) && !MemberProfileCache.ContainsKey(typeProfileName)) { if (typeProfileAttribute != null) { IChoProfile profile1 = typeProfileAttribute.ConstructProfile(ChoThreadLocalStorage.Target, null); //SetAsNotDisposed(profile1, false); MemberProfileCache.Add(typeProfileName, profile1); } else { MemberProfileCache.Add(typeProfileName, GlobalProfile); } } if (memberProfileAttribute == null) { return(MemberProfileCache[typeProfileName]); } else { IChoProfile profile1 = memberProfileAttribute.ConstructProfile(ChoThreadLocalStorage.Target, MemberProfileCache[typeProfileName]); //SetAsNotDisposed(profile1, false); MemberProfileCache.Add(profileName, profile1); return(MemberProfileCache[profileName]); } } }
//private static void SetAsNotDisposed(IChoProfile profile, bool dispose) //{ // if (profile == null) // return; // if (profile is ChoBufferProfile) // ((ChoBufferProfile)profile).CanDispose = dispose; // else if (profile is ChoStreamProfile) // ((ChoStreamProfile)profile).CanDispose = dispose; //} private static string GetProfileName(string name, out MemberInfo memberInfo, out string typeProfileFileName, out ChoProfileAttribute memberProfileAttribute, out ChoProfileAttribute typeProfileAttribute) { typeProfileFileName = null; StackFrame stackFrame = ChoStackTrace.GetStackFrame(typeof(ChoProfile).Namespace); memberInfo = stackFrame.GetMethod(); memberProfileAttribute = null; foreach (ChoProfileAttribute profileAttribute in ChoType.GetMemberAttributesByBaseType <ChoProfileAttribute>(memberInfo)) { if (profileAttribute.Name == name) { memberProfileAttribute = profileAttribute; break; } } ChoProfileAttribute emptyTypeProfileAttribute = null; typeProfileAttribute = null; foreach (ChoProfileAttribute profileAttribute in ChoType.GetAttributes <ChoProfileAttribute>(memberInfo.ReflectedType)) { if (String.IsNullOrEmpty(profileAttribute.Name)) { emptyTypeProfileAttribute = profileAttribute; } if (profileAttribute.Name == name) { typeProfileAttribute = profileAttribute; break; } } if (typeProfileAttribute == null) { if (emptyTypeProfileAttribute == null) { typeProfileFileName = GLOBAL_PROFILE_NAME; } else { typeProfileFileName = "{0}_{1}_{2}_{3}".FormatString(name.IsNullOrEmpty() ? "Default" : name, "Type", ChoThreadLocalStorage.Target == null ? 0 : ChoThreadLocalStorage.Target.GetHashCode(), ChoPropertyManager.ExpandProperties(ChoThreadLocalStorage.Target, emptyTypeProfileAttribute.Name)); } } else { typeProfileFileName = "{0}_{1}_{2}_{3}".FormatString(name.IsNullOrEmpty() ? "Default" : name, "Type", ChoThreadLocalStorage.Target == null ? 0 : ChoThreadLocalStorage.Target.GetHashCode(), ChoPropertyManager.ExpandProperties(ChoThreadLocalStorage.Target, typeProfileAttribute.Name)); } if (memberProfileAttribute != null) { return("{0}_{1}_{2}_{3}".FormatString(name.IsNullOrEmpty() ? "Default" : name, memberInfo.Name, ChoThreadLocalStorage.Target == null ? 0 : ChoThreadLocalStorage.Target.GetHashCode(), ChoPropertyManager.ExpandProperties(ChoThreadLocalStorage.Target, memberProfileAttribute.Name))); } else { return(typeProfileFileName); } }