コード例 #1
0
ファイル: CMRestoreSQLBackup.cs プロジェクト: vgrinin/gin
        private List <SqlParameterClass> InitRestoreParameters(IExecutionContext context, string resultSetCtxName)
        {
            List <SqlParameterClass> parameters = new List <SqlParameterClass>();

            DataTable fileList    = (DataTable)context.GetResult(resultSetCtxName);
            var       files       = fileList.AsEnumerable();
            var       rows        = files.AsEnumerable();
            var       rowDataFile = rows.FirstOrDefault(r => (string)r["Type"] == "D");

            if (rowDataFile == null)
            {
                throw new Exception("Бэкап не содержит файла MDF базы данных");
            }
            var rowLogFile = rows.FirstOrDefault(r => (string)r["Type"] == "L");

            if (rowLogFile == null)
            {
                throw new Exception("Бэкап не содержит файла LDF журнала транзакций");
            }
            string ldfFileLogicalName  = (string)rowLogFile["LogicalName"];
            string mdfFileLogicalName  = (string)rowDataFile["LogicalName"];
            string ldfFilePhysicalName = (string)rowLogFile["PhysicalName"];
            string mdfFilePhysicalName = (string)rowDataFile["PhysicalName"];

            if (DataBaseFullPath != null)
            {
                string mdfFileOnlyName = Path.GetFileName(mdfFilePhysicalName);
                string ldfFileOnlyName = Path.GetFileName(ldfFilePhysicalName);

                DataBaseFullPath = context.GetStringFrom(DataBaseFullPath);

                mdfFilePhysicalName = Path.Combine(DataBaseFullPath, mdfFileOnlyName);
                ldfFilePhysicalName = Path.Combine(DataBaseFullPath, ldfFileOnlyName);
            }

            SqlParameterClass p = context.AddSqlParameterToContext("BASENAME", DatabaseName, SqlDbType.VarChar, 1024, ParameterDirection.Input);

            parameters.Add(p);

            string absoluteSourcePath = context.GetStringFrom(BackupFilePath);

            p = context.AddSqlParameterToContext("FULLNAME", absoluteSourcePath, SqlDbType.VarChar, 1024, ParameterDirection.Input);
            parameters.Add(p);
            p = context.AddSqlParameterToContext("MDFLOGICALNAME", mdfFileLogicalName, SqlDbType.VarChar, 1024, ParameterDirection.Input);
            parameters.Add(p);

            p = context.AddSqlParameterToContext("MDFFILEPATH", mdfFilePhysicalName, SqlDbType.VarChar, 1024, ParameterDirection.Input);
            parameters.Add(p);

            p = context.AddSqlParameterToContext("LDFLOGICALNAME", ldfFileLogicalName, SqlDbType.VarChar, 1024, ParameterDirection.Input);
            parameters.Add(p);

            p = context.AddSqlParameterToContext("LDFFILEPATH", ldfFilePhysicalName, SqlDbType.VarChar, 1024, ParameterDirection.Input);
            parameters.Add(p);

            return(parameters);
        }
コード例 #2
0
ファイル: CMRestoreSQLBackup.cs プロジェクト: vgrinin/gin
        private List <SqlParameterClass> InitFilelistParameters(IExecutionContext context)
        {
            List <SqlParameterClass> parameters = new List <SqlParameterClass>();

            string            absoluteBackupFilePath = context.GetStringFrom(BackupFilePath);
            SqlParameterClass p = context.AddSqlParameterToContext("FULLNAME", absoluteBackupFilePath, SqlDbType.VarChar, 1024, ParameterDirection.Input);

            parameters.Add(p);

            return(parameters);
        }
コード例 #3
0
ファイル: SQLUtil.cs プロジェクト: vgrinin/gin
        public static SqlParameterClass AddSqlParameterToContext(this IExecutionContext context, string name, string value, SqlDbType type, int size, ParameterDirection direction)
        {
            string prefix = Guid.NewGuid().ToString("N") + "_";
            string contextName = prefix + name;
            string valueName = contextName + "_value";

            SaveString saveConst = new SaveString()
            {
                Value = value,
                ResultName = valueName
            };
            saveConst.Do(context);
            SqlParameterClass p = new SqlParameterClass()
            {
                ParameterName = name,
                Direction = direction,
                Type = type,
                Size = size,
                ValueName = valueName
            };
            return p;
        }
コード例 #4
0
        private List <SqlParameterClass> InitParameters(IExecutionContext context)
        {
            List <SqlParameterClass> parameters = new List <SqlParameterClass>();

            string absoluteDatabaseName = context.GetStringFrom(DatabaseName);

            context.Log.AddLogInformation("DatabaseName = '" + absoluteDatabaseName + "'");
            SqlParameterClass p = context.AddSqlParameterToContext("BASENAME", absoluteDatabaseName, SqlDbType.VarChar, 255, ParameterDirection.Input);

            parameters.Add(p);

            string absoluteBackupFilePath = context.GetStringFrom(BackupFilePath);

            context.Log.AddLogInformation("BackupFilePath = '" + absoluteBackupFilePath + "'");
            string backupName = Path.GetFileNameWithoutExtension(absoluteBackupFilePath);

            p = context.AddSqlParameterToContext("NAME", backupName, SqlDbType.VarChar, 255, ParameterDirection.Input);
            parameters.Add(p);
            p = context.AddSqlParameterToContext("FULLNAME", absoluteBackupFilePath, SqlDbType.VarChar, 255, ParameterDirection.Input);
            parameters.Add(p);
            return(parameters);
        }