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


C# SortedSet.LastOrDefault方法代码示例

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


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

示例1: GetSetupStatus

        public SetupStatus GetSetupStatus()
        {
            var setupStatus = new SetupStatus();

            try
            {
                if (string.IsNullOrEmpty(Configuration.ContextType))
                    return null;

                if (string.IsNullOrEmpty(Configuration.ScriptsBase))
                    return null;

                var schemaContext = (ISchemaContext)Activator.CreateInstanceFrom(_executingAssembly, Configuration.ContextType).Unwrap();

                if (schemaContext == null)
                    return null;

                var abstractList = schemaContext.GetScriptsInstalled();

                schemaContext.Dispose();

                var allEntries = abstractList
                    .Select(a => new SchemaVersion
                    {
                        ScriptPath = a.ScriptPath,
                        MajorVersion = a.MajorVersion,
                        MinorVersion = a.MinorVersion,
                        ScriptVersion = a.ScriptVersion
                    })
                    .ToList();
                allEntries.Sort(new SchemaVersionComparer());

                var schemaInstance = allEntries.LastOrDefault();

                if (schemaInstance == null)
                {
                    setupStatus.StatusCode = SetupStatusCode.NotInstalled;
                    setupStatus.Message = "None of the scripts have been run";

                    return setupStatus;
                }

                var sortedList = new SortedSet<SchemaVersion>();
                var filePath = HostingEnvironment.MapPath(Configuration.ScriptsBase);
                if (filePath != null)
                {
                    var files = Directory.GetFiles(filePath).ToList();
                    files.ForEach(f =>
                    {
                        var schemaItem = f.Parse();
                        sortedList.Add(schemaItem);
                    });
                }

                var lastInstance = sortedList.LastOrDefault();

                if (lastInstance != null && lastInstance.Equals(schemaInstance))
                {
                    setupStatus.StatusCode = SetupStatusCode.NoUpdates;
                    setupStatus.Message = "Your instance is up to date!";

                    return setupStatus;
                }

                var scriptsToBeRan = sortedList.Except(allEntries, new SchemaVersionEqualityComparer()).ToList();

                setupStatus.StatusCode = SetupStatusCode.HasUpdates;
                setupStatus.Message = "Your instance has some updates";
                setupStatus.FullPathsOfScripts = scriptsToBeRan;
                setupStatus.ScriptsPending = scriptsToBeRan.Select(s => Path.GetFileName(s.ScriptPath)).ToList();

                return setupStatus;
            }
            catch (Exception exception)
            {
                if (exception.Message.Contains("Invalid object name"))
                {
                    setupStatus.StatusCode = SetupStatusCode.DatabaseNotSetup;
                    setupStatus.Message = "Database has not been setup";
                }
                else
                {
                    setupStatus.StatusCode = SetupStatusCode.DatabaseError;
                    setupStatus.Message = exception.Message;
                }
            }

            return setupStatus;
        }
开发者ID:karthik25,项目名称:db-status-provider,代码行数:89,代码来源:SetupStatusGenerator.cs


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