本文整理汇总了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;
}