diff --git a/products/ASC.Files/Server/Helpers/EasyBibHelper.cs b/products/ASC.Files/Server/Helpers/EasyBibHelper.cs index f4cd3fff05..15fb9585fb 100644 --- a/products/ASC.Files/Server/Helpers/EasyBibHelper.cs +++ b/products/ASC.Files/Server/Helpers/EasyBibHelper.cs @@ -26,23 +26,29 @@ using System; using System.Collections.Generic; + +using ASC.Common.Caching; using ASC.Common.Logging; +using ASC.Core; using ASC.Core.Common.Configuration; using ASC.FederatedLogin.Helpers; -using ASC.Web.Files.Classes; + +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; + using Newtonsoft.Json.Linq; namespace ASC.Web.Files.Helpers { public class EasyBibHelper : Consumer { - public static ILog Log = Global.Logger; + public ILog Log { get; set; } - static string searchBookUrl = "https://worldcat.citation-api.com/query?search=", + static string searchBookUrl = "https://worldcat.citation-api.com/query?search=", searchJournalUrl = "https://crossref.citation-api.com/query?search=", searchWebSiteUrl = "https://web.citation-api.com/query?search=", - easyBibStyles = "http://easybib-csl.herokuapp.com/1.0/styles"; - + easyBibStyles = "http://easybib-csl.herokuapp.com/1.0/styles"; + public enum EasyBibSource { book = 0, @@ -53,19 +59,31 @@ namespace ASC.Web.Files.Helpers public string AppKey { get { return this["easyBibappkey"]; } - } - + } + public EasyBibHelper() - { - + { + } - public EasyBibHelper(string name, int order, Dictionary props, Dictionary additional = null) - : base(name, order, props, additional) - { + public EasyBibHelper( + IOptionsMonitor option, + TenantManager tenantManager, + CoreBaseSettings coreBaseSettings, + CoreSettings coreSettings, + ConsumerFactory consumerFactory, + IConfiguration configuration, + ICacheNotify cache, + string name, + int order, + Dictionary props, + Dictionary additional = null) + : base(tenantManager, coreBaseSettings, coreSettings, consumerFactory, configuration, cache, name, order, props, additional) + { + Log = option.CurrentValue; } - public static string GetEasyBibCitationsList(int source, string data) + public static string GetEasyBibCitationsList(int source, string data) { var uri = ""; switch (source) @@ -85,7 +103,7 @@ namespace ASC.Web.Files.Helpers uri += data; const string method = "GET"; - var headers = new Dictionary(){}; + var headers = new Dictionary() { }; try { return RequestHelper.PerformRequest(uri, "", method, "", headers); @@ -98,10 +116,10 @@ namespace ASC.Web.Files.Helpers } public static string GetEasyBibStyles() - { - + { + const string method = "GET"; - var headers = new Dictionary(){}; + var headers = new Dictionary() { }; try { return RequestHelper.PerformRequest(easyBibStyles, "", method, "", headers); @@ -111,7 +129,7 @@ namespace ASC.Web.Files.Helpers return "error"; } } - public static object GetEasyBibCitation(string data) + public object GetEasyBibCitation(string data) { try { @@ -127,15 +145,15 @@ namespace ASC.Web.Files.Helpers var body = citationData; var headers = new Dictionary() { }; - return RequestHelper.PerformRequest(uri, contentType, method, body, headers); - + return RequestHelper.PerformRequest(uri, contentType, method, body, headers); + } catch (Exception) { return null; throw; - } - + } + } } } \ No newline at end of file diff --git a/products/ASC.Files/Server/Helpers/WordpressHelper.cs b/products/ASC.Files/Server/Helpers/WordpressHelper.cs index b179943d7d..55c3a2c68c 100644 --- a/products/ASC.Files/Server/Helpers/WordpressHelper.cs +++ b/products/ASC.Files/Server/Helpers/WordpressHelper.cs @@ -25,33 +25,45 @@ using System; + using ASC.Common.Logging; using ASC.FederatedLogin; using ASC.FederatedLogin.LoginProviders; using ASC.Web.Files.Classes; using ASC.Web.Files.ThirdPartyApp; - + +using Microsoft.Extensions.Options; + namespace ASC.Web.Files.Helpers { public class WordpressToken { - public static ILog Log = Global.Logger; + public ILog Log { get; set; } + public TokenHelper TokenHelper { get; } + public const string AppAttr = "wordpress"; + + public WordpressToken(IOptionsMonitor optionsMonitor, TokenHelper tokenHelper) + { + Log = optionsMonitor.CurrentValue; + TokenHelper = tokenHelper; + } - public static OAuth20Token GetToken() + public OAuth20Token GetToken() { - return Token.GetToken(AppAttr); + return TokenHelper.GetToken(AppAttr); } - public static void SaveToken(OAuth20Token token) + public void SaveToken(OAuth20Token token) { if (token == null) throw new ArgumentNullException("token"); - Token.SaveToken(new Token(token, AppAttr)); - } - public static void DeleteToken(OAuth20Token token) + TokenHelper.SaveToken(new Token(token, AppAttr)); + } + + public void DeleteToken(OAuth20Token token) { if (token == null) throw new ArgumentNullException("token"); - Token.DeleteToken(AppAttr); + TokenHelper.DeleteToken(AppAttr); } } @@ -74,8 +86,8 @@ namespace ASC.Web.Files.Helpers { Log.Error("Get Wordpress info about me ", ex); return ""; - } - + } + } public static bool CreateWordpressPost(string title, string content, int status, string blogId, OAuth20Token token) diff --git a/products/ASC.Files/Server/HttpHandlers/SearchHandler.cs b/products/ASC.Files/Server/HttpHandlers/SearchHandler.cs index f028869e2b..73d85213c5 100644 --- a/products/ASC.Files/Server/HttpHandlers/SearchHandler.cs +++ b/products/ASC.Files/Server/HttpHandlers/SearchHandler.cs @@ -72,6 +72,7 @@ namespace ASC.Web.Files.Configuration public FilesLinkUtility FilesLinkUtility { get; } public FileUtility FileUtility { get; } public PathProvider PathProvider { get; } + public ThirdpartyConfiguration ThirdpartyConfiguration { get; } public SearchHandler( FileSecurity fileSecurity, @@ -82,7 +83,8 @@ namespace ASC.Web.Files.Configuration FilesSettingsHelper filesSettingsHelper, FilesLinkUtility filesLinkUtility, FileUtility fileUtility, - PathProvider pathProvider) + PathProvider pathProvider, + ThirdpartyConfiguration thirdpartyConfiguration) { FileSecurity = fileSecurity; DaoFactory = daoFactory; @@ -93,6 +95,7 @@ namespace ASC.Web.Files.Configuration FilesLinkUtility = filesLinkUtility; FileUtility = fileUtility; PathProvider = pathProvider; + ThirdpartyConfiguration = thirdpartyConfiguration; } public IEnumerable SearchFiles(string text)