Exemple #1
0
        public void CalculatePackage(int packageId)
        {
            DateTime since      = PackageController.GetPackageBandwidthUpdate(packageId);
            DateTime nextUpdate = DateTime.Now;

            try
            {
                // get all package items
                List <ServiceProviderItem> items = PackageController.GetServiceItemsForStatistics(
                    0, packageId, false, true, false, false);

                // order items by service
                Dictionary <int, List <ServiceProviderItem> > orderedItems =
                    PackageController.OrderServiceItemsByServices(items);

                // calculate statistics for each service set
                List <ServiceProviderItemBandwidth> itemsBandwidth = new List <ServiceProviderItemBandwidth>();
                foreach (int serviceId in orderedItems.Keys)
                {
                    ServiceProviderItemBandwidth[] serviceBandwidth = CalculateItems(serviceId,
                                                                                     orderedItems[serviceId], since);
                    if (serviceBandwidth != null)
                    {
                        itemsBandwidth.AddRange(serviceBandwidth);
                    }
                }

                // update info in the database
                string xml = BuildDiskBandwidthStatisticsXml(itemsBandwidth.ToArray());
                PackageController.UpdatePackageBandwidth(packageId, xml);

                // if everything is OK
                // update date
                PackageController.UpdatePackageBandwidthUpdate(packageId, nextUpdate);

                // suspend package if requested
                if (suspendOverused)
                {
                    // disk space
                    QuotaValueInfo dsQuota = PackageController.GetPackageQuota(packageId, Quotas.OS_BANDWIDTH);

                    if (dsQuota.QuotaExhausted)
                    {
                        PackageController.ChangePackageStatus(null, packageId, PackageStatus.Suspended, false);
                    }
                }
            }
            catch (Exception ex)
            {
                // load package details
                PackageInfo package = PackageController.GetPackage(packageId);

                // load user details
                UserInfo user = PackageController.GetPackageOwner(package.PackageId);

                // log error
                TaskManager.WriteError(String.Format("Error calculating bandwidth for '{0}' space of user '{1}': {2}",
                                                     package.PackageName, user.Username, ex.ToString()));
            }
        }
        public void CalculatePackage(int packageId)
        {
            try
            {
                // get all package items
                List <ServiceProviderItem> items = PackageController.GetServiceItemsForStatistics(
                    0, packageId, true, false, false, false);

                //TaskManager.Write("Items: " + items.Count);

                // order items by service
                Dictionary <int, List <ServiceProviderItem> > orderedItems =
                    PackageController.OrderServiceItemsByServices(items);

                // calculate statistics for each service set
                List <ServiceProviderItemDiskSpace> itemsDiskspace = new List <ServiceProviderItemDiskSpace>();
                foreach (int serviceId in orderedItems.Keys)
                {
                    ServiceProviderItemDiskSpace[] serviceDiskspace = CalculateItems(serviceId, orderedItems[serviceId]);
                    if (serviceDiskspace != null)
                    {
                        itemsDiskspace.AddRange(serviceDiskspace);
                    }
                }

                // update info in the database
                string xml = BuildDiskSpaceStatisticsXml(itemsDiskspace.ToArray());
                PackageController.UpdatePackageDiskSpace(packageId, xml);
                //TaskManager.Write("XML: " + xml);

                // suspend package if requested
                if (suspendOverused)
                {
                    // disk space
                    QuotaValueInfo dsQuota = PackageController.GetPackageQuota(packageId, Quotas.OS_DISKSPACE);

                    if (dsQuota.QuotaExhausted)
                    {
                        PackageController.ChangePackageStatus(null, packageId, PackageStatus.Suspended, false);
                    }
                }
            }
            catch (Exception ex)
            {
                // load package details
                PackageInfo package = PackageController.GetPackage(packageId);

                // load user details
                UserInfo user = PackageController.GetPackageOwner(package.PackageId);

                // log error
                TaskManager.WriteError(String.Format("Error calculating diskspace for '{0}' space of user '{1}': {2}",
                                                     package.PackageName, user.Username, ex.ToString()));
            }
        }
        public static long GetFsrmQuotaInBytes(QuotaValueInfo quotaInfo)
        {
            if (quotaInfo.QuotaAllocatedValue == -1)
            {
                return -1;
            }

            if (quotaInfo.QuotaDescription.ToLower().Contains("gb"))
            {
                return quotaInfo.QuotaAllocatedValue*1024*1024*1024;
            }

            if (quotaInfo.QuotaDescription.ToLower().Contains("mb"))
            {
                return quotaInfo.QuotaAllocatedValue * 1024 * 1024;
            }

            return quotaInfo.QuotaAllocatedValue * 1024 ;
        }
Exemple #4
0
        public static long GetFsrmQuotaInBytes(QuotaValueInfo quotaInfo)
        {
            if (quotaInfo.QuotaAllocatedValue == -1)
            {
                return(-1);
            }

            if (quotaInfo.QuotaDescription.ToLower().Contains("gb"))
            {
                return(quotaInfo.QuotaAllocatedValue * 1024 * 1024 * 1024);
            }

            if (quotaInfo.QuotaDescription.ToLower().Contains("mb"))
            {
                return(quotaInfo.QuotaAllocatedValue * 1024 * 1024);
            }

            return(quotaInfo.QuotaAllocatedValue * 1024);
        }
Exemple #5
0
        public static int SetFolderQuota(int packageId, string path, string driveName, string quotas)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

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

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

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

            // place log record
            TaskManager.StartTask("FILES", "SET_QUOTA_ON_FOLDER", path, packageId);

            try
            {
                // disk space quota
                // This gets all the disk space allocated for a specific customer
                // It includes the package Add Ons * Quatity + Hosting Plan System disk space value. //Quotas.OS_DISKSPACE
                QuotaValueInfo diskSpaceQuota = PackageController.GetPackageQuota(packageId, quotas);


                #region figure Quota Unit

                // Quota Unit
                string unit = String.Empty;
                if (diskSpaceQuota.QuotaDescription.ToLower().Contains("gb"))
                {
                    unit = "GB";
                }
                else if (diskSpaceQuota.QuotaDescription.ToLower().Contains("mb"))
                {
                    unit = "MB";
                }
                else
                {
                    unit = "KB";
                }

                #endregion

                OS.OperatingSystem os = GetOS(packageId);

                os.SetQuotaLimitOnFolder(path, driveName, QuotaType.Hard, diskSpaceQuota.QuotaAllocatedValue.ToString() + unit, 0, String.Empty, String.Empty);

                return(0);
            }
            catch (Exception ex)
            {
                //Log and return a generic error rather than throwing an exception
                TaskManager.WriteError(ex);
                return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #6
0
        public override void DoWork()
        {
            // Input parameters:
            //  - DISKSPACE_OVERUSED
            //  - BANDWIDTH_OVERUSED

            // get the list of all packages
            List <PackageInfo> packages = PackageController.GetPackagePackages(TaskManager.PackageId, false);

            TaskManager.Write("Packages to verify: " + packages.Count.ToString());

            bool checkDiskspace = (String.Compare((string)TaskManager.TaskParameters["DISKSPACE_OVERUSED"], "true", true) == 0);
            bool checkBandwidth = (String.Compare((string)TaskManager.TaskParameters["BANDWIDTH_OVERUSED"], "true", true) == 0);

            bool suspendOverused = Convert.ToBoolean(TaskManager.TaskParameters["SUSPEND_OVERUSED"]);

            bool   sendWarningEmail         = Convert.ToBoolean(TaskManager.TaskParameters["SEND_WARNING_EMAIL"]);
            bool   sendSuspensionEmail      = Convert.ToBoolean(TaskManager.TaskParameters["SEND_SUSPENSION_EMAIL"]);
            int    warningUsageThreshold    = Convert.ToInt32(TaskManager.TaskParameters["WARNING_USAGE_THRESHOLD"]);
            int    suspensionUsageThreshold = Convert.ToInt32(TaskManager.TaskParameters["SUSPENSION_USAGE_THRESHOLD"]);
            string warningMailFrom          = Convert.ToString(TaskManager.TaskParameters["WARNING_MAIL_FROM"]);
            string warningMailBcc           = Convert.ToString(TaskManager.TaskParameters["WARNING_MAIL_BCC"]);
            string warningMailSubject       = Convert.ToString(TaskManager.TaskParameters["WARNING_MAIL_SUBJECT"]);
            string warningMailBody          = Convert.ToString(TaskManager.TaskParameters["WARNING_MAIL_BODY"]);
            string suspensionMailFrom       = Convert.ToString(TaskManager.TaskParameters["SUSPENSION_MAIL_FROM"]);
            string suspensionMailBcc        = Convert.ToString(TaskManager.TaskParameters["SUSPENSION_MAIL_BCC"]);
            string suspensionMailSubject    = Convert.ToString(TaskManager.TaskParameters["SUSPENSION_MAIL_SUBJECT"]);
            string suspensionMailBody       = Convert.ToString(TaskManager.TaskParameters["SUSPENSION_MAIL_BODY"]);

            int suspendedPackages = 0;

            foreach (PackageInfo package in packages)
            {
                bool isBandwidthBelowWarningThreshold    = true;
                bool isBandwidthBelowSuspensionThreshold = true;
                bool isDiskSpaceBelowWarningThreshold    = true;
                bool isDiskSpaceBelowSuspensionThreshold = true;

                UserInfo userInfo = UserController.GetUser(package.UserId);

                int diskSpaceUsage = 0;
                int bandwidthUsage = 0;
                // disk space
                if (checkDiskspace)
                {
                    QuotaValueInfo dsQuota = PackageController.GetPackageQuota(package.PackageId, Quotas.OS_DISKSPACE);
                    if (dsQuota.QuotaAllocatedValue > 0)
                    {
                        diskSpaceUsage = (dsQuota.QuotaUsedValue * 100 / dsQuota.QuotaAllocatedValue);
                        isDiskSpaceBelowWarningThreshold    = diskSpaceUsage < warningUsageThreshold;
                        isDiskSpaceBelowSuspensionThreshold = diskSpaceUsage < suspensionUsageThreshold;
                    }
                }

                // bandwidth
                if (checkBandwidth)
                {
                    QuotaValueInfo bwQuota = PackageController.GetPackageQuota(package.PackageId, Quotas.OS_BANDWIDTH);
                    if (bwQuota.QuotaAllocatedValue > 0)
                    {
                        bandwidthUsage = (bwQuota.QuotaUsedValue * 100 / bwQuota.QuotaAllocatedValue);
                        isBandwidthBelowWarningThreshold    = bandwidthUsage < warningUsageThreshold;
                        isBandwidthBelowSuspensionThreshold = bandwidthUsage < suspensionUsageThreshold;
                    }
                }

                string userName = String.Format("{0} {1} ({2})/{3}", userInfo.FirstName, userInfo.LastName, userInfo.Username, userInfo.Email);
                //
                List <string> formatItems = new List <string>();
                // add diskspace usage if enabled
                if (checkDiskspace)
                {
                    formatItems.Add(String.Format(DISKSPACE_FORMAT_STRING, diskSpaceUsage));
                }
                // add bandwidth usage if enabled
                if (checkBandwidth)
                {
                    formatItems.Add(String.Format(BANDWIDTH_FORMAT_STRING, bandwidthUsage));
                }
                // build usage string
                string usage = String.Join(", ", formatItems.ToArray());

                // cleanup items
                formatItems.Clear();
                // add diskspace warning max usage
                if (checkDiskspace)
                {
                    formatItems.Add(String.Format(DISKSPACE_FORMAT_STRING, warningUsageThreshold));
                }
                // add bandwidth warning max usage
                if (checkBandwidth)
                {
                    formatItems.Add(String.Format(BANDWIDTH_FORMAT_STRING, warningUsageThreshold));
                }
                // build warning max usage string
                string warningMaxUsage = String.Join(", ", formatItems.ToArray());

                // cleanup items
                formatItems.Clear();
                // add diskspace suspension max usage
                if (checkDiskspace)
                {
                    formatItems.Add(String.Format(DISKSPACE_FORMAT_STRING, suspensionUsageThreshold));
                }
                // add bandwidth suspension max usage
                if (checkBandwidth)
                {
                    formatItems.Add(String.Format(BANDWIDTH_FORMAT_STRING, suspensionUsageThreshold));
                }
                // build suspension max usage string
                string suspensionMaxUsage = String.Join(", ", formatItems.ToArray());

                string warningMailSubjectProcessed = ReplaceVariables(warningMailSubject, warningMaxUsage, usage, package.PackageName, userName);
                string warningMailBodyProcessed    = ReplaceVariables(warningMailBody, warningMaxUsage, usage, package.PackageName, userName);

                string suspensionMailSubjectProcessed = ReplaceVariables(suspensionMailSubject, suspensionMaxUsage, usage, package.PackageName, userName);
                string suspensionMailBodyProcessed    = ReplaceVariables(suspensionMailBody, suspensionMaxUsage, usage, package.PackageName, userName);


                // Send email notifications
                if (sendWarningEmail && (!isDiskSpaceBelowWarningThreshold || !isBandwidthBelowWarningThreshold))
                {
                    // Send warning email.
                    this.SendEmail(warningMailFrom, userInfo.Email, warningMailBcc, warningMailSubjectProcessed, warningMailBodyProcessed, false);
                }

                if (sendSuspensionEmail && (!isDiskSpaceBelowSuspensionThreshold || !isBandwidthBelowSuspensionThreshold))
                {
                    // Send suspension email.
                    this.SendEmail(suspensionMailFrom, userInfo.Email, suspensionMailBcc, suspensionMailSubjectProcessed, suspensionMailBodyProcessed, false);
                }

                // suspend package if required
                if (suspendOverused && (!isDiskSpaceBelowSuspensionThreshold || !isBandwidthBelowSuspensionThreshold))
                {
                    suspendedPackages++;

                    // load user details
                    UserInfo user = PackageController.GetPackageOwner(package.PackageId);

                    TaskManager.Write(String.Format("Suspend space '{0}' of user '{1}'",
                                                    package.PackageName, user.Username));

                    try
                    {
                        PackageController.ChangePackageStatus(null, package.PackageId, PackageStatus.Suspended, false);
                    }
                    catch (Exception ex)
                    {
                        TaskManager.WriteError("Error while changing space status: " + ex.ToString());
                    }
                }
            }

            // log results
            TaskManager.Write("Total packages suspended: " + suspendedPackages.ToString());
        }
Exemple #7
0
        public static int AddFtpAccount(FtpAccount item)
        {
            // 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
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.FTP_ACCOUNTS);

            if (quota.QuotaExhausted)
            {
                return(BusinessErrorCodes.ERROR_FTP_RESOURCE_QUOTA_LIMIT);
            }

            // check if FTP account already exists
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Ftp);

            if (serviceId == 0)
            {
                return(BusinessErrorCodes.ERROR_FTP_RESOURCE_UNAVAILABLE);
            }

            // place log record
            TaskManager.StartTask("FTP_ACCOUNT", "ADD", item.Name);
            TaskManager.WriteParameter("Folder", item.Folder);
            TaskManager.WriteParameter("CanRead", item.CanRead);
            TaskManager.WriteParameter("CanWrite", item.CanWrite);


            try
            {
                // check package items
                if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(FtpAccount)) != null)
                {
                    return(BusinessErrorCodes.ERROR_FTP_PACKAGE_ITEM_EXISTS);
                }

                // check service items
                FTPServer ftp = new FTPServer();
                ServiceProviderProxy.Init(ftp, serviceId);
                if (ftp.AccountExists(item.Name))
                {
                    return(BusinessErrorCodes.ERROR_FTP_SERVICE_ITEM_EXISTS);
                }

                // store original path
                string origFolder = item.Folder;

                // convert folder
                StringDictionary ftpSettings = ServerController.GetServiceSettings(serviceId);
                if (Utils.ParseBool(ftpSettings["BuildUncFilesPath"], false))
                {
                    // UNC
                    // get OS service
                    int osServiceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Os);
                    item.Folder = FilesController.GetFullUncPackagePath(item.PackageId, osServiceId, item.Folder);
                }
                else
                {
                    // Absolute
                    item.Folder = FilesController.GetFullPackagePath(item.PackageId, item.Folder);
                }

                item.Enabled = true;

                // add service item
                ftp.CreateAccount(item);

                // save item
                item.Password  = CryptoUtils.Encrypt(item.Password);
                item.ServiceId = serviceId;
                item.Folder    = (origFolder == "") ? "\\" : origFolder;
                int itemId = PackageController.AddPackageItem(item);
                TaskManager.ItemId = itemId;
                return(itemId);
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex);
                throw;
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        private bool CheckServiceLevelQuota(QuotaValueInfo quota)
        {

            if (quota.QuotaAllocatedValue != -1)
            {
                return quota.QuotaAllocatedValue > quota.QuotaUsedValue;
            }

            return true;
        }
        public static HostingPlanContext GetHostingPlanContext(int planId)
        {
            HostingPlanContext context = new HostingPlanContext();

            // load hosting plan
            context.HostingPlan = GetHostingPlan(planId);
            if (context.HostingPlan == null)
                return null;

            // load groups and quotas
            DataSet ds = GetHostingPlanQuotas(0, planId, 0);

            List<HostingPlanGroupInfo> groups = new List<HostingPlanGroupInfo>();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                HostingPlanGroupInfo group = new HostingPlanGroupInfo();
                group.GroupId = (int)dr["GroupID"];
                group.GroupName = (string)dr["GroupName"];

                bool enabled = (bool)dr["Enabled"];
                group.Enabled = enabled;
                group.CalculateBandwidth = (bool)dr["CalculateBandwidth"];
                group.CalculateDiskSpace = (bool)dr["CalculateDiskSpace"];

                if (enabled)
                {
                    groups.Add(group);
                    context.Groups.Add(group.GroupName, group);
                }
            }

            List<QuotaValueInfo> quotas = new List<QuotaValueInfo>();
            foreach (DataRow dr in ds.Tables[1].Rows)
            {
                QuotaValueInfo quota = new QuotaValueInfo();
                quota.QuotaId = (int)dr["QuotaId"];
                quota.GroupId = (int)dr["GroupId"];
                quota.QuotaName = (string)dr["QuotaName"];
                quota.QuotaTypeId = (int)dr["QuotaTypeId"];
                quota.QuotaAllocatedValue = (int)dr["QuotaValue"];
                quotas.Add(quota);
                context.Quotas.Add(quota.QuotaName, quota);
            }

            context.GroupsArray = groups.ToArray();
            context.QuotasArray = quotas.ToArray();

            return context;
        }
        public static int AddSqlUser(SqlUser item, string groupName)
        {
            // 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
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, groupName + ".Users");

            if (quota.QuotaExhausted)
            {
                return(BusinessErrorCodes.ERROR_MSSQL_USERS_RESOURCE_QUOTA_LIMIT);
            }

            // check if mail resource is available
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, groupName);

            if (serviceId == 0)
            {
                return(BusinessErrorCodes.ERROR_MSSQL_RESOURCE_UNAVAILABLE);
            }

            // check package items
            if (PackageController.GetPackageItemByName(item.PackageId, groupName, item.Name, typeof(SqlUser)) != null)
            {
                return(BusinessErrorCodes.ERROR_MSSQL_USERS_PACKAGE_ITEM_EXISTS);
            }

            // place log record
            TaskManager.StartTask("SQL_USER", "ADD", item.Name);
            TaskManager.WriteParameter("Provider", groupName);

            int itemId = default(int);

            try
            {
                // check service items
                DatabaseServer sql = GetDatabaseServer(serviceId);
                if (sql.UserExists(item.Name))
                {
                    return(BusinessErrorCodes.ERROR_MSSQL_USERS_SERVICE_ITEM_EXISTS);
                }

                // add service item
                sql.CreateUser(item, item.Password);

                // save item
                item.Password  = CryptoUtils.Encrypt(item.Password);
                item.ServiceId = serviceId;
                itemId         = PackageController.AddPackageItem(item);

                TaskManager.ItemId = itemId;
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex);
                //
                if (ex.Message.Contains("INVALID_USERNAME"))
                {
                    return(BusinessErrorCodes.ERROR_MYSQL_INVALID_USER_NAME);
                }
                // Return a generic error instead of default(int)
                itemId = BusinessErrorCodes.FAILED_EXECUTE_SERVICE_OPERATION;
            }
            finally
            {
                TaskManager.CompleteTask();
            }
            return(itemId);
        }
        public static int AddSqlDatabase(SqlDatabase item, string groupName)
        {
            // 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
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, groupName + ".Databases");

            if (quota.QuotaExhausted)
            {
                return(BusinessErrorCodes.ERROR_MSSQL_DATABASES_RESOURCE_QUOTA_LIMIT);
            }

            // check if mail resource is available
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, groupName);

            if (serviceId == 0)
            {
                return(BusinessErrorCodes.ERROR_MSSQL_RESOURCE_UNAVAILABLE);
            }

            // check package items
            if (PackageController.GetPackageItemByName(item.PackageId, groupName, item.Name, typeof(SqlDatabase)) != null)
            {
                return(BusinessErrorCodes.ERROR_MSSQL_DATABASES_PACKAGE_ITEM_EXISTS);
            }

            // place log record
            TaskManager.StartTask("SQL_DATABASE", "ADD", item.Name);
            TaskManager.WriteParameter("Provider", groupName);

            int itemId = default(int);

            //
            try
            {
                // check service items
                DatabaseServer sql = GetDatabaseServer(serviceId);
                if (sql.DatabaseExists(item.Name))
                {
                    return(BusinessErrorCodes.ERROR_MSSQL_DATABASES_SERVICE_ITEM_EXISTS);
                }

                // calculate database location
                StringDictionary settings = ServerController.GetServiceSettings(serviceId);
                UserInfo         user     = PackageController.GetPackageOwner(item.PackageId);
                if (settings["UseDefaultDatabaseLocation"] != null &&
                    !Utils.ParseBool(settings["UseDefaultDatabaseLocation"], false))
                {
                    item.Location = Utils.ReplaceStringVariable(settings["DatabaseLocation"], "user_name", user.Username);
                }

                // set database size
                item.DataSize = GetMaxDatabaseSize(item.PackageId, groupName);


                // set log size
                item.LogSize = GetMaxLogSize(item.PackageId, groupName);

                // add service item
                sql.CreateDatabase(item);

                // save item
                item.ServiceId = serviceId;
                itemId         = PackageController.AddPackageItem(item);

                TaskManager.ItemId = itemId;
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex);
                //
                if (ex.Message.Contains("INVALID_DATABASE_NAME"))
                {
                    return(BusinessErrorCodes.ERROR_MYSQL_INVALID_DATABASE_NAME);
                }
                // Return a generic error instead of default(int)
                itemId = BusinessErrorCodes.FAILED_EXECUTE_SERVICE_OPERATION;
            }
            finally
            {
                TaskManager.CompleteTask();
            }
            return(itemId);
        }
        public static int AddSite(StatsSite item)
        {
            // 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
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.STATS_SITES);

            if (quota.QuotaExhausted)
            {
                return(BusinessErrorCodes.ERROR_STATS_RESOURCE_QUOTA_LIMIT);
            }

            // check if stats resource is available
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Statistics);

            if (serviceId == 0)
            {
                return(BusinessErrorCodes.ERROR_STATS_RESOURCE_UNAVAILABLE);
            }

            // check package items
            if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(StatsSite)) != null)
            {
                return(BusinessErrorCodes.ERROR_STATS_PACKAGE_ITEM_EXISTS);
            }

            // place log record
            TaskManager.StartTask("STATS_SITE", "ADD", item.Name);

            try
            {
                // load web site
                WebSite siteItem = (WebSite)PackageController.GetPackageItemByName(item.PackageId,
                                                                                   item.Name, typeof(WebSite));

                if (siteItem == null)
                {
                    return(BusinessErrorCodes.ERROR_WEB_SITE_SERVICE_UNAVAILABLE);
                }

                // get service web site
                WebServer web = new WebServer();
                ServiceProviderProxy.Init(web, siteItem.ServiceId);
                WebSite site = web.GetSite(siteItem.SiteId);

                List <DomainInfo> pointers = WebServerController.GetWebSitePointers(siteItem.Id);
                List <string>     aliases  = new List <string>();

                foreach (DomainInfo pointer in pointers)
                {
                    aliases.Add(pointer.DomainName);
                }

                StatisticsServer stats = new StatisticsServer();
                ServiceProviderProxy.Init(stats, serviceId);
                string siteNumber       = (site.IIs7) ? site[WebSite.IIS7_SITE_ID] : siteItem.SiteId.Replace("/", "");
                string logsCommonFolder = site.LogsPath;
                string logsFolder       = Path.Combine(logsCommonFolder, siteNumber);

                // get service settings
                StringDictionary settings = ServerController.GetServiceSettings(serviceId);
                if (Utils.ParseBool(settings["BuildUncLogsPath"], false))
                {
                    logsFolder = FilesController.ConvertToUncPath(siteItem.ServiceId, logsFolder);
                }

                item.LogDirectory  = logsFolder;
                item.DomainAliases = aliases.ToArray();

                // install statistics
                item.SiteId = stats.AddSite(item);

                // save statistics item
                item.ServiceId = serviceId;
                int itemId = PackageController.AddPackageItem(item);

                TaskManager.ItemId = itemId;

                return(itemId);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #13
0
        public static int AddSharePointGroup(SystemGroup item)
        {
            // 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
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.SHAREPOINT_GROUPS);

            if (quota.QuotaExhausted)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_GROUPS_RESOURCE_QUOTA_LIMIT);
            }

            // check if mail resource is available
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.SharePoint);

            if (serviceId == 0)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_UNAVAILABLE);
            }

            // check package items
            if (PackageController.GetPackageItemByName(item.PackageId, ResourceGroups.SharePoint, item.Name, typeof(SystemGroup)) != null)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_GROUPS_PACKAGE_ITEM_EXISTS);
            }

            // place log record
            TaskManager.StartTask("SHAREPOINT", "ADD_GROUP", item.Name);

            try
            {
                // check service items
                SharePointServer sps = GetSharePoint(serviceId);
                if (sps.GroupExists(item.Name))
                {
                    return(BusinessErrorCodes.ERROR_SHAREPOINT_GROUPS_SERVICE_ITEM_EXISTS);
                }

                item.Description = "WebsitePanel System Group";

                // add service item
                sps.CreateGroup(item);

                // save item
                item.ServiceId = serviceId;
                int itemId = PackageController.AddPackageItem(item);

                TaskManager.ItemId = itemId;

                return(itemId);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #14
0
        public static int AddSite(SharePointSite item)
        {
            // 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
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.SHAREPOINT_SITES);

            if (quota.QuotaExhausted)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_QUOTA_LIMIT);
            }

            // check if stats resource is available
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.SharePoint);

            if (serviceId == 0)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_UNAVAILABLE);
            }

            // check package items
            if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(SharePointSite)) != null)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_EXISTS);
            }

            // place log record
            TaskManager.StartTask("SHAREPOINT", "ADD_SITE", item.Name);
            TaskManager.WriteParameter("Database group", item.DatabaseGroupName);
            TaskManager.WriteParameter("Database name", item.DatabaseName);
            TaskManager.WriteParameter("Database user", item.DatabaseUser);

            int databaseItemId     = 0;
            int databaseUserItemId = 0;

            try
            {
                // load web site
                WebSite siteItem = (WebSite)PackageController.GetPackageItemByName(item.PackageId,
                                                                                   item.Name, typeof(WebSite));

                if (siteItem == null)
                {
                    return(BusinessErrorCodes.ERROR_WEB_SITE_SERVICE_UNAVAILABLE);
                }

                // get service web site
                WebServer web = new WebServer();
                ServiceProviderProxy.Init(web, siteItem.ServiceId);
                WebSite site = web.GetSite(siteItem.SiteId);

                /////////////////////////////////////////
                //
                //  PREPARE SHAREPOINT SITE INSTALLATION
                //

                ServiceInfo wssService = ServerController.GetServiceInfo(serviceId);
                bool        wss30      = (wssService.ProviderId == 23);     // WSS 3.0

                // remember original web site bindings
                ServerBinding[] bindings = site.Bindings;

                // set application pool and root folder
                item.ApplicationPool = site.ApplicationPool;
                item.RootFolder      = site.ContentPath;

                // change web site .NET framework if required
                bool siteUpdated = false;
                if (!wss30 && (site.AspNetInstalled != "1" ||
                               site.DedicatedApplicationPool))
                {
                    site.AspNetInstalled          = "1";
                    site.DedicatedApplicationPool = false;
                    web.UpdateSite(site);

                    siteUpdated = true;
                }

                if (wss30 && site.AspNetInstalled != "2")
                {
                    site.AspNetInstalled = "2";
                    web.UpdateSite(site);

                    siteUpdated = true;
                }

                if (siteUpdated)
                {
                    site = web.GetSite(siteItem.SiteId);
                    item.ApplicationPool = site.ApplicationPool;
                }

                if (site.FrontPageInstalled)
                {
                    // remove FrontPage
                    web.UninstallFrontPage(siteItem.SiteId, siteItem.FrontPageAccount);
                }

                // create SQL database
                SqlDatabase database = new SqlDatabase();
                database.PackageId = item.PackageId;
                database.Name      = item.DatabaseName;
                databaseItemId     = DatabaseServerController.AddSqlDatabase(database, item.DatabaseGroupName);
                if (databaseItemId < 0)
                {
                    return(databaseItemId);
                }

                // create SQL user
                SqlUser dbUser = new SqlUser();
                dbUser.PackageId   = item.PackageId;
                dbUser.Name        = item.DatabaseUser;
                dbUser.Password    = item.DatabasePassword;
                databaseUserItemId = DatabaseServerController.AddSqlUser(dbUser, item.DatabaseGroupName);
                if (databaseUserItemId < 0)
                {
                    return(databaseUserItemId);
                }

                // delete SQL database from service
                // and change database user role
                int sqlServiceId = PackageController.GetPackageServiceId(item.PackageId, item.DatabaseGroupName);
                if (sqlServiceId < 0)
                {
                    return(BusinessErrorCodes.ERROR_MSSQL_RESOURCE_UNAVAILABLE);
                }

                // load server settings
                StringDictionary sqlSettings = ServerController.GetServiceSettings(sqlServiceId);
                item.DatabaseServer = sqlSettings["ExternalAddress"];

                DatabaseServer dbServer = new DatabaseServer();
                ServiceProviderProxy.Init(dbServer, sqlServiceId);

                // delete database from service
                dbServer.DeleteDatabase(database.Name);

                // give SQL user "db_creator" role
                dbServer.ExecuteSqlNonQuery("master", String.Format(
                                                "sp_addsrvrolemember '{0}', 'dbcreator'\nGO", dbUser.Name));

                // install SharePoint site
                SharePointServer sps = GetSharePoint(serviceId);
                sps.ExtendVirtualServer(item);

                // remove SQL user from "db_creator" role
                dbServer.ExecuteSqlNonQuery("master", String.Format(
                                                "sp_dropsrvrolemember '{0}', 'dbcreator'\nGO", dbUser.Name));

                // restore original web site bindings
                web.UpdateSiteBindings(site.SiteId, bindings);

                // save statistics item
                item.ServiceId = serviceId;
                int itemId = PackageController.AddPackageItem(item);

                TaskManager.ItemId = itemId;

                return(itemId);
            }
            catch (Exception ex)
            {
                // delete database if required
                if (databaseItemId > 0)
                {
                    DatabaseServerController.DeleteSqlDatabase(databaseItemId);
                }

                // delete user if required
                if (databaseUserItemId > 0)
                {
                    DatabaseServerController.DeleteSqlUser(databaseUserItemId);
                }

                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #15
0
        public static int AddOdbcSource(SystemDSN item)
        {
            // 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
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.OS_ODBC);

            if (quota.QuotaExhausted)
            {
                return(BusinessErrorCodes.ERROR_OS_DSN_RESOURCE_QUOTA_LIMIT);
            }

            // check if mail resource is available
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Os);

            if (serviceId == 0)
            {
                return(BusinessErrorCodes.ERROR_OS_RESOURCE_UNAVAILABLE);
            }

            // check package items
            if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(SystemDSN)) != null)
            {
                return(BusinessErrorCodes.ERROR_OS_DSN_PACKAGE_ITEM_EXISTS);
            }

            // place log record
            TaskManager.StartTask("ODBC_DSN", "ADD", item.Name);

            try
            {
                // check service items
                OS.OperatingSystem os = GetOS(serviceId);
                if (os.GetDSN(item.Name) != null)
                {
                    return(BusinessErrorCodes.ERROR_OS_DSN_SERVICE_ITEM_EXISTS);
                }

                string[] dbNameParts = item.DatabaseName.Split('|');
                string   groupName   = null;
                if (dbNameParts.Length > 1)
                {
                    item.DatabaseName = dbNameParts[0];
                    groupName         = dbNameParts[1];
                }

                // get database server address
                item.DatabaseServer = GetDatabaseServerName(groupName, item.PackageId);

                if (item.Driver == "MsAccess" || item.Driver == "Excel" || item.Driver == "Text")
                {
                    item.DatabaseName = FilesController.GetFullPackagePath(item.PackageId, item.DatabaseName);
                }

                // add service item
                os.CreateDSN(item);

                // save item
                item.DatabasePassword = CryptoUtils.Encrypt(item.DatabasePassword);
                item.ServiceId        = serviceId;
                int itemId = PackageController.AddPackageItem(item);

                TaskManager.ItemId = itemId;

                return(itemId);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static PackageContext GetPackageContext(int packageId)
        {
            PackageContext context = new PackageContext();

            // load package
            context.Package = GetPackage(packageId);
            if (context.Package == null)
                return null;

            // load groups and quotas
            DataSet ds = GetPackageQuotas(packageId);

            List<HostingPlanGroupInfo> groups = new List<HostingPlanGroupInfo>();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                HostingPlanGroupInfo group = new HostingPlanGroupInfo();
                group.GroupId = (int)dr["GroupID"];
                group.GroupName = (string)dr["GroupName"];
                group.Enabled = true;
                group.CalculateBandwidth = (bool)dr["CalculateBandwidth"];
                group.CalculateDiskSpace = (bool)dr["CalculateDiskSpace"];
                groups.Add(group);
                context.Groups.Add(group.GroupName, group);
            }

            List<QuotaValueInfo> quotas = new List<QuotaValueInfo>();
            foreach (DataRow dr in ds.Tables[1].Rows)
            {
                QuotaValueInfo quota = new QuotaValueInfo();
                quota.QuotaId = (int)dr["QuotaId"];
                quota.GroupId = (int)dr["GroupId"];
                quota.QuotaName = (string)dr["QuotaName"];
                quota.QuotaTypeId = (int)dr["QuotaTypeId"];
                quota.QuotaAllocatedValue = (int)dr["QuotaValue"];
                quota.QuotaUsedValue = (int)dr["QuotaUsedValue"];
                quota.QuotaExhausted = (packageId < 2) || (quota.QuotaAllocatedValue != -1 && quota.QuotaUsedValue >= quota.QuotaAllocatedValue);
                quotas.Add(quota);
                context.Quotas.Add(quota.QuotaName, quota);
            }

            context.GroupsArray = groups.ToArray();
            context.QuotasArray = quotas.ToArray();

            return context;
        }
Exemple #17
0
        public override void DoWork()
        {
            // Input parameters:
            //  - DISKSPACE_OVERUSED
            //  - BANDWIDTH_OVERUSED

            BackgroundTask topTask = TaskManager.TopTask;

            // get the list of all packages
            List <PackageInfo> packages = PackageController.GetPackagePackages(topTask.PackageId, false);

            TaskManager.Write("Packages to verify: " + packages.Count.ToString());

            bool checkMSSQL = (String.Compare((string)topTask.GetParamValue("MSSQL_OVERUSED"), "true", true) == 0);
            bool checkMySQL = (String.Compare((string)topTask.GetParamValue("MYSQL_OVERUSED"), "true", true) == 0);

            bool   sendWarningEmail       = Convert.ToBoolean(topTask.GetParamValue("SEND_WARNING_EMAIL"));
            bool   sendOverusedEmail      = Convert.ToBoolean(topTask.GetParamValue("SEND_OVERUSED_EMAIL"));
            int    warningUsageThreshold  = Convert.ToInt32(topTask.GetParamValue("WARNING_USAGE_THRESHOLD"));
            int    overusedUsageThreshold = Convert.ToInt32(topTask.GetParamValue("OVERUSED_USAGE_THRESHOLD"));
            string warningMailFrom        = Convert.ToString(topTask.GetParamValue("WARNING_MAIL_FROM"));
            string warningMailBcc         = Convert.ToString(topTask.GetParamValue("WARNING_MAIL_BCC"));
            string warningMailSubject     = Convert.ToString(topTask.GetParamValue("WARNING_MAIL_SUBJECT"));
            string warningMailBody        = Convert.ToString(topTask.GetParamValue("WARNING_MAIL_BODY"));
            string overusedMailFrom       = Convert.ToString(topTask.GetParamValue("OVERUSED_MAIL_FROM"));
            string overusedMailBcc        = Convert.ToString(topTask.GetParamValue("OVERUSED_MAIL_BCC"));
            string overusedMailSubject    = Convert.ToString(topTask.GetParamValue("OVERUSED_MAIL_SUBJECT"));
            string overusedMailBody       = Convert.ToString(topTask.GetParamValue("OVERUSED_MAIL_BODY"));

            int overusedPackages = 0;

            foreach (PackageInfo package in packages)
            {
                UserInfo userInfo = UserController.GetUser(package.UserId);

                List <DatabaseQuota> quotaMSSQL = new List <DatabaseQuota>();
                List <DatabaseQuota> quotaMYSQL = new List <DatabaseQuota>();

                if (checkMSSQL || checkMySQL)
                {
                    QuotaValueInfo dsQuota   = null;
                    DataSet        Diskspace = PackageController.GetPackageDiskspace(package.PackageId);
                    foreach (DataRow spaceRow in Diskspace.Tables[0].Rows)
                    {
                        string groupName = spaceRow["GroupName"].ToString();
                        if (checkMSSQL && groupName.ToUpper().Contains("MSSQL"))
                        {
                            dsQuota = PackageController.GetPackageQuota(package.PackageId, groupName + ".MaxDatabaseSize");
                            if (dsQuota.QuotaAllocatedValue > 0)
                            {
                                int databaseSpaceUsage = Convert.ToInt32(spaceRow["Diskspace"]) * 100 / dsQuota.QuotaAllocatedValue;
                                quotaMSSQL.Add(new DatabaseQuota(groupName.ToUpper().Replace("MSSQL", "SQL Server "),
                                                                 Convert.ToInt32(spaceRow["Diskspace"]), dsQuota.QuotaAllocatedValue,
                                                                 databaseSpaceUsage < warningUsageThreshold,
                                                                 databaseSpaceUsage < overusedUsageThreshold));
                            }
                        }
                        if (checkMySQL && groupName.ToUpper().Contains("MYSQL"))
                        {
                            dsQuota = PackageController.GetPackageQuota(package.PackageId, groupName + ".MaxDatabaseSize");
                            if (dsQuota.QuotaAllocatedValue > 0)
                            {
                                int databaseSpaceUsage = Convert.ToInt32(spaceRow["Diskspace"]) * 100 / dsQuota.QuotaAllocatedValue;
                                quotaMYSQL.Add(new DatabaseQuota(groupName.ToUpper().Replace("MYSQL", "MySQL "),
                                                                 Convert.ToInt32(spaceRow["Diskspace"]), dsQuota.QuotaAllocatedValue,
                                                                 databaseSpaceUsage < warningUsageThreshold,
                                                                 databaseSpaceUsage < overusedUsageThreshold));
                            }
                        }
                    }

                    string        userName                = String.Format("{0} {1} ({2})/{3}", userInfo.FirstName, userInfo.LastName, userInfo.Username, userInfo.Email);
                    bool          notifyOverusedByMail    = false;
                    bool          notifyWarningByMail     = false;
                    List <string> formatItems             = new List <string>();
                    List <string> formatWarningThreshold  = new List <string>();
                    List <string> formatOverusedThreshold = new List <string>();
                    // add Microsoft SQL usage if enabled
                    if (checkMSSQL)
                    {
                        foreach (DatabaseQuota q in quotaMSSQL)
                        {
                            if (!q.BelowWarningThreshold || !q.BelowUsageThreshold)
                            {
                                formatItems.Add(String.Format(DISKSPACE_FORMAT_STRING, q.ProviderName, q.SpaceUsed, q.SpaceUsed * 100 / q.SpaceAllocated));
                            }
                            if (!q.BelowWarningThreshold)
                            {
                                formatWarningThreshold.Add(String.Format(ALLOC_FORMAT_STRING, q.ProviderName, q.SpaceAllocated));
                                notifyWarningByMail = true;
                            }
                            if (!q.BelowUsageThreshold)
                            {
                                formatOverusedThreshold.Add(String.Format(ALLOC_FORMAT_STRING, q.ProviderName, q.SpaceAllocated));
                                notifyOverusedByMail = true;
                            }
                        }
                    }

                    // add MySQL usage if enabled
                    if (checkMySQL)
                    {
                        foreach (DatabaseQuota q in quotaMYSQL)
                        {
                            if (!q.BelowWarningThreshold || !q.BelowUsageThreshold)
                            {
                                formatItems.Add(String.Format(DISKSPACE_FORMAT_STRING, q.ProviderName, q.SpaceUsed, (q.SpaceUsed * 100) / q.SpaceAllocated));
                            }
                            if (!q.BelowWarningThreshold)
                            {
                                formatWarningThreshold.Add(String.Format(ALLOC_FORMAT_STRING, q.ProviderName, q.SpaceAllocated));
                                notifyWarningByMail = true;
                            }
                            if (!q.BelowUsageThreshold)
                            {
                                formatOverusedThreshold.Add(String.Format(ALLOC_FORMAT_STRING, q.ProviderName, q.SpaceAllocated));
                                notifyOverusedByMail = true;
                            }
                        }
                    }
                    // build usage strings
                    string usage         = String.Join("\n", formatItems.ToArray());
                    string usageWarning  = String.Join("\n", formatWarningThreshold.ToArray());
                    string usageOverused = String.Join("\n", formatOverusedThreshold.ToArray());

                    string warningMailSubjectProcessed = ReplaceVariables(warningMailSubject, usageWarning, usage, package.PackageName, userName);
                    string warningMailBodyProcessed    = ReplaceVariables(warningMailBody, usageWarning, usage, package.PackageName, userName);

                    string overusedMailSubjectProcessed = ReplaceVariables(overusedMailSubject, usageOverused, usage, package.PackageName, userName);
                    string overusedMailBodyProcessed    = ReplaceVariables(overusedMailBody, usageOverused, usage, package.PackageName, userName);


                    // Send email notifications
                    if (sendWarningEmail && notifyWarningByMail)
                    {
                        // Send warning email.
                        this.SendEmail(warningMailFrom, userInfo.Email, warningMailBcc, warningMailSubjectProcessed, warningMailBodyProcessed, false);
                    }

                    if (sendOverusedEmail && notifyOverusedByMail)
                    {
                        // Send overused email.
                        this.SendEmail(overusedMailFrom, userInfo.Email, overusedMailBcc, overusedMailSubjectProcessed, overusedMailBodyProcessed, false);
                    }
                    if (notifyOverusedByMail)
                    {
                        overusedPackages++;
                    }
                }
            }

            // log results
            TaskManager.Write("Total packages overused: " + overusedPackages.ToString());
        }