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


C# Run.Add方法代码示例

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


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

示例1: Create

        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var json = JSON.FromStream(Stream);

            run.GameName = json.run_name as string;
            run.AttemptCount = json.run_count;

            var timingMethod = (int)(json.timer_type) == 0 
                ? TimingMethod.RealTime 
                : TimingMethod.GameTime;

            var segments = json.splits as IEnumerable<dynamic>;

            foreach (var segment in segments)
            {
                var segmentName = segment.name as string;
                var pbSplitTime = parseTime((int?)segment.pb_split, timingMethod);
                var bestSegment = parseTime((int?)segment.split_best, timingMethod);

                var parsedSegment = new Segment(segmentName, pbSplitTime, bestSegment);
                run.Add(parsedSegment);
            }

            return run;
        }
开发者ID:PrototypeAlpha,项目名称:LiveSplit,代码行数:27,代码来源:SplittyRunFactory.cs

示例2: Create

        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var run = new Run(factory);

            var json = JSON.FromStream(Stream);

            run.CategoryName = json.title as string;
            run.AttemptCount = json.attempt_count;
            run.Offset = TimeSpanParser.Parse(json.start_delay as string);

            //Best Split Times can be used for the Segment History
            //Every single best split time should be included as its own run, 
            //since the best split times could be apart from each other less 
            //than the best segments, so we have to assume they are from different runs.
            var attemptHistoryIndex = 1;

            var segments = json.splits as IEnumerable<dynamic>;

            foreach (var segment in segments)
            {
                var segmentName = segment.title as string;
                var pbSplitTime = parseTime(segment.time as string);
                var bestSegment = parseTime(segment.best_segment as string);

                var parsedSegment = new Segment(segmentName, pbSplitTime, bestSegment);

                var bestSplitTime = parseTime(segment.best_time as string);
                if (bestSplitTime.RealTime != null)
                {
                    run.AttemptHistory.Add(new Attempt(attemptHistoryIndex, default(Time), null, null));

                    //Insert a new run that skips to the current split
                    foreach (var alreadyInsertedSegment in run)
                    {
                        alreadyInsertedSegment.SegmentHistory.Add(attemptHistoryIndex, default(Time));
                    }

                    parsedSegment.SegmentHistory.Add(attemptHistoryIndex, bestSplitTime);

                    attemptHistoryIndex++;
                }

                run.Add(parsedSegment);
            }

            return run;
        }
开发者ID:Rezura,项目名称:LiveSplit,代码行数:47,代码来源:UrnRunFactory.cs

示例3: FindOrderedRuns

        private IEnumerable<Run> FindOrderedRuns()
        {
            Run run = null;

            var originalIndex = 0;
            foreach (var request in _requests)
            {
                if (run == null)
                {
                    run = new Run();
                    run.Add(request, originalIndex);
                }
                else if (run.RequestType == request.RequestType)
                {
                    if (run.Count == _maxBatchCount)
                    {
                        yield return run;
                        run = new Run();
                    }
                    run.Add(request, originalIndex);
                }
                else
                {
                    yield return run;
                    run = new Run();
                    run.Add(request, originalIndex);
                }

                originalIndex++;
            }

            if (run != null)
            {
                yield return run;
            }
        }
开发者ID:niemyjski,项目名称:mongo-csharp-driver,代码行数:36,代码来源:BulkMixedWriteOperation.cs

示例4: Create

        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            string path = "";
            if (!string.IsNullOrEmpty(Path))
                path = System.IO.Path.GetDirectoryName(Path);

            var run = new Run(factory);

            var reader = new StreamReader(Stream);

            var line = reader.ReadLine();
            var titleInfo = line.Split('\t');
            run.AttemptCount = int.Parse(titleInfo[0]);
            run.Offset = TimeSpanParser.Parse(titleInfo[1]);
            if (!string.IsNullOrEmpty(path))
            {
                try
                {
                    run.GameIcon = Image.FromFile(System.IO.Path.Combine(path, titleInfo[2]));
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }

            line = reader.ReadLine();
            titleInfo = line.Split('\t');
            run.CategoryName = titleInfo[0];
            var comparisons = titleInfo.Skip(2).ToArray();

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Length <= 0 || string.IsNullOrWhiteSpace(line))
                    continue;

                var segment = new Segment("");

                var segmentInfo = line.Split('\t');

                segment.Name = segmentInfo[0];
                Time newBestSegment = new Time();
                newBestSegment.RealTime = parseTimeNullable(segmentInfo[1]);
                segment.BestSegmentTime = newBestSegment;
                Time pbTime = new Time();
                for (var i = 0; i < comparisons.Length; ++i)
                {
                    Time newComparison = new Time(segment.Comparisons[comparisons[i]]);
                    newComparison.RealTime = pbTime.RealTime = parseTimeNullable(segmentInfo[i + 2]);
                    segment.Comparisons[comparisons[i]] = newComparison;
                }
                segment.PersonalBestSplitTime = pbTime;

                line = reader.ReadLine();

                if (line.Length > 0 && !string.IsNullOrWhiteSpace(line) && !string.IsNullOrEmpty(path))
                {
                    try
                    {
                        segment.Icon = Image.FromFile(System.IO.Path.Combine(path, line.Split('\t')[0]));
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }

                run.Add(segment);
            }

            parseHistory(run);

            foreach (var comparison in comparisons)
                run.CustomComparisons.Add(comparison);

            return run;
        }
开发者ID:0xwas,项目名称:LiveSplit,代码行数:77,代码来源:TimeSplitTrackerRunFactory.cs

示例5: Create

        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var document = new XmlDocument();
            document.Load(Stream);

            var run = new Run(factory);
            var parent = document["Run"];
            var version = SettingsHelper.ParseAttributeVersion(parent);

            if (version >= new Version(1, 6))
            {
                var metadata = parent["Metadata"];
                run.Metadata.RunID = metadata["Run"].GetAttribute("id");
                run.Metadata.PlatformName = metadata["Platform"].InnerText;
                run.Metadata.UsesEmulator = bool.Parse(metadata["Platform"].GetAttribute("usesEmulator"));
                run.Metadata.RegionName = metadata["Region"].InnerText;
                foreach (var variableNode in metadata["Variables"].ChildNodes.OfType<XmlElement>())
                {
                    run.Metadata.VariableValueNames.Add(variableNode.GetAttribute("name"), variableNode.InnerText);
                }
            }

            run.GameIcon = SettingsHelper.GetImageFromElement(parent["GameIcon"]);
            run.GameName = SettingsHelper.ParseString(parent["GameName"]);
            run.CategoryName = SettingsHelper.ParseString(parent["CategoryName"]);
            run.Offset = SettingsHelper.ParseTimeSpan(parent["Offset"]);
            run.AttemptCount = SettingsHelper.ParseInt(parent["AttemptCount"]);

            ParseAttemptHistory(version, parent, run);

            var segmentsNode = parent["Segments"];

            foreach (var segmentNode in segmentsNode.GetElementsByTagName("Segment"))
            {
                var segmentElement = segmentNode as XmlElement;

                var split = new Segment(SettingsHelper.ParseString(segmentElement["Name"]));
                split.Icon = SettingsHelper.GetImageFromElement(segmentElement["Icon"]);

                if (version >= new Version(1, 3))
                {
                    var splitTimes = segmentElement["SplitTimes"];
                    foreach (var comparisonNode in splitTimes.GetElementsByTagName("SplitTime"))
                    {
                        var comparisonElement = comparisonNode as XmlElement;
                        var comparisonName = comparisonElement.GetAttribute("name");
                        if (comparisonElement.InnerText.Length > 0)
                        {
                            split.Comparisons[comparisonName] = version >= new Version(1, 4, 1) ? Time.FromXml(comparisonElement) : Time.ParseText(comparisonElement.InnerText);
                        }
                        if (!run.CustomComparisons.Contains(comparisonName))
                            run.CustomComparisons.Add(comparisonName);
                    }
                }
                else
                {
                    var pbSplit = segmentElement["PersonalBestSplitTime"];
                    if (pbSplit.InnerText.Length > 0)
                    {
                        split.Comparisons[Run.PersonalBestComparisonName] = version >= new Version(1, 4, 1) ? Time.FromXml(pbSplit) : Time.ParseText(pbSplit.InnerText);
                    }
                }

                var goldSplit = segmentElement["BestSegmentTime"];
                if (goldSplit.InnerText.Length > 0)
                {
                    split.BestSegmentTime = version >= new Version(1, 4, 1) ? Time.FromXml(goldSplit) : Time.ParseText(goldSplit.InnerText);
                }

                var history = segmentElement["SegmentHistory"];
                foreach (var historyNode in history.GetElementsByTagName("Time"))
                {
                    var node = historyNode as XmlElement;
                    IIndexedTime indexedTime;
                    if (version >= new Version(1, 4, 1))
                        indexedTime = IndexedTimeHelper.ParseXml(node);
                    else
                        indexedTime = IndexedTimeHelper.ParseXmlOld(node);

                    if (!split.SegmentHistory.ContainsKey(indexedTime.Index))
                        split.SegmentHistory.Add(indexedTime.Index, indexedTime.Time);
                }

                run.Add(split);
            }

            if (version >= new Version(1, 4, 2))
            {
                var newXmlDoc = new XmlDocument();
                newXmlDoc.InnerXml = parent["AutoSplitterSettings"].OuterXml;
                run.AutoSplitterSettings = newXmlDoc.FirstChild as XmlElement;
                run.AutoSplitterSettings.Attributes.Append(SettingsHelper.ToAttribute(newXmlDoc, "gameName", run.GameName));
            }

            if (!string.IsNullOrEmpty(FilePath))
                run.FilePath = FilePath;

            return run;
        }
开发者ID:Glurmo,项目名称:LiveSplit,代码行数:99,代码来源:XMLRunFactory.cs

示例6: Create

        public IRun Create(IComparisonGeneratorsFactory factory)
        {
            var document = new XmlDocument();
            document.Load(Stream);

            var run = new Run(factory);
            var parent = document["Run"];
            var version = SettingsHelper.ParseAttributeVersion(parent);

            run.GameIcon = SettingsHelper.GetImageFromElement(parent["GameIcon"]);
            run.GameName = SettingsHelper.ParseString(parent["GameName"]);
            run.CategoryName = SettingsHelper.ParseString(parent["CategoryName"]);
            run.Offset = SettingsHelper.ParseTimeSpan(parent["Offset"]);
            run.AttemptCount = SettingsHelper.ParseInt(parent["AttemptCount"]);

            ParseAttemptHistory(version, parent, run);

            var segmentsNode = parent["Segments"];

            foreach (var segmentNode in segmentsNode.GetElementsByTagName("Segment"))
            {
                var segmentElement = segmentNode as XmlElement;

                var split = new Segment(SettingsHelper.ParseString(segmentElement["Name"]));
                split.Icon = SettingsHelper.GetImageFromElement(segmentElement["Icon"]);

                if (version >= new Version(1, 3))
                {
                    var splitTimes = segmentElement["SplitTimes"];
                    foreach (var comparisonNode in splitTimes.GetElementsByTagName("SplitTime"))
                    {
                        var comparisonElement = comparisonNode as XmlElement;
                        var comparisonName = comparisonElement.GetAttribute("name");
                        if (comparisonElement.InnerText.Length > 0)
                        {
                            split.Comparisons[comparisonName] = version >= new Version(1, 4, 1) ? Time.FromXml(comparisonElement) : Time.ParseText(comparisonElement.InnerText);
                        }
                        if (!run.CustomComparisons.Contains(comparisonName))
                            run.CustomComparisons.Add(comparisonName);
                    }
                }
                else
                {
                    var pbSplit = segmentElement["PersonalBestSplitTime"];
                    if (pbSplit.InnerText.Length > 0)
                    {
                        split.Comparisons[Run.PersonalBestComparisonName] = version >= new Version(1, 4, 1) ? Time.FromXml(pbSplit) : Time.ParseText(pbSplit.InnerText);
                    }
                }

                var goldSplit = segmentElement["BestSegmentTime"];
                if (goldSplit.InnerText.Length > 0)
                {
                    split.BestSegmentTime = version >= new Version(1, 4, 1) ? Time.FromXml(goldSplit) : Time.ParseText(goldSplit.InnerText);
                }

                var history = segmentElement["SegmentHistory"];
                foreach (var historyNode in history.GetElementsByTagName("Time"))
                {
                    split.SegmentHistory.Add(version >= new Version(1, 4, 1) ? IndexedTimeHelper.ParseXml(historyNode as XmlElement) : IndexedTimeHelper.ParseXmlOld(historyNode as XmlElement));
                }

                run.Add(split);
            }

            if (version >= new Version(1, 4, 2))
            {
                var newXmlDoc = new XmlDocument();
                newXmlDoc.InnerXml = parent["AutoSplitterSettings"].OuterXml;
                run.AutoSplitterSettings = newXmlDoc.FirstChild as XmlElement;
                run.AutoSplitterSettings.Attributes.Append(SettingsHelper.ToAttribute(newXmlDoc, "gameName", run.GameName));
            }

            if (!string.IsNullOrEmpty(FilePath))
                run.FilePath = FilePath;

            return run;
        }
开发者ID:0xwas,项目名称:LiveSplit,代码行数:78,代码来源:XMLRunFactory.cs


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