Beispiel #1
0
    //+-----------------------------------------------------------------------------------------------------
    //| g e t S p e c i f i c V e r s i o n
    //+-----------------------------------------------------------------------------------------------------
    // Auteur: Jonathan Lapierre
    // Compagnie: Thoran inc.
    /// <summary>
    /// Get a specific version information
    /// </summary>
    /// <param name="Major">The major number to look for</param>
    /// <param name="Minor">The build number to look for</param>
    /// <param name="Build">The build number to look for</param>
    /// <returns>Will return an empty version object if not found</returns>
    public Versioning getSpecificVersion(string Major, string Minor, string Build)
    {
        try
        {
            //Check if the XML was already loaded, if not load it
            if (this.xmlConfig.InnerXml == "")
            {
                this.LoadFromFile();
            }

            //Loop the nodes to find the specific version
            foreach (XmlNode MasterNodeFetch in xmlConfig.SelectNodes("/root/version"))
            {
                if (MasterNodeFetch.Attributes["major"].Value == Major)
                {
                    if (MasterNodeFetch.Attributes["minor"].Value == Minor)
                    {
                        if (MasterNodeFetch.Attributes["build"].Value == Build)
                        {
                            Versioning retVers = new Versioning();
                            retVers.Major           = Major;
                            retVers.Minor           = Minor;
                            retVers.Build           = Build;
                            retVers.VersionInfo     = MasterNodeFetch.ChildNodes[0].InnerText;
                            retVers.MajorMinorBuild = retVers.Major + "." + retVers.Minor + "." + retVers.Build;
                            retVers.CurrentVersion  = new System.Version(retVers.MajorMinorBuild);

                            DateTime ReleaseDate;

                            //Check if date is valid
                            if (DateTime.TryParse(MasterNodeFetch.Attributes["releaseDate"].Value, out ReleaseDate))
                            {
                                retVers.ReleaseDate = ReleaseDate;
                            }
                            else
                            {
                                retVers.ReleaseDate = DateTime.MinValue;
                            }

                            return(retVers);
                        }
                    }
                }
            }

            return(new Versioning());
        }
        catch (Exception err)
        {
            GlobalFuncLocal.log(err.Message + " | " + err.StackTrace, GlobalFuncLocal.ErrorLevel.CRITICAL);

            //Throw exception to let programmer or administrator know that their is a missing or invalid version.xml file
            throw new Exception("Missing or invalid version.xml file. Please check log for more information");
        }
    }
Beispiel #2
0
    //+-----------------------------------------------------------------------------------------------------
    //| L o a d F r o m F i l e
    //+-----------------------------------------------------------------------------------------------------
    // Auteur: Jonathan Lapierre
    // Compagnie: Thoran inc.
    /// <summary>
    /// This method will load the version file from disk into the private XML object
    /// </summary>
    private void LoadFromFile()
    {
        try
        {
            //Check to find version file exist
            FileInfo xmlConfigFIle = new FileInfo(HttpContext.Current.Server.MapPath("~") + "\\version.xml");

            //If file is found, try loading the file in the XML document object.
            xmlConfig.Load(xmlConfigFIle.FullName);
        }
        catch (Exception err)
        {
            GlobalFuncLocal.log(err.Message + " | " + err.StackTrace, GlobalFuncLocal.ErrorLevel.CRITICAL);

            //Throw exception to let programmer or administrator know that their is a missing or invalid version.xml file
            throw new Exception("Missing or invalid version.xml file. Please check log for more information");
        }
    }