1. Iacopo Pace's Avatar
    Hi everyone,
    I have a very strange problem. I am using a scheduled task to update my live tile, which is rendered using the TCD Controls live tile library through a JSON data retrieved from a REST API.
    The tile is updated normally on WP8 (lumia 620) and WP7.8 when connected to the debugger (Lumia 800).

    When WP7.8 is not connected to the debugger, the REST API is called, data retrieved but the tile won't be rendered... By debugging the app through toasts, I noticed the fault is inside the RenderTileTemplate method, which works good without the REST call, though (e.g.: getting the data locally, not through REST call).
    Can anyone help me? Here is the code:

    [CODE]
    Uri back = null;
    String txt = null;
    int fontSize = 0;
    if (!NetworkInterface.GetIsNetworkAvailable())
    {
    return;
    }
    var client = new RestClient("REST API URL");
    RestRequest reqCredit = new RestRequest();
    reqCredit.Resource = "allInfo";
    reqCredit.RootElement = "Values";
    reqCredit.AddParameter("uid", uid);
    reqCredit.AddParameter("pwd", pwd);
    reqCredit.RequestFormat = DataFormat.Json;
    reqCredit.Method = Method.GET;

    client.ExecuteAsync<AllInfoJSON>(reqCredit, (response)
    =>
    {
    if (response != null && response.StatusCode == HttpStatusCode.OK && !response.Data.status.Equals("error", StringComparison.OrdinalIgnoreCase))
    {
    txt = response.Data.creditValues[0].value;

    fontSize = 0;

    Deployment.Current.Dispatcher.BeginInvoke(new Action(delegate//rendering done on the UI thread!!!!!
    {
    //MediumTileTemplate is custom but works... changing it to default one doesn't help....
    back = TileRenderer.RenderTileTemplate(new MediumTileTemplate(txt, fontSize), "creditoTreTile", TileSize.Medium_336x336);//render the tile
    }));
    }
    });

    while (back == null)
    {
    System.Threading.Thread.Sleep(1000);
    }
    // Code is never reached unless debugging on WP7.8 or WP8
    String backTitle = "Il " + DateTime.Now.Date.Day + "/" + DateTime.Now.Date.Month + "@" + DateTime.Now.ToString("HH:mm");
    if (TileSetter.IsNewTilesSupported) {
    if (DBManagement.isInfoFrontOn())
    {
    TileSetter.SetPrimaryTileFlipTemplate(backTitle, "Credito Tre", "", "", 0, null, back, new Uri("Background.png", UriKind.Relative), null, null);
    } else {
    TileSetter.SetPrimaryTileFlipTemplate("Credito Tre", backTitle, "", "", 0, null, new Uri("Background.png", UriKind.Relative), back, null, null);
    }
    } else {
    if (DBManagement.isInfoFrontOn())
    {
    TileSetter.SetPrimaryTile(backTitle, "Credito Tre", "", 0, back, new Uri("Background.png", UriKind.Relative));
    } else {
    TileSetter.SetPrimaryTile("Credito Tre", backTitle, "", 0, new Uri("Background.png", UriKind.Relative), back);
    }
    }

    NotifyComplete();
    [/CODE]

    And the RenderTileTemplate code, is public on NuGet, and reported here. The error is at the Render call or, time to time, at the Encode call:
    [CODE]
    public static Uri RenderTileTemplate(Control template, string filename, TileSize tileSize = TileSize.Medium_336x336)
    {
    string dims = tileSize.ToString();
    dims = dims.Substring(dims.LastIndexOf('_') + 1);
    int[] size = new int[] { Convert.ToInt32(dims.Substring(0, 3)), Convert.ToInt32(dims.Substring(4, 3)) };
    template.Measure(new Size(size[0], size[1]));
    template.Arrange(new Rect(0, 0, size[0], size[1]));
    WriteableBitmap wb = new WriteableBitmap(size[0], size[1]);
    wb.Render(template, null);
    wb.Invalidate();
    var encoder = new PngEncoder();
    using (var str = new IsolatedStorageFileStream(string.Format(pattern, filename), FileMode.Create, isoStore))
    {
    encoder.Encode(wb.ToImage(), str);
    }
    return //The URI PATH;
    }
    [/CODE]

    Thanks a lot! :)
    03-09-2013 08:34 PM

Similar Threads

  1. WP7.5 problem: some contacts are disappearing
    By shanerobot in forum Windows Phone 7
    Replies: 0
    Last Post: 10-02-2012, 02:57 AM
  2. What problems do you hope WP8 fixes in WP7?
    By Mokonoko in forum Windows Phone 8
    Replies: 49
    Last Post: 09-06-2012, 04:55 PM
  3. Replies: 4
    Last Post: 02-16-2012, 12:44 AM
  4. Focus/WP7 users plz help - 3G/Wifi problem?
    By bradleyj in forum Samsung Focus
    Replies: 2
    Last Post: 11-06-2011, 10:13 AM
  5. Wp7 apps/games installation problem
    By dohukgamer in forum Windows Phone 7
    Replies: 3
    Last Post: 08-30-2011, 02:55 AM
LINK TO POST COPIED TO CLIPBOARD