Пример #1
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++;
            }
        }
Пример #2
0
        public Anime(AniDBResponse response, AMask aMask) : this()
        {
            if (response.Code != AniDBResponse.ReturnCode.ANIME && response.Code != AniDBResponse.ReturnCode.ANIME_BEST_MATCH)
            {
                throw new ArgumentException("Response is not an ANIME response");
            }

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

            foreach (string[] s in response.DataFields)
            {
                dataFields.AddRange(s);
            }

            int currentIndex = 0;

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

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

                object field = null;

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

                if (AMaskDefs[flag].DataType == typeof(string))
                {
                    field = dataFields[currentIndex];
                }
                else if (AMaskDefs[flag].DataType == typeof(int?))
                {
                    field = int.Parse(dataFields[currentIndex]);
                }
                else if (AMaskDefs[flag].DataType == typeof(bool?))
                {
                    field = bool.Parse(dataFields[currentIndex]);
                }
                else if (AMaskDefs[flag].DataType == typeof(IList <string>))
                {
                    //TODO: Make sure these are the only possibilities (and are the right choices)

                    field = new List <string>(dataFields[currentIndex].Split(flag == AMask.AMaskValues.CategoryList ? ',' : '\''));
                }
                else if (AMaskDefs[flag].DataType == typeof(IList <AIDRelationType>))
                {
                    field = new List <AIDRelationType>();

                    foreach (string s in dataFields[currentIndex].Split('\''))
                    {
                        ((List <AIDRelationType>)field).Add((AIDRelationType)int.Parse(s));
                    }
                }
                else if (AMaskDefs[flag].DataType == typeof(DateFlag))
                {
                    field = (DateFlag)int.Parse(dataFields[currentIndex]);
                }

                currentIndex++;

                AMaskDefs[flag].SetValue(field);
            }
        }
Пример #3
0
 private void SetAMaskValue(AMask.AMaskValues a, object value)
 {
     AMaskDefs[a].SetValue(value);
 }
Пример #4
0
 private object GetAMaskValue(AMask.AMaskValues a)
 {
     return(AMaskDefs[a].GetValue());
 }
Пример #5
0
 internal void SetAMaskValue <T>(AMask.AMaskValues a, T value)
 {
     ((FieldData <T>)AMaskFields[a]).Value = value;
 }
Пример #6
0
 internal T GetAMaskValue <T>(AMask.AMaskValues a)
 {
     return(((FieldData <T>)AMaskFields[a]).Value);
 }