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


C# Maybe.Convert方法代码示例

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


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

示例1: Run

        /// <summary>
        /// Run the hosted runtime, blocking the calling thread.
        /// </summary>
        /// <returns>True if the worker stopped as planned (e.g. due to updated assemblies)</returns>
        public bool Run(Maybe<ICloudConfigurationSettings> externalRoleConfiguration)
        {
            _stoppedWaitHandle.Reset();

            // Runtime IoC Setup

            var runtimeBuilder = new ContainerBuilder();
            runtimeBuilder.RegisterModule(new CloudModule());
            runtimeBuilder.RegisterModule(externalRoleConfiguration.Convert(s =>  new CloudConfigurationModule(s), () => new CloudConfigurationModule()));
            runtimeBuilder.RegisterType<Runtime>().InstancePerDependency();

            // Run

            using (var runtimeContainer = runtimeBuilder.Build())
            {
                var log = runtimeContainer.Resolve<ILog>();

                AppDomain.CurrentDomain.UnhandledException += (sender, e) => log.ErrorFormat(
                    e.ExceptionObject as Exception,
                    "Runtime Host: An unhandled {0} exception occurred on worker {1} in a background thread. The Runtime Host will be restarted: {2}.",
                    e.ExceptionObject.GetType().Name, CloudEnvironment.PartitionKey, e.IsTerminating);

                _runtime = null;
                try
                {
                    _runtime = runtimeContainer.Resolve<Runtime>();
                    _runtime.RuntimeContainer = runtimeContainer;

                    // runtime endlessly keeps pinging queues for pending work
                    _runtime.Execute();

                    log.DebugFormat("Runtime Host: Runtime has stopped cleanly on worker {0}.",
                        CloudEnvironment.PartitionKey);
                }
                catch (TypeLoadException typeLoadException)
                {
                    log.ErrorFormat(typeLoadException, "Runtime Host: Type {0} could not be loaded. The Runtime Host will be restarted.",
                        typeLoadException.TypeName);
                }
                catch (FileLoadException fileLoadException)
                {
                    // Tentatively: referenced assembly is missing
                    log.Fatal(fileLoadException, "Runtime Host: Could not load assembly probably due to a missing reference assembly. The Runtime Host will be restarted.");
                }
                catch (SecurityException securityException)
                {
                    // Tentatively: assembly cannot be loaded due to security config
                    log.FatalFormat(securityException, "Runtime Host: Could not load assembly {0} probably due to security configuration. The Runtime Host will be restarted.",
                        securityException.FailedAssemblyInfo);
                }
                catch (TriggerRestartException)
                {
                    log.DebugFormat("Runtime Host: Triggered to stop execution on worker {0}. The Role Instance will be recycled and the Runtime Host restarted.",
                        CloudEnvironment.PartitionKey);

                    return true;
                }
                catch (ThreadAbortException)
                {
                    Thread.ResetAbort();
                    log.DebugFormat("Runtime Host: execution was aborted on worker {0}. The Runtime is stopping.", CloudEnvironment.PartitionKey);
                }
                catch (Exception ex)
                {
                    // Generic exception
                    log.ErrorFormat(ex, "Runtime Host: An unhandled {0} exception occurred on worker {1}. The Runtime Host will be restarted.",
                        ex.GetType().Name, CloudEnvironment.PartitionKey);
                }
                finally
                {
                    _stoppedWaitHandle.Set();
                    _runtime = null;
                }

                return false;
            }
        }
开发者ID:alexmg,项目名称:lokad-cloud,代码行数:81,代码来源:SingleRuntimeHost.cs


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