internal static ServiceProvider GetExchangeServiceProvider(int exchangeServiceId, int organizationServiceId)
        {
            ServiceProvider ws = new ServiceProvider();

            ServiceProviderProxy.Init(ws, exchangeServiceId);

            string[] exchangeSettings = ws.ServiceProviderSettingsSoapHeaderValue.Settings;

            List<string> resSettings = new List<string>(exchangeSettings);

            string orgPrimaryDomainController = GetPrimaryDomainController(organizationServiceId);

            ExtendExchangeSettings(resSettings, orgPrimaryDomainController);
            ws.ServiceProviderSettingsSoapHeaderValue.Settings = resSettings.ToArray();
            return ws;
        }
Exemplo n.º 2
0
        private void ProcessServiceItems(bool changeState, bool enabled,
            int serviceId, List<ServiceProviderItem> items)
        {
            string methodName = changeState ? "ChangeServiceItemsState" : "DeleteServiceItems";

            int PACKET_SIZE = 10;
            int ATTEMPTS = 3;

            TaskManager.Write(String.Format("Start analyze {0} service ({1} items)",
                serviceId, items.Count));

            try
            {
                // convert items to SoapObjects by packets of 0
                int startItem = 0;
                List<SoapServiceProviderItem> objItems = new List<SoapServiceProviderItem>();

                for (int i = 0; i < items.Count; i++)
                {
                    // add to the packet
                    objItems.Add(SoapServiceProviderItem.Wrap(items[i]));

                    if (((i > 0) && (i % PACKET_SIZE == 0))
                        || i == (items.Count - 1)) // packet is ready
                    {
                        if (objItems.Count == 0)
                            continue;

                        int attempt = 0;
                        bool success = false;
                        while (attempt < ATTEMPTS)
                        {
                            // increment attempt
                            attempt++;

                            try
                            {
                                // send packet for calculation
                                // invoke service provider
                                TaskManager.Write(String.Format("Invoke {0} method ('{1}' - '{2}' items) - {3} attempt",
                                    methodName, items[startItem].Name, items[i].Name, attempt));
                                
                                ServiceProvider prov = new ServiceProvider();
                                ServiceProviderProxy.Init(prov, serviceId);

                                if (changeState)
                                    prov.ChangeServiceItemsState(objItems.ToArray(), enabled);
                                else
                                    prov.DeleteServiceItems(objItems.ToArray());

                                // exit from the loop
                                success = true;
                                break;
                            }
                            catch (Exception ex)
                            {
                                TaskManager.WriteWarning(ex.ToString());
                            }
                        }

                        if (!success)
                            throw new Exception("The number of attemtps has been reached. The whole operation aborted.");

                        // reset packet counter
                        startItem = i + 1;
                        objItems.Clear();
                    }
                } // end for items
            }
            catch (Exception ex)
            {
                // log exception
                TaskManager.WriteWarning(ex.ToString());
            }

            TaskManager.Write(String.Format("End analyze {0} service ({1} items)",
                serviceId, items.Count));
        }
        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);
                        ServiceProvider exchangeProvider = ExchangeServerController.GetExchangeServiceProvider(exchangeServiceId, item.Id);                                                

                        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.HostedSharePoint))
                    {
                        SharePointSiteDiskSpace[] sharePointSiteDiskSpaces =
                            HostedSharePointServerController.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));

                    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.");
        }
        public ServiceProviderItemBandwidth[] CalculateItems(int serviceId, List<ServiceProviderItem> items,
            DateTime since)
        {
            // convert items to SoapObjects
            List<SoapServiceProviderItem> objItems = new List<SoapServiceProviderItem>();
            foreach (ServiceProviderItem item in items)
                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));

                    ServiceProvider prov = new ServiceProvider();
                    ServiceProviderProxy.Init(prov, serviceId);
                    return prov.GetServiceItemsBandwidth(objItems.ToArray(), since);
                }
                catch (Exception ex)
                {
                    TaskManager.WriteError(ex.ToString());
                }
            }

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