private void _addVersionedScript( CswUpdateSchemaTo UpdateTo )
        {
            // Instance the UpdateDriver
            CswSchemaUpdateDriver CswSchemaUpdateDriver = new CswSchemaUpdateDriver( UpdateTo );

            CswSchemaUpdateDriver.CswNbtSchemaModTrnsctn = new CswNbtSchemaModTrnsctn( _CswNbtResources );
            if( false == CswSchemaUpdateDriver.AlreadyRun() || CswSchemaUpdateDriver.AlwaysRun )
            {
                if( false == CswSchemaUpdateDriver.AlwaysRun )
                {
                    CswSchemaUpdateDriver.SchemaVersion = _makeNextSchemaVersion();
                    CswSchemaUpdateDriver.Description = CswSchemaUpdateDriver.ScriptName;
                    if( false == _isDuplicateScript( CswSchemaUpdateDriver ) )
                    {
                        _UpdateDrivers.Add( CswSchemaUpdateDriver.SchemaVersion, CswSchemaUpdateDriver );
                    }
                }
                else
                {
                    CswSchemaUpdateDriver.SchemaVersion = new CswSchemaVersion( 0, '#', 0 );
                    CswSchemaUpdateDriver.Description = "Run Always Script: " + CswSchemaUpdateDriver.ScriptName;
                    _UpdateDrivers.Add( CswSchemaUpdateDriver.SchemaVersion, CswSchemaUpdateDriver );
                }
            }
        }
Example #2
0
        }//_runScript()

        public bool runArbitraryScript(CswSchemaUpdateDriver CswSchemaUpdateDriver)
        {
            //_ResourcesInitHandler( _AccessId )
            CswNbtResources CswNbtResources = null;

            _ResourcesInitHandler(_AccessId, ref CswNbtResources);
            return(_runScript(CswNbtResources, CswSchemaUpdateDriver, false));
        }//UpdateArbitraryScript
 private void _addRunAfterScript( CswUpdateSchemaTo UpdateTo, string Description = null )
 {
     CswSchemaUpdateDriver CswSchemaUpdateDriver = new CswSchemaUpdateDriver( UpdateTo );
     CswSchemaUpdateDriver.SchemaVersion = new CswSchemaVersion( 99, '#', _RunAfterScripts.Count );
     CswSchemaUpdateDriver.Description += Description ?? string.Empty;
     if( false == _RunAfterScripts.Contains( CswSchemaUpdateDriver ) )
     {
         _RunAfterScripts.Add( CswSchemaUpdateDriver );
     }
 }
Example #4
0
        //case 26617: removing otiose instance of CswNbtResources resolved catastrophic memory leak
        private bool _runScript(CswNbtResources CswNbtResources, CswSchemaUpdateDriver CswSchemaUpdateDriver, bool StampVersion)
        {
            bool ReturnVal = true;

            // CswNbtResources CswNbtResources = _ResourcesInitHandler( _AccessId );
            CswNbtSchemaModTrnsctn CswNbtSchemaModTrnsctn = new CswNbtSchemaModTrnsctn(CswNbtResources);

            CswTableUpdate _UpdateHistoryTableUpdate = CswNbtResources.makeCswTableUpdate("schemaupdater_updatehistory_update", "update_history");
            DataTable      _UpdateHistoryTable       = _UpdateHistoryTableUpdate.getTable();

            CswSchemaUpdateDriver.CswNbtSchemaModTrnsctn = CswNbtSchemaModTrnsctn;
            CswSchemaUpdateDriver.update();
            ReturnVal = CswSchemaUpdateDriver.UpdateSucceeded;

            if (false == ReturnVal)
            {
                // Belt and suspenders.
                CswNbtResources.logError(new CswDniException("Schema Updater encountered a problem: " + CswSchemaUpdateDriver.Message));
                _ErrorMessage = "Error updating to schema version " + CswSchemaUpdateDriver.SchemaVersion.ToString() + ": " + CswSchemaUpdateDriver.Message;
            }
            else if (StampVersion)
            {
                _CswSchemaScripts.stampSchemaVersion(CswNbtResources, CswSchemaUpdateDriver);
            }

            DataRow NewUpdateHistoryRow = _UpdateHistoryTable.NewRow();

            NewUpdateHistoryRow["updatedate"] = DateTime.Now.ToString();
            NewUpdateHistoryRow["version"]    = CswSchemaUpdateDriver.SchemaVersion.ToString();
            NewUpdateHistoryRow["scriptname"] = CswSchemaUpdateDriver.ScriptName;
            NewUpdateHistoryRow["succeeded"]  = CswConvert.ToDbVal(ReturnVal);

            if (false == ReturnVal)
            {
                NewUpdateHistoryRow["log"] = "Failed update: " + CswSchemaUpdateDriver.Message;
            }

            _UpdateHistoryTable.Rows.Add(NewUpdateHistoryRow);

            _UpdateHistoryTableUpdate.update(_UpdateHistoryTable);

            CswNbtResources.finalize();
            CswNbtResources.release();


            CswSchemaUpdateDriver.CswNbtSchemaModTrnsctn = null;

            GC.Collect();

            return(ReturnVal);
        }//_runScript()
        }//Next()

        public CswSchemaUpdateDriver this[CswSchemaVersion CswSchemaVersion]
        {
            get
            {
                CswSchemaUpdateDriver ReturnVal = null;

                if( _UpdateDrivers.ContainsKey( CswSchemaVersion ) )
                {
                    ReturnVal = _UpdateDrivers[CswSchemaVersion];
                }

                return ( ReturnVal );
            }
        }
        public CswSchemaUpdateDriver Next( CswNbtResources CswNbtResources )
        {
            CswSchemaUpdateDriver ReturnVal = null;

            if( _UpdateDrivers.Count > ( _CurrentIdx + 1 ) )
            {
                if( Int32.MinValue == _CurrentIdx )
                {
                    _CurrentIdx = 0;
                }
                else
                {
                    _CurrentIdx++;
                }

                KeyValuePair<CswSchemaVersion, CswSchemaUpdateDriver> CurrentItem = _UpdateDrivers.ElementAt( _CurrentIdx );
                ReturnVal = CurrentItem.Value;
            }

            return ReturnVal;
        }//Next()
Example #7
0
        }//UpdateArbitraryScript

        /// <summary>
        /// Update the schema to the next version
        /// </summary>
        public bool runNextVersionedScript()
        {
            CswNbtResources CswNbtResources = null;

            _ResourcesInitHandler(_AccessId, ref CswNbtResources);

            CswSchemaUpdateDriver CurrentUpdateDriver = null;
            bool UpdateSuccessful = true;
            bool StampVersion     = true;

            if (null != (CurrentUpdateDriver = _CswSchemaScripts.Next(CswNbtResources)))
            {
                //_CurrentUpdateDriver = CurrentUpdateDriver;
                if (CurrentUpdateDriver.AlwaysRun)
                {
                    StampVersion = false;
                }
                UpdateSuccessful = _runScript(CswNbtResources, CurrentUpdateDriver, StampVersion);
            } // if update is valid

            return(UpdateSuccessful);
        }//runNextVersionedScript()
Example #8
0
        private bool _runNonVersionScripts(List <CswSchemaUpdateDriver> ScriptCollection, CswNbtResources CswNbtResources, SchemaInfoEventArgs SchemaInfoEventArgs)
        {
            bool ReturnVal = true;

            for (int idx = 0; ReturnVal && (idx < ScriptCollection.Count); idx++)
            {
                CswSchemaUpdateDriver CurrentUpdateDriver = ScriptCollection[idx];

                string ScriptDescription = CurrentUpdateDriver.SchemaVersion.ToString() + ": " + CurrentUpdateDriver.Description;
                ReturnVal = _CswSchemaUpdater.runArbitraryScript(CurrentUpdateDriver);
                if (ReturnVal)
                {
                    SetStatus("Update successful: " + ScriptDescription);
                }
                else
                {
                    SetStatus("Update failed: " + ScriptDescription + ": " + CurrentUpdateDriver.Message);
                }

                _updateHistoryTable(CswNbtResources, SchemaInfoEventArgs);
            }

            return(ReturnVal);
        }//_runNonVersionScripts
 /// <summary>
 /// Returns true if a script with the same ScriptName was already added to _UpdateDrivers
 /// </summary>
 /// <param name="CswSchemaUpdateDriver"></param>
 /// <returns></returns>
 private bool _isDuplicateScript( CswSchemaUpdateDriver CswSchemaUpdateDriver )
 {
     return _UpdateDrivers.Values.Any( UpdateDriver => UpdateDriver.ScriptName == CswSchemaUpdateDriver.ScriptName );
 }
 public void stampSchemaVersion( CswNbtResources CswNbtResources, CswSchemaUpdateDriver CswSchemaUpdateDriver )
 {
     CswNbtResources.ConfigVbls.setConfigVariableValue( "schemaversion", CswSchemaUpdateDriver.SchemaVersion.ToString() ); ;
 }