Exemple #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);
                }
            }
        }
        /// <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>
        /// 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));
        }
        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);
        }