Esempio n. 1
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="location">The location.</param>
        public void SetValue( Rock.Model.Location location )
        {
            if ( location != null )
            {
                ItemId = location.Id.ToString();
                List<int> parentLocationIds = new List<int>();
                var parentLocation = location.ParentLocation;

                while ( parentLocation != null )
                {
                    if ( parentLocationIds.Contains( parentLocation.Id ) )
                    {
                        // infinite recursion
                        break;
                    }

                    parentLocationIds.Insert( 0, parentLocation.Id ); ;
                    parentLocation = parentLocation.ParentLocation;
                }

                InitialItemParentIds = parentLocationIds.AsDelimited( "," );
                ItemName = location.ToString();
            }
            else
            {
                ItemId = Constants.None.IdValue;
                ItemName = Constants.None.TextHtml;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="location">The location.</param>
        public void SetValue( Rock.Model.Location location )
        {
            if ( location != null )
            {
                ItemId = location.Id.ToString();

                string parentLocationIds = string.Empty;
                var parentLocation = location.ParentLocation;
                while ( parentLocation != null )
                {
                    parentLocationIds = parentLocation.Id + "," + parentLocationIds;
                    parentLocation = parentLocation.ParentLocation;
                }

                InitialItemParentIds = parentLocationIds.TrimEnd( new char[] { ',' } );
                ItemName = location.ToString();
            }
            else
            {
                ItemId = Constants.None.IdValue;
                ItemName = Constants.None.TextHtml;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Geocodes the specified <see cref="Rock.CRM.Address"/>
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="personId">The person id.</param>
        public void Geocode( Rock.CRM.Address address, int? personId )
        {
            Core.ServiceLogService logService = new Core.ServiceLogService();
            string inputAddress = address.ToString();

            // Try each of the geocoding services that were found through MEF

            foreach ( KeyValuePair<int, Lazy<Rock.Address.GeocodeComponent, Rock.Extension.IComponentData>> service in Rock.Address.GeocodeContainer.Instance.Components )
                if ( !service.Value.Value.AttributeValues.ContainsKey( "Active" ) || bool.Parse( service.Value.Value.AttributeValues["Active"].Value ) )
                {
                    string result;
                    bool success = service.Value.Value.Geocode( address, out result );

                    // Log the results of the service
                    Core.ServiceLog log = new Core.ServiceLog();
                    log.Time = DateTime.Now;
                    log.Type = "Address Geocode";
                    log.Name = service.Value.Metadata.ComponentName;
                    log.Input = inputAddress;
                    log.Result = result;
                    log.Success = success;
                    logService.Add( log, personId );
                    logService.Save( log, personId );

                    // If succesful, set the results and stop processing
                    if ( success  )
                    {
                        address.GeocodeService = service.Value.Metadata.ComponentName;
                        address.GeocodeResult = result;
                        address.GeocodeDate = DateTime.Now;
                        break;
                    }
                }

            address.GeocodeAttempt = DateTime.Now;
        }