public static ResultObject DeleteOrganization(int itemId)
        {
            ResultObject result = new ResultObject();

            result.IsSuccess = true;

            try
            {
                // initialize task manager
                TaskManager.StartTask(TaskManagerSource, "DELETE_ORGANIZATION");
                TaskManager.WriteParameter("itemId", itemId);

                // load organization item
                ExchangeOrganization item = PackageController.GetPackageItem(itemId) as ExchangeOrganization;
                if (item == null)
                {
                    return(Error <ResultObject>(OrganizationNotFoundError));
                }

                #region Check Space and Account
                // Check account
                int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
                if (accountCheck < 0)
                {
                    return(Warning <ResultObject>((-accountCheck).ToString()));
                }

                // Check space
                int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive);
                if (packageCheck < 0)
                {
                    return(Warning <ResultObject>((-packageCheck).ToString()));
                }
                #endregion

                // get Exchange service
                ExchangeServerHostedEdition exchange = GetExchangeService(item.ServiceId);

                // delete organization
                exchange.DeleteOrganization(item.Name);

                // delete meta-item
                PackageController.DeletePackageItem(itemId);

                return(result);
            }
            catch (Exception ex)
            {
                // log error
                TaskManager.WriteError(ex);

                // exit with error code
                return(Error <ResultObject>(DeleteOrganizationError, ex.Message));
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static int DeleteSqlDatabase(int itemId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original meta item
            SqlDatabase origItem = (SqlDatabase)PackageController.GetPackageItem(itemId);

            if (origItem == null)
            {
                return(BusinessErrorCodes.ERROR_MSSQL_DATABASES_PACKAGE_ITEM_NOT_FOUND);
            }

            // place log record
            TaskManager.StartTask("SQL_DATABASE", "DELETE", origItem.Name);
            TaskManager.ItemId = itemId;
            TaskManager.WriteParameter("Provider", origItem.GroupName);

            try
            {
                // get service
                DatabaseServer sql = GetDatabaseServer(origItem.ServiceId);

                // delete service item
                sql.DeleteDatabase(origItem.Name);

                // delete meta item
                PackageController.DeletePackageItem(origItem.Id);

                return(0);
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex);
                // Return a generic error instead of re-throwing an exception
                return(BusinessErrorCodes.FAILED_EXECUTE_SERVICE_OPERATION);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Beispiel #3
0
        public static int DeleteSite(int itemId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }


            // load original meta item
            StatsSite origItem = (StatsSite)PackageController.GetPackageItem(itemId);

            if (origItem == null)
            {
                return(BusinessErrorCodes.ERROR_STATS_PACKAGE_ITEM_NOT_FOUND);
            }

            // place log record
            TaskManager.StartTask("STATS_SITE", "DELETE", origItem.Name);
            TaskManager.ItemId = origItem.Id;

            try
            {
                // get service
                StatisticsServer stats = new StatisticsServer();
                ServiceProviderProxy.Init(stats, origItem.ServiceId);

                // delete service item
                stats.DeleteSite(origItem.SiteId);

                // delete meta item
                PackageController.DeletePackageItem(origItem.Id);

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Beispiel #4
0
        public static int DeleteFtpAccount(int itemId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original meta item
            FtpAccount origItem = (FtpAccount)PackageController.GetPackageItem(itemId);

            if (origItem == null)
            {
                return(BusinessErrorCodes.ERROR_FTP_PACKAGE_ITEM_NOT_FOUND);
            }

            // place log record
            TaskManager.StartTask("FTP_ACCOUNT", "DELETE", origItem.Name);
            TaskManager.ItemId = itemId;

            try
            {
                // get service
                FTPServer ftp = new FTPServer();
                ServiceProviderProxy.Init(ftp, origItem.ServiceId);

                // delete service item
                ftp.DeleteAccount(origItem.Name);

                // delete meta item
                PackageController.DeletePackageItem(origItem.Id);

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Beispiel #5
0
        public static int DeleteOdbcSource(int itemId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original meta item
            SystemDSN origItem = (SystemDSN)PackageController.GetPackageItem(itemId);

            if (origItem == null)
            {
                return(BusinessErrorCodes.ERROR_OS_DSN_PACKAGE_ITEM_NOT_FOUND);
            }

            // place log record
            TaskManager.StartTask("ODBC_DSN", "DELETE", origItem.Name);
            TaskManager.ItemId = itemId;

            try
            {
                // get service
                OS.OperatingSystem os = GetOS(origItem.ServiceId);

                // delete service item
                os.DeleteDSN(origItem.Name);

                // delete meta item
                PackageController.DeletePackageItem(origItem.Id);

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Beispiel #6
0
        public static int DeleteSharePointUser(int itemId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original meta item
            SystemUser origItem = (SystemUser)PackageController.GetPackageItem(itemId);

            if (origItem == null)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_USERS_PACKAGE_ITEM_NOT_FOUND);
            }

            // place log record
            TaskManager.StartTask("SHAREPOINT", "DELETE_USER", origItem.Name);
            TaskManager.ItemId = itemId;

            try
            {
                // get service
                SharePointServer sps = GetSharePoint(origItem.ServiceId);

                // delete service item
                sps.DeleteUser(origItem.Name);

                // delete meta item
                PackageController.DeletePackageItem(origItem.Id);

                return(0);
            }
            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
            SharePointEnterpriseSiteCollection origItem = (SharePointEnterpriseSiteCollection)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 siteName = origItem.Name.Replace(String.Format("{0}://", rootWebApplicationUri.Scheme), String.Empty);

            // Log operation.
            TaskManager.StartTask("HOSTED_SHAREPOINT_ENTERPRISE", "DELETE_SITE", origItem.Name, itemId);

            try
            {
                // Delete site collection on server.
                HostedSharePointServerEnt hostedSharePointServer = GetHostedSharePointServer(origItem.ServiceId);
                hostedSharePointServer.Enterprise_DeleteSiteCollection(origItem);
                // Delete record in metabase.
                PackageController.DeletePackageItem(origItem.Id);

                int dnsServiceId = PackageController.GetPackageServiceId(origItem.PackageId, ResourceGroups.Dns);
                if (dnsServiceId > 0)
                {
                    string[] tmpStr     = siteName.Split('.');
                    string   hostName   = tmpStr[0];
                    string   domainName = siteName.Substring(hostName.Length + 1, siteName.Length - (hostName.Length + 1));

                    List <GlobalDnsRecord> dnsRecords      = ServerController.GetDnsRecordsByService(origItem.ServiceId);
                    List <DnsRecord>       resourceRecords = DnsServerController.BuildDnsResourceRecords(dnsRecords, hostName, domainName, "");
                    DNSServer dns = new DNSServer();

                    ServiceProviderProxy.Init(dns, dnsServiceId);
                    // add new resource records
                    dns.DeleteZoneRecords(domainName, resourceRecords.ToArray());
                }

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static int DeleteZone(int zoneItemId)
        {
            // delete DNS zone if applicable
            DnsZone zoneItem = (DnsZone)PackageController.GetPackageItem(zoneItemId);

            //
            if (zoneItem != null)
            {
                TaskManager.StartTask("DNS_ZONE", "DELETE", zoneItem.Name, zoneItemId);
                //
                try
                {
                    // delete DNS zone
                    DNSServer dns = new DNSServer();
                    ServiceProviderProxy.Init(dns, zoneItem.ServiceId);

                    // delete secondary zones
                    StringDictionary primSettings         = ServerController.GetServiceSettings(zoneItem.ServiceId);
                    string           strSecondaryServices = primSettings["SecondaryDNSServices"];
                    if (!String.IsNullOrEmpty(strSecondaryServices))
                    {
                        string[] secondaryServices = strSecondaryServices.Split(',');
                        foreach (string strSecondaryId in secondaryServices)
                        {
                            try
                            {
                                int secondaryId = Utils.ParseInt(strSecondaryId, 0);
                                if (secondaryId == 0)
                                {
                                    continue;
                                }

                                DNSServer secDns = new DNSServer();
                                ServiceProviderProxy.Init(secDns, secondaryId);

                                secDns.DeleteZone(zoneItem.Name);
                            }
                            catch (Exception ex1)
                            {
                                // problem when deleting secondary zone
                                TaskManager.WriteError(ex1, "Error deleting secondary DNS zone");
                            }
                        }
                    }

                    try
                    {
                        dns.DeleteZone(zoneItem.Name);
                    }
                    catch (Exception ex2)
                    {
                        TaskManager.WriteError(ex2, "Error deleting primary DNS zone");
                    }

                    // delete service item
                    PackageController.DeletePackageItem(zoneItemId);

                    // Delete also all seconday service items
                    var zoneItems = PackageController.GetPackageItemsByType(zoneItem.PackageId, ResourceGroups.Dns, typeof(SecondaryDnsZone));

                    foreach (var item in zoneItems.Where(z => z.Name == zoneItem.Name))
                    {
                        PackageController.DeletePackageItem(item.Id);
                    }
                }
                catch (Exception ex)
                {
                    TaskManager.WriteError(ex);
                }
                finally
                {
                    TaskManager.CompleteTask();
                }
            }
            //
            return(0);
        }
Beispiel #9
0
        public static int DeleteSite(int itemId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original meta item
            SharePointSite origItem = (SharePointSite)PackageController.GetPackageItem(itemId);

            if (origItem == null)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_NOT_FOUND);
            }

            // place log record
            TaskManager.StartTask("SHAREPOINT", "DELETE_SITE", origItem.Name);
            TaskManager.ItemId = itemId;

            try
            {
                // get service
                SharePointServer sps = GetSharePoint(origItem.ServiceId);

                // delete service item
                sps.UnextendVirtualServer(origItem.Name, true);

                try
                {
                    // delete database
                    ServiceProviderItem dbItem = PackageController.GetPackageItemByName(origItem.PackageId, origItem.DatabaseGroupName,
                                                                                        origItem.DatabaseName, typeof(SqlDatabase));
                    if (dbItem != null)
                    {
                        DatabaseServerController.DeleteSqlDatabase(dbItem.Id);
                    }

                    // delete database user
                    dbItem = PackageController.GetPackageItemByName(origItem.PackageId, origItem.DatabaseGroupName,
                                                                    origItem.DatabaseUser, typeof(SqlUser));
                    if (dbItem != null)
                    {
                        DatabaseServerController.DeleteSqlUser(dbItem.Id);
                    }
                }
                catch (Exception ex2)
                {
                    TaskManager.WriteError(ex2);
                }

                // delete meta item
                PackageController.DeletePackageItem(origItem.Id);

                try
                {
                    // start web site
                    WebSite site = WebServerController.GetWebSite(origItem.PackageId, origItem.Name);
                    if (site != null)
                    {
                        WebServerController.ChangeSiteState(site.Id, ServerState.Started);
                    }
                }
                catch (Exception ex)
                {
                    TaskManager.WriteError(ex);
                }

                return(0);
            }
            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();
            }
        }