private void BindStatistics()
        {
            // total counters
            int totalMailboxItems    = 0;
            int totalMailboxesSizeMB = 0;

            // mailboxes
            ExchangeItemStatistics[] mailboxes = ES.Services.ExchangeServer.GetMailboxesStatistics(PanelRequest.ItemID);
            gvMailboxes.DataSource = mailboxes;
            gvMailboxes.DataBind();

            foreach (ExchangeItemStatistics item in mailboxes)
            {
                totalMailboxItems    += item.TotalItems;
                totalMailboxesSizeMB += item.TotalSizeMB;
            }

            OrganizationStatistics stats = ES.Services.ExchangeServer.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);

            lblTotalMailboxItems.Text = totalMailboxItems.ToString();
            lblTotalMailboxSize.Text  = totalMailboxesSizeMB.ToString();
            lblTotalMailboxes.Text    = stats.CreatedMailboxes.ToString();
            int avgSize = totalMailboxesSizeMB / stats.CreatedMailboxes;

            lblAverageMailboxSize.Text = avgSize.ToString("N2");
        }
        private void BindServiceLevels()
        {
            PackageContext         cntx  = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId);
            OrganizationStatistics stats = ES.Services.Organizations.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);

            if (cntx.Groups.ContainsKey(ResourceGroups.ServiceLevels))
            {
                List <ServiceLevel> enabledServiceLevels = new List <ServiceLevel>();

                foreach (var serviceLevel in ES.Services.Organizations.GetSupportServiceLevels())
                {
                    if (CheckServiceLevelQuota(serviceLevel, stats.ServiceLevels))
                    {
                        enabledServiceLevels.Add(serviceLevel);
                    }
                }

                ddlServiceLevels.DataSource     = enabledServiceLevels;
                ddlServiceLevels.DataTextField  = "LevelName";
                ddlServiceLevels.DataValueField = "LevelId";
                ddlServiceLevels.DataBind();

                ddlServiceLevels.Items.Insert(0, new ListItem("<Select Service Level>", string.Empty));
                ddlServiceLevels.Items.FindByValue(string.Empty).Selected = true;

                secServiceLevels.Visible = true;
            }
            else
            {
                secServiceLevels.Visible = false;
            }
        }
        private void BindServiceLevelsStats(OrganizationStatistics stats)
        {
            foreach (var quota in stats.ServiceLevels)
            {
                HtmlTableRow tr = new HtmlTableRow();
                tr.Attributes["class"] = "OrgStatsRow";
                HtmlTableCell col1 = new HtmlTableCell();
                col1.Attributes["class"]  = "OrgStatsQuota";
                col1.Attributes["nowrap"] = "nowrap";
                HyperLink link = new HyperLink();
                link.ID   = "lnk_" + quota.QuotaName.Replace(Quotas.SERVICE_LEVELS, "").Replace(" ", string.Empty).Trim();
                link.Text = quota.QuotaDescription.Replace(", users", " (users):");

                col1.Controls.Add(link);

                HtmlTableCell col2         = new HtmlTableCell();
                QuotaViewer   quotaControl = (QuotaViewer)LoadControl("../UserControls/QuotaViewer.ascx");
                quotaControl.ID             = quota.QuotaName.Replace(Quotas.SERVICE_LEVELS, "").Replace(" ", string.Empty).Trim() + "Stats";
                quotaControl.QuotaTypeId    = quota.QuotaTypeId;
                quotaControl.DisplayGauge   = true;
                quotaControl.QuotaValue     = quota.QuotaAllocatedValue;
                quotaControl.QuotaUsedValue = quota.QuotaUsedValue;
                if (quota.QuotaAllocatedValue != -1)
                {
                    quotaControl.QuotaAvailable = quota.QuotaAllocatedValue - quota.QuotaUsedValue;
                }

                col2.Controls.Add(quotaControl);

                tr.Controls.Add(col1);
                tr.Controls.Add(col2);
                serviceLevelsStatsPanel.Controls.Add(tr);
            }
        }
        protected void BindEnterpriseStorageStats()
        {
            btnAddFolder.Enabled = true;

            OrganizationStatistics organizationStats = ES.Services.EnterpriseStorage.GetStatisticsByOrganization(PanelRequest.ItemID);

            foldersQuota.QuotaUsedValue = organizationStats.CreatedEnterpriseStorageFolders;
            foldersQuota.QuotaValue     = organizationStats.AllocatedEnterpriseStorageFolders;

            spaceAvailableQuota.QuotaUsedValue = organizationStats.UsedEnterpriseStorageSpace;
            spaceAvailableQuota.QuotaValue     = organizationStats.AllocatedEnterpriseStorageSpace;

            spaceQuota.QuotaValue = (int)Math.Round(ConvertMBytesToGB(organizationStats.UsedEnterpriseStorageSpace), 0);

            if (organizationStats.AllocatedEnterpriseStorageFolders != -1)
            {
                int folderAvailable = foldersQuota.QuotaAvailable = organizationStats.AllocatedEnterpriseStorageFolders - organizationStats.CreatedEnterpriseStorageFolders;

                if (folderAvailable <= 0)
                {
                    btnAddFolder.Enabled = false;
                }
            }

            if (organizationStats.AllocatedEnterpriseStorageSpace != -1)
            {
                int spaceAvailable = spaceAvailableQuota.QuotaAvailable = organizationStats.AllocatedEnterpriseStorageSpace - organizationStats.UsedEnterpriseStorageSpace;

                if (spaceAvailable <= 0)
                {
                    btnAddFolder.Enabled = false;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!ES.Services.EnterpriseStorage.CheckUsersDomainExists(PanelRequest.ItemID))
                {
                    Response.Redirect(EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), "enterprisestorage_folders",
                                              "ItemID=" + PanelRequest.ItemID));
                }

                OrganizationStatistics organizationStats = ES.Services.Organizations.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);

                if (organizationStats.AllocatedEnterpriseStorageSpace != -1)
                {
                    rangeFolderSize.MaximumValue = Math.Round((organizationStats.AllocatedEnterpriseStorageSpace - (decimal)organizationStats.UsedEnterpriseStorageSpace) / OneGb
                                                              + Utils.ParseDecimal(txtFolderSize.Text, 0), 2).ToString();
                    rangeFolderSize.ErrorMessage = string.Format("The quota you've entered exceeds the available quota for organization ({0}Gb)", rangeFolderSize.MaximumValue);
                }

                if (organizationStats.AllocatedGroups != -1)
                {
                    int groupsAvailable = organizationStats.AllocatedGroups - organizationStats.CreatedGroups;

                    if (groupsAvailable <= 0)
                    {
                        chkAddDefaultGroup.Enabled = false;
                    }
                }
            }
        }
Example #6
0
        private void BindCRMStats(OrganizationStatistics stats, OrganizationStatistics tenantStats)
        {
            lnkCRMUsers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "crmusers",
                                              "SpaceID=" + PanelSecurity.PackageId);

            lnkLimitedCRMUsers.NavigateUrl = lnkCRMUsers.NavigateUrl;
            lnkESSCRMUsers.NavigateUrl     = lnkCRMUsers.NavigateUrl;

            lnkCRMDBSize.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "crm_storage_settings",
                                               "SpaceID=" + PanelSecurity.PackageId);

            crmUsersStats.QuotaUsedValue = stats.CreatedCRMUsers;
            crmUsersStats.QuotaValue     = stats.AllocatedCRMUsers;

            //if (stats.AllocatedCRMUsers != -1) crmUsersStats.QuotaAvailable = tenantStats.AllocatedCRMUsers - tenantStats.CreatedCRMUsers;

            crmLimitedUsersStats.QuotaUsedValue = stats.CreatedLimitedCRMUsers;
            crmLimitedUsersStats.QuotaValue     = stats.AllocatedLimitedCRMUsers;

            crmESSUsersStats.QuotaUsedValue = stats.CreatedESSCRMUsers;
            crmESSUsersStats.QuotaValue     = stats.AllocatedESSCRMUsers;

            crmDBSize.QuotaUsedValue = Convert.ToInt32(stats.UsedCRMDiskSpace > 0 ? stats.UsedCRMDiskSpace / (1024 * 1024) : -1);
            crmDBSize.QuotaValue     = Convert.ToInt32(stats.AllocatedCRMDiskSpace > 0 ? stats.AllocatedCRMDiskSpace / (1024 * 1024) : -1);
        }
Example #7
0
        private void BindRemoteDesktopStats(OrganizationStatistics stats, OrganizationStatistics tenantStats)
        {
            rdsServers.QuotaValue     = stats.AllocatedRdsServers;
            rdsServers.QuotaUsedValue = stats.CreatedRdsServers;
            if (stats.AllocatedRdsServers != -1)
            {
                rdsServers.QuotaAvailable = tenantStats.AllocatedRdsServers - tenantStats.CreatedRdsServers;
            }

            rdsCollections.QuotaValue     = stats.AllocatedRdsCollections;
            rdsCollections.QuotaUsedValue = stats.CreatedRdsCollections;

            if (stats.AllocatedRdsCollections != -1)
            {
                rdsCollections.QuotaAvailable = tenantStats.AllocatedRdsCollections - tenantStats.CreatedRdsCollections;
            }

            rdsUsers.QuotaValue     = stats.AllocatedRdsUsers;
            rdsUsers.QuotaUsedValue = stats.CreatedRdsUsers;

            if (stats.AllocatedRdsCollections != -1)
            {
                rdsUsers.QuotaAvailable = tenantStats.AllocatedRdsUsers - tenantStats.CreatedRdsUsers;
            }

            lnkRdsServers.NavigateUrl     = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "rds_collections", "SpaceID=" + PanelSecurity.PackageId);
            lnkRdsCollections.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "rds_collections", "SpaceID=" + PanelSecurity.PackageId);
            lnkRdsUsers.NavigateUrl       = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "rds_collections", "SpaceID=" + PanelSecurity.PackageId);
        }
Example #8
0
        private void BindStats()
        {
            OrganizationStatistics stats =
                ES.Services.ExchangeServer.GetOrganizationStatistics(PanelRequest.ItemID);

            foldersQuota.QuotaUsedValue = stats.CreatedPublicFolders;
            foldersQuota.QuotaValue     = stats.AllocatedPublicFolders;
        }
Example #9
0
        private void BindCRMStats(OrganizationStatistics orgStats)
        {
            lnkCRMUsers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "crmusers",
                                              "SpaceID=" + PanelSecurity.PackageId);

            crmUsersStats.QuotaUsedValue = orgStats.CreatedCRMUsers;
            crmUsersStats.QuotaValue     = orgStats.AllocatedCRMUsers;
        }
Example #10
0
        private void BindStats()
        {
            // quota values
            OrganizationStatistics stats =
                ES.Services.Organizations.GetOrganizationStatistics(PanelRequest.ItemID);

            siteCollectionsQuota.QuotaUsedValue = stats.CreatedSharePointSiteCollections;
            siteCollectionsQuota.QuotaValue     = stats.AllocatedSharePointSiteCollections;
        }
Example #11
0
 public Organization(string email, string name) : base(email, name)
 {
     Description            = "";
     LogoFilePath           = "";
     Certified              = false;
     DonationOptions        = new DonationOptions();
     DonationGoal           = new DonationGoal(false, 0, 0); // NullDonationGoal ?
     OrganizationStatistics = new OrganizationStatistics();
 }
Example #12
0
        private void BindStats()
        {
            OrganizationStatistics stats = ES.Services.Organizations.GetOrganizationStatistics(PanelRequest.ItemID);
            int allocatedOCSUsers        = stats.AllocatedOCSUsers;
            int usedUsers = stats.CreatedOCSUsers;

            usersQuota.QuotaUsedValue = usedUsers;
            usersQuota.QuotaValue     = allocatedOCSUsers;
        }
        private void BindStats()
        {
            // quota values
            OrganizationStatistics stats =
                ES.Services.ExchangeServer.GetOrganizationStatistics(PanelRequest.ItemID);

            contactsQuota.QuotaUsedValue = stats.CreatedContacts;
            contactsQuota.QuotaValue     = stats.AllocatedContacts;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            OrganizationStatistics stats = ES.Services.Organizations.GetOrganizationStatistics(PanelRequest.ItemID);
            int allocatedCrmUsers        = stats.AllocatedBlackBerryUsers;
            int usedUsers = stats.CreatedBlackBerryUsers;

            usersQuota.QuotaUsedValue = usedUsers;
            usersQuota.QuotaValue     = allocatedCrmUsers;
        }
        private void BindStats()
        {
            // quota values
            OrganizationStatistics stats =
                ES.Services.Organizations.GetOrganizationStatistics(PanelRequest.ItemID);

            usersQuota.QuotaUsedValue = stats.CreatedUsers;
            usersQuota.QuotaValue     = stats.AllocatedUsers;
        }
Example #16
0
        private void BindStats()
        {
            // set quotas
            OrganizationStatistics stats =
                ES.Services.Organizations.GetOrganizationStatistics(PanelRequest.ItemID);

            domainsQuota.QuotaUsedValue = stats.CreatedDomains;
            domainsQuota.QuotaValue     = stats.AllocatedDomains;
        }
Example #17
0
        private void BindStats()
        {
            // quota values
            OrganizationStatistics stats = ES.Services.Organizations.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);

            deletedUsersQuota.QuotaUsedValue = stats.DeletedUsers;
            deletedUsersQuota.QuotaValue     = stats.AllocatedDeletedUsers;
            if (stats.AllocatedUsers != -1)
            {
                deletedUsersQuota.QuotaAvailable = stats.AllocatedDeletedUsers - stats.DeletedUsers;
            }
        }
Example #18
0
        private void BindStats()
        {
            OrganizationStatistics stats       = ES.Services.ExchangeServer.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);
            OrganizationStatistics tenantStats = ES.Services.ExchangeServer.GetOrganizationStatistics(PanelRequest.ItemID);

            foldersQuota.QuotaUsedValue = stats.CreatedPublicFolders;
            foldersQuota.QuotaValue     = stats.AllocatedPublicFolders;
            if (stats.AllocatedPublicFolders != -1)
            {
                foldersQuota.QuotaAvailable = tenantStats.AllocatedPublicFolders - tenantStats.CreatedPublicFolders;
            }
        }
        private void BindQuota(PackageContext cntx)
        {
            OrganizationStatistics stats = ES.Services.Organizations.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);

            rdsServersQuota.QuotaUsedValue = stats.CreatedRdsServers;
            rdsServersQuota.QuotaValue     = stats.AllocatedRdsServers;

            if (stats.AllocatedUsers != -1)
            {
                rdsServersQuota.QuotaAvailable = stats.AllocatedRdsServers - stats.CreatedRdsServers;
            }
        }
Example #20
0
        private void BindStats()
        {
            // quota values
            OrganizationStatistics stats = ES.Services.ExchangeServer.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);

            listsQuota.QuotaUsedValue = stats.CreatedDistributionLists;
            listsQuota.QuotaValue     = stats.AllocatedDistributionLists;
            if (stats.AllocatedDistributionLists != -1)
            {
                listsQuota.QuotaAvailable = stats.AllocatedDistributionLists - stats.CreatedDistributionLists;
            }
        }
Example #21
0
        private void BindStats()
        {
            // quota values
            OrganizationStatistics stats = ES.Services.Organizations.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);

            siteCollectionsQuota.QuotaUsedValue = stats.CreatedSharePointEnterpriseSiteCollections;
            siteCollectionsQuota.QuotaValue     = stats.AllocatedSharePointEnterpriseSiteCollections;
            if (stats.AllocatedSharePointEnterpriseSiteCollections != -1)
            {
                siteCollectionsQuota.QuotaAvailable = stats.AllocatedSharePointEnterpriseSiteCollections - stats.CreatedSharePointEnterpriseSiteCollections;
            }
        }
Example #22
0
        private void BindSfBStats(OrganizationStatistics stats)
        {
            sfbUsersStats.QuotaValue     = stats.AllocatedSfBUsers;
            sfbUsersStats.QuotaUsedValue = stats.CreatedSfBUsers;
            if (stats.AllocatedSfBUsers != -1)
            {
                sfbUsersStats.QuotaAvailable = stats.AllocatedSfBUsers - stats.CreatedSfBUsers;
            }

            lnkSfBUsers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "sfb_users",
                                              "SpaceID=" + PanelSecurity.PackageId.ToString());
        }
Example #23
0
        private void BindBESStats(OrganizationStatistics stats, OrganizationStatistics tenantStats)
        {
            besUsersStats.QuotaValue     = stats.AllocatedBlackBerryUsers;
            besUsersStats.QuotaUsedValue = stats.CreatedBlackBerryUsers;
            if (stats.AllocatedBlackBerryUsers != -1)
            {
                besUsersStats.QuotaAvailable = tenantStats.AllocatedBlackBerryUsers - tenantStats.CreatedBlackBerryUsers;
            }

            lnkBESUsers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "blackberry_users",
                                              "SpaceID=" + PanelSecurity.PackageId.ToString());
        }
Example #24
0
        private void BindLyncStats(OrganizationStatistics stats, OrganizationStatistics tenantStats)
        {
            lyncUsersStats.QuotaValue     = stats.AllocatedLyncUsers;
            lyncUsersStats.QuotaUsedValue = stats.CreatedLyncUsers;
            if (stats.AllocatedLyncUsers != -1)
            {
                lyncUsersStats.QuotaAvailable = tenantStats.AllocatedLyncUsers - tenantStats.CreatedLyncUsers;
            }

            lnkLyncUsers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "lync_users",
                                               "SpaceID=" + PanelSecurity.PackageId.ToString());
        }
Example #25
0
        private void BindQuota(PackageContext cntx)
        {
            OrganizationStatistics stats       = ES.Services.Organizations.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);
            OrganizationStatistics tenantStats = ES.Services.Organizations.GetOrganizationStatistics(PanelRequest.ItemID);

            collectionsQuota.QuotaUsedValue = stats.CreatedRdsCollections;
            collectionsQuota.QuotaValue     = stats.AllocatedRdsCollections;

            if (stats.AllocatedUsers != -1)
            {
                collectionsQuota.QuotaAvailable = tenantStats.AllocatedRdsCollections - tenantStats.CreatedRdsCollections;
            }
        }
Example #26
0
        private void BindStats()
        {
            // quota values
            OrganizationStatistics stats       = ES.Services.ExchangeServer.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);
            OrganizationStatistics tenantStats = ES.Services.ExchangeServer.GetOrganizationStatistics(PanelRequest.ItemID);

            contactsQuota.QuotaUsedValue = stats.CreatedContacts;
            contactsQuota.QuotaValue     = stats.AllocatedContacts;
            if (stats.AllocatedContacts != -1)
            {
                contactsQuota.QuotaAvailable = tenantStats.AllocatedContacts - tenantStats.CreatedContacts;
            }
        }
        private void BindStats()
        {
            // set quotas
            OrganizationStatistics stats       = ES.Services.Organizations.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);
            OrganizationStatistics tenantStats = ES.Services.Organizations.GetOrganizationStatistics(PanelRequest.ItemID);

            spacesQuota.QuotaUsedValue = stats.CreatedEnterpriseStorageFolders;
            spacesQuota.QuotaValue     = stats.AllocatedEnterpriseStorageFolders;
            if (stats.AllocatedEnterpriseStorageFolders != -1)
            {
                spacesQuota.QuotaAvailable = tenantStats.AllocatedEnterpriseStorageFolders - tenantStats.CreatedEnterpriseStorageFolders;
            }
        }
Example #28
0
        private void BindStats()
        {
            // set quotas
            OrganizationStatistics stats       = ES.Services.Organizations.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);
            OrganizationStatistics tenantStats = ES.Services.Organizations.GetOrganizationStatistics(PanelRequest.ItemID);

            domainsQuota.QuotaUsedValue = stats.CreatedDomains;
            domainsQuota.QuotaValue     = stats.AllocatedDomains;
            if (stats.AllocatedDomains != -1)
            {
                domainsQuota.QuotaAvailable = tenantStats.AllocatedDomains - tenantStats.CreatedDomains;
            }
        }
Example #29
0
        private void BindStats()
        {
            OrganizationStatistics stats = ES.Services.Organizations.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);
            int allocatedLyncUsers       = stats.AllocatedLyncUsers;
            int usedUsers = stats.CreatedLyncUsers;

            usersQuota.QuotaUsedValue = usedUsers;
            usersQuota.QuotaValue     = allocatedLyncUsers;

            if (stats.AllocatedLyncUsers != -1)
            {
                usersQuota.QuotaAvailable = stats.AllocatedLyncUsers - stats.CreatedLyncUsers;
            }
        }
Example #30
0
        private void AddServiceLevelsQuotas()
        {
            var orgs = ES.Services.Organizations.GetOrganizations(PanelSecurity.PackageId, true);
            OrganizationStatistics stats = null;

            if (orgs != null && orgs.FirstOrDefault() != null)
            {
                stats = ES.Services.Organizations.GetOrganizationStatistics(orgs.First().Id);
            }

            foreach (var quota in Array.FindAll <QuotaValueInfo>(
                         cntx.QuotasArray, x => x.QuotaName.Contains(Quotas.SERVICE_LEVELS)))
            {
                HtmlTableRow tr = new HtmlTableRow();
                tr.ID = "pnl_" + quota.QuotaName.Replace(Quotas.SERVICE_LEVELS, "").Replace(" ", string.Empty).Trim();
                HtmlTableCell col1 = new HtmlTableCell();
                col1.Attributes["class"]  = "SubHead";
                col1.Attributes["nowrap"] = "nowrap";
                Label lbl = new Label();
                lbl.ID   = "lbl_" + quota.QuotaName.Replace(Quotas.SERVICE_LEVELS, "").Replace(" ", string.Empty).Trim();
                lbl.Text = quota.QuotaDescription + ":";

                col1.Controls.Add(lbl);

                HtmlTableCell col2 = new HtmlTableCell();
                col2.Attributes["class"] = "Normal";
                Quota quotaControl = (Quota)LoadControl("UserControls/Quota.ascx");
                quotaControl.ID = "quota_" +
                                  quota.QuotaName.Replace(Quotas.SERVICE_LEVELS, "").Replace(" ", string.Empty).Trim();
                quotaControl.QuotaName    = quota.QuotaName;
                quotaControl.DisplayGauge = true;

                col2.Controls.Add(quotaControl);

                tr.Controls.Add(col1);
                tr.Controls.Add(col2);
                tblQuotas.Controls.Add(tr);

                if (stats != null)
                {
                    var serviceLevel = stats.ServiceLevels.FirstOrDefault(q => q.QuotaName == quota.QuotaName);
                    if (serviceLevel != null)
                    {
                        quotaControl.QuotaAllocatedValue = serviceLevel.QuotaAllocatedValue;
                    }
                }
            }
        }
        private void BindCRMStats(OrganizationStatistics stats)
        {
            lnkCRMUsers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "crmusers",
                "SpaceID=" + PanelSecurity.PackageId);

            lnkLimitedCRMUsers.NavigateUrl = lnkCRMUsers.NavigateUrl;
            lnkESSCRMUsers.NavigateUrl = lnkCRMUsers.NavigateUrl;

            lnkCRMDBSize.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "crm_storage_settings",
                "SpaceID=" + PanelSecurity.PackageId);

            crmUsersStats.QuotaUsedValue = stats.CreatedCRMUsers;
            crmUsersStats.QuotaValue = stats.AllocatedCRMUsers;

            //if (stats.AllocatedCRMUsers != -1) crmUsersStats.QuotaAvailable = stats.AllocatedCRMUsers - stats.CreatedCRMUsers;

            crmLimitedUsersStats.QuotaUsedValue = stats.CreatedLimitedCRMUsers;
            crmLimitedUsersStats.QuotaValue = stats.AllocatedLimitedCRMUsers;

            crmESSUsersStats.QuotaUsedValue = stats.CreatedESSCRMUsers;
            crmESSUsersStats.QuotaValue = stats.AllocatedESSCRMUsers;

            crmDBSize.QuotaUsedValue = Convert.ToInt32(stats.UsedCRMDiskSpace > 0 ? stats.UsedCRMDiskSpace / (1024 * 1024) : -1);
            crmDBSize.QuotaValue = Convert.ToInt32(stats.AllocatedCRMDiskSpace>0 ? stats.AllocatedCRMDiskSpace/(1024*1024) : -1);
        }
        private static OrganizationStatistics GetStatisticsInternal(int itemId, bool byOrganization)
        {
            // place log record
            TaskManager.StartTask("ENTERPRISE_STORAGE", "GET_ORG_STATS", itemId);

            try
            {
                Organization org = (Organization)PackageController.GetPackageItem(itemId);
                if (org == null)
                    return null;

                OrganizationStatistics stats = new OrganizationStatistics();

                if (byOrganization)
                {
                    SystemFile[] folders = GetEnterpriseFoldersPaged(itemId, false, false, false, "", "", 0, int.MaxValue).PageItems;

                    stats.CreatedEnterpriseStorageFolders = folders.Count();

                    stats.UsedEnterpriseStorageSpace = folders.Where(x => x.FRSMQuotaMB != -1).Sum(x => x.FRSMQuotaMB);
                }
                else
                {
                    UserInfo user = ObjectUtils.FillObjectFromDataReader<UserInfo>(DataProvider.GetUserByExchangeOrganizationIdInternally(org.Id));
                    List<PackageInfo> Packages = PackageController.GetPackages(user.UserId);

                    if ((Packages != null) & (Packages.Count > 0))
                    {
                        foreach (PackageInfo Package in Packages)
                        {
                            List<Organization> orgs = null;

                            orgs = ExchangeServerController.GetExchangeOrganizations(Package.PackageId, false);

                            if ((orgs != null) & (orgs.Count > 0))
                            {
                                foreach (Organization o in orgs)
                                {
                                    SystemFile[] folders = GetEnterpriseFoldersPaged(o.Id, true, false, false, "", "", 0, int.MaxValue).PageItems;

                                    stats.CreatedEnterpriseStorageFolders += folders.Count();

                                    stats.UsedEnterpriseStorageSpace += folders.Where(x => x.FRSMQuotaMB != -1).Sum(x => x.FRSMQuotaMB);
                                }
                            }
                        }
                    }
                }

                // allocated quotas
                PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
                stats.AllocatedEnterpriseStorageSpace = cntx.Quotas[Quotas.ENTERPRISESTORAGE_DISKSTORAGESPACE].GetQuotaAllocatedValue(byOrganization);
                stats.AllocatedEnterpriseStorageFolders = cntx.Quotas[Quotas.ENTERPRISESTORAGE_FOLDERS].GetQuotaAllocatedValue(byOrganization);

                return stats;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        private void BindRemoteDesktopStats(OrganizationStatistics stats)
        {
            rdsServers.QuotaValue = stats.AllocatedRdsServers;
            rdsServers.QuotaUsedValue = stats.CreatedRdsServers;
            if (stats.AllocatedRdsServers != -1)
            {
                rdsServers.QuotaAvailable = stats.AllocatedRdsServers - stats.CreatedRdsServers;
            }

            rdsCollections.QuotaValue = stats.AllocatedRdsCollections;
            rdsCollections.QuotaUsedValue = stats.CreatedRdsCollections;

            if (stats.AllocatedRdsCollections != -1)
            {
                rdsCollections.QuotaAvailable = stats.AllocatedRdsCollections - stats.CreatedRdsCollections;
            }                       

            rdsUsers.QuotaValue = stats.AllocatedRdsUsers;
            rdsUsers.QuotaUsedValue = stats.CreatedRdsUsers;

            if (stats.AllocatedRdsCollections != -1)
            {
                rdsUsers.QuotaAvailable = stats.AllocatedRdsUsers - stats.CreatedRdsUsers;
            }

            lnkRdsServers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "rds_collections", "SpaceID=" + PanelSecurity.PackageId);
            lnkRdsCollections.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "rds_collections", "SpaceID=" + PanelSecurity.PackageId);
            lnkRdsUsers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "rds_collections", "SpaceID=" + PanelSecurity.PackageId);
        }
        private void BindServiceLevelsStats(OrganizationStatistics stats)
        {
            foreach (var quota in stats.ServiceLevels)
            {
                HtmlTableRow tr = new HtmlTableRow();
                tr.Attributes["class"] = "OrgStatsRow";
                HtmlTableCell col1 = new HtmlTableCell();
                col1.Attributes["class"] = "OrgStatsQuota";
                col1.Attributes["nowrap"] = "nowrap";
                HyperLink link = new HyperLink();
                link.ID = "lnk_" + quota.QuotaName.Replace(Quotas.SERVICE_LEVELS, "").Replace(" ", string.Empty).Trim();
                link.Text = quota.QuotaDescription.Replace(", users", " (users):");

                col1.Controls.Add(link);

                HtmlTableCell col2 = new HtmlTableCell();
                QuotaViewer quotaControl = (QuotaViewer) LoadControl("../UserControls/QuotaViewer.ascx");
                quotaControl.ID = quota.QuotaName.Replace(Quotas.SERVICE_LEVELS, "").Replace(" ", string.Empty).Trim() + "Stats";
                quotaControl.QuotaTypeId = quota.QuotaTypeId;
                quotaControl.DisplayGauge = true;
                quotaControl.QuotaValue = quota.QuotaAllocatedValue;
                quotaControl.QuotaUsedValue = quota.QuotaUsedValue;
                if (quota.QuotaAllocatedValue != -1)
                    quotaControl.QuotaAvailable = quota.QuotaAllocatedValue - quota.QuotaUsedValue;

                col2.Controls.Add(quotaControl);

                tr.Controls.Add(col1);
                tr.Controls.Add(col2);
                serviceLevelsStatsPanel.Controls.Add(tr);
            }
        }
        private void BindEnterpriseStorageStats(OrganizationStatistics stats)
        {
            enterpriseStorageSpaceStats.QuotaValue = stats.AllocatedEnterpriseStorageSpace;
            enterpriseStorageSpaceStats.QuotaUsedValue = stats.UsedEnterpriseStorageSpace;
            if (stats.AllocatedEnterpriseStorageSpace != -1) enterpriseStorageSpaceStats.QuotaAvailable = stats.AllocatedEnterpriseStorageSpace - stats.UsedEnterpriseStorageSpace;

            lnkEnterpriseStorageSpace.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "enterprisestorage_folders",
            "SpaceID=" + PanelSecurity.PackageId.ToString());

            enterpriseStorageFoldersStats.QuotaValue = stats.AllocatedEnterpriseStorageFolders;
            enterpriseStorageFoldersStats.QuotaUsedValue = stats.CreatedEnterpriseStorageFolders;
            if (stats.AllocatedEnterpriseStorageFolders != -1) enterpriseStorageFoldersStats.QuotaAvailable = stats.AllocatedEnterpriseStorageFolders - stats.CreatedEnterpriseStorageFolders;

            lnkEnterpriseStorageFolders.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "enterprisestorage_folders",
            "SpaceID=" + PanelSecurity.PackageId.ToString());
        }
        private void BindBESStats(OrganizationStatistics stats)
        {
            besUsersStats.QuotaValue = stats.AllocatedBlackBerryUsers;
            besUsersStats.QuotaUsedValue = stats.CreatedBlackBerryUsers;
            if (stats.AllocatedBlackBerryUsers != -1) besUsersStats.QuotaAvailable = stats.AllocatedBlackBerryUsers - stats.CreatedBlackBerryUsers;

            lnkBESUsers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "blackberry_users",
            "SpaceID=" + PanelSecurity.PackageId.ToString());
        }
        private void BindLyncStats(OrganizationStatistics stats)
        {
            lyncUsersStats.QuotaValue = stats.AllocatedLyncUsers;
            lyncUsersStats.QuotaUsedValue = stats.CreatedLyncUsers;
            if (stats.AllocatedLyncUsers != -1) lyncUsersStats.QuotaAvailable = stats.AllocatedLyncUsers - stats.CreatedLyncUsers;

            lnkLyncUsers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "lync_users",
            "SpaceID=" + PanelSecurity.PackageId.ToString());
        }
        private void BindCRM2013Stats(OrganizationStatistics stats)
        {
            lnkProfessionalCRMUsers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "crmusers",
                "SpaceID=" + PanelSecurity.PackageId);

            lnkBasicCRMUsers.NavigateUrl = lnkCRMUsers.NavigateUrl;
            lnkEssentialCRMUsers.NavigateUrl = lnkCRMUsers.NavigateUrl;

            lnkCRM2013DBSize.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "crm_storage_settings",
                "SpaceID=" + PanelSecurity.PackageId);

            crmProfessionalUsersStats.QuotaUsedValue = stats.CreatedProfessionalCRMUsers;
            crmProfessionalUsersStats.QuotaValue = stats.AllocatedProfessionalCRMUsers;

            crmBasicUsersStats.QuotaUsedValue = stats.CreatedBasicCRMUsers;
            crmBasicUsersStats.QuotaValue = stats.AllocatedBasicCRMUsers;

            crmEssentialUsersStats.QuotaUsedValue = stats.CreatedEssentialCRMUsers;
            crmEssentialUsersStats.QuotaValue = stats.AllocatedEssentialCRMUsers;

            crm2013DBSize.QuotaUsedValue = Convert.ToInt32(stats.UsedCRMDiskSpace > 0 ? stats.UsedCRMDiskSpace / (1024 * 1024) : -1);
            crm2013DBSize.QuotaValue = Convert.ToInt32(stats.AllocatedCRMDiskSpace > 0 ? stats.AllocatedCRMDiskSpace / (1024 * 1024) : -1);
        }
        private static OrganizationStatistics GetOrganizationStatisticsInternal(int itemId, bool byOrganization)
        {
            #region Demo Mode
            if (IsDemoMode)
            {
                OrganizationStatistics stats = new OrganizationStatistics();
                stats.AllocatedMailboxes = 10;
                stats.CreatedMailboxes = 4;
                stats.AllocatedContacts = 4;
                stats.CreatedContacts = 2;
                stats.AllocatedDistributionLists = 5;
                stats.CreatedDistributionLists = 1;
                stats.AllocatedPublicFolders = 40;
                stats.CreatedPublicFolders = 4;
                stats.AllocatedDomains = 5;
                stats.CreatedDomains = 2;
                stats.AllocatedDiskSpace = 200;
                stats.UsedDiskSpace = 70;
                return stats;
            }
            #endregion

            // place log record
            TaskManager.StartTask("EXCHANGE", "GET_ORG_STATS", itemId);

            try
            {
                Organization org = GetOrganization(itemId);
                if (org == null)
                    return null;

                // Log Extension
                LogExtension.WriteVariables(new {byOrganization});

                OrganizationStatistics stats = new OrganizationStatistics();

                if (byOrganization)
                {
                    OrganizationStatistics tempStats = ObjectUtils.FillObjectFromDataReader<OrganizationStatistics>(DataProvider.GetExchangeOrganizationStatistics(org.Id));

                    stats.CreatedMailboxes = tempStats.CreatedMailboxes;
                    stats.CreatedContacts = tempStats.CreatedContacts;
                    stats.CreatedDistributionLists = tempStats.CreatedDistributionLists;
                    stats.CreatedDomains = tempStats.CreatedDomains;
                    stats.CreatedPublicFolders = tempStats.CreatedPublicFolders;
                    stats.UsedDiskSpace = tempStats.UsedDiskSpace;
                    stats.UsedLitigationHoldSpace = tempStats.UsedLitigationHoldSpace;
                    stats.UsedArchingStorage = tempStats.UsedArchingStorage;

                    stats.CreatedSharedMailboxes = tempStats.CreatedSharedMailboxes;
                    stats.CreatedResourceMailboxes = tempStats.CreatedResourceMailboxes;
                }
                else
                {
                    UserInfo user = ObjectUtils.FillObjectFromDataReader<UserInfo>(DataProvider.GetUserByExchangeOrganizationIdInternally(org.Id));
                    List<PackageInfo> Packages = PackageController.GetPackages(user.UserId);

                    if ((Packages != null) & (Packages.Count > 0))
                    {
                        foreach (PackageInfo Package in Packages)
                        {
                            List<Organization> orgs = null;

                            orgs = GetExchangeOrganizations(Package.PackageId, false);

                            if ((orgs != null) & (orgs.Count > 0))
                            {
                                foreach (Organization o in orgs)
                                {
                                    // Log Extension
                                    LogExtension.WriteVariable("Nested Org", o.Name);
                                   
                                    OrganizationStatistics tempStats = ObjectUtils.FillObjectFromDataReader<OrganizationStatistics>(DataProvider.GetExchangeOrganizationStatistics(o.Id));

                                    stats.CreatedMailboxes += tempStats.CreatedMailboxes;
                                    stats.CreatedContacts += tempStats.CreatedContacts;
                                    stats.CreatedDistributionLists += tempStats.CreatedDistributionLists;
                                    stats.CreatedDomains += tempStats.CreatedDomains;
                                    stats.CreatedPublicFolders += tempStats.CreatedPublicFolders;
                                    stats.UsedDiskSpace += tempStats.UsedDiskSpace;
                                    stats.UsedLitigationHoldSpace += tempStats.UsedLitigationHoldSpace;
                                    stats.UsedArchingStorage += tempStats.UsedArchingStorage;

                                    stats.CreatedSharedMailboxes += tempStats.CreatedSharedMailboxes;
                                    stats.CreatedResourceMailboxes += tempStats.CreatedResourceMailboxes;
                                }
                            }
                        }
                    }
                }

                // disk space
                //stats.UsedDiskSpace = org.DiskSpace;


                // allocated quotas
                PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
                if (byOrganization)
                {
                    stats.AllocatedMailboxes = cntx.Quotas[Quotas.EXCHANGE2007_MAILBOXES].QuotaAllocatedValuePerOrganization;
                    stats.AllocatedContacts = cntx.Quotas[Quotas.EXCHANGE2007_CONTACTS].QuotaAllocatedValuePerOrganization;
                    stats.AllocatedDistributionLists = cntx.Quotas[Quotas.EXCHANGE2007_DISTRIBUTIONLISTS].QuotaAllocatedValuePerOrganization;
                    stats.AllocatedPublicFolders = cntx.Quotas[Quotas.EXCHANGE2007_PUBLICFOLDERS].QuotaAllocatedValuePerOrganization;
                    stats.AllocatedDiskSpace = cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValuePerOrganization;
                    stats.AllocatedLitigationHoldSpace = cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValuePerOrganization;
                    stats.AllocatedArchingStorage = cntx.Quotas[Quotas.EXCHANGE2013_ARCHIVINGSTORAGE].QuotaAllocatedValuePerOrganization;

                    stats.AllocatedSharedMailboxes = cntx.Quotas[Quotas.EXCHANGE2013_SHAREDMAILBOXES].QuotaAllocatedValuePerOrganization;
                    stats.AllocatedResourceMailboxes = cntx.Quotas[Quotas.EXCHANGE2013_RESOURCEMAILBOXES].QuotaAllocatedValuePerOrganization;
                }
                else
                {
                    stats.AllocatedMailboxes = cntx.Quotas[Quotas.EXCHANGE2007_MAILBOXES].QuotaAllocatedValue;
                    stats.AllocatedContacts = cntx.Quotas[Quotas.EXCHANGE2007_CONTACTS].QuotaAllocatedValue;
                    stats.AllocatedDistributionLists = cntx.Quotas[Quotas.EXCHANGE2007_DISTRIBUTIONLISTS].QuotaAllocatedValue;
                    stats.AllocatedPublicFolders = cntx.Quotas[Quotas.EXCHANGE2007_PUBLICFOLDERS].QuotaAllocatedValue;
                    stats.AllocatedDiskSpace = cntx.Quotas[Quotas.EXCHANGE2007_DISKSPACE].QuotaAllocatedValue;
                    stats.AllocatedLitigationHoldSpace = cntx.Quotas[Quotas.EXCHANGE2007_RECOVERABLEITEMSSPACE].QuotaAllocatedValue;
                    stats.AllocatedArchingStorage = cntx.Quotas[Quotas.EXCHANGE2013_ARCHIVINGSTORAGE].QuotaAllocatedValue;

                    stats.AllocatedSharedMailboxes = cntx.Quotas[Quotas.EXCHANGE2013_SHAREDMAILBOXES].QuotaAllocatedValue;
                    stats.AllocatedResourceMailboxes = cntx.Quotas[Quotas.EXCHANGE2013_RESOURCEMAILBOXES].QuotaAllocatedValue;
                }
              
                return stats;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
 private void BindServiceLevelsStats(OrganizationStatistics stats)
 {
     List<ServiceLevelQuotaValueInfo> serviceLevelQuotas = new List<ServiceLevelQuotaValueInfo>();
     foreach (var quota in stats.ServiceLevels)
     {
         serviceLevelQuotas.Add(new ServiceLevelQuotaValueInfo
         {
             QuotaName = quota.QuotaName,
             QuotaDescription = quota.QuotaDescription + " in this Organization:",
             QuotaTypeId = quota.QuotaTypeId,
             QuotaValue = quota.QuotaAllocatedValue,
             QuotaUsedValue = quota.QuotaUsedValue,
             QuotaAvailable = quota.QuotaAllocatedValue - quota.QuotaUsedValue
         });
     }
     dlServiceLevelQuotas.DataSource = serviceLevelQuotas;
     dlServiceLevelQuotas.DataBind();
 }