/// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event to initialize the page.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            // Check CM
            if (!SPSConfigurationManager.Check())
            {
                throw new ApplicationException("This application requires SPSProfessional Configuration Manager.");
            }

            // Get the list
            _listGuid = SPHttpUtility.UrlKeyValueDecode(Page.Request.QueryString["List"]);

            // Check the list
            if (string.IsNullOrEmpty(_listGuid))
            {
                throw new ArgumentException("Invalid List parameter");
            }

            // Clean
            _listGuid = SPHttpUtility.UrlKeyValueDecode(_listGuid);

            // Get the list
            try
            {
                var listID = new Guid(_listGuid);
                _list = SPContext.Current.Web.Lists[listID];
            }
            catch (IndexOutOfRangeException)
            {
                throw new KeyNotFoundException("List not found");
            }
        }
Esempio n. 2
0
        public override void ItemUpdated(SPItemEventProperties properties)
        {
            //TODO: Remove
            //HttpRuntime runtime = new HttpRuntime();

            /* Unfortunately properties.BeforeProperties does not get populated in this event, so if the 'category' or
             * 'key' of the config item changes (i.e. a rename), we can't identity the old item in the cache to remove.
             * However, all this means is our cache will have an extra item in which isn't used, so this is no big deal..
             */
            string category = properties.ListItem[SPSConfigurationManager.FIELD_CATEGORY] as string;
            string key      = properties.ListItem[SPSConfigurationManager.FIELD_KEY] as string;
            string cacheKey = SPSConfigurationManager.FormatKey(category, key);

            HttpRuntime.Cache.Remove(cacheKey);

            // also proactively add item to cache so first user doesn't get the hit. Note we also account for
            // any renames with use of BeforeProperties/AfterProperties..
            string value = properties.ListItem[SPSConfigurationManager.FIELD_VALUE] as string;

            if (value != null)
            {
                HttpRuntime.Cache.Insert(cacheKey, value, null, DateTime.MaxValue, Cache.NoSlidingExpiration);
            }

            base.ItemUpdated(properties);
        }
        /// <summary>
        /// Checks the in configuration manager.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static string CheckInConfigurationManager(string text)
        {
            if (!string.IsNullOrEmpty(text))
            {
                string key = text.Substring(0, 1);

                if (key == ":")
                {
                    return(SPSConfigurationManager.EnsureGetValue(CM_Category, text.Substring(1)));
                }
            }
            return(text);
        }
Esempio n. 4
0
        /// <summary>
        /// Deletes the configuration.
        /// </summary>
        public void DeleteConfiguration()
        {
            if (ListHasEventHandler())
            {
                RemoveEventHandler();
                ModifyFields(false);

                // delete values from config manager
                foreach (SPSKeyValuePair keyValuePair in _properties)
                {
                    SPSConfigurationManager.DeleteKey(_category, keyValuePair.Key);
                }
            }
        }
Esempio n. 5
0
        public override void ItemDeleted(SPItemEventProperties properties)
        {
            // delete item from cache..
            // TODO: Remove
            // HttpRuntime runtime = new HttpRuntime();

            string category = properties.BeforeProperties[SPSConfigurationManager.FIELD_CATEGORY] as string;
            string key      = properties.BeforeProperties[SPSConfigurationManager.FIELD_KEY] as string;
            string cacheKey = SPSConfigurationManager.FormatKey(category, key);

            HttpRuntime.Cache.Remove(cacheKey);

            base.ItemDeleted(properties);
        }
Esempio n. 6
0
 private void GetDataFromConfigurationManager()
 {
     _properties.Add(FLD_SITE_NAME, SPSConfigurationManager.EnsureGetValue(_category, FLD_SITE_NAME));
     _properties.Add(FLD_SITE_URL, SPSConfigurationManager.EnsureGetValue(_category, FLD_SITE_URL));
     _properties.Add(FLD_TEMPLATE, SPSConfigurationManager.EnsureGetValue(_category, FLD_TEMPLATE));
     _properties.Add(TEMPLATE_MAP, SPSConfigurationManager.EnsureGetValue(_category, TEMPLATE_MAP));
     _properties.Add(OPT_LOG_ERROR, SPSConfigurationManager.EnsureGetValue(_category, OPT_LOG_ERROR));
     _properties.Add(OPT_HIDE_TEMPLATE_FIELD, SPSConfigurationManager.EnsureGetValue(_category, OPT_HIDE_TEMPLATE_FIELD));
     _properties.Add(OPT_FORCE_DUP, SPSConfigurationManager.EnsureGetValue(_category, OPT_FORCE_DUP));
     _properties.Add(OPT_ON_QUICKLAUNCH, SPSConfigurationManager.EnsureGetValue(_category, OPT_ON_QUICKLAUNCH));
     _properties.Add(OPT_ON_TOPNAVBAR, SPSConfigurationManager.EnsureGetValue(_category, OPT_ON_TOPNAVBAR));
     _properties.Add(OPT_UNIQUE_PERMISSIONS, SPSConfigurationManager.EnsureGetValue(_category, OPT_UNIQUE_PERMISSIONS));
     _properties.Add(OPT_NEW_PERMISSIONS, SPSConfigurationManager.EnsureGetValue(_category, OPT_NEW_PERMISSIONS));
     _properties.Add(OPT_ATTACH_DELETE_SITE, SPSConfigurationManager.EnsureGetValue(_category, OPT_ATTACH_DELETE_SITE));
 }
Esempio n. 7
0
        public override void ItemAdded(SPItemEventProperties properties)
        {
            // add item to cache..
            //TODO:Remove
            //HttpRuntime runtime = new HttpRuntime();

            string category = properties.AfterProperties[SPSConfigurationManager.FIELD_CATEGORY] as string;
            string key      = properties.AfterProperties[SPSConfigurationManager.FIELD_KEY] as string;
            string cacheKey = SPSConfigurationManager.FormatKey(category, key);
            string value    = properties.AfterProperties[SPSConfigurationManager.FIELD_VALUE] as string;

            if (value != null)
            {
                HttpRuntime.Cache.Insert(cacheKey, value, null, DateTime.MaxValue, Cache.NoSlidingExpiration);
            }

            base.ItemAdded(properties);
        }
Esempio n. 8
0
        /// <summary>
        /// Saves the configuration.
        /// </summary>
        public void SaveConfiguration()
        {
            if (!ListHasEventHandler())
            {
                AddItemAddEventHandler();
                ModifyFields(true);

                if (OptAttachDelete)
                {
                    AddItemDeletingEventHandler();
                }
            }

            // save values in config manager
            foreach (SPSKeyValuePair keyValuePair in _properties)
            {
                SPSConfigurationManager.SetKey(_category, keyValuePair.Key, keyValuePair.Value, CM_UPDATE);
            }
        }