예제 #1
0
        void WriteParameterInfo(FileHostingPathHelper ph)
        {
            string    context = "ExecuteAction";
            const int padding = 50;

            OnStepProgress(context, Utils.GetHeaderMessage("Begin [PrepareAndValidate]"));

            //_wfp.PrepareAndValidate();

            OnStepProgress(context, Utils.GetMessagePadRight("ScriptFolder", _wfp.ScriptFolder, padding));
            OnStepProgress(context, Utils.GetMessagePadRight("SqlPlusPath", config.Default.SqlPlusPath, padding));
            OnStepProgress(context, Utils.GetMessagePadRight("RequestNumber", _wfp.RequestNumber, padding));
            OnStepProgress(context, Utils.GetMessagePadRight("PackageAdapterInstanceID", _wfp.PackageAdapterInstanceId, padding));
            OnStepProgress(context, Utils.GetMessagePadRight("SchemaFolder", ph.SchemaFolder, padding));
            OnStepProgress(context, Utils.GetMessagePadRight("WorkRoot", ph.WorkRoot, padding));
            OnStepProgress(context, Utils.GetMessagePadRight("Environment", ph.Environment, padding));
            OnStepProgress(context, Utils.GetMessagePadRight("ApplicationName", ph.ApplicationName, padding));
            OnStepProgress(context, Utils.GetMessagePadRight("ManifestFolder", ph.SourcePath, padding));

            if (_wfp.Sections != null)
            {
                OnStepProgress(context, Utils.GetMessagePadRight("Manifest", _wfp.Sections, padding));
                OnStepProgress(context, Utils.GetMessagePadRight("Manifest", _wfp.Sections.ToXml(false), padding));
                WriteWorkflowSectionDetail(false);
            }
            else
            {
                OnStepProgress(context, Utils.GetMessagePadRight("Manifest", "(null)", padding));
            }

            foreach (IConnectionSettings cs in _wfp.ConnectionSettings)
            {
                OnStepProgress(context, Utils.GetMessagePadRight("ConnectionSettings", cs, padding));
            }
        }
예제 #2
0
        public void ExecuteAction()
        {
            string context = "ExecuteAction";

            string msg = Utils.GetHeaderMessage(
                string.Format("Synapse, Legacy Database Adapter. {0}, Entering Main Workflow.", Utils.GetBuildDateVersion()));

            if (OnStepStarting(context, msg))
            {
                return;
            }

            OnStepProgress(context, Utils.CompressXml(_startInfo.Parameters));

            Stopwatch clock = new Stopwatch();

            clock.Start();

            Exception ex = null;

            try
            {
                #region initialize global variable dictionary
                _variables["{RequestNumber}"]            = _wfp.RequestNumber;
                _variables["{PackageAdapterInstanceId}"] = _wfp.PackageAdapterInstanceId;
                _variables["{MetaData}"] = string.Empty;
                _variables["{Success}"]  = true.ToString();
                #endregion

                try
                {
                    _wfp.ScriptFolder.Resolve();
                    OnStepProgress(context, Utils.GetMessagePadRight("ScriptFolder", _wfp.ScriptFolder, 50));
                }
                catch (Exception rex)
                {
                    string err = GetExceptionMessageRecursive(rex);
                    throw new Exception(
                              string.Format("Unable to resolve ScriptFolder.  Exception: {0}\r\n{1}",
                                            err, _wfp.SchemaFolder));
                }

                _ph = new FileHostingPathHelper(
                    _wfp.Environment, _wfp.ApplicationName,
                    config.Default.FolderPath,
                    _wfp.SchemaFolder, _wfp.RequestNumber,
                    _wfp.ScriptFolder, config.Default.SourceRoot,
                    config.Default.CachedRoot, config.Default.StagedRoot,
                    config.Default.ProcessedRoot, _wfp.PackageAdapterInstanceId);

                if (_ph.IsValid && _wfp.PrepareAndValidateConnections())
                {
                    if (!_startInfo.IsDryRun)
                    {
                        string source = _ph.SourcePath;
                        if (_wfp.IsControlledMigration && _wfp.MigrationType == MigrationType.Prod)
                        {
                            source = _ph.StagedPath;
                        }

                        bool   useSqlImpersonation = _wfp.DatabaseType == DatabaseType.SqlServer && !_wfp.SuppressSqlServerImpersonation;
                        string workPath            = Path.Combine(_ph.CachePath, "work");

                        //copy content to cache, then reset the script folder
                        //  from a relative to full(resolved) path
                        CopyFolder(source, _ph.CachePath);
                        _wfp.ScriptFolder.SourcePath = _ph.CachePath;
                        if (useSqlImpersonation)
                        {
                            CopyFolder(source, workPath);
                            _wfp.ScriptFolder.SourcePath = workPath;
                        }

                        //load and validates the section info (RollIn/RollBack)
                        _wfp.PrepareAndValidateSections();

                        //give some output
                        WriteParameterInfo(_ph);

                        if (_wfp.Sections.IsValid)
                        {
                            //delete the staged source, it's in cache and valid, so let's roll (so to speak)
                            Task.Factory.StartNew((object obj) => { DeleteFolder(source, true); }, null);


                            if (useSqlImpersonation)
                            {
                                _wfp.Sections.RewriteScripts();
                                IterateSections();
                                DeleteFolder(workPath, false);
                            }
                            else
                            {
                                IterateSections();
                            }

                            if (_wfp.IsControlledMigration && _wfp.MigrationType == MigrationType.PreProd)
                            {
                                CopyFolder(_ph.CachePath, _ph.StagedPath);
                            }

                            MoveFolder(_ph.CachePath, _ph.ProcessedPath);
                        }
                        else
                        {
                            //sections not valid, delete the cache (housekeeping)
                            DeleteFolder(_ph.CachePath, false);
                            throw new Exception("No valid manifest files found");
                        }
                    }
                }
                else
                {
                    WriteParameterInfo(_ph);
                }
            }
            catch (Exception exception)
            {
                ex = exception;
            }
            if (_wfp.Sections != null)
            {
                WriteWorkflowSectionDetail(true);
            }

            StatusType ps = GetPackageStatusFromErrorState(ex);
            bool       ok = ps == StatusType.Complete;
            msg = Utils.GetHeaderMessage(string.Format("End Main Workflow: {0}, Total Execution Time: {1}",
                                                       ok ? "Complete." : "One or more steps failed.", clock.ElapsedSeconds()));
            OnProgress(context, msg, ps, _startInfo.InstanceId, int.MaxValue, false, ex);
        }