void FillBasicWmiDataFields(ref UnsafeNativeMethods.WmiData wmiData, WebBaseEvent eventRaised) { WebApplicationInformation appInfo = WebBaseEvent.ApplicationInformation; wmiData.eventType = (int)WebBaseEvent.WebEventTypeFromWebEvent(eventRaised); // Note: WMI sint64 requires a string param // Data contained in WebBaseEvent wmiData.eventCode = eventRaised.EventCode; wmiData.eventDetailCode = eventRaised.EventDetailCode; wmiData.eventTime = WmiFormatTime(eventRaised.EventTime); wmiData.eventMessage = eventRaised.Message; wmiData.sequenceNumber = eventRaised.EventSequence.ToString(CultureInfo.InstalledUICulture); wmiData.occurrence = eventRaised.EventOccurrence.ToString(CultureInfo.InstalledUICulture); wmiData.eventId = eventRaised.EventID.ToString("N", CultureInfo.InstalledUICulture); wmiData.appDomain = appInfo.ApplicationDomain; wmiData.trustLevel = appInfo.TrustLevel; wmiData.appVirtualPath = appInfo.ApplicationVirtualPath; wmiData.appPath = appInfo.ApplicationPath; wmiData.machineName = appInfo.MachineName; if (eventRaised.IsSystemEvent) { wmiData.details = String.Empty; } else { WebEventFormatter formatter = new WebEventFormatter(); eventRaised.FormatCustomEventDetails(formatter); wmiData.details = formatter.ToString(); } }
void FillRequestWmiDataFields(ref UnsafeNativeMethods.WmiData wmiData, WebRequestInformation reqInfo) { string user; string authType; bool authed; IPrincipal iprincipal = reqInfo.Principal; if (iprincipal == null) { user = String.Empty; authType = String.Empty; authed = false; } else { IIdentity id = iprincipal.Identity; user = id.Name; authed = id.IsAuthenticated; authType = id.AuthenticationType; } wmiData.requestUrl = reqInfo.RequestUrl; wmiData.requestPath = reqInfo.RequestPath; wmiData.userHostAddress = reqInfo.UserHostAddress; wmiData.userName = user; wmiData.userAuthenticated = authed; wmiData.userAuthenticationType = authType; wmiData.requestThreadAccountName = reqInfo.ThreadAccountName; }
void FillErrorWmiDataFields(ref UnsafeNativeMethods.WmiData wmiData, WebThreadInformation threadInfo) { wmiData.threadId = threadInfo.ThreadID; wmiData.threadAccountName = threadInfo.ThreadAccountName; wmiData.stackTrace = threadInfo.StackTrace; wmiData.isImpersonating = threadInfo.IsImpersonating; }
private ClientConfigPaths(string exePath, bool includeUserConfig) { _includesUserConfig = includeUserConfig; Assembly exeAssembly = null; string applicationUri = null; string applicationFilename = null; // get the assembly and applicationUri for the file if (exePath == null) { // First check if a configuration file has been set for this app domain. If so, we will use that. // The CLR would already have normalized this, so no further processing necessary. AppDomain domain = AppDomain.CurrentDomain; AppDomainSetup setup = domain.SetupInformation; _applicationConfigUri = setup.ConfigurationFile; // Now figure out the application path. exeAssembly = Assembly.GetEntryAssembly(); if (exeAssembly != null) { _hasEntryAssembly = true; applicationUri = exeAssembly.CodeBase; bool isFile = false; // If it is a local file URI, convert it to its filename, without invoking Uri class. // example: "file:///C:/WINNT/Microsoft.NET/Framework/v2.0.x86fre/csc.exe" if (StringUtil.StartsWithIgnoreCase(applicationUri, FILE_URI_LOCAL)) { isFile = true; applicationUri = applicationUri.Substring(FILE_URI_LOCAL.Length); } // If it is a UNC file URI, convert it to its filename, without invoking Uri class. // example: "file://server/share/csc.exe" else if (StringUtil.StartsWithIgnoreCase(applicationUri, FILE_URI_UNC)) { isFile = true; applicationUri = applicationUri.Substring(FILE_URI.Length); } if (isFile) { applicationUri = applicationUri.Replace('/', '\\'); applicationFilename = applicationUri; } else { applicationUri = exeAssembly.EscapedCodeBase; } } else { StringBuilder sb = new StringBuilder(MAX_PATH); UnsafeNativeMethods.GetModuleFileName(new HandleRef(null, IntPtr.Zero), sb, sb.Capacity); applicationUri = Path.GetFullPath(sb.ToString()); applicationFilename = applicationUri; } } else { applicationUri = Path.GetFullPath(exePath); if (!FileUtil.FileExists(applicationUri, false)) { throw ExceptionUtil.ParameterInvalid("exePath"); } applicationFilename = applicationUri; } // Fallback if we haven't set the app config file path yet. if (_applicationConfigUri == null) { _applicationConfigUri = applicationUri + ConfigExtension; } // Set application path _applicationUri = applicationUri; // In the case when exePath was explicitly supplied, we will not be able to // construct user.config paths, so quit here. if (exePath != null) { return; } // Skip expensive initialization of user config file information if requested. if (!_includesUserConfig) { return; } bool isHttp = StringUtil.StartsWithIgnoreCase(_applicationConfigUri, HTTP_URI); SetNamesAndVersion(applicationFilename, exeAssembly, isHttp); // Check if this is a clickonce deployed application. If so, point the user config // files to the clickonce data directory. if (this.IsClickOnceDeployed(AppDomain.CurrentDomain)) { string dataPath = AppDomain.CurrentDomain.GetData(ClickOnceDataDirectory) as string; string versionSuffix = Validate(_productVersion, false); // NOTE: No roaming config for clickonce - not supported. if (Path.IsPathRooted(dataPath)) { _localConfigDirectory = CombineIfValid(dataPath, versionSuffix); _localConfigFilename = CombineIfValid(_localConfigDirectory, UserConfigFilename); } } else if (!isHttp) { // If we get the config from http, we do not have a roaming or local config directory, // as it cannot be edited by the app in those cases because it does not have Full Trust. // suffix for user config paths string part1 = Validate(_companyName, true); string validAppDomainName = Validate(AppDomain.CurrentDomain.FriendlyName, true); string applicationUriLower = !String.IsNullOrEmpty(_applicationUri) ? _applicationUri.ToLower(CultureInfo.InvariantCulture) : null; string namePrefix = !String.IsNullOrEmpty(validAppDomainName) ? validAppDomainName : Validate(_productName, true); string hashSuffix = string.Empty; string part2 = (!String.IsNullOrEmpty(namePrefix) && !String.IsNullOrEmpty(hashSuffix)) ? namePrefix + hashSuffix : null; string part3 = Validate(_productVersion, false); string dirSuffix = CombineIfValid(CombineIfValid(part1, part2), part3); } }