<commit_before>﻿namespace nuPickers
{
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    using nuPickers.Caching;
    using nuPickers.Shared.EnumDataSource;
    using nuPickers.Shared.RelationMapping;
    using nuPickers.Shared.SaveFormat;
    using Shared.DataSource;
    using Shared.Editor;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using umbraco;
    using Umbraco.Core;
    using Umbraco.Core.Models;
    using Umbraco.Web;

    public class Picker
    {        
        /// <summary>
        /// cache var, stores value after querying relations or parsing a save format
        /// </summary>
        private string[] pickedKeys = null;

        #region Constructors

        /// <summary>
        /// public constructor - picker value is calculated from lookup, either the published value from cache, or the latest saved db value 
        /// </summary>
        /// <param name="contextId">the id of the content, media or member</param>
        /// <param name="propertyAlias">the property alias</param>
        /// <param name="usePublishedValue">when true uses the published value, otherwise when false uses the lastest saved value (which may also be the published value)</param>
        public Picker(int contextId, string propertyAlias, bool usePublishedValue = true)
        {
            this.ContextId = contextId;
            this.PropertyAlias = propertyAlias;

            UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
            Picker picker;

            switch (Helper.GetUmbracoObjectType(this.ContextId))
            {
                case uQuery.UmbracoObjectType.Document:
                    picker = umbracoHelper.TypedContent(this.ContextId).GetPropertyValue<Picker>(this.PropertyAlias);
                    this.ParentId = picker.ParentId;
                    this.DataTypeId = picker.DataTypeId;
                    this.PropertyEditorAlias = picker.PropertyEditorAlias;

                    if (usePublishedValue)
                    {
                        this.SavedValue = picker.SavedValue;
                    }
                    else
                    {
                        this.SavedValue = ApplicationContext.Current.Services.ContentService.GetById(this.ContextId).GetValue(propertyAlias);
                    }

                    break;

                case uQuery.UmbracoObjectType.Media:
                    picker = umbracoHelper.TypedMedia(this.ContextId).GetPropertyValue<Picker>(this.PropertyAlias);
                    this.ParentId = picker.ParentId;
                    this.DataTypeId = picker.DataTypeId;
                    this.PropertyEditorAlias = picker.PropertyEditorAlias;
                    this.SavedValue = picker.SavedValue;
                    break;

                case uQuery.UmbracoObjectType.Member:
                    picker = umbracoHelper.TypedMember(this.ContextId).GetPropertyValue<Picker>(this.PropertyAlias);
                    this.ParentId = picker.ParentId;
                    this.DataTypeId = picker.DataTypeId;
                    this.PropertyEditorAlias = picker.PropertyEditorAlias;
                    this.SavedValue = picker.SavedValue;
                    break;
            }
        }

        /// <summary>
        /// internal constructor - picker value is supplied (used by PropertyValueConverter & RelationMappingEvent)
        /// </summary>
        /// <param name="contextId">the id of the content, media or member (-1 means out of context)</param>
        /// <param name="PublishedPropertyType">contains details about the propety editor</param>
        /// <param name="savedValue">the actual value saved</param>
        internal Picker(int contextId, int parentId, string propertyAlias, int dataTypeId, string propertyEditorAlias, object savedValue)
        {
            this.ContextId = contextId;
            this.ParentId = parentId;
            this.PropertyAlias = propertyAlias;
            this.DataTypeId = dataTypeId;<commit_msg>simplified public constructor of Picker (same signature)<commit_after>﻿namespace nuPickers
{
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    using nuPickers.Caching;
    using nuPickers.Shared.EnumDataSource;
    using nuPickers.Shared.RelationMapping;
    using nuPickers.Shared.SaveFormat;
    using Shared.DataSource;
    using Shared.Editor;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using umbraco;
    using Umbraco.Core;
    using Umbraco.Core.Models;
    using Umbraco.Web;

    public class Picker
    {        
        /// <summary>
        /// cache var, stores value after querying relations or parsing a save format
        /// </summary>
        private string[] pickedKeys = null;

        #region Constructors

        /// <summary>
        /// public constructor - picker value is calculated from lookup, either the published value from cache, or the latest saved db value 
        /// </summary>
        /// <param name="contextId">the id of the content, media or member</param>
        /// <param name="propertyAlias">the property alias</param>
        /// <param name="usePublishedValue">when true uses the published value, otherwise when false uses the lastest saved value (which may also be the published value)</param>
        public Picker(int contextId, string propertyAlias, bool usePublishedValue = true)
        {
            this.ContextId = contextId;
            this.PropertyAlias = propertyAlias;

            UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
            Picker picker = null;

            // based on type, ask Umbraco for a picker obj (via the PickerPropertyValueConverter)
            switch (Helper.GetUmbracoObjectType(this.ContextId))
            {
                case uQuery.UmbracoObjectType.Document: picker = umbracoHelper.TypedContent(this.ContextId).GetPropertyValue<Picker>(this.PropertyAlias);

                    if (!usePublishedValue)
                    {
                        // reset (private) property on returned picker, so it's value is taken from the database
                        picker.SavedValue = ApplicationContext.Current.Services.ContentService.GetById(this.ContextId).GetValue(propertyAlias);
                    }

                    break;

                case uQuery.UmbracoObjectType.Media: picker = umbracoHelper.TypedMedia(this.ContextId).GetPropertyValue<Picker>(this.PropertyAlias); break;
                case uQuery.UmbracoObjectType.Member: picker = umbracoHelper.TypedMember(this.ContextId).GetPropertyValue<Picker>(this.PropertyAlias);  break;
            }

            this.ParentId = picker.ParentId;
            this.DataTypeId = picker.DataTypeId;
            this.PropertyEditorAlias = picker.PropertyEditorAlias;
            this.SavedValue = picker.SavedValue;
        }

        /// <summary>
        /// internal constructor - picker value is supplied (used by PropertyValueConverter & RelationMappingEvent)
        /// </summary>
        /// <param name="contextId">the id of the content, media or member (-1 means out of context)</param>
        /// <param name="PublishedPropertyType">contains details about the propety editor</param>
        /// <param name="savedValue">the actual value saved</param>
        internal Picker(int contextId, int parentId, string propertyAlias, int dataTypeId, string propertyEditorAlias, object savedValue)
        {
            this.ContextId = contextId;
            this.ParentId = parentId;
            this.PropertyAlias = propertyAlias;
            this.DataTypeId = dataTypeId;
{'fraction_non_alphanumeric': 0.08403031887088343, 'fraction_numerical': 0.00026136957658128593, 'mean_word_length': 2.155876288659794, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5418877', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1870, 'n_words': 485}