public void Validate(IEnumerable<TableData> tables, IJobSpecification job)
        {
            var hasPartitionKey = false;
            var staleTime = GetStaleTime(tables);

            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Open();

                if (!string.IsNullOrEmpty(CreateDatabaseName))
                {

                    if (Update)
                    {
                        conn.ChangeDatabase(CreateDatabaseName);

                        //Check lock. Release immediately upon success.
                        AcquireLock(conn, null);
                        ReleaseLock(conn, null);

                        ValidateSchema(conn, tables);
                    }

                    if (staleTime > TimeSpan.Zero)
                    {
                        hasPartitionKey = true;
                        if (Update && !Rebuild)
                        {
                            var lastCutoff =
                                new SqlCommand(@"SELECT TOP 1 LastCutoff FROM Sitecore.JobInfo", conn).ExecuteScalar();
                            _cutoff = DBNull.Value.Equals(lastCutoff) ? (DateTime?)null : ((DateTime)lastCutoff).SpecifyKind(DateTimeKind.Utc);
                            if (_cutoff.HasValue)
                            {
                                _cutoff = SqlUpdateUtil.GetPartitionDate(_cutoff.Value.Add(-staleTime), staleTime);
                            }
                        }

                        _nextCuttoff = DateTime.UtcNow;
                    }
                }
            }

            if (!string.IsNullOrEmpty(SsasConnectionString))
            {
                var connectionStringBuilder = new SqlConnectionStringBuilder(ConnectionString);
                if (!string.IsNullOrEmpty(CreateDatabaseName))
                {
                    connectionStringBuilder.InitialCatalog = CreateDatabaseName;
                }
                else
                {
                    throw new Exception("Database must be specified either in the connection string or as the Database parameter");
                }
                _ssasExporter = new SsasExporter(SsasConnectionString, SsasDbName,
                    "Provider=SQLOLEDB;" + connectionStringBuilder.ConnectionString);
                _ssasExporter.Update = Update;
                _ssasExporter.Validate(tables, job);

                _ssasExporter.ReferenceDate = (_nextCuttoff ?? DateTime.UtcNow).Add(-staleTime);

                if (Rebuild)
                {
                    _ssasExporter.IncrementalUpdate = SqlClearOptions.None;
                }
                else
                {
                    _ssasExporter.IncrementalUpdate = SqlClearOptions;
                    if (hasPartitionKey)
                    {
                        _ssasExporter.IncrementalUpdate |= SqlClearOptions.Facts;
                    }
                }
            }
            else if (!string.IsNullOrEmpty(SsasDbName))
            {
                throw new Exception("A connection string for SSAS Tabular is needed");
            }
        }
        public void Validate(IEnumerable <TableData> tables, IJobSpecification job)
        {
            var hasPartitionKey = false;
            var staleTime       = GetStaleTime(tables);

            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Open();

                if (!string.IsNullOrEmpty(CreateDatabaseName))
                {
                    if (Update)
                    {
                        conn.ChangeDatabase(CreateDatabaseName);

                        //Check lock. Release immediately upon success.
                        AcquireLock(conn, null);
                        ReleaseLock(conn, null);

                        ValidateSchema(conn, tables);
                    }

                    if (staleTime > TimeSpan.Zero)
                    {
                        hasPartitionKey = true;
                        if (Update && !Rebuild)
                        {
                            var lastCutoff =
                                new SqlCommand(@"SELECT TOP 1 LastCutoff FROM Sitecore.JobInfo", conn).ExecuteScalar();
                            _cutoff = DBNull.Value.Equals(lastCutoff) ? (DateTime?)null : ((DateTime)lastCutoff).SpecifyKind(DateTimeKind.Utc);
                            if (_cutoff.HasValue)
                            {
                                _cutoff = SqlUpdateUtil.GetPartitionDate(_cutoff.Value.Add(-staleTime), staleTime);
                            }
                        }

                        _nextCuttoff = DateTime.UtcNow;
                    }
                }
            }

            if (!string.IsNullOrEmpty(SsasConnectionString))
            {
                var connectionStringBuilder = new SqlConnectionStringBuilder(ConnectionString);
                if (!string.IsNullOrEmpty(CreateDatabaseName))
                {
                    connectionStringBuilder.InitialCatalog = CreateDatabaseName;
                }
                else
                {
                    throw new Exception("Database must be specified either in the connection string or as the Database parameter");
                }
                _ssasExporter = new SsasExporter(SsasConnectionString, SsasDbName,
                                                 "Provider=SQLOLEDB;" + connectionStringBuilder.ConnectionString);
                _ssasExporter.Update = Update;
                _ssasExporter.Validate(tables, job);

                _ssasExporter.ReferenceDate = (_nextCuttoff ?? DateTime.UtcNow).Add(-staleTime);

                if (Rebuild)
                {
                    _ssasExporter.IncrementalUpdate = SqlClearOptions.None;
                }
                else
                {
                    _ssasExporter.IncrementalUpdate = SqlClearOptions;
                    if (hasPartitionKey)
                    {
                        _ssasExporter.IncrementalUpdate |= SqlClearOptions.Facts;
                    }
                }
            }
            else if (!string.IsNullOrEmpty(SsasDbName))
            {
                throw new Exception("A connection string for SSAS Tabular is needed");
            }
        }