internal UpdateAcceptForm(IUpdateable applicationInfo, UpdateXml updateInfo)
        {
            InitializeComponent();

            this.applicationInfo = applicationInfo;
            this.updateInfo      = updateInfo;
            this.Text            = this.applicationInfo.ApplicationName;
            if (this.applicationInfo.ApllicationIcon != null)
            {
                this.Icon = applicationInfo.ApllicationIcon;
            }
            this.labelNewVersion.Text = $"New version {this.updateInfo.Version.ToString()}";
        }
        internal UpdateInfoForm(IUpdateable applicationInfo, UpdateXml updateInfo)
        {
            InitializeComponent();

            if (applicationInfo.ApllicationIcon != null)
            {
                this.Icon = applicationInfo.ApllicationIcon;
                this.Text = applicationInfo.ApplicationName + " - Update Info";
                this.labelVersions.Text =
                    $"Current version {applicationInfo.ApplicationAssembly.GetName().Version.ToString()}\n" +
                    $"Update version {updateInfo.Version.ToString()}";
                this.richTextBoxDescription.Text = updateInfo.Description;
            }
        }
        private void BgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                MessageBox.Show("No updates available.");
            }

            UpdateXml[] updateXmls           = e.Result as UpdateXml[];
            UpdateXml   senderApplicationXml =
                updateXmls?.SingleOrDefault(xml => xml.FileName == "MetricsSenderApplication.exe"); // Version of sender is the version of the system

            if (updateXmls != null && senderApplicationXml != null &&
                senderApplicationXml.IsNewerThan(applicationInfo.ApplicationAssembly.GetName().Version))
            {
                if (new UpdateAcceptForm(applicationInfo, updateXmls[0]).ShowDialog(applicationInfo.Context) == DialogResult.Yes)
                {
                    this.DownloadUpdate(updateXmls);
                }
            }
            else
            {
                MessageBox.Show("No updates available.");
            }
        }
        private void BgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            IUpdateable application = (IUpdateable)e.Argument;

            bool existsOnServer;

            try
            {
                existsOnServer = UpdateXml.ExistsOnServer(application.UpdateXmlUri);
            }
            catch (Exception ex)
            {
                existsOnServer = false;
            }

            if (!existsOnServer)
            {
                e.Cancel = true;
            }
            else
            {
                e.Result = UpdateXml.Parse(application.UpdateXmlUri, application.ApplicationID);
            }
        }
        internal static UpdateXml[] Parse(Uri location, string appID)
        {
            Version version = null;
            string  url = "", fileName = "", md5 = "", description = "", launchArgs = "";

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(location.AbsoluteUri);

                XmlNodeList nodes = doc.DocumentElement.SelectNodes($"//update[@appId='{appID}']");

                if (nodes == null)
                {
                    return(null);
                }

                UpdateXml[] xmls = new UpdateXml[nodes.Count];

                for (int i = 0; i < nodes.Count; i++)
                {
                    version     = System.Version.Parse(nodes[i]["version"].InnerText);
                    url         = nodes[i]["url"].InnerText;
                    fileName    = nodes[i]["fileName"].InnerText;
                    md5         = nodes[i]["md5"].InnerText.ToLower();
                    description = nodes[i]["description"].InnerText;
                    launchArgs  = nodes[i]["launchArgs"].InnerText;
                    xmls[i]     = new UpdateXml(version, new Uri(url), fileName, md5, description, launchArgs);
                }
                return(xmls);
            }
            catch (Exception e)
            {
                return(null);
            }
        }