コード例 #1
0
		private async Task<IEncoder> getEncoderAsync(ITrack track)
		{
			var encoder = await track.GetValueAsync("Encoder");
			if (String.IsNullOrWhiteSpace(encoder))
			{
				if (log.IsFatalEnabled)
				{
					log.Fatal("No valid Encoder property found quitting");
				}

				return null;
			}

			var encoderSplit = encoder.Value.Split(',');
			if (encoderSplit.Length < 2)
			{
				if (log.IsFatalEnabled)
				{
					log.FatalFormat("Encoder is in the incorrect formation it should be '<FullTypeName>, <FullAssemblyName>' instead '{0}' was received.", encoder);
				}

				return null;
			}
			ObjectHandle encoderBox = null;
			try
			{
				encoderBox = Activator.CreateInstance(encoderSplit[1], encoderSplit[0]);
			}
			catch (Exception ex)
			{
				if (log.IsFatalEnabled)
				{
					log.FatalFormat("An exception was thrown while trying to create an encoder of type '{0}'. Exception: {1}", encoder, ex);
				}
				return null;
			}

			if (encoderBox == null)
			{
				if (log.IsFatalEnabled)
				{
					log.FatalFormat("Unable to create an encoder of type '{0}'.", encoder);
				}

				return null;
			}

			IEncoder e = encoderBox.Unwrap() as IEncoder;
			if (e == null)
			{
				if (log.IsFatalEnabled)
				{
					log.FatalFormat("Type of {0} does not implement IEncoder.", encoderBox.Unwrap().GetType());
				}
				return null;
			}

			return e;
		}
コード例 #2
0
		private async Task<IMetaData> getMetaDataAsync(ITrack track)
		{
			var metaDataType = await track.GetValueAsync("MetaData");
			if (String.IsNullOrWhiteSpace(metaDataType))
			{
				if (log.IsFatalEnabled)
				{
					log.Fatal("No valid MetaData property found quitting");
				}

				return null;
			}

			var metaDataSplit = metaDataType.Value.Split(',');
			if (metaDataSplit.Length < 2)
			{
				if (log.IsFatalEnabled)
				{
					log.FatalFormat("MetaData is in the incorrect formation it should be '<FullTypeName>, <FullAssemblyName>' instead '{0}' was received.", metaDataType);
				}

				return null;
			}
			ObjectHandle metaDataBox = null;
			try
			{
				metaDataBox = Activator.CreateInstance(metaDataSplit[1], metaDataSplit[0]);
			}
			catch (Exception ex)
			{
				if (log.IsFatalEnabled)
				{
					log.FatalFormat("An exception was thrown while trying to create an IMetaData of type '{0}'. Exception: {1}", metaDataType, ex);
				}
				return null;
			}

			if (metaDataBox == null)
			{
				if (log.IsFatalEnabled)
				{
					log.FatalFormat("Unable to create an IMetaData of type '{0}'.", metaDataType);
				}

				return null;
			}

			IMetaData md = metaDataBox.Unwrap() as IMetaData;
			if (md == null)
			{
				if (log.IsFatalEnabled)
				{
					log.FatalFormat("Type of {0} does not implement IMetaData.", metaDataBox.Unwrap().GetType());
				}
				return null;
			}

			return md;
		}
コード例 #3
0
		protected virtual async Task<String> GetArgumentsAsync(ITrack track, String sourceFile, String destinationFile)
		{
			if (track == null)
			{
				throw new ArgumentNullException("track");
			}

			if (sourceFile == null)
			{
				throw new ArgumentNullException("sourceFile");
			}

			if (destinationFile == null)
			{
				throw new ArgumentNullException("destinationFile");
			}

			StringBuilder arguments = new StringBuilder();
			arguments.AppendFormat("\"{0}\" --output \"{1}\" ", Methods.FixString(Methods.ChangeDirectorySeparator(sourceFile, '/')), Methods.FixString(Methods.ChangeDirectorySeparator(destinationFile, '/')));

			PropertyMetaData value = await track.GetValueAsync("ShowName");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--TVShowName \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("MediaKind");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--stik \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("Genre");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--genre \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("Image");
			if (!String.IsNullOrWhiteSpace(value))
			{
				String imagePath = value.Value;
				if (!Path.IsPathRooted(value.Value))
				{
					imagePath = Path.GetFullPath(Path.Combine(value.FullPath, value.Value));
				}
				arguments.AppendFormat("--artwork \"{0}\" ", Methods.FixString(Methods.ChangeDirectorySeparator(imagePath, '/')));
			}

			value = await track.GetValueAsync("Title");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--title \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("Description");
			if (!String.IsNullOrWhiteSpace(value))
			{
				if (value.Value.Length > 255)
				{
					value = value.Value.Substring(0, 252) + "...";
				}
				arguments.AppendFormat("--description \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("Album");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--album \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("TrackNumber");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--tracknum \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("DiskNumber");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--disk \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("EID");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--TVEpisode \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("Episode");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--TVEpisodeNum \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("Season");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--TVSeasonNum \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("Year");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--year \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("Artist");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--artist \"{0}\" ", Methods.FixString(value));
			}

			value = await track.GetValueAsync("AlbumArtist");
			if (!String.IsNullOrWhiteSpace(value))
			{
				arguments.AppendFormat("--composer \"{0}\" ", Methods.FixString(value));
			}

			return arguments.ToString();
		}