示例#1
0
        /// <summary>
        /// Sends a heartbeat payload with detailed platform information for processing by a listening CAST Server.
        /// </summary>
        public void SendHeartbeat()
        {
            using (Profiler.Measure("CastService.SendHeartbeat"))
            {
                if (!GetIsCastConfigured())
                {
                    return;
                }

                using (new SecurityBypassContext())
                {
                    var dbSettings = ConfigurationSettings.GetDatabaseConfigurationSection().ConnectionSettings;
                    var dbInfo     = DatabaseConfigurationHelper.Convert(dbSettings);
                    var tenants    = new TenantList(TenantService.GetTenants());
                    var apps       = ApplicationService.GetApps().ToList();
                    var hostname   = Dns.GetHostName();
                    var domainname = IPGlobalProperties.GetIPGlobalProperties().DomainName;
                    var pi         = new RemotePlatformInfo
                    {
                        Id             = GetDatabaseId(),
                        Tenants        = tenants,
                        Apps           = apps,
                        FrontEndHost   = hostname,
                        FrontEndDomain = domainname,
                        DatabaseServer = dbInfo.Server,
                        Database       = dbInfo.Database
                    };

                    HeartbeatSender.Send(SpecialStrings.CastHeartbeatKey, pi, false);
                }
            }
        }
示例#2
0
        /// <summary>
        ///     Creates a raw connection to the default database.
        /// </summary>
        public static SqlConnection GetConnection()
        {
            DatabaseInfo databaseInfo = _cachedDatabaseInfo;

            if (databaseInfo == null)
            {
                // Get access to the database configuration settings
                DatabaseConfiguration databaseConfiguration = ConfigurationSettings.GetDatabaseConfigurationSection( );
                if (databaseConfiguration == null)
                {
                    throw new Exception("The application database has not been configured.");
                }

                // Initialize the database information
                databaseInfo = DatabaseConfigurationHelper.Convert(databaseConfiguration.ConnectionSettings);
                if (databaseInfo == null)
                {
                    throw new InvalidOperationException("The application database configuration settings are invalid.");
                }

                _cachedDatabaseInfo = databaseInfo;
            }

            IDbConnection conn = DatabaseHelper.GetConnection(databaseInfo);

            return((SqlConnection)conn);
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="AuditLogSyslogWriter" /> class.
        /// </summary>
        /// <param name="syslogMessageWriter">The syslog message writer.</param>
        /// <exception cref="System.ArgumentNullException">syslogMessageWriter</exception>
        public AuditLogSyslogWriter(ISyslogMessageWriter syslogMessageWriter)
        {
            if (syslogMessageWriter == null)
            {
                throw new ArgumentNullException(nameof(syslogMessageWriter));
            }

            _syslogMessageWriter = syslogMessageWriter;

            SyslogConfiguration syslogConfiguration = ConfigurationSettings.GetSyslogConfigurationSection();

            if (syslogConfiguration?.SyslogApplicationSettings != null)
            {
                _enterpriseId    = syslogConfiguration.SyslogApplicationSettings.EnterpriseId;
                _applicationName = syslogConfiguration.SyslogApplicationSettings.ApplicationName;
            }

            // Fallback
            if (_enterpriseId == 0)
            {
                _enterpriseId = SyslogReadiNowConstants.EnterpriseId;
            }

            if (string.IsNullOrEmpty(_applicationName))
            {
                _applicationName = SyslogReadiNowConstants.ApplicationName;
            }

            _databaseName   = string.Empty;
            _databaseServer = string.Empty;
            var databaseConfiguration = ConfigurationSettings.GetDatabaseConfigurationSection();

            if (databaseConfiguration?.ConnectionSettings != null)
            {
                _databaseName   = databaseConfiguration.ConnectionSettings.Database;
                _databaseServer = databaseConfiguration.ConnectionSettings.Server;
            }

            _processName = Process.GetCurrentProcess().MainModule.ModuleName;
            _hostName    = GetHostName();

            try
            {
                _ipHostEntry = Dns.GetHostEntry(Dns.GetHostName());
            }
            catch
            {
                // ignored
            }

            if (!string.IsNullOrEmpty(SystemInfo.InstallFolder))
            {
                _installFolder = SystemInfo.InstallFolder.Replace("\\", "/");
            }
        }
        /// <summary>
        ///     Validates the message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="auditLogEventData">The audit log event data.</param>
        /// <returns></returns>
        private bool ValidateMessage(SyslogMessage message, IAuditLogEntryData auditLogEventData)
        {
            SyslogApplicationSettings syslogApplicationSettings = ConfigurationSettings.GetSyslogConfigurationSection().SyslogApplicationSettings;
            SyslogSeverity            severity;

            string databaseName          = string.Empty;
            string databaseServer        = string.Empty;
            var    databaseConfiguration = ConfigurationSettings.GetDatabaseConfigurationSection();

            if (databaseConfiguration?.ConnectionSettings != null)
            {
                databaseName   = databaseConfiguration.ConnectionSettings.Database;
                databaseServer = databaseConfiguration.ConnectionSettings.Server;
            }

            switch (auditLogEventData.SeverityEnum)
            {
            case AuditLogSeverityEnum_Enumeration.AuditLogInformation:
                severity = SyslogSeverity.Informational;
                break;

            case AuditLogSeverityEnum_Enumeration.AuditLogWarning:
                severity = SyslogSeverity.Warning;
                break;

            case AuditLogSeverityEnum_Enumeration.AuditLogError:
                severity = SyslogSeverity.Error;
                break;

            default:
                throw new ArgumentException("auditLogEventData");
            }

            Assert.AreEqual(1, message.Version, "The version is incorrect.");
            Assert.AreEqual(SyslogFacility.LogAudit, message.Facility, "The facility is incorrect");
            Assert.AreEqual(severity, message.Severity, "The severity is incorrect");
            Assert.AreEqual(syslogApplicationSettings.ApplicationName, message.AppName, "The app name is incorrect");
            Assert.AreEqual(auditLogEventData.AuditLogEntryMetadata.MessageId, message.MsgId, "The message id is invalid");
            Assert.AreEqual(4, message.StructuredDataElements.Count, "The number of structured data elements is invalid");
            Assert.AreEqual("audit@" + syslogApplicationSettings.EnterpriseId, message.StructuredDataElements[0].SdId);
            Assert.AreEqual(auditLogEventData.AuditLogEntryMetadata.MessageId + "@" + syslogApplicationSettings.EnterpriseId, message.StructuredDataElements[1].SdId);
            Assert.AreEqual("systemInfo@" + syslogApplicationSettings.EnterpriseId, message.StructuredDataElements[2].SdId);
            Assert.AreEqual("installDirectory", message.StructuredDataElements[2].Parameters[0].Name);
            Assert.AreEqual(SystemInfo.InstallFolder.Replace("\\", "/"), message.StructuredDataElements[2].Parameters[0].Value);

            Assert.AreEqual("databaseName", message.StructuredDataElements[2].Parameters[1].Name);
            Assert.AreEqual(databaseName, message.StructuredDataElements[2].Parameters[1].Value);

            Assert.AreEqual("databaseServer", message.StructuredDataElements[2].Parameters[2].Name);
            Assert.AreEqual(databaseServer, message.StructuredDataElements[2].Parameters[2].Value);

            Assert.AreEqual(SyslogOriginConstants.Origin, message.StructuredDataElements[3].SdId);

            return(true);
        }
示例#5
0
        /// <summary>
        /// Gets an object that encapsulates an open and authorized database connection.
        /// </summary>
        /// <param name="requireTransaction">if set to <c>true</c> a valid database transaction is required.</param>
        /// <param name="commandTimeout">The command timeout.</param>
        /// <param name="transactionTimeout">The transaction timeout.</param>
        /// <param name="databaseInfo">An object describing the database properties.</param>
        /// <param name="enlistTransaction">if set to <c>true</c> enlists the current transaction if possible.</param>
        /// <param name="preventPostSaveActionsPropagating">if set to <c>true</c> the post save actions will not propagate up the db context stack.</param>
        /// <param name="createConnectionImmediately">Create the connection immediately rather than when first used. Use this to prevent distributed transaction escalation problems.</param>
        /// <param name="isUnitTestTransaction">if set to <c>true</c> [is unit test transaction].</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">The application database has not been configured.</exception>
        /// <exception cref="System.InvalidOperationException">The application database configuration settings are invalid.</exception>
        public static DatabaseContext GetContext(bool requireTransaction = false, int commandTimeout = -1, int transactionTimeout = -1, DatabaseInfo databaseInfo = null, bool enlistTransaction = true, bool preventPostSaveActionsPropagating = false, bool createConnectionImmediately = false, bool isUnitTestTransaction = false)
        {
            if (DatabaseOverride.IsActive)
            {
                databaseInfo = DatabaseOverride.Current;
            }

            if (databaseInfo == null)
            {
                databaseInfo = _cachedDatabaseInfo;

                if (databaseInfo == null)
                {
                    /////
                    // Get access to the database configuration settings
                    /////
                    DatabaseConfiguration databaseConfiguration = ConfigurationSettings.GetDatabaseConfigurationSection( );

                    if (databaseConfiguration == null)
                    {
                        throw new Exception("The application database has not been configured.");
                    }

                    /////
                    // Initialize the database information
                    /////
                    databaseInfo = DatabaseConfigurationHelper.Convert(databaseConfiguration.ConnectionSettings);

                    if (databaseInfo == null)
                    {
                        throw new InvalidOperationException("The application database configuration settings are invalid.");
                    }

                    _cachedDatabaseInfo = databaseInfo;
                }
            }

            /////
            // Initialize command timeout.
            /////
            if (commandTimeout <= 0)
            {
                commandTimeout = databaseInfo.CommandTimeout;
            }

            /////
            // Initialize Transaction timeout.
            /////
            if (transactionTimeout <= 0)
            {
                transactionTimeout = databaseInfo.TransactionTimeout;
            }

            return(GetContext_Impl(databaseInfo, requireTransaction, commandTimeout, transactionTimeout, enlistTransaction, preventPostSaveActionsPropagating, createConnectionImmediately, isUnitTestTransaction));
        }
示例#6
0
        private static NameValueCollection GetSchedulerProperties()
        {
            var properties = new NameValueCollection();

            if (_connectionString == null)
            {
                var dbSettings = ConfigurationSettings.GetDatabaseConfigurationSection().ConnectionSettings;
                var dbInfo     = DatabaseConfigurationHelper.Convert(dbSettings);
                _connectionString = dbInfo.ConnectionString + ";Enlist=false";
            }

            // Note that all types are referred to using n Assembly qualified name. This seems to be be best approach when the assemblies are in the GAC.

            properties["quartz.scheduler.instanceName"]              = "ReadiNow Scheduler";
            properties["quartz.scheduler.instanceId"]                = "AUTO";
            properties["quartz.scheduler.typeLoadHelper.type"]       = typeof(SchedulingTypeLoadHelper).AssemblyQualifiedName;
            properties["quartz.scheduler.makeSchedulerThreadDaemon"] = "false";
            properties["quartz.threadPool.type"]               = typeof(SimpleThreadPool).AssemblyQualifiedName; // "Quartz.Simpl.SimpleThreadPool, Quartz";
            properties["quartz.threadPool.threadCount"]        = "5";
            properties["quartz.threadPool.threadPriority"]     = "Normal";
            properties["quartz.threadPool.makeThreadsDaemons"] = "false";

            properties["quartz.jobStore.misfireThreshold"] = "60000";
            properties["quartz.jobStore.type"]             = typeof(Quartz.Impl.AdoJobStore.JobStoreTX).AssemblyQualifiedName; //"Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
            properties["quartz.jobStore.useProperties"]    = "true";
            properties["quartz.jobStore.dataSource"]       = "default";
            properties["quartz.jobStore.tablePrefix"]      = "QRTZ_";

            properties["quartz.jobStore.clustered"]          = "true";
            properties["quartz.jobStore.driverDelegateType"] = typeof(EdcDelegate).AssemblyQualifiedName;   //"EDC.ReadiNow.Scheduling.EdcDelegate, EDC.ReadiNow.Common, Version=1.0.0.0, Culture=neutral";

            properties["quartz.dataSource.default.connectionString"] = _connectionString;
            properties["quartz.dataSource.default.provider"]         = "SqlServer-20";

            return(properties);
        }
        /// <summary>
        /// Applies report settings to the structured query and also builds an appropriate query settings object.
        /// </summary>
        /// <param name="structuredQuery"></param>
        /// <param name="queryReportSettings"></param>
        /// <returns></returns>
        private static PreparedQuery PrepareReportRun(StructuredQuery structuredQuery, ReportSettings queryReportSettings)
        {
            QuerySettings querySettings;

            // Build the query engine settings
            bool secureReports;

            if (!_cachedSecureReports.HasValue)
            {
                DatabaseConfiguration dbConfiguration;
                dbConfiguration = ConfigurationSettings.GetDatabaseConfigurationSection( );
                if (dbConfiguration != null)
                {
                    _cachedSecureReports = dbConfiguration.ConnectionSettings.SecureReports;
                }
            }

            secureReports = _cachedSecureReports.Value;

            // Set the time zone for the report
            if (queryReportSettings.Timezone != null)
            {
                structuredQuery.TimeZoneName = queryReportSettings.Timezone.StandardName;
            }

            // Update the query engine settings
            querySettings = new QuerySettings
            {
                SecureQuery             = secureReports,
                SupportPaging           = queryReportSettings.SupportPaging,
                FirstRow                = queryReportSettings.InitialRow,
                PageSize                = queryReportSettings.PageSize,
                QuickSearchTerm         = queryReportSettings.QuickSearch,
                SupportQuickSearch      = !string.IsNullOrWhiteSpace(queryReportSettings.QuickSearch),
                FullAggregateClustering = true,
                RefreshCachedResult     = queryReportSettings.RefreshCachedResult,
                RefreshCachedSql        = queryReportSettings.RefreshCachedSql,
                CpuLimitSeconds         = queryReportSettings.CpuLimitSeconds
            };

            if (queryReportSettings.ReportOnType.HasValue)
            {
                Model.IEntity typeEntity = Model.Entity.Get <Model.EntityType>(queryReportSettings.ReportOnType);
                if (typeEntity == null)
                {
                    throw new WebArgumentException("Not a valid type");
                }

                (( ResourceEntity )structuredQuery.RootEntity).EntityTypeId = queryReportSettings.ReportOnType.Value;
            }

            if (queryReportSettings.ReportParameters != null)
            {
                // Apply any filters for analyser
                if (queryReportSettings.ReportParameters.AnalyserConditions != null &&
                    queryReportSettings.ReportParameters.AnalyserConditions.Count > 0)
                {
                    ApplyAnalyserConditions(structuredQuery, queryReportSettings.ReportParameters.AnalyserConditions);
                }
                // Apply any filters for sorting
                if (queryReportSettings.ReportParameters.SortColumns != null)
                {
                    ApplySortOrder(structuredQuery, queryReportSettings.ReportParameters.SortColumns);
                }
                // Determine if main row report is to be ignored
                querySettings.ResultSchemaOnly = queryReportSettings.ReportParameters.GroupAggregateRules != null && queryReportSettings.ReportParameters.GroupAggregateRules.IgnoreRows;
            }

            if (queryReportSettings.ReportRelationship != null)
            {
                ApplyRelatedResourceCondition(structuredQuery, queryReportSettings.ReportRelationship, querySettings);
            }

            if (queryReportSettings.RelatedEntityFilters != null)
            {
                ApplyRelatedEntityFilters(structuredQuery, queryReportSettings.RelatedEntityFilters);
            }

            if (queryReportSettings.FilteredEntityIdentifiers != null &&
                queryReportSettings.FilteredEntityIdentifiers.Count > 0)
            {
                ApplyFilteredEntityIdentifiers(structuredQuery, queryReportSettings.FilteredEntityIdentifiers);
            }

            PreparedQuery preparedQuery = new PreparedQuery
            {
                QuerySettings   = querySettings,
                StructuredQuery = structuredQuery
            };

            return(preparedQuery);
        }
示例#8
0
        /// <summary>
        /// Get the syslog writer.
        /// </summary>
        /// <returns>The syslog writer.</returns>
        public static IEventLogWriter GetSyslogEventLogWriter()
        {
            DiagnosticsConfiguration diagnosticsConfiguration = ConfigurationSettings.GetDiagnosticsConfigurationSection();

            EventLogSyslogSettings syslogSettings = diagnosticsConfiguration?.SyslogSettings;

            if (syslogSettings == null || !syslogSettings.IsEnabled || string.IsNullOrEmpty(syslogSettings.HostName) || syslogSettings.Port <= 0)
            {
                return(null);
            }

            int    enterpriseId    = 0;
            string applicationName = string.Empty;

            SyslogConfiguration syslogConfiguration = ConfigurationSettings.GetSyslogConfigurationSection();

            if (syslogConfiguration?.SyslogApplicationSettings != null)
            {
                enterpriseId    = syslogConfiguration.SyslogApplicationSettings.EnterpriseId;
                applicationName = syslogConfiguration.SyslogApplicationSettings.ApplicationName;
            }

            // Fallback
            if (enterpriseId == 0)
            {
                enterpriseId = SyslogReadiNowConstants.EnterpriseId;
            }

            if (string.IsNullOrEmpty(applicationName))
            {
                applicationName = SyslogReadiNowConstants.ApplicationName;
            }

            string databaseName          = string.Empty;
            string databaseServer        = string.Empty;
            var    databaseConfiguration = ConfigurationSettings.GetDatabaseConfigurationSection();

            if (databaseConfiguration?.ConnectionSettings != null)
            {
                databaseName   = databaseConfiguration.ConnectionSettings.Database;
                databaseServer = databaseConfiguration.ConnectionSettings.Server;
            }

            IStreamProvider          tcpStreamProvider     = new TcpStreamProvider(syslogSettings.HostName, syslogSettings.Port, true, syslogSettings.IsSecure, syslogSettings.IgnoreSslErrors);
            ISyslogMessageSerializer syslogMsgSerializer   = new SyslogMessageSerializer();
            ISyslogMessageWriter     streamWriter          = new SyslogStreamWriter(tcpStreamProvider, syslogMsgSerializer);
            ISyslogMessageWriter     queueingMessageWriter = new SyslogQueueingMessageWriter(streamWriter, 0);

            return(new EventLogSyslogWriter(queueingMessageWriter)
            {
                EnterpriseId = enterpriseId,
                ApplicationName = applicationName,
                SoftwareVersion = SystemInfo.PlatformVersion,
                ErrorEnabled = syslogSettings.ErrorEnabled,
                WarningEnabled = syslogSettings.WarningEnabled,
                InformationEnabled = syslogSettings.InformationEnabled,
                TraceEnabled = syslogSettings.TraceEnabled,
                InstallFolder = SystemInfo.InstallFolder,
                DatabaseName = databaseName,
                DatabaseServer = databaseServer
            });
        }