예제 #1
0
        }//_updateAccessId()

        private void _describe(CswNbtResources CswNbtResources, CswSchemaUpdater CswSchemaUpdater, CswConsoleOutput CswConsoleOutput)
        {
            List <string> Descriptions = new List <string>();

            foreach (CswSchemaUpdateDriver CurrentDriver in CswSchemaUpdater.UpdateDrivers.Values)
            {
                string CurrentDescription = CurrentDriver.SchemaVersion.ToString() + ": " + CurrentDriver.Description;
                if (false == Descriptions.Contains(CurrentDescription))
                {
                    Descriptions.Add(CurrentDescription);
                }
            }

            CswConsoleOutput.write(_VersionInfo);

            if ((null != CswSchemaUpdater) && (string.Empty != CswNbtResources.AccessId))
            {
                CswConsoleOutput.write(_Separator_NuLine + _Separator_NuLine + "Minimum schema version: " + CswSchemaUpdater.MinimumVersion);
                CswConsoleOutput.write(_Separator_NuLine + "Latest schema version: " + CswSchemaUpdater.LatestVersion);
            }

            CswConsoleOutput.write(_Separator_NuLine + _Separator_NuLine + "Script inventory:");

            foreach (string CurrentDescription in Descriptions)
            {
                CswConsoleOutput.write(_Separator_NuLine + CurrentDescription);
            }
        }//_describe
예제 #2
0
        }//_runNonVersionScripts()

        private bool _updateAccessId(string AccessId, CswNbtResources CswNbtResources, CswSchemaUpdater CswSchemaUpdater, CswConsoleOutput CswConsoleOutput, bool SuppressRealTimeProgressTics, bool ContinueOnError)
        {
            CswSchemaUpdateThread CswSchemaUpdateThread = new CswSchemaUpdateThread(CswSchemaUpdater);

            CswConsoleOutput.write("Running Non-Versioned Pre-Scripts" + _Separator_NuLine + _Separator_NuLine);

            CswSchemaScriptsProd CswSchemaScriptsProd = new CswSchemaScriptsProd(CswNbtResources);

            bool UpdateSucceeded = _runNonVersionScripts(CswSchemaUpdater, CswSchemaScriptsProd.RunBeforeScripts, CswConsoleOutput);

            if (UpdateSucceeded)
            {
                CswSchemaVersion CurrentVersion = CswSchemaUpdater.CurrentVersion(CswNbtResources);
                // refresh current version in case it was altered
                CswNbtResources.ConfigVbls.refresh();
                CurrentVersion = CswSchemaUpdater.CurrentVersion(CswNbtResources);

                CswConsoleOutput.write("Updating from " + CurrentVersion.ToString() + " to " + CswSchemaUpdater.LatestVersion.ToString() + _Separator_NuLine + _Separator_NuLine);

                for (int i = 0; ((UpdateSucceeded || ContinueOnError) &&
                                 ((CurrentVersion != CswSchemaUpdater.LatestVersion) || (i < CswSchemaUpdater.UpdateDrivers.Count))); i++)
                {
                    if (CurrentVersion < CswSchemaUpdater.MinimumVersion)
                    {
                        UpdateSucceeded = false;
                        CswConsoleOutput.write("AccessId " + AccessId + ": ");
                        CswConsoleOutput.write(" failed: Schema version (" + CurrentVersion.ToString() + ") is below minimum version (" + CswSchemaUpdater.MinimumVersion.ToString() + ")" + _Separator_NuLine);
                    }
                    else
                    {
                        CswSchemaVersion UpdateToVersion = CswSchemaUpdater.SchemaVersions[i];

                        string UpdateDescription = CswSchemaUpdater.getDriver(UpdateToVersion).SchemaVersion + ": " + CswSchemaUpdater.getDriver(UpdateToVersion).Description;

                        CswSchemaUpdateThread.start();

                        if (false == SuppressRealTimeProgressTics)
                        {
                            CswConsoleOutput.write(UpdateDescription + ": ");
                        }

                        while (CswEnumSchemaUpdateState.Running == CswSchemaUpdateThread.UpdateState)
                        {
                            if (false == SuppressRealTimeProgressTics)
                            {
                                CswConsoleOutput.write(".");
                            }

                            Thread.Sleep(1000);
                        }

                        UpdateSucceeded = (CswEnumSchemaUpdateState.Succeeded == CswSchemaUpdateThread.UpdateState);

                        if (UpdateSucceeded)
                        {
                            string Message = string.Empty;
                            if (false == SuppressRealTimeProgressTics)
                            {
                                Message = " succeeded" + _Separator_NuLine;
                            }
                            else
                            {
                                Message = UpdateDescription + " succeeded" + _Separator_NuLine;
                            }

                            CswConsoleOutput.write(Message);
                        }
                        else
                        {
                            string Message = string.Empty;
                            if (false == SuppressRealTimeProgressTics)
                            {
                                Message = " failed: " + CswSchemaUpdateThread.Message + _Separator_NuLine;
                            }
                            else
                            {
                                Message = UpdateDescription + " failed: " + CswSchemaUpdateThread.Message + _Separator_NuLine;
                            }

                            CswConsoleOutput.write(Message, ForceWrite: true, SuppressAccessId: false);
                        }

                        CswNbtResources.ClearCache();

                        CurrentVersion = CswSchemaUpdater.CurrentVersion(CswNbtResources);
                    }
                } // for()
            }     //if pre-scripts succeded

            if (UpdateSucceeded)
            {
                UpdateSucceeded = _runNonVersionScripts(CswSchemaUpdater, CswSchemaScriptsProd.RunAfterScripts, CswConsoleOutput);
            }

            return(UpdateSucceeded);
        }//_updateAccessId()
예제 #3
0
        }//_runConcurrentSchemaUpdates()

        private bool _runNonVersionScripts(CswSchemaUpdater CswSchemaUpdater, List <CswSchemaUpdateDriver> ScriptCollection, CswConsoleOutput CswConsoleOutput)
        {
            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)
                {
                    CswConsoleOutput.write(ScriptDescription + "succeeded" + _Separator_NuLine);
                }
                else
                {
                    CswConsoleOutput.write(ScriptDescription + "failed: " + CurrentUpdateDriver.Message + _Separator_NuLine);
                }
            }

            return(ReturnVal);
        }//_runNonVersionScripts()
예제 #4
0
        public bool process(string[] args)
        {
            bool ReturnVal = true;

            CswNbtResources CswNbtResources = null;

            _makeResources(string.Empty, ref CswNbtResources);
            CswConsoleOutput CswConsoleOutput = new CswConsoleOutput(CswNbtResources.CswLogger, CswNbtResources.AccessId);

            try
            {
                _convertArgsToDictionary(args);

                if (_UserArgs.ContainsKey(_ArgKey.Help))
                {
                    CswConsoleOutput.write(_Help);
                }
                else
                {
                    StringCollection AccessIdsToUpdate = new StringCollection();

                    if (_UserArgs.ContainsKey(_ArgKey.AccessId))
                    {
                        AccessIdsToUpdate.Add(_UserArgs[_ArgKey.AccessId]);
                    }
                    else if (_UserArgs.ContainsKey(_ArgKey.All) || _UserArgs.ContainsKey(_ArgKey.Version))
                    {
                        foreach (string AccessId in CswNbtResources.CswDbCfgInfo.AccessIds)
                        {
                            AccessIdsToUpdate.Add(AccessId);
                        }
                    }
                    else
                    {
                        //if the user's input does not fit our semantic space, he needs help (as do we all)
                        CswConsoleOutput.write(_Help);
                    }

                    if (_UserArgs.ContainsKey(_ArgKey.Version))
                    {
                        CswConsoleOutput.write("AccessId, Version");
                        CswConsoleOutput.write(_Separator_NuLine);
                    }


                    //Detect missing accessIDs
                    StringCollection AccessIdsToRemove = new StringCollection();
                    foreach (string CurrentAccessId in AccessIdsToUpdate)
                    {
                        if (false == CswNbtResources.CswDbCfgInfo.AccessIds.Contains(CurrentAccessId))
                        {
                            AccessIdsToRemove.Add(CurrentAccessId);
                        }
                    }//iterate accessids for missing ones

                    //Remove misisng accessIds
                    foreach (string CurrentAccessId in AccessIdsToRemove)
                    {
                        AccessIdsToUpdate.Remove(CurrentAccessId);
                        CswConsoleOutput.write("AccessId " + CurrentAccessId + " could not be found; no action will be taken on it", false);
                        CswConsoleOutput.write(_Separator_NuLine);
                    }//iterate access ids to remove missing ones

                    //if we're just reporting versions, we're not going to do concurrent-updating
                    if (_UserArgs.ContainsKey(_ArgKey.Version))
                    {
                        foreach (string CurrentAccessId in AccessIdsToUpdate)
                        {
                            CswNbtResources.AccessId = CurrentAccessId;
                            _doVersionOp(CurrentAccessId, CswNbtResources, CswConsoleOutput);
                            CswConsoleOutput.write(_Separator_NuLine);
                        }//iterate accessids to report version
                    }
                    else if (_UserArgs.ContainsKey(_ArgKey.MaxConcurrentSchemata))
                    {
                        Int32 MaxConcurrentSchema = CswConvert.ToInt32(_UserArgs[_ArgKey.MaxConcurrentSchemata]);
                        ReturnVal = _runConcurrentSchemaUpdates(AccessIdsToUpdate, MaxConcurrentSchema);
                    }
                    else //non-concurrent schema update op
                    {
                        foreach (string CurrentAccessId in AccessIdsToUpdate)
                        {
                            CswConsoleOutput.write(_Separator_NuLine);
                            CswNbtResources.AccessId = CurrentAccessId;
                            CswConsoleOutput.write(_Separator_NuLine + "Applying schema operation to AccessId " + CurrentAccessId + "=========================" + _Separator_NuLine, false);
                            ReturnVal = _doUpdateOp(CurrentAccessId, CswNbtResources, _makeResources, CswConsoleOutput, false, _continueExecutingScriptsOnError());
                            CswConsoleOutput.write(_Separator_NuLine);
                        } //
                    }     //if-else on type of operations to do
                }         // if-else( _UserArgs.ContainsKey( Help ) )
            }             //try

            catch (Exception Exception)
            {
                CswConsoleOutput.write("Update failed: " + Exception.Message);
            }


            return(ReturnVal);
        }//process()
예제 #5
0
        private void _doVersionOp(string CurrentAccessId, CswNbtResources CswNbtResources, CswConsoleOutput CswConsoleOutput)
        {
            CswSchemaUpdater CswSchemaUpdater = new CswSchemaUpdater(CurrentAccessId, _makeResources, new CswSchemaScriptsProd(CswNbtResources));

            CswConsoleOutput.write(CurrentAccessId + ", " + CswSchemaUpdater.CurrentVersion(CswNbtResources));
        }
예제 #6
0
        }//_doUpdateOpThreadWrapper()

        /// <summary>
        /// CAUTION: in concurrent mode ( -maxconcurrentschemata > 0 ), this method will be multi-threaded
        /// </summary>
        /// <param name="CurrentAccessId"></param>
        /// <param name="CswNbtResources"></param>
        /// <param name="ResourcesInitHandler"></param>
        /// <param name="CswConsoleOutput"></param>
        private bool _doUpdateOp(string CurrentAccessId, CswNbtResources CswNbtResources, CswSchemaUpdater.ResourcesInitHandler ResourcesInitHandler, CswConsoleOutput CswConsoleOutput, bool SuppressRealTimeProgressTics, bool ContinueOnError)
        {
            bool ReturnVal = true;

            // Do the update on the current accessid
            CswSchemaScriptsProd CswSchemaScripts = null;

            //if( _UserArgs.ContainsKey( _ArgKey.Mode ) && _ArgVal_Test == _UserArgs[_ArgKey.Mode] )
            //{
            //// Use test cases
            //Int32 StartAtTestCase = 0;
            //if( _UserArgs.ContainsKey( _ArgKey.StartAtTestCase ) )
            //{
            //    StartAtTestCase = CswConvert.ToInt32( _UserArgs[_ArgKey.StartAtTestCase] );
            //}

            //Int32 EndAtTestCase = 0;
            //if( _UserArgs.ContainsKey( _ArgKey.EndAtTestCase ) )
            //{
            //    EndAtTestCase = CswConvert.ToInt32( _UserArgs[_ArgKey.EndAtTestCase] );
            //}

            //List<string> TestCasesToIgnore = new List<string>();
            //if( _UserArgs.ContainsKey( _ArgKey.IgnoreTestCasesCsv ) )
            //{
            //    CswCommaDelimitedString CswCommaDelimitedString = new CswCommaDelimitedString();
            //    CswCommaDelimitedString.FromString( _UserArgs[_ArgKey.IgnoreTestCasesCsv] );
            //    TestCasesToIgnore = CswCommaDelimitedString.ToList<string>();
            //}
            //CswSchemaScripts = new CswSchemaScriptsTest( StartAtTestCase, EndAtTestCase, TestCasesToIgnore );
            //}
            //else
            //{
            // Use production scripts
            CswSchemaScripts = new CswSchemaScriptsProd(CswNbtResources);
            //}

            CswSchemaUpdater CswSchemaUpdater = new CswSchemaUpdater(CurrentAccessId, ResourcesInitHandler, CswSchemaScripts);

            if (false == _UserArgs.ContainsKey(_ArgKey.Describe))
            {
                ReturnVal = _updateAccessId(CurrentAccessId, CswNbtResources, CswSchemaUpdater, CswConsoleOutput, SuppressRealTimeProgressTics, ContinueOnError);
            }
            else if (_UserArgs.ContainsKey(_ArgKey.Mode) && _ArgVal_Test == _UserArgs[_ArgKey.Mode])
            {
                CswConsoleOutput.write("Ach. The iteration model for production scripts so woefully different than for test scripts that verily do I say unto the brother, uh, yay: it is easier for a camel to pass through the eye of a needle than is to give an inventory of production test scripts. Of course, since the production test scripts don't deploy the Description property of CswRequestDriver in as a rich a way as do the test scripts, it probably doesn't matter. See case 21739");
            }
            else
            {
                _describe(CswNbtResources, CswSchemaUpdater, CswConsoleOutput);
            }

            return(ReturnVal);
        }