public InstallationNameAndVersion Get(string name, SqlConnection connection, SqlTransaction transaction)
        {
            var result = default(InstallationNameAndVersion);

            using (var command = new SqlCommand(string.Format("SELECT * FROM {0} WHERE InstallationName = @InstallationName", _installerOptions.InstalledVersionsDatabaseTableName), connection, transaction))
            {
                command.Parameters.Add(new SqlParameter("@InstallationName", name));
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            result = new InstallationNameAndVersion
                            {
                                Id = (int)reader["Id"],
                                InstallationName = (string)reader["InstallationName"],
                                InstalledVersion = (int)reader["InstalledVersion"],
                                PreviousVersion = (int)reader["PreviousVersion"],
                                StartedInstallingVersion = (int)reader["StartedInstallingVersion"]
                            };
                        }
                    }
                }
            }

            return result;
        }
Ejemplo n.º 2
0
        internal void InstallBaseVersion(InstallerBaseVersion installerBaseVersion, SqlConnection connection, SqlTransaction transaction)
        {
            var installedNameAndVersion = new InstallationNameAndVersion
            {
                InstallationName = installerBaseVersion.InstallationName,
                InstalledVersion = installerBaseVersion.Version,
                PreviousVersion = 0,
                StartedInstallingVersion = installerBaseVersion.Version
            };

            _versionStorage.Create(installedNameAndVersion, connection, transaction);
        }
        public int EndInstallation(InstallationNameAndVersion installedVersion, SqlConnection connection, SqlTransaction transaction)
        {
            var updateSql = string.Format("UPDATE {0} SET InstalledVersion = @InstalledVersion + 1 WHERE Id = @id AND PreviousVersion = @PreviousVersion AND StartedInstallingVersion = @StartedInstallingVersion AND InstalledVersion = @InstalledVersion", _installerOptions.InstalledVersionsDatabaseTableName);
            using (var command = new SqlCommand(updateSql, connection, transaction))
            {
                command.Parameters.Add(new SqlParameter("@Id", installedVersion.Id));
                command.Parameters.Add(new SqlParameter("@PreviousVersion", installedVersion.PreviousVersion));
                command.Parameters.Add(new SqlParameter("@StartedInstallingVersion", installedVersion.StartedInstallingVersion));
                command.Parameters.Add(new SqlParameter("@InstalledVersion", installedVersion.InstalledVersion));

                return command.ExecuteNonQuery();
            }
        }
        public void Create(InstallationNameAndVersion installedNameAndVersion, SqlConnection connection, SqlTransaction transaction)
        {
            string insertSql = string.Format(@"INSERT INTO {0} (InstallationName, PreviousVersion, StartedInstallingVersion, InstalledVersion) VALUES (@InstallationName, @PreviousVersion, @StartedInstallingVersion, @InstalledVersion); SELECT CAST(SCOPE_IDENTITY() as int)", _installerOptions.InstalledVersionsDatabaseTableName);
            using (var command = new SqlCommand(insertSql, connection, transaction))
            {
                command.Parameters.Add(new SqlParameter("@InstallationName", installedNameAndVersion.InstallationName));
                command.Parameters.Add(new SqlParameter("@InstalledVersion", installedNameAndVersion.InstalledVersion));
                command.Parameters.Add(new SqlParameter("@PreviousVersion", installedNameAndVersion.PreviousVersion));
                command.Parameters.Add(new SqlParameter("@StartedInstallingVersion", installedNameAndVersion.StartedInstallingVersion));

                installedNameAndVersion.Id = (int)command.ExecuteScalar();
            }
        }
Ejemplo n.º 5
0
        internal virtual InstallationNameAndVersion GetInstalledVersion(string name, SqlConnection connection, SqlTransaction transaction)
        {
            if (!_versionStorage.IsInstalled(connection, transaction))
            {
                throw new InvalidOperationException("Installer is not installed");
            }

            InstallationNameAndVersion installedNameAndVersion = _versionStorage.Get(name, connection, transaction);

            if (installedNameAndVersion == default(InstallationNameAndVersion))
            {
                installedNameAndVersion = new InstallationNameAndVersion
                {
                    InstallationName = name,
                    InstalledVersion = 0,
                    PreviousVersion = 0,
                    StartedInstallingVersion = 0
                };

                _versionStorage.Create(installedNameAndVersion, connection, transaction);
            }

            return installedNameAndVersion;
        }