private Dictionary <string, string> PrefetchLinks(EditDto editData)
        {
            try
            {
                // Step 1: try to find hyperlink fields
                var bundlesHavingLinks = BundleWithLinkFields(editData);

                var links = bundlesHavingLinks.SelectMany(set
                                                          => set.Hyperlink.SelectMany(h
                                                                                      => h.Value?.Select(linkAttrib
                                                                                                         => new
                {
                    set.Guid,
                    Link = linkAttrib.Value
                })))
                            .Where(set => set != null)
                            // Step 2: Check which ones have a link reference
                            .Where(set => ValueConverterBase.CouldBeReference(set.Link))
                            .ToList();

                // Step 3: Look them up
                // Step 4: return dictionary with these
                return(links.ToDictionary(
                           s => s.Link,
                           s => _valueConverter.ToValue(s.Link, s.Guid)
                           ));
            }
            catch
            {
                return(new Dictionary <string, string>
                {
                    { "Error", "An error occurred pre-fetching the links" }
                });
            }
        }
Beispiel #2
0
        private Dictionary <string, LinkInfoDto> PrefetchLinks(int appId, EditDto editData)
        {
            try
            {
                // Step 1: try to find hyperlink fields
                var bundlesHavingLinks = BundleWithLinkFields(editData);

                var links = bundlesHavingLinks
                            .SelectMany(set => set.HyperlinkFields
                                        .SelectMany(h => h.Value?.Select(linkAttrib => new
                {
                    Link      = linkAttrib.Value,
                    Converted = TryToConvertOrErrorText(appId, set.ContentTypeName, h.Key, linkAttrib.Value, set.Guid),
                })))
                            .Where(set => set != null)
                            // Step 2: Check which ones have a link reference
                            .Where(set => ValueConverterBase.CouldBeReference(set.Link))
                            // Make distinct by Link
                            .GroupBy(l => l.Link)
                            .Select(g => g.First())
                            .ToList();


                // Step 3: Look them up
                // Step 4: return dictionary with these
                return(links.ToDictionary(
                           s => s.Link,
                           s => s.Converted));
            }
            catch (Exception ex)
            {
                return(new Dictionary <string, LinkInfoDto>
                {
                    { "Error", new LinkInfoDto {
                          Value = "An error occurred pre-fetching the links " + ex.Message
                      } }
                });
            }
        }
Beispiel #3
0
        private object _getValue(string field, string language = null, bool lookup = true)
        {
            var defaultMode = language == null && lookup;

            #region check the two special cases Toolbar / Presentation which the EAV doesn't know
#if NETFRAMEWORK
            // ReSharper disable once ConvertIfStatementToSwitchStatement
#pragma warning disable 618
            if (field == "Toolbar")
            {
                return(Toolbar.ToString());
            }
#pragma warning restore 618
#endif
            if (field == ViewParts.Presentation)
            {
                return(Presentation);
            }

            #endregion

            // use the standard dimensions or overload
            var dimsToUse = language == null ? Dimensions : new[] { language };

            // check Entity is null (in cases where null-objects are asked for properties)
            if (Entity == null)
            {
                return(null);
            }

            // check if we already have it in the cache - but only in normal lookups
            if (defaultMode && _valCache.ContainsKey(field))
            {
                return(_valCache[field]);
            }

            var result = Entity.GetBestValue(field, dimsToUse);

            // New mechanism to not use resolve-hyperlink
            if (lookup && result is string strResult &&
                ValueConverterBase.CouldBeReference(strResult) &&
                Entity.Attributes.ContainsKey(field) &&
                Entity.Attributes[field].Type == Eav.Constants.DataTypeHyperlink)
            {
                result = _serviceProviderOrNull?.Build <IValueConverter>()?.ToValue(strResult, EntityGuid)
                         ?? result;
            }

            if (result is IEnumerable <IEntity> rel)
            {
                // Note: if it's a Dynamic Entity without block (like App.Settings) it needs the Service Provider from this object to work
                result = new DynamicEntityWithList(Entity, field, rel, dimsToUse, CompatibilityLevel, Block,
                                                   _serviceProviderOrNull);
            }

            if (defaultMode)
            {
                _valCache.Add(field, result);
            }
            return(result);
        }