Пример #1
0
 /// <summary>
 /// IComparable.CompareTo implementation.
 /// </summary>
 /// <param name="obj">An object to compare with this instance.</param>
 /// <returns>
 /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance is less than obj. Zero This instance is equal to obj. Greater than zero This instance is greater than obj.
 /// </returns>
 /// <exception cref="T:System.ArgumentException">obj is not the same type as this instance. </exception>
 public int CompareTo(object obj)
 {
     if (obj is UpdateEntry)
     {
         UpdateEntry upd = ( UpdateEntry )obj;
         if (VersionNumber.CompareTo(upd.VersionNumber) == 0)     //Version numbers are equal
         {
             return(Version.CompareTo(upd.Version));
         }
         else
         {
             return(VersionNumber.CompareTo(upd.VersionNumber));
         }
     }
     throw new ArgumentException("object is not a UpdateEntry");
 }
Пример #2
0
        private static void InitializeScriptList()
        {
            int dbVersion = 0;

            XmlDocument myDoc           = new XmlDocument();
            ArrayList   tempScriptsList = new ArrayList();

            // load the history file
            string myDocPath = ConfigurationManager.AppSettings["RainbowSetupScriptsPath"] + "History.xml";

            myDoc.Load(myDocPath);

            // get a list of <Release> nodes
            XmlNodeList releases = myDoc.DocumentElement.SelectNodes("Release");

            foreach (XmlNode release in releases)
            {
                UpdateEntry myUpdate = new UpdateEntry();

                // get the header information
                // we check for null to avoid exception if any of these nodes are not present
                if (release.SelectSingleNode("ID") != null)
                {
                    myUpdate.VersionNumber = Int32.Parse(release.SelectSingleNode("ID/text()").Value);
                }

                if (release.SelectSingleNode("Version") != null)
                {
                    myUpdate.Version = release.SelectSingleNode("Version/text()").Value;
                }

                if (release.SelectSingleNode("Script") != null)
                {
                    myUpdate.scriptNames.Add(release.SelectSingleNode("Script/text()").Value);
                }

                if (release.SelectSingleNode("Date") != null)
                {
                    myUpdate.Date = DateTime.Parse(release.SelectSingleNode("Date/text()").Value);
                }

                //We should apply this patch
                if (dbVersion < myUpdate.VersionNumber)
                {
                    //Rainbow.Framework.Helpers.LogHelper.Logger.Log(Rainbow.Framework.Site.Configuration.LogLevel.Debug, "Detected version to apply: " + myUpdate.Version);

                    myUpdate.Apply = true;

                    // get a list of <Installer> nodes
                    XmlNodeList installers = release.SelectNodes("Modules/Installer/text()");

                    // iterate over the <Installer> Nodes (in original document order)
                    // (we can do this because XmlNodeList implements IEnumerable)
                    foreach (XmlNode installer in installers)
                    {
                        //and build an ArrayList of the scripts...
                        myUpdate.Modules.Add(installer.Value);
                        //Rainbow.Framework.Helpers.LogHelper.Logger.Log(Rainbow.Framework.Site.Configuration.LogLevel.Debug, "Detected module to install: " + installer.Value);
                    }

                    // get a <Script> node, if any
                    XmlNodeList sqlScripts = release.SelectNodes("Scripts/Script/text()");

                    // iterate over the <Installer> Nodes (in original document order)
                    // (we can do this because XmlNodeList implements IEnumerable)
                    foreach (XmlNode sqlScript in sqlScripts)
                    {
                        //and build an ArrayList of the scripts...
                        myUpdate.scriptNames.Add(sqlScript.Value);
                        //Rainbow.Framework.Helpers.LogHelper.Logger.Log(Rainbow.Framework.Site.Configuration.LogLevel.Debug, "Detected script to run: " + sqlScript.Value);
                    }

                    tempScriptsList.Add(myUpdate);
                }
            }

            //If we have some version to apply...
            if (tempScriptsList.Count > 0)
            {
                scriptsList = ( UpdateEntry[] )tempScriptsList.ToArray(typeof(UpdateEntry));

                //by Manu. Versions are sorted by version number
                Array.Sort(scriptsList);

                //Create a flat version for binding
                int currentVersion = 0;
                foreach (UpdateEntry myUpdate in scriptsList)
                {
                    if (myUpdate.Apply)
                    {
                        if (currentVersion != myUpdate.VersionNumber)
                        {
                            LogHelper.Logger.Log(LogLevel.Debug, "Version: " + myUpdate.VersionNumber);
                            currentVersion = myUpdate.VersionNumber;
                        }

                        foreach (string scriptName in myUpdate.scriptNames)
                        {
                            if (scriptName.Length > 0)
                            {
                                LogHelper.Logger.Log(LogLevel.Debug, "-- Script: " + scriptName);
                            }
                        }

                        foreach (string moduleInstaller in myUpdate.Modules)
                        {
                            if (moduleInstaller.Length > 0)
                            {
                                LogHelper.Logger.Log(LogLevel.Debug, "-- Module: " + moduleInstaller + " (ignored recreating test DB)");
                            }
                        }
                    }
                }
            }
        }