One of the most frequently and eagerly used programming constructs of the Microsoft.Net Framework is Enum. There are several interesting features that make it very compelling to use to for all kinds of dropdowns and checklists:
- The bounds factor – proper use of Enum type guarantee that the selected value will fall within the constraints of the allowed value set.
- The ability to treat Enums as flags (and compound them into flag sets) as well as a one-of selector.
- The ease of use and potentially complete separation of the “Enum value” from the underlying machine type representation that ensures the most efficient memory usage.
Surprisingly enough EPiServer as it stands right now does not have an easy facility to turn Enums into properties. To give credit where credit is due, the EPiServer framework provides a nice surrogate that mimic that behaviour to a degree. The relevant property types are:
- PropertyAppSettingsMultiple – which “creates check boxes with options that are defined in the AppSettings section in web.config. The name of the property should match the key for the app setting.”
- PropertyAppSettings – which “creates a drop down list with options that are defined in the AppSettings section in web.config. The name of the property should match the key for the app setting.”
You quickly realize though that the properties have some limitations that makes their use a bit less compelling:
- The properties are not strongly typed
- The property entry in AppSettings section has to have the name that matches the property name on the page.
- It’s rather poorly documented, Other than relating to this blog entry or Erik’s post documenting it I could not find any other examples on how to use them. (but then again, who needs docs really when we have Reflector)
- You cannot have the very same property duplicated on the page since you can only have a single property of a given name per page. So you need to have multiple entries in AppSettings that match the name of each of those properties on your pages. I know… semantics but still…
- You are working on strings rather than enums (Did i mention it’s not type safe?)
- The values in the AppSettings are stored in a somewhat DLS-y manner (consecutive options are separated from each other with the ‘|’ character, the name and the value are separated with a ‘;’, for example: <add key = "RegionId" value="First Option;Option1|Default Option;Option2|Disabled Option;Option3" /> ) and I have had on an occasion entered a string there that caused the server to crash.
- The values are not translatable, or at least I could not find how to do it and any Reflector digging rendered no results either.
Read the rest of this article »
Popularity: 5% [?]
Aparently I have written something on that note before for CMS 4 and it looks like someone still needs it as I got a request for an updated version for it a couple of days ago. So here we go:
for the most part the syntax for the call is equivalent to what is was before so go to my previous article regarding that (check out the old article for details). What I’ve added this time around is:
- the @PropertyName can be declared as ‘%’ if you want to look in all property names
- @PropertyType can be –1 if you want to look in all property types otherwise you need to specify type id (this has changed from type name before due to database schema changes)
- additionally this version of the stored proc will only look in the Master language Branch, so it will work for the single language pages and for multi-language but for language agnostic properties. (should you require the language to be variable the change is pretty simple – I can send you the updated version by email.
/****** Object: StoredProcedure [dbo].[PagedSearch] Script Date: 07/07/2009 12:18:10 ******/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PagedSearch]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[PagedSearch]
GO
CREATE Procedure PagedSearch
@Condition varchar(1024),
@PropertyName varchar(1024),
@PropertyType int,
@PageSize int,
@PageNumber int,
@Offset int
AS
BEGIN
DECLARE @RowStart int
DECLARE @RowEnd int
SET @RowStart = @PageSize * @PageNumber + @Offset;
SET @RowEnd = @RowStart + @PageSize + @Offset;
WITH PageRefs AS
(SELECT page.pkID as PageId,
ROW_NUMBER() OVER (ORDER BY pageLang.StartPublish DESC) as RowNumber
FROM tblPage page, tblProperty propValue, tblPageDefinition propDef, tblPageLanguage pageLang
WHERE page.pkID = propValue.fkPageID
AND page.fkMasterLanguageBranchID = pageLang.fkLanguageBranchID
AND page.pkID = pageLang.fkPageID
AND propValue.fkPageDefinitionID = propDef.pkID
AND (@propertyType = -1 or propDef.fkPageDefinitionTypeID = @propertyType) -- is proper type
AND propDef.Searchable = 1 -- the property is searchable
AND propValue.String like @Condition -- contains facets
AND propDef.[Name] like @PropertyName) -- property of proper name
SELECT PageId
FROM PageRefs
WHERE (RowNumber Between @RowStart and @RowEnd) or (@PageSize = 0);
END
GO
However… looking how the schema has changed over time, I am not convinced this approach is really the best one for someone who is not prepared to deal with the changes (e.g. you better be able to change the stored procedure based on the schema changes – or bribe me with pizza and beers for updates :) ).
Additionally this procedure only searches for properties that store their value in Short string field. To make it look into long string you need to Change the highlighted line to.
AND (propValue.LongString like @Condition)
or alternatively to look in both change it to:
AND ((propValue.String like @Condition) or (propValue.LongString like @Condition))
Enjoy!
Popularity: 33% [?]
Have you ever (or have your customers) created and edited a page in one language only to realize that their selected locale was wrong? Have you ever wished you could delete a master language branch of a page after creating its localized counterpart but you could only delete the newly created slave language instead? Have a customer ever requested that they could copy a whole branch and you convert it to another language so that they could then translate in-place?
Well I have… and I’m sure I will. And so did Fredrikj on the our #epicode IRC channel ;).
Basically I had the tool that would convert from one language to another, but Fredrikj requested something that would switch master language of a page from one to another. Since I’ve already had some of the work done, I’ve updated the stored procedure I’ve written some time ago and slapped a nice GUI up on it. Here’s the result:
What the tool allows you to do is perform either language conversion or master branch switching on a selected page and all of its children (if you choose so).
The stored procedure have been updated to work on CMS5 R2 (will no longer work on R1 – but if you need that functionality, comment here or give me a shout and I’ll create a compatible version for you).
A word of caution though – I take no guarantee whatsoever about its operation. Especially, if you wreck your client’s database with it. I did what I could to prevent some of the obvious problems (like switching to a non existing master or converting to an existing one) but I will not be responsible if it won’t work for you. make a database backup and experiment there before you do any changes on the real data. That said – it works for me, so I think it should also work for you.
You can download the archive containing the tool here. unzip it to your EPiServer web application folder keeping the folder structure or the plugin reference will be wrong. Include the *.aspx and the *.cs files in your project and apply the SQL file to your database (The manipulation is performed by a stored procedure located in the file).
Also if you’re performing the change in a load balanced environment, you may need to restart the other servers once you do the changes. I reset the DataFactory cache, but I am not sure it propagates through to other servers.
Popularity: 73% [?]
Immediately after you implement the VirtualPathProvider proxy from my previous post you will notice a one fairly serious lack in it. Namely all the files within that provider will be hiding behind the registration form. That is not cool for a couple of reasons…
- You may want to keep all of the files in one store – being forced to put them into a designated folder is not desired.
- You may want to make some file freely available for some time and lock it after a while, or the other way around (e.g. to allow the robots to crawl it initially). having to move them is just silly and defeats the purpose.
So how do you discriminate the files that you want locked from those that you want to be publically available, and potentially from those that you want only the logged in users to be able to get?
Specifying the EPiServer File Metadata sweetness
One of the potential solutions would be to define a special rights group and check for that group for the people that have your “registered” magic-cookie. That however introduces a bogus group, and I would rather like to avoid that. However if you look into the FileSummary.config file that’s located in your web application folder you will find a slightly mysterious content. A bit of hacking reveals that you can actually add your own metadata to the file. For example adding the access rights based on what I’ve established above would look as follows (the content you can already find in the file that comes with the public templates that-we-all-oh-so-love is skipped):
Read the rest of this article »
Popularity: 96% [?]