crm: refactoring

This commit is contained in:
Alexey Bannov 2021-05-28 20:20:12 +03:00
parent 401c8ca2e2
commit a9a7c0a4b7
22 changed files with 288 additions and 288 deletions

View File

@ -48,10 +48,10 @@ namespace ASC.CRM.Api
{
}
public WebItemSecurity WebItemSecurity { get; }
public DaoFactory DaoFactory { get; }
public TenantManager TenantManager { get; }
public TenantUtil TenantUtil { get; }
private WebItemSecurity _webItemSecurity;
private DaoFactory _daoFactory;
private TenantManager _tenantManager;
private TenantUtil _tenantUtil;
public CrmCalendar(WebItemSecurity webItemSecurity,
DaoFactory daoFactory,
@ -61,10 +61,10 @@ namespace ASC.CRM.Api
TenantUtil tenantUtil
) : base(authContext, timeZoneConverter)
{
TenantUtil = tenantUtil;
TenantManager = tenantManager;
WebItemSecurity = webItemSecurity;
DaoFactory = daoFactory;
_tenantUtil = tenantUtil;
_tenantManager = tenantManager;
_webItemSecurity = webItemSecurity;
_daoFactory = daoFactory;
Context.HtmlBackgroundColor = "";
Context.HtmlTextColor = "";
@ -84,12 +84,12 @@ namespace ASC.CRM.Api
var events = new List<IEvent>();
if (
!WebItemSecurity.IsAvailableForMe(WebItemManager.CRMProductID))
!_webItemSecurity.IsAvailableForMe(WebItemManager.CRMProductID))
{
return events;
}
var tasks = DaoFactory.GetTaskDao().GetTasks(String.Empty, userId, 0, false, DateTime.MinValue,
var tasks = _daoFactory.GetTaskDao().GetTasks(String.Empty, userId, 0, false, DateTime.MinValue,
DateTime.MinValue, EntityType.Any, 0, 0, 0, null);
foreach (var t in tasks)
@ -97,7 +97,7 @@ namespace ASC.CRM.Api
if (t.DeadLine == DateTime.MinValue) continue;
var allDayEvent = t.DeadLine.Hour == 0 && t.DeadLine.Minute == 0;
var utcDate = allDayEvent ? t.DeadLine.Date : TenantUtil.DateTimeToUtc(t.DeadLine);
var utcDate = allDayEvent ? t.DeadLine.Date : _tenantUtil.DateTimeToUtc(t.DeadLine);
var e = new Event
{
@ -121,7 +121,7 @@ namespace ASC.CRM.Api
public override TimeZoneInfo TimeZone
{
get { return TimeZoneInfo.FindSystemTimeZoneById(TenantManager.GetCurrentTenant().TimeZone); }
get { return TimeZoneInfo.FindSystemTimeZoneById(_tenantManager.GetCurrentTenant().TimeZone); }
}
private bool IsVisibleEvent(DateTime startDate, DateTime endDate, DateTime eventStartDate, DateTime eventEndDate)

View File

@ -49,6 +49,16 @@ namespace ASC.Web.CRM.Classes
[Scope]
public class Global
{
private IConfiguration _configuration;
private SettingsManager _settingsManager;
protected int _tenantID;
private FilesLinkUtility _filesLinkUtility;
private SetupInfo _setupInfo;
private SecurityContext _securityContext;
private StorageFactory _storageFactory;
private CrmSecurity _crmSecurity;
public Global(StorageFactory storageFactory,
SecurityContext securityContext,
SetupInfo setupInfo,
@ -59,19 +69,16 @@ namespace ASC.Web.CRM.Classes
IConfiguration configuration
)
{
StorageFactory = storageFactory;
FilesLinkUtility = filesLinkUtility;
SetupInfo = setupInfo;
SecurityContext = securityContext;
CRMSecurity = crmSecurity;
TenantID = tenantManager.GetCurrentTenant().TenantId;
SettingsManager = settingsManager;
Configuration = configuration;
_storageFactory = storageFactory;
_filesLinkUtility = filesLinkUtility;
_setupInfo = setupInfo;
_securityContext = securityContext;
_crmSecurity = crmSecurity;
_tenantID = tenantManager.GetCurrentTenant().TenantId;
_settingsManager = settingsManager;
_configuration = configuration;
}
public IConfiguration Configuration { get; }
public SettingsManager SettingsManager { get; }
public static readonly int EntryCountOnPage = 25;
public static readonly int VisiblePageCount = 10;
@ -87,25 +94,15 @@ namespace ASC.Web.CRM.Classes
public static readonly int MaxHistoryEventCharacters = 65000;
public static readonly decimal MaxInvoiceItemPrice = (decimal)99999999.99;
protected int TenantID { get; private set; }
public FilesLinkUtility FilesLinkUtility { get; }
public SetupInfo SetupInfo { get; }
public SecurityContext SecurityContext { get; }
public StorageFactory StorageFactory { get; }
public CrmSecurity CRMSecurity { get; }
public IDataStore GetStore()
{
return StorageFactory.GetStorage(TenantID.ToString(), "crm");
return _storageFactory.GetStorage(_tenantID.ToString(), "crm");
}
public IDataStore GetStoreTemplate()
{
return StorageFactory.GetStorage(String.Empty, "crm_template");
return _storageFactory.GetStorage(String.Empty, "crm_template");
}
public bool CanCreateProjects()
@ -150,12 +147,12 @@ namespace ASC.Web.CRM.Classes
{
get
{
var value = Configuration["crm:invoice:download:enable"];
var value = _configuration["crm:invoice:download:enable"];
if (string.IsNullOrEmpty(value)) return false;
bool canDownloadFiles = Convert.ToBoolean(value);
if (canDownloadFiles && string.IsNullOrEmpty(FilesLinkUtility.DocServiceConverterUrl))
if (canDownloadFiles && string.IsNullOrEmpty(_filesLinkUtility.DocServiceConverterUrl))
{
canDownloadFiles = false;
}
@ -168,16 +165,16 @@ namespace ASC.Web.CRM.Classes
{
get
{
return !string.IsNullOrEmpty(FilesLinkUtility.DocServiceDocbuilderUrl) && CRMSecurity.IsAdmin;
return !string.IsNullOrEmpty(_filesLinkUtility.DocServiceDocbuilderUrl) && _crmSecurity.IsAdmin;
}
}
public void SaveDefaultCurrencySettings(CurrencyInfo currency)
{
var tenantSettings = SettingsManager.Load<CrmSettings>();
var tenantSettings = _settingsManager.Load<CrmSettings>();
tenantSettings.DefaultCurrency = currency.Abbreviation;
SettingsManager.Save<CrmSettings>(tenantSettings);
_settingsManager.Save<CrmSettings>(tenantSettings);
}

View File

@ -43,24 +43,24 @@ namespace ASC.Web.CRM.Classes
[Scope]
public class ImportFromCSVManager
{
private MessageService _messageService;
private ImportFromCSV _importFromCSV;
private Global _global;
public ImportFromCSVManager(Global global,
ImportFromCSV importFromCSV,
MessageService messageService)
{
Global = global;
ImportFromCSV = importFromCSV;
MessageService = messageService;
_global = global;
_importFromCSV = importFromCSV;
_messageService = messageService;
}
public MessageService MessageService { get; }
public ImportFromCSV ImportFromCSV { get; }
public Global Global { get; }
public void StartImport(EntityType entityType, String CSVFileURI, String importSettingsJSON)
{
ImportFromCSV.Start(entityType, CSVFileURI, importSettingsJSON);
_importFromCSV.Start(entityType, CSVFileURI, importSettingsJSON);
MessageService.Send(GetMessageAction(entityType));
_messageService.Send(GetMessageAction(entityType));
}
public FileUploadResult ProcessUploadFake(string fileTemp, string importSettingsJSON)
@ -69,12 +69,12 @@ namespace ASC.Web.CRM.Classes
if (String.IsNullOrEmpty(fileTemp) || String.IsNullOrEmpty(importSettingsJSON)) return fileUploadResult;
if (!Global.GetStore().IsFile("temp", fileTemp)) return fileUploadResult;
if (!_global.GetStore().IsFile("temp", fileTemp)) return fileUploadResult;
JsonDocument jObject;
//Read contents
using (Stream storeStream = Global.GetStore().GetReadStream("temp", fileTemp))
using (Stream storeStream = _global.GetStore().GetReadStream("temp", fileTemp))
{
using (var CSVFileStream = new MemoryStream())
{
@ -87,7 +87,7 @@ namespace ASC.Web.CRM.Classes
}
CSVFileStream.Position = 0;
jObject = ImportFromCSV.GetInfo(CSVFileStream, importSettingsJSON);
jObject = _importFromCSV.GetInfo(CSVFileStream, importSettingsJSON);
}
}

View File

@ -42,16 +42,16 @@ namespace ASC.Web.CRM.Classes
[Scope]
public class InvoiceFormattedData
{
private OrganisationLogoManager _organisationLogoManager;
private DaoFactory _daoFactory;
public InvoiceFormattedData(DaoFactory daoFactory,
OrganisationLogoManager organisationLogoManager)
{
DaoFactory = daoFactory;
OrganisationLogoManager = organisationLogoManager;
_daoFactory = daoFactory;
_organisationLogoManager = organisationLogoManager;
}
public OrganisationLogoManager OrganisationLogoManager { get; }
public DaoFactory DaoFactory { get; }
public int TemplateType { get; set; }
public Tuple<string, string> Seller { get; set; }
@ -92,7 +92,7 @@ namespace ASC.Web.CRM.Classes
private InvoiceFormattedData CreateData(Invoice invoice, int billingAddressID, int deliveryAddressID)
{
var data = new InvoiceFormattedData(DaoFactory, OrganisationLogoManager);
var data = new InvoiceFormattedData(_daoFactory, _organisationLogoManager);
var sb = new StringBuilder();
var list = new List<string>();
var cultureInfo = string.IsNullOrEmpty(invoice.Language)
@ -107,7 +107,7 @@ namespace ASC.Web.CRM.Classes
#region Seller, LogoBase64, LogoSrcFormat
var invoiceSettings = DaoFactory.GetInvoiceDao().GetSettings();
var invoiceSettings = _daoFactory.GetInvoiceDao().GetSettings();
if (!string.IsNullOrEmpty(invoiceSettings.CompanyName))
{
@ -153,7 +153,7 @@ namespace ASC.Web.CRM.Classes
{
data.LogoBase64Id = invoiceSettings.CompanyLogoID;
//data.LogoBase64 = OrganisationLogoManager.GetOrganisationLogoBase64(invoiceSettings.CompanyLogoID);
data.LogoSrcFormat = OrganisationLogoManager.OrganisationLogoSrcFormat;
data.LogoSrcFormat = _organisationLogoManager.OrganisationLogoSrcFormat;
}
#endregion
@ -190,7 +190,7 @@ namespace ASC.Web.CRM.Classes
#region Customer
var customer = DaoFactory.GetContactDao().GetByID(invoice.ContactID);
var customer = _daoFactory.GetContactDao().GetByID(invoice.ContactID);
if (customer != null)
{
@ -199,7 +199,7 @@ namespace ASC.Web.CRM.Classes
sb.Append(customer.GetTitle());
var billingAddress = billingAddressID != 0
? DaoFactory.GetContactInfoDao().GetByID(billingAddressID)
? _daoFactory.GetContactInfoDao().GetByID(billingAddressID)
: null;
if (billingAddress != null && billingAddress.InfoType == ContactInfoType.Address &&
billingAddress.Category == (int)AddressCategory.Billing)
@ -258,7 +258,7 @@ namespace ASC.Web.CRM.Classes
data.TableBodyRows = new List<List<string>>();
var invoiceLines = invoice.GetInvoiceLines(DaoFactory);
var invoiceLines = invoice.GetInvoiceLines(_daoFactory);
var invoiceTaxes = new Dictionary<int, decimal>();
decimal subtotal = 0;
@ -267,12 +267,12 @@ namespace ASC.Web.CRM.Classes
foreach (var line in invoiceLines)
{
var item = DaoFactory.GetInvoiceItemDao().GetByID(line.InvoiceItemID);
var item = _daoFactory.GetInvoiceItemDao().GetByID(line.InvoiceItemID);
var tax1 = line.InvoiceTax1ID > 0
? DaoFactory.GetInvoiceTaxDao().GetByID(line.InvoiceTax1ID)
? _daoFactory.GetInvoiceTaxDao().GetByID(line.InvoiceTax1ID)
: null;
var tax2 = line.InvoiceTax2ID > 0
? DaoFactory.GetInvoiceTaxDao().GetByID(line.InvoiceTax2ID)
? _daoFactory.GetInvoiceTaxDao().GetByID(line.InvoiceTax2ID)
: null;
var subtotalValue = Math.Round(line.Quantity * line.Price, 2);
@ -332,7 +332,7 @@ namespace ASC.Web.CRM.Classes
foreach (var invoiceTax in invoiceTaxes)
{
var iTax = DaoFactory.GetInvoiceTaxDao().GetByID(invoiceTax.Key);
var iTax = _daoFactory.GetInvoiceTaxDao().GetByID(invoiceTax.Key);
data.TableFooterRows.Add(new Tuple<string, string>(
string.Format("{0} ({1}%)", iTax.Name, iTax.Rate),
invoiceTax.Value.ToString(CultureInfo.InvariantCulture)));
@ -373,7 +373,7 @@ namespace ASC.Web.CRM.Classes
#region Consignee
var consignee = DaoFactory.GetContactDao().GetByID(invoice.ConsigneeID);
var consignee = _daoFactory.GetContactDao().GetByID(invoice.ConsigneeID);
if (consignee != null)
{
@ -382,7 +382,7 @@ namespace ASC.Web.CRM.Classes
sb.Append(consignee.GetTitle());
var deliveryAddress = deliveryAddressID != 0
? DaoFactory.GetContactInfoDao().GetByID(deliveryAddressID)
? _daoFactory.GetContactInfoDao().GetByID(deliveryAddressID)
: null;
if (deliveryAddress != null && deliveryAddress.InfoType == ContactInfoType.Address &&
deliveryAddress.Category == (int)AddressCategory.Postal)
@ -438,7 +438,7 @@ namespace ASC.Web.CRM.Classes
private InvoiceFormattedData ReadData(string jsonData)
{
var data = new InvoiceFormattedData(DaoFactory, OrganisationLogoManager);
var data = new InvoiceFormattedData(_daoFactory, _organisationLogoManager);
var jsonObj = JsonDocument.Parse(jsonData).RootElement;
#region TemplateType
@ -461,7 +461,7 @@ namespace ASC.Web.CRM.Classes
if (string.IsNullOrEmpty(data.LogoBase64) && data.LogoBase64Id != 0)
{
data.LogoBase64 = OrganisationLogoManager.GetOrganisationLogoBase64(data.LogoBase64Id);
data.LogoBase64 = _organisationLogoManager.GetOrganisationLogoBase64(data.LogoBase64Id);
}
@ -588,7 +588,7 @@ namespace ASC.Web.CRM.Classes
data.TableBodyRows = new List<List<string>>();
var invoiceLines = invoice.GetInvoiceLines(DaoFactory);
var invoiceLines = invoice.GetInvoiceLines(_daoFactory);
var invoiceTaxes = new Dictionary<int, decimal>();
decimal subtotal = 0;
@ -597,12 +597,12 @@ namespace ASC.Web.CRM.Classes
foreach (var line in invoiceLines)
{
var item = DaoFactory.GetInvoiceItemDao().GetByID(line.InvoiceItemID);
var item = _daoFactory.GetInvoiceItemDao().GetByID(line.InvoiceItemID);
var tax1 = line.InvoiceTax1ID > 0
? DaoFactory.GetInvoiceTaxDao().GetByID(line.InvoiceTax1ID)
? _daoFactory.GetInvoiceTaxDao().GetByID(line.InvoiceTax1ID)
: null;
var tax2 = line.InvoiceTax2ID > 0
? DaoFactory.GetInvoiceTaxDao().GetByID(line.InvoiceTax2ID)
? _daoFactory.GetInvoiceTaxDao().GetByID(line.InvoiceTax2ID)
: null;
var subtotalValue = Math.Round(line.Quantity * line.Price, 2);
@ -662,7 +662,7 @@ namespace ASC.Web.CRM.Classes
foreach (var invoiceTax in invoiceTaxes)
{
var iTax = DaoFactory.GetInvoiceTaxDao().GetByID(invoiceTax.Key);
var iTax = _daoFactory.GetInvoiceTaxDao().GetByID(invoiceTax.Key);
data.TableFooterRows.Add(new Tuple<string, string>(
string.Format("{0} ({1}%)", iTax.Name, iTax.Rate),
invoiceTax.Value.ToString(CultureInfo.InvariantCulture)));

View File

@ -44,23 +44,22 @@ namespace ASC.Web.CRM.Classes
[Scope]
public class OrganisationLogoManager
{
private DaoFactory _daoFactory;
private ILog _logger;
private Global _global;
private WebImageSupplier _webImageSupplier;
public OrganisationLogoManager(WebImageSupplier webImageSupplier,
Global global,
IOptionsMonitor<ILog> logger,
DaoFactory daoFactory)
{
WebImageSupplier = webImageSupplier;
Global = global;
Logger = logger.Get("ASC.CRM");
DaoFactory = daoFactory;
_webImageSupplier = webImageSupplier;
_global = global;
_logger = logger.Get("ASC.CRM");
_daoFactory = daoFactory;
}
public DaoFactory DaoFactory { get; }
public ILog Logger { get; }
public Global Global { get; }
public WebImageSupplier WebImageSupplier { get; }
#region Members
@ -120,14 +119,14 @@ namespace ASC.Web.CRM.Classes
public String GetDefaultLogoUrl()
{
return WebImageSupplier.GetAbsoluteWebPath("org_logo_default.png", ProductEntryPoint.ID);
return _webImageSupplier.GetAbsoluteWebPath("org_logo_default.png", ProductEntryPoint.ID);
}
public String GetOrganisationLogoBase64(int logoID)
{
if (logoID <= 0) { return ""; }
return DaoFactory.GetInvoiceDao().GetOrganisationLogoBase64(logoID);
return _daoFactory.GetInvoiceDao().GetOrganisationLogoBase64(logoID);
}
@ -141,7 +140,7 @@ namespace ASC.Web.CRM.Classes
public void DeletePhoto(bool recursive)
{
var photoDirectory = BuildFileDirectory();
var store = Global.GetStore();
var store = _global.GetStore();
lock (_synchronizedObj)
{
@ -159,14 +158,14 @@ namespace ASC.Web.CRM.Classes
public int TryUploadOrganisationLogoFromTmp(DaoFactory factory)
{
var directoryPath = BuildFileDirectory();
var dataStore = Global.GetStore();
var dataStore = _global.GetStore();
if (!dataStore.IsDirectory(directoryPath))
return 0;
try
{
var photoPaths = Global.GetStore().ListFilesRelative("", directoryPath, OrganisationLogoImgName + "*", false);
var photoPaths = _global.GetStore().ListFilesRelative("", directoryPath, OrganisationLogoImgName + "*", false);
if (photoPaths.Length == 0)
return 0;
@ -183,7 +182,7 @@ namespace ASC.Web.CRM.Classes
catch (Exception ex)
{
Logger.ErrorFormat("TryUploadOrganisationLogoFromTmp failed with error: {0}", ex);
_logger.ErrorFormat("TryUploadOrganisationLogoFromTmp failed with error: {0}", ex);
return 0;
}
@ -193,7 +192,7 @@ namespace ASC.Web.CRM.Classes
{
var photoPath = BuildFilePath("." + Global.GetImgFormatName(imageFormat));
return ExecResizeImage(imageData, OrganisationLogoSize, Global.GetStore(), photoPath);
return ExecResizeImage(imageData, OrganisationLogoSize, _global.GetStore(), photoPath);
}
}
}

View File

@ -41,19 +41,19 @@ namespace ASC.Web.CRM
[Scope]
public class PathProvider
{
private HttpContext _httpContext;
private CommonLinkUtility _commonLinkUtility;
private WebPath _webPath;
public PathProvider(IHttpContextAccessor httpContextAccessor,
CommonLinkUtility commonLinkUtility)
{
CommonLinkUtility = commonLinkUtility;
HttpContext = httpContextAccessor.HttpContext;
_commonLinkUtility = commonLinkUtility;
_httpContext = httpContextAccessor.HttpContext;
BaseAbsolutePath = CommonLinkUtility.ToAbsolute(BaseVirtualPath);
BaseAbsolutePath = _commonLinkUtility.ToAbsolute(BaseVirtualPath);
}
public HttpContext HttpContext { get; }
public CommonLinkUtility CommonLinkUtility { get; }
public WebPath WebPath { get; }
public readonly String BaseVirtualPath = "~/Products/CRM/";
public readonly String BaseAbsolutePath;

View File

@ -36,38 +36,38 @@ namespace ASC.Web.CRM.Classes
{
private readonly string numberId;
public SignalrServiceClient SignalrServiceClient { get; }
private SignalrServiceClient _signalrServiceClient;
public SignalRHelper(string numberId,
SignalrServiceClient signalrServiceClient)
{
SignalrServiceClient = signalrServiceClient;
_signalrServiceClient = signalrServiceClient;
this.numberId = numberId.TrimStart('+');
}
public void Enqueue(string call, string agent)
{
SignalrServiceClient.EnqueueCall(numberId, call, agent);
_signalrServiceClient.EnqueueCall(numberId, call, agent);
}
public void Incoming(string call, string agent)
{
SignalrServiceClient.IncomingCall(call, agent);
_signalrServiceClient.IncomingCall(call, agent);
}
public void MissCall(string call, string agent)
{
SignalrServiceClient.MissCall(numberId, call, agent);
_signalrServiceClient.MissCall(numberId, call, agent);
}
public void Reload(string agentId = null)
{
SignalrServiceClient.Reload(numberId, agentId);
_signalrServiceClient.Reload(numberId, agentId);
}
public Tuple<Agent, bool> GetAgent(List<Guid> contactsResponsibles)
{
return SignalrServiceClient.GetAgent<Tuple<Agent, bool>>(numberId, contactsResponsibles);
return _signalrServiceClient.GetAgent<Tuple<Agent, bool>>(numberId, contactsResponsibles);
}
}
}

View File

@ -49,13 +49,14 @@ namespace ASC.Web.CRM
private readonly Guid _importCompleted = new Guid("{6A717AAD-16AE-4713-A782-B887766BEB9F}");
private readonly Guid _createNewContact = new Guid("{ADAC1E70-4163-41c1-8968-67A44E4D24E7}");
private CoreBaseSettings _coreBaseSettings;
public ProductSubscriptionManager(CoreBaseSettings coreBaseSettings, NotifySource notifySource)
{
CoreBaseSettings = coreBaseSettings;
_coreBaseSettings = coreBaseSettings;
}
public NotifySource NotifySource { get; }
public CoreBaseSettings CoreBaseSettings { get; }
public List<SubscriptionObject> GetSubscriptionObjects(Guid subItem)
{
@ -102,7 +103,7 @@ namespace ASC.Web.CRM
{
ID = _exportCompleted,
Name = CRMCommonResource.SubscriptionType_ExportCompleted,
NotifyAction = CoreBaseSettings.CustomMode ? NotifyConstants.Event_ExportCompletedCustomMode : NotifyConstants.Event_ExportCompleted,
NotifyAction = _coreBaseSettings.CustomMode ? NotifyConstants.Event_ExportCompletedCustomMode : NotifyConstants.Event_ExportCompleted,
Single = true,
CanSubscribe = true
},
@ -110,7 +111,7 @@ namespace ASC.Web.CRM
{
ID = _importCompleted,
Name = CRMCommonResource.SubscriptionType_ImportCompleted,
NotifyAction = CoreBaseSettings.CustomMode ? NotifyConstants.Event_ImportCompletedCustomMode : NotifyConstants.Event_ImportCompleted,
NotifyAction = _coreBaseSettings.CustomMode ? NotifyConstants.Event_ImportCompletedCustomMode : NotifyConstants.Event_ImportCompleted,
Single = true,
CanSubscribe = true
},

View File

@ -44,31 +44,32 @@ namespace ASC.Web.CRM.Configuration
[Scope]
public class CrmSpaceUsageStatManager : SpaceUsageStatManager
{
private int _tenantId;
private FilesDbContext _filesDbContext;
private PathProvider _pathProvider;
public CrmSpaceUsageStatManager(DbContextManager<FilesDbContext> filesDbContext,
PathProvider pathProvider,
TenantManager tenantManager)
{
PathProvider = pathProvider;
FilesDbContext = filesDbContext.Value;
TenantId = tenantManager.GetCurrentTenant().TenantId;
_pathProvider = pathProvider;
_filesDbContext = filesDbContext.Value;
_tenantId = tenantManager.GetCurrentTenant().TenantId;
}
public int TenantId { get; }
public FilesDbContext FilesDbContext { get; }
public PathProvider PathProvider { get; }
public override List<UsageSpaceStatItem> GetStatData()
{
var spaceUsage = FilesDbContext.Files.Join(FilesDbContext.Tree,
var spaceUsage = _filesDbContext.Files.Join(_filesDbContext.Tree,
x => x.FolderId,
y => y.FolderId,
(x, y) => new { x, y }
)
.Join(FilesDbContext.BunchObjects,
.Join(_filesDbContext.BunchObjects,
x => x.y.ParentId,
y => Convert.ToInt32(y.LeftNode),
(x, y) => new { x, y })
.Where(x => x.y.TenantId == TenantId &&
.Where(x => x.y.TenantId == _tenantId &&
Microsoft.EntityFrameworkCore.EF.Functions.Like(x.y.RightNode, "crm/crm_common/%"))
.Sum(x => x.x.x.ContentLength);
@ -78,7 +79,7 @@ namespace ASC.Web.CRM.Configuration
Name = CRMCommonResource.WholeCRMModule,
SpaceUsage = spaceUsage,
Url = VirtualPathUtility.ToAbsolute(PathProvider.StartURL())
Url = VirtualPathUtility.ToAbsolute(_pathProvider.StartURL())
}
};

View File

@ -48,23 +48,24 @@ namespace ASC.Web.CRM.Configuration
[Scope]
public class ProductEntryPoint : Product
{
private ProductContext _context;
private FilesIntegration _filesIntegration;
private PathProvider _pathProvider;
private SecurityContext _securityContext;
private UserManager _userManager;
public ProductEntryPoint(SecurityContext securityContext,
UserManager userManager,
PathProvider pathProvider,
FilesIntegration filesIntegration)
{
SecurityContext = securityContext;
UserManager = userManager;
PathProvider = pathProvider;
FilesIntegration = filesIntegration;
_securityContext = securityContext;
_userManager = userManager;
_pathProvider = pathProvider;
_filesIntegration = filesIntegration;
}
public static readonly Guid ID = WebItemManager.CRMProductID;
private ProductContext _context;
public FilesIntegration FilesIntegration { get; }
public PathProvider PathProvider { get; }
public SecurityContext SecurityContext { get; }
public UserManager UserManager { get; }
public override string ApiURL
{
get => "api/2.0/crm/info.json";
@ -75,17 +76,17 @@ namespace ASC.Web.CRM.Configuration
{
get
{
var id = SecurityContext.CurrentAccount.ID;
var id = _securityContext.CurrentAccount.ID;
if (UserManager.IsUserInGroup(id, ASC.Core.Users.Constants.GroupAdmin.ID) || UserManager.IsUserInGroup(id, ID))
if (_userManager.IsUserInGroup(id, ASC.Core.Users.Constants.GroupAdmin.ID) || _userManager.IsUserInGroup(id, ID))
return CRMCommonResource.ProductDescriptionEx;
return CRMCommonResource.ProductDescription;
}
}
public override string StartURL { get { return PathProvider.StartURL(); } }
public override string HelpURL { get { return string.Concat(PathProvider.BaseVirtualPath, "help.aspx"); } }
public override string StartURL { get { return _pathProvider.StartURL(); } }
public override string HelpURL { get { return string.Concat(_pathProvider.BaseVirtualPath, "help.aspx"); } }
public override string ProductClassName { get { return "crm"; } }
public override bool Visible { get { return true; } }
public override ProductContext Context { get { return _context; } }

View File

@ -36,15 +36,16 @@ namespace ASC.Web.CRM.Configuration
[WebZone(WebZoneType.CustomProductList)]
public class VoipModule : IAddon
{
private PathProvider _pathProvider;
private SetupInfo _setupInfo;
public VoipModule(PathProvider pathProvider,
SetupInfo setupInfo)
{
PathProvider = pathProvider;
SetupInfo = setupInfo;
_pathProvider = pathProvider;
_setupInfo = setupInfo;
}
public PathProvider PathProvider { get; }
public SetupInfo SetupInfo { get; }
public Guid ID
{
@ -63,7 +64,7 @@ namespace ASC.Web.CRM.Configuration
public string StartURL
{
get { return PathProvider.StartURL() + "settings.aspx?type=voip.common&sysname=/modules/voip"; }
get { return _pathProvider.StartURL() + "settings.aspx?type=voip.common&sysname=/modules/voip"; }
}
public string HelpURL
@ -73,7 +74,7 @@ namespace ASC.Web.CRM.Configuration
public string ProductClassName { get { return "voip"; } }
public bool Visible { get { return SetupInfo.VoipEnabled; } }
public bool Visible { get { return _setupInfo.VoipEnabled; } }
public AddonContext Context { get; private set; }

View File

@ -54,20 +54,20 @@ namespace ASC.Web.CRM.Services.NotifyService
[Scope]
public class NotifyClient
{
private IServiceProvider _serviceProvider;
public NotifyClient(IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
_serviceProvider = serviceProvider;
}
public IServiceProvider ServiceProvider { get; }
public void SendAboutCreateNewContact(List<Guid> recipientID,
int contactID,
string contactTitle, NameValueCollection fields)
{
if ((recipientID.Count == 0) || String.IsNullOrEmpty(contactTitle)) return;
using var scope = ServiceProvider.CreateScope();
using var scope = _serviceProvider.CreateScope();
var notifySource = scope.ServiceProvider.GetService<NotifySource>();
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(notifySource, scope);
@ -86,7 +86,7 @@ namespace ASC.Web.CRM.Services.NotifyService
{
if (userID.Length == 0) return;
using var scope = ServiceProvider.CreateScope();
using var scope = _serviceProvider.CreateScope();
var notifySource = scope.ServiceProvider.GetService<NotifySource>();
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(notifySource, scope);
@ -105,7 +105,7 @@ namespace ASC.Web.CRM.Services.NotifyService
private NameValueCollection ExtractBaseDataFrom(EntityType entityType, int entityID, DaoFactory daoFactory)
{
using var scope = ServiceProvider.CreateScope();
using var scope = _serviceProvider.CreateScope();
var pathProvider = scope.ServiceProvider.GetService<PathProvider>();
var result = new NameValueCollection();
@ -154,7 +154,7 @@ namespace ASC.Web.CRM.Services.NotifyService
{
if (userID.Length == 0) return;
using var scope = ServiceProvider.CreateScope();
using var scope = _serviceProvider.CreateScope();
var notifySource = scope.ServiceProvider.GetService<NotifySource>();
var pathProvider = scope.ServiceProvider.GetService<PathProvider>();
var securityContext = scope.ServiceProvider.GetService<SecurityContext>();
@ -219,7 +219,7 @@ namespace ASC.Web.CRM.Services.NotifyService
{
if (recipientID == Guid.Empty) return;
using var scope = ServiceProvider.CreateScope();
using var scope = _serviceProvider.CreateScope();
var coreBaseSettings = scope.ServiceProvider.GetService<CoreBaseSettings>();
var notifySource = scope.ServiceProvider.GetService<NotifySource>();
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(notifySource, scope);
@ -239,7 +239,7 @@ namespace ASC.Web.CRM.Services.NotifyService
{
if (recipientID == Guid.Empty) return;
using var scope = ServiceProvider.CreateScope();
using var scope = _serviceProvider.CreateScope();
var notifySource = scope.ServiceProvider.GetService<NotifySource>();
var coreBaseSettings = scope.ServiceProvider.GetService<CoreBaseSettings>();
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(notifySource, scope);
@ -282,7 +282,7 @@ namespace ASC.Web.CRM.Services.NotifyService
public void SendAutoReminderAboutTask(DateTime scheduleDate)
{
using var scope = ServiceProvider.CreateScope();
using var scope = _serviceProvider.CreateScope();
var defaultDao = scope.ServiceProvider.GetService<DaoFactory>();
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
@ -379,7 +379,7 @@ namespace ASC.Web.CRM.Services.NotifyService
public void SendTaskReminder(Task task, String taskCategoryTitle, Contact taskContact, ASC.CRM.Core.Entities.Cases taskCase, ASC.CRM.Core.Entities.Deal taskDeal)
{
using var scope = ServiceProvider.CreateScope();
using var scope = _serviceProvider.CreateScope();
var notifySource = scope.ServiceProvider.GetService<NotifySource>();
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(notifySource, scope);
@ -447,7 +447,7 @@ namespace ASC.Web.CRM.Services.NotifyService
public void SendAboutResponsibleByTask(Task task, String taskCategoryTitle, Contact taskContact, Cases taskCase, ASC.CRM.Core.Entities.Deal taskDeal, Hashtable fileListInfoHashtable)
{
using var scope = ServiceProvider.CreateScope();
using var scope = _serviceProvider.CreateScope();
var notifySource = scope.ServiceProvider.GetService<NotifySource>();
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(notifySource, scope);
var tenantUtil = scope.ServiceProvider.GetService<TenantUtil>();
@ -518,7 +518,7 @@ namespace ASC.Web.CRM.Services.NotifyService
public void SendAboutResponsibleForOpportunity(Deal deal)
{
using var scope = ServiceProvider.CreateScope();
using var scope = _serviceProvider.CreateScope();
var notifySource = scope.ServiceProvider.GetService<NotifySource>();
var securityContext = scope.ServiceProvider.GetService<SecurityContext>();
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(notifySource, scope);

View File

@ -47,7 +47,7 @@ namespace ASC.Web.CRM.Classes
private void ImportCaseData(DaoFactory _daoFactory)
{
using (var CSVFileStream = _dataStore.GetReadStream("temp", _csvFileURI))
using (CsvReader csv = ImportFromCSV.CreateCsvReaderInstance(CSVFileStream, _importSettings))
using (CsvReader csv = _importFromCSV.CreateCsvReaderInstance(CSVFileStream, _importSettings))
{
int currentIndex = 0;
@ -146,7 +146,7 @@ namespace ASC.Web.CRM.Classes
findedCases.Add(objCases);
if (currentIndex + 1 > ImportFromCSV.MaxRoxCount) break;
if (currentIndex + 1 > _importFromCSV.MaxRoxCount) break;
currentIndex++;
}

View File

@ -65,7 +65,7 @@ namespace ASC.Web.CRM.Classes
#region Read csv
using (var CSVFileStream = _dataStore.GetReadStream("temp", _csvFileURI))
{
CsvReader csv = ImportFromCSV.CreateCsvReaderInstance(CSVFileStream, _importSettings);
CsvReader csv = _importFromCSV.CreateCsvReaderInstance(CSVFileStream, _importSettings);
int currentIndex = 0;
@ -116,7 +116,7 @@ namespace ASC.Web.CRM.Classes
}
#endregion
if (currentIndex + 1 > ImportFromCSV.MaxRoxCount) break;
if (currentIndex + 1 > _importFromCSV.MaxRoxCount) break;
currentIndex++;
}
}
@ -352,7 +352,7 @@ namespace ASC.Web.CRM.Classes
if (String.IsNullOrEmpty(firstName) && String.IsNullOrEmpty(lastName) && String.IsNullOrEmpty(companyName))
return false;
Percentage += 1.0 * 100 / (ImportFromCSV.MaxRoxCount * 3);
Percentage += 1.0 * 100 / (_importFromCSV.MaxRoxCount * 3);
PublishChanges();

View File

@ -61,15 +61,15 @@ namespace ASC.Web.CRM.Classes
private string[] _columns;
private bool _IsConfigure;
public readonly CurrencyProvider _currencyProvider;
public readonly NotifyClient _notifyClient;
public readonly SettingsManager _settingsManager;
public readonly CrmSecurity _crmSecurity;
public readonly TenantManager _tenantManager;
public readonly SecurityContext _securityContext;
public readonly UserManager _userManager;
public readonly DaoFactory _daoFactory;
public readonly ILog _logManager;
private readonly CurrencyProvider _currencyProvider;
private readonly NotifyClient _notifyClient;
private readonly SettingsManager _settingsManager;
private readonly CrmSecurity _crmSecurity;
private readonly TenantManager _tenantManager;
private readonly SecurityContext _securityContext;
private readonly UserManager _userManager;
private readonly DaoFactory _daoFactory;
private readonly ILog _logManager;
public ImportDataOperation(Global global,
TenantManager tenantManager,

View File

@ -51,7 +51,7 @@ namespace ASC.Web.CRM.Classes
var allUsers = _userManager.GetUsers(EmployeeStatus.All).ToList();
using (var CSVFileStream = _dataStore.GetReadStream("temp", _csvFileURI))
using (CsvReader csv = ImportFromCSV.CreateCsvReaderInstance(CSVFileStream, _importSettings))
using (CsvReader csv = _importFromCSV.CreateCsvReaderInstance(CSVFileStream, _importSettings))
{
int currentIndex = 0;
@ -83,7 +83,7 @@ namespace ASC.Web.CRM.Classes
obj.Description = GetPropertyValue("description");
var csvResponsibleValue = GetPropertyValue("responsible");
var responsible = allUsers.Where(n => n.DisplayUserName(DisplayUserSettingsHelper).Equals(csvResponsibleValue)).FirstOrDefault();
var responsible = allUsers.Where(n => n.DisplayUserName(_displayUserSettingsHelper).Equals(csvResponsibleValue)).FirstOrDefault();
if (responsible != null)
obj.ResponsibleID = responsible.ID;
@ -261,12 +261,12 @@ namespace ASC.Web.CRM.Classes
}
}
Percentage += 1.0 * 100 / (ImportFromCSV.MaxRoxCount * 2);
Percentage += 1.0 * 100 / (_importFromCSV.MaxRoxCount * 2);
PublishChanges();
findedDeals.Add(obj);
if (currentIndex + 1 > ImportFromCSV.MaxRoxCount) break;
if (currentIndex + 1 > _importFromCSV.MaxRoxCount) break;
currentIndex++;

View File

@ -44,6 +44,12 @@ namespace ASC.Web.CRM.Classes
[Scope]
public class ImportFromCSV
{
private readonly ImportDataOperation _importDataOperation;
private readonly int _tenantId;
private readonly object _syncObj = new object();
private readonly DistributedTaskQueue _importQueue;
public readonly int MaxRoxCount = 10000;
public ImportFromCSV(TenantManager tenantProvider,
DistributedTaskQueueOptionsManager progressQueueOptionsManager,
ImportDataOperation importDataOperation)
@ -53,11 +59,6 @@ namespace ASC.Web.CRM.Classes
_importDataOperation = importDataOperation;
}
private readonly ImportDataOperation _importDataOperation;
private readonly int _tenantId;
private readonly object _syncObj = new object();
private readonly DistributedTaskQueue _importQueue;
public readonly int MaxRoxCount = 10000;
public int GetQuotas()
{

View File

@ -47,23 +47,23 @@ namespace ASC.Web.CRM.Classes
{
public partial class ImportDataOperation
{
private ImportFromCSV _importFromCSV;
private TenantUtil _tenantUtil;
private DisplayUserSettingsHelper _displayUserSettingsHelper;
public ImportDataOperation(TenantUtil tenantUtil,
ImportFromCSV importFromCSV,
DisplayUserSettingsHelper displayUserSettingsHelper)
{
TenantUtil = tenantUtil;
ImportFromCSV = importFromCSV;
DisplayUserSettingsHelper = displayUserSettingsHelper;
_tenantUtil = tenantUtil;
_importFromCSV = importFromCSV;
_displayUserSettingsHelper = displayUserSettingsHelper;
}
public ImportFromCSV ImportFromCSV { get; }
public TenantUtil TenantUtil { get; }
public DisplayUserSettingsHelper DisplayUserSettingsHelper { get; }
private void ImportTaskData(DaoFactory _daoFactory)
{
using (var CSVFileStream = _dataStore.GetReadStream("temp", _csvFileURI))
using (CsvReader csv = ImportFromCSV.CreateCsvReaderInstance(CSVFileStream, _importSettings))
using (CsvReader csv = _importFromCSV.CreateCsvReaderInstance(CSVFileStream, _importSettings))
{
int currentIndex = 0;
@ -95,10 +95,10 @@ namespace ASC.Web.CRM.Classes
if (DateTime.TryParse(GetPropertyValue("due_date"), out deadline))
obj.DeadLine = deadline;
else
obj.DeadLine = TenantUtil.DateTimeNow();
obj.DeadLine = _tenantUtil.DateTimeNow();
var csvResponsibleValue = GetPropertyValue("responsible");
var responsible = allUsers.Where(n => n.DisplayUserName(DisplayUserSettingsHelper).Equals(csvResponsibleValue)).FirstOrDefault();
var responsible = allUsers.Where(n => n.DisplayUserName(_displayUserSettingsHelper).Equals(csvResponsibleValue)).FirstOrDefault();
if (responsible != null)
obj.ResponsibleID = responsible.ID;
@ -163,7 +163,7 @@ namespace ASC.Web.CRM.Classes
findedTasks.Add(obj);
if ((currentIndex + 1) > ImportFromCSV.MaxRoxCount) break;
if ((currentIndex + 1) > _importFromCSV.MaxRoxCount) break;
currentIndex++;

View File

@ -94,7 +94,6 @@ namespace ASC.Web.CRM.Classes
private SecurityContext _securityContext;
private TenantUtil _tenantUtil;
public object Error { get; set; }
private SendBatchEmailsOperation()

View File

@ -49,6 +49,15 @@ namespace ASC.Web.CRM.Classes
[Scope]
public class PdfCreator
{
private InvoiceFormattedData _invoiceFormattedData;
private DaoFactory _daoFactory;
private IServiceProvider _serviceProvider;
private DocumentServiceConnector _documentServiceConnector;
private OrganisationLogoManager _organisationLogoManager;
private Files.Classes.PathProvider _filesPathProvider;
private ILog _logger;
public PdfCreator(IOptionsMonitor<ILog> logger,
Files.Classes.PathProvider filesPathProvider,
DocumentServiceConnector documentServiceConnector,
@ -57,20 +66,17 @@ namespace ASC.Web.CRM.Classes
DaoFactory daoFactory,
InvoiceFormattedData invoiceFormattedData)
{
FilesPathProvider = filesPathProvider;
_filesPathProvider = filesPathProvider;
Logger = logger.Get("ASC.CRM");
_logger = logger.Get("ASC.CRM");
DocumentServiceConnector = documentServiceConnector;
ServiceProvider = serviceProvider;
OrganisationLogoManager = organisationLogoManager;
DaoFactory = daoFactory;
InvoiceFormattedData = invoiceFormattedData;
_documentServiceConnector = documentServiceConnector;
_serviceProvider = serviceProvider;
_organisationLogoManager = organisationLogoManager;
_daoFactory = daoFactory;
_invoiceFormattedData = invoiceFormattedData;
}
public InvoiceFormattedData InvoiceFormattedData { get; }
public DaoFactory DaoFactory { get; }
private Stream Template
{
@ -81,12 +87,6 @@ namespace ASC.Web.CRM.Classes
}
}
public IServiceProvider ServiceProvider { get; }
public DocumentServiceConnector DocumentServiceConnector { get; }
public OrganisationLogoManager OrganisationLogoManager { get; }
public Files.Classes.PathProvider FilesPathProvider { get; }
public ILog Logger { get; }
private const string FormatPdf = ".pdf";
private const string FormatDocx = ".docx";
@ -95,20 +95,20 @@ namespace ASC.Web.CRM.Classes
public void CreateAndSaveFile(int invoiceId)
{
Logger.DebugFormat("PdfCreator. CreateAndSaveFile. Invoice ID = {0}", invoiceId);
_logger.DebugFormat("PdfCreator. CreateAndSaveFile. Invoice ID = {0}", invoiceId);
try
{
var invoice = DaoFactory.GetInvoiceDao().GetByID(invoiceId);
var invoice = _daoFactory.GetInvoiceDao().GetByID(invoiceId);
if (invoice == null)
{
Logger.Warn(CRMErrorsResource.InvoiceNotFound + ". Invoice ID = " + invoiceId);
_logger.Warn(CRMErrorsResource.InvoiceNotFound + ". Invoice ID = " + invoiceId);
return;
}
Logger.DebugFormat("PdfCreator. CreateAndSaveFile. Invoice ID = {0}. Convertation", invoiceId);
_logger.DebugFormat("PdfCreator. CreateAndSaveFile. Invoice ID = {0}. Convertation", invoiceId);
string urlToFile;
@ -117,13 +117,13 @@ namespace ASC.Web.CRM.Classes
urlToFile = GetUrlToFile(docxStream);
}
Logger.DebugFormat("PdfCreator. CreateAndSaveFile. Invoice ID = {0}. UrlToFile = {1}", invoiceId,
_logger.DebugFormat("PdfCreator. CreateAndSaveFile. Invoice ID = {0}. UrlToFile = {1}", invoiceId,
urlToFile);
var file = ServiceProvider.GetService<File<int>>();
var file = _serviceProvider.GetService<File<int>>();
file.Title = string.Format("{0}{1}", invoice.Number, FormatPdf);
file.FolderID = DaoFactory.GetFileDao().GetRoot();
file.FolderID = _daoFactory.GetFileDao().GetRoot();
var request = WebRequest.Create(urlToFile);
@ -132,8 +132,8 @@ namespace ASC.Web.CRM.Classes
{
file.ContentLength = response.ContentLength;
Logger.DebugFormat("PdfCreator. CreateAndSaveFile. Invoice ID = {0}. SaveFile", invoiceId);
file = DaoFactory.GetFileDao().SaveFile(file, stream);
_logger.DebugFormat("PdfCreator. CreateAndSaveFile. Invoice ID = {0}. SaveFile", invoiceId);
file = _daoFactory.GetFileDao().SaveFile(file, stream);
}
if (file == null)
@ -143,17 +143,17 @@ namespace ASC.Web.CRM.Classes
invoice.FileID = Int32.Parse(file.ID.ToString());
Logger.DebugFormat("PdfCreator. CreateAndSaveFile. Invoice ID = {0}. UpdateInvoiceFileID. FileID = {1}", invoiceId, file.ID);
_logger.DebugFormat("PdfCreator. CreateAndSaveFile. Invoice ID = {0}. UpdateInvoiceFileID. FileID = {1}", invoiceId, file.ID);
DaoFactory.GetInvoiceDao().UpdateInvoiceFileID(invoice.ID, invoice.FileID);
_daoFactory.GetInvoiceDao().UpdateInvoiceFileID(invoice.ID, invoice.FileID);
Logger.DebugFormat("PdfCreator. CreateAndSaveFile. Invoice ID = {0}. AttachFiles. FileID = {1}", invoiceId, file.ID);
_logger.DebugFormat("PdfCreator. CreateAndSaveFile. Invoice ID = {0}. AttachFiles. FileID = {1}", invoiceId, file.ID);
DaoFactory.GetRelationshipEventDao().AttachFiles(invoice.ContactID, invoice.EntityType, invoice.EntityID, new[] { invoice.FileID });
_daoFactory.GetRelationshipEventDao().AttachFiles(invoice.ContactID, invoice.EntityType, invoice.EntityID, new[] { invoice.FileID });
}
catch (Exception e)
{
Logger.Error(e);
_logger.Error(e);
}
}
@ -170,7 +170,7 @@ namespace ASC.Web.CRM.Classes
}
catch (Exception e)
{
Logger.Error(e);
_logger.Error(e);
throw;
}
@ -178,19 +178,19 @@ namespace ASC.Web.CRM.Classes
private string GetUrlToFile(Stream docxStream)
{
var externalUri = FilesPathProvider.GetTempUrl(docxStream, FormatDocx);
var externalUri = _filesPathProvider.GetTempUrl(docxStream, FormatDocx);
externalUri = DocumentServiceConnector.ReplaceCommunityAdress(externalUri);
externalUri = _documentServiceConnector.ReplaceCommunityAdress(externalUri);
Logger.DebugFormat("PdfCreator. GetUrlToFile. externalUri = {0}", externalUri);
_logger.DebugFormat("PdfCreator. GetUrlToFile. externalUri = {0}", externalUri);
var revisionId = DocumentServiceConnector.GenerateRevisionId(Guid.NewGuid().ToString());
string urlToFile;
DocumentServiceConnector.GetConvertedUri(externalUri, FormatDocx, FormatPdf, revisionId, null, false, out urlToFile);
_documentServiceConnector.GetConvertedUri(externalUri, FormatDocx, FormatPdf, revisionId, null, false, out urlToFile);
Logger.DebugFormat("PdfCreator. GetUrlToFile. urlToFile = {0}", urlToFile);
_logger.DebugFormat("PdfCreator. GetUrlToFile. urlToFile = {0}", urlToFile);
return urlToFile;
@ -200,15 +200,15 @@ namespace ASC.Web.CRM.Classes
{
using (var docxStream = GetStreamDocx(data))
{
var externalUri = FilesPathProvider.GetTempUrl(docxStream, FormatDocx);
var externalUri = _filesPathProvider.GetTempUrl(docxStream, FormatDocx);
externalUri = DocumentServiceConnector.ReplaceCommunityAdress(externalUri);
externalUri = _documentServiceConnector.ReplaceCommunityAdress(externalUri);
var revisionId = DocumentServiceConnector.GenerateRevisionId(Guid.NewGuid().ToString());
string urlToFile;
DocumentServiceConnector.GetConvertedUri(externalUri, FormatDocx, FormatPdf, revisionId, null, true, out urlToFile);
_documentServiceConnector.GetConvertedUri(externalUri, FormatDocx, FormatPdf, revisionId, null, true, out urlToFile);
return new ConverterData
{
@ -228,14 +228,14 @@ namespace ASC.Web.CRM.Classes
string urlToFile;
DocumentServiceConnector.GetConvertedUri(data.StorageUrl, FormatDocx, FormatPdf, data.RevisionId, null, true, out urlToFile);
_documentServiceConnector.GetConvertedUri(data.StorageUrl, FormatDocx, FormatPdf, data.RevisionId, null, true, out urlToFile);
if (string.IsNullOrEmpty(urlToFile))
{
return null;
}
var invoice = DaoFactory.GetInvoiceDao().GetByID(data.InvoiceId);
var invoice = _daoFactory.GetInvoiceDao().GetByID(data.InvoiceId);
return SaveFile(invoice, urlToFile, daoFactory);
}
@ -252,10 +252,10 @@ namespace ASC.Web.CRM.Classes
{
if (stream != null)
{
var document = ServiceProvider.GetService<File<int>>();
var document = _serviceProvider.GetService<File<int>>();
document.Title = string.Format("{0}{1}", data.Number, FormatPdf);
document.FolderID = DaoFactory.GetFileDao().GetRoot();
document.FolderID = _daoFactory.GetFileDao().GetRoot();
document.ContentLength = response.ContentLength;
if (data.GetInvoiceFile(daoFactory) != null)
@ -263,7 +263,7 @@ namespace ASC.Web.CRM.Classes
document.ID = data.FileID;
}
file = DaoFactory.GetFileDao().SaveFile(document, stream);
file = _daoFactory.GetFileDao().SaveFile(document, stream);
}
}
}
@ -273,7 +273,7 @@ namespace ASC.Web.CRM.Classes
private Stream GetStreamDocx(Invoice data)
{
var invoiceData = InvoiceFormattedData.GetData(data, 0, 0);
var invoiceData = _invoiceFormattedData.GetData(data, 0, 0);
var logo = new byte[] { };
if (!string.IsNullOrEmpty(invoiceData.LogoBase64))
@ -282,7 +282,7 @@ namespace ASC.Web.CRM.Classes
}
else if (invoiceData.LogoBase64Id != 0)
{
logo = Convert.FromBase64String(OrganisationLogoManager.GetOrganisationLogoBase64(invoiceData.LogoBase64Id));
logo = Convert.FromBase64String(_organisationLogoManager.GetOrganisationLogoBase64(invoiceData.LogoBase64Id));
}
var result = new MemoryStream();

View File

@ -48,23 +48,23 @@ namespace ASC.Web.CRM.Classes
[Transient]
public class PdfQueueWorker
{
private readonly DistributedTaskQueue Queue;
private readonly int tenantId;
private readonly Guid userId;
private readonly DistributedTaskQueue _queue;
private readonly int _tenantId;
private readonly Guid _userId;
private readonly object Locker = new object();
private PdfProgressItem _pdfProgressItem;
public PdfQueueWorker(DistributedTaskQueueOptionsManager queueOptions,
PdfProgressItem pdfProgressItem,
TenantManager tenantProvider,
SecurityContext securityContext)
{
Queue = queueOptions.Get<PdfProgressItem>();
PdfProgressItem = pdfProgressItem;
tenantId = tenantProvider.GetCurrentTenant().TenantId;
userId = securityContext.CurrentAccount.ID;
_queue = queueOptions.Get<PdfProgressItem>();
_pdfProgressItem = pdfProgressItem;
_tenantId = tenantProvider.GetCurrentTenant().TenantId;
_userId = securityContext.CurrentAccount.ID;
}
public PdfProgressItem PdfProgressItem { get; }
public string GetTaskId(int tenantId, int invoiceId)
{
@ -75,35 +75,35 @@ namespace ASC.Web.CRM.Classes
{
var id = GetTaskId(tenantId, invoiceId);
var findedItem = Queue.GetTasks<PdfProgressItem>().FirstOrDefault(x => x.Id == id);
var findedItem = _queue.GetTasks<PdfProgressItem>().FirstOrDefault(x => x.Id == id);
return findedItem;
}
public void TerminateTask(int invoiceId)
{
var item = GetTaskStatus(tenantId, invoiceId);
var item = GetTaskStatus(_tenantId, invoiceId);
if (item != null)
Queue.RemoveTask(item.Id);
_queue.RemoveTask(item.Id);
}
public PdfProgressItem StartTask(int invoiceId)
{
lock (Locker)
{
var task = GetTaskStatus(tenantId, invoiceId);
var task = GetTaskStatus(_tenantId, invoiceId);
if (task != null && task.IsCompleted)
{
Queue.RemoveTask(task.Id);
_queue.RemoveTask(task.Id);
task = null;
}
if (task == null)
{
PdfProgressItem.Configure(GetTaskId(tenantId, invoiceId), tenantId, userId, invoiceId);
Queue.QueueTask(PdfProgressItem);
_pdfProgressItem.Configure(GetTaskId(_tenantId, invoiceId), _tenantId, _userId, invoiceId);
_queue.QueueTask(_pdfProgressItem);
}

View File

@ -47,6 +47,17 @@ namespace ASC.Web.CRM.Classes
[Scope]
public class ReportHelper
{
private CurrencyProvider _currencyProvider;
private IHttpContextAccessor _httpContext;
private SecurityContext _securityContext;
private DocbuilderReportsUtilityHelper _docbuilderReportsUtilityHelper;
private DaoFactory _daoFactory;
private IServiceProvider _serviceProvider;
private Global _global;
private SettingsManager _settingsManager;
private TenantUtil _tenantUtil;
private TenantManager _tenantManager;
public ReportHelper(TenantManager tenantManager,
TenantUtil tenantUtil,
Global global,
@ -59,29 +70,18 @@ namespace ASC.Web.CRM.Classes
CurrencyProvider currencyProvider
)
{
TenantManager = tenantManager;
TenantUtil = tenantUtil;
Global = global;
SettingsManager = settingsManager;
ServiceProvider = serviceProvider;
DaoFactory = daoFactory;
DocbuilderReportsUtilityHelper = docbuilderReportsUtilityHelper;
SecurityContext = securityContext;
HttpContext = httpContextAccessor;
CurrencyProvider = currencyProvider;
_tenantManager = tenantManager;
_tenantUtil = tenantUtil;
_global = global;
_settingsManager = settingsManager;
_serviceProvider = serviceProvider;
_daoFactory = daoFactory;
_docbuilderReportsUtilityHelper = docbuilderReportsUtilityHelper;
_securityContext = securityContext;
_httpContext = httpContextAccessor;
_currencyProvider = currencyProvider;
}
private CurrencyProvider CurrencyProvider { get; }
public IHttpContextAccessor HttpContext { get; }
public SecurityContext SecurityContext { get; }
public DocbuilderReportsUtilityHelper DocbuilderReportsUtilityHelper { get; }
public DaoFactory DaoFactory { get; }
public IServiceProvider ServiceProvider { get; }
public Global Global { get; }
public SettingsManager SettingsManager { get; }
public TenantUtil TenantUtil { get; }
public TenantManager TenantManager { get; }
private string GetFileName(ReportType reportType)
{
string reportName;
@ -125,13 +125,13 @@ namespace ASC.Web.CRM.Classes
return string.Format("{0} ({1} {2}).xlsx",
reportName,
TenantUtil.DateTimeNow().ToShortDateString(),
TenantUtil.DateTimeNow().ToShortTimeString());
_tenantUtil.DateTimeNow().ToShortDateString(),
_tenantUtil.DateTimeNow().ToShortTimeString());
}
public bool CheckReportData(ReportType reportType, ReportTimePeriod timePeriod, Guid[] managers)
{
var reportDao = DaoFactory.GetReportDao();
var reportDao = _daoFactory.GetReportDao();
throw new NotImplementedException();
@ -164,23 +164,23 @@ namespace ASC.Web.CRM.Classes
public List<string> GetMissingRates(ReportType reportType)
{
var reportDao = DaoFactory.GetReportDao();
var reportDao = _daoFactory.GetReportDao();
if (reportType == ReportType.WorkloadByTasks || reportType == ReportType.WorkloadByInvoices ||
reportType == ReportType.WorkloadByContacts || reportType == ReportType.WorkloadByVoip) return null;
var crmSettings = SettingsManager.Load<CrmSettings>();
var defaultCurrency = CurrencyProvider.Get(crmSettings.DefaultCurrency);
var crmSettings = _settingsManager.Load<CrmSettings>();
var defaultCurrency = _currencyProvider.Get(crmSettings.DefaultCurrency);
return reportDao.GetMissingRates(defaultCurrency.Abbreviation);
}
private object GetReportData(ReportType reportType, ReportTimePeriod timePeriod, Guid[] managers)
{
var crmSettings = SettingsManager.Load<CrmSettings>();
var crmSettings = _settingsManager.Load<CrmSettings>();
var reportDao = DaoFactory.GetReportDao();
var defaultCurrency = CurrencyProvider.Get(crmSettings.DefaultCurrency).Abbreviation;
var reportDao = _daoFactory.GetReportDao();
var defaultCurrency = _currencyProvider.Get(crmSettings.DefaultCurrency).Abbreviation;
switch (reportType)
{
@ -227,15 +227,15 @@ namespace ASC.Web.CRM.Classes
using (var stream = new System.IO.MemoryStream(data))
{
var document = ServiceProvider.GetService<File<int>>();
var document = _serviceProvider.GetService<File<int>>();
document.Title = state.FileName;
document.FolderID = DaoFactory.GetFileDao().GetRoot();
document.FolderID = _daoFactory.GetFileDao().GetRoot();
document.ContentLength = stream.Length;
var file = DaoFactory.GetFileDao().SaveFile(document, stream);
var file = _daoFactory.GetFileDao().SaveFile(document, stream);
DaoFactory.GetReportDao().SaveFile((int)file.ID, state.ReportType);
_daoFactory.GetReportDao().SaveFile((int)file.ID, state.ReportType);
state.FileId = (int)file.ID;
}
@ -264,12 +264,12 @@ namespace ASC.Web.CRM.Classes
ReportOrigin.CRM,
SaveReportFile,
null,
TenantManager.GetCurrentTenant().TenantId,
SecurityContext.CurrentAccount.ID);
_tenantManager.GetCurrentTenant().TenantId,
_securityContext.CurrentAccount.ID);
var state = new ReportState(ServiceProvider, reportStateData, HttpContext);
var state = new ReportState(_serviceProvider, reportStateData, _httpContext);
DocbuilderReportsUtilityHelper.Enqueue(state);
_docbuilderReportsUtilityHelper.Enqueue(state);
return state;
}