Exemple #1
0
        void LogLevel_OnSelectionChanged(object sender, RoutedEventArgs e)
        {
            ComboBox logCombo = sender as ComboBox;

            if (logCombo != null)
            {
                theBackendData.WriteLog("log_level combo selected\n", eid_vwr_loglevel.EID_VWR_LOG_DETAIL);

                switch (logCombo.SelectedIndex)
                {
                //only save changes if they are not set yet (this event also gets fired during initialization)
                case 0:
                    if (theBackendData.log_level != eid_vwr_loglevel.EID_VWR_LOG_ERROR)
                    {
                        theBackendData.log_level = eid_vwr_loglevel.EID_VWR_LOG_ERROR;
                        theBackendData.StoreViewerLogLevel("Error");
                        theBackendData.WriteLog("switched log_level to Error\n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL);
                    }
                    break;

                case 1:
                    if (theBackendData.log_level != eid_vwr_loglevel.EID_VWR_LOG_COARSE)
                    {
                        theBackendData.log_level = eid_vwr_loglevel.EID_VWR_LOG_COARSE;
                        theBackendData.StoreViewerLogLevel("Warning");
                        theBackendData.WriteLog("switched log_level to Warning\n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL);
                    }
                    break;

                case 2:
                    if (theBackendData.log_level != eid_vwr_loglevel.EID_VWR_LOG_NORMAL)
                    {
                        theBackendData.log_level = eid_vwr_loglevel.EID_VWR_LOG_NORMAL;
                        theBackendData.StoreViewerLogLevel("Info");
                        theBackendData.WriteLog("switched log_level to Info\n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL);
                    }
                    break;

                case 3:
                    if (theBackendData.log_level != eid_vwr_loglevel.EID_VWR_LOG_DETAIL)
                    {
                        theBackendData.log_level = eid_vwr_loglevel.EID_VWR_LOG_DETAIL;
                        theBackendData.StoreViewerLogLevel("Debug");
                        theBackendData.WriteLog("switched log_level to Debug\n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL);
                    }
                    break;

                default:
                {
                    theBackendData.WriteLog("invalid index of log_level combo selected\n", eid_vwr_loglevel.EID_VWR_LOG_COARSE);
                    break;
                }
                }
            }
        }
Exemple #2
0
        /*
         *
         * <beid>
         * <OS name="windows">
         *      <comp name="eid-viewer">
         *              <latest-version major="5" minor="1" build="20">
         *                      <latest-url	url = "https://eid.belgium.be/" url_nl = "https://eid.belgium.be/nl" url_fr = "https://eid.belgium.be/fr" url_de = "https://eid.belgium.be/de" url_en = "https://eid.belgium.be/en"/>
         *                      <release-notes url = "https://eid.belgium.be/sites/default/files/software/RN5020.pdf"/>
         *                      <auto-upgrade-versions>
         *                              <auto-upgrade-version>
         *                                      <min major="5" minor="0" build="6"/>
         *                                      <max major="5" minor="0" build="8"/>
         *                              </auto-upgrade-version>
         *                              <auto-upgrade-version>
         *                                      <min major="5" minor="0" build="10"/>
         *                                      <max major="5" minor="2" build="16"/>
         *                              </auto-upgrade-version>
         *                      </auto-upgrade-versions>
         *              </latest-version>
         *              <latest-supported-OS>
         *                      <oldOS version = "6.1">
         *                              <oldOS-latest-version major="4" minor="4" build="20">
         *                                      <oldOS-latest-url   url = "https://eid.belgium.be/" url_nl = "https://eid.belgium.be/nl" url_fr = "https://eid.belgium.be/fr" url_de = "https://eid.belgium.be/de" url_en = "https://eid.belgium.be/en"/>
         *                                      <oldOS-release-notes url = "https://eid.belgium.be/sites/default/files/software/RN4420.pdf"/>
         *                              </oldOS-latest-version>
         *
         *                      </oldOS>
         *                      <oldOS version = "6.2">
         *                              <oldOS-latest-version major="5" minor="1" build="2">
         *                                      <oldOS-latest-url   url = "https://eid.belgium.be/" url_nl = "https://eid.belgium.be/nl" url_fr = "https://eid.belgium.be/fr" url_de = "https://eid.belgium.be/de" url_en = "https://eid.belgium.be/en"/>
         *                                      <oldOS-release-notes url = "https://eid.belgium.be/sites/default/files/software/RN502.pdf"/>
         *                              </oldOS-latest-version>
         *                      </oldOS>
         *              </latest-supported-OS>
         *      </eid-viewer>
         * </OS>
         * <OS name="macOS">
         * </OS>
         * </beid>
         *
         * */

        public static bool getUpdateUrl(out bool updateNeeded, string lang, ref string url, ref string releaseNotes)
        {
            XmlTextReader textReader = new XmlTextReader("https://eid.belgium.be/sites/default/files/software/eidversions.xml");

            updateNeeded = false;
            bool keepParsing = true;

            url = "";

            try
            {
                //jump to the <OS name="windows"> section
                if (!jumpToSubElement(ref textReader, "OS", "name", "windows", "beid"))
                {
                    return(false);
                }

                //in the windows section, jump to the <comp name="eid-viewer"> section
                if (!jumpToSubElement(ref textReader, "comp", "name", "eid-viewer", "beid"))
                {
                    return(false);
                }

                //within the <OS name="windows"> <comp name="eid-viewer"> element, search for the subelements <latest-version> and <latest-supported-OS>
                //walk trough all the nodes
                while (textReader.Read() && keepParsing)
                {
                    switch (textReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        //check if this viewer's version is within the update range
                        //do not return when done, if the OS this viewer is running on is part of the latest-supported-OS,
                        //a different update (or none) is required
                        if (String.Equals(textReader.Name, "latest-version", StringComparison.Ordinal))
                        {
                            //get the latest version number from the attributes
                            //if this one equals the current version, stop parsing
                            if (CompareXMLToCurrentVersion(ref textReader) > 0)
                            {
                                //there is a higher version number present, now fill in all data from the xml (url, release_notes)
                                //verify if our version number is within an auto update range
                                while (textReader.Read() && keepParsing)
                                {
                                    switch (textReader.NodeType)
                                    {
                                    case XmlNodeType.Element:

                                        //parse the multiple version ranges
                                        if (String.Equals(textReader.Name, "latest-url", StringComparison.Ordinal))
                                        {
                                            //check if this element contains the url attribute, if so, store it in the url string
                                            CheckAttributeValue(ref textReader, "url_" + lang, ref url);
                                            //if no url of this viewer's language is specified, try getting the default url
                                            if (url.Equals(""))
                                            {
                                                CheckAttributeValue(ref textReader, "url", ref url);
                                            }
                                        }

                                        else if (String.Equals(textReader.Name, "release-notes", StringComparison.Ordinal))
                                        {
                                            //check if this element contains the url attribute, if so, store it in the url string
                                            CheckAttributeValue(ref textReader, "url", ref releaseNotes);
                                        }

                                        //parse the multiple version ranges
                                        else if (String.Equals(textReader.Name, "auto-upgrade-versions", StringComparison.Ordinal))
                                        {
                                            if (InAutoUpgradeVersions(ref textReader))
                                            {
                                                updateNeeded = true;
                                            }
                                        }

                                        break;

                                    case XmlNodeType.EndElement:
                                        //stop at the end of this sub-element ("latest-version")
                                        if (String.Equals(textReader.Name, "latest-version", StringComparison.Ordinal))
                                        {
                                            keepParsing = false;
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                }
                                //do not drop out of the outer while loop
                                keepParsing = true;
                            }
                            else
                            {
                                //no need to update (no newer version) , no error
                                return(true);
                            }
                        }

                        /*currently we do not support this feature, due to the items below
                         *
                         * //wait till you find the "OS" tag with the currentOS attribute
                         * //beware, below .Net 5.0, Environment.OSversion may be wrong when running in Windows compatibility mode,
                         * //also needs a manual manifest file in order to use deprecated version checks (to distinguish versions above 6.2)
                         * //this feature is currently unused in the xml file, and no old release section currently exists on eid.belgium.be
                         *
                         * else if (String.Equals(textReader.Name, "latest-supported-OS", StringComparison.Ordinal))
                         * {
                         *  string OSversion = Environment.OSVersion.Version.Major.ToString() + "." + Environment.OSVersion.Version.Minor.ToString();
                         *
                         *  //within the <OS name="windows"> <comp name="eid-viewer"> <latest-supported-OS> element
                         *  //try to find sub element version, stop searching when closing element "latest-supported-OS" is reached
                         *  if (jumpToSubElement(ref textReader, "oldOS", "version", OSversion, "latest-supported-OS"))
                         *  {
                         *      if (jumpToSubElement(ref textReader, "oldOS-latest-version", "oldOS"))
                         *      {
                         *          //we found an "oldOS-latest-version" section for the current running OS (meaning this OS is no longer supported in the latest online version)
                         *          //this means we need to ignore all data outside this section (urls, update needed, etc..)
                         *          updateNeeded = false;
                         *          url = "";
                         *          releaseNotes = "";
                         *
                         *          //check if a higher version is available for this OS specifically (latest supported version for this OS)
                         *          if (CompareXMLToCurrentVersion(ref textReader) > 0)
                         *          {
                         *              updateNeeded = true;
                         *
                         *              //parse the oldOS subsection
                         *              while (textReader.Read() && keepParsing)
                         *              {
                         *                  switch (textReader.NodeType)
                         *                  {
                         *                      case XmlNodeType.Element:
                         *                          if (String.Equals(textReader.Name, "oldOS-latest-url", StringComparison.Ordinal))
                         *                          {
                         *                              //check if this element contains the url attribute, if so, store it in the url string
                         *                              CheckAttributeValue(ref textReader, "url_" + lang, ref url);
                         *                              //if no url of this viewer's language is specified, try getting the default url
                         *                              if (url.Equals(""))
                         *                              {
                         *                                  CheckAttributeValue(ref textReader, "url", ref url);
                         *                              }
                         *                          }
                         *                          else if (String.Equals(textReader.Name, "oldOS-release-notes", StringComparison.Ordinal))
                         *                          {
                         *                              //check if this element contains the url attribute, if so, store it in the url string
                         *                              CheckAttributeValue(ref textReader, "url", ref releaseNotes);
                         *                          }
                         *                          break;
                         *
                         *                      case XmlNodeType.EndElement:
                         *                          //stop at the end of this sub-element ("latest-version")
                         *                          if (String.Equals(textReader.Name, "oldOS-latest-version", StringComparison.Ordinal))
                         *                          {
                         *                              keepParsing = false;
                         *                          }
                         *                          break;
                         *                      default:
                         *                          break;
                         *                  }
                         *              }
                         *          }
                         *          //we can stop parsing the entire xml file, as we have parsed a "oldOS-latest-version" section for this OS
                         *          keepParsing = false;
                         *      }
                         *  }
                         * }
                         */

                        break;

                    case XmlNodeType.EndElement:
                        //when we reach the end of the "OS" Windows section, no use to keep parsing the macOS and linux sections
                        if (String.Equals(textReader.Name, "OS", StringComparison.Ordinal))
                        {
                            keepParsing = false;
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (System.Xml.XmlException e)
            {
                eIDViewer.BackendDataViewModel theBackendData = (BackendDataViewModel)(App.Current.Resources["eIDViewerBackendObj"]);
                theBackendData.WriteLog("error parsing xml version file: \n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL);
                theBackendData.WriteLog(e.ToString() + "\n", eid_vwr_loglevel.EID_VWR_LOG_DETAIL);
                return(false); //xml corrupt?
            }
            catch
            {
                return(false); //xml corrupt?
            }
            return(true);      //no error
        }
        void Perform_Version_Check(bool showMessages)
        {
            try
            {
                Popup myPopup = new Popup();
                myPopup.IsOpen = true;
                //do not log explicit when no messages should be shown to user (i.e. during auto version check)
                eid_vwr_loglevel errorLevel = eid_vwr_loglevel.EID_VWR_LOG_NORMAL;

                string url          = "";
                string releaseNotes = "";

                if (showMessages)
                {
                    errorLevel = eid_vwr_loglevel.EID_VWR_LOG_ERROR;
                }

                theBackendData.WriteLog("starting the online version check..\n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL);

                string language = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.ToString();

                if (!Version.getUpdateUrl(out bool updateNeeded, language, ref url, ref releaseNotes))
                {
                    //no updated version found, report this in the log
                    theBackendData.WriteLog("failed to check for online update\n", errorLevel);
                    ShowErrorMessage(showMessages);
                    return;
                }

                if (updateNeeded)
                {
                    if (url == "")
                    {
                        theBackendData.WriteLog("A newer version of the eID Viewer has been found, but not the url to download it\n", eid_vwr_loglevel.EID_VWR_LOG_COARSE);
                        theBackendData.WriteLog("Newer version should be available at https://eid.belgium.be\n", eid_vwr_loglevel.EID_VWR_LOG_COARSE);
                        ShowErrorMessage(showMessages);
                        return;
                    }
                    //for safety, we do not accept all urls
                    else if (url.StartsWith("https://eid.belgium.be"))
                    {
                        //xml Version check
                        string aboutMessage = "\n" + eIDViewer.Resources.ApplicationStringResources.newVersionDownload;
                        string caption      = eIDViewer.Resources.ApplicationStringResources.newVersionDownloadTitle;

                        MessageBoxResult result = MessageBox.Show(aboutMessage, caption, MessageBoxButton.OKCancel, MessageBoxImage.Information, MessageBoxResult.Cancel);
                        if (result == MessageBoxResult.OK)
                        {
                            try
                            {
                                System.Diagnostics.Process.Start(url);
                            }
                            catch (Exception ex)
                            {
                                theBackendData.WriteLog("Error: Could not start a browser to visit" + url + ex.Message, eid_vwr_loglevel.EID_VWR_LOG_COARSE);
                            }
                        }
                    }
                    else
                    {
                        theBackendData.WriteLog("The url to download the new version did not start with https://eid.belgium.be\n", eid_vwr_loglevel.EID_VWR_LOG_COARSE);
                        ShowErrorMessage(showMessages);
                        return;
                    }
                }
                else
                {
                    theBackendData.WriteLog("No viewer update is needed\n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL);
                    if (showMessages)
                    {
                        MessageBox.Show(eIDViewer.Resources.ApplicationStringResources.VersionUpToDate, eIDViewer.Resources.ApplicationStringResources.VersionUpToDateTitle, MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occured during eID Viewer version check" + ex.Message);
            }
        }