protected RuntimeScriptFile GetTargetRuntimeScriptFile(string targetScriptFilename)
        {
            targetScriptFilename.ThrowIfNull(nameof(targetScriptFilename));


            RuntimeScriptFile targetRuntimeScriptFile = null;

            if (targetScriptFilename.Trim().ToUpperInvariant() != RuntimeScriptFile.TargetNoneScriptFileName.Trim().ToUpperInvariant())
            {
                if (targetScriptFilename.Trim().ToUpperInvariant() == RuntimeScriptFile.TargetLastScriptFileName.Trim().ToUpperInvariant())
                {
                    targetRuntimeScriptFile = AllFileSystemScriptFiles.LastOrDefault();
                }
                else
                {
                    targetRuntimeScriptFile = AllFileSystemScriptFiles.FirstOrDefault(e => e.Filename.Trim().ToUpperInvariant() == targetScriptFilename.Trim().ToUpperInvariant());
                    if (targetRuntimeScriptFile == null)
                    {
                        throw new ArgumentException($"{targetRuntimeScriptFile} is not exist in the {ScriptFileType.FileTypeCode} files", nameof(targetScriptFilename));
                    }
                }
            }



            return(targetRuntimeScriptFile);
        }
        protected RuntimeScriptFile CreateLasetExecutedFileItem()
        {
            RuntimeScriptFile prevExecutionLastScriptFile = null;

            if (!string.IsNullOrWhiteSpace(DBExecutedFiles.LastFileOfLastExecutedFilename))
            {
                string lastFileFullPath = Path.Combine(FileSystemScriptFiles.FolderPath, DBExecutedFiles.LastFileOfLastExecutedFilename);
                prevExecutionLastScriptFile = FileSystemScriptFiles.CreateRuntimeScriptFileInstanceByFilename(lastFileFullPath);
            }

            return(prevExecutionLastScriptFile);
        }
Beispiel #3
0
        public static bool TryParseNextRuntimeScriptFileInstance(ScriptFileTypeBase scriptFileType, string folderPath, string scriptName, RuntimeScriptFile prevRuntimeScriptFile, out RuntimeScriptFile newRuntimeScriptFile)
        {
            int nextOrderNum = 1;

            if (prevRuntimeScriptFile != null)
            {
                nextOrderNum = prevRuntimeScriptFile.OrderNum + 1;
            }

            newRuntimeScriptFile = new RuntimeScriptFile(scriptFileType, folderPath, scriptName, nextOrderNum);

            return(newRuntimeScriptFile.IsValidFileName);
        }
        protected virtual List <RuntimeScriptFile> FilterPendingScriptsFilesByTarget(RuntimeScriptFile prevExecutionLastScriptFile, RuntimeScriptFile targetScriptFile, List <RuntimeScriptFile> sourceRuntimeFiles)
        {
            sourceRuntimeFiles.ThrowIfNull(nameof(sourceRuntimeFiles));
            //targetScriptFile.ThrowIfNull(nameof(targetScriptFile));

            List <RuntimeScriptFile> pendingScriptFilesList = new List <RuntimeScriptFile>();


            foreach (RuntimeScriptFile scriptFileItem in sourceRuntimeFiles)
            {
                // Comment:  We return all the files that after the preve executed file and before (and equal) to the target file.
                if ((prevExecutionLastScriptFile == null || 0 < string.Compare(scriptFileItem.SortKey, prevExecutionLastScriptFile.SortKey, StringComparison.Ordinal)) &&
                    (targetScriptFile == null || string.Compare(scriptFileItem.SortKey, targetScriptFile.SortKey, StringComparison.Ordinal) <= 0))
                {
                    pendingScriptFilesList.Add(scriptFileItem);
                }
            }

            return(pendingScriptFilesList);
        }
Beispiel #5
0
        protected void LoadScriptFilesList()
        {
            List <RuntimeScriptFile> newScriptFilesList = new List <RuntimeScriptFile>();

            if (Directory.Exists(FolderPath))
            {
                string[] arrAllScriptFiles = Directory.GetFiles(FolderPath, $"{ScriptFileType.Prefix}*.sql", SearchOption.TopDirectoryOnly);

                foreach (string fileFullPath in arrAllScriptFiles)
                {
                    RuntimeScriptFile currScriptFile = new RuntimeScriptFile(ScriptFileType, FolderPath, fileFullPath);

                    string computedFileHash = _fileChecksum.GetHashByFilePath(fileFullPath);
                    currScriptFile.ComputedHash         = computedFileHash;
                    currScriptFile.ComputedHashDateTime = DateTime.Now;

                    newScriptFilesList.Add(currScriptFile);
                }
            }

            ScriptFilesList = newScriptFilesList.OrderBy(e => e.SortKey).ToList();
        }
Beispiel #6
0
        public RuntimeScriptFile CreateNextRuntimeScriptFileInstance(string scriptName, RuntimeScriptFile prevRuntimeScriptFile)
        {
            scriptName.ThrowIfNull(nameof(scriptName));

            if (!RuntimeScriptFile.TryParseNextRuntimeScriptFileInstance(ScriptFileType, FolderPath, scriptName, prevRuntimeScriptFile, out RuntimeScriptFile newRuntimeScriptFile))
            {
                string errorMessage =
                    CoreTextResources
                    .InvalidFilenameErrorMessage
                    .Replace("[Filename]", newRuntimeScriptFile.Filename)
                    .Replace("[FileTypeCode]", ScriptFileType.FileTypeCode)
                    .Replace("[FilenamePattern]", ScriptFileType.FilenamePattern);

                throw new Exception(errorMessage);
            }

            File.AppendAllText(newRuntimeScriptFile.FileFullPath, "", Encoding.UTF8);

            Load();


            return(newRuntimeScriptFile);
        }
        private void CreateFileExistInDBButNotExistInSystemList(FileSystemScriptFiles fileSystemScriptFiles)
        {
            NotExistInFileSystemButExistInDB = new List <RuntimeScriptFile>();

            foreach (DataRow dbExecutedFileRow in DBExecutedFiles.ExecutedFilesList)
            {
                string dbFilename = Convert.ToString(dbExecutedFileRow["Filename"], CultureInfo.InvariantCulture);

                RuntimeScriptFile fileSystemFile =
                    AllFileSystemScriptFiles.FirstOrDefault(e => dbFilename.Trim().ToUpperInvariant() == e.Filename.Trim().ToUpperInvariant());

                if (fileSystemFile == null)
                {
                    string            fileFullPath = Path.Combine(fileSystemScriptFiles.FolderPath, dbFilename);
                    RuntimeScriptFile misssingFileSystemFileItem = fileSystemScriptFiles.CreateRuntimeScriptFileInstanceByFilename(fileFullPath);
                    NotExistInFileSystemButExistInDB.Add(misssingFileSystemFileItem);
                }

                if (dbFilename == DBExecutedFiles.LastFileOfLastExecutedFilename)
                {
                    break;
                }
            }
        }
Beispiel #8
0
 public bool TryParseNextRuntimeScriptFileName(string scriptName, RuntimeScriptFile prevRuntimeScriptFile, out RuntimeScriptFile newRuntimeScriptFile)
 {
     return(RuntimeScriptFile.TryParseNextRuntimeScriptFileInstance(ScriptFileType, FolderPath, scriptName, prevRuntimeScriptFile, out newRuntimeScriptFile));
 }
 public bool TryParseNextRuntimeScriptFileName(string scriptName, out RuntimeScriptFile newRuntimeScriptFile)
 {
     return(FileSystemScriptFiles.TryParseNextRuntimeScriptFileName(scriptName, LastScriptFile, out newRuntimeScriptFile));
 }