public static ITunerHost CreateTunerHost(TunerUserConfiguration tunerUserConfiguration, ILogger logger, IJsonSerializer jsonSerializer, IHttpClient httpClient) { ITunerHost tunerHost; logger.Info("Creating a TunerHost of type: " + tunerUserConfiguration.ServerType); IEnumerable <Type> hostTypes = TunerHostStatics.GetAllTunerHostTypes(); Type hostType = hostTypes.FirstOrDefault(t => String.Equals(t.Name, tunerUserConfiguration.ServerType, StringComparison.OrdinalIgnoreCase)); tunerHost = (ITunerHost)Activator.CreateInstance(hostType, logger, jsonSerializer, httpClient); foreach (var field in tunerUserConfiguration.UserFields) { logger.Info("Adding variable: " + field.Name + " with value of " + field.Value); tunerHost.GetType().GetProperty(field.Name).SetValue(tunerHost, field.Value, null); logger.Info("Added: " + field.Name + " with value of " + field.Value); } logger.Info("Done Creating Tuner"); return(tunerHost); }
public static ITunerHost CreateTunerHost(TunerUserConfiguration tunerUserConfiguration, ILogger logger, IJsonSerializer jsonSerializer, IHttpClient httpClient) { ITunerHost tunerHost; logger.Info("Creating a TunerHost of type: " + tunerUserConfiguration.ServerType.ToString()); switch (tunerUserConfiguration.ServerType) { case (TunerServerType.HdHomerun): tunerHost = new HdHomeRunHost(logger, jsonSerializer, httpClient); break; default: throw new ApplicationException("Not a valid host"); } foreach (var field in tunerUserConfiguration.UserFields) { logger.Info("Adding variable: " + field.Name + " with value of " + field.Value); tunerHost.GetType().GetProperty(field.Name).SetValue(tunerHost, field.Value, null); } logger.Info("Done Creating Tuner"); return(tunerHost); }