Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ CreateManifestAndDescriptors()

static byte[] System.Diagnostics.Tracing.EventSource.CreateManifestAndDescriptors ( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type eventSourceType,
string eventSourceDllName,
EventSource source,
EventManifestOptions flags = EventManifestOptions::None )
inlinestaticprivateinherited

Definition at line 2181 of file EventSource.cs.

2182 {
2183 ManifestBuilder manifestBuilder = null;
2184 bool flag = source == null || !source.SelfDescribingEvents;
2185 Exception ex = null;
2186 byte[] result = null;
2187 if (eventSourceType.IsAbstract && (flags & EventManifestOptions.Strict) == 0)
2188 {
2189 return null;
2190 }
2191 try
2192 {
2193 MethodInfo[] methods = eventSourceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
2194 int num = 1;
2195 EventMetadata[] eventData = null;
2197 if (source != null || (flags & EventManifestOptions.Strict) != 0)
2198 {
2199 eventData = new EventMetadata[methods.Length + 1];
2200 eventData[0].Name = "";
2201 }
2202 ResourceManager resources = null;
2203 EventSourceAttribute eventSourceAttribute = (EventSourceAttribute)GetCustomAttributeHelper(eventSourceType, typeof(EventSourceAttribute), flags);
2204 if (eventSourceAttribute != null && eventSourceAttribute.LocalizationResources != null)
2205 {
2206 resources = new ResourceManager(eventSourceAttribute.LocalizationResources, eventSourceType.Assembly);
2207 }
2208 manifestBuilder = ((source == null) ? new ManifestBuilder(GetName(eventSourceType, flags), GetGuid(eventSourceType), eventSourceDllName, resources, flags) : new ManifestBuilder(source.Name, source.Guid, eventSourceDllName, resources, flags));
2209 manifestBuilder.StartEvent("EventSourceMessage", new EventAttribute(0)
2210 {
2211 Level = EventLevel.LogAlways,
2212 Task = (EventTask)65534
2213 });
2214 manifestBuilder.AddEventParameter(typeof(string), "message");
2215 manifestBuilder.EndEvent();
2216 if ((flags & EventManifestOptions.Strict) != 0)
2217 {
2218 if (!(GetEventSourceBaseType(eventSourceType, (flags & EventManifestOptions.AllowEventSourceOverride) != 0, eventSourceType.Assembly.ReflectionOnly) != null))
2219 {
2220 manifestBuilder.ManifestError(SR.EventSource_TypeMustDeriveFromEventSource);
2221 }
2222 if (!eventSourceType.IsAbstract && !eventSourceType.IsSealed)
2223 {
2224 manifestBuilder.ManifestError(SR.EventSource_TypeMustBeSealedOrAbstract);
2225 }
2226 }
2227 string[] array = new string[3] { "Keywords", "Tasks", "Opcodes" };
2228 foreach (string text in array)
2229 {
2230 Type nestedType = eventSourceType.GetNestedType(text);
2231 if (!(nestedType != null))
2232 {
2233 continue;
2234 }
2235 if (eventSourceType.IsAbstract)
2236 {
2237 manifestBuilder.ManifestError(SR.Format(SR.EventSource_AbstractMustNotDeclareKTOC, nestedType.Name));
2238 continue;
2239 }
2240 FieldInfo[] fields = nestedType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
2241 foreach (FieldInfo staticField in fields)
2242 {
2244 }
2245 }
2246 manifestBuilder.AddKeyword("Session3", 17592186044416uL);
2247 manifestBuilder.AddKeyword("Session2", 35184372088832uL);
2248 manifestBuilder.AddKeyword("Session1", 70368744177664uL);
2249 manifestBuilder.AddKeyword("Session0", 140737488355328uL);
2251 {
2252 foreach (MethodInfo methodInfo in methods)
2253 {
2254 ParameterInfo[] args = methodInfo.GetParameters();
2255 EventAttribute eventAttribute = (EventAttribute)GetCustomAttributeHelper(methodInfo, typeof(EventAttribute), flags);
2256 if (methodInfo.IsStatic)
2257 {
2258 continue;
2259 }
2260 if (eventSourceType.IsAbstract)
2261 {
2262 if (eventAttribute != null)
2263 {
2264 manifestBuilder.ManifestError(SR.Format(SR.EventSource_AbstractMustNotDeclareEventMethods, methodInfo.Name, eventAttribute.EventId));
2265 }
2266 continue;
2267 }
2268 if (eventAttribute == null)
2269 {
2270 if (methodInfo.ReturnType != typeof(void) || methodInfo.IsVirtual || IsCustomAttributeDefinedHelper(methodInfo, typeof(NonEventAttribute), flags))
2271 {
2272 continue;
2273 }
2274 EventAttribute eventAttribute2 = new EventAttribute(num);
2276 }
2277 else if (eventAttribute.EventId <= 0)
2278 {
2279 manifestBuilder.ManifestError(SR.Format(SR.EventSource_NeedPositiveId, methodInfo.Name), runtimeCritical: true);
2280 continue;
2281 }
2282 if (methodInfo.Name.LastIndexOf('.') >= 0)
2283 {
2284 manifestBuilder.ManifestError(SR.Format(SR.EventSource_EventMustNotBeExplicitImplementation, methodInfo.Name, eventAttribute.EventId));
2285 }
2286 num++;
2287 string name = methodInfo.Name;
2288 if (eventAttribute.Opcode == EventOpcode.Info)
2289 {
2290 bool flag2 = eventAttribute.Task == EventTask.None;
2291 if (flag2)
2292 {
2293 eventAttribute.Task = (EventTask)(65534 - eventAttribute.EventId);
2294 }
2295 if (!eventAttribute.IsOpcodeSet)
2296 {
2297 eventAttribute.Opcode = GetOpcodeWithDefault(EventOpcode.Info, name);
2298 }
2299 if (flag2)
2300 {
2301 if (eventAttribute.Opcode == EventOpcode.Start)
2302 {
2303 string text2 = name.Substring(0, name.Length - "Start".Length);
2304 if (string.Compare(name, 0, text2, 0, text2.Length) == 0 && string.Compare(name, text2.Length, "Start", 0, Math.Max(name.Length - text2.Length, "Start".Length)) == 0)
2305 {
2306 manifestBuilder.AddTask(text2, (int)eventAttribute.Task);
2307 }
2308 }
2309 else if (eventAttribute.Opcode == EventOpcode.Stop)
2310 {
2311 int num2 = eventAttribute.EventId - 1;
2312 if (eventData != null && num2 < eventData.Length)
2313 {
2314 EventMetadata eventMetadata = eventData[num2];
2315 string text3 = name.Substring(0, name.Length - "Stop".Length);
2316 if (eventMetadata.Descriptor.Opcode == 1 && string.Compare(eventMetadata.Name, 0, text3, 0, text3.Length) == 0 && string.Compare(eventMetadata.Name, text3.Length, "Start", 0, Math.Max(eventMetadata.Name.Length - text3.Length, "Start".Length)) == 0)
2317 {
2318 eventAttribute.Task = (EventTask)eventMetadata.Descriptor.Task;
2319 flag2 = false;
2320 }
2321 }
2322 if (flag2 && (flags & EventManifestOptions.Strict) != 0)
2323 {
2324 throw new ArgumentException(SR.EventSource_StopsFollowStarts);
2325 }
2326 }
2327 }
2328 }
2330 if (source == null || !source.SelfDescribingEvents)
2331 {
2332 manifestBuilder.StartEvent(name, eventAttribute);
2333 for (int l = 0; l < args.Length; l++)
2334 {
2335 manifestBuilder.AddEventParameter(args[l].ParameterType, args[l].Name);
2336 }
2337 manifestBuilder.EndEvent();
2338 }
2339 if (source == null && (flags & EventManifestOptions.Strict) == 0)
2340 {
2341 continue;
2342 }
2344 if (eventAttribute.Channel != 0)
2345 {
2346 eventAttribute.Keywords |= (EventKeywords)manifestBuilder.GetChannelKeyword(eventAttribute.Channel, (ulong)eventAttribute.Keywords);
2347 }
2348 if (manifestBuilder.HasResources)
2349 {
2350 string key = "event_" + name;
2352 if (localizedMessage != null)
2353 {
2354 eventAttribute.Message = localizedMessage;
2355 }
2356 }
2358 }
2359 }
2360 NameInfo.ReserveEventIDsBelow(num);
2361 if (source != null)
2362 {
2364 source.m_eventData = eventData;
2365 source.m_channelData = manifestBuilder.GetChannelData();
2366 }
2367 if (!eventSourceType.IsAbstract && (source == null || !source.SelfDescribingEvents))
2368 {
2369 flag = (flags & EventManifestOptions.OnlyIfNeededForRegistration) == 0 || manifestBuilder.GetChannelData().Length != 0;
2370 if (!flag && (flags & EventManifestOptions.Strict) == 0)
2371 {
2372 return null;
2373 }
2374 result = manifestBuilder.CreateManifest();
2375 }
2376 }
2377 catch (Exception ex2)
2378 {
2379 if ((flags & EventManifestOptions.Strict) == 0)
2380 {
2381 throw;
2382 }
2383 ex = ex2;
2384 }
2385 if ((flags & EventManifestOptions.Strict) != 0 && ((manifestBuilder != null && manifestBuilder.Errors.Count > 0) || ex != null))
2386 {
2387 string text4 = string.Empty;
2388 if (manifestBuilder != null && manifestBuilder.Errors.Count > 0)
2389 {
2390 bool flag3 = true;
2391 foreach (string error in manifestBuilder.Errors)
2392 {
2393 if (!flag3)
2394 {
2395 text4 += Environment.NewLine;
2396 }
2397 flag3 = false;
2398 text4 += error;
2399 }
2400 }
2401 else
2402 {
2403 text4 = "Unexpected error: " + ex.Message;
2404 }
2405 throw new ArgumentException(text4, ex);
2406 }
2407 if (!flag)
2408 {
2409 return null;
2410 }
2411 return result;
2412 }
static void AddProviderEnumKind(ManifestBuilder manifest, FieldInfo staticField, string providerEnumKind)
static Guid GetGuid(Type eventSourceType)
static string GetName(Type eventSourceType)
static Attribute GetCustomAttributeHelper(MemberInfo member, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.PublicProperties)] Type attributeType, EventManifestOptions flags=EventManifestOptions.None)
static void DebugCheckEvent(ref Dictionary< string, string > eventsByName, EventMetadata[] eventData, MethodInfo method, EventAttribute eventAttribute, ManifestBuilder manifest, EventManifestOptions options)
static void TrimEventDescriptors(ref EventMetadata[] eventData)
static Type GetEventSourceBaseType(Type eventSourceType, bool allowEventSourceOverride, bool reflectionOnly)
static EventOpcode GetOpcodeWithDefault(EventOpcode opcode, string eventName)
static bool IsCustomAttributeDefinedHelper(MemberInfo member, Type attributeType, EventManifestOptions flags=EventManifestOptions.None)
static void AddEventDescriptor([NotNull] ref EventMetadata[] eventData, string eventName, EventAttribute eventAttribute, ParameterInfo[] eventParameters, bool hasRelatedActivityID)
static bool RemoveFirstArgIfRelatedActivityId(ref ParameterInfo[] args)
static CultureInfo CurrentUICulture

References System.Diagnostics.Tracing.EventSource.AddEventDescriptor(), System.Diagnostics.Tracing.EventSource.AddProviderEnumKind(), System.array, System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Globalization.CultureInfo.CurrentUICulture, System.Diagnostics.Tracing.EventSource.DebugCheckEvent(), System.SR.EventSource_AbstractMustNotDeclareEventMethods, System.SR.EventSource_AbstractMustNotDeclareKTOC, System.SR.EventSource_EventMustNotBeExplicitImplementation, System.SR.EventSource_NeedPositiveId, System.SR.EventSource_StopsFollowStarts, System.SR.EventSource_TypeMustBeSealedOrAbstract, System.SR.EventSource_TypeMustDeriveFromEventSource, System.SR.Format(), System.Diagnostics.Tracing.EventSource.GetCustomAttributeHelper(), System.Diagnostics.Tracing.EventSource.GetEventSourceBaseType(), System.Diagnostics.Tracing.EventSource.GetGuid(), System.Diagnostics.Tracing.EventSource.GetName(), System.Diagnostics.Tracing.EventSource.GetOpcodeWithDefault(), System.Diagnostics.Tracing.EventSource.IsCustomAttributeDefinedHelper(), System.key, System.Math.Max(), System.Diagnostics.Tracing.EventSource.Name, System.Environment.NewLine, System.Diagnostics.Tracing.EventSource.RemoveFirstArgIfRelatedActivityId(), System.Diagnostics.Tracing.NameInfo.ReserveEventIDsBelow(), System.source, System.text, and System.Diagnostics.Tracing.EventSource.TrimEventDescriptors().

Referenced by System.Diagnostics.Tracing.EventSource.EnsureDescriptorsInitialized(), and System.Diagnostics.Tracing.EventSource.GenerateManifest().