OK, this may be hard to explain so forgive me if you don't understand any of it. I am porting some of my functions that were previously in classes in my main application into a class library so I can use them in any projects. I have literally just started this so the code might not be very complete but I have this so far:
namespace WeatherLink
{
public class DataDownloader
{
public class MetOffice
{
public DataType DataType;
public bool CacheData;
public string CacheLocation;
public string ApiKey;
public string GetData()
{
string resource = "";
if (DataType.Type == "VisibleObservation")
{
string sourcePath = string.Format(Path.Combine(@"C:\Users\Henry\AppData\Local\WeatherLink\temp\runtime_cache\visibleObservation"));
if (!File.Exists(sourcePath))
{
string sourceImage = string.Format("http://datapoint.metoffice.gov.uk/public/data/layer/wxobs/SATELLITE_Visible_N_Section/png?TIME={0}Z&key={1}");
System.Drawing.Bitmap image = new Bitmap(Image.FromStream(System.Net.HttpWebRequest.Create(sourceImage).GetResponse().GetResponseStream()));
Bitmap bitmap = new Bitmap(640, 852);
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.DrawImage(image, new Point[] { new Point(0, 0), new Point(650, 0), new Point(0, 852) });
bitmap.Save(sourcePath);
resource = sourcePath;
}
}
else { resource = sourcePath; }
return resource;
}
return resource;
}
}
public class EuMetSat
{
}
}
public class DataType
{
public string Type { get; set; }
}
}
...and I call it like this:
DataDownloader.MetOffice MetOffice = new DataDownloader.MetOffice();
DataDownloader.EuMetSat EuMetSat = new DataDownloader.EuMetSat();
I want to know how I can change my code in the library so that I can call a DataDownloader like this:
DataDownloader dd = new DataDownloader(MetOffice);
DataDownloader dd = new DataDownloader(EuMetSat);
...So instead of calling it using all the levels of the namespace I want to call the DataDownloader and specify its type (either MetOffice or EuMetSat). How do I do this? Would I have to use methods instead of classes for the 2 types? Like when you initiate most variables, as an example an XmlDocument has brackets after it (new XmlDocument()) where you could specify something for it. How would I do this in my code (new DataDownloader(MetOffice))? I hope you understand what I am trying to do. Thank You