From 16ec864a090c548be6d8aadfdc90a8e191cf85d6 Mon Sep 17 00:00:00 2001 From: robvde Date: Fri, 20 Dec 2013 15:54:48 +0400 Subject: [PATCH] Fixed lync out of index error and added ability to verify if organization is a valid Tenant Proxies not generated --- .../HostedSolution/ILyncServer.cs | 1 + .../Lync2013HP.cs | 65 ++++++++++++++++--- .../Lync2010.cs | 65 ++++++++++++++++--- .../WebsitePanel.Server/LyncServer.asmx.cs | 17 +++++ 4 files changed, 132 insertions(+), 16 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ILyncServer.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ILyncServer.cs index 39dee306..fa93c3a3 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ILyncServer.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ILyncServer.cs @@ -35,6 +35,7 @@ namespace WebsitePanel.Providers.HostedSolution public interface ILyncServer { string CreateOrganization(string organizationId, string sipDomain, bool enableConferencing, bool enableConferencingVideo, int maxConferenceSize, bool enabledFederation, bool enabledEnterpriseVoice); + string GetOrganizationTenantId(string organizationId); bool DeleteOrganization(string organizationId, string sipDomain); bool CreateUser(string organizationId, string userUpn, LyncUserPlan plan); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Lync2013HP/Lync2013HP.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Lync2013HP/Lync2013HP.cs index 32909339..a06670a2 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Lync2013HP/Lync2013HP.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution.Lync2013HP/Lync2013HP.cs @@ -112,6 +112,11 @@ namespace WebsitePanel.Providers.HostedSolution return CreateOrganizationInternal(organizationId, sipDomain, enableConferencing, enableConferencingVideo, maxConferenceSize, enabledFederation, enabledEnterpriseVoice); } + public string GetOrganizationTenantId(string organizationId) + { + return GetOrganizationTenantIdInternal(organizationId); + } + public bool DeleteOrganization(string organizationId, string sipDomain) { return DeleteOrganizationInternal(organizationId, sipDomain); @@ -277,7 +282,42 @@ namespace WebsitePanel.Providers.HostedSolution return TenantId; } + private string GetOrganizationTenantIdInternal(string organizationId) + { + HostedSolutionLog.LogStart("GetOrganizationTenantIdInternal"); + HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId); + string tenantIdStr = string.Empty; + + Runspace runSpace = null; + try + { + runSpace = OpenRunspace(); + + Command cmd = new Command("Get-CsTenant"); + cmd.Parameters.Add("Identity", GetOrganizationPath(organizationId)); + Collection result = ExecuteShellCommand(runSpace, cmd, false); + if ((result != null) && (result.Count > 0)) + { + Guid tenantId = (Guid)GetPSObjectProperty(result[0], "TenantId"); + + tenantIdStr = tenantId.ToString(); + } + + } + catch (Exception ex) + { + HostedSolutionLog.LogError("GetOrganizationTenantIdInternal", ex); + throw; + } + finally + { + + CloseRunspace(runSpace); + } + HostedSolutionLog.LogEnd("GetOrganizationTenantIdnInternal"); + return tenantIdStr; + } private bool DeleteOrganizationInternal(string organizationId, string sipDomain) { @@ -508,7 +548,7 @@ namespace WebsitePanel.Providers.HostedSolution HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId); HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn); - LyncUser lyncUser = new LyncUser(); + LyncUser lyncUser = null; Runspace runSpace = null; try { @@ -517,15 +557,24 @@ namespace WebsitePanel.Providers.HostedSolution Command cmd = new Command("Get-CsUser"); cmd.Parameters.Add("Identity", userUpn); Collection result = ExecuteShellCommand(runSpace, cmd); - PSObject user = result[0]; - lyncUser.DisplayName = (string)GetPSObjectProperty(user, "DisplayName"); - lyncUser.SipAddress = (string)GetPSObjectProperty(user, "SipAddress"); - lyncUser.LineUri = (string)GetPSObjectProperty(user, "LineURI"); + 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"); - lyncUser.SipAddress = lyncUser.SipAddress.ToLower().Replace("sip:", ""); - lyncUser.LineUri = lyncUser.LineUri.ToLower().Replace("tel:+", ""); - lyncUser.LineUri = lyncUser.LineUri.ToLower().Replace("tel:", ""); } catch (Exception ex) { diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Lync2010.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Lync2010.cs index 6eb6cf54..a292f0b1 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Lync2010.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Lync2010.cs @@ -112,6 +112,11 @@ namespace WebsitePanel.Providers.HostedSolution return CreateOrganizationInternal(organizationId, sipDomain, enableConferencing, enableConferencingVideo, maxConferenceSize, enabledFederation, enabledEnterpriseVoice); } + public string GetOrganizationTenantId(string organizationId) + { + return GetOrganizationTenantIdInternal(organizationId); + } + public bool DeleteOrganization(string organizationId, string sipDomain) { return DeleteOrganizationInternal(organizationId, sipDomain); @@ -276,7 +281,42 @@ namespace WebsitePanel.Providers.HostedSolution return TenantId; } + private string GetOrganizationTenantIdInternal(string organizationId) + { + HostedSolutionLog.LogStart("GetOrganizationTenantIdInternal"); + HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId); + string tenantIdStr = string.Empty; + + Runspace runSpace = null; + try + { + runSpace = OpenRunspace(); + + Command cmd = new Command("Get-CsTenant"); + cmd.Parameters.Add("Identity", GetOrganizationPath(organizationId)); + Collection result = ExecuteShellCommand(runSpace, cmd, false); + if ((result != null) && (result.Count > 0)) + { + Guid tenantId = (Guid)GetPSObjectProperty(result[0], "TenantId"); + + tenantIdStr = tenantId.ToString(); + } + + } + catch (Exception ex) + { + HostedSolutionLog.LogError("GetOrganizationTenantIdInternal", ex); + throw; + } + finally + { + + CloseRunspace(runSpace); + } + HostedSolutionLog.LogEnd("GetOrganizationTenantIdnInternal"); + return tenantIdStr; + } private bool DeleteOrganizationInternal(string organizationId, string sipDomain) { @@ -507,7 +547,7 @@ namespace WebsitePanel.Providers.HostedSolution HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId); HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn); - LyncUser lyncUser = new LyncUser(); + LyncUser lyncUser = null; Runspace runSpace = null; try { @@ -516,15 +556,24 @@ namespace WebsitePanel.Providers.HostedSolution Command cmd = new Command("Get-CsUser"); cmd.Parameters.Add("Identity", userUpn); Collection result = ExecuteShellCommand(runSpace, cmd); - PSObject user = result[0]; - lyncUser.DisplayName = (string)GetPSObjectProperty(user, "DisplayName"); - lyncUser.SipAddress = (string)GetPSObjectProperty(user, "SipAddress"); - lyncUser.LineUri = (string)GetPSObjectProperty(user, "LineURI"); + 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"); - lyncUser.SipAddress = lyncUser.SipAddress.ToLower().Replace("sip:", ""); - lyncUser.LineUri = lyncUser.LineUri.ToLower().Replace("tel:+", ""); - lyncUser.LineUri = lyncUser.LineUri.ToLower().Replace("tel:", ""); } catch (Exception ex) { diff --git a/WebsitePanel/Sources/WebsitePanel.Server/LyncServer.asmx.cs b/WebsitePanel/Sources/WebsitePanel.Server/LyncServer.asmx.cs index 9e0e09e6..0ab4e33e 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/LyncServer.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server/LyncServer.asmx.cs @@ -70,6 +70,23 @@ namespace WebsitePanel.Server } } + [WebMethod, SoapHeader("settings")] + public string GetOrganizationTenantId(string organizationId, string sipDomain, bool enableConferencing, bool enableConferencingVideo, int maxConferenceSize, bool enabledFederation, bool enabledEnterpriseVoice) + { + try + { + Log.WriteStart("{0}.GetOrganizationTenantId", ProviderSettings.ProviderName); + string ret = Lync.GetOrganizationTenantId(organizationId); + Log.WriteEnd("{0}.GetOrganizationTenantId", ProviderSettings.ProviderName); + return ret; + } + catch (Exception ex) + { + Log.WriteError(String.Format("Error: {0}.GetOrganizationTenantId", ProviderSettings.ProviderName), ex); + throw; + } + } + [WebMethod, SoapHeader("settings")] public bool DeleteOrganization(string organizationId, string sipDomain) {