本文整理汇总了C#中IRun.Last方法的典型用法代码示例。如果您正苦于以下问题:C# IRun.Last方法的具体用法?C# IRun.Last怎么用?C# IRun.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRun
的用法示例。
在下文中一共展示了IRun.Last方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddComparisonFromRun
private static bool AddComparisonFromRun(this IRun target,
IRun comparisonRun, string name, Form form = null)
{
if (!target.Comparisons.Contains(name))
{
if (!name.StartsWith("[Race]"))
{
target.CustomComparisons.Add(name);
foreach (var segment in comparisonRun)
{
if (segment == comparisonRun.Last())
target.Last().Comparisons[name] = comparisonRun.Last().PersonalBestSplitTime;
else
{
var runSegment = target.FirstOrDefault(x => x.Name.Trim().ToLower() == segment.Name.Trim().ToLower());
if (runSegment != null)
runSegment.Comparisons[name] = segment.PersonalBestSplitTime;
}
}
target.HasChanged = true;
target.FixSplits();
}
else
{
var result = MessageBox.Show(form, "A Comparison name cannot start with [Race].", "Invalid Comparison Name", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (result == DialogResult.Retry)
return false;
}
}
else
{
var result = MessageBox.Show(form, "A Comparison with this name already exists.", "Comparison Already Exists", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (result == DialogResult.Retry)
return false;
}
return true;
}
示例2: SubmitRun
public bool SubmitRun(IRun run, string username, string password, Func<Image> screenShotFunction = null, bool attachSplits = false, TimingMethod method = TimingMethod.RealTime, string gameId = "", string categoryId = "", string version = "", string comment = "", string video = "", params string[] additionalParams)
{
var timeFormatter = new RegularTimeFormatter(TimeAccuracy.Seconds);
if (attachSplits)
comment += " " + SplitsIO.Instance.Share(run, screenShotFunction);
var postRequest = (HttpWebRequest)WebRequest.Create(GetUri("submit"));
postRequest.Method = "POST";
postRequest.ContentType = "application/x-www-form-urlencoded";
using (var postStream = postRequest.GetRequestStream())
{
var writer = new StreamWriter(postStream);
writer.Write("nickname=");
writer.Write(HttpUtility.UrlEncode(username));
//nickname=CryZeTesting&country=Germany&twitter=CryZe107&youtube=CryZe92&twitch=CryZe92&game=The+Legend+of+Zelda%3A+The+Wind+Waker&category=Test%25&console=&played_on=Emulator&emulator=Dolphin+3.5®ion=NTSC-J&time=5%3A07%3A25&date=12%2F18%2F2013&video=http%3A%2F%2Fyoutube.com%2FTesting¬es=Still+in+Browser.+And+I+just+fucked+up+xD
//Country
//Twitter
/*if (Twitter.Instance.)
writer.Write("nickname=");
writer.Write(HttpUtility.UrlEncode(username));*/
//Youtube
/*writer.Write("nickname=");
writer.Write(HttpUtility.UrlEncode(username));*/
if (Twitch.Instance.IsLoggedIn)
{
writer.Write("&twitch=");
writer.Write(HttpUtility.UrlEncode(Twitch.Instance.ChannelName));
}
writer.Write("&game=");
writer.Write(HttpUtility.UrlEncode(run.GameName));
writer.Write("&category=");
writer.Write(HttpUtility.UrlEncode(run.CategoryName));
writer.Write("&console="); //TODO We need console
//writer.Write(HttpUtility.UrlEncode(run.CategoryName));
//Played on
//region
//Time
writer.Write("&time=");
writer.Write(HttpUtility.UrlEncode(timeFormatter.Format(run.Last().PersonalBestSplitTime.RealTime)));
writer.Write("&date=");
var dateTime = run.AttemptHistory.First(x => x.Time.RealTime == run.Last().PersonalBestSplitTime.RealTime).Ended.Value.Time;
writer.Write(HttpUtility.UrlEncode(String.Format("{0:00}/{1:00}/{2}", dateTime.Month, dateTime.Day, dateTime.Year)));
writer.Write("&video=");
writer.Write(HttpUtility.UrlEncode(video));
writer.Write("¬es=");
writer.Write(HttpUtility.UrlEncode(comment));
writer.Flush();
}
using (var response = postRequest.GetResponse())
using (var resultStream = response.GetResponseStream())
{
var reader = new StreamReader(resultStream);
return reader.ReadToEnd().Contains("<strong>Submitted!</strong>");
}
}
示例3: CheckIfPersonalBestIsValid
public bool CheckIfPersonalBestIsValid(IRun run)
{
var pb = run.Last().PersonalBestSplitTime.RealTime;
var attempt = run.AttemptHistory.FirstOrDefault(x => x.Time.RealTime == pb);
return attempt.Ended.HasValue;
}
示例4: SubmitRun
public static bool SubmitRun(IRun run, out string reasonForRejection,
string comment = null, Uri videoUri = null, DateTime? date = null,
bool submitToSplitsIO = true)
{
try
{
var metadata = run.Metadata;
var isValid = ValidateRun(run, out reasonForRejection);
if (!isValid)
{
return false;
}
//This is legal for mods, so we either have to check the mods or rely on the API responding
//This results in unnecessary submits to splits i/o though.
//This is also ignoring series moderators. That's such a rare case that it probably never happens.
if (metadata.Game.Ruleset.RequiresVideo && videoUri == null && !metadata.Game.ModeratorUsers.Contains(Client.Profile.GetProfile()))
{
reasonForRejection = "Runs of this game require a video.";
return false;
}
var timingMethods = metadata.Game.Ruleset.TimingMethods;
var runTime = run.Last().PersonalBestSplitTime;
if (date == null)
{
date = FindPersonalBestAttemptDate(run);
}
if (date.HasValue && date.Value.ToUniversalTime().Date > DateTime.UtcNow.Date)
{
reasonForRejection = "The date of the run can't be in the future.";
return false;
}
if (date.HasValue && metadata.Game.YearOfRelease.HasValue && date.Value.ToUniversalTime().Date.Year < metadata.Game.YearOfRelease)
{
reasonForRejection = "The date of the run can't be before the release date of the game.";
return false;
}
try
{
var categoryId = metadata.Category.ID;
var platformId = metadata.Platform.ID;
var regionId = metadata.Region != null ? metadata.Region.ID : null;
var realTime = timingMethods.Contains(SpeedrunComSharp.TimingMethod.RealTime) ? runTime.RealTime : null;
var realTimeWithoutLoads = timingMethods.Contains(SpeedrunComSharp.TimingMethod.RealTimeWithoutLoads) ? runTime.GameTime : null;
var gameTime = timingMethods.Contains(SpeedrunComSharp.TimingMethod.GameTime) ? runTime.GameTime : null;
var emulated = metadata.Game.Ruleset.EmulatorsAllowed && metadata.UsesEmulator;
var splitsIOUri = submitToSplitsIO ? new Uri(SplitsIO.Instance.Share(run)) : null;
var variables = metadata.VariableValues.Values.Where(x => x != null);
var submittedRun = Client.Runs.Submit(
//simulateSubmitting: true,
categoryId: categoryId,
platformId: platformId,
regionId: regionId,
realTime: realTime,
realTimeWithoutLoads: realTimeWithoutLoads,
gameTime: gameTime,
comment: comment,
videoUri: videoUri,
date: date,
emulated: emulated,
splitsIOUri: splitsIOUri,
verify: false,
variables: variables
);
run.Metadata.Run = submittedRun;
}
catch (APIException ex)
{
reasonForRejection = string.Join(Environment.NewLine, ex.Errors);
return false;
}
reasonForRejection = null;
return true;
}
catch (Exception ex)
{
reasonForRejection = "The run could not be submitted for an unknown reason.";
Log.Error(ex);
return false;
}
}
示例5: ValidateRun
public static bool ValidateRun(IRun run, out string reasonForRejection)
{
try
{
var metadata = run.Metadata;
if (!string.IsNullOrEmpty(metadata.RunID))
{
reasonForRejection = "This run already exists on speedrun.com.";
return false;
}
if (!MakeSureUserIsAuthenticated())
{
reasonForRejection = "You can't submit a run without being authenticated.";
return false;
}
if (string.IsNullOrEmpty(run.GameName))
{
reasonForRejection = "You need to specify a game.";
return false;
}
if (metadata.Game == null)
{
reasonForRejection = "The game could not be found on speedrun.com.";
return false;
}
if (string.IsNullOrEmpty(run.CategoryName))
{
reasonForRejection = "You need to specify a category.";
return false;
}
if (metadata.Category == null)
{
reasonForRejection = "The category could not be found on speedrun.com.";
return false;
}
if (metadata.Category.Players.Value > 1)
{
reasonForRejection = "Submitting runs for more than the currently authenticated user is not implemented yet.";
return false;
}
if (metadata.Platform == null)
{
reasonForRejection = "You need to specify the platform of the game.";
return false;
}
var primaryTimingMethod = metadata.Game.Ruleset.DefaultTimingMethod.ToLiveSplitTimingMethod();
var runTime = run.Last().PersonalBestSplitTime;
if (!runTime[primaryTimingMethod].HasValue)
{
reasonForRejection = "You can't submit a run without a time.";
return false;
}
var variableThatNeedsAValueButHasNone = metadata.VariableValues.Where(x => x.Key.IsMandatory).FirstOrDefault(x => x.Value == null);
if (variableThatNeedsAValueButHasNone.Value != null)
{
reasonForRejection = string.Format("You need to specify a value for the variable \"{0}\".", variableThatNeedsAValueButHasNone.Key.Name);
return false;
}
reasonForRejection = null;
return true;
}
catch (Exception ex)
{
reasonForRejection = "The run could not be validated for an unknown reason.";
Log.Error(ex);
return false;
}
}
示例6: FindPersonalBestAttemptDate
public static DateTime? FindPersonalBestAttemptDate(IRun run)
{
var runTime = run.Last().PersonalBestSplitTime;
var attempt = run.AttemptHistory.FirstOrDefault(x =>
x.Time.GameTime == runTime.GameTime
&& x.Time.RealTime == runTime.RealTime);
return attempt.Ended;
}
示例7: SubmitRun
public bool SubmitRun(IRun run, string username, string password, Func<Image> screenShotFunction = null, bool attachSplits = false, TimingMethod method = TimingMethod.RealTime, string gameId = "", string categoryId = "", string version = "", string comment = "", string video = "", params string[] additionalParams)
{
var titleBuilder = new StringBuilder();
//var descriptionBuilder = new StringBuilder();
var gameNameEmpty = string.IsNullOrEmpty(run.GameName);
var categoryEmpty = string.IsNullOrEmpty(run.CategoryName);
titleBuilder.Append(new RegularTimeFormatter(TimeAccuracy.Seconds).Format(run.Last().PersonalBestSplitTime[method]));
if (titleBuilder.Length > 0 && (!gameNameEmpty || !categoryEmpty))
titleBuilder.Append(" in ");
titleBuilder.Append(run.GameName);
if (!gameNameEmpty && !categoryEmpty)
titleBuilder.Append(" - ");
titleBuilder.Append(run.CategoryName);
if (attachSplits)
comment += " " + SplitsIO.Instance.Share(run, screenShotFunction);
/*var splitTimeFormatter = new ShortTimeFormatter();
foreach (var segment in run)
{
descriptionBuilder.Append(segment.Name);
descriptionBuilder.Append(" ");
descriptionBuilder.Append(segment.SplitTime);
}*/
if (screenShotFunction != null)
{
var image = screenShotFunction();
var result = UploadImage(image, titleBuilder.ToString(), comment);
var url = "http://imgur.com/" + (string)result.data.id;
Process.Start(url);
Clipboard.SetText(url);
}
return true;
}
示例8: SubmitRun
public dynamic SubmitRun(
IRun run,
string username, string password,
string gameId, string categoryId,
string version, string comment,
string video,
params string[] additionalParams)
{
var timeFormatter = new ASUPTimeFormatter();
var splitsBuilder = new StringBuilder();
splitsBuilder.Append("[");
foreach (var segment in run)
{
splitsBuilder.Append(timeFormatter.Format(segment.PersonalBestSplitTime.RealTime));
splitsBuilder.Append(", ");
}
splitsBuilder.Length -= 2;
splitsBuilder.Append("]");
var elements = new string[]
{
"type", "submitrun",
"username", username,
"password", password,
"game", gameId,
"category", categoryId,
"version", version,
"runtime", timeFormatter.Format(run.Last().PersonalBestSplitTime.RealTime),
"comment", comment,
"video", video,
"splits", splitsBuilder.ToString(),
}.Concat(additionalParams).ToArray();
return JSON.FromUriPost(ServerUri, elements);
}