Esempio n. 1
0
 /// <summary>
 /// Инициализация "Преобразователя" данных.
 /// </summary>
 public ConverterBase(string inputData,
                      IConversionFactory <T> cf)
 {
     this._parser           = cf.CreateParser();
     this._parser.InputData = inputData;
     this._mapper           = cf.CreateMapper();
 }
Esempio n. 2
0
 public Deserializer(ILogger logger, IReflectionCache reflectionCache, IConversionFactory conversionFactory)
 {
     _logger            = logger;
     _packetReader      = new PacketReader();
     _reflectionCache   = reflectionCache;
     _conversionFactory = conversionFactory;
 }
Esempio n. 3
0
 private static void AddInitialData <T, K>(ObservableCollection <K> slave, IEnumerable <T> master,
                                           IConversionFactory <T, K> conversionFactory)
 {
     foreach (var item in master)
     {
         slave.Add(conversionFactory.Build(item));
     }
 }
Esempio n. 4
0
        protected override Guid ToObject(string value, Type type, IConversionFactory factory)
        {
            if (!Guid.TryParse(value, out Guid id))
            {
                throw new ConversionException(value, type);
            }

            return(id);
        }
        protected override byte?ToObject(string value, Type type, IConversionFactory factory)
        {
            if (value == "-1" || value == "-")
            {
                return(null);
            }

            return((byte)factory.ToObject(value, typeof(byte)));
        }
Esempio n. 6
0
        protected override int ToObject(string value, Type type, IConversionFactory factory)
        {
            if (!int.TryParse(value, out int parsed))
            {
                throw new ConversionException(value, type);
            }

            return(parsed);
        }
        protected override short?ToObject(string value, Type type, IConversionFactory factory)
        {
            if (value == "-1")
            {
                return(null);
            }

            return((short)factory.ToObject(value, typeof(short)));
        }
Esempio n. 8
0
 protected override Enum ToObject(string value, Type type, IConversionFactory factory)
 {
     try
     {
         return((Enum)Enum.Parse(type, value));
     }
     catch (Exception)
     {
         throw new ConversionException(value, type);
     }
 }
Esempio n. 9
0
        protected override string ToString(IList value, Type type, IConversionFactory factory)
        {
            Type valueType = value.GetType().GenericTypeArguments.FirstOrDefault();
            var  sb        = new StringBuilder();

            foreach (object entry in value)
            {
                sb.Append(factory.ToString(entry, valueType)).Append(" ");
            }

            return(sb.ToString().TrimEnd());
        }
Esempio n. 10
0
        protected override IList ToObject(string value, Type type, IConversionFactory factory)
        {
            Type generic  = type.GenericTypeArguments.FirstOrDefault();
            Type listType = typeof(List <>).MakeGenericType(type);
            var  list     = (IList)Activator.CreateInstance(listType);

            string[] values = value.Split(' ');

            foreach (string entry in values)
            {
                list.Add(factory.ToObject(entry, generic));
            }

            return(list);
        }
Esempio n. 11
0
        protected override RaidListPacket ToObject(string value, Type type, IConversionFactory factory)
        {
            string[] split = value.Split(' ');

            int minimumLevel = Convert.ToInt32(split[0]);
            int maximumLevel = Convert.ToInt32(split[1]);
            int raidId       = Convert.ToInt32(split[2]);
            var playerData   = new List <RaidPlayerData>();

            int start = 3;

            if (int.TryParse(split[start], out int temp))
            {
                start++;
                raidId = temp;
            }

            for (int i = start; i < split.Length; i++)
            {
                string   player         = split[i];
                string[] splittedPlayer = player.Split('.');

                int    level         = Convert.ToInt32(splittedPlayer[0]);
                var    classType     = (ClassType)Convert.ToInt32(splittedPlayer[2]);
                string name          = splittedPlayer[4];
                int    championLevel = Convert.ToInt32(splittedPlayer[7]);
                int    id            = Convert.ToInt32(splittedPlayer[6]);

                playerData.Add(new RaidPlayerData
                {
                    Level         = level,
                    ChampionLevel = championLevel,
                    Id            = id,
                    Name          = name,
                    Class         = classType
                });
            }

            return(new RaidListPacket
            {
                Data = playerData,
                MaximumLevel = maximumLevel,
                MinimumLevel = minimumLevel,
                RaidId = raidId
            });
        }
Esempio n. 12
0
        protected override RaidPacket ToObject(string value, Type type, IConversionFactory factory)
        {
            string[] splitted = value.Split(' ');

            var packet = new RaidPacket
            {
                Type = RaidPacketType.Unknown
            };

            if (splitted[0] == "1")
            {
                if (splitted[1] == "0")
                {
                    packet.Type = RaidPacketType.Start;
                }

                if (splitted[1] == "1")
                {
                    packet.Type = RaidPacketType.Initialization;
                }
            }

            if (splitted[0] == "2")
            {
                if (splitted[1] == "-1")
                {
                    packet.Type = RaidPacketType.Left;
                }
                else
                {
                    packet.Type     = RaidPacketType.RaidLeader;
                    packet.LeaderId = (long)factory.ToObject(splitted[1], typeof(long));
                }
            }

            if (splitted[0] == "3")
            {
                packet.Type = RaidPacketType.PlayerHealths;
            }



            return(packet);
        }
Esempio n. 13
0
        protected override InvPacket ToObject(string value, Type type, IConversionFactory factory)
        {
            string[] split = value.Split(' ');

            var subs    = new List <IvnSubPacket>();
            var bagType = (BagType)Convert.ToInt32(split[0]);

            for (int i = 1; i < split.Length; i++)
            {
                string[] itemData = split[i].Split('.');

                int slot = Convert.ToInt32(itemData[0]);
                int vnum = Convert.ToInt32(itemData[1]);

                var sub = new IvnSubPacket
                {
                    Slot = slot,
                    VNum = vnum
                };

                if (bagType == BagType.EQUIPMENT)
                {
                    short rarity  = Convert.ToInt16(itemData[2]);
                    byte  upgrade = Convert.ToByte(itemData[3]);

                    sub.RareAmount    = rarity;
                    sub.UpgradeDesign = upgrade;
                }
                else
                {
                    int amount = Convert.ToInt32(itemData[2]);
                    sub.RareAmount = amount;
                }

                subs.Add(sub);
            }

            return(new InvPacket
            {
                BagType = bagType,
                SubPackets = subs
            });
        }
Esempio n. 14
0
        protected override InPacket ToObject(string value, Type type, IConversionFactory factory)
        {
            string[] split = value.Split(' ');

            var entityType = (EntityType)Convert.ToInt32(split[0]);
            int startIndex = entityType == EntityType.PLAYER ? 3 : 2;

            var packet = new InPacket
            {
                EntityType = entityType,
                Name       = entityType == EntityType.PLAYER ? split[1] : string.Empty,
                Vnum       = entityType != EntityType.PLAYER ? Convert.ToInt32(split[1]) : 0,
                EntityId   = Convert.ToInt32(split[startIndex]),
                PositionX  = Convert.ToInt16(split[startIndex + 1]),
                PositionY  = Convert.ToInt16(split[startIndex + 2]),
                Direction  = entityType != EntityType.GROUND_ITEM ? Convert.ToByte(split[startIndex + 3]) : (byte)0
            };

            string content = string.Join(" ", split.Skip(startIndex + (entityType == EntityType.GROUND_ITEM ? 3 : 4)));

            switch (entityType)
            {
            case EntityType.MONSTER:
            case EntityType.NPC:
                packet.NpcSubPacket = (InNpcSubPacket)factory.ToObject(content, typeof(InNpcSubPacket));
                break;

            case EntityType.PLAYER:
                packet.PlayerSubPacket       = (InPlayerSubPacket)factory.ToObject(content, typeof(InPlayerSubPacket));
                packet.PlayerSubPacket.Level = byte.Parse(split.Skip(27).SkipWhile(x => x.Any(char.IsLetter)).Skip(5).First());
                break;

            case EntityType.GROUND_ITEM:
                packet.DropSubPacket = (InDropSubPacket)factory.ToObject(content, typeof(InDropSubPacket));
                break;

            default:
                throw new InvalidOperationException();
            }

            return(packet);
        }
Esempio n. 15
0
        protected override IList ToObject(string value, Type type, IConversionFactory factory)
        {
            Type generic  = type.GenericTypeArguments.FirstOrDefault();
            Type listType = typeof(List <>).MakeGenericType(type);
            var  list     = (IList)Activator.CreateInstance(listType);

            char separator = ' ';

            if (typeof(IPacket).IsAssignableFrom(generic))
            {
                separator = '^';
            }

            string[] values = value.Split(separator);
            foreach (string entry in values)
            {
                list.Add(factory.ToObject(entry, generic));
            }

            return(list);
        }
Esempio n. 16
0
        protected override SkiPacket ToObject(string value, Type type, IConversionFactory factory)
        {
            var skills = new List <int>();

            string[] split = value.Split(' ');
            foreach (string entry in split)
            {
                string[] skillId = entry.Split('|');
                if (skillId.Length > 0)
                {
                    skills.Add(Convert.ToInt32(skillId[0]));
                    continue;
                }

                skills.Add(Convert.ToInt32(entry));
            }

            return(new SkiPacket
            {
                Skills = skills
            });
        }
        protected override IvnPacket ToObject(string value, Type type, IConversionFactory factory)
        {
            string[] values   = value.Split(' ');
            string[] itemData = values[1].Split('.');

            var bagType = (BagType)Convert.ToInt32(values[0]);

            int slot = Convert.ToInt32(itemData[0]);
            int vnum = Convert.ToInt32(itemData[1]);

            var sub = new IvnSubPacket
            {
                Slot = slot,
                VNum = vnum
            };

            if (bagType == BagType.EQUIPMENT)
            {
                short rarity  = Convert.ToInt16(itemData[2]);
                byte  upgrade = Convert.ToByte(itemData[3]);

                sub.RareAmount    = rarity;
                sub.UpgradeDesign = upgrade;
            }
            else
            {
                int amount = Convert.ToInt32(itemData[2]);
                sub.RareAmount = amount;
            }

            return(new IvnPacket
            {
                BagType = bagType,
                SubPacket = sub
            });
        }
Esempio n. 18
0
        protected override Qnamli2Packet ToObject(string value, Type type, IConversionFactory factory)
        {
            var packet = new Qnamli2Packet();

            string[] splitted = value.Split(' ');

            packet.Command         = (string)factory.ToObject(splitted[1], typeof(string));
            packet.Type            = (Game18NConstString)factory.ToObject(splitted[2], typeof(Game18NConstString));
            packet.ParametersCount = (int)factory.ToObject(splitted[3], typeof(int));


            packet.Parameters = new string[packet.ParametersCount];
            for (int i = 0; i < packet.ParametersCount; i++)
            {
                if (i + 4 >= splitted.Length)
                {
                    break;
                }

                packet.Parameters[i] = splitted[i + 4];
            }

            return(packet);
        }
Esempio n. 19
0
 protected override string ToString(int value, Type type, IConversionFactory factory) => value.ToString();
Esempio n. 20
0
 object IConverter.ToObject(string value, Type type, IConversionFactory factory) => ToObject(value, type, factory);
Esempio n. 21
0
 protected abstract T ToObject(string value, Type type, IConversionFactory factory);
Esempio n. 22
0
 protected abstract string ToString(T value, Type type, IConversionFactory factory);
Esempio n. 23
0
 protected override string ToString(bool value, Type type, IConversionFactory factory) => value ? "1" : "0";
Esempio n. 24
0
 public static void SlaveTo <T, K>(this ObservableCollection <K> slave, ObservableCollection <T> master, IConversionFactory <T, K> conversionFactory)
 {
     AddInitialData(slave, master, conversionFactory);
     master.CollectionChanged += (sender, args) =>
     {
         if (args.Action == NotifyCollectionChangedAction.Add)
         {
             AddItems(slave, args, conversionFactory);
         }
         else if (args.Action == NotifyCollectionChangedAction.Remove)
         {
             RemoveItems(slave, args);
         }
         else if (args.Action == NotifyCollectionChangedAction.Reset)
         {
             slave.Clear();
         }
     };
 }
 protected override string ToString(IvnPacket value, Type type, IConversionFactory factory) => throw new NotImplementedException();
Esempio n. 26
0
 public Serializer(ILogger logger, IConversionFactory conversionFactory)
 {
     _conversionFactory = conversionFactory;
     _logger            = logger;
 }
 protected override string ToString(short?value, Type type, IConversionFactory factory) => value == null ? "-1" : factory.ToString(value, typeof(short));
Esempio n. 28
0
 protected override bool ToObject(string value, Type type, IConversionFactory factory) => value == "1";
Esempio n. 29
0
 protected override string ToObject(string value, Type type, IConversionFactory factory) => value;
Esempio n. 30
0
 private static void AddItems <T, K>(ObservableCollection <K> slave, NotifyCollectionChangedEventArgs args, IConversionFactory <T, K> conversionFactory)
 {
     foreach (var newItem in args.NewItems)
     {
         slave.Add(conversionFactory.Build((T)newItem));
     }
 }