Esempio n. 1
0
        /// <summary>
        /// Sends statistics to the SDN server but only if there are more than 100 person records
        /// or the sample data has not been loaded.
        ///
        /// The statistics are:
        ///     * Rock Instance Id
        ///     * Update Version
        ///     * IP Address - The IP address of your Rock server.
        ///
        /// ...and we only send these if they checked the "Include Impact Statistics":
        ///     * Organization Name and Address
        ///     * Public Web Address
        ///     * Number of Active Records
        ///
        /// As per http://www.rockrms.com/Rock/Impact
        /// </summary>
        /// <param name="version">the semantic version number</param>
        private void SendStatictics(string version)
        {
            try
            {
                var rockContext           = new RockContext();
                int numberOfActiveRecords = new PersonService(rockContext).Queryable(includeDeceased: false, includeBusinesses: false).Count();

                if (numberOfActiveRecords > 100 || !Rock.Web.SystemSettings.GetValue(SystemSettingKeys.SAMPLEDATA_DATE).AsDateTime().HasValue)
                {
                    string         organizationName     = string.Empty;
                    ImpactLocation organizationLocation = null;
                    string         publicUrl            = string.Empty;

                    var rockInstanceId = Rock.Web.SystemSettings.GetRockInstanceId();
                    var ipAddress      = Request.ServerVariables["LOCAL_ADDR"];

                    if (cbIncludeStats.Checked)
                    {
                        var globalAttributes = GlobalAttributesCache.Get();
                        organizationName = globalAttributes.GetValue("OrganizationName");
                        publicUrl        = globalAttributes.GetValue("PublicApplicationRoot");

                        // Fetch the organization address
                        var organizationAddressLocationGuid = globalAttributes.GetValue("OrganizationAddress").AsGuid();
                        if (!organizationAddressLocationGuid.Equals(Guid.Empty))
                        {
                            var location = new Rock.Model.LocationService(rockContext).Get(organizationAddressLocationGuid);
                            if (location != null)
                            {
                                organizationLocation = new ImpactLocation(location);
                            }
                        }
                    }
                    else
                    {
                        numberOfActiveRecords = 0;
                    }

                    var environmentData = Rock.Web.Utilities.RockUpdateHelper.GetEnvDataAsJson(Request, ResolveRockUrl("~/"));

                    // now send them to SDN/Rock server
                    SendToSpark(rockInstanceId, version, ipAddress, publicUrl, organizationName, organizationLocation, numberOfActiveRecords, environmentData);
                }
            }
            catch (Exception ex)
            {
                // Just catch any exceptions, log it, and keep moving... We don't want to mess up the experience
                // over a few statistics/metrics.
                try
                {
                    LogException(ex);
                }
                catch { }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Sends the public data and impact statistics to the Rock server.
        /// </summary>
        /// <param name="rockInstanceId">The rock instance identifier.</param>
        /// <param name="version">The version.</param>
        /// <param name="ipAddress">The ip address.</param>
        /// <param name="publicUrl">The public URL.</param>
        /// <param name="organizationName">Name of the organization.</param>
        /// <param name="organizationLocation">The organization location.</param>
        /// <param name="numberOfActiveRecords">The number of active records.</param>
        /// <param name="environmentData">The environment data (JSON).</param>
        private void SendToSpark(Guid rockInstanceId, string version, string ipAddress, string publicUrl, string organizationName, ImpactLocation organizationLocation, int numberOfActiveRecords, string environmentData)
        {
            ImpactStatistic impactStatistic = new ImpactStatistic()
            {
                RockInstanceId        = rockInstanceId,
                Version               = version,
                IpAddress             = ipAddress,
                PublicUrl             = publicUrl,
                OrganizationName      = organizationName,
                OrganizationLocation  = organizationLocation,
                NumberOfActiveRecords = numberOfActiveRecords,
                EnvironmentData       = environmentData
            };

            var client  = new RestClient("http://www.rockrms.com/api/impacts/save");
            var request = new RestRequest(Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddBody(impactStatistic);
            var response = client.Execute(request);
        }
Esempio n. 3
0
        /// <summary>
        /// Sends the public data and impact statistics to the Rock server.
        /// </summary>
        /// <param name="rockInstanceId"></param>
        /// <param name="version"></param>
        /// <param name="ipAddress"></param>
        /// <param name="publicUrl"></param>
        /// <param name="organizationName"></param>
        /// <param name="organizationAddress"></param>
        /// <param name="numberOfActiveRecords"></param>
        private void SendToSpark( Guid rockInstanceId, string version, string ipAddress, string publicUrl, string organizationName, ImpactLocation organizationLocation, int numberOfActiveRecords )
        {
            ImpactStatistic impactStatistic = new ImpactStatistic()
            {
                RockInstanceId = rockInstanceId,
                Version = version,
                IpAddress = ipAddress,
                PublicUrl = publicUrl,
                OrganizationName = organizationName,
                OrganizationLocation = organizationLocation,
                NumberOfActiveRecords = numberOfActiveRecords
            };

            var client = new RestClient( "http://www.rockrms.com/api/impacts/save" );
            var request = new RestRequest( Method.POST );
            request.RequestFormat = DataFormat.Json;
            request.AddBody( impactStatistic );
            var response = client.Execute( request );
        }
Esempio n. 4
0
        /// <summary>
        /// Sends statistics to the SDN server but only if there are more than 100 person records
        /// or the sample data has not been loaded. 
        /// 
        /// The statistics are:
        ///     * Rock Instance Id
        ///     * Update Version
        ///     * IP Address - The IP address of your Rock server.
        ///     
        /// ...and we only send these if they checked the "Include Impact Statistics":
        ///     * Organization Name and Address
        ///     * Public Web Address
        ///     * Number of Active Records
        ///     
        /// As per http://www.rockrms.com/Rock/Impact
        /// </summary>
        /// <param name="version">the semantic version number</param>
        private void SendStatictics( string version )
        {
            try
            {
                var rockContext = new RockContext();
                int numberOfActiveRecords = new PersonService( rockContext ).Queryable( includeDeceased: false, includeBusinesses: false ).Count();

                if ( numberOfActiveRecords > 100 || !Rock.Web.SystemSettings.GetValue( SystemSettingKeys.SAMPLEDATA_DATE ).AsDateTime().HasValue )
                {
                    string organizationName = string.Empty;
                    ImpactLocation organizationLocation = null;
                    string publicUrl = string.Empty;

                    var rockInstanceId = Rock.Web.SystemSettings.GetRockInstanceId();
                    var ipAddress = Request.ServerVariables["LOCAL_ADDR"];

                    if ( cbIncludeStats.Checked )
                    {
                        var globalAttributes = GlobalAttributesCache.Read();
                        organizationName = globalAttributes.GetValue( "OrganizationName" );
                        publicUrl = globalAttributes.GetValue( "PublicApplicationRoot" );

                        // Fetch the organization address
                        var organizationAddressLocationGuid = globalAttributes.GetValue( "OrganizationAddress" ).AsGuid();
                        if ( !organizationAddressLocationGuid.Equals( Guid.Empty ) )
                        {
                            var location = new Rock.Model.LocationService( rockContext ).Get( organizationAddressLocationGuid );
                            if ( location != null )
                            {
                                organizationLocation = new ImpactLocation( location );
                            }
                        }
                    }
                    else
                    {
                        numberOfActiveRecords = 0;
                    }

                    // now send them to SDN/Rock server
                    SendToSpark( rockInstanceId, version, ipAddress, publicUrl, organizationName, organizationLocation, numberOfActiveRecords );
                }
            }
            catch ( Exception ex )
            {
                // Just catch any exceptions, log it, and keep moving... We don't want to mess up the experience
                // over a few statistics/metrics.
                try
                {
                    LogException( ex );
                }
                catch { }
            }
        }