public void RemoveRow(int index)
 {
     if (index < 0 || index >= DataList.Count)
         throw new IndexOutOfRangeException(string.Format("所提供的的索引超出了行数的范围,当前共{0}行", DataList.Count.ToString()));
     DataList.RemoveAt(index);
     int len = 0;
     if (PositionMapping.ContainsKey(index + 1))
     {
         len = PositionMapping[index + 1] - PositionMapping[index];
         TableBuilder.Remove(PositionMapping[index], len);
         var keys=PositionMapping.Keys.ToList();
         foreach (int i in keys)
         {
             if (PositionMapping.ContainsKey(i + 1))
             {
                 PositionMapping[i] = PositionMapping[i + 1] - len;
             }
         }
         PositionMapping.Remove(DataList.Count);
     }
     else
     {
         len = TableBuilder.Length - PositionMapping[index] - 1;
         TableBuilder.Remove(PositionMapping[index], len);
         PositionMapping.Remove(index);
     }
     if (Index >= DataList.Count)
         Index = DataList.Count - 1;
 }
 public AccomodationController(IConfiguration configuration) : base(configuration)
 {
     _configuration = configuration;
     posLibrary = new PositionLibrary(_configuration);
     positionProviders = new PositionProviders(_configuration);
     accomoMapping = new PositionMapping(_configuration);
     masterProviders = new MasterProviders(_configuration);
 }
 public void WriteRow(T model,bool error=true)
 {
     if (model== null && error)
     {
         throw new ArgumentNullException("添加空行通常是无效的,如果当真有业务需求,请将error参数设置为false,默认为true");
     }
     var position = TableBuilder.Length - 1;
     PositionMapping.Add(DataList.Count, position);
     DataList.Add(model);
     HasRows = true;
     TableBuilder.Append(GetRowString(model));
 }
示例#4
0
        public Position TranslatePosition(Position pos)
        {
            try
            {
                if (pos.Equals(Position.Unknown))
                {
                    return(Position.Unknown);
                }

                if (dirty)
                {
                    _mappings.Sort();
                    dirty = false;
                }

                if (_mappings.Count > 0)
                {
                    int idx = _mappings.BinarySearch(new PositionMapping(pos, Position.Unknown));
                    if (idx >= 0)
                    {
                        return(_mappings[idx].Value);
                    }
                    else
                    {
                        int             closestIndex   = (~idx) - 1;
                        PositionMapping matchedMapping = _mappings[closestIndex];
                        if (!matchedMapping.Value.Equals(Position.Unknown))
                        {
                            if (matchedMapping.Key.Line == pos.Line)
                            {
                                return(new Position(
                                           matchedMapping.Value.Line,
                                           matchedMapping.Value.Column + (pos.Column - matchedMapping.Key.Column)));
                            }
                            else
                            {
                                return(new Position(
                                           matchedMapping.Value.Line + (pos.Line - matchedMapping.Key.Line),
                                           pos.Column));
                            }
                        }
                    }
                }

                return(Position.Unknown);
            }
            catch (Exception e)
            {
                Trace.Fail(e.ToString());
                return(Position.Unknown);
            }
        }
示例#5
0
        public static IPlayerData CreateFromData(JToken player)
        {
            ESPNPlayerData stats = new ESPNPlayerData();

            stats.DisplayName = (string)player["player"]["fullName"];
            stats.SourceID    = (string)player["player"]["id"];
            stats.Outlook     = (string)player["player"]["seasonOutlook"];

            HashSet <Position> allPositions  = new HashSet <Position>();
            List <int>         espnPositions = new List <int>(((JArray)player["player"]["eligibleSlots"]).Select(s => (int)s).ToArray());

            foreach (int espnPosition in espnPositions)
            {
                List <Position> positions;
                if (PositionMapping.TryGetValue(espnPosition, out positions))
                {
                    foreach (Position position in positions)
                    {
                        allPositions.Add(position);
                    }
                }
            }
            stats.Positions = allPositions.ToList();

            Dictionary <string, string> espnStats = new Dictionary <string, string>();
            JToken statsRoot = player["player"]["stats"];

            if (statsRoot != null && statsRoot.Count() > 0)
            {
                bool foundStats = false;
                foreach (JToken statSet in player["player"]["stats"].Children())
                {
                    foreach (string espnStat in ESPNConstants.Stats.Batters.All.Union(ESPNConstants.Stats.Pitchers.All))
                    {
                        string statValueStr = (string)statSet["stats"][espnStat];
                        if (!string.IsNullOrEmpty(statValueStr))
                        {
                            espnStats[espnStat] = statValueStr;
                            foundStats          = true;
                        }
                    }

                    if (foundStats)
                    {
                        break;
                    }
                }
            }
            ESPNConstants.Stats.MapESPNStatDictionaryToDataModelStatDictionary(espnStats, stats.Stats);

            return(stats);
        }
示例#6
0
 public CruiseController(IConfiguration configuration) : base(configuration)
 {
     _configuration  = configuration;
     positionMapping = new PositionMapping(_configuration);
 }
示例#7
0
 public OthersController(IConfiguration configuration) : base(configuration)
 {
     _configuration    = configuration;
     positionProviders = new PositionProviders(_configuration);
     positionMapping   = new PositionMapping(_configuration);
 }
示例#8
0
 /// <summary>
 /// 重写自定义Map配置
 /// </summary>
 /// <param name="modelBuilder"></param>
 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     PositionMapping.MappingToTable(modelBuilder);
 }
示例#9
0
 public TransfersController(IConfiguration configuration) : base(configuration)
 {
     _configuration  = configuration;
     positionMapping = new PositionMapping(_configuration);
 }
示例#10
0
 public TourEntitiesController(IConfiguration configuration) : base(configuration)
 {
     _configuration  = configuration;
     positionMapping = new PositionMapping(_configuration);
 }