This commit is contained in:
dev_amdtel 2013-08-10 00:52:34 +04:00
commit 3b6fe9c4bb
204 changed files with 23591 additions and 9818 deletions

View file

@ -0,0 +1,534 @@
// Copyright (c) 2012, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Data;
using WebsitePanel.Providers.Common;
using WebsitePanel.Providers.HostedSolution;
using WebsitePanel.Providers.ResultObjects;
namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
{
public class BlackBerryController
{
private static bool CheckQuota(int itemId)
{
Organization org = OrganizationController.GetOrganization(itemId);
PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
IntResult userCount = GetBlackBerryUsersCount(itemId, string.Empty, string.Empty);
int allocatedBlackBerryUsers = cntx.Quotas[Quotas.BLACKBERRY_USERS].QuotaAllocatedValue;
return allocatedBlackBerryUsers == -1 || allocatedBlackBerryUsers > userCount.Value;
}
private static BlackBerry GetBlackBerryProxy(int itemId)
{
Organization org = OrganizationController.GetOrganization(itemId);
int serviceId = PackageController.GetPackageServiceId(org.PackageId, ResourceGroups.BlackBerry);
BlackBerry blackBerry = new BlackBerry();
ServiceProviderProxy.Init(blackBerry, serviceId);
return blackBerry;
}
internal static bool CheckBlackBerryUserExists(int accountId)
{
return DataProvider.CheckBlackBerryUserExists(accountId);
}
public static ResultObject CreateBlackBerryUser(int itemId, int accountId)
{
ResultObject res = TaskManager.StartResultTask<ResultObject>("BLACBERRY", "CREATE_BLACKBERRY_USER");
bool isBlackBerryUser;
try
{
isBlackBerryUser = DataProvider.CheckBlackBerryUserExists(accountId);
}
catch(Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_CHECK_IF_BLACKBERRY_USER_EXISTS, ex);
return res;
}
if (isBlackBerryUser)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.USER_IS_ALREADY_BLAKBERRY_USER);
return res;
}
OrganizationUser user;
try
{
user = OrganizationController.GetAccount(itemId, accountId);
if (user == null)
throw new ApplicationException(
string.Format("User is null. ItemId={0}, AccountId={1}", itemId,
accountId));
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT, ex);
return res;
}
if (user.AccountType != ExchangeAccountType.Mailbox)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.ACCOUNT_TYPE_IS_NOT_MAILBOX);
return res;
}
try
{
user = OrganizationController.GetUserGeneralSettings(itemId, accountId);
if (string.IsNullOrEmpty(user.FirstName))
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.USER_FIRST_NAME_IS_NOT_SPECIFIED);
return res;
}
if (string.IsNullOrEmpty(user.LastName))
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.USER_LAST_NAME_IS_NOT_SPECIFIED);
return res;
}
}
catch(Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_GET_USER_GENERAL_SETTINGS, ex);
return res;
}
BlackBerry blackBerry;
try
{
blackBerry = GetBlackBerryProxy(itemId);
}
catch(Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_GET_BLACKBERRY_PROXY, ex);
return res;
}
try
{
bool quota = CheckQuota(itemId);
if (!quota)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.USER_QUOTA_HAS_BEEN_REACHED);
return res;
}
}
catch(Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_CHECK_QUOTA, ex);
return res;
}
try
{
ResultObject userRes = blackBerry.CreateBlackBerryUser(user.PrimaryEmailAddress);
res.ErrorCodes.AddRange(userRes.ErrorCodes);
if (!userRes.IsSuccess)
{
TaskManager.CompleteResultTask(res);
return res;
}
}
catch(Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_ADD_BLACKBERRY_USER, ex);
return res;
}
try
{
DataProvider.AddBlackBerryUser(accountId);
}
catch(Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_ADD_BLACKBERRY_USER_TO_DATABASE, ex);
return res;
}
TaskManager.CompleteResultTask();
return res;
}
public static OrganizationUsersPagedResult GetBlackBerryUsers(int itemId, string sortColumn, string sortDirection, string name, string email, int startRow, int count)
{
OrganizationUsersPagedResult res = TaskManager.StartResultTask<OrganizationUsersPagedResult>("BLACKBERRY", "GET_BLACKBERRY_USERS");
try
{
IDataReader reader =
DataProvider.GetBlackBerryUsers(itemId, sortColumn, sortDirection, name, email, startRow, count);
List<OrganizationUser> accounts = new List<OrganizationUser>();
ObjectUtils.FillCollectionFromDataReader(accounts, reader);
res.Value = new OrganizationUsersPaged {PageUsers = accounts.ToArray()};
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, CrmErrorCodes.GET_CRM_USERS, ex);
return res;
}
IntResult intRes = GetBlackBerryUsersCount(itemId, name, email);
res.ErrorCodes.AddRange(intRes.ErrorCodes);
if (!intRes.IsSuccess)
{
TaskManager.CompleteResultTask(res);
return res;
}
res.Value.RecordsCount = intRes.Value;
TaskManager.CompleteResultTask();
return res;
}
public static IntResult GetBlackBerryUsersCount(int itemId, string name, string email)
{
IntResult res = TaskManager.StartResultTask<IntResult>("BLACKBERRY", "GET_BLACKBERRY_USERS_COUNT");
try
{
res.Value = DataProvider.GetBlackBerryUsersCount(itemId, name, email);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, CrmErrorCodes.GET_CRM_USER_COUNT, ex);
return res;
}
TaskManager.CompleteResultTask();
return res;
}
public static ResultObject DeleteBlackBerryUser(int itemId, int accountId)
{
ResultObject res = TaskManager.StartResultTask<ResultObject>("BLACKBERRY", "DELETE_BLACKBERRY_USER");
BlackBerry blackBerry;
try
{
blackBerry = GetBlackBerryProxy(itemId);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_GET_BLACKBERRY_PROXY, ex);
return res;
}
OrganizationUser user;
try
{
user = OrganizationController.GetAccount(itemId, accountId);
if (user == null)
throw new ApplicationException(
string.Format("User is null. ItemId={0}, AccountId={1}", itemId,
accountId));
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT, ex);
return res;
}
try
{
ResultObject bbRes = blackBerry.DeleteBlackBerryUser(user.PrimaryEmailAddress);
res.ErrorCodes.AddRange(bbRes.ErrorCodes);
if (!bbRes.IsSuccess)
{
TaskManager.CompleteResultTask(res);
return res;
}
}
catch(Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_DELETE_BLACKBERRY_USER, ex);
return res;
}
try
{
DataProvider.DeleteBlackBerryUser(accountId);
}
catch(Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_DELETE_BLACKBERRY_USER_FROM_METADATA, ex);
return res;
}
TaskManager.CompleteResultTask();
return res;
}
public static BlackBerryUserStatsResult GetBlackBerryUserStats(int itemId, int accountId)
{
BlackBerryUserStatsResult res = TaskManager.StartResultTask<BlackBerryUserStatsResult>("BLACKBERRY",
"DELETE_BLACKBERRY_USER");
BlackBerry blackBerry;
try
{
blackBerry = GetBlackBerryProxy(itemId);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_GET_BLACKBERRY_PROXY, ex);
return res;
}
OrganizationUser user;
try
{
user = OrganizationController.GetAccount(itemId, accountId);
if (user == null)
throw new ApplicationException(
string.Format("User is null. ItemId={0}, AccountId={1}", itemId,
accountId));
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT, ex);
return res;
}
try
{
BlackBerryUserStatsResult tmp = blackBerry.GetBlackBerryUserStats(user.PrimaryEmailAddress);
res.ErrorCodes.AddRange(tmp.ErrorCodes);
if (!tmp.IsSuccess)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_GET_USER_STATS);
return res;
}
res.Value = tmp.Value;
}
catch(Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_GET_USER_STATS, ex);
return res;
}
TaskManager.CompleteResultTask();
return res;
}
public static ResultObject SetActivationPasswordWithExpirationTime(int itemId, int accountId, string password, int time)
{
BlackBerryUserStatsResult res = TaskManager.StartResultTask<BlackBerryUserStatsResult>("BLACKBERRY",
"DELETE_BLACKBERRY_USER");
BlackBerry blackBerry;
try
{
blackBerry = GetBlackBerryProxy(itemId);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_GET_BLACKBERRY_PROXY, ex);
return res;
}
OrganizationUser user;
try
{
user = OrganizationController.GetAccount(itemId, accountId);
if (user == null)
throw new ApplicationException(
string.Format("User is null. ItemId={0}, AccountId={1}", itemId,
accountId));
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT, ex);
return res;
}
try
{
ResultObject tmp = blackBerry.SetActivationPasswordWithExpirationTime(user.PrimaryEmailAddress, password, time);
res.ErrorCodes.AddRange(tmp.ErrorCodes);
if (!tmp.IsSuccess)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_SET_ACTIVATION_PASSWORD);
return res;
}
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_SET_ACTIVATION_PASSWORD, ex);
return res;
}
TaskManager.CompleteResultTask();
return res;
}
public static ResultObject SetEmailActivationPassword(int itemId, int accountId)
{
ResultObject res = TaskManager.StartResultTask<BlackBerryUserStatsResult>("BLACKBERRY",
"DELETE_BLACKBERRY_USER");
BlackBerry blackBerry;
try
{
blackBerry = GetBlackBerryProxy(itemId);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_GET_BLACKBERRY_PROXY, ex);
return res;
}
OrganizationUser user;
try
{
user = OrganizationController.GetAccount(itemId, accountId);
if (user == null)
throw new ApplicationException(
string.Format("User is null. ItemId={0}, AccountId={1}", itemId,
accountId));
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT, ex);
return res;
}
try
{
ResultObject tmp = blackBerry.SetEmailActivationPassword(user.PrimaryEmailAddress);
res.ErrorCodes.AddRange(tmp.ErrorCodes);
if (!tmp.IsSuccess)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_SET_EMAIL_ACTIVATION_PASSWORD);
return res;
}
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_SET_EMAIL_ACTIVATION_PASSWORD, ex);
return res;
}
TaskManager.CompleteResultTask();
return res;
}
public static ResultObject DeleteDataFromBlackBerryDevice(int itemId, int accountId)
{
ResultObject res = TaskManager.StartResultTask<BlackBerryUserStatsResult>("BLACKBERRY",
"DELETE_BLACKBERRY_USER");
BlackBerry blackBerry;
try
{
blackBerry = GetBlackBerryProxy(itemId);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_GET_BLACKBERRY_PROXY, ex);
return res;
}
OrganizationUser user;
try
{
user = OrganizationController.GetAccount(itemId, accountId);
if (user == null)
throw new ApplicationException(
string.Format("User is null. ItemId={0}, AccountId={1}", itemId,
accountId));
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT, ex);
return res;
}
try
{
ResultObject tmp = blackBerry.DeleteDataFromBlackBerryDevice(user.PrimaryEmailAddress);
res.ErrorCodes.AddRange(tmp.ErrorCodes);
if (!tmp.IsSuccess)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_DELETE_DATA_FROM_BLACKBERRY_DEVICE);
return res;
}
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, BlackBerryErrorsCodes.CANNOT_DELETE_DATA_FROM_BLACKBERRY_DEVICE, ex);
return res;
}
TaskManager.CompleteResultTask();
return res;
}
}
}

View file

@ -0,0 +1,97 @@
// Copyright (c) 2012, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Threading;
using System.Collections.Generic;
using System.Text;
using WebsitePanel.Providers;
using WebsitePanel.Providers.Common;
using WebsitePanel.Providers.HostedSolution;
using WebsitePanel.Providers.ResultObjects;
using WebsitePanel.Providers.Lync;
using WebsitePanel.EnterpriseServer.Code.HostedSolution;
namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
{
public class LyncControllerAsync
{
private int lyncServiceId;
private int organizationServiceId;
public int LyncServiceId
{
get { return this.lyncServiceId; }
set { this.lyncServiceId = value; }
}
public int OrganizationServiceId
{
get { return this.organizationServiceId; }
set { this.organizationServiceId = value; }
}
public void Enable_CsComputerAsync()
{
// start asynchronously
Thread t = new Thread(new ThreadStart(Enable_CsComputer));
t.Start();
}
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;
}
}
}
}
}

View file

@ -0,0 +1,450 @@
// Copyright (c) 2012, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using WebsitePanel.Providers.Common;
using WebsitePanel.Providers.HostedSolution;
using WebsitePanel.Providers.ResultObjects;
using WebsitePanel.Providers.OCS;
namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
{
public class OCSController
{
private static OCSServer GetOCSProxy(int itemId)
{
Organization org = OrganizationController.GetOrganization(itemId);
int serviceId = PackageController.GetPackageServiceId(org.PackageId, ResourceGroups.OCS);
OCSServer ocs = new OCSServer();
ServiceProviderProxy.Init(ocs, serviceId);
return ocs;
}
private static bool CheckQuota(int itemId)
{
Organization org = OrganizationController.GetOrganization(itemId);
PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
IntResult userCount = GetOCSUsersCount(itemId, string.Empty, string.Empty);
int allocatedBlackBerryUsers = cntx.Quotas[Quotas.OCS_USERS].QuotaAllocatedValue;
return allocatedBlackBerryUsers == -1 || allocatedBlackBerryUsers > userCount.Value;
}
private static void SetUserGeneralSettingsByDefault(int itemId, string instanceId, OCSServer ocs)
{
Organization org = OrganizationController.GetOrganization(itemId);
PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
ocs.SetUserGeneralSettings(instanceId, !cntx.Quotas[Quotas.OCS_FederationByDefault].QuotaExhausted,
!cntx.Quotas[Quotas.OCS_PublicIMConnectivityByDefault].QuotaExhausted,
!cntx.Quotas[Quotas.OCS_ArchiveIMConversationByDefault].QuotaExhausted,
!cntx.Quotas[Quotas.OCS_ArchiveFederatedIMConversationByDefault].QuotaExhausted,
!cntx.Quotas[Quotas.OCS_PresenceAllowedByDefault].QuotaExhausted);
}
private static OCSEdgeServer[] GetEdgeServers(string edgeServices)
{
List<OCSEdgeServer> list = new List<OCSEdgeServer>();
if (!string.IsNullOrEmpty(edgeServices))
{
string[] services = edgeServices.Split(';');
foreach (string current in services)
{
string[] data = current.Split(',');
try
{
int serviceId = int.Parse(data[1]);
OCSEdgeServer ocs = new OCSEdgeServer();
ServiceProviderProxy.Init(ocs, serviceId);
list.Add(ocs);
}
catch (Exception ex)
{
TaskManager.WriteError(ex);
}
}
}
return list.ToArray();
}
public static void DeleteDomain(int itemId, string domainName)
{
Organization org = OrganizationController.GetOrganization(itemId);
if (org.IsOCSOrganization)
{
int serviceId = PackageController.GetPackageServiceId(org.PackageId, ResourceGroups.OCS);
StringDictionary settings = ServerController.GetServiceSettings(serviceId);
string edgeServersData = settings[OCSConstants.EDGEServicesData];
OCSEdgeServer[] edgeServers = GetEdgeServers(edgeServersData);
DeleteDomain(domainName, edgeServers);
}
}
public static void DeleteDomain(string domainName, OCSEdgeServer[] edgeServers)
{
foreach (OCSEdgeServer currentEdgeServer in edgeServers)
{
try
{
currentEdgeServer.DeleteDomain(domainName);
}
catch (Exception ex)
{
TaskManager.WriteError(ex);
}
}
}
public static void AddDomain(string domainName, OCSEdgeServer[] edgeServers)
{
foreach (OCSEdgeServer currentEdgeServer in edgeServers)
{
try
{
currentEdgeServer.AddDomain(domainName);
}
catch (Exception ex)
{
TaskManager.WriteError(ex);
}
}
}
public static void AddDomain(string domainName, int itemId)
{
Organization org = OrganizationController.GetOrganization(itemId);
if (!org.IsOCSOrganization)
{
int serviceId = PackageController.GetPackageServiceId(org.PackageId, ResourceGroups.OCS);
StringDictionary settings = ServerController.GetServiceSettings(serviceId);
string edgeServersData = settings[OCSConstants.EDGEServicesData];
OCSEdgeServer[] edgeServers = GetEdgeServers(edgeServersData);
AddDomain(domainName, edgeServers);
}
}
private static void CreateOCSDomains(int itemId)
{
Organization org = OrganizationController.GetOrganization(itemId);
if (!org.IsOCSOrganization)
{
List<OrganizationDomainName> domains = OrganizationController.GetOrganizationDomains(itemId);
int serviceId = PackageController.GetPackageServiceId(org.PackageId, ResourceGroups.OCS);
StringDictionary settings = ServerController.GetServiceSettings(serviceId);
string edgeServersData = settings[OCSConstants.EDGEServicesData];
OCSEdgeServer[] edgeServers = GetEdgeServers(edgeServersData);
foreach (OrganizationDomainName currentDomain in domains)
{
AddDomain(currentDomain.DomainName, edgeServers);
}
org.IsOCSOrganization = true;
PackageController.UpdatePackageItem(org);
}
}
public static OCSUserResult CreateOCSUser(int itemId, int accountId)
{
OCSUserResult res = TaskManager.StartResultTask<OCSUserResult>("OCS", "CREATE_OCS_USER");
OCSUser retOCSUser = new OCSUser();
bool isOCSUser;
try
{
isOCSUser = DataProvider.CheckOCSUserExists(accountId);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.CANNOT_CHECK_IF_OCS_USER_EXISTS, ex);
return res;
}
if (isOCSUser)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.USER_IS_ALREADY_OCS_USER);
return res;
}
OrganizationUser user;
try
{
user = OrganizationController.GetAccount(itemId, accountId);
if (user == null)
throw new ApplicationException(
string.Format("User is null. ItemId={0}, AccountId={1}", itemId,
accountId));
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT, ex);
return res;
}
try
{
user = OrganizationController.GetUserGeneralSettings(itemId, accountId);
if (string.IsNullOrEmpty(user.FirstName))
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.USER_FIRST_NAME_IS_NOT_SPECIFIED);
return res;
}
if (string.IsNullOrEmpty(user.LastName))
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.USER_LAST_NAME_IS_NOT_SPECIFIED);
return res;
}
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.CANNOT_GET_USER_GENERAL_SETTINGS, ex);
return res;
}
try
{
bool quota = CheckQuota(itemId);
if (!quota)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.USER_QUOTA_HAS_BEEN_REACHED);
return res;
}
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.CANNOT_CHECK_QUOTA, ex);
return res;
}
OCSServer ocs;
try
{
ocs = GetOCSProxy(itemId);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.CANNOT_GET_OCS_PROXY, ex);
return res;
}
string instanceId;
try
{
CreateOCSDomains(itemId);
instanceId = ocs.CreateUser(user.PrimaryEmailAddress, user.DistinguishedName);
retOCSUser.InstanceId = instanceId;
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.CANNOT_ADD_OCS_USER, ex);
return res;
}
try
{
SetUserGeneralSettingsByDefault(itemId, instanceId, ocs);
}
catch(Exception ex)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.CANNOT_SET_DEFAULT_SETTINGS, ex);
return res;
}
try
{
DataProvider.AddOCSUser(accountId, instanceId);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.CANNOT_ADD_OCS_USER_TO_DATABASE, ex);
return res;
}
res.Value = retOCSUser;
TaskManager.CompleteResultTask();
return res;
}
public static OCSUsersPagedResult GetOCSUsers(int itemId, string sortColumn, string sortDirection, string name, string email, int startRow, int count)
{
OCSUsersPagedResult res = TaskManager.StartResultTask<OCSUsersPagedResult>("OCS", "GET_OCS_USERS");
try
{
IDataReader reader =
DataProvider.GetOCSUsers(itemId, sortColumn, sortDirection, name, email, startRow, count);
List<OCSUser> accounts = new List<OCSUser>();
ObjectUtils.FillCollectionFromDataReader(accounts, reader);
res.Value = new OCSUsersPaged { PageUsers = accounts.ToArray() };
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.GET_OCS_USERS, ex);
return res;
}
IntResult intRes = GetOCSUsersCount(itemId, name, email);
res.ErrorCodes.AddRange(intRes.ErrorCodes);
if (!intRes.IsSuccess)
{
TaskManager.CompleteResultTask(res);
return res;
}
res.Value.RecordsCount = intRes.Value;
TaskManager.CompleteResultTask();
return res;
}
public static IntResult GetOCSUsersCount(int itemId, string name, string email)
{
IntResult res = TaskManager.StartResultTask<IntResult>("OCS", "GET_OCS_USERS_COUNT");
try
{
res.Value = DataProvider.GetOCSUsersCount(itemId, name, email);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.GET_OCS_USER_COUNT, ex);
return res;
}
TaskManager.CompleteResultTask();
return res;
}
public static ResultObject DeleteOCSUser(int itemId, string instanceId)
{
ResultObject res = TaskManager.StartResultTask<ResultObject>("OCS", "DELETE_OCS_USER");
OCSServer ocsServer;
try
{
ocsServer = GetOCSProxy(itemId);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.CANNOT_GET_OCS_PROXY, ex);
return res;
}
try
{
ocsServer.DeleteUser(instanceId);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.CANNOT_DELETE_OCS_USER, ex);
return res;
}
try
{
DataProvider.DeleteOCSUser(instanceId);
}
catch (Exception ex)
{
TaskManager.CompleteResultTask(res, OCSErrorCodes.CANNOT_DELETE_OCS_USER_FROM_METADATA, ex);
return res;
}
TaskManager.CompleteResultTask();
return res;
}
public static OCSUser GetUserGeneralSettings(int itemId, string instanceId)
{
TaskManager.StartTask("OCS", "GET_OCS_USER_GENERAL_SETTINGS");
OCSUser user;
try
{
OCSServer ocs = GetOCSProxy(itemId);
user = ocs.GetUserGeneralSettings(instanceId);
}
catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
TaskManager.CompleteTask();
return user;
}
public static void SetUserGeneralSettings(int itemId, string instanceId, bool enabledForFederation, bool enabledForPublicIMConnectivity, bool archiveInternalCommunications, bool archiveFederatedCommunications, bool enabledForEnhancedPresence)
{
TaskManager.StartTask("OCS", "SET_OCS_USER_GENERAL_SETTINGS");
try
{
OCSServer ocs = GetOCSProxy(itemId);
ocs.SetUserGeneralSettings(instanceId, enabledForFederation, enabledForPublicIMConnectivity,
archiveInternalCommunications, archiveFederatedCommunications,
enabledForEnhancedPresence);
}
catch(Exception ex)
{
throw TaskManager.WriteError(ex);
}
TaskManager.CompleteTask();
}
}
}

View file

@ -0,0 +1,672 @@
// Copyright (c) 2012, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using WebsitePanel.EnterpriseServer.Code.SharePoint;
using WebsitePanel.Providers.CRM;
using WebsitePanel.Providers.HostedSolution;
using WebsitePanel.Providers.ResultObjects;
using WebsitePanel.Providers.SharePoint;
namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
{
public class ReportController
{
private static void PopulateOrganizationStatisticsReport(Organization org, EnterpriseSolutionStatisticsReport report, string topReseller)
{
OrganizationStatisticsRepotItem item = new OrganizationStatisticsRepotItem();
PopulateBaseItem(item, org, topReseller);
if (report.ExchangeReport != null)
{
try
{
List<ExchangeMailboxStatistics> mailboxStats =
report.ExchangeReport.Items.FindAll(
delegate(ExchangeMailboxStatistics stats)
{ return stats.OrganizationID == org.OrganizationId; });
item.TotalMailboxes = mailboxStats.Count;
foreach (ExchangeMailboxStatistics current in mailboxStats)
{
item.TotalMailboxesSize += current.TotalSize;
}
Providers.Exchange.ExchangeServer exchange;
if (!string.IsNullOrEmpty(org.GlobalAddressList))
{
try
{
int exchangeServiceId = GetExchangeServiceID(org.PackageId);
exchange =
ExchangeServerController.GetExchangeServer(exchangeServiceId, org.ServiceId);
}
catch (Exception ex)
{
throw new ApplicationException(
string.Format("Could not get exchange server. PackageId: {0}", org.PackageId), ex);
}
try
{
item.TotalPublicFoldersSize = exchange.GetPublicFolderSize(org.OrganizationId, "\\" + org.OrganizationId);
}
catch (Exception ex)
{
throw new ApplicationException(
string.Format("Could not get public folder size. OrgId: {0}", org.OrganizationId), ex);
}
}
try
{
org.DiskSpace = (int)(item.TotalPublicFoldersSize + item.TotalMailboxesSize);
PackageController.UpdatePackageItem(org);
}
catch(Exception ex)
{
throw new ApplicationException(string.Format("Could not calcualate diskspace. Org Id: {0}", org.Id), ex);
}
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
}
}
if (report.SharePointReport != null)
{
List<SharePointStatistics> sharePoints =
report.SharePointReport.Items.FindAll(
delegate(SharePointStatistics stats) { return stats.OrganizationID == org.OrganizationId; });
item.TotalSharePointSiteCollections = sharePoints.Count;
foreach (SharePointStatistics current in sharePoints)
{
item.TotalSharePointSiteCollectionsSize += current.SiteCollectionSize;
}
}
if (report.CRMReport != null)
{
List<CRMOrganizationStatistics> crmOrganizationStatistics =
report.CRMReport.Items.FindAll(
delegate(CRMOrganizationStatistics stats) { return stats.OrganizationID == org.OrganizationId; });
item.TotalCRMUsers = crmOrganizationStatistics.Count;
}
item.TotalLyncUsers = 0;
item.TotalLyncEVUsers = 0;
if (report.LyncReport != null)
{
List<LyncUserStatistics> lyncOrganizationStatistics =
report.LyncReport.Items.FindAll(
delegate(LyncUserStatistics stats) { return stats.OrganizationID == org.OrganizationId; });
foreach (LyncUserStatistics current in lyncOrganizationStatistics)
{
if (current.EnterpriseVoice) item.TotalLyncEVUsers++;
}
item.TotalLyncUsers = lyncOrganizationStatistics.Count;
}
report.OrganizationReport.Items.Add(item);
}
private static HostedSharePointServer GetHostedSharePointServer(int serviceId)
{
HostedSharePointServer sps = new HostedSharePointServer();
ServiceProviderProxy.Init(sps, serviceId);
return sps;
}
private static int GetHostedSharePointServiceId(int packageId)
{
return PackageController.GetPackageServiceId(packageId, ResourceGroups.HostedSharePoint);
}
private static void PopulateBaseItem(BaseStatistics stats, Organization org, string topReseller)
{
PackageInfo package;
UserInfo user;
try
{
package = PackageController.GetPackage(org.PackageId);
}
catch(Exception ex)
{
throw new ApplicationException(string.Format("Could not get package {0}", org.PackageId), ex);
}
try
{
user = UserController.GetUser(package.UserId);
}
catch(Exception ex)
{
throw new ApplicationException(string.Format("Could not get user {0}", package.UserId), ex);
}
stats.HostingSpace = package.PackageName;
stats.OrganizationID = org.OrganizationId;
stats.OrganizationName = org.Name;
stats.CustomerName = UserController.GetUser(package.UserId).Username;
stats.CustomerCreated = user.Created;
stats.ResellerName = UserController.GetUser(user.OwnerId).Username;
stats.TopResellerName = topReseller;
stats.OrganizationCreated = org.CreatedDate;
stats.HostingSpaceCreated = package.PurchaseDate;
}
private static int GetCRMServiceId(int packageId)
{
int serviceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.HostedCRM);
return serviceId;
}
private static CRM GetCRMProxy(int packageId)
{
int crmServiceId = GetCRMServiceId(packageId);
CRM ws = new CRM();
ServiceProviderProxy.Init(ws, crmServiceId);
return ws;
}
private static void PopulateCRMReportItems(Organization org, EnterpriseSolutionStatisticsReport report, string topReseller)
{
if (org.CrmOrganizationId == Guid.Empty)
return;
List<OrganizationUser> users;
try
{
users = CRMController.GetCRMOrganizationUsers(org.Id);
}
catch(Exception ex)
{
throw new ApplicationException(
string.Format("Could not get CRM Organization users. OrgId : {0}", org.Id), ex);
}
CRM crm;
try
{
crm = GetCRMProxy(org.PackageId);
}
catch(Exception ex)
{
throw new ApplicationException(string.Format("Could not get CRM Proxy. PackageId: {0}", org.PackageId),
ex);
}
foreach (OrganizationUser user in users)
{
try
{
CRMOrganizationStatistics stats = new CRMOrganizationStatistics();
PopulateBaseItem(stats, org, topReseller);
stats.CRMOrganizationId = org.CrmOrganizationId;
stats.CRMUserName = user.DisplayName;
Guid crmUserId = CRMController.GetCrmUserId(user.AccountId);
CrmUserResult res = crm.GetCrmUserById(crmUserId, org.OrganizationId);
if (res.IsSuccess && res.Value != null)
{
stats.ClientAccessMode = res.Value.ClientAccessMode;
stats.CRMDisabled = res.Value.IsDisabled;
}
else
{
StringBuilder sb = new StringBuilder("Could not get CRM user by id.");
foreach (string str in res.ErrorCodes)
{
sb.AppendFormat("\n{0};", str);
}
throw new ApplicationException(sb.ToString());
}
report.CRMReport.Items.Add(stats);
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
}
}
}
private static void PopulateOrganizationData(Organization org, EnterpriseSolutionStatisticsReport report, string topReseller)
{
if (report.ExchangeReport != null)
{
try
{
PopulateExchangeReportItems(org, report, topReseller);
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
}
}
if (report.CRMReport != null)
{
try
{
PopulateCRMReportItems(org, report, topReseller);
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
}
}
if (report.SharePointReport != null)
{
try
{
PopulateSharePointItem(org, report, topReseller);
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
}
}
if (report.LyncReport != null)
{
try
{
PopulateLyncReportItems(org, report, topReseller);
}
catch (Exception ex)
{
TaskManager.WriteError(ex);
}
}
if (report.OrganizationReport != null)
{
try
{
PopulateOrganizationStatisticsReport(org, report, topReseller);
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
}
}
}
private static int GetExchangeServiceID(int packageId)
{
return PackageController.GetPackageServiceId(packageId, ResourceGroups.Exchange);
}
private static int GetLyncServiceID(int packageId)
{
return PackageController.GetPackageServiceId(packageId, ResourceGroups.Lync);
}
private static void PopulateSharePointItem(Organization org, EnterpriseSolutionStatisticsReport report, string topReseller)
{
List<SharePointSiteCollection> siteCollections;
try
{
siteCollections = HostedSharePointServerController.GetSiteCollections(org.Id);
}
catch(Exception ex)
{
throw new ApplicationException(string.Format("Could not get site collections. OrgId: {0}", org.Id), ex);
}
if (siteCollections == null || siteCollections.Count == 0)
return;
HostedSharePointServer srv;
try
{
int serviceId = GetHostedSharePointServiceId(org.PackageId);
srv = GetHostedSharePointServer(serviceId);
}
catch(Exception ex)
{
throw new ApplicationException(
string.Format("Could not get sharepoint server. PackageId: {0}", org.PackageId), ex);
}
foreach (SharePointSiteCollection siteCollection in siteCollections)
{
try
{
SharePointStatistics stats = new SharePointStatistics();
PopulateBaseItem(stats, org, topReseller);
stats.SiteCollectionUrl = siteCollection.PhysicalAddress;
stats.SiteCollectionOwner = siteCollection.OwnerName;
stats.SiteCollectionQuota = siteCollection.MaxSiteStorage;
stats.SiteCollectionCreated = siteCollection.CreatedDate;
stats.SiteCollectionSize = srv.GetSiteCollectionSize(siteCollection.PhysicalAddress);
report.SharePointReport.Items.Add(stats);
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
}
}
}
private static void PopulateExchangeReportItems(Organization org, EnterpriseSolutionStatisticsReport report, string topReseller)
{
//Check if exchange organization
if (string.IsNullOrEmpty(org.GlobalAddressList))
return;
List<ExchangeAccount> mailboxes;
Providers.Exchange.ExchangeServer exchange;
try
{
mailboxes = ExchangeServerController.GetExchangeMailboxes(org.Id);
}
catch (Exception ex)
{
throw new ApplicationException(
string.Format("Could not get mailboxes for current organization {0}", org.Id), ex);
}
try
{
int exchangeServiceId = GetExchangeServiceID(org.PackageId);
exchange = ExchangeServerController.GetExchangeServer(exchangeServiceId, org.ServiceId);
}
catch(Exception ex)
{
throw new ApplicationException(
string.Format("Could not get exchange server. PackageId: {0}", org.PackageId), ex);
}
ExchangeMailboxStatistics stats;
foreach (ExchangeAccount mailbox in mailboxes)
{
try
{
stats = null;
try
{
stats = exchange.GetMailboxStatistics(mailbox.UserPrincipalName);
}
catch (Exception ex)
{
TaskManager.WriteError(ex, "Could not get mailbox statistics. AccountName: {0}",
mailbox.UserPrincipalName);
}
if (stats != null)
{
PopulateBaseItem(stats, org, topReseller);
stats.MailboxType = mailbox.AccountType;
if (mailbox.AccountType == ExchangeAccountType.Mailbox)
{
ExchangeAccount a = ExchangeServerController.GetAccount(mailbox.ItemId, mailbox.AccountId);
stats.MailboxPlan = a.MailboxPlan;
}
stats.BlackberryEnabled = BlackBerryController.CheckBlackBerryUserExists(mailbox.AccountId);
report.ExchangeReport.Items.Add(stats);
}
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
}
}
}
private static void PopulateLyncReportItems(Organization org, EnterpriseSolutionStatisticsReport report, string topReseller)
{
//Check if lync organization
if (string.IsNullOrEmpty(org.LyncTenantId))
return;
LyncUser[] lyncUsers = null;
try
{
LyncUsersPagedResult res = LyncController.GetLyncUsers(org.Id);
if (res.IsSuccess) lyncUsers = res.Value.PageUsers;
}
catch (Exception ex)
{
throw new ApplicationException(
string.Format("Could not get lync users for current organization {0}", org.Id), ex);
}
if (lyncUsers == null)
return;
foreach (LyncUser lyncUser in lyncUsers)
{
try
{
LyncUserStatistics stats = new LyncUserStatistics();
try
{
stats.SipAddress = lyncUser.SipAddress;
if (string.IsNullOrEmpty(lyncUser.LineUri)) stats.PhoneNumber = string.Empty; else stats.PhoneNumber = lyncUser.LineUri;
LyncUserPlan plan = LyncController.GetLyncUserPlan(org.Id, lyncUser.LyncUserPlanId);
stats.Conferencing = plan.Conferencing;
stats.EnterpriseVoice = plan.EnterpriseVoice;
stats.Federation = plan.Federation;
stats.InstantMessaing = plan.IM;
stats.MobileAccess = plan.Mobility;
stats.LyncUserPlan = plan.LyncUserPlanName;
stats.DisplayName = lyncUser.DisplayName;
}
catch (Exception ex)
{
TaskManager.WriteError(ex, "Could not get lync statistics. AccountName: {0}",
lyncUser.DisplayName);
}
if (stats != null)
{
PopulateBaseItem(stats, org, topReseller);
report.LyncReport.Items.Add(stats);
}
}
catch (Exception ex)
{
TaskManager.WriteError(ex);
}
}
}
private static void PopulateSpaceData(int packageId, EnterpriseSolutionStatisticsReport report, string topReseller)
{
List<Organization> organizations;
try
{
organizations = OrganizationController.GetOrganizations(packageId, false);
}
catch(Exception ex)
{
throw new ApplicationException(string.Format("Cannot get organizations in current package {0}", packageId), ex);
}
foreach(Organization org in organizations)
{
try
{
PopulateOrganizationData(org, report, topReseller);
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
}
}
}
private static void PopulateUserData(UserInfo user, EnterpriseSolutionStatisticsReport report, string topReseller)
{
DataSet ds;
try
{
ds = PackageController.GetRawMyPackages(user.UserId);
}
catch(Exception ex)
{
throw new ApplicationException(string.Format("Cannot get user's spaces {0}", user.UserId), ex);
}
foreach(DataRow row in ds.Tables[0].Rows)
{
int packageId = (int) row["PackageID"];
try
{
PopulateSpaceData(packageId, report, topReseller);
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
}
}
}
private static void GetUsersData(EnterpriseSolutionStatisticsReport report, int userId, bool generateExchangeReport, bool generateSharePointReport, bool generateCRMReport, bool generateOrganizationReport, bool generateLyncReport, string topReseller)
{
List<UserInfo> users;
try
{
users = UserController.GetUsers(userId, false);
}
catch(Exception ex)
{
throw new ApplicationException("Cannot get users for report", ex);
}
foreach (UserInfo user in users)
{
try
{
PopulateUserData(user, report, topReseller);
if (user.Role == UserRole.Reseller || user.Role == UserRole.Administrator)
{
GetUsersData(report, user.UserId, generateExchangeReport, generateSharePointReport,
generateCRMReport,
generateOrganizationReport,
generateLyncReport,
string.IsNullOrEmpty(topReseller) ? user.Username : topReseller);
}
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
}
}
}
public static EnterpriseSolutionStatisticsReport GetEnterpriseSolutionStatisticsReport(int userId, bool generateExchangeReport, bool generateSharePointReport, bool generateCRMReport, bool generateOrganizationReport, bool generateLyncReport)
{
EnterpriseSolutionStatisticsReport report = new EnterpriseSolutionStatisticsReport();
if (generateExchangeReport || generateOrganizationReport)
report.ExchangeReport = new ExchangeStatisticsReport();
if (generateSharePointReport || generateOrganizationReport)
report.SharePointReport = new SharePointStatisticsReport();
if (generateLyncReport || generateOrganizationReport)
report.LyncReport = new LyncStatisticsReport();
if (generateCRMReport || generateOrganizationReport)
report.CRMReport = new CRMStatisticsReport();
if (generateOrganizationReport)
report.OrganizationReport = new OrganizationStatisticsReport();
try
{
GetUsersData(report, userId, generateExchangeReport, generateSharePointReport, generateCRMReport,
generateOrganizationReport, generateLyncReport, null);
}
catch(Exception ex)
{
TaskManager.WriteError(ex, "Cannot get enterprise solution statistics report");
}
return report;
}
}
}