static void Main(string[] args) { var dllFile = new FileInfo(@"..\SimpleLib.WeatherAdapters\bin\Debug\netcoreapp2.1\SimpleLib.WeatherAdapters.dll"); var weatherAdapterType = typeof(IWeatherServiceAdapter); var weatherAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(dllFile.FullName); var weatherAssemplyTypes = weatherAssembly.GetTypes().Where(t => weatherAdapterType.IsAssignableFrom(t)).ToList(); var factory = new WeatherServiceFactory(weatherAssemplyTypes); CommandLineApplication commandLineApplication = new CommandLineApplication(throwOnUnexpectedArg: false); CommandArgument location = null; commandLineApplication.Command("location", (target) => location = target.Argument( "location", "Enter the location name.", multipleValues: false)); CommandOption service = commandLineApplication.Option( "-$|-s |--service <service>", "Weather service to use. The greeting supports" + " two types of service 'metaweather' and 'apixu'", CommandOptionType.SingleValue); commandLineApplication.HelpOption("-? | -h | --help"); commandLineApplication.OnExecute(() => { if (service.HasValue()) { var weatherServiceAdapter = factory.CreateServiceAdapter(service.Value()); var weatherService = new WeatherService(weatherServiceAdapter); var result = Task.Run(() => weatherService.GetWeatherData("london")).Result; Console.WriteLine(result); } return(0); }); commandLineApplication.Execute(args); }
static void ProzessWheaterRequest(ref BackgroundTaskModel model) { try { IWeatherService ws = WeatherServiceFactory.GetWeatherServiceFactory(); var response = ws.GetWeatherData( new JSONHelper <WeatherTaskRequestModel>().Deserialize( model.TaskData) ); if (response != null) { model.TaskResponse = new JSONHelper <WeatherTaskResponseModel>().Serialize(response.Result); model.ProcessedSuccessfully = true; return; } model.ProcessedSuccessfully = false; }catch (Exception ex) { throw; } }