Exemple #1
0
        public StreamedSequenceInfo(Type dataType, Expression itemExpression)
        {
            ResultItemType = ReflectionUtility.GetItemTypeOfClosedGenericIEnumerable(dataType, "dataType");
            if (!ResultItemType.IsAssignableFrom(itemExpression.Type))
            {
                var message = string.Format("ItemExpression is of type '{0}', but should be '{1}' (or derived from it).", itemExpression.Type, ResultItemType);
                throw new ArgumentException(message, "itemExpression");
            }

            DataType       = dataType;
            ItemExpression = itemExpression;
        }
Exemple #2
0
        public static ResultItemType CreateResultType(SPWeb web, string name, string displayTemplateUrl, PropertyRule[] rules, bool optimizeForFrequentUse)
        {
            ResultItemType resType = new ResultItemType(new SearchObjectOwner(SearchObjectLevel.SPWeb, web));

            resType.Name               = name;
            resType.SourceID           = new Guid();
            resType.DisplayTemplateUrl = "~sitecollection" + displayTemplateUrl;
            SPFile file = web.GetFile(SPUtility.ConcatUrls(web.ServerRelativeUrl, displayTemplateUrl));

            //resType.DisplayProperties = ParseManagePropertyMappings(file.ListItemAllFields["Managed Property Mappings"].ToString());
            resType.Rules = new PropertyRuleCollection(new List <PropertyRule>(rules));
            typeof(ResultItemType).GetProperty("OptimizeForFrequentUse").SetValue(resType, optimizeForFrequentUse);
            return(resType);
        }
Exemple #3
0
        /// <summary>
        /// Delete a result type in the site collection
        /// </summary>
        /// <param name="site">The site</param>
        /// <param name="resultType">The result type object</param>
        public void DeleteResultType(SPSite site, ResultTypeInfo resultType)
        {
            ResultItemType resType = null;

            var searchOwner         = new SearchObjectOwner(SearchObjectLevel.SPSite, site.RootWeb);
            var resultTypeManager   = new ResultItemTypeManager(this.GetDefaultSearchServiceApplication(site));
            var existingResultTypes = resultTypeManager.GetResultItemTypes(searchOwner, true);

            // Get the existing result type
            resType = existingResultTypes.FirstOrDefault(r => r.Name.Equals(resultType.Name));

            if (resType != null)
            {
                resultTypeManager.DeleteResultItemType(resType);
            }
        }
Exemple #4
0
        /// <summary>
        /// Ensure a Result Type in a site collection
        /// </summary>
        /// <param name="site">The site collection</param>
        /// <param name="resultType">The result type info object</param>
        /// <returns>The result type item</returns>
        public ResultItemType EnsureResultType(SPSite site, ResultTypeInfo resultType)
        {
            var searchOwner  = new SearchObjectOwner(SearchObjectLevel.SPSite, site.RootWeb);
            var resultSource = this.GetResultSourceByName(site, resultType.ResultSource.Name, resultType.ResultSource.Level);

            var resultTypeManager   = new ResultItemTypeManager(this.GetDefaultSearchServiceApplication(site));
            var existingResultTypes = resultTypeManager.GetResultItemTypes(searchOwner, true);

            // Get the existing result type
            var resType = existingResultTypes.FirstOrDefault(r => r.Name.Equals(resultType.Name));

            if (resType == null)
            {
                resType          = new ResultItemType(searchOwner);
                resType.Name     = resultType.Name;
                resType.SourceID = resultSource.Id;

                resType.DisplayTemplateUrl = resultType.DisplayTemplate.ItemTemplateTokenizedPath;
                var properties = resultType.DisplayProperties.Select(t => t.Name).ToArray();
                resType.DisplayProperties = string.Join(",", properties);
                resType.RulePriority      = resultType.Priority;

                // Create rules
                var rules =
                    resultType.Rules.Select(
                        this.CreateCustomPropertyRule)
                    .ToList();
                resType.Rules = new PropertyRuleCollection(rules);

                typeof(ResultItemType).GetProperty("OptimizeForFrequentUse")
                .SetValue(resType, resultType.OptimizeForFrequenUse);

                // Add the result type
                resultTypeManager.AddResultItemType(resType);
            }

            return(resType);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://portal.spdev16.com/one-stop-shop"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPServiceContext serviceContext = SPServiceContext.GetContext(site);

                    var searchApplicationProxy = (SearchServiceApplicationProxy)serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy));
                    //var owner = new SearchObjectOwner(SearchObjectLevel.SPSite, web);
                    var owner = new SearchObjectOwner(SearchObjectLevel.SPWeb, web);

                    ICollection <ResultItemType> itemTypes = searchApplicationProxy.GetResultItemTypes(null, null, owner, true);

                    ResultItemType item = CreateResultType(web, "Internal Resource - Deployed", "/_catalogs/masterpage/Display Templates/Search/Item_InternalResource.js",
                                                           new PropertyRule[] {
                        CustomPropertyRule("ContentTypeId", PropertyRuleOperator.DefaultOperator.Contains, new string[] { "41E5CAB13DEA48B8A69A7A47EA4F4EE4" })
                    }, false);

                    searchApplicationProxy.AddResultItemType(item);
                }
            }
        }
        /// <summary>
        /// Ensure search Result Type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ResultItemType EnsureResultType(ResultTypeDTO type)
        {
            var resultTypesManager = new ResultItemTypeManager(_searchProxy);
            var resultType         = resultTypesManager.GetResultItemTypes(_searchOwner, true).FirstOrDefault(rt => rt.Name.Equals(type.Name, StringComparison.OrdinalIgnoreCase));

            if (resultType != null)
            {
                return(UpdateResultType(resultType.ID, type));
            }

            resultType = new ResultItemType(_searchOwner)
            {
                Name = type.Name,
                DisplayTemplateUrl = type.DisplayTemplateUrl,
                RulePriority       = type.Priority
            };

            if (!string.IsNullOrEmpty(type.ResultSource))
            {
                var source = GetResultsSource(type.ResultSource);
                resultType.SourceID = source.Id;
            }

            var rules = new PropertyRuleCollection();

            foreach (var builtInRule in type.BuiltInRules)
            {
                rules.Add(GetBuiltInPropertyRule(builtInRule));
            }
            foreach (var rule in type.CustomRules)
            {
                rules.Add(CreatePropertyRule(rule.ManagedPropertyName, rule.Operator, rule.Values));
            }
            resultType.Rules = rules;

            return(resultTypesManager.AddResultItemType(resultType));
        }
Exemple #7
0
        /// <summary>
        /// Ensure a Result Type in a site collection
        /// </summary>
        /// <param name="site">The site collection</param>
        /// <param name="resultType">The result type info object</param>
        /// <returns>The result type item</returns>
        public ResultItemType EnsureResultType(SPSite site, ResultTypeInfo resultType)
        {
            var searchOwner = new SearchObjectOwner(SearchObjectLevel.SPSite, site.RootWeb);
            var resultSource = this.GetResultSourceByName(site, resultType.ResultSource.Name, resultType.ResultSource.Level);

            var resultTypeManager = new ResultItemTypeManager(this.GetDefaultSearchServiceApplication(site));
            var existingResultTypes = resultTypeManager.GetResultItemTypes(searchOwner, true);

            // Get the existing result type
            var resType = existingResultTypes.FirstOrDefault(r => r.Name.Equals(resultType.Name));

            if (resType == null)
            {
                resType = new ResultItemType(searchOwner);
                resType.Name = resultType.Name;
                resType.SourceID = resultSource.Id;

                resType.DisplayTemplateUrl = resultType.DisplayTemplate.ItemTemplateTokenizedPath;
                var properties = resultType.DisplayProperties.Select(t => t.Name).ToArray();
                resType.DisplayProperties = string.Join(",", properties);
                resType.RulePriority = resultType.Priority;

                // Create rules
                var rules = 
                    resultType.Rules.Select(
                        this.CreateCustomPropertyRule)
                        .ToList();
                resType.Rules = new PropertyRuleCollection(rules);

                typeof(ResultItemType).GetProperty("OptimizeForFrequentUse")
                    .SetValue(resType, resultType.OptimizeForFrequenUse);

                // Add the result type
                resultTypeManager.AddResultItemType(resType);
            }
 
            return resType;
        }
Exemple #8
0
 /// <summary>
 /// Default constructor of ResultItem control
 /// </summary>
 /// <param name="index">Index of control in collection of ResultItem controls under Result</param>
 /// <param name="type">Type of template the ResultItem control represents</param>
 /// <param name="dataItem">Data from search query</param>
 public ResultItem(int index, ResultItemType type, object dataItem)
 {
     this.itemType  = type;
     this.itemIndex = itemIndex;
     this.dataItem  = dataItem;
 }
 public ResultItemViewModel(string displayText, EntityBase referencedEntity, ResultItemType itemType)
 {
     _displayText      = displayText;
     _referencedEntity = referencedEntity;
     _itemType         = itemType;
 }
        private void CreateControlHierarchy(bool dataBind)
        {
            Service.GoogleSearchResult result = null;

            // Result items
            items = new ArrayList();

            int count = 0;

            if (dataBind == true)
            {
                if (DataSource == null)
                {
                    return;
                }
                result     = (Service.GoogleSearchResult)DataSource;
                Query      = result.searchQuery;
                StartIndex = result.startIndex - 1;

                // set ViewState values for read-only props
                ViewState["TotalResultsCount"] =
                    result.estimatedTotalResultsCount;
                ViewState["EndIndex"] = result.endIndex - 1;

                count = result.resultElements.Length;
            }
            else
            {
                object temp = ViewState["ResultItemCount"];
                if (temp != null)
                {
                    count = (int)temp;
                }
            }

            if (HeaderTemplate != null)
            {
                ResultItem headerItem = CreateResultItem(-1,
                                                         ResultItemType.Header, false, null);
                items.Add(headerItem);
            }

            ResultItem statusItem = CreateResultItem(-1, ResultItemType.Status,
                                                     dataBind, result);

            items.Add(statusItem);

            // loop through and create ResultItem controls for each of the
            // result elements from the Google web service result
            ResultItemType itemType = ResultItemType.Item;

            for (int i = 0; i < count; i++)
            {
                if (separatorTemplate != null)
                {
                    ResultItem separator =
                        CreateResultItem(-1, ResultItemType.Separator, false, null);
                    items.Add(separator);
                }

                Service.ResultElement resultElem = null;
                if (dataBind == true)
                {
                    resultElem = result.resultElements[i];
                }

                ResultItem item = CreateResultItem(i, itemType, dataBind,
                                                   resultElem);
                items.Add(item);

                // swap between item and alternatingitem types
                if (itemType == ResultItemType.Item)
                {
                    itemType = ResultItemType.AlternatingItem;
                }
                else
                {
                    itemType = ResultItemType.Item;
                }
            }

            // display pager if allowed by user and if results
            // are greater than a page in length
            if (DisplayPager == true && TotalResultsCount > PageSize)
            {
                ResultItem pager = CreatePagerResultItem(dataBind, result);
                items.Add(pager);
            }

            if (FooterTemplate != null)
            {
                ResultItem footer = CreateResultItem(-1, ResultItemType.Footer,
                                                     false, null);
                items.Add(footer);
            }
            if (dataBind)
            {
                ViewState["ResultItemCount"] = count;
            }
        }
        private ResultItem CreateResultItem(int index, ResultItemType
                                            itemType, bool dataBind, object dataItem)
        {
            ITemplate selectedTemplate;

            switch (itemType)
            {
            case ResultItemType.Header:
                selectedTemplate = HeaderTemplate;
                break;

            case ResultItemType.Status:
                if (StatusTemplate == null)
                {
                    // if no StatusTemplate, pick up the default
                    // template ResultStatusTemplate
                    selectedTemplate = new ResultStatusTemplate();
                }
                else
                {
                    selectedTemplate = StatusTemplate;
                }
                break;

            case ResultItemType.Item:
                if (ItemTemplate == null)
                {
                    // if no ItemTemplate, pick up the default
                    // template ResultItemTemplate
                    selectedTemplate = new ResultItemTemplate();
                }
                else
                {
                    selectedTemplate = ItemTemplate;
                }
                break;

            case ResultItemType.AlternatingItem:
                selectedTemplate = AlternatingItemTemplate;
                if (selectedTemplate == null)
                {
                    // if no AlternatingItemTemplate, switch to Item type
                    // and pick up ItemTemplate
                    itemType         = ResultItemType.Item;
                    selectedTemplate = ItemTemplate;
                    if (selectedTemplate == null)
                    {
                        // if that doesnt work, pick up the default
                        // template ResultItemTemplate
                        selectedTemplate = new ResultItemTemplate();
                    }
                }
                break;

            case ResultItemType.Separator:
                selectedTemplate = SeparatorTemplate;
                break;

            case ResultItemType.Footer:
                selectedTemplate = FooterTemplate;
                break;

            default:
                selectedTemplate = null;
                break;
            }

            ResultItem item = new ResultItem(index, itemType, dataItem);

            if (selectedTemplate != null)
            {
                selectedTemplate.InstantiateIn(item);
            }

            OnItemCreated(new ResultItemEventArgs(item));
            Controls.Add(item);

            if (dataBind)
            {
                item.DataBind();
                OnItemDataBound(new ResultItemEventArgs(item));
            }

            return(item);
        }