ST Work with db optimised
This commit is contained in:
parent
20c474a8a7
commit
d618fb5f64
5 changed files with 113 additions and 43 deletions
|
@ -6587,6 +6587,24 @@ SELECT
|
|||
WHERE [DomainId] = @DomainId AND [RecordType] = @RecordType
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetDomainAllDnsRecords')
|
||||
DROP PROCEDURE GetDomainAllDnsRecords
|
||||
GO
|
||||
CREATE PROCEDURE [dbo].GetDomainAllDnsRecords
|
||||
(
|
||||
@DomainId INT
|
||||
)
|
||||
AS
|
||||
SELECT
|
||||
ID,
|
||||
DomainId,
|
||||
DnsServer,
|
||||
RecordType,
|
||||
Value,
|
||||
Date
|
||||
FROM [dbo].[DomainDnsRecords]
|
||||
WHERE [DomainId] = @DomainId
|
||||
GO
|
||||
|
||||
|
||||
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'AddDomainDnsRecord')
|
||||
|
@ -6674,6 +6692,20 @@ AS
|
|||
UPDATE [dbo].[Domains] SET [LastUpdateDate] = @Date WHERE [DomainID] = @DomainId
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'UpdateDomainDates')
|
||||
DROP PROCEDURE UpdateDomainDates
|
||||
GO
|
||||
CREATE PROCEDURE [dbo].UpdateDomainDates
|
||||
(
|
||||
@DomainId INT,
|
||||
@DomainCreationDate DateTime,
|
||||
@DomainExpirationDate DateTime,
|
||||
@DomainLastUpdateDate DateTime
|
||||
)
|
||||
AS
|
||||
UPDATE [dbo].[Domains] SET [CreationDate] = @DomainCreationDate, [ExpirationDate] = @DomainExpirationDate, [LastUpdateDate] = @DomainLastUpdateDate WHERE [DomainID] = @DomainId
|
||||
GO
|
||||
|
||||
|
||||
--Updating Domain procedures
|
||||
|
||||
|
|
|
@ -1910,9 +1910,21 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public static IDataReader GetProcessBackgroundTasks(BackgroundTaskStatus status)
|
||||
{
|
||||
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
||||
ObjectQualifier + "GetProcessBackgroundTasks",
|
||||
new SqlParameter("@status", (int)status));
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure,
|
||||
ObjectQualifier + "GetProcessBackgroundTasks",
|
||||
new SqlParameter("@status", (int)status));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string text = string.Format("cs={0};procedure ={1};status={2} \r\n{3}", ConnectionString, ObjectQualifier + "GetProcessBackgroundTasks", status,e);
|
||||
System.IO.File.WriteAllText(@"C:\WebsitePanel\SchedulerService\WriteText.txt", text);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static IDataReader GetBackgroundTopTask(Guid guid)
|
||||
|
@ -4744,9 +4756,19 @@ namespace WebsitePanel.EnterpriseServer
|
|||
);
|
||||
}
|
||||
|
||||
public static IDataReader GetDomainAllDnsRecords(int domainId)
|
||||
{
|
||||
return SqlHelper.ExecuteReader(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"GetDomainAllDnsRecords",
|
||||
new SqlParameter("@DomainId", domainId)
|
||||
);
|
||||
}
|
||||
|
||||
public static void AddDomainDnsRecord(DnsRecordInfo domainDnsRecord)
|
||||
{
|
||||
SqlHelper.ExecuteReader(
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"AddDomainDnsRecord",
|
||||
|
@ -4770,7 +4792,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public static void DeleteDomainDnsRecord(int id)
|
||||
{
|
||||
SqlHelper.ExecuteReader(
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"DeleteDomainDnsRecord",
|
||||
|
@ -4795,7 +4817,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
private static void UpdateDomainDate(int domainId, string stroredProcedure, DateTime date)
|
||||
{
|
||||
SqlHelper.ExecuteReader(
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
stroredProcedure,
|
||||
|
@ -4804,6 +4826,19 @@ namespace WebsitePanel.EnterpriseServer
|
|||
);
|
||||
}
|
||||
|
||||
public static void UpdateDomainDates(int domainId, DateTime? domainCreationDate, DateTime? domainExpirationDate, DateTime? domainLastUpdateDate)
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"UpdateDomainDates",
|
||||
new SqlParameter("@DomainId", domainId),
|
||||
new SqlParameter("@DomainCreationDate", domainCreationDate),
|
||||
new SqlParameter("@DomainExpirationDate", domainExpirationDate),
|
||||
new SqlParameter("@DomainLastUpdateDate", domainLastUpdateDate)
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using WebsitePanel.Providers.DomainLookup;
|
||||
using Whois.NET;
|
||||
|
||||
|
@ -26,11 +27,15 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public override void DoWork()
|
||||
{
|
||||
TaskManager.WriteWarning("Domain Expiration Task started");
|
||||
|
||||
BackgroundTask topTask = TaskManager.TopTask;
|
||||
var domainUsers = new Dictionary<int, UserInfo>();
|
||||
var checkedDomains = new List<int>();
|
||||
var expiredDomains = new List<DomainInfo>();
|
||||
var nonExistenDomains = new List<DomainInfo>();
|
||||
var subDomains = new List<DomainInfo>();
|
||||
var allTopLevelDomains = new List<DomainInfo>();
|
||||
|
||||
// get input parameters
|
||||
int daysBeforeNotify;
|
||||
|
@ -55,10 +60,12 @@ namespace WebsitePanel.EnterpriseServer
|
|||
{
|
||||
var domains = ServerController.GetDomains(package.PackageId);
|
||||
|
||||
var subDomains = domains.Where(x => x.IsSubDomain).ToList();
|
||||
subDomains.AddRange(domains.Where(x => x.IsSubDomain));
|
||||
|
||||
var topLevelDomains = domains = domains.Where(x => !x.IsSubDomain && !x.IsDomainPointer).ToList(); //Selecting top-level domains
|
||||
|
||||
allTopLevelDomains.AddRange(topLevelDomains);
|
||||
|
||||
domains = topLevelDomains.Where(x => x.CreationDate == null || x.ExpirationDate == null ? true : CheckDomainExpiration(x.ExpirationDate, daysBeforeNotify)).ToList(); // selecting expired or with empty expire date domains
|
||||
|
||||
var domainUser = UserController.GetUser(package.UserId);
|
||||
|
@ -88,16 +95,23 @@ namespace WebsitePanel.EnterpriseServer
|
|||
{
|
||||
nonExistenDomains.Add(domain);
|
||||
}
|
||||
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var subDomain in subDomains)
|
||||
subDomains = subDomains.GroupBy(p => p.DomainId).Select(g => g.First()).ToList();
|
||||
allTopLevelDomains = allTopLevelDomains.GroupBy(p => p.DomainId).Select(g => g.First()).ToList();
|
||||
|
||||
foreach (var subDomain in subDomains)
|
||||
{
|
||||
var mainDomain = allTopLevelDomains.Where(x => subDomain.DomainName.ToLowerInvariant().Contains(x.DomainName.ToLowerInvariant())).OrderByDescending(s => s.DomainName.Length).FirstOrDefault(); ;
|
||||
|
||||
if (mainDomain != null)
|
||||
{
|
||||
var mainDomain = topLevelDomains.Where(x => subDomain.DomainName.ToLowerInvariant().Contains(x.DomainName.ToLowerInvariant())).OrderByDescending(s => s.DomainName.Length).FirstOrDefault(); ;
|
||||
ServerController.UpdateDomainRegistrationData(subDomain, mainDomain.CreationDate, mainDomain.ExpirationDate);
|
||||
|
||||
if (mainDomain != null)
|
||||
{
|
||||
ServerController.UpdateDomainRegistrationData(subDomain, mainDomain.CreationDate, mainDomain.ExpirationDate);
|
||||
}
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using WebsitePanel.Providers.DNS;
|
||||
using WebsitePanel.Providers.DomainLookup;
|
||||
using WebsitePanel.Server;
|
||||
|
@ -85,8 +86,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
DomainDnsChanges domainChanges = new DomainDnsChanges();
|
||||
domainChanges.DomainName = domain.DomainName;
|
||||
|
||||
var mxRecords = ObjectUtils.CreateListFromDataReader<DnsRecordInfo>(DataProvider.GetDomainDnsRecords(domain.DomainId, DnsRecordType.MX));
|
||||
var nsRecords = ObjectUtils.CreateListFromDataReader<DnsRecordInfo>(DataProvider.GetDomainDnsRecords(domain.DomainId, DnsRecordType.NS));
|
||||
var dbDnsRecords = ObjectUtils.CreateListFromDataReader<DnsRecordInfo>(DataProvider.GetDomainAllDnsRecords(domain.DomainId));
|
||||
|
||||
//execute server
|
||||
foreach (var dnsServer in dnsServers)
|
||||
|
@ -97,8 +97,8 @@ namespace WebsitePanel.EnterpriseServer
|
|||
FillRecordData(dnsMxRecords, domain, dnsServer);
|
||||
FillRecordData(dnsNsRecords, domain, dnsServer);
|
||||
|
||||
domainChanges.DnsChanges.AddRange(ApplyDomainRecordsChanges(mxRecords, dnsMxRecords, dnsServer));
|
||||
domainChanges.DnsChanges.AddRange(ApplyDomainRecordsChanges(nsRecords, dnsNsRecords, dnsServer));
|
||||
domainChanges.DnsChanges.AddRange(ApplyDomainRecordsChanges(dbDnsRecords.Where(x => x.RecordType == DnsRecordType.MX), dnsMxRecords, dnsServer));
|
||||
domainChanges.DnsChanges.AddRange(ApplyDomainRecordsChanges(dbDnsRecords.Where(x => x.RecordType == DnsRecordType.NS), dnsNsRecords, dnsServer));
|
||||
}
|
||||
|
||||
domainsChanges.Add(domainChanges);
|
||||
|
@ -200,6 +200,8 @@ namespace WebsitePanel.EnterpriseServer
|
|||
private void RemoveRecord(DnsRecordInfo dnsRecord)
|
||||
{
|
||||
DataProvider.DeleteDomainDnsRecord(dnsRecord.Id);
|
||||
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
private void AddRecords(IEnumerable<DnsRecordInfo> dnsRecords)
|
||||
|
@ -213,6 +215,8 @@ namespace WebsitePanel.EnterpriseServer
|
|||
private void AddRecord(DnsRecordInfo dnsRecord)
|
||||
{
|
||||
DataProvider.AddDomainDnsRecord(dnsRecord);
|
||||
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
private void SendMailMessage(UserInfo user, IEnumerable<DomainDnsChanges> domainsChanges)
|
||||
|
|
|
@ -2680,26 +2680,20 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public static DomainInfo UpdateDomainRegistrationData(DomainInfo domain)
|
||||
{
|
||||
DateTime? createdDate = null;
|
||||
DateTime? expiredDate = null;
|
||||
|
||||
try
|
||||
{
|
||||
DataProvider.UpdateDomainLastUpdateDate(domain.DomainId, DateTime.Now);
|
||||
|
||||
var whoisResult = WhoisClient.Query(domain.DomainName.ToLowerInvariant());
|
||||
|
||||
var createdDate = GetDomainInfoDate(whoisResult.Raw, _createdDatePatterns);
|
||||
var expiredDate = GetDomainInfoDate(whoisResult.Raw, _expiredDatePatterns);
|
||||
createdDate = GetDomainInfoDate(whoisResult.Raw, _createdDatePatterns);
|
||||
expiredDate = GetDomainInfoDate(whoisResult.Raw, _expiredDatePatterns);
|
||||
|
||||
if (createdDate != null)
|
||||
{
|
||||
domain.CreationDate = createdDate;
|
||||
DataProvider.UpdateDomainCreationDate(domain.DomainId, createdDate.Value);
|
||||
}
|
||||
domain.CreationDate = createdDate;
|
||||
domain.ExpirationDate = expiredDate;
|
||||
|
||||
if (expiredDate != null)
|
||||
{
|
||||
domain.ExpirationDate = expiredDate;
|
||||
DataProvider.UpdateDomainExpirationDate(domain.DomainId, expiredDate.Value);
|
||||
}
|
||||
DataProvider.UpdateDomainDates(domain.DomainId, createdDate, expiredDate, DateTime.Now);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -2711,19 +2705,10 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public static DomainInfo UpdateDomainRegistrationData(DomainInfo domain, DateTime? creationDate, DateTime? expirationDate)
|
||||
{
|
||||
if (creationDate != null)
|
||||
{
|
||||
domain.CreationDate = creationDate;
|
||||
DataProvider.UpdateDomainCreationDate(domain.DomainId, creationDate.Value);
|
||||
}
|
||||
DataProvider.UpdateDomainDates(domain.DomainId, creationDate, expirationDate, DateTime.Now);
|
||||
|
||||
if (expirationDate != null)
|
||||
{
|
||||
domain.ExpirationDate = expirationDate;
|
||||
DataProvider.UpdateDomainExpirationDate(domain.DomainId, expirationDate.Value);
|
||||
}
|
||||
|
||||
DataProvider.UpdateDomainLastUpdateDate(domain.DomainId, DateTime.Now);
|
||||
domain.CreationDate = creationDate;
|
||||
domain.ExpirationDate = expirationDate;
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue