internal static ExchangeServer GetExchangeServer(int exchangeServiceId, int organizationServiceId)
        {
            ExchangeServer ws = new ExchangeServer();

            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;
        }
        private static void SetMailBoxRetentionPolicyAndArchiving(int itemId, int mailboxPlanId, int retentionPolicyId, string accountName, ExchangeServer exchange, string orgId, ResultObject result, bool EnableArchiving)
        {

            long archiveQuotaKB = 0;
            long archiveWarningQuotaKB = 0;
            string RetentionPolicy = "";

            ExchangeMailboxPlan mailboxPlan = GetExchangeMailboxPlan(itemId, mailboxPlanId);
            if ( mailboxPlan != null)
            {
                archiveQuotaKB = mailboxPlan.ArchiveSizeMB != -1 ? ((long)mailboxPlan.ArchiveSizeMB * 1024) : -1;
                archiveWarningQuotaKB = mailboxPlan.ArchiveSizeMB != -1 ? (((long)mailboxPlan.ArchiveWarningPct * (long) mailboxPlan.ArchiveSizeMB * 1024) / 100) : -1;
            }


            if (retentionPolicyId > 0)
            {
                ExchangeMailboxPlan retentionPolicy = GetExchangeMailboxPlan(itemId, retentionPolicyId);
                if (retentionPolicy != null)
                {
                    UpdateExchangeRetentionPolicy(itemId, retentionPolicyId, result);
                }

            }
            ResultObject res = exchange.SetMailBoxArchiving(orgId, accountName, EnableArchiving, archiveQuotaKB, archiveWarningQuotaKB, RetentionPolicy);
            if (res != null)
            {
                result.ErrorCodes.AddRange(res.ErrorCodes);
                result.IsSuccess = result.IsSuccess && res.IsSuccess;
            }
        }