public SharePointSiteDiskSpace[] Enterprise_CalculateSharePointSitesDiskSpace(int itemId, out int errorCode)
 {
     return(HostedSharePointServerEntController.CalculateSharePointSitesDiskSpace(itemId, out errorCode));
 }
Esempio n. 2
0
        public ServiceProviderItemDiskSpace[] CalculateItems(int serviceId, List <ServiceProviderItem> items)
        {
            // convert items to SoapObjects
            List <SoapServiceProviderItem> objItems = new List <SoapServiceProviderItem>();

            //hack for organization... Refactoring!!!


            List <ServiceProviderItemDiskSpace> organizationDiskSpaces = new List <ServiceProviderItemDiskSpace>();

            foreach (ServiceProviderItem item in items)
            {
                long size = 0;
                if (item is Organization)
                {
                    Organization org = (Organization)item;

                    //Exchange DiskSpace
                    if (!string.IsNullOrEmpty(org.GlobalAddressList))
                    {
                        int exchangeServiceId = GetExchangeServiceID(org.PackageId);
                        if (exchangeServiceId > 0)
                        {
                            ServiceProvider exchangeProvider = ExchangeServerController.GetExchangeServiceProvider(exchangeServiceId, item.ServiceId);

                            SoapServiceProviderItem        soapOrg        = SoapServiceProviderItem.Wrap(org);
                            ServiceProviderItemDiskSpace[] itemsDiskspace =
                                exchangeProvider.GetServiceItemsDiskSpace(new SoapServiceProviderItem[] { soapOrg });

                            if (itemsDiskspace != null && itemsDiskspace.Length > 0)
                            {
                                size += itemsDiskspace[0].DiskSpace;
                            }
                        }
                    }

                    // Crm DiskSpace
                    if (org.CrmOrganizationId != Guid.Empty)
                    {
                        //CalculateCrm DiskSpace
                    }

                    //SharePoint DiskSpace

                    int res;

                    PackageContext cntx = PackageController.GetPackageContext(org.PackageId);

                    if (cntx.Groups.ContainsKey(ResourceGroups.SharepointFoundationServer))
                    {
                        SharePointSiteDiskSpace[] sharePointSiteDiskSpaces =
                            HostedSharePointServerController.CalculateSharePointSitesDiskSpace(org.Id, out res);
                        if (res == 0)
                        {
                            foreach (SharePointSiteDiskSpace currecnt in sharePointSiteDiskSpaces)
                            {
                                size += currecnt.DiskSpace;
                            }
                        }
                    }

                    if (cntx.Groups.ContainsKey(ResourceGroups.SharepointEnterpriseServer))
                    {
                        SharePointSiteDiskSpace[] sharePointSiteDiskSpaces =
                            HostedSharePointServerEntController.CalculateSharePointSitesDiskSpace(org.Id, out res);
                        if (res == 0)
                        {
                            foreach (SharePointSiteDiskSpace currecnt in sharePointSiteDiskSpaces)
                            {
                                size += currecnt.DiskSpace;
                            }
                        }
                    }

                    ServiceProviderItemDiskSpace tmp = new ServiceProviderItemDiskSpace();
                    tmp.ItemId    = item.Id;
                    tmp.DiskSpace = size;
                    organizationDiskSpaces.Add(tmp);
                }
                else
                {
                    objItems.Add(SoapServiceProviderItem.Wrap(item));
                }
            }


            int attempt  = 0;
            int ATTEMPTS = 3;

            while (attempt < ATTEMPTS)
            {
                // increment attempt
                attempt++;

                try
                {
                    // send packet for calculation
                    // invoke service provider
                    //TaskManager.Write(String.Format("{0} - Invoke GetServiceItemsDiskSpace method ('{1}' items) - {2} attempt",
                    //    DateTime.Now, objItems.Count, attempt));

                    if (objItems.Count > 0)
                    {
                        ServiceProvider prov = new ServiceProvider();
                        ServiceProviderProxy.Init(prov, serviceId);
                        ServiceProviderItemDiskSpace[] itemsDiskSpace = prov.GetServiceItemsDiskSpace(objItems.ToArray());
                        if (itemsDiskSpace != null && itemsDiskSpace.Length > 0)
                        {
                            organizationDiskSpaces.AddRange(itemsDiskSpace);
                        }
                    }

                    return(organizationDiskSpaces.ToArray());
                }
                catch (Exception ex)
                {
                    TaskManager.WriteError(ex.ToString());
                }
            }

            throw new Exception("The number of attemtps has been reached. The package calculation has been aborted.");
        }