private static ResultObject CreateDnsZoneRecord(int domainId, string recordName, string ip) { ResultObject ret = StartTask <ResultObject>("CRM", "CREATE_DNS_ZONE"); try { //check for existing empty A record DnsRecord[] records = ServerController.GetDnsZoneRecords(domainId); foreach (DnsRecord record in records) { if ((record.RecordType == DnsRecordType.A) && (String.Compare(recordName, record.RecordName, true) == 0)) { CompleteTask(ret, CrmErrorCodes.CANNOT_CREATE_DNS_ZONE, null, string.Format("DNS record already exists. DomainId={0}, RecordName={1}", domainId, recordName)); return(ret); } } int res = ServerController.AddDnsZoneRecord(domainId, recordName, DnsRecordType.A, ip, 0); if (res != 0) { CompleteTask(ret, CrmErrorCodes.CANNOT_CREATE_DNS_ZONE, null, string.Format("Cannot create dns record. DomainId={0}, IP={1}, ErrorCode={2}, RecordName={3}", domainId, ip, res, recordName)); return(ret); } } catch (Exception ex) { CompleteTask(ret, CrmErrorCodes.CANNOT_CREATE_DNS_ZONE, ex); return(ret); } CompleteTask(); return(ret); }
public int AddDnsZoneRecord(int domainId, string recordName, DnsRecordType recordType, string recordData, int mxPriority, int srvPriority, int srvWeight, int srvPortNumber) { return(ServerController.AddDnsZoneRecord(domainId, recordName, recordType, recordData, mxPriority, srvPriority, srvWeight, srvPortNumber)); }
/// <summary> /// Adds SharePoint site collection. /// </summary> /// <param name="item">Site collection description.</param> /// <returns>Created site collection id within metabase.</returns> public static int AddSiteCollection(SharePointSiteCollection item) { string domainName = item.Name; // Check account. int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return(accountCheck); } // Check package. int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive); if (packageCheck < 0) { return(packageCheck); } // Check quota. OrganizationStatistics orgStats = OrganizationController.GetOrganizationStatistics(item.OrganizationId); //QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.HOSTED_SHAREPOINT_SITES); if (orgStats.AllocatedSharePointSiteCollections > -1 && orgStats.CreatedSharePointSiteCollections >= orgStats.AllocatedSharePointSiteCollections) { return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_QUOTA_LIMIT); } // Check if stats resource is available int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.HostedSharePoint); if (serviceId == 0) { return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_UNAVAILABLE); } StringDictionary hostedSharePointSettings = ServerController.GetServiceSettings(serviceId); Uri rootWebApplicationUri = new Uri(hostedSharePointSettings["RootWebApplicationUri"]); item.Name = String.Format("{0}://{1}", rootWebApplicationUri.Scheme, item.Name); if (rootWebApplicationUri.Port > 0 && rootWebApplicationUri.Port != 80 && rootWebApplicationUri.Port != 443) { item.PhysicalAddress = String.Format("{0}:{1}", item.Name, rootWebApplicationUri.Port); } else { item.PhysicalAddress = item.Name; } Organization org = OrganizationController.GetOrganization(item.OrganizationId); item.MaxSiteStorage = RecalculateMaxSize(org.MaxSharePointStorage, (int)item.MaxSiteStorage); item.WarningStorage = item.MaxSiteStorage == -1 ? -1 : Math.Min((int)item.WarningStorage, item.MaxSiteStorage); // Check package item with given name already exists. if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(SharePointSiteCollection)) != null) { return(BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_EXISTS); } // Log operation. TaskManager.StartTask("HOSTEDSHAREPOINT", "ADD_SITE_COLLECTION", item.Name); try { // Create site collection on server. HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(serviceId); hostedSharePointServer.CreateSiteCollection(item); // Make record in metabase. item.ServiceId = serviceId; int itemId = PackageController.AddPackageItem(item); int dnsServiceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Dns); if (dnsServiceId > 0) { DomainInfo domain = ServerController.GetDomain(domainName); if (domain != null) { string website = domain.WebSiteName; if (!String.IsNullOrEmpty(domain.WebSiteName)) { DnsRecord[] records = ServerController.GetDnsZoneRecords(domain.DomainId); foreach (DnsRecord record in records) { if (record.RecordType.Equals(DnsRecordType.A) && String.IsNullOrEmpty(record.RecordName)) { ServerController.DeleteDnsZoneRecord(domain.DomainId, String.Empty, DnsRecordType.A, record.RecordData); break; } } } ServerController.AddDnsZoneRecord(domain.DomainId, String.Empty, DnsRecordType.A, hostedSharePointSettings["RootWebApplicationIpAddress"], 0); } } TaskManager.ItemId = itemId; return(itemId); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
/// <summary> /// Deletes SharePoint site collection with given id. /// </summary> /// <param name="itemId">Site collection id within metabase.</param> /// <returns>?</returns> public static int DeleteSiteCollection(int itemId) { // Check account. int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return(accountCheck); } // Load original meta item SharePointSiteCollection origItem = (SharePointSiteCollection)PackageController.GetPackageItem(itemId); if (origItem == null) { return(BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_NOT_FOUND); } // Get service settings. StringDictionary hostedSharePointSettings = ServerController.GetServiceSettings(origItem.ServiceId); Uri rootWebApplicationUri = new Uri(hostedSharePointSettings["RootWebApplicationUri"]); string domainName = origItem.Name.Replace(String.Format("{0}://", rootWebApplicationUri.Scheme), String.Empty); // Log operation. TaskManager.StartTask("HOSTEDSHAREPOINT", "DELETE_SITE", origItem.Name); TaskManager.ItemId = itemId; try { // Delete site collection on server. HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(origItem.ServiceId); hostedSharePointServer.DeleteSiteCollection(origItem.Url); // Delete record in metabase. PackageController.DeletePackageItem(origItem.Id); int dnsServiceId = PackageController.GetPackageServiceId(origItem.PackageId, ResourceGroups.Dns); if (dnsServiceId > 0) { DomainInfo domain = ServerController.GetDomain(domainName); if (domain != null) { ServerController.DeleteDnsZoneRecord(domain.DomainId, String.Empty, DnsRecordType.A, hostedSharePointSettings["RootWebApplicationIpAddress"]); ServerController.DeleteDnsZoneRecord(domain.DomainId, "www", DnsRecordType.A, hostedSharePointSettings["RootWebApplicationIpAddress"]); if (!String.IsNullOrEmpty(domain.WebSiteName)) { DnsRecord[] records = ServerController.GetDnsZoneRecords(domain.DomainId); foreach (DnsRecord record in records) { if (record.RecordType.Equals(DnsRecordType.A) && record.RecordName.Equals("www", StringComparison.CurrentCultureIgnoreCase)) { ServerController.AddDnsZoneRecord(domain.DomainId, String.Empty, DnsRecordType.A, record.RecordData, 0); break; } } } } } return(0); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
public int AddDnsZoneRecord(int domainId, string recordName, DnsRecordType recordType, string recordData, int mxPriority) { return(ServerController.AddDnsZoneRecord(domainId, recordName, recordType, recordData, mxPriority)); }