Json.GetLastVersion C# (CSharp) Method

GetLastVersion() public method

public GetLastVersion ( string currentVersion ) : bool
currentVersion string
return bool
    public bool GetLastVersion(string currentVersion)
    {
        // Create a request using a URL that can receive a post.
        WebRequest request = WebRequest.Create (serverUrl + "/version");

        // Set the Method property of the request to GET.
        request.Method = "GET";

        // Set the ContentType property of the WebRequest.
        //request.ContentType = "application/x-www-form-urlencoded";

        HttpWebResponse response;
        try {
            response = (HttpWebResponse) request.GetResponse();
        } catch {
            this.ResultMessage =
                Catalog.GetString("Could not get last version.") + "\n" +
                string.Format(Catalog.GetString("You are not connected to the Internet\nor {0} server is down."),
                serverUrl);
            return false;
        }

        string responseFromServer;
        using (var sr = new StreamReader(response.GetResponseStream()))
        {
            responseFromServer = sr.ReadToEnd();
        }

        //this prints:
        // {"stable": "1.4.9"}
        //this.ResultMessage = "Last version published: " + responseFromServer;

        string [] strFull = responseFromServer.Split(new char[] {':'});
        int startPos = strFull[1].IndexOf('"') +1;
        int endPos = strFull[1].LastIndexOf('"') -2;

        string lastVersionPublished = strFull[1].Substring(startPos,endPos); //1.4.9

        string updateStr = "";
        if(currentVersion != lastVersionPublished)
            updateStr = "\n\n" + Catalog.GetString("Update software at ") + "www.chronojump.org";

        this.ResultMessage =
            Catalog.GetString("Installed version is: ") + currentVersion + "\n" +
            Catalog.GetString("Last version published: ") + lastVersionPublished +
            updateStr;

        //ChronojumpUpdated = (currentVersion == ResultMessage);

        return true;
    }

Usage Example

Ejemplo n.º 1
0
    private void on_button_check_last_version_clicked(object o, EventArgs args)
    {
        Json js      = new Json();
        bool success = js.GetLastVersion(progVersion);

        if (success)
        {
            LogB.Information(js.ResultMessage);
            label_send_log_message.Text = js.ResultMessage;
        }
        else
        {
            LogB.Error(js.ResultMessage);
            label_send_log_message.Text = js.ResultMessage;
        }
    }
All Usage Examples Of Json::GetLastVersion