Example #1
0
        internal Dictionary <ItemBase, Tuple <Uri, UrlSourceType> > GetForQuery(int idItemType, Type type, IEnumerable <ItemBase> items)
        {
            var absoluteUrl = AppCore.ServerUrl;
            var urlManager  = AppCore.Get <UrlManager>();
            var itemsSet    = items.ToDictionary <ItemBase, ItemBase, Tuple <Uri, UrlSourceType> >(x => x, x => null);

            var keys   = itemsSet.Keys.ToList();
            var result = urlManager.GetUrl(keys.Select(x => x.ID), idItemType, RoutingConstants.MAINKEY);

            if (!result.IsSuccess)
            {
                result = urlManager.GetUrl(keys.Select(x => x.ID), idItemType, RoutingConstants.MAINKEY);
            }
            if (!result.IsSuccess)
            {
                Debug.WriteLine("ItemBase.GetForQuery({0}): {1}", idItemType, result.Message);
                throw new Exception("Ошибка получения адресов");
            }

            var itemsEmpty = new System.Collections.ObjectModel.Collection <ItemBase>();

            foreach (var x in keys)
            {
                if (result.Result.TryGetValue(x.ID, out string value) && !string.IsNullOrEmpty(value))
                {
                    if (Uri.TryCreate(value, UriKind.Absolute, out Uri url))
                    {
                        itemsSet[x] = new Tuple <Uri, UrlSourceType>(url, UrlSourceType.Routing);
                    }
                    else if (Uri.TryCreate(absoluteUrl, value, out Uri url2))
                    {
                        itemsSet[x] = new Tuple <Uri, UrlSourceType>(url2, UrlSourceType.Routing);
                    }
                }
                else
                {
                    itemsEmpty.Add(x);
                }
            }

            if (itemsEmpty.Count > 0)
            {
                itemsEmpty.GroupBy(x => x.OwnerModuleWeb, x => x).ForEach(gr_ =>
                {
                    if (gr_.Key != null)
                    {
                        var itemsModule = gr_.ToList();

                        var generated = gr_.Key.GenerateLinks(itemsModule);
                        if (generated != null)
                        {
                            foreach (var pair in generated)
                            {
                                if (pair.Value != null)
                                {
                                    itemsSet[pair.Key] = new Tuple <Uri, UrlSourceType>(pair.Value, UrlSourceType.Module);
                                }
                            }
                        }
                    }
                });
            }

            return(itemsSet);
        }