Ejemplo n.º 1
0
            private Dictionary <string, string> AddComments(string dbscript)
            {
                LogMsg(MessageImportance.High, "AddComments() called.");

                //var dbscriptparts = dbscript.Split('\\');
                //var scriptname = dbscriptparts[dbscriptparts.Length - 1];
                //string objectname = null;
                //if (scriptname.Split('.').Length == 4)
                //{
                //    // Some of our db files now store the file with funny names now so that the filenames will sort in the order they need to execute.
                //    // The object name is still in the filename, but we have to pick it out differently than before.
                //    // example: D:\tfs\Integration\Main 6.2\Integration\CreateCI_DB\CI_CENTRAL\DatabaseObjects\Tables\000.50.APPLICATION_SETTINGS.sql
                //    // The desired object is simply APPLICATION_SETTINGS.
                //    objectname = scriptname.Split('.')[2];
                //}
                //else
                //{
                //    // if the filename does NOT have three "." then assume it's in the file name minus the path and extension.
                //    // example:  d:\folder1\folder2\MyTable.sql = object name MyTable.
                //    objectname = Path.GetFileNameWithoutExtension(scriptname);
                //}

                var icMainTokenList       = new[] { "${Version}", "${ClientICMainVersion}", "${Changeset}", "${LastModifiedDate}" };
                var icMainClientTokenList = new[] { "${Version}", "${ClientICMainVersion}", "${Changeset}", "${LastModifiedDate}", "${ClientVersion}" };

                var tokenList = IsIcMainClient ? icMainClientTokenList : icMainTokenList;
                var tokens    = tokenList.ToDictionary(token => token, token => string.Empty);

                tokens["${Version}"] = newDBVersion;

                if (IsIcMainClient)
                {
                    tokens["${ClientVersion}"] = newDBVersion;
                }

                if (checkInStampedScripts)
                {
                    // Add comment to database object
                    TFSUtils.tfsCheckout(dbscript, TFS_User, TFS_Pass);
                }
                else
                {
                    FileUtils.UnsetReadOnly(Path.GetDirectoryName(dbscript), Path.GetFileName(dbscript),
                                            SearchOption.TopDirectoryOnly);
                }
                TokenUtils.ReplaceTokens(dbscript, dbscript, tokens);
                return(tokens);
            }
Ejemplo n.º 2
0
            private void checkoutVersionFiles()
            {
                if (string.IsNullOrEmpty(Version))
                {
                    TFSUtils.tfsGet(VersionXmlFile, TFS_User, TFS_Pass);
                }
                TFSUtils.tfsGet(VersionCsFile, TFS_User, TFS_Pass);
                if (string.IsNullOrEmpty(Version))
                {
                    TFSUtils.tfsCheckout(VersionXmlFile, TFS_User, TFS_Pass);
                }
                TFSUtils.tfsCheckout(VersionCsFile, TFS_User, TFS_Pass);

                // TODO: Remove Telenor-specific logic
                // For Telenor builds only, check out config files
                if (VersionXmlFile.Contains("Telenor"))
                {
                    configFile = ProjectRoot + @"\Applications\WindowsService\App.config";
                    TFSUtils.tfsGet(configFile, TFS_User, TFS_Pass);
                    TFSUtils.tfsCheckout(configFile, TFS_User, TFS_Pass);
                }
            }
Ejemplo n.º 3
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.º 4
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);
                    }
                }
            }