2019-06-14 16:14:24 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System Limited 2010-2018
|
|
|
|
*
|
|
|
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
|
|
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
|
|
|
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
|
|
|
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
|
|
|
*
|
|
|
|
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
|
|
|
*
|
|
|
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
|
|
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
|
|
|
*
|
|
|
|
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
|
|
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
|
|
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
|
|
|
* in every copy of the program you distribute.
|
|
|
|
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-02-17 08:58:14 +00:00
|
|
|
|
|
|
|
using ASC.Common;
|
2019-06-14 16:14:24 +00:00
|
|
|
using ASC.Core;
|
|
|
|
using ASC.Core.Tenants;
|
|
|
|
using ASC.Core.Users;
|
|
|
|
|
|
|
|
namespace ASC.Web.Studio.UserControls.Statistics
|
|
|
|
{
|
2019-09-09 12:56:33 +00:00
|
|
|
public class TenantStatisticsProvider
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2020-08-12 09:58:08 +00:00
|
|
|
private UserManager UserManager { get; }
|
|
|
|
private TenantManager TenantManager { get; }
|
2019-09-09 12:56:33 +00:00
|
|
|
|
2019-09-16 14:51:39 +00:00
|
|
|
public TenantStatisticsProvider(UserManager userManager, TenantManager tenantManager)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2019-09-09 12:56:33 +00:00
|
|
|
UserManager = userManager;
|
2019-09-16 14:51:39 +00:00
|
|
|
TenantManager = tenantManager;
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2019-09-12 11:34:58 +00:00
|
|
|
public int GetUsersCount()
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2019-09-12 11:34:58 +00:00
|
|
|
return UserManager.GetUsersByGroup(Constants.GroupUser.ID).Length;
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 12:56:33 +00:00
|
|
|
public long GetUsedSize()
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2019-09-16 14:51:39 +00:00
|
|
|
return GetUsedSize(TenantManager.GetCurrentTenant().TenantId);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 12:56:33 +00:00
|
|
|
public long GetUsedSize(int tenant)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
|
|
|
return GetQuotaRows(tenant).Sum(r => r.Counter);
|
|
|
|
}
|
|
|
|
|
2019-09-09 12:56:33 +00:00
|
|
|
public long GetUsedSize(Guid moduleId)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2019-09-16 14:51:39 +00:00
|
|
|
return GetQuotaRows(TenantManager.GetCurrentTenant().TenantId).Where(r => new Guid(r.Tag).Equals(moduleId)).Sum(r => r.Counter);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 12:56:33 +00:00
|
|
|
public IEnumerable<TenantQuotaRow> GetQuotaRows(int tenant)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2019-09-18 12:14:15 +00:00
|
|
|
return TenantManager.FindTenantQuotaRows(new TenantQuotaRowQuery(tenant))
|
2019-06-14 16:14:24 +00:00
|
|
|
.Where(r => !string.IsNullOrEmpty(r.Tag) && new Guid(r.Tag) != Guid.Empty);
|
|
|
|
}
|
|
|
|
}
|
2019-10-31 11:28:30 +00:00
|
|
|
|
2019-11-11 09:03:49 +00:00
|
|
|
public static class TenantStatisticsProviderExtension
|
2019-10-31 11:28:30 +00:00
|
|
|
{
|
2020-02-17 08:58:14 +00:00
|
|
|
public static DIHelper AddTenantStatisticsProviderService(this DIHelper services)
|
2019-10-31 11:28:30 +00:00
|
|
|
{
|
2020-07-17 10:52:28 +00:00
|
|
|
if (services.TryAddScoped<TenantStatisticsProvider>())
|
|
|
|
{
|
|
|
|
return services
|
|
|
|
.AddUserManagerService()
|
|
|
|
.AddTenantManagerService();
|
|
|
|
}
|
2019-10-31 11:28:30 +00:00
|
|
|
|
2020-07-17 10:52:28 +00:00
|
|
|
return services;
|
2019-10-31 11:28:30 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|