Пример #1
0
        private IEnumerable <DatabaseFileInfo> InitRelocatedFiles()
        {
            DataRowCollection?rows = Restore.ReadFileList(_server).Rows;

            _ = rows ?? throw new FailedOperationException(Properties.Resources.CorruptDatabaseFileInfo);
            List <DatabaseFileInfo> files = new(rows.Count);

            if (!_server.Databases.Contains(_destinationDatabaseName))
            {
                foreach (DataRow?file in rows)
                {
                    _ = file ?? throw new FailedOperationException(Properties.Resources.CorruptDatabaseFileInfo);
                    var info = new DatabaseFileInfo(file.ToDictionary());
                    Restore.RelocateFiles.Add(Relocate(info));
                    files.Add(info);
                }
            }
            return(files);
        }
Пример #2
0
        private RelocateFile Relocate(DatabaseFileInfo fileInfo)
        {
            RelocateFile file = new();

            switch (fileInfo.FileType)
            {
            case FileType.Data:
                file.LogicalFileName  = _destinationDatabaseName;
                file.PhysicalFileName = Path.Combine(_server.Settings.DefaultFile, _destinationDatabaseName + ".mdf");
                break;

            case FileType.Log:
                file.LogicalFileName  = _destinationDatabaseName + "_log";
                file.PhysicalFileName = Path.Combine(_server.Settings.DefaultFile, _destinationDatabaseName + "_log.ldf");
                break;

            default:
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.FileTypeNotSupported, fileInfo.FileType));
            }
            return(file);
        }