예제 #1
0
 public DbObject(string file, string fileContent, DataReader dataReader)
 {
     _dataReader = dataReader;
     _file = file;
     _fileContent = fileContent;
     _fileLastAccessed = File.GetLastAccessTime(file);
     _fileLastModified = File.GetLastWriteTime(file);
     _dbObjName = GetObjectNameFromFileContent();
 }
예제 #2
0
 public FunctionDbObject(string file, string fileContent, DataReader dataReader)
     : base(file, fileContent, dataReader)
 {
 }
예제 #3
0
		public TriggerDbObject(string file, string fileContent, DataReader dataReader)
			: base(file, fileContent, dataReader)
		{
		}
예제 #4
0
        public static DbObject CreateDbObject(string file, DataReader dataReader)
        {
            string fileContent = ReadFileContent(file);

            if (DBUpgradeScriptDbObject.ContainsScript(file))
            {
                return new DBUpgradeScriptDbObject(file, fileContent, dataReader);
            }

            if (ProcedureDbObject.ContainsProcedure(fileContent))
            {
                return new ProcedureDbObject(file, fileContent, dataReader);
            }

            if (FunctionDbObject.ContainsFunction(fileContent))
            {
                return new FunctionDbObject(file, fileContent, dataReader);
            }

            if (ViewDbObject.ContainsView(fileContent))
            {
                return new ViewDbObject(file, fileContent, dataReader);
            }

            if (TriggerDbObject.ContainsTrigger(fileContent))
			{
                return new TriggerDbObject(file, fileContent, dataReader);
			}

            throw new Exception("The content of file " + file + "is not recognised");
        }
예제 #5
0
 public DBUpgradeScriptDbObject(string file, string fileContent, DataReader dataReader)
     : base(file, fileContent, dataReader)
 {
 }
예제 #6
0
		public override bool Execute()
        {
            Log.LogMessage(MessageImportance.High, "updateSP : version {0}",System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());

			bool buildAllFiles = !File.Exists(BuildTargetFile);

			DateTime targetTime = DateTime.Now;
			if (!buildAllFiles)
			{
				targetTime = File.GetLastWriteTime(BuildTargetFile);
			}
			//Log.LogMessage(MessageImportance.High, "BuildAllFiles = {0}", buildAllFiles);
			if (!buildAllFiles)
			{
				//Log.LogMessage(MessageImportance.High, "target time = {0}", targetTime);
			}

            Log.LogMessage(MessageImportance.High, "Build Configuration: {0}", BuildConfig);
            string configFile = ResolveConfigFilePath(TfsBuildDefinition,BuildConfig);
            
            DataReader dataReader = new DataReader();
            dataReader.Initialise(configFile);

            ScriptFile scriptFile = PrepareOutputScriptFile(OutputScriptFile);

            LogDatabaseAndServerPairs(dataReader);

			dataReader.RestoreSnapShot();
            dataReader.PrepareDbObjectDefintionStorage();

			foreach (string file in BuildFiles)
			{
				//Log.LogMessage(MessageImportance.High, "Processing: {0}", file);
				DateTime thisFileTime = File.GetLastWriteTime(file);
				if (buildAllFiles || thisFileTime > targetTime)
				{
                    DbObject dbobj = DbObject.CreateDbObject(file, dataReader);

                    string error = string.Empty;
                    StringBuilder sqlScript = new StringBuilder();
                    if (!dbobj.AppendToBatchScript(sqlScript, ref error))
                    {
                        Log.LogError(error);
                        return false;
                    }

                    try
                    {
                        bool bIgnoreNotExistForPermissions = true;

                        // Do not ignore errors 
                        if (file.Equals("dbupgradescript.sql", StringComparison.OrdinalIgnoreCase))
                            bIgnoreNotExistForPermissions = false;

                        string sql = sqlScript.ToString();

                        List<string> msgList = dataReader.UpdateDbObject(dbobj.DbObjName, dbobj.DbObjType, sql, null, bIgnoreNotExistForPermissions);

                        foreach (string msg in msgList)
                        {
                            Log.LogMessage(MessageImportance.High, msg);
                        }

                        if (dataReader.SqlCommandMsgs.Length > 0)
                        {
                            Log.LogMessage(MessageImportance.High, dataReader.SqlCommandMsgs);
                        }

                        scriptFile.AppendSql(sql);
                    }
                    catch (Exception e)
                    {
                        Log.LogError("Error processing " + file + ": " + e.Message);
                        return false;
                    }
				}
			}


			dataReader.ReCreateSnapShot();

            Log.LogMessage(MessageImportance.High, "BuildTargetFile = "+BuildTargetFile);
            string buildTargetPathAndFile = Path.Combine(Environment.CurrentDirectory, BuildTargetFile);
            Log.LogMessage(MessageImportance.High, "Full path to build target file = " + buildTargetPathAndFile);

            // Make sure the folder for the build target file exists
            string dir = Path.GetDirectoryName(buildTargetPathAndFile);
            if (!Directory.Exists(dir))
            {
                Log.LogMessage(MessageImportance.High, "Creating folder for target file '"+dir+"'");
                Directory.CreateDirectory(dir);
            }

            using (StreamWriter writer = new StreamWriter(buildTargetPathAndFile))
			{
			    writer.WriteLine(DateTime.Now.ToString());
			}

			return true;

		}
예제 #7
0
        private void LogDatabaseAndServerPairs(DataReader dataReader)
        {
            List<DataReader.DatabaseAndServerPairs> dbsp = dataReader.GetListOfDatabaseAndServerPairs();

            string msg = "Databases and Server pairs: ";

            foreach (DataReader.DatabaseAndServerPairs p in  dbsp)
            {
                msg += string.Format("[{0},{1}] ", p.dbName, p.serverName);
            }

            Log.LogMessage(MessageImportance.High, msg);
        }