本文整理汇总了C#中StatisAnalysisSession类的典型用法代码示例。如果您正苦于以下问题:C# StatisAnalysisSession类的具体用法?C# StatisAnalysisSession怎么用?C# StatisAnalysisSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StatisAnalysisSession类属于命名空间,在下文中一共展示了StatisAnalysisSession类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUnlockedAchievements
protected override IEnumerable<Achievement> GetUnlockedAchievements(StatisAnalysisSession statisAnalysisSession, IEnumerable<Achievement> availableAchievements)
{
var unlockedAchievements = new ConcurrentBag<Achievement>();
var tasks = new Task[availableAchievements.Count()];
var i = 0;
foreach (var uncompletedAchievement in availableAchievements)
{
var a = uncompletedAchievement;
tasks[i++] = Task.Factory.StartNew(() =>
{
/* Technically we create a lot of objects all the time.
* It's possible that these objects could have a lifespan longer than just a session.
* However maintaining state is always a PITA */
var achievement = (StaticAnalysisAchievementBase)Activator.CreateInstance(a.AchievementType);
if (achievement.IsAchievementUnlocked(statisAnalysisSession))
{
a.CodeOrigin = achievement.AchievementCodeOrigin;
a.IsCompleted = true;
unlockedAchievements.Add(a);
}
});
}
Task.WaitAll(tasks);
return unlockedAchievements;
}
示例2: IsAchievementUnlocked
/// <summary>
/// Detects the achievement.
/// </summary>
/// <param name="statisAnalysisSession">The detection session.</param>
/// <returns><c>true</c> if the ChallengeRunner returned 'OK'; otherwise <c>false</c>.</returns>
public override bool IsAchievementUnlocked(StatisAnalysisSession statisAnalysisSession)
{
if (string.IsNullOrEmpty(statisAnalysisSession.StaticAnalysisManifest.ActiveProjectOutputDirectory))
{
return false;
}
var dlls = new List<string>();
// Some directory listing hackery
dlls.AddRange(GetOutputFiles(statisAnalysisSession, "*.dll"));
dlls.AddRange(GetOutputFiles(statisAnalysisSession, "*.exe"));
// If the Strokes.Challenges.Student-dll isn't in the build output,
// this project can with certainty be said to not be a challenge-solve attempt.
if (!dlls.Any(dll => dll.Contains("Strokes.Challenges.dll")))
return false;
var processStartInfo = new ProcessStartInfo();
processStartInfo.UseShellExecute = false;
processStartInfo.WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
processStartInfo.FileName = Path.Combine(processStartInfo.WorkingDirectory, "Strokes.ChallengeRunner.exe");
processStartInfo.CreateNoWindow = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.Arguments = string.Join(" ",
statisAnalysisSession.StaticAnalysisManifest.ActiveProjectOutputDirectory.Replace(" ", "*"), ChallengeRunner);
var process = Process.Start(processStartInfo);
var output = process.StandardOutput.ReadToEnd();
var error = process.StandardError.ReadToEnd();
return output == "OK";
}
示例3: CreateVisitor
protected override AbstractAchievementVisitor CreateVisitor(StatisAnalysisSession statisAnalysisSession)
{
return new Visitor()
{
MethodToFind = methodName,
Requirements = RequiredOverloads
};
}
示例4: IsAchievementUnlocked
public override bool IsAchievementUnlocked(StatisAnalysisSession statisAnalysisSession)
{
// Return out if there are no files to check achievements in.
if (!statisAnalysisSession.StaticAnalysisManifest.ChangedFiles.Any())
{
return false;
}
// Obtain a session object and the codebase type declarations
var nrefactorySession = statisAnalysisSession.GetSessionObjectOfType<NRefactorySession>();
NRefactoryContext = new NRefactoryContext()
{
CodebaseDeclarations = nrefactorySession.GetCodebaseDeclarations(statisAnalysisSession.StaticAnalysisManifest),
InvokedSystemTypes = nrefactorySession.GetSystemInvocations(statisAnalysisSession.StaticAnalysisManifest)
};
// Have the concrete implementation create it's visitor
var visitor = CreateVisitor(statisAnalysisSession);
// Parse all files in the changed files collection for achievements
foreach (var filename in statisAnalysisSession.StaticAnalysisManifest.ChangedFiles)
{
// Obtain a parser from the nrefactorySession.
// This parser is shared context between all concrete achievement implementations.
var compilationUnit = nrefactorySession.GetCompilationUnit(filename);
// Pass concrete visitor into the AST created by the parser
compilationUnit.AcceptVisitor(visitor, null);
// Call OnParsingCompleted on the visitor to give it a last chance to unlock achievements.
visitor.OnParsingCompleted();
// Check if the visitor declared the concrete achievement as unlocked.
if (visitor.IsAchievementUnlocked)
{
AchievementCodeOrigin = visitor.CodeOrigin;
if (AchievementCodeOrigin != null)
{
AchievementCodeOrigin.FileName = filename;
}
return true;
}
}
return false;
}
示例5: PerformStaticAnalysis
public IEnumerable<Achievement> PerformStaticAnalysis(StaticAnalysisManifest staticAnalysisManifest, bool onlyUnlockable)
{
IEnumerable<Achievement> unlockedAchievements = Enumerable.Empty<Achievement>();
using (var statisAnalysisSession = new StatisAnalysisSession(staticAnalysisManifest))
{
OnStaticAnalysisStarted(this, new EventArgs());
var stopwatch = new Stopwatch();
stopwatch.Start();
var allAchievements = onlyUnlockable
? AchievementRepository.GetUnlockableAchievements()
: AchievementRepository.GetAchievements();
var availableStaticAnalysisAchievements = allAchievements.Where
(
a => typeof(StaticAnalysisAchievementBase).IsAssignableFrom(a.AchievementType)
).ToList();
unlockedAchievements = GetUnlockedAchievements
(
statisAnalysisSession, availableStaticAnalysisAchievements
).ToList();
stopwatch.Stop();
OnStaticAnalysisCompleted(this, new StaticAnalysisEventArgs
{
AchievementsTested = availableStaticAnalysisAchievements.Count,
ElapsedMilliseconds = (int)stopwatch.ElapsedMilliseconds
});
}
if (unlockedAchievements.Any())
{
foreach (var completedAchievement in unlockedAchievements)
{
AchievementRepository.MarkAchievementAsCompleted(completedAchievement);
}
OnAchievementsUnlocked(this, new AchievementEventArgs
{
UnlockedAchievements = unlockedAchievements
});
}
return unlockedAchievements;
}
示例6: GetUnlockedAchievements
protected override IEnumerable<Achievement> GetUnlockedAchievements(StatisAnalysisSession statisAnalysisSession, IEnumerable<Achievement> availableAchievements)
{
var unlockedAchievements = new List<Achievement>();
foreach (var uncompletedAchievement in availableAchievements)
{
var a = uncompletedAchievement;
var achievement = (StaticAnalysisAchievementBase)Activator.CreateInstance(a.AchievementType);
if (achievement.IsAchievementUnlocked(statisAnalysisSession))
{
a.CodeOrigin = achievement.AchievementCodeOrigin;
a.IsCompleted = true;
unlockedAchievements.Add(a);
}
}
return unlockedAchievements;
}
示例7: CreateVisitor
protected override AbstractAchievementVisitor CreateVisitor(StatisAnalysisSession statisAnalysisSession)
{
return new Visitor();
}
示例8: CreateVisitor
protected abstract AbstractAchievementVisitor CreateVisitor(StatisAnalysisSession statisAnalysisSession);
示例9: CreateVisitor
protected override AbstractAchievementVisitor CreateVisitor(StatisAnalysisSession statisAnalysisSession)
{
return new Visitor(NRefactoryContext.CodebaseDeclarations);
}
示例10: GetUnlockedAchievements
protected abstract IEnumerable<Achievement> GetUnlockedAchievements(
StatisAnalysisSession statisAnalysisSession,
IEnumerable<Achievement> availableAchievements
);
示例11: IsAchievementUnlocked
public abstract bool IsAchievementUnlocked(StatisAnalysisSession statisAnalysisSession);
示例12: CreateVisitor
protected override AbstractAchievementVisitor CreateVisitor(StatisAnalysisSession statisAnalysisSession)
{
return new Visitor(NRefactoryContext, VerifyArgumentUsage, systemType, methodName);
}
示例13: GetOutputFiles
/// <summary>
/// Gets the output files for a given session, filtered by the given search pattern.
/// </summary>
/// <param name="statisAnalysisSession">The detection session.</param>
/// <param name="searchPattern">The search pattern.</param>
/// <returns>A list of file paths.</returns>
private static IEnumerable<string> GetOutputFiles(StatisAnalysisSession statisAnalysisSession, string searchPattern)
{
var directory = statisAnalysisSession.StaticAnalysisManifest.ActiveProjectOutputDirectory;
return Directory.GetFiles(directory, searchPattern, SearchOption.AllDirectories)
.Where(file => file.IndexOf("vshost") < 0);
}