Ejemplo n.º 1
0
            private void CopyICMainClientScripts(string schema, string[] databaseobjectfolders)
            {
                LogMsg(MessageImportance.High, "CopyICMainClientScripts() called.");

                LogMsg(MessageImportance.High, "Getting directory listing of {0}", string.Format(@"{0}\..\IC Main Scripts\{1}", BasePath, schema));

                // Copy IC Main scripts to setup folder
                var icMainFolders = Directory.GetDirectories(string.Format(@"{0}\..\IC Main Scripts\{1}", BasePath, schema), "*", SearchOption.TopDirectoryOnly);

                LogMsg(MessageImportance.High, GetLogMessage("icMainFolders", icMainFolders));

                if (icMainFolders.Length <= 0)
                {
                    LogMsg(MessageImportance.High, "No IC Main folders found, so exiting CopyICMainClientScripts() method.");
                    return;
                }

                var icMainFolderVersions = new SortedList <string, string>();

                foreach (var icMainFolder in icMainFolders)
                {
                    // Check out destination scripts if they exist
                    var tempDestPath = string.Format(@"{0}\..\Setup\DbUpgrade\DBScripts\{1}\{2}", BasePath, newDBVersion, schema);
                    if (checkInStampedScripts)
                    {
                        TFSUtils.tfsCheckout(tempDestPath, TFS_User, TFS_Pass);
                    }

                    // Copy scripts
                    LogMsg(MessageImportance.High, "Copying files matching '*.*' from '{0}' to '{1}'.", icMainFolder, tempDestPath);
                    FileUtils.CopyFiles(icMainFolder, "*.*", tempDestPath);

                    // Add folder to sorted list
                    var icMainFolderNameParts = icMainFolder.Split('\\');
                    var icMainFolderName      = icMainFolderNameParts[icMainFolderNameParts.Length - 1];
                    icMainFolderVersions.Add(icMainFolderName, icMainFolder);
                }

                LogMsg(MessageImportance.High, GetLogMessage("icMainFolderVersions", icMainFolderVersions));

                var latestICMainFolder = string.Format(@"{0}\..\IC Main Scripts\{1}\{2}", BasePath, schema,
                                                       icMainFolderVersions.Last().Key);

                LogMsg(MessageImportance.High, "latestICMainFolder = {0}", latestICMainFolder);

                LogMsg(MessageImportance.High, GetLogMessage("databaseobjectfolders", databaseobjectfolders));

                // Copy IC Main DB objects to setup folder
                foreach (var tempLatestICMainDatabaseObjectFolder in databaseobjectfolders.Select(
                             databaseobjectfolder => string.Format(@"{0}\DatabaseObjects\{1}", latestICMainFolder,
                                                                   databaseobjectfolder)))
                {
                    if (checkInStampedScripts)
                    {
                        // Check out script
                        TFSUtils.tfsCheckout(tempLatestICMainDatabaseObjectFolder, TFS_User, TFS_Pass);
                    }

                    // Determine output path
                    var destscriptfolder = string.Format(@"{0}\..\Setup\DbUpgrade\DBScripts\_PreProcess\{1}", BasePath, schema);

                    if (checkInStampedScripts)
                    {
                        // Check out destination scripts
                        TFSUtils.tfsCheckout(destscriptfolder, TFS_User, TFS_Pass);
                    }

                    if (Directory.Exists(tempLatestICMainDatabaseObjectFolder))
                    {
                        foreach (var dbscript in Directory.GetFiles(tempLatestICMainDatabaseObjectFolder, "*.sql", SearchOption.TopDirectoryOnly))
                        {
                            // Add comments to script
                            var tokens = AddComments(dbscript);

                            // Determine output path
                            var scriptpathparts = dbscript.Split('\\');
                            var destscriptpath  = string.Format(@"{0}\{1}", destscriptfolder, scriptpathparts[scriptpathparts.Length - 1]);

                            if (!checkInStampedScripts)
                            {
                                FileUtils.UnsetReadOnly(destscriptfolder, Path.GetFileName(destscriptpath), SearchOption.TopDirectoryOnly);
                            }

                            // Perform token replacement on script and copy to destination folder
                            TokenUtils.ReplaceTokens(dbscript, destscriptpath, tokens);
                        }
                    }
                    else
                    {
                        LogMsg(MessageImportance.High, "Directory not found: {0}", tempLatestICMainDatabaseObjectFolder);
                    }

                    if (checkInStampedScripts)
                    {
                        // Undo original script (template)
                        TFSUtils.tfsUndo(tempLatestICMainDatabaseObjectFolder, TFS_User, TFS_Pass);
                    }
                }
            }
Ejemplo n.º 2
0
            private void CopyDatabaseObjects(IEnumerable <string> databaseobjectfolders, string schema, string newICMainVersion)
            {
                LogMsg(MessageImportance.High, "CopyDatabaseObjects() called.");

                // Copy database objects
                foreach (var databaseobjectfolder in databaseobjectfolders)
                {
                    // determine the dbscript folder
                    var dbscriptpath = string.Format(@"{0}\{1}\DatabaseObjects\{2}", BasePath, schema, databaseobjectfolder);

                    if (checkInStampedScripts)
                    {
                        // check out everything in the dbscript folder
                        TFSUtils.tfsCheckout(dbscriptpath, TFS_User, TFS_Pass);
                    }

                    // Determine output folder
                    var destscriptfolder = IsIcMain ? string.Format(@"{0}\{1}\UpdateScripts\{2}\DatabaseObjects\{3}", BasePath, schema, newICMainVersion, databaseobjectfolder) :
                                           string.Format(@"{0}\..\Setup\DbUpgrade\DBScripts\_PreProcess\{1}", BasePath, schema);

                    if (checkInStampedScripts)
                    {
                        // check out everything in the destination folder.
                        TFSUtils.tfsCheckout(destscriptfolder, TFS_User, TFS_Pass);
                    }

                    LogMsg("Inside CopyDatabaseObjects(), checking if path '{0}' exists.", dbscriptpath);
                    if (Directory.Exists(dbscriptpath))
                    {
                        LogMsg("Inside CopyDatabaseObjects(), directory exists.  Looping through SQL files in this directory.");

                        var dbscripts = Directory.GetFiles(dbscriptpath, "*.sql", SearchOption.TopDirectoryOnly);

                        LogMsg(MessageImportance.High, GetLogMessage("dbscripts", dbscripts));

                        foreach (var dbscript in dbscripts)
                        {
                            LogMsg("Inside CopyDatabaseObjects().  Adding comments to script '{0}'.", dbscript);

                            // Add comments to script
                            var tokens = AddComments(dbscript);

                            var scriptpathparts = dbscript.Split('\\');
                            var destscriptpath  = string.Format(@"{0}\{1}", destscriptfolder, scriptpathparts[scriptpathparts.Length - 1]);

                            var tokenString = tokens.Aggregate("", (current, token) => current + string.Format("key: {0}; value={1}\r\n", token.Key, token.Value));

                            LogMsg("Inside CopyDatabaseObjects().  Calling ReplaceTokens() with dbscript '{0}', destscriptpath '{1}', tokens '{2}'.", dbscript, destscriptpath, tokenString);

                            if (!checkInStampedScripts)
                            {
                                FileUtils.UnsetReadOnly(destscriptfolder, Path.GetFileName(destscriptpath), SearchOption.TopDirectoryOnly);
                            }

                            // Perform token replacement on script and copy to destination folder
                            TokenUtils.ReplaceTokens(dbscript, destscriptpath, tokens);
                        }
                    }

                    if (checkInStampedScripts)
                    {
                        // Undo original script (template)
                        TFSUtils.tfsUndo(dbscriptpath, TFS_User, TFS_Pass);
                    }
                }
            }