protected void btnCreate_Click(object sender, EventArgs e)
        {
            int            accountId = userSelector.GetAccountId();
            LyncUserResult res       = ES.Services.Lync.CreateLyncUser(PanelRequest.ItemID, accountId, Convert.ToInt32(planSelector.planId));

            if (res.IsSuccess && res.ErrorCodes.Count == 0)
            {
                PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId);
                bool           enterpriseVoiceQuota = Utils.CheckQouta(Quotas.LYNC_ENTERPRISEVOICE, cntx);

                string lineUri = "";
                if ((enterpriseVoiceQuota) & (ddlPhoneNumber.Items.Count != 0))
                {
                    lineUri = ddlPhoneNumber.SelectedItem.Text + ":" + tbPin.Text;
                }

                //#1
                LyncUser lyncUser = ES.Services.Lync.GetLyncUserGeneralSettings(PanelRequest.ItemID, accountId);
                ES.Services.Lync.SetLyncUserGeneralSettings(PanelRequest.ItemID, accountId, lyncUser.SipAddress, lineUri);

                Response.Redirect(EditUrl("AccountID", accountId.ToString(), "edit_lync_user",
                                          "SpaceID=" + PanelSecurity.PackageId,
                                          "ItemID=" + PanelRequest.ItemID));
            }
            else
            {
                messageBox.ShowMessage(res, "CREATE_LYNC_USER", "LYNC");
            }
        }
Exemple #2
0
        private void BindItems()
        {
            // get settings
            LyncUser lyncUser = ES.Services.Lync.GetLyncUserGeneralSettings(PanelRequest.ItemID, PanelRequest.AccountID);

            // title
            litDisplayName.Text = lyncUser.DisplayName;

            planSelector.planId         = lyncUser.LyncUserPlanId.ToString();
            lyncUserSettings.sipAddress = lyncUser.SipAddress;

            Utils.SelectListItem(ddlPhoneNumber, lyncUser.LineUri);

            PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId);

            OrganizationUser user = ES.Services.Organizations.GetUserGeneralSettings(PanelRequest.ItemID,
                                                                                     PanelRequest.AccountID);

            if (user.LevelId > 0 && cntx.Groups.ContainsKey(ResourceGroups.ServiceLevels))
            {
                WebsitePanel.EnterpriseServer.Base.HostedSolution.ServiceLevel serviceLevel = ES.Services.Organizations.GetSupportServiceLevel(user.LevelId);

                litServiceLevel.Visible = true;
                litServiceLevel.Text    = serviceLevel.LevelName;
                litServiceLevel.ToolTip = serviceLevel.LevelDescription;
            }
            imgVipUser.Visible = user.IsVIP && cntx.Groups.ContainsKey(ResourceGroups.ServiceLevels);
        }
Exemple #3
0
 public LyncUser GetLyncUserGeneralSettings(string organizationId, string userUpn)
 {
     try
     {
         Log.WriteStart("{0}.GetLyncUserGeneralSettings", ProviderSettings.ProviderName);
         LyncUser ret = Lync.GetLyncUserGeneralSettings(organizationId, userUpn);
         Log.WriteEnd("{0}.GetLyncUserGeneralSettings", ProviderSettings.ProviderName);
         return(ret);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("Error: {0}.GetLyncUserGeneralSettings", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
0
        public static LyncUserResult CreateLyncUser(int itemId, int accountId, int lyncUserPlanId)
        {
            LyncUserResult res = TaskManager.StartResultTask <LyncUserResult>("LYNC", "CREATE_LYNC_USER");

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

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


            LyncUser retLyncUser = new LyncUser();
            bool     isLyncUser;

            isLyncUser = DataProvider.CheckLyncUserExists(accountId);
            if (isLyncUser)
            {
                TaskManager.CompleteResultTask(res, LyncErrorCodes.USER_IS_ALREADY_LYNC_USER);
                return(res);
            }

            OrganizationUser user;

            user = OrganizationController.GetAccount(itemId, accountId);
            if (user == null)
            {
                TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT);
                return(res);
            }

            user = OrganizationController.GetUserGeneralSettings(itemId, accountId);
            if (string.IsNullOrEmpty(user.FirstName))
            {
                TaskManager.CompleteResultTask(res, LyncErrorCodes.USER_FIRST_NAME_IS_NOT_SPECIFIED);
                return(res);
            }

            if (string.IsNullOrEmpty(user.LastName))
            {
                TaskManager.CompleteResultTask(res, LyncErrorCodes.USER_LAST_NAME_IS_NOT_SPECIFIED);
                return(res);
            }

            bool quota = CheckQuota(itemId);

            if (!quota)
            {
                TaskManager.CompleteResultTask(res, LyncErrorCodes.USER_QUOTA_HAS_BEEN_REACHED);
                return(res);
            }


            LyncServer lync;

            try
            {
                bool bReloadConfiguration = false;

                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);
                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
                    {
                        DomainInfo domain = ServerController.GetDomain(org.DefaultDomain);

                        //Add the service records
                        if (domain != null)
                        {
                            if (domain.ZoneItemId != 0)
                            {
                                ServerController.AddServiceDNSRecords(org.PackageId, ResourceGroups.Lync, domain, "");
                            }
                        }

                        PackageController.UpdatePackageItem(org);

                        bReloadConfiguration = true;
                    }
                }

                if (lync.GetOrganizationTenantId(org.OrganizationId) == string.Empty)
                {
                    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);

                        bReloadConfiguration = true;
                    }
                }


                LyncUserPlan plan = GetLyncUserPlan(itemId, lyncUserPlanId);

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

                if (bReloadConfiguration)
                {
                    LyncControllerAsync userWorker = new LyncControllerAsync();
                    userWorker.LyncServiceId         = lyncServiceId;
                    userWorker.OrganizationServiceId = org.ServiceId;
                    userWorker.Enable_CsComputerAsync();
                }
            }
            catch (Exception ex)
            {
                TaskManager.CompleteResultTask(res, LyncErrorCodes.CANNOT_ADD_LYNC_USER, ex);
                return(res);
            }

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

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