Example #1
0
        public RuntimeScriptFile(ScriptFileTypeBase scriptFileType, string folderPath, string fileFullPath)
        {
            scriptFileType.ThrowIfNull(nameof(scriptFileType));
            fileFullPath.ThrowIfNull(nameof(fileFullPath));
            folderPath.ThrowIfNull(nameof(folderPath));

            ScriptFileType = scriptFileType;
            FolderPath     = folderPath;


            FileInfo fiFile = new FileInfo(fileFullPath);

            string shouldBeFileFullPath = Path.Combine(FolderPath, fiFile.Name);

            if (shouldBeFileFullPath.Trim().ToUpperInvariant() != fileFullPath.Trim().ToUpperInvariant())
            {
                throw new ArgumentException($"The argument path: '{fileFullPath}' is different from '{shouldBeFileFullPath}'");
            }

            string filename = fiFile.Name;
            string filenameWithoutExtension = fiFile.Name.Replace(fiFile.Extension, "");


            bool isFilenameValid = Regex.IsMatch(filename, ScriptFileType.RegexFilenamePattern);

            if (!isFilenameValid)
            {
                string errorMessage =
                    CoreTextResources
                    .InvalidFilenameErrorMessage
                    .Replace("[Filename]", filename)
                    .Replace("[FileTypeCode]", ScriptFileType.FileTypeCode)
                    .Replace("[FilenamePattern]", ScriptFileType.FilenamePattern);

                throw new Exception(errorMessage);
            }

            string[] arrFilenameParts = Regex.Split(filenameWithoutExtension, "_");

            ScriptName = string.Join("_", arrFilenameParts.Skip(2));

            string fileOrderNumStr = arrFilenameParts[1];

            if (!int.TryParse(fileOrderNumStr, out int tempOrderNum_FromFilename))
            {
                string errorMessage =
                    CoreTextResources
                    .InvalidOrderNumForIncScriptException
                    .Replace("[Filename]", filename);

                throw new Exception(errorMessage);
            }

            OrderNum = tempOrderNum_FromFilename;
        }
Example #2
0
        public FileSystemScriptFiles(FileChecksum fileChecksum,
                                     ScriptFileTypeBase scriptFileType,
                                     string folderPath)
        {
            fileChecksum.ThrowIfNull(nameof(fileChecksum));
            scriptFileType.ThrowIfNull(nameof(scriptFileType));
            folderPath.ThrowIfNull(nameof(folderPath));


            _fileChecksum  = fileChecksum;
            ScriptFileType = scriptFileType;
            FolderPath     = folderPath;

            Load();
        }