예제 #1
0
 internal void SetFMaskValue <T>(FMask.FMaskValues f, T value)
 {
     ((FieldData <T>)FMaskFields[f]).Value = value;
 }
예제 #2
0
        public AniDBFile(AniDBResponse fileResponse, FMask fMask, AMask aMask) : this()
        {
            if (fileResponse.Code != AniDBResponse.ReturnCode.FILE)
            {
                throw new ArgumentException("Response is not a FILE response");
            }

            List <string> dataFields = new List <string>();

            foreach (string[] sa in fileResponse.DataFields)
            {
                dataFields.AddRange(sa);
            }

            FID = int.Parse(dataFields[0]);

            int currentIndex = 1;

            for (int i = 39; /* 8*5 - 1 ie. 40 bits */ i >= 0; i--)
            {
                if (currentIndex >= dataFields.Count)
                {
                    break;
                }

                FMask.FMaskValues flag = (FMask.FMaskValues)((long)Math.Pow(2, i));

                if (!fMask.Mask.HasFlag(flag))
                {
                    continue;
                }

                //Parse value
                object field = null;

                if (dataFields[currentIndex] != "")
                {
                    if (FMaskFields[flag].DataType == typeof(string))
                    {
                        field = dataFields[currentIndex];
                    }
                    else if (FMaskFields[flag].DataType == typeof(int))
                    {
                        field = int.Parse(dataFields[currentIndex]);
                    }
                    else if (FMaskFields[flag].DataType == typeof(short))
                    {
                        field = short.Parse(dataFields[currentIndex]);
                    }
                    else if (FMaskFields[flag].DataType == typeof(bool))
                    {
                        field = short.Parse(dataFields[currentIndex]) == 1;
                    }
                    else if (FMaskFields[flag].DataType == typeof(long))
                    {
                        field = long.Parse(dataFields[currentIndex]);
                    }
                    else if (FMaskFields[flag].DataType == typeof(StateMask))
                    {
                        field = short.Parse(dataFields[currentIndex]);
                    }
                    else if (FMaskFields[flag].DataType == typeof(IDictionary <int, byte>))
                    {
                        string[] splitString = dataFields[currentIndex].Split('\'');
                        Dictionary <int, byte> otherEpisodes = new Dictionary <int, byte>();

                        if (dataFields[currentIndex] != "")
                        {
                            for (int j = 0; j < splitString.Length; j += 2)
                            {
                                otherEpisodes.Add(int.Parse(splitString[j]), byte.Parse(splitString[j + 1]));
                            }
                        }

                        field = otherEpisodes;
                    }
                    else if (FMaskFields[flag].DataType == typeof(IList <string>))
                    {
                        field = new List <string>(dataFields[currentIndex].Split('\''));
                    }
                    else if (FMaskFields[flag].DataType == typeof(IList <int>))
                    {
                        field = dataFields[currentIndex].Split('\'').Select(int.Parse).ToList();
                    }
                }

                FMaskFields[flag].SetValue(field);

                currentIndex++;
            }

            for (int i = 31; i >= 0; i--)
            {
                if (currentIndex >= dataFields.Count)
                {
                    break;
                }

                AMask.AMaskValues flag = (AMask.AMaskValues)((uint)Math.Pow(2, i));

                if (!aMask.Mask.HasFlag(flag))
                {
                    continue;
                }

                object field = null;

                if (AMaskFields[flag].DataType == typeof(int))
                {
                    field = int.Parse(dataFields[currentIndex]);
                }
                else if (AMaskFields[flag].DataType == typeof(string))
                {
                    field = dataFields[currentIndex];
                }
                else if (AMaskFields[flag].DataType == typeof(IList <string>))
                {
                    field = new List <string>(dataFields[currentIndex].Split('\''));
                }
                else if (AMaskFields[flag].DataType == typeof(IList <int>))
                {
                    field = dataFields[currentIndex].Split('\'').Select(int.Parse).ToList();
                }
                else if (AMaskFields[flag].DataType == typeof(IList <Anime.AIDRelationType>))
                {
                    field = new List <Anime.AIDRelationType>();

                    foreach (string s in dataFields[currentIndex].Split('\''))
                    {
                        ((List <Anime.AIDRelationType>)field).Add((Anime.AIDRelationType) int.Parse(s));
                    }
                }

                AMaskFields[flag].SetValue(field);

                currentIndex++;
            }
        }
예제 #3
0
 internal T GetFMaskValue <T>(FMask.FMaskValues f)
 {
     return(((FieldData <T>)FMaskFields[f]).Value);
 }