示例#1
0
        public static LyncFederationDomain[] GetFederationDomains(int itemId)
        {
            // place log record
            TaskManager.StartTask("LYNC", "GET_LYNC_FEDERATIONDOMAINS", itemId);

            LyncFederationDomain[] lyncFederationDomains = null;

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

                int        lyncServiceId = GetLyncServiceID(org.PackageId);
                LyncServer lync          = GetLyncServer(lyncServiceId, org.ServiceId);

                lyncFederationDomains = lync.GetFederationDomains(org.OrganizationId);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }

            return(lyncFederationDomains);
        }
示例#2
0
        public static int DeleteOrganization(int itemId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

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

            // place log record
            TaskManager.StartTask("LYNC", "DELETE_ORG", itemId);

            try
            {
                // delete organization in Exchange
                //System.Threading.Thread.Sleep(5000);
                Organization org = (Organization)PackageController.GetPackageItem(itemId);

                int        lyncServiceId = GetLyncServiceID(org.PackageId);
                LyncServer lync          = GetLyncServer(lyncServiceId, org.ServiceId);

                bool successful = lync.DeleteOrganization(org.OrganizationId, org.DefaultDomain);

                return(successful ? 0 : BusinessErrorCodes.ERROR_LYNC_DELETE_SOME_PROBLEMS);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
示例#3
0
        public static LyncUserResult SetUserLyncPlan(int itemId, int accountId, int lyncUserPlanId)
        {
            LyncUserResult res = TaskManager.StartResultTask <LyncUserResult>("LYNC", "SET_LYNC_USER_LYNCPLAN");

            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                TaskManager.CompleteResultTask(res, LyncErrorCodes.NOT_AUTHORIZED);
                return(res);
            }

            try
            {
                Organization org = (Organization)PackageController.GetPackageItem(itemId);
                if (org == null)
                {
                    throw new ApplicationException(
                              string.Format("Organization is null. ItemId={0}", itemId));
                }

                int        lyncServiceId = GetLyncServiceID(org.PackageId);
                LyncServer lync          = GetLyncServer(lyncServiceId, org.ServiceId);

                LyncUserPlan plan = GetLyncUserPlan(itemId, lyncUserPlanId);

                OrganizationUser user;
                user = OrganizationController.GetAccount(itemId, accountId);

                if (!lync.SetLyncUserPlan(org.OrganizationId, user.UserPrincipalName, plan))
                {
                    TaskManager.CompleteResultTask(res, LyncErrorCodes.CANNOT_ADD_LYNC_USER);
                    return(res);
                }

                try
                {
                    DataProvider.SetLyncUserLyncUserplan(accountId, lyncUserPlanId);
                }
                catch (Exception ex)
                {
                    TaskManager.CompleteResultTask(res, LyncErrorCodes.CANNOT_ADD_LYNC_USER_TO_DATABASE, ex);
                    return(res);
                }

                res.IsSuccess = true;
                TaskManager.CompleteResultTask();
                return(res);
            }
            catch (Exception ex)
            {
                TaskManager.CompleteResultTask(res, LyncErrorCodes.CANNOT_UPDATE_LYNC_USER, ex);
                return(res);
            }
        }
示例#4
0
        public static string[] GetPolicyList(int itemId, LyncPolicyType type, string name)
        {
            string[] ret = null;
            try
            {
                if (itemId == -1)
                {
                    // policy list in all lync servers
                    List <string>     allpolicylist = new List <string>();
                    List <ServerInfo> servers       = ServerController.GetAllServers();
                    foreach (ServerInfo server in servers)
                    {
                        List <ServiceInfo> services = ServerController.GetServicesByServerIdGroupName(server.ServerId, ResourceGroups.Lync);
                        foreach (ServiceInfo service in services)
                        {
                            LyncServer lync   = GetLyncServer(service.ServiceId, -1);
                            string[]   values = lync.GetPolicyList(type, name);
                            foreach (string val in values)
                            {
                                if (allpolicylist.IndexOf(val) == -1)
                                {
                                    allpolicylist.Add(val);
                                }
                            }
                        }
                    }
                    ret = allpolicylist.ToArray();
                }
                else
                {
                    Organization org = (Organization)PackageController.GetPackageItem(itemId);

                    int        lyncServiceId = GetLyncServiceID(org.PackageId);
                    LyncServer lync          = GetLyncServer(lyncServiceId, org.ServiceId);

                    ret = lync.GetPolicyList(type, name);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
            }

            return(ret);
        }
示例#5
0
        public static LyncServer GetLyncServer(int lyncServiceId, int organizationServiceId)
        {
            LyncServer ws = new LyncServer();

            ServiceProviderProxy.Init(ws, lyncServiceId);

            string[] lyncSettings = ws.ServiceProviderSettingsSoapHeaderValue.Settings;

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

            if (organizationServiceId != -1)
            {
                ExtendLyncSettings(resSettings, "primarydomaincontroller", GetProviderProperty(organizationServiceId, "primarydomaincontroller"));
                ExtendLyncSettings(resSettings, "rootou", GetProviderProperty(organizationServiceId, "rootou"));
            }
            ws.ServiceProviderSettingsSoapHeaderValue.Settings = resSettings.ToArray();
            return(ws);
        }
示例#6
0
        public static LyncUser GetLyncUserGeneralSettings(int itemId, int accountId)
        {
            TaskManager.StartTask("LYNC", "GET_LYNC_USER_GENERAL_SETTINGS");

            LyncUser user = null;

            try
            {
                Organization org = (Organization)PackageController.GetPackageItem(itemId);
                if (org == null)
                {
                    throw new ApplicationException(
                              string.Format("Organization is null. ItemId={0}", itemId));
                }

                int        lyncServiceId = GetLyncServiceID(org.PackageId);
                LyncServer lync          = GetLyncServer(lyncServiceId, org.ServiceId);

                OrganizationUser usr;
                usr = OrganizationController.GetAccount(itemId, accountId);

                if (usr != null)
                {
                    user = lync.GetLyncUserGeneralSettings(org.OrganizationId, usr.UserPrincipalName);
                }

                if (user != null)
                {
                    LyncUserPlan plan = ObjectUtils.FillObjectFromDataReader <LyncUserPlan>(DataProvider.GetLyncUserPlanByAccountId(accountId));

                    if (plan != null)
                    {
                        user.LyncUserPlanId   = plan.LyncUserPlanId;
                        user.LyncUserPlanName = plan.LyncUserPlanName;
                    }
                }
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            TaskManager.CompleteTask();
            return(user);
        }
示例#7
0
        public static LyncUserResult RemoveFederationDomain(int itemId, string domainName)
        {
            LyncUserResult res = TaskManager.StartResultTask <LyncUserResult>("LYNC", "REMOVE_LYNC_FEDERATIONDOMAIN", itemId, new BackgroundTaskParameter("domainName", domainName));

            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                TaskManager.CompleteResultTask(res, LyncErrorCodes.NOT_AUTHORIZED);
                return(res);
            }

            try
            {
                Organization org = (Organization)PackageController.GetPackageItem(itemId);
                if (org == null)
                {
                    throw new ApplicationException(
                              string.Format("Organization is null. ItemId={0}", itemId));
                }

                int        lyncServiceId = GetLyncServiceID(org.PackageId);
                LyncServer lync          = GetLyncServer(lyncServiceId, org.ServiceId);

                if (org.OrganizationId.ToLower() == domainName.ToLower())
                {
                    TaskManager.CompleteResultTask(res, LyncErrorCodes.CANNOT_REMOVE_LYNC_FEDERATIONDOMAIN);
                    return(res);
                }

                lync.RemoveFederationDomain(org.OrganizationId, domainName);
            }
            catch (Exception ex)
            {
                TaskManager.CompleteResultTask(res, LyncErrorCodes.CANNOT_REMOVE_LYNC_FEDERATIONDOMAIN, ex);
                return(res);
            }

            TaskManager.CompleteResultTask();
            return(res);
        }
示例#8
0
        private void Enable_CsComputer()
        {
            int[] lyncServiceIds;

            LyncController.GetLyncServices(lyncServiceId, out lyncServiceIds);

            foreach (int id in lyncServiceIds)
            {
                LyncServer lync = null;
                try
                {
                    lync = LyncController.GetLyncServer(id, organizationServiceId);
                    if (lync != null)
                    {
                        lync.ReloadConfiguration();
                    }
                }
                catch (Exception exe)
                {
                    TaskManager.WriteError(exe);
                    continue;
                }
            }
        }
示例#9
0
        public static LyncUserResult AddFederationDomain(int itemId, string domainName, string proxyFqdn)
        {
            List <BackgroundTaskParameter> parameters = new List <BackgroundTaskParameter>();

            parameters.Add(new BackgroundTaskParameter("domainName", domainName));
            parameters.Add(new BackgroundTaskParameter("proxyFqdn", proxyFqdn));

            LyncUserResult res = TaskManager.StartResultTask <LyncUserResult>("LYNC", "ADD_LYNC_FEDERATIONDOMAIN", itemId, parameters);

            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                TaskManager.CompleteResultTask(res, LyncErrorCodes.NOT_AUTHORIZED);
                return(res);
            }


            try
            {
                Organization org = (Organization)PackageController.GetPackageItem(itemId);
                if (org == null)
                {
                    throw new ApplicationException(
                              string.Format("Organization is null. ItemId={0}", itemId));
                }

                int        lyncServiceId = GetLyncServiceID(org.PackageId);
                LyncServer lync          = GetLyncServer(lyncServiceId, org.ServiceId);

                if (string.IsNullOrEmpty(org.LyncTenantId))
                {
                    PackageContext cntx = PackageController.GetPackageContext(org.PackageId);

                    org.LyncTenantId = lync.CreateOrganization(org.OrganizationId,
                                                               org.DefaultDomain,
                                                               Convert.ToBoolean(cntx.Quotas[Quotas.LYNC_CONFERENCING].QuotaAllocatedValue),
                                                               Convert.ToBoolean(cntx.Quotas[Quotas.LYNC_ALLOWVIDEO].QuotaAllocatedValue),
                                                               Convert.ToInt32(cntx.Quotas[Quotas.LYNC_MAXPARTICIPANTS].QuotaAllocatedValue),
                                                               Convert.ToBoolean(cntx.Quotas[Quotas.LYNC_FEDERATION].QuotaAllocatedValue),
                                                               Convert.ToBoolean(cntx.Quotas[Quotas.LYNC_ENTERPRISEVOICE].QuotaAllocatedValue));

                    if (string.IsNullOrEmpty(org.LyncTenantId))
                    {
                        TaskManager.CompleteResultTask(res, LyncErrorCodes.CANNOT_ENABLE_ORG);
                        return(res);
                    }
                    else
                    {
                        PackageController.UpdatePackageItem(org);
                    }
                }

                lync = GetLyncServer(lyncServiceId, org.ServiceId);

                bool bDomainExists             = false;
                LyncFederationDomain[] domains = GetFederationDomains(itemId);
                foreach (LyncFederationDomain d in domains)
                {
                    if (d.DomainName.ToLower() == domainName.ToLower())
                    {
                        bDomainExists = true;
                        break;
                    }
                }

                if (!bDomainExists)
                {
                    lync.AddFederationDomain(org.OrganizationId, domainName.ToLower(), proxyFqdn);
                }
            }
            catch (Exception ex)
            {
                TaskManager.CompleteResultTask(res, LyncErrorCodes.CANNOT_ADD_LYNC_FEDERATIONDOMAIN, ex);
                return(res);
            }

            TaskManager.CompleteResultTask();
            return(res);
        }
示例#10
0
        public static LyncUserResult SetLyncUserGeneralSettings(int itemId, int accountId, string sipAddress, string lineUri)
        {
            LyncUserResult res = TaskManager.StartResultTask <LyncUserResult>("LYNC", "SET_LYNC_USER_GENERAL_SETTINGS");

            string PIN = "";

            string[] uriAndPin = ("" + lineUri).Split(':');

            if (uriAndPin.Length > 0)
            {
                lineUri = uriAndPin[0];
            }
            if (uriAndPin.Length > 1)
            {
                PIN = uriAndPin[1];
            }

            LyncUser user = null;

            try
            {
                Organization org = (Organization)PackageController.GetPackageItem(itemId);
                if (org == null)
                {
                    throw new ApplicationException(
                              string.Format("Organization is null. ItemId={0}", itemId));
                }

                int        lyncServiceId = GetLyncServiceID(org.PackageId);
                LyncServer lync          = GetLyncServer(lyncServiceId, org.ServiceId);

                OrganizationUser usr;
                usr = OrganizationController.GetAccount(itemId, accountId);

                if (usr != null)
                {
                    user = lync.GetLyncUserGeneralSettings(org.OrganizationId, usr.UserPrincipalName);
                }

                if (user != null)
                {
                    LyncUserPlan plan = ObjectUtils.FillObjectFromDataReader <LyncUserPlan>(DataProvider.GetLyncUserPlanByAccountId(accountId));

                    if (plan != null)
                    {
                        user.LyncUserPlanId   = plan.LyncUserPlanId;
                        user.LyncUserPlanName = plan.LyncUserPlanName;
                    }


                    if (!string.IsNullOrEmpty(sipAddress))
                    {
                        if (user.SipAddress != sipAddress)
                        {
                            if (sipAddress != usr.UserPrincipalName)
                            {
                                if (DataProvider.LyncUserExists(accountId, sipAddress))
                                {
                                    TaskManager.CompleteResultTask(res, LyncErrorCodes.ADDRESS_ALREADY_USED);
                                    return(res);
                                }
                            }
                            user.SipAddress = sipAddress;
                        }
                    }

                    user.LineUri = lineUri;
                    user.PIN     = PIN;

                    lync.SetLyncUserGeneralSettings(org.OrganizationId, usr.UserPrincipalName, user);

                    DataProvider.UpdateLyncUser(accountId, sipAddress);
                }
            }
            catch (Exception ex)
            {
                TaskManager.CompleteResultTask(res, LyncErrorCodes.FAILED_SET_SETTINGS, ex);
                return(res);
            }

            res.IsSuccess = true;
            TaskManager.CompleteResultTask();
            return(res);
        }