当前位置: 首页>>代码示例>>C#>>正文


C# IAnalytics.UnexpectedException方法代码示例

本文整理汇总了C#中IAnalytics.UnexpectedException方法的典型用法代码示例。如果您正苦于以下问题:C# IAnalytics.UnexpectedException方法的具体用法?C# IAnalytics.UnexpectedException怎么用?C# IAnalytics.UnexpectedException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAnalytics的用法示例。


在下文中一共展示了IAnalytics.UnexpectedException方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Open

        public static DeploymentStatusFile Open(string id, IEnvironment environment, IAnalytics analytics, IOperationLock statusLock)
        {
            return statusLock.LockOperation(() =>
            {
                string path = Path.Combine(environment.DeploymentsPath, id, StatusFile);

                if (!FileSystemHelpers.FileExists(path))
                {
                    return null;
                }

                try
                {
                    XDocument document = null;
                    using (var stream = FileSystemHelpers.OpenRead(path))
                    {
                        document = XDocument.Load(stream);
                    }

                    return new DeploymentStatusFile(id, environment, statusLock, document);
                }
                catch (Exception ex)
                {
                    // in the scenario where w3wp is abruptly terminated while xml is being written,
                    // we may end up with corrupted xml.  we will handle the error and remove the problematic directory.
                    analytics.UnexpectedException(ex);

                    FileSystemHelpers.DeleteDirectorySafe(Path.GetDirectoryName(path), ignoreErrors: true);

                    // it is ok to return null as callers already handle null.
                    return null;
                }
            }, DeploymentStatusManager.LockTimeout);
        }
开发者ID:Walk4Muscle,项目名称:kudu,代码行数:34,代码来源:DeploymentStatusFile.cs

示例2: UpdateAppConfig

        internal static void UpdateAppConfig(string configFilePath, IAnalytics analytics)
        {
            try
            {
                var settings = SettingsProcessor.Instance;

                bool updateXml = false;

                // Read app.config
                string exeFilePath = configFilePath.Substring(0, configFilePath.Length - ".config".Length);

                // Only continue to update config file if the corresponding exe file exists
                if (!FileSystemHelpers.FileExists(exeFilePath))
                {
                    return;
                }

                // save the LastWriteTime before our modification, so we can restore
                // it below
                FileInfo fileInfo = new FileInfo(configFilePath);
                DateTime lastWriteTime = fileInfo.LastWriteTimeUtc;

                Configuration config = ConfigurationManager.OpenExeConfiguration(exeFilePath);

                foreach (var appSetting in settings.AppSettings)
                {
                    config.AppSettings.Settings.Remove(appSetting.Key);
                    config.AppSettings.Settings.Add(appSetting.Key, appSetting.Value);
                    updateXml = true;
                }

                foreach (ConnectionStringSettings connectionString in settings.ConnectionStrings)
                {
                    ConnectionStringSettings currentConnectionString = config.ConnectionStrings.ConnectionStrings[connectionString.Name];
                    if (currentConnectionString != null)
                    {
                        // Update provider name if connection string already exists and provider name is null (custom type)
                        connectionString.ProviderName = connectionString.ProviderName ?? currentConnectionString.ProviderName;
                    }

                    config.ConnectionStrings.ConnectionStrings.Remove(connectionString.Name);
                    config.ConnectionStrings.ConnectionStrings.Add(connectionString);

                    updateXml = true;
                }

                if (updateXml)
                {
                    // Write updated app.config
                    config.Save();
                }

                // we need to restore the previous last update time so our file write
                // doesn't cause the job directory to be considered dirty
                fileInfo.LastWriteTimeUtc = lastWriteTime;
            }
            catch (Exception ex)
            {
                analytics.UnexpectedException(ex);
            }
        }
开发者ID:NorimaConsulting,项目名称:kudu,代码行数:61,代码来源:BaseJobRunner.cs

示例3: UpdateAppConfigAddTraceListeners

        /// <summary>
        /// Updates the app.config using XML directly for injecting trace providers.
        /// </summary>
        internal static void UpdateAppConfigAddTraceListeners(string configFilePath, IAnalytics analytics)
        {
            try
            {
                var xmlConfig = XDocument.Load(configFilePath);

                // save the LastWriteTime before our modification, so we can restore
                // it below
                FileInfo fileInfo = new FileInfo(configFilePath);
                DateTime lastWriteTime = fileInfo.LastWriteTimeUtc;

                // Make sure the trace listeners section available otherwise create it
                var configurationElement = GetOrCreateElement(xmlConfig, "configuration");
                var systemDiagnosticsElement = GetOrCreateElement(configurationElement, "system.diagnostics");
                var traceElement = GetOrCreateElement(systemDiagnosticsElement, "trace");
                var listenersElement = GetOrCreateElement(traceElement, "listeners");

                // Inject existing trace providers to the target app.config
                foreach (TraceListener listener in Trace.Listeners)
                {
                    // Ignore the default trace provider
                    if (String.Equals(listener.Name, "default", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    // Do not add a trace provider if it already exists (by name)
                    XElement listenerElement = listenersElement.Elements().FirstOrDefault(xElement =>
                    {
                        XAttribute nameAttribute = xElement.Attribute("name");
                        return nameAttribute != null && String.Equals(nameAttribute.Value, listener.Name, StringComparison.OrdinalIgnoreCase);
                    });

                    if (listenerElement == null)
                    {
                        var addElement = new XElement("add");
                        addElement.Add(new XAttribute("name", listener.Name));
                        addElement.Add(new XAttribute("type", listener.GetType().AssemblyQualifiedName));
                        listenersElement.AddFirst(addElement);
                    }
                }

                FileSystemHelpers.WriteAllText(configFilePath, xmlConfig.ToString());

                // we need to restore the previous last update time so our file write
                // doesn't cause the job directory to be considered dirty
                fileInfo.LastWriteTimeUtc = lastWriteTime;
            }
            catch (Exception ex)
            {
                analytics.UnexpectedException(ex);
            }
        }
开发者ID:NorimaConsulting,项目名称:kudu,代码行数:56,代码来源:BaseJobRunner.cs

示例4: IsAnyInstallationRequireRestart

        /// <summary>
        /// <para>Scan every site extensions, check if there is any successful installation</para>
        /// <para>Looking for below cases:</para>
        /// <para>if not install to webroot, trigger restart; if install to webroot and with applicationHost.xdt file, trigger restart.</para>
        /// </summary>
        /// <param name="siteExtensionStatusRoot">should be $ROOT\site\siteextensions</param>
        /// <param name="siteExtensionRoot">should be $ROOT\SiteExtensions</param>
        public static bool IsAnyInstallationRequireRestart(string siteExtensionStatusRoot, string siteExtensionRoot, ITracer tracer, IAnalytics analytics)
        {
            try
            {
                using (tracer.Step("Checking if there is any installation require site restart ..."))
                {
                    string[] packageDirs = FileSystemHelpers.GetDirectories(siteExtensionStatusRoot);
                    // folder name is the package id
                    foreach (var dir in packageDirs)
                    {
                        try
                        {
                            DirectoryInfo dirInfo = new DirectoryInfo(dir);
                            var statusSettings = new SiteExtensionStatus(siteExtensionStatusRoot, dirInfo.Name, tracer);
                            if (statusSettings.IsSiteExtensionRequireRestart(siteExtensionRoot))
                            {
                                return true;
                            }
                        }
                        catch (Exception ex)
                        {
                            analytics.UnexpectedException(ex, trace: false);
                            tracer.TraceError(ex, "Failed to query {0} under {1}, continus to check others ...", _statusSettingsFileName, dir);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                analytics.UnexpectedException(ex, trace: false);
                tracer.TraceError(ex, "Not able to query directory under {0}", siteExtensionStatusRoot);
            }

            return false;
        }
开发者ID:NorimaConsulting,项目名称:kudu,代码行数:42,代码来源:SiteExtensionStatus.cs


注:本文中的IAnalytics.UnexpectedException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。