public static string LogError(Exception e) { var monitor = InitializerSection.GetSection().LogMonitor; monitor.Init(); return(monitor.LogException(e)); }
public static string GetTableFieldHeader(string projectCode, string tableName, string fieldName, string version, string publicKeyToken) { var cacheKey = $"{tableName}.{fieldName}:{LocalizationHelper.IsCultureKZ}"; if (ProjectFieldHeadersCache.ContainsKey(cacheKey)) { return(ProjectFieldHeadersCache[cacheKey]); } string header = null; var type = BuildManager.GetType( string.Format( "{1}.Properties.{0}Resources, {1}, Version={2}, Culture=neutral, PublicKeyToken={3}", tableName, projectCode, version ?? InitializerSection.GetSection().DefaultVersion, publicKeyToken ?? InitializerSection.GetSection().DefaultPublicKeyToken), false, true); var property = type?.GetProperty(fieldName + "__Header", BindingFlags.Static | BindingFlags.Public); if (property != null) { header = (string)property.GetValue(null, new object[0]); } if (string.IsNullOrEmpty(header)) { header = tableName + "." + fieldName; } return(ProjectFieldHeadersCache[cacheKey] = header); }
public static string[] GetGroups() { var config = InitializerSection.GetSection(); var groups = new string[] { }; if (!string.IsNullOrEmpty(config.GroupProviderType)) { var type = BuildManager.GetType(config.GroupProviderType, true, true); var simpleGroupProvider = (IGroupProvider)Activator.CreateInstance(type); var userName = GetSID(); var formGroups = simpleGroupProvider.GetGroupsForUser(userName); return(formGroups.ToArray()); } var windowsIdentity = HttpContext.Current.User.Identity as WindowsIdentity; if (windowsIdentity != null) { var windowsGroups = windowsIdentity.Groups; if (windowsGroups == null) { return(new string[0]); } groups = windowsGroups.Select(r => r.Value).ToArray(); } return(groups); }
public static ProgressManager RunAsync(string key, params ProgressManagerAction[] actions) { ProgressManager progressManager; lock (ListLock) { if (List.ContainsKey(key) && List[key].InProgress) { throw new ProgressManagerExistsException("ProgressManager with key '" + key + "' exists"); } if (!List.ContainsKey(key)) { var manager = new ProgressManager(); manager.LogMonitor = InitializerSection.GetSection().LogMonitor; manager.LogMonitor.Sid = User.GetSID(); manager.LogMonitor.Init(); List[key] = manager; } progressManager = List[key]; } progressManager.RunAsync(actions); return(progressManager); }
public static bool DoesHaveUserPermissionToReport(string pluginName) { var config = InitializerSection.GetSection(); var type = BuildManager.GetType(config.ReportAccess, true, true); var access = (IReportAccess)Activator.CreateInstance(type); return(access.DoesHaveUserPermission(pluginName)); }
public static void UserDoesNotHavePermitions(string errorMassage) { var config = InitializerSection.GetSection(); if (AccessDeniedException.IsInService()) { throw new AccessDeniedException(errorMassage); } HttpContext.Current.Response.Redirect(config.DoesNotHavePermitionsPage + "?ErrorMessage=" + HttpUtility.UrlEncode(errorMassage)); }
public static void Initialize() { lock (_lock) { if (initializerSection == null) { initializerSection = InitializerSection.GetSection().InitializerClasses; initializerSection.Initialize(); } } }
private static TResult GetPersonInfoInternal <TResult>(string sid) { if (string.IsNullOrEmpty(sid)) { return(default(TResult)); } try { if (InitializerSection.GetSection().IsConvertToSSDL) { if (!sid.StartsWith("S-") && !"anonymous".Equals(sid)) { var base64 = Convert.FromBase64String(sid); var sidValue = new SecurityIdentifier(base64, 0); sid = sidValue.Value; } } } catch (FormatException) { } var key = PersonInfoBySid + typeof(TResult).FullName + ">:" + sid; TResult value; if (HttpContext.Current != null && HttpContext.Current.Cache[key] != null) { value = (TResult)HttpContext.Current.Cache[key]; } else { WebInitializer.Initialize(); using (var db = new DBDataContext(SpecificInstances.DbFactory.CreateConnection())) { value = db.GetPersonInfoBySid <TResult>(sid).FirstOrDefault(); if (value != null && HttpContext.Current != null) { HttpContext.Current.Cache.Add( key, value, null, DateTime.Now.AddMinutes(2), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); } } } return(value); }
public static string CheckPersonInfo() { var config = InitializerSection.GetSection(); if (string.IsNullOrEmpty(config.TypeOfMethodCheckPersonInfo)) { return(null); } var type = BuildManager.GetType(config.TypeOfMethodCheckPersonInfo, true, true); var mehtod = type.GetMethod("CheckPersonInfo"); return((string)mehtod.Invoke(null, new object[0])); }
public static void EnsurePersonInfoCorrect() { var config = InitializerSection.GetSection(); if (string.IsNullOrEmpty(config.TypeOfMethodEnsurePersonInfoCorrect)) { return; } var type = BuildManager.GetType(config.TypeOfMethodEnsurePersonInfoCorrect, true, true); var mehtod = type.GetMethod("EnsurePersonInfoCorrect"); mehtod.Invoke(null, new object[0]); }
public static IReportPlugin GetPlugin(string reportPluginName) { var section = ReportInitializerSection.GetReportInitializerSection(); var errors = new StringBuilder(); var tPlugin = typeof(IWebReportPlugin); IWebReportPlugin reportPlugin = null; try { var types = section.ReprotPlugins.GetReportPlugins(); foreach (var type in types.Where(tPlugin.IsAssignableFrom)) { try { if (type.FullName.Equals(reportPluginName)) { reportPlugin = (IWebReportPlugin)Activator.CreateInstance(type); break; } } catch (Exception e) { errors.AppendLine("Can't create '" + type.FullName + "':"); errors.AppendLine(e.ToString()); errors.AppendLine(); errors.AppendLine(); } } } catch (Exception e) { errors.AppendLine(e.ToString()); errors.AppendLine(); errors.AppendLine(); } if (errors.Length > 0) { var errorsStr = errors.ToString(); var sid = HttpContext.Current.User == null ? "Nat.Initializer" : User.GetSID(); var logMonitor = InitializerSection.GetSection().LogMonitor; logMonitor.Init(); logMonitor.Log( LogConstants.SystemErrorInApp, () => new LogMessageEntry(sid, LogMessageType.SystemErrorInApp, errorsStr)); TraceContextExt.WarnExt(HttpContext.Current.Trace, errorsStr); } return(reportPlugin); }
public static string GetSubdivisionKSP() { var config = InitializerSection.GetSection(); var typeName = config.TypeOfMethodGetSubdivisionKSP; if (string.IsNullOrEmpty(typeName)) { return(string.Empty); } var type = BuildManager.GetType(typeName, true, true); var mehtod = type.GetMethod("GetSubdivisionKSP", new Type[0]); return((string)mehtod.Invoke(null, new object[0])); }
public static string GetTableHeader(string projectCode, string tableName, string version, string publicKeyToken) { var cacheKey = tableName + ":" + LocalizationHelper.IsCultureKZ; if (ProjectHeadersCache.ContainsKey(cacheKey)) { return(ProjectHeadersCache[cacheKey]); } string header = null; var type = BuildManager.GetType( string.Format( "{1}.Properties.{0}Resources, {1}, Version={2}, Culture=neutral, PublicKeyToken={3}", tableName, projectCode, version ?? InitializerSection.GetSection().DefaultVersion, publicKeyToken ?? InitializerSection.GetSection().DefaultPublicKeyToken), false, true); var property = type?.GetProperty("Header", BindingFlags.Static | BindingFlags.Public); if (property != null) { header = (string)property.GetValue(null, new object[0]); } if (string.IsNullOrEmpty(header)) { using (var db = new DBDataContext(SpecificInstances.DbFactory.CreateConnection())) { header = CacheQueries.GetNameCached <MON_RequestTable, string, string>( db, tableName, (r, value) => r.TableCode == value, r => r.TableName); } } if (string.IsNullOrEmpty(header)) { header = tableName; } return(ProjectHeadersCache[cacheKey] = header); }
private static ILogMonitor GetLogMonitor() { ILogMonitor logMonitor; try { var section = InitializerSection.GetSection(); logMonitor = section.LogMonitor; logMonitor.Init(); } catch (Exception) { var type = Type.GetType("Nat.Web.Controls.LogMonitor, Nat.Web.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=11c252a207597415"); logMonitor = (ILogMonitor)Activator.CreateInstance(type); } return(logMonitor); }
private static void Export(HttpContext context, string queryParameters, IDataSourceView4 dataSourceView, IExportJournal journal, ICollection <string> selectedValues) { if (!dataSourceView.CheckPermit() || !dataSourceView.CheckPermitExport()) { context.Response.StatusCode = 404; context.Response.End(); return; } var data = selectedValues != null && selectedValues.Count > 0 ? dataSourceView.GetSelectIRowByID(queryParameters, selectedValues.ToArray()) : dataSourceView.GetSelectIRow(queryParameters); var log = InitializerSection.GetSection().LogMonitor; log.Init(); var exportData = data.ToList(); journal.Url = new MainPageUrlBuilder("/MainPage.aspx/data/" + journal.TableName + "Journal" + queryParameters); journal.PrepareExportData(exportData); var args = new JournalExportEventArgs { CheckPermit = true, Columns = GridHtmlGenerator.GetColumnsForExport(journal.GetColumns()), FilterValues = journal.GetFilterValues(), Format = "Excel", Header = journal.TableHeader, LogMonitor = log, Control = new AccessControl(dataSourceView.CheckPermitExport), Data = exportData, }; var url = new MainPageUrlBuilder { UserControl = journal.TableName + "Journal", IsDataControl = true, ShowHistory = true, }; args.ViewJournalUrl = new StringBuilder(); url.CreateUrl(args.ViewJournalUrl); args.ViewJournalUrl.Append("?id.EqualsCollection="); var stream = WebSpecificInstances.GetExcelExporter().GetExcelStream(args); PageHelper.DownloadFile(stream, journal.TableHeader + "." + args.FileNameExtention, context.Response); }
private string GetRowName(DependentTable args) { var type = BuildManager.GetType( string.Format( "{1}.{0}JournalDataSourceView, {1}, Version={2}, Culture=neutral, PublicKeyToken={3}", args.TableCode, args.ProjectCode, args.Version ?? InitializerSection.GetSection().DefaultVersion, args.PublicKeyToken ?? InitializerSection.GetSection().DefaultPublicKeyToken), false, true); if (type != null) { var source = (IDataSourceViewGetName)Activator.CreateInstance(type); return(source.GetName(args.ID)); } return(null); }
private void SetParametersByCustomCode(TableParametersArgs args, string projectCode, string version, string publicKeyToken) { var type = BuildManager.GetType( string.Format( "{0}.ReferencesConflictResolver, {0}, Version={1}, Culture=neutral, PublicKeyToken={2}", projectCode, version ?? InitializerSection.GetSection().DefaultVersion, publicKeyToken ?? InitializerSection.GetSection().DefaultPublicKeyToken), false, true); if (type == null) { return; } var source = Activator.CreateInstance(type) as IReferencesConflictResolver; source?.OnReferenceConflictResolving(args); }
public static bool IsInRole(string role) { if (methodIsInRole != null) { return((bool)methodIsInRole.Invoke(null, new object[] { role })); } var config = InitializerSection.GetSection(); if (string.IsNullOrEmpty(config.SecurityRoles)) { return(HttpContext.Current != null && HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated && HttpContext.Current.User.IsInRole(role)); } var type = BuildManager.GetType(config.SecurityRoles, true, true); methodIsInRole = type.GetMethod("IsInRole"); return((bool)methodIsInRole.Invoke(null, new object[] { role })); }
public void ExportDataToXlsx(DataTable table, string reportName) { var exporter = new ExporterXslxByArgs(); var logMonitor = InitializerSection.GetSection().LogMonitor; logMonitor.Init(); exporter.LogMonitor = logMonitor; var args = new JournalExportEventArgs { Header = reportName, CheckPermit = false, Columns = GetColumns(table), Data = table.Rows, FilterValues = new List <string>(), FixedRowsCount = 3, }; using (var stream = exporter.GetExcel(args)) { PageHelper.DownloadFile(stream, reportName + ".xlsx", HttpContext.Current.Response); } }
public ResultRows GetSourceData(int startIndex, int count, string dataSource, bool isKz, string parameters, string filter, string sid) { var source = (IDataSourceView)Activator.CreateInstance(BuildManager.GetType(dataSource, true, true), null); if (!source.CheckPermit()) { return new ResultRows { Total = 0, Data = new BaseRow[0] } } ; LocalizationHelper.SetThreadCulture(isKz ? "kk-kz" : "ru-ru", null); if (!string.IsNullOrEmpty(sid)) { Tools.Security.User.SetSID(sid); } var selectParameters = parameters; if (!string.IsNullOrEmpty(filter)) { var filters = new List <MainPageUrlBuilder.FilterParameter> { new MainPageUrlBuilder.FilterParameter { Value = filter, Key = source.TableName, } }; var jss = new JavaScriptSerializer(); var serializedFilter = "__filters=" + GlobalObject.encodeURIComponent(jss.Serialize(filters)); selectParameters = string.IsNullOrEmpty(selectParameters) ? serializedFilter : "&" + serializedFilter; } var query = source.GetSelectIRow(selectParameters); var total = query.Count(); var result = query.Skip(startIndex).Take(count).Cast <BaseRow>().ToArray(); if (source.LogViewData != null) { var logMonitor = InitializerSection.GetSection().LogMonitor; logMonitor.Init(); logMonitor.Log(source.LogViewData.Value, delegate { const string Message = "Выполнен запрос данных через сервис WebServiceAutoComplete.GetSourceData"; logMonitor.FieldChanged(string.Empty, "startIndex", string.Empty, startIndex); logMonitor.FieldChanged(string.Empty, "count", string.Empty, count); logMonitor.FieldChanged(string.Empty, "dataSource", string.Empty, dataSource); logMonitor.FieldChanged(string.Empty, "isKz", string.Empty, isKz.ToString()); logMonitor.FieldChanged(string.Empty, "parameters", string.Empty, parameters); logMonitor.FieldChanged(string.Empty, "filter", string.Empty, filter); if (!string.IsNullOrEmpty(sid)) { var fio = Tools.Security.User.GetPersonInfo(sid); if (fio != null) { sid += " - " + fio.Fio_Ru; } var originalSid = Tools.Security.User.GetSID(false); fio = Tools.Security.User.GetPersonInfo(originalSid); if (fio != null) { originalSid += " - " + fio.Fio_Ru; } logMonitor.FieldChanged(string.Empty, "sid", originalSid, sid); } logMonitor.FieldChanged( string.Empty, "Предоставлены записи", string.Empty, string.Join("; ", result.Select(r => r.id + ": " + r.nameRu).ToArray())); return(new LogMessageEntry { Message = Message, MessageCodeAsLong = source.LogViewData.Value, }); }); } return(new ResultRows { Data = result, Total = total, }); }
public static IExporter GetExcelExporter() { return(InitializerSection.GetSection().GetExcelExporter()); }