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


C# IRun.Last方法代码示例

本文整理汇总了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;
 }
开发者ID:xarrez,项目名称:LiveSplit,代码行数:37,代码来源:IRunImporter.cs

示例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&region=NTSC-J&time=5%3A07%3A25&date=12%2F18%2F2013&video=http%3A%2F%2Fyoutube.com%2FTesting&notes=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("&notes=");
                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>");
            }
        }
开发者ID:Glurmo,项目名称:LiveSplit,代码行数:75,代码来源:Congratsio.cs

示例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;
 }
开发者ID:Glurmo,项目名称:LiveSplit,代码行数:6,代码来源:Congratsio.cs

示例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;
            }
        }
开发者ID:zoton2,项目名称:LiveSplit,代码行数:91,代码来源:SpeedrunCom.cs

示例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;
            }
        }
开发者ID:zoton2,项目名称:LiveSplit,代码行数:81,代码来源:SpeedrunCom.cs

示例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;
        }
开发者ID:zoton2,项目名称:LiveSplit,代码行数:10,代码来源:SpeedrunCom.cs

示例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;
        }
开发者ID:0xwas,项目名称:LiveSplit,代码行数:40,代码来源:Imgur.cs

示例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);
        }
开发者ID:Rezura,项目名称:LiveSplit,代码行数:39,代码来源:ASUP.cs


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