Esempio n. 1
0
		public Group(AniDBResponse groupResponse)
		{
			if(groupResponse.Code != AniDBResponse.ReturnCode.GROUP)
				throw new ArgumentException("Response is not a GROUP response");

			GID = int.Parse(groupResponse.DataFields[0][0]);
			Rating = int.Parse(groupResponse.DataFields[0][1]);
			Votes = int.Parse(groupResponse.DataFields[0][2]);
			AnimeCount = int.Parse(groupResponse.DataFields[0][3]);
			FileCount = int.Parse(groupResponse.DataFields[0][4]);
			Name = groupResponse.DataFields[0][5];
			ShortName = groupResponse.DataFields[0][6];
			IrcChannel = groupResponse.DataFields[0][7];
			IrcServer = groupResponse.DataFields[0][8];
			Url = groupResponse.DataFields[0][9];
			PicName = groupResponse.DataFields[0][10];
			FoundedDate = int.Parse(groupResponse.DataFields[0][11]);
			DisbandedDate = int.Parse(groupResponse.DataFields[0][12]);
			DateFlags = (DateFlag) short.Parse(groupResponse.DataFields[0][13]);
			LastReleaseDate = int.Parse(groupResponse.DataFields[0][14]);
			LastActivityDate = int.Parse(groupResponse.DataFields[0][15]);

			GroupRelations = new Dictionary<int, RelationType>();
			for(int i = 16; i < groupResponse.DataFields.Length; i++)
			{
				string[] relation = groupResponse.DataFields[0][i].Split('\'');

				GroupRelations.Add(int.Parse(relation[1]), (RelationType)int.Parse(relation[0]));
			}
		}
Esempio n. 2
0
        public Episode(AniDBResponse response)
        {
            if (response.Code != AniDBResponse.ReturnCode.EPISODE)
            {
                throw new ArgumentException("Response is not an EPISODE response");
            }

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

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

            EID    = int.Parse(dataFields[0]);
            AID    = int.Parse(dataFields[1]);
            Length = int.Parse(dataFields[2]);
            Rating = int.Parse(dataFields[3]);
            Votes  = int.Parse(dataFields[4]);

            EpisodeNumber = int.Parse(Char.IsDigit(dataFields[5][0]) ? dataFields[5] : dataFields[5].Remove(0, 1));

            EnglishName = dataFields[6];
            RomanjiName = dataFields[7];
            KanjiName   = dataFields[8];
            AirDate     = int.Parse(dataFields[9]);
            SpecialType = (Special)int.Parse(dataFields[10]);
            //TODO: Sanity check that SpecialType matches SpecialTypeNo
        }
Esempio n. 3
0
        public Group(AniDBResponse groupResponse)
        {
            if (groupResponse.Code != AniDBResponse.ReturnCode.GROUP)
            {
                throw new ArgumentException("Response is not a GROUP response");
            }

            GID              = int.Parse(groupResponse.DataFields[0][0]);
            Rating           = int.Parse(groupResponse.DataFields[0][1]);
            Votes            = int.Parse(groupResponse.DataFields[0][2]);
            AnimeCount       = int.Parse(groupResponse.DataFields[0][3]);
            FileCount        = int.Parse(groupResponse.DataFields[0][4]);
            Name             = groupResponse.DataFields[0][5];
            ShortName        = groupResponse.DataFields[0][6];
            IrcChannel       = groupResponse.DataFields[0][7];
            IrcServer        = groupResponse.DataFields[0][8];
            Url              = groupResponse.DataFields[0][9];
            PicName          = groupResponse.DataFields[0][10];
            FoundedDate      = int.Parse(groupResponse.DataFields[0][11]);
            DisbandedDate    = int.Parse(groupResponse.DataFields[0][12]);
            DateFlags        = (DateFlag)short.Parse(groupResponse.DataFields[0][13]);
            LastReleaseDate  = int.Parse(groupResponse.DataFields[0][14]);
            LastActivityDate = int.Parse(groupResponse.DataFields[0][15]);

            GroupRelations = new Dictionary <int, RelationType>();
            for (int i = 16; i < groupResponse.DataFields.Length; i++)
            {
                string[] relation = groupResponse.DataFields[0][i].Split('\'');

                GroupRelations.Add(int.Parse(relation[1]), (RelationType)int.Parse(relation[0]));
            }
        }
Esempio n. 4
0
        internal protected void OnResponse(AniDBResponse response)
        {
            var handler = ResponseHandler;

            if (handler != null)
            {
                handler(response);
            }
        }
Esempio n. 5
0
		public AniDBRequest(string command, IEnumerable<KeyValuePair<string, string>> parValues)
		{
			Command = command;
			Tag = ShortGuid.NewGuid().ToString();
			ParValues = parValues.ToDictionary(p => p.Key, p => p.Value);

			ResponseHandler += r => _response = r;

			Timeout = new Timer
								{
									Enabled = false,
									AutoReset = false
								};
		}
Esempio n. 6
0
        public AniDBRequest(string command, IEnumerable <KeyValuePair <string, string> > parValues)
        {
            Command   = command;
            Tag       = ShortGuid.NewGuid().ToString();
            ParValues = parValues.ToDictionary(p => p.Key, p => p.Value);

            ResponseHandler += r => _response = r;

            Timeout = new Timer
            {
                Enabled   = false,
                AutoReset = false
            };
        }
Esempio n. 7
0
        public void HandleResponse(AniDBResponse response)
        {
            if (response.Code == AniDBResponse.ReturnCode.LOGIN_ACCEPTED ||
                response.Code == AniDBResponse.ReturnCode.LOGIN_ACCEPTED_NEW_VERSION)
            {
                SessionKey = response.ReturnString.Split(new [] { ' ' }, 2)[0];
            }

            if (response.Code == AniDBResponse.ReturnCode.LOGGED_OUT ||
                response.Code == AniDBResponse.ReturnCode.LOGIN_FAILED ||
                response.Code == AniDBResponse.ReturnCode.LOGIN_FIRST)
            {
                SessionKey = "";
            }

            AniDBRequest request;

            if (_sentRequests.TryRemove(response.Tag, out request))
            {
                request.Timeout.Stop();
                request.OnResponse(response);
            }
        }
Esempio n. 8
0
        private async void RecievePackets()
        {
            while (true)
            {
                try
                {
                    var result = await _udpClient.ReceiveAsync();

                    byte[] responseBytes = result.Buffer;

                    if (responseBytes == null)
                    {
                        continue;
                    }

                    var response = new AniDBResponse(responseBytes, _encoding);
                    new Task(() => HandleResponse(response)).Start();
                }
                catch (ObjectDisposedException ode)
                {
                    break;
                }
            }
        }
Esempio n. 9
0
		public Episode(AniDBResponse response)
		{
			if(response.Code != AniDBResponse.ReturnCode.EPISODE)
				throw new ArgumentException("Response is not an EPISODE response");

			List<string> dataFields = new List<string>();
			foreach (string[] s in response.DataFields)
				dataFields.AddRange(s);

			EID = int.Parse(dataFields[0]);
			AID = int.Parse(dataFields[1]);
			Length = int.Parse(dataFields[2]);
			Rating = int.Parse(dataFields[3]);
			Votes = int.Parse(dataFields[4]);

			EpisodeNumber = int.Parse(Char.IsDigit(dataFields[5][0]) ? dataFields[5] : dataFields[5].Remove(0, 1));

			EnglishName = dataFields[6];
			RomanjiName = dataFields[7];
			KanjiName = dataFields[8];
			AirDate = int.Parse(dataFields[9]);
			SpecialType = (Special)int.Parse(dataFields[10]);
			//TODO: Sanity check that SpecialType matches SpecialTypeNo
		}
Esempio n. 10
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++;
            }
        }
Esempio n. 11
0
		internal protected void OnResponse(AniDBResponse response)
		{
			var handler = ResponseHandler;
			if (handler != null) handler(response);
		}
Esempio n. 12
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);
            }
        }
Esempio n. 13
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++;
			}
		}
Esempio n. 14
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);

			}
		}
Esempio n. 15
0
		public void HandleResponse(AniDBResponse response)
		{
			if (response.Code == AniDBResponse.ReturnCode.LOGIN_ACCEPTED ||
				response.Code == AniDBResponse.ReturnCode.LOGIN_ACCEPTED_NEW_VERSION)
					SessionKey = response.ReturnString.Split(new [] {' '}, 2)[0];

			if (response.Code == AniDBResponse.ReturnCode.LOGGED_OUT ||
				response.Code == AniDBResponse.ReturnCode.LOGIN_FAILED ||
				response.Code == AniDBResponse.ReturnCode.LOGIN_FIRST)
					SessionKey = "";

			AniDBRequest request;
			if (_sentRequests.TryRemove(response.Tag, out request))
			{
				request.Timeout.Stop();
				request.OnResponse(response);
			}
		}
Esempio n. 16
0
		private async void RecievePackets()
		{
			while(true)
			{
				try
				{
					var result = await _udpClient.ReceiveAsync();

					byte[] responseBytes = result.Buffer;
					
					if (responseBytes == null)
						continue;

					var response = new AniDBResponse(responseBytes, _encoding);
					new Task(() => HandleResponse(response)).Start();
				}
				catch(ObjectDisposedException ode)
				{
					break;
				}
			}
		}