예제 #1
0
        /// <summary> Gets users general settings.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="userUpn"> The user UPN.</param>
        /// <returns> User settings.</returns>
        internal override LyncUser GetLyncUserGeneralSettingsInternal(string organizationId, string userUpn)
        {
            HostedSolutionLog.LogStart("GetLyncUserGeneralSettingsInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);
            var      lyncUser = new LyncUser();
            Runspace runspace = null;

            try
            {
                runspace = OpenRunspace();

                var command = new Command("Get-CsUser");
                command.Parameters.Add("Identity", userUpn);
                Collection <PSObject> result = ExecuteShellCommand(runspace, command, false);
                PSObject user = result[0];

                lyncUser.DisplayName = (string)GetPSObjectProperty(user, "DisplayName");
                lyncUser.SipAddress  = (string)GetPSObjectProperty(user, "SipAddress");
                lyncUser.LineUri     = (string)GetPSObjectProperty(user, "LineURI");

                lyncUser.SipAddress = lyncUser.SipAddress.ToLower().Replace("sip:", "");
                lyncUser.LineUri    = lyncUser.LineUri.ToLower().Replace("tel:+", "");
                lyncUser.LineUri    = lyncUser.LineUri.ToLower().Replace("tel:", "");
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("GetLyncUserGeneralSettingsInternal", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("GetLyncUserGeneralSettingsInternal");

            return(lyncUser);
        }
예제 #2
0
 /// <remarks/>
 public void SetLyncUserGeneralSettingsAsync(string organizationId, string userUpn, LyncUser lyncUser, object userState) {
     if ((this.SetLyncUserGeneralSettingsOperationCompleted == null)) {
         this.SetLyncUserGeneralSettingsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSetLyncUserGeneralSettingsOperationCompleted);
     }
     this.InvokeAsync("SetLyncUserGeneralSettings", new object[] {
                 organizationId,
                 userUpn,
                 lyncUser}, this.SetLyncUserGeneralSettingsOperationCompleted, userState);
 }
예제 #3
0
 /// <remarks/>
 public void SetLyncUserGeneralSettingsAsync(string organizationId, string userUpn, LyncUser lyncUser) {
     this.SetLyncUserGeneralSettingsAsync(organizationId, userUpn, lyncUser, null);
 }
예제 #4
0
 /// <remarks/>
 public System.IAsyncResult BeginSetLyncUserGeneralSettings(string organizationId, string userUpn, LyncUser lyncUser, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("SetLyncUserGeneralSettings", new object[] {
                 organizationId,
                 userUpn,
                 lyncUser}, callback, asyncState);
 }
예제 #5
0
 public bool SetLyncUserGeneralSettings(string organizationId, string userUpn, LyncUser lyncUser) {
     object[] results = this.Invoke("SetLyncUserGeneralSettings", new object[] {
                 organizationId,
                 userUpn,
                 lyncUser});
     return ((bool)(results[0]));
 }
예제 #6
0
        /// <summary> Sets users general settings.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="userUpn"> The user UPN.</param>
        /// <param name="lyncUser"> The lync user settings.</param>
        /// <returns> The result.</returns>
        internal override bool SetLyncUserGeneralSettingsInternal(string organizationId, string userUpn, LyncUser lyncUser)
        {
            HostedSolutionLog.LogStart("SetLyncUserGeneralSettingsInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);

            bool            ret         = true;
            Runspace        runspace    = null;
            LyncTransaction transaction = StartTransaction();

            try
            {
                runspace = OpenRunspace();
                Guid     tenantId = GetObjectGuid(organizationId, runspace);
                string[] tmp      = userUpn.Split('@');

                if (tmp.Length < 2)
                {
                    return(false);
                }

                var command = new Command("Get-CsSipDomain");
                Collection <PSObject> sipDomains = ExecuteShellCommand(runspace, command, false);
                bool bSipDomainExists            = sipDomains.Select(domain => (string)GetPSObjectProperty(domain, "Name")).Any(d => d.ToLower() == tmp[1].ToLower());

                if (!bSipDomainExists)
                {
                    command = new Command("New-CsSipDomain");
                    command.Parameters.Add("Identity", tmp[1].ToLower());
                    ExecuteShellCommand(runspace, command, false);

                    transaction.RegisterNewSipDomain(tmp[1].ToLower());

                    string         path      = AddADPrefix(GetOrganizationPath(organizationId));
                    DirectoryEntry ou        = ActiveDirectoryUtils.GetADObject(path);
                    string[]       sipDs     = ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "Url");
                    var            listSipDs = new List <string>();
                    listSipDs.AddRange(sipDs);
                    listSipDs.Add(tmp[1]);

                    ActiveDirectoryUtils.SetADObjectPropertyValue(ou, "Url", listSipDs.ToArray());
                    ou.CommitChanges();

                    CreateSimpleUrl(runspace, tenantId);
                    transaction.RegisterNewSimpleUrl(tmp[1].ToLower(), tenantId.ToString());

                    path = AddADPrefix(GetResultObjectDN(organizationId, runspace));
                    DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path);

                    if (tmp.Length > 0)
                    {
                        string Url = SimpleUrlRoot + tmp[1];
                        ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-BaseSimpleUrl", Url.ToLower());
                    }

                    user.CommitChanges();
                }

                command = new Command("Set-CsUser");
                command.Parameters.Add("Identity", userUpn);

                if (!string.IsNullOrEmpty(lyncUser.SipAddress))
                {
                    command.Parameters.Add("SipAddress", "SIP:" + lyncUser.SipAddress);
                }

                if (!string.IsNullOrEmpty(lyncUser.LineUri))
                {
                    command.Parameters.Add("LineUri", "TEL:+" + lyncUser.LineUri);
                }
                else
                {
                    command.Parameters.Add("LineUri", null);
                }

                ExecuteShellCommand(runspace, command, false);

                if (!String.IsNullOrEmpty(lyncUser.PIN))
                {
                    command = new Command("Set-CsClientPin");
                    command.Parameters.Add("Identity", userUpn);
                    command.Parameters.Add("Pin", lyncUser.PIN);
                    ExecuteShellCommand(runspace, command, false);
                }

                command = new Command("Update-CsAddressBook");
                ExecuteShellCommand(runspace, command, false);

                command = new Command("Update-CsUserDatabase");
                ExecuteShellCommand(runspace, command, false);
            }
            catch (Exception ex)
            {
                ret = false;
                HostedSolutionLog.LogError("SetLyncUserGeneralSettingsInternal", ex);
                RollbackTransaction(transaction);
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("SetLyncUserGeneralSettingsInternal");

            return(ret);
        }
예제 #7
0
 internal virtual bool SetLyncUserGeneralSettingsInternal(string organizationId, string userUpn, LyncUser lyncUser)
 {
     throw new NotImplementedException();
 }
예제 #8
0
        private bool SetLyncUserGeneralSettingsInternal(string organizationId, string userUpn, LyncUser lyncUser)
        {
            HostedSolutionLog.LogStart("SetLyncUserGeneralSettingsInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);

            bool ret = true;
            Runspace runSpace = null;
            Guid tenantId = Guid.Empty;
            LyncTransaction transaction = StartTransaction();

            try
            {
                runSpace = OpenRunspace();
                Command cmd = new Command("Get-CsTenant");
                cmd.Parameters.Add("Identity", GetOrganizationPath(organizationId));
                Collection<PSObject> result = ExecuteShellCommand(runSpace, cmd, false);
                if ((result != null) && (result.Count > 0))
                {
                    tenantId = (Guid)GetPSObjectProperty(result[0], "TenantId");

                    string[] tmp = userUpn.Split('@');
                    if (tmp.Length < 2) return false;

                    // Get SipDomains and verify existence
                    bool bSipDomainExists = false;
                    cmd = new Command("Get-CsSipDomain");
                    Collection<PSObject> sipDomains = ExecuteShellCommand(runSpace, cmd, false);

                    foreach (PSObject domain in sipDomains)
                    {
                        string d = (string)GetPSObjectProperty(domain, "Name");
                        if (d.ToLower() == tmp[1].ToLower())
                        {
                            bSipDomainExists = true;
                            break;
                        }
                    }

                    string path = string.Empty;

                    if (!bSipDomainExists)
                    {
                        // Create Sip Domain
                        cmd = new Command("New-CsSipDomain");
                        cmd.Parameters.Add("Identity", tmp[1].ToLower());
                        ExecuteShellCommand(runSpace, cmd, false);

                        transaction.RegisterNewSipDomain(tmp[1].ToLower());


                        path = AddADPrefix(GetOrganizationPath(organizationId));
                        DirectoryEntry ou = ActiveDirectoryUtils.GetADObject(path);
                        string[] sipDs = (string[])ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "msRTCSIP-Domains");
                        List<string> listSipDs = new List<string>();
                        listSipDs.AddRange(sipDs);
                        listSipDs.Add(tmp[1]);

                        ActiveDirectoryUtils.SetADObjectPropertyValue(ou, "msRTCSIP-Domains", listSipDs.ToArray());
                        ou.CommitChanges();

                        //Create simpleurls
                        CreateSimpleUrl(runSpace, tmp[1].ToLower(), tenantId);
                        transaction.RegisterNewSimpleUrl(tmp[1].ToLower(), tenantId.ToString());

                        path = AddADPrefix(GetResultObjectDN(result));
                        DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path);

                        if (tmp.Length > 0)
                        {
                            string Url = SimpleUrlRoot + tmp[1];
                            ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-BaseSimpleUrl", Url.ToLower());
                        }
                        user.CommitChanges();
                    }
                }

                cmd = new Command("Set-CsUser");
                cmd.Parameters.Add("Identity", userUpn);
                if (!string.IsNullOrEmpty(lyncUser.SipAddress)) cmd.Parameters.Add("SipAddress", "SIP:" + lyncUser.SipAddress);
                if (!string.IsNullOrEmpty(lyncUser.LineUri)) cmd.Parameters.Add("LineUri", "TEL:+" + lyncUser.LineUri);
                else cmd.Parameters.Add("LineUri", null);
                ExecuteShellCommand(runSpace, cmd, false);

                if (!String.IsNullOrEmpty(lyncUser.PIN))
                {
                    cmd = new Command("Set-CsClientPin");
                    cmd.Parameters.Add("Identity", userUpn);
                    cmd.Parameters.Add("Pin", lyncUser.PIN);
                    ExecuteShellCommand(runSpace, cmd, false);
                }


                //initiate addressbook generation
                cmd = new Command("Update-CsAddressBook");
                ExecuteShellCommand(runSpace, cmd, false);

                //initiate user database replication
                cmd = new Command("Update-CsUserDatabase");
                ExecuteShellCommand(runSpace, cmd, false);

            }
            catch (Exception ex)
            {
                ret = false;
                HostedSolutionLog.LogError("SetLyncUserGeneralSettingsInternal", ex);
                RollbackTransaction(transaction);
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            HostedSolutionLog.LogEnd("SetLyncUserGeneralSettingsInternal");
            return ret;
        }
예제 #9
0
 public virtual bool SetLyncUserGeneralSettings(string organizationId, string userUpn, LyncUser lyncUser)
 {
     return(SetLyncUserGeneralSettingsInternal(organizationId, userUpn, lyncUser));
 }
예제 #10
0
        private LyncUser GetLyncUserGeneralSettingsInternal(string organizationId, string userUpn)
        {
            HostedSolutionLog.LogStart("GetLyncUserGeneralSettingsInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);

            LyncUser lyncUser = null;
            Runspace runSpace = null;
            try
            {
                runSpace = OpenRunspace();

                Command cmd = new Command("Get-CsUser");
                cmd.Parameters.Add("Identity", userUpn);
                Collection<PSObject> result = ExecuteShellCommand(runSpace, cmd);

                if ((result != null) && (result.Count > 0))
                {
                    PSObject user = result[0];

                    lyncUser = new LyncUser();

                    lyncUser.DisplayName = (string)GetPSObjectProperty(user, "DisplayName");
                    lyncUser.SipAddress = (string)GetPSObjectProperty(user, "SipAddress");
                    lyncUser.LineUri = (string)GetPSObjectProperty(user, "LineURI");

                    lyncUser.SipAddress = lyncUser.SipAddress.ToLower().Replace("sip:", "");
                    lyncUser.LineUri = lyncUser.LineUri.ToLower().Replace("tel:+", "");
                    lyncUser.LineUri = lyncUser.LineUri.ToLower().Replace("tel:", "");
                }
                else
                    HostedSolutionLog.LogInfo("GetLyncUserGeneralSettingsInternal: No info found");

            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("GetLyncUserGeneralSettingsInternal", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            HostedSolutionLog.LogEnd("GetLyncUserGeneralSettingsInternal");
            return lyncUser;
        }
예제 #11
0
 public bool SetLyncUserGeneralSettings(string organizationId, string userUpn, LyncUser lyncUser)
 {
     return SetLyncUserGeneralSettingsInternal(organizationId, userUpn, lyncUser);
 }
예제 #12
0
 public bool SetLyncUserGeneralSettings(string organizationId, string userUpn, LyncUser lyncUser)
 {
     try
     {
         Log.WriteStart("{0}.SetLyncUserGeneralSettings", ProviderSettings.ProviderName);
         bool ret = Lync.SetLyncUserGeneralSettings(organizationId, userUpn, lyncUser);
         Log.WriteEnd("{0}.SetLyncUserGeneralSettings", ProviderSettings.ProviderName);
         return ret;
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("Error: {0}.SetLyncUserGeneralSettings", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
예제 #13
0
 internal virtual bool SetLyncUserGeneralSettingsInternal(string organizationId, string userUpn, LyncUser lyncUser)
 {
     throw new NotImplementedException();
 }
예제 #14
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;

        }