0

since a couple of days I'm trying to write a C# program for my WP7 phone to get some kind of data file from a website.

There is a main link (http://www.convert-control.de/plant/53752/yield/2012) which generates a chart view of the yield my solar panels produced at a specific time. Here above its for the year 2012. Changing the request to ... yield/2012/4/5 will give you the yield of the 5th of april.

So what happend is, that after this request, the server will generate a file which is caled chartdata.

After I've called the main link, I'm able to fire up a 2nd request which is http://www.convert-control.de//chartdata/53752 in my browser and I get the related data. These data are used to fill the charts. This chart is a swf object.

So, my question is now, how can I write my request in c# for a WP7 program, thats giving me the data for further usage?

Thanks for your help, Jo

1 Answers1

0

Jo!

Getting data is simple. Your data is under 8kb in size, the best method for such small volume is IMO using WebClient.DownloadStringAsync method (or DownloadStringTaskAsync is you'll decide to use Async CTP which I recommend, BTW).

After you've got your response in a string, I suggest using Json.NET to parse it into the strongly-typed objects. Here's the code auto-generated by json2csharp.com from your data, with only a few fixes (untested):

public class Title
{
    public string text { get; set; }
}

public class Key
{
    public string text { get; set; }
    public string colour { get; set; }
    [JsonProperty("font-size")]
    public int font_size { get; set; }
}

public class Val
{
    public string colour, tip;
    public int val;
}

public class Element
{
    public string type { get; set; }
    public int alpha { get; set; }
    public List<List<Val>> values { get; set; }
    public List<Key> keys { get; set; }
}

public class Tooltip
{
    public bool shadow { get; set; }
    public int stroke { get; set; }
    public string colour { get; set; }
    public string background { get; set; }
    public string title { get; set; }
    public string body { get; set; }
}

public class Labels
{
    public List<string> labels { get; set; }
    public int steps { get; set; }
}

public class XAxis
{
    public string colour { get; set; }
    public Labels labels { get; set; }
    [JsonProperty("grid-colour")]
    public string grid_colour { get; set; }
}

public class YAxis
{
    public int min { get; set; }
    public int max { get; set; }
    public int steps { get; set; }
    [JsonProperty("grid-colour")]
    public string grid_colour { get; set; }
    public string colour { get; set; }
}

public class XLegend
{
    public string text { get; set; }
    public string style { get; set; }
}

public class YLegend
{
    public string text { get; set; }
    public string style { get; set; }
}

public class RootObject
{
    public Title title { get; set; }
    public List<Element> elements { get; set; }
    public string bg_colour { get; set; }
    public Tooltip tooltip { get; set; }
    public int num_decimals { get; set; }
    public bool is_fixed_num_decimals_forced { get; set; }
    public bool is_decimal_separator_comma { get; set; }
    public XAxis x_axis { get; set; }
    public YAxis y_axis { get; set; }
    public XLegend x_legend { get; set; }
    public YLegend y_legend { get; set; }
}

Then, you call JsonConvert.DeserializeObject<RootObject>( response ) with the response string you've got from the web server, and you ret a strongly-types C# object holding all the response data. Process or visualize it however you like.

AFAIK currently there's no way to reuse your SWF control on the Windows Phone. You must create your own UI to visualize your data. If you need help with that part, you should probably google and/or post another question here.

Soonts
  • 20,079
  • 9
  • 57
  • 130
  • Thanks, thats interresting. I never used JSON. I'll give it a try and will see what happens. – User7545875q Feb 18 '13 at 15:08
  • Aih,... unfortunately its not the answer to my question. The thing is, that I'm NOT able to get this data at all. Basically (in the browser) this chartdata URL is generated and stored somewhere, when I fire up http://www.convert-control.de/plant/53752/yield/2012. THEN (in a browser), I can type the chartdata adress to get what I need. Filtering the data has already been done. I'm using HTMLAgilityPack to do so. The question is: how can I trigger the 1st link to be able to receive the 2nd. Thanx, Jo – User7545875q Feb 18 '13 at 15:24
  • Download the first document (you don't need any linked contentm just the HTML). The header says it's XHTML 1.0 Strict, so if you're lucky you'll be able to load it into the XML parser. Once parsed, perform the XPath query "//object[@id=yieldChart]/param[@name=flashvars]/@value", the node value will be e.g. "data-file=/en/chartdata/53752", /en/chartdata/53752 is the data you need. – Soonts Feb 19 '13 at 03:43
  • But, you don't need to "trigger the 1st link to be able to receive the 2nd". The 2nd link can be easily constructed from the first, by extremely cheap string operations (e.g. with a regexp), if the 1st is "control.de/plant/#####/yield/2012" then the 2-nd is control.de/en/startdata/##### where "#####" is dec.imal digits. – Soonts Feb 19 '13 at 03:46
  • hmmm,... the 1st answer I have to check but I'm not very sure I understand what you meen with it. But the 2nd dont work. When you simply call .../chartdata/xxxxxx it gives you nothing. I think, when the .../yield/... was triggert, THEN something will be stored in the temp browser directory. And then the link is available. Might be, that a JAVA Script is doing the job and prepares a file on the remote site (convert-control) which will be downloadable hereafter... By the way ... these digits are the account of my solar controler. It stays the same overall, – User7545875q Feb 19 '13 at 22:34