コード例 #1
0
 /// <summary>
 /// Get the options for <paramref name="source"/>.
 /// </summary>
 /// <param name="source">Defines the method for retrieving options.</param>
 /// <returns>The options for <paramref name="source"/>.</returns>
 public ControlValueOptionList GetOptions(IOptionSource source)
 {
     DynamicOptionSource dynamicSource = source as DynamicOptionSource;
     ServiceEndpoint endpoint = this.endpointList.Find(x => x.Id == dynamicSource.ServiceEndpointId);
     string json = this.communicator.SendRequest(endpoint, dynamicSource, null);
     JToken token = JToken.Parse(json);
     JContainer jcontainer = token as JContainer;
     ControlValueOptionList list;
     jcontainer.TrySerialiseArray(out list);
     return list;
 }
コード例 #2
0
        /// <summary>
        /// Get the options for <paramref name="source"/>.
        /// </summary>
        /// <param name="source">Defines the method for retrieving options.</param>
        /// <returns>The options for <paramref name="source"/>.</returns>
        public ControlValueOptionList GetOptions(IOptionSource source)
        {
            ControlValueOptionList optionList = new ControlValueOptionList();
            SystemOptionSource systemSource = source as SystemOptionSource;

            UserSearchCriteria criteria = new UserSearchCriteria
                                          {
                                              IncludeServiceUsers = false,
                                              IncludeNoOrganisationUsers = false,
                                              OrganisationIds = new List<string> { this.organisationId }
                                          };

            if (!string.IsNullOrWhiteSpace(systemSource.FilterRoleId))
            {
                criteria.RoleIds = new List<string> { systemSource.FilterRoleId };
            }

            IEnumerable<OptionSourceUser> usersWithRole = this.findUsersFn(criteria);
            MappedField categoryMap = systemSource.ResponseFieldMap.FirstOrDefault(m => m.Target == CATEGORY);
            string categoryKey = categoryMap != null ? categoryMap.Source : string.Empty;

            string descriptionKey = string.Empty;
            var description = systemSource.ResponseFieldMap.FirstOrDefault(m => m.Target == DESCRIPTION);
            if (description != null)
            {
                descriptionKey = description.Source;
            }

            string valueKey = string.Empty;
            var value = systemSource.ResponseFieldMap.FirstOrDefault(m => m.Target == VALUE);
            if (value != null)
            {
                valueKey = value.Source;
            }

            optionList.AddRange(usersWithRole.Select(item => new ControlValueOption
            {
                Category = !string.IsNullOrWhiteSpace(categoryKey) && item.GetType().GetProperty(categoryKey).GetValue(item) != null ? item.GetType().GetProperty(categoryKey).GetValue(item).ToString() : string.Empty,
                Description = !string.IsNullOrWhiteSpace(descriptionKey) && item.GetType().GetProperty(descriptionKey).GetValue(item) != null ? item.GetType().GetProperty(descriptionKey).GetValue(item).ToString() : string.Empty,
                Value = !string.IsNullOrWhiteSpace(valueKey) && item.GetType().GetProperty(valueKey).GetValue(item) != null ? item.GetType().GetProperty(valueKey).GetValue(item).ToString() : string.Empty
            }));

            return optionList;
        }
コード例 #3
0
        /// <summary>
        /// Get the options for <paramref name="source"/>.
        /// </summary>
        /// <param name="source">Defines the method for retrieving options.</param>
        /// <returns>The options for <paramref name="source"/>.</returns>
        public ControlValueOptionList GetOptions(IOptionSource source)
        {
            PrebuiltOptionSource prebuiltSource = source as PrebuiltOptionSource;
            GenericDataSet dataSet = this.dataSetList[prebuiltSource.DataSetId];
            ControlValueOptionList optionList = new ControlValueOptionList();

            MappedField categoryMap = prebuiltSource.ResponseFieldMap.FirstOrDefault(m => m.Target == CATEGORY);
            string categoryKey = categoryMap != null ? categoryMap.Source : string.Empty;
            string descriptionKey = prebuiltSource.ResponseFieldMap.FirstOrDefault(m => m.Target == DESCRIPTION).Source;
            string valueKey = prebuiltSource.ResponseFieldMap.FirstOrDefault(m => m.Target == VALUE).Source;

            optionList.AddRange(dataSet.Data.Select(item => new ControlValueOption
                                                    {
                                                        Category = item.ContainsKey(categoryKey) ? item[categoryKey] : string.Empty,
                                                        Description = item.ContainsKey(descriptionKey) ? item[descriptionKey] : string.Empty,
                                                        Value = item.ContainsKey(valueKey) ? item[valueKey] : string.Empty
                                                    }));

            return optionList;
        }
コード例 #4
0
        /// <summary>
        /// Get the options for <paramref name="source"/>.
        /// </summary>
        /// <param name="source">Defines the method for retrieving options.</param>
        /// <returns>The options for <paramref name="source"/>.</returns>
        public ControlValueOptionList GetOptions(IOptionSource source)
        {
            RepeaterOptionSource repeaterSource = source as RepeaterOptionSource;
            ControlValueOptionList list = new ControlValueOptionList();
            object[] objectArr = this.applicationData.GetValue<object[]>(repeaterSource.RepeaterName);
            if (objectArr == null || objectArr.Length == 0)
            {
                return list;
            }

            Dictionary<string, object>[] repeaterItems = objectArr as Dictionary<string, object>[];
            list.AddRange(repeaterItems.Select(item => new ControlValueOption
                                              {
                                                  Value = string.Join(" ", repeaterSource.ValueFields.Select(key => item[key].ToString())),
                                                  Description = string.Join(" ", repeaterSource.DescriptionFields.Select(key => item[key].ToString())),
                                                  Category = string.IsNullOrEmpty(repeaterSource.CategoryField) ? string.Empty : item[repeaterSource.CategoryField].ToString()
                                              }));

            return list;
        }
コード例 #5
0
 /// <summary>
 /// Get the options for <paramref name="source"/>.
 /// </summary>
 /// <param name="source">Defines the method for retrieving options.</param>
 /// <returns>The options for <paramref name="source"/>.</returns>
 public ControlValueOptionList GetOptions(IOptionSource source)
 {
     StaticOptionSource staticSource = source as StaticOptionSource;
     return staticSource.Options;
 }
コード例 #6
0
 /// <summary>
 /// Gets a <see cref="IOptionSourceProvider"/> that is capable of loading an option list for <paramref name="source"/>.
 /// </summary>
 /// <param name="source">The option source to be loaded.</param>
 /// <returns>A <see cref="IOptionSourceProvider"/> that is capable of loading an option list for <paramref name="source"/>.</returns>
 public IOptionSourceProvider Get(IOptionSource source)
 {
     return this.list.FirstOrDefault(p => p.CanHandle(source));
 }
コード例 #7
0
 /// <summary>
 /// Returns <see langword="true"/> if the instance can handle <paramref name="source"/>,
 /// otherwise <see langword="false"/>.
 /// </summary>
 /// <param name="provider">The provider that acts as the this instance.</param>
 /// <param name="source">The object to be handled.</param>
 /// <returns>
 /// <see langword="true"/> if the instance can handle <paramref name="source"/>,
 /// otherwise <see langword="false"/>
 /// </returns>
 public static bool CanHandle(this IOptionSourceProvider provider, IOptionSource source)
 {
     return provider.CanHandle(source.GetType());
 }