protected void btnSave_Click(object sender, EventArgs e) { txtStatus.Visible = true; try { SfBUser[] Accounts = ES.Services.SfB.GetSfBUsersByPlanId(PanelRequest.ItemID, Convert.ToInt32(sfbUserPlanSelectorSource.planId)); foreach (SfBUser a in Accounts) { txtStatus.Text = "Completed"; SfBUserResult result = ES.Services.SfB.SetUserSfBPlan(PanelRequest.ItemID, a.AccountID, Convert.ToInt32(sfbUserPlanSelectorTarget.planId)); if (result.IsSuccess) { BindPlans(); txtStatus.Text = "Error: " + a.DisplayName; ShowErrorMessage("SFB_FAILED_TO_STAMP"); return; } } } catch (Exception ex) { ShowErrorMessage("SFB_FAILED_TO_STAMP", ex); } }
protected void btnCreate_Click(object sender, EventArgs e) { int accountId = userSelector.GetAccountId(); SfBUserResult res = ES.Services.SfB.CreateSfBUser(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.SFB_ENTERPRISEVOICE, cntx); string lineUri = ""; if ((enterpriseVoiceQuota) & (ddlPhoneNumber.Items.Count != 0)) { lineUri = ddlPhoneNumber.SelectedItem.Text + ":" + tbPin.Text; } //#1 SfBUser sfbUser = ES.Services.SfB.GetSfBUserGeneralSettings(PanelRequest.ItemID, accountId); ES.Services.SfB.SetSfBUserGeneralSettings(PanelRequest.ItemID, accountId, sfbUser.SipAddress, lineUri); Response.Redirect(EditUrl("AccountID", accountId.ToString(), "edit_sfb_user", "SpaceID=" + PanelSecurity.PackageId, "ItemID=" + PanelRequest.ItemID)); } else { messageBox.ShowMessage(res, "CREATE_SFB_USER", "SFB"); } }
public static SfBUserResult SetUserSfBPlan(int itemId, int accountId, int sfbUserPlanId) { SfBUserResult res = TaskManager.StartResultTask <SfBUserResult>("SFB", "SET_SFB_USER_SFBPLAN"); int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { TaskManager.CompleteResultTask(res, SfBErrorCodes.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 sfbServiceId = GetSfBServiceID(org.PackageId); SfBServer sfb = GetSfBServer(sfbServiceId, org.ServiceId); SfBUserPlan plan = GetSfBUserPlan(itemId, sfbUserPlanId); OrganizationUser user; user = OrganizationController.GetAccount(itemId, accountId); if (!sfb.SetSfBUserPlan(org.OrganizationId, user.UserPrincipalName, plan)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ADD_SFB_USER); return(res); } try { DataProvider.SetSfBUserSfBUserplan(accountId, sfbUserPlanId); } catch (Exception ex) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ADD_SFB_USER_TO_DATABASE, ex); return(res); } res.IsSuccess = true; TaskManager.CompleteResultTask(); return(res); } catch (Exception ex) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_UPDATE_SFB_USER, ex); return(res); } }
public static SfBUserResult DeleteSfBUser(int itemId, int accountId) { SfBUserResult res = TaskManager.StartResultTask <SfBUserResult>("SFB", "DELETE_SFB_USER"); int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { TaskManager.CompleteResultTask(res, SfBErrorCodes.NOT_AUTHORIZED); return(res); } SfBServer sfb; try { Organization org = (Organization)PackageController.GetPackageItem(itemId); if (org == null) { throw new ApplicationException( string.Format("Organization is null. ItemId={0}", itemId)); } int sfbServiceId = GetSfBServiceID(org.PackageId); sfb = GetSfBServer(sfbServiceId, org.ServiceId); OrganizationUser user; user = OrganizationController.GetAccount(itemId, accountId); if (user != null) { sfb.DeleteUser(user.UserPrincipalName); } } catch (Exception ex) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_DELETE_SFB_USER, ex); return(res); } try { DataProvider.DeleteSfBUser(accountId); } catch (Exception ex) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_DELETE_SFB_USER_FROM_METADATA, ex); return(res); } TaskManager.CompleteResultTask(); return(res); }
public static SfBUserResult RemoveFederationDomain(int itemId, string domainName) { SfBUserResult res = TaskManager.StartResultTask <SfBUserResult>("SFB", "REMOVE_SFB_FEDERATIONDOMAIN", itemId, new BackgroundTaskParameter("domainName", domainName)); int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { TaskManager.CompleteResultTask(res, SfBErrorCodes.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 sfbServiceId = GetSfBServiceID(org.PackageId); SfBServer sfb = GetSfBServer(sfbServiceId, org.ServiceId); if (org.OrganizationId.ToLower() == domainName.ToLower()) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_REMOVE_SFB_FEDERATIONDOMAIN); return(res); } sfb.RemoveFederationDomain(org.OrganizationId, domainName); } catch (Exception ex) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_REMOVE_SFB_FEDERATIONDOMAIN, ex); return(res); } TaskManager.CompleteResultTask(); return(res); }
protected bool SaveSettings() { if (!Page.IsValid) { return(false); } try { PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); bool enterpriseVoiceQuota = Utils.CheckQouta(Quotas.SFB_ENTERPRISEVOICE, cntx); string lineUri = ""; if ((enterpriseVoiceQuota) & (ddlPhoneNumber.Items.Count != 0)) { lineUri = ddlPhoneNumber.SelectedItem.Text + ":" + tbPin.Text; } SfBUserResult res = ES.Services.SfB.SetUserSfBPlan(PanelRequest.ItemID, PanelRequest.AccountID, Convert.ToInt32(planSelector.planId)); if (res.IsSuccess && res.ErrorCodes.Count == 0) { res = ES.Services.SfB.SetSfBUserGeneralSettings(PanelRequest.ItemID, PanelRequest.AccountID, sfbUserSettings.sipAddress, lineUri); } if (res.IsSuccess && res.ErrorCodes.Count == 0) { messageBox.ShowSuccessMessage("UPDATE_SFB_USER"); return(true); } else { messageBox.ShowMessage(res, "UPDATE_SFB_USER", "SFB"); return(false); } } catch (Exception ex) { messageBox.ShowErrorMessage("UPDATE_SFB_USER", ex); return(false); } }
protected void gvDomains_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeleteItem") { try { SfBUserResult res = ES.Services.SfB.RemoveFederationDomain(PanelRequest.ItemID, e.CommandArgument.ToString()); if (!(res.IsSuccess && res.ErrorCodes.Count == 0)) { messageBox.ShowMessage(res, "DELETE_SFB_FEDERATIONDOMAIN", "SFB"); return; } // rebind domains BindDomainNames(); } catch (Exception ex) { ShowErrorMessage("SFB_DELETE_DOMAIN", ex); } } }
private void AddDomain() { if (!Page.IsValid) { return; } // get domain name string domainName = DomainName.Text.Trim(); string proxyFQDN = ProxyFQDN.Text.Trim(); SfBUserResult res = ES.Services.SfB.AddFederationDomain(PanelRequest.ItemID, domainName, proxyFQDN); if (!(res.IsSuccess && res.ErrorCodes.Count == 0)) { messageBox.ShowMessage(res, "ADD_SFB_FEDERATIONDOMAIN", "SFB"); } // return RedirectBack(); }
public static SfBUserResult 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)); SfBUserResult res = TaskManager.StartResultTask <SfBUserResult>("SFB", "ADD_SFB_FEDERATIONDOMAIN", itemId, parameters); int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { TaskManager.CompleteResultTask(res, SfBErrorCodes.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 sfbServiceId = GetSfBServiceID(org.PackageId); SfBServer sfb = GetSfBServer(sfbServiceId, org.ServiceId); if (string.IsNullOrEmpty(org.SfBTenantId)) { PackageContext cntx = PackageController.GetPackageContext(org.PackageId); org.SfBTenantId = sfb.CreateOrganization(org.OrganizationId, org.DefaultDomain, Convert.ToBoolean(cntx.Quotas[Quotas.SFB_CONFERENCING].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_ALLOWVIDEO].QuotaAllocatedValue), Convert.ToInt32(cntx.Quotas[Quotas.SFB_MAXPARTICIPANTS].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_FEDERATION].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_ENTERPRISEVOICE].QuotaAllocatedValue)); if (string.IsNullOrEmpty(org.SfBTenantId)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ENABLE_ORG); return(res); } else { PackageController.UpdatePackageItem(org); } } sfb = GetSfBServer(sfbServiceId, org.ServiceId); bool bDomainExists = false; SfBFederationDomain[] domains = GetFederationDomains(itemId); foreach (SfBFederationDomain d in domains) { if (d.DomainName.ToLower() == domainName.ToLower()) { bDomainExists = true; break; } } if (!bDomainExists) { sfb.AddFederationDomain(org.OrganizationId, domainName.ToLower(), proxyFqdn); } } catch (Exception ex) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ADD_SFB_FEDERATIONDOMAIN, ex); return(res); } TaskManager.CompleteResultTask(); return(res); }
public static SfBUserResult SetSfBUserGeneralSettings(int itemId, int accountId, string sipAddress, string lineUri) { SfBUserResult res = TaskManager.StartResultTask <SfBUserResult>("SFB", "SET_SFB_USER_GENERAL_SETTINGS"); string PIN = ""; string[] uriAndPin = ("" + lineUri).Split(':'); if (uriAndPin.Length > 0) { lineUri = uriAndPin[0]; } if (uriAndPin.Length > 1) { PIN = uriAndPin[1]; } SfBUser user = null; try { Organization org = (Organization)PackageController.GetPackageItem(itemId); if (org == null) { throw new ApplicationException( string.Format("Organization is null. ItemId={0}", itemId)); } int sfbServiceId = GetSfBServiceID(org.PackageId); SfBServer sfb = GetSfBServer(sfbServiceId, org.ServiceId); OrganizationUser usr; usr = OrganizationController.GetAccount(itemId, accountId); if (usr != null) { user = sfb.GetSfBUserGeneralSettings(org.OrganizationId, usr.UserPrincipalName); } if (user != null) { SfBUserPlan plan = ObjectUtils.FillObjectFromDataReader <SfBUserPlan>(DataProvider.GetSfBUserPlanByAccountId(accountId)); if (plan != null) { user.SfBUserPlanId = plan.SfBUserPlanId; user.SfBUserPlanName = plan.SfBUserPlanName; } if (!string.IsNullOrEmpty(sipAddress)) { if (user.SipAddress != sipAddress) { if (sipAddress != usr.UserPrincipalName) { if (DataProvider.SfBUserExists(accountId, sipAddress)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.ADDRESS_ALREADY_USED); return(res); } } user.SipAddress = sipAddress; } } user.LineUri = lineUri; user.PIN = PIN; sfb.SetSfBUserGeneralSettings(org.OrganizationId, usr.UserPrincipalName, user); DataProvider.UpdateSfBUser(accountId, sipAddress); } } catch (Exception ex) { TaskManager.CompleteResultTask(res, SfBErrorCodes.FAILED_SET_SETTINGS, ex); return(res); } res.IsSuccess = true; TaskManager.CompleteResultTask(); return(res); }
public static SfBUserResult CreateSfBUser(int itemId, int accountId, int sfbUserPlanId) { SfBUserResult res = TaskManager.StartResultTask <SfBUserResult>("SFB", "CREATE_SFB_USER"); int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { TaskManager.CompleteResultTask(res, SfBErrorCodes.NOT_AUTHORIZED); return(res); } SfBUser retSfBUser = new SfBUser(); bool isSfBUser; isSfBUser = DataProvider.CheckSfBUserExists(accountId); if (isSfBUser) { TaskManager.CompleteResultTask(res, SfBErrorCodes.USER_IS_ALREADY_SFB_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, SfBErrorCodes.USER_FIRST_NAME_IS_NOT_SPECIFIED); return(res); } if (string.IsNullOrEmpty(user.LastName)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.USER_LAST_NAME_IS_NOT_SPECIFIED); return(res); } bool quota = CheckQuota(itemId); if (!quota) { TaskManager.CompleteResultTask(res, SfBErrorCodes.USER_QUOTA_HAS_BEEN_REACHED); return(res); } SfBServer sfb; 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 sfbServiceId = GetSfBServiceID(org.PackageId); sfb = GetSfBServer(sfbServiceId, org.ServiceId); if (string.IsNullOrEmpty(org.SfBTenantId)) { PackageContext cntx = PackageController.GetPackageContext(org.PackageId); org.SfBTenantId = sfb.CreateOrganization(org.OrganizationId, org.DefaultDomain, Convert.ToBoolean(cntx.Quotas[Quotas.SFB_CONFERENCING].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_ALLOWVIDEO].QuotaAllocatedValue), Convert.ToInt32(cntx.Quotas[Quotas.SFB_MAXPARTICIPANTS].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_FEDERATION].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_ENTERPRISEVOICE].QuotaAllocatedValue)); if (string.IsNullOrEmpty(org.SfBTenantId)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.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.SfB, domain, ""); } } PackageController.UpdatePackageItem(org); bReloadConfiguration = true; } } if (sfb.GetOrganizationTenantId(org.OrganizationId) == string.Empty) { PackageContext cntx = PackageController.GetPackageContext(org.PackageId); org.SfBTenantId = sfb.CreateOrganization(org.OrganizationId, org.DefaultDomain, Convert.ToBoolean(cntx.Quotas[Quotas.SFB_CONFERENCING].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_ALLOWVIDEO].QuotaAllocatedValue), Convert.ToInt32(cntx.Quotas[Quotas.SFB_MAXPARTICIPANTS].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_FEDERATION].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_ENTERPRISEVOICE].QuotaAllocatedValue)); if (string.IsNullOrEmpty(org.SfBTenantId)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ENABLE_ORG); return(res); } else { PackageController.UpdatePackageItem(org); bReloadConfiguration = true; } } SfBUserPlan plan = GetSfBUserPlan(itemId, sfbUserPlanId); if (!sfb.CreateUser(org.OrganizationId, user.UserPrincipalName, plan)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ADD_SFB_USER); return(res); } if (bReloadConfiguration) { SfBControllerAsync userWorker = new SfBControllerAsync(); userWorker.SfBServiceId = sfbServiceId; userWorker.OrganizationServiceId = org.ServiceId; userWorker.Enable_CsComputerAsync(); } } catch (Exception ex) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ADD_SFB_USER, ex); return(res); } try { DataProvider.AddSfBUser(accountId, sfbUserPlanId, user.UserPrincipalName); } catch (Exception ex) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ADD_SFB_USER_TO_DATABASE, ex); return(res); } res.IsSuccess = true; TaskManager.CompleteResultTask(); return(res); }