+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / index search for event

index search for event

4 posts, 0 answered
  1. Stephen
    Stephen avatar
    70 posts
    Registered:
    09 Jun 2009
    10 Jan 2011
    Link to this post
    I created an index search for events based on the post, but I got an error when I setup index for event in admin section. Can  you help me out? Thanks a lot.

    The given key was not present in the dictionary.
    Description:
    An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
    Source Error:
    Line 90:         public void Initialize(System.Collections.Generic.IDictionary<string, string> settings)
    Line 91:         {
    Line 92:             eventsPageUrl = settings["ProductPageUrl"];
    Line 93:             settings.TryGetValue("EventIndexProvider", out productsProvider);
    Line 94:             if (String.IsNullOrEmpty(eventsPageUrl))

    My EventSettingsControl
        public class EventSettingsControl : CompositeControl, ISettingsControl
        {
            #region Properties
            /// <summary>
            /// Gets or sets the Control Template path
            /// </summary>
            public string ControlTemplatePath
            {
                get
                {
                    object o = ViewState["ControlTemplatePath"];
                    if (o == null)
                        return "~/Sitefinity/Admin/ControlTemplates/Events/CustomIndexSettingsControl.ascx";
                    return (string)o;
                }
                set
                {
                    ViewState["ControlTemplatePath"] = value;
                }
            }
            public ITemplate ControlTemplate
            {
                get
                {
                    if (controlTemplate == null)
                        controlTemplate = ControlUtils.GetTemplate<DefaultTemplate>(ControlTemplatePath);
                    return controlTemplate;
                }
                set
                {
                    controlTemplate = value;
                }
            }
            public string ProviderName
            {
                get
                {
                    object o = ViewState["ProviderName"];
                    if (o == null)
                        return String.Empty;
                    return (string)o;
                }
                set
                {
                    ViewState["ProviderName"] = value;
                }
            }
            public string SingleProductUrl
            {
                get
                {
                    if (ctrlContainer.SingleProductUrl != null)
                        return ctrlContainer.SingleProductUrl.Text;
                    return string.Empty;
                }
                set
                {
                    ctrlContainer.SingleProductUrl.Text = value;
                }
            }
            #endregion
            #region Inherited Methods
            public override void RenderBeginTag(HtmlTextWriter writer)
            {
            }
           
            public override void RenderEndTag(HtmlTextWriter writer)
            {
            }
          
            protected override void CreateChildControls()
            {
                ctrlContainer = new ControlContainer(this);
                ControlTemplate.InstantiateIn(ctrlContainer);
                properties = TypeDescriptor.GetProperties(this);
                PropertyDescriptor desc = properties.Find("SingleProductUrl", false);
                editorDialog = new PropertyEditorDialog();
                editorDialog.TypeContainer = this;
                editorDialog.PropertyChanged += editorDialog_PropertyChanged;
                Controls.Add(editorDialog);
                string[] provNames = null;
                int count = ConfigHelper.Handler.GenericContentProviders.Count;
                if (count > 1)
                {
                    int i = 0;
                    provNames = new string[count];
                    foreach (GenericContentElement element in ConfigHelper.Handler.GenericContentProviders)
                    {
                        GlobalPermission perm = new GlobalPermission((GlobalPermissions)EventsManager.SecurityRoots[element.ProviderName], CrudRights.View);
                        if (perm.CheckDemand())
                        {
                            provNames[i++] = element.ProviderName;
                        }
                    }
                }
                ListControl list = ctrlContainer.ProviderName;
                if (provNames != null)
                {
                    foreach (string name in provNames)
                    {
                        if (!String.IsNullOrEmpty(name))
                        {
                            ListItem item = new ListItem(name.Replace('_', ' '), name);
                            list.Items.Add(item);
                        }
                    }
                }
                ctrlContainer.ProviderNameLi.Visible = (list.Items.Count > 1);
                ctrlContainer.SelectProductUrl.CommandName = "Telerik.Cms.Web.UI.PageIndexUrlWebEditor, Telerik.Cms";
                ctrlContainer.SelectProductUrl.CommandArgument = desc.Name;
                ctrlContainer.SelectProductUrl.Command += SelectSingleProductUrl_Command;
                ctrlContainer.ProviderName.SelectedIndexChanged += ProviderName_SelectedIndexChanged;
                if (settings != null && settings.Count > 0)
                {
                    ctrlContainer.ProviderName.SelectedValue = ProviderName = settings["EventIndexProvider"];
                    ctrlContainer.SingleProductUrl.Text = settings["ProductPageUrl"];
                }
                Controls.Add(ctrlContainer);
            }
            void ProviderName_SelectedIndexChanged(object sender, EventArgs e)
            {
                ProviderName = ((ListControl)sender).SelectedValue;
            }
            void SelectSingleProductUrl_Command(object sender, CommandEventArgs e)
            {
                object data;
                string name = (string)e.CommandArgument;
                PropertyDescriptor desc = properties.Find(name, false);
                data = desc.Converter.ConvertToInvariantString(this);
                editorDialog.Show(name, e.CommandName, data, this);
            }
            void editorDialog_PropertyChanged(object source, PropertyValueChangedEventArgs e)
            {
                string[] resultValue = ((string)e.PropertyValue).Split(';');
                SetProperty(this, properties, e.PropertyName, resultValue[1]);
            }
            private void SetProperty(object component, PropertyDescriptorCollection _properties, string name, object value)
            {
                PropertyDescriptor desc = _properties.Find(name, false);
                desc.SetValue(component, value);
            }
           
            public void InitSettings(IDictionary<string, string> _settings)
            {
                settings = _settings;
            }

            public IDictionary<string, string> GetSettings()
            {
                settings = new Dictionary<string, string>();
                settings["EventIndexProvider"] = ProviderName = ctrlContainer.ProviderName.SelectedValue;
                settings["ProductPageUrl"] = ctrlContainer.SingleProductUrl.Text;
                return settings;
            }
            #endregion
            #region Private Fields
            private PropertyDescriptorCollection properties;
            private ITemplate controlTemplate;
            private ControlContainer ctrlContainer;
            private IDictionary<string, string> settings;
            private PropertyEditorDialog editorDialog;
            #endregion
            #region DefaultTemplate
            /// <summary>
            /// The default template class
            /// </summary>
            protected class DefaultTemplate : ITemplate
            {
                public void InstantiateIn(Control container)
                {
                }
            }
            #endregion
            #region Container
            /// <summary>
            /// The control container class
            /// </summary>
            protected class ControlContainer : GenericContainer<EventSettingsControl>
            {
                public ControlContainer(EventSettingsControl owner)
                    : base(owner)
                {
                }
                public ListControl ProviderName
                {
                    get
                    {
                        if (providerName == null)
                            providerName = FindRequiredControl<ListControl>("Events");
                        return providerName;
                    }
                }
                public IEditableTextControl SingleProductUrl
                {
                    get
                    {
                        if (singleProductUrl == null)
                            singleProductUrl = (IEditableTextControl)FindControl(typeof(IEditableTextControl), "singleProductUrl", true);
                        return singleProductUrl;
                    }
                }
                public IButtonControl SelectProductUrl
                {
                    get
                    {
                        if (selectProductUrl == null)
                            selectProductUrl = (IButtonControl)FindControl(typeof(IButtonControl), "selectSingleProductUrl", true);
                        return selectProductUrl;
                    }
                }
                public HtmlGenericControl ProviderNameLi
                {
                    get
                    {
                        if (providerNameLi == null)
                            providerNameLi = FindRequiredControl<HtmlGenericControl>("providerNameLi");
                        return providerNameLi;
                    }
                }
                private HtmlGenericControl providerNameLi;
                private IButtonControl selectProductUrl;
                private ListControl providerName;
                private IEditableTextControl singleProductUrl;
            }
            #endregion
        }
    }

    EventProvider
    public class EventIndexProvider : IIndexingServiceClient
        {
            public string Name
            {
                get
                {
                    return "EventIndexProvider";
                }
            }
     
            public string Description
            {
                get
                {
                    return "Provides indexing for events";
                }
            }
     
            protected string[] MetaFields
            {
                get
                {
                    return new string[]{
                        "Title"
                    };
                }
            }
     
            public IIndexerInfo[] GetContentToIndex()
            {
                List<IIndexerInfo> list = new List<IIndexerInfo>();
     
                // get current events
                EventsManager mgr = new EventsManager("Events");
                IMetaSearchInfo[] filters = new IMetaSearchInfo[1];
     
                //filters[0] = new MetaSearchInfo(MetaValueTypes.DateTime, "Expiration_Date", DateTime.Now, SearchCondition.GreaterOrEqual);
                filters[0] = new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", DateTime.Now, SearchCondition.LessOrEqual);
                IList events = mgr.Content.GetContent("Event_Start DESC", filters);
     
                foreach (IContent ev in events)
                {
                    Hashtable metaFields = new Hashtable();
                    foreach (string key in MetaFields)
                    {
                        metaFields.Add(key, "");
                    }
     
                    metaFields["Title"] = ev.GetMetaData("Title");
     
                    list.Add(
                        new EventIndexerInfo(
                        string.Format(eventsPageUrl.Replace(".aspx","") + "{0}.aspx", ev.Url),
                        metaFields,
                        ev.Content.ToString())
                        );
                }
     
                return list.ToArray();
            }
     
            public string[] GetUrlsToIndex()
            {
                return new string[0];
            }
     
            public event EventHandler<IndexEventArgs> Index;
     
            public void Initialize(System.Collections.Generic.IDictionary<string, string> settings)
            {
                eventsPageUrl = settings["ProductPageUrl"];
                settings.TryGetValue("EventIndexProvider", out productsProvider);
                if (String.IsNullOrEmpty(eventsPageUrl))
                    throw new ArgumentException(String.Format("CannotCreateAbsoluteUri"));
            }
     
            private string productsProvider;
            private string eventsPageUrl;
        }

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Jan 2011
    Link to this post
    Hello Stephen,

    The error says that in your settings you do not have this key  ["ProductPageUrl"];
    Could you verify the items in IDictionary<string, string> settings before you try get this key? You should also have IndexViewControl

    protected override void CreateChildControls()
           {
               this.ResultsPageUrlText.Text = this.GetValue("ProductPageUrl", this.settings["ProductPageUrl"]);
               this.Controls.Add(this.Container);
           }
     
           private string GetValue(string key, string value)
           {
               switch (key)
               {
                   case "ProductPageUrl":
                       return String.IsNullOrEmpty(value) ? "NOT SET" : value;
                   default:
                       return "";
               }
           }

    Please check whether the ProductPageUrl is set inside EventSettingsControl .

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Stephen
    Stephen avatar
    70 posts
    Registered:
    09 Jun 2009
    11 Jan 2011
    Link to this post
    Thanks Ivan. I have the IndexViewControl, which also generates the same error.

    This is how I set the key in EventsSettingControl
    public IDictionary<string, string> GetSettings()
            {
                settings = new Dictionary<string, string>();
                settings["EventIndexProvider"] = ProviderName = ctrlContainer.ProviderName.SelectedValue;
                settings["ProductPageUrl"] = ctrlContainer.SingleProductUrl.Text;
                return settings;
            }

    The only difference between my index provider and the product search provider in your post is that my index provider is inherited from IIndexingServiceClient, but the product search provider is inherited from ContentIndexProvider. Does it caused any issues? Thanks.

    My Provider:
    public class EventIndexProvider : IIndexingServiceClient
      {
           public void Initialize(System.Collections.Generic.IDictionary<string, string> settings)
            {
                eventsPageUrl = settings["ProductPageUrl"];
                settings.TryGetValue("EventIndexProvider", out productsProvider);
                if (String.IsNullOrEmpty(eventsPageUrl))
                    throw new ArgumentException(String.Format("CannotCreateAbsoluteUri"));
            }
     
    }

    ProductSearch Provider
    public class ProductsIndexProvider : ContentIndexProvider
    {
           public override void Initialize(IDictionary<string, string> settings)
            {
                productsPageUrl = settings["ProductPageUrl"];
                settings.TryGetValue("ProductsProvider", out productsProvider);
     
                if (String.IsNullOrEmpty(productsPageUrl))
                    throw new ArgumentException(String.Format("CannotCreateAbsoluteUri"));
                base.Initialize(settings);
            }
    }

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Jan 2011
    Link to this post
    Hi Stephen,

    Please send me the provider and the settings control you use and I will check the code on a local project.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered