| John's profileJohn West Blogs about Si...PhotosBlogLists | Help |
|
9/15/2009 Use the Sitecore 6.1 Rules Engine to Control Item NamesUpdate: Shared source project created: http://trac.sitecore.net/ItemNamingRules. With Sitecore CMS 6.1, you can use the rules engine to control item names. For example, you may want to enforce character limits in the names of items that correspond to URLs. For more information about the rules engine, see the the Rules Engine Cookbook on the Sitecore Developer Network. You may also want to read my previous post about the rules engine and conditional rendering. Sitecore supports at least five techniques to control item names:
You can continue to use settings, events, pipelines, and validation to control item names. But with 6.1, you can use the rules engine as well. A rule consists of one or more conditions and one or more actions. When Sitecore evaluates a rule, if the conditions specified in that rule evaluate to true, then Sitecore invokes the actions specified in that rule. For the condition part of this rule, users might want to apply the rule to one or more specific items, to all items based on a data template, to an item and its descendants, to the descendants of an item, to items matching a query, or to some other collection of items. I assume that the default conditions that ship with the product meet the most common requirements. Two conditions that might be helpful when determining whether or not to rename an item: whether the item has layout details for the default device, and whether the item has layout details for any device: [See http://trac.sitecore.net/ItemNamingRules for code.] For instructions to insert the condition definition items under the /Sitecore/System/Settings/Rules/Common/Conditions item using the System/Rules/Condition data template, or for instructions to use either of these conditions in a rule, see the Rules Engine Cookbook. Some strings for cutting and pasting:
Name: When the item has layout details for the default device” using the System/Rules/Condition data template Text: when the item has layout details for any device Type: Sitecore.Sharedsource.Rules.Conditions.HasLayoutDetailsForDefaultDevice, Assembly
Name: When the item has layout details for any device Text: when the item has layout details for any device Type: Sitecore.Sharedsource.Rules.Conditions.HasLayoutDetailsForAnyDevice,assembly
Regarding the action part of the rule, there would be numerous parameters to specify for a single action. The solution should not force the user to specify parameters they don’t use. But because actions are not aware of each other, the user might have to specify the same parameters to multiple actions. More importantly, the user has to understand the impact of ordering actions. For example, it doesn’t make sense to ensure a minimum name length before removing invalid characters. I thought about merging certain actions and hard-coding certain parameters, but I generally like a flexible approach. Then I started prototyping, and realized that the flexible approach was more work for both me and any user. So I merged some of the actions (the strong words indicate parameters):
It’s honestly a coincidence that this simplification eliminates all of the duplicate parameters that I would otherwise have to pass to additional actions. I also sorted the actions so that the user interface displays them in the order in which the user should add them to the rule. I started out with a base class for actions that rename items: [See http://trac.sitecore.net/ItemNamingRules for code.] Then I created classes for each action: [See http://trac.sitecore.net/ItemNamingRules for code.] For instructions to insert the action definition items under the /Sitecore/System/Settings/Rules/Common/actions item using the System/Rules/Action data template, or for instructions to use any of these actions in a rule, see the Rules Engine Cookbook. Some strings for cutting and pasting:
Name: Replace Invalid Characters in Item Name Text: replace characters in the item name that do not match the regular expression [MatchPattern,Text,,pattern] with [ReplaceWith,Text,,this character sequence] Type: Sitecore.Sharedsource.Rules.Actions.Naming.ReplaceInvalidCharacters, Assembly
Name: Ensure Minimum Length of Item Name Text: ensure a minimum name length by appending characters from [DefaultName,Text,,index] Type: Sitecore.Sharedsource.Rules.Actions.Naming.EnsureMinimumLength, Assembly
Name: Ensure Item Name is Unique Text: ensure item name is unique and does not exceed [MaxLength,int,,maximum length] characters Type: Sitecore.Sharedsource.Rules.Actions.Naming.EnsureUnique, Assembly
Name: Lowercase Item Name Text: lowercase letters Type: Sitecore.Sharedsource.Rules.Actions.Naming.Lowercase, Assembly
Finally, insert the the rule definition item under the /Sitecore/System/Settings/Rules/Item Saved/Rules item using the System/Rules/Rule data template. For instructions to insert a rule, see the Rules Engine Cookbook. Before entering any parameters, my rule looks like this: And after entering parameters: Now, when I save any item that has layout details for any device, whether I save that item through the UI or through an API call, Sitecore replaces invalid characters with underscores, merges sequences of underscores into a single underscore, trims underscores from the beginning and the end of the item name, appends to the item name to ensure at least seven characters, appends a timestamp to the item name if required to make it unique among its siblings, and ensures that the item name does not exceed 35 characters. Warning: Like almost any customization, this could have dangerous repercussions, especially if configured incorrectly (for example, by renaming any item in the wrong branch, or in the Core database). Additionally, I didn’t significantly test this before posting, and there are definitely still some issues to think about. For example, you probably don’t want to rename the home item, you don’t want these rules to apply to the __Standard values of data templates (even though they may contain layout details), etc. But enough people ask about this topic that I thought it was time to describe this approach. After some refinement, I will try to make this a shared source project. 9/11/2009 SDN Poll: Do You Know of Sitecore Solutions that Embed Renderings in Rich Text Editor Fields?With some customization, Sitecore CMS users can embed renderings in the content of Rich Text Editor (RTE) fields. For example, a user editing an RTE field can insert a snippet that represents a video rendering, and use the properties of that rendering to select a video and enter any other parameters much like they could do in the Developer Center. The customization uses ASP.NET APIs to process renderings in RTE fields while rendering pages. Instead of using this approach, if acceptable to the users, I would add a field to the data template to allow the user to select one or more videos, and configure renderings to always embedding any selected videos in the same places on the page. I realize that this alternative solution does not account for all cases. But the RTE approach never seemed like a good idea to me for at least two reasons:
In Sitecore 6, the Design Pane of the Page Editor gives non-technical users point-and-click control of where renderings appear on the page. In 6.1, conditional rendering and parameters templates could further reduce the need for the RTE customization in some solutions. To get an idea of if, how, and why people use this feature, or what alternatives they use to avoid it, I created a poll on the Sitecore Developer Network: http://sdn.sitecore.net/SDN5/Forum/ShowPost.aspx?PostID=20973 Please take the time to make a selection. Your feedback on this issue is important to me. Thanks & regards, -John 9/1/2009 Windows 7 Tips, Tricks, and Annoyances for Sitecore DevelopersAfter about a week of light use, I find myself relatively happy with Windows 7. Some of the changes are helpful, others have little impact, while few make me less productive. Not much of a post at the moment, but it's only been a week, and I've probably already forgotten the initial annoyances. I will try to update this page to help other developers make the switch. When installing, I intended to update my post about configuring a Sitecore developer workstation. But the installation was so much like Windows Vista or 2008 that this didn't seem to be necessary. Probably the most important thing that I noticed is that by default, IIS application pools don't run as NETWORK SERVICE. It appears that Windows creates a transitory user named after the application pool. But these users don't appear in the list of users, apparently making it impossible to apply NTFS permissions for these accounts. I am sure there is a way to set permissions, but I couldn't find it. My workaround is to change the owner of the application pool to NETWORK SERVICE, though I assume this defeats some kind of stability, reliability, or security advantage to the transitory users. Update: One of my Most Valuable Colleagues did some research on this subject, primarily starting from http://learn.iis.net/page.aspx/624/application-pool-identities/. Apparently Windows 2008 Service Pack 2 introduced the “Application Pool Identities” security feature, which uses the “Virtual Accounts” feature to allow you to configure unique application pool owners without actually managing any accounts. These users don’t appear in the UI, so if you want to set permissions for the user, you have to type something like "IIS AppPool\DefaultAppPool" into the security dialog, where what appears as the machine/domain doesn’t mean much to me, and what appears as the username is actually the name of the application pool. Update again: one potential advantage of application pool identities: it should be easier to determine the correct w3wp.exe process to attach in the Visual Studio debugger. I use the QuickLaunch toolbar extensively. This toolbar doesn't appear in Windows 7, so you have to create it yourself. No big deal there, but this toolbar had the handy "Show the Desktop" icon, which minimizes all windows so that you can see the icons on the desktop. It took me a while to find the equivalent feature in Windows 7, but it's really easy - just click the rectangle at the far-right corner of the task bar (or press Windows-D). Update: It is really surprising how slow and unreliable the “Show Desktop” feature has become in Windows 7. For me, as long as the hard disk is thrashing due to application activity, nothing minimizes. It makes me very nervous when my operating cannot reliably perform such a simple operation. Update again: The Show Desktop feature in Windows 7 is absolutely terrible. You click it, it ignores you, you ALT-TAB to an application, you start typing, and THEN it minimizes that application. And this is not even when the disk is thrashing or the icon is the spinning wheel. I have no explanation, but I really want one from Microsoft. Update: I just rebooted, and my “QuickLaunch” toolbar disappeared. I was able to get it back somehow, but it had lost my preferences. I am starting to seriously question whether Windows 7 is any more stable than early betas of Vista, or if it’s just a new UI for the broken bits. I click on things and they just don’t respond. I often have to do the same thing several times to actually get that thing done. It’s like the UI is not aware of the mouse clicking as long as the disk is thrashing (this is a brand-new, well-equipped machine). And the cursor is not even the spinning wheel when this occurs. Maybe this is another new security feature – if you can’t use the computer, you can’t compromise its security? Update: I couldn’t get Microsoft File Transfer manager working on Windows 7. There is probably some browser security setting that would allow it, but no information from Microsoft. Yes, I did try the MSI, and no, it didn’t help. So I’m back in Windows 2008 to download from MSDN. Sigh… Update: My Windows 7 x64 C:\Windows folder is already over 16GB. That seems ridiculous for a consumer operating system. The same directory on my Vista partition is about 12GB, Windows 2008 is about the same as Windows 7. XP is under 7GB. Other than the language bar issues described below (which I believe descend from XP), for me, the most annoying thing so far is the changes to VPN. It's as if the entire "Manage Network Connections" area of the Network control panel is simply gone, replaced with a dumbed-down interface that might make some sense to end-users, but provides little value for me. I cannot find a way to add an icon to connect to a VPN to my “QuickLaunch” toolbar (or the Startup folder, as some people do to connect to the VPN automatically when they log in). Instead of clicking twice as I had in the past (the VPN icon on the QuickLaunch toolbar, and then the Connect button), I have to click three times - first the network icon in the notification area, then the VPN entry to show the Connect button, and finally the Connect button. Not a big deal, but I don't understand the reason for this change. Update: I installed all updates available through Windows Update, and Windows did not prompt me to reboot. But the Shut Down button on the Start menu indicates that I must reboot to install additional updates. This seems like a bug. Update again: I used that button to reboot and there was no indication that Windows actually installed any updates. The button is back to normal now. I really don't understand the default taskbar. I use a large monitor and I have good eyesight, I use the same applications every day, and I don't have hundreds of icons to differentiate, despite the fact that most softwares try to add useless icons everywhere they can (Adobe Reader? Give me a break, who opens that using an icon? And why does it need a startup program? For their terrible reader malware, Adobe doesn’t get a link from my blog, even though I have to use it because other PDF readers can’t open some files). So I don't need huge icons. Here's my taskbar configuration: This isn't specific to Windows 7, but Windows 7 maintains many of the annoyances that Microsoft introduced with Windows Vista, such as User Account Control (UAC). For example, I frequently right-click on a file and open it with an application such as Notepad++, only to find that even though I am an administrator who has used Windows since 1995, Microsoft still doesn't trust me not to fat-finger everything all the time. So I can’t save changes to the file (typically hosts), or extract the archive where I want to, etc. So I have to copy whatever's in Notepad++ to the Windows clipboard, close the application, find the icon for that application (on my "QuickLaunch" toolbar), run it as administrator, and paste in the text. I configure certain icons in the QuickLaunch toolbar (Visual Studio, Notepad++, DOS prompt, 7-Zip, etc.) to run as administrator so I don't have to remember to right-click them and run them as administrator. And I have to open Windows explorer and find the hosts file to drag into Notepad++ because for some reason the directory doesn’t appear in the Open File dialog. Maybe I could type in the path, but this is another puzzler that just leaves me scratching my head. In the words of (horeslips) Nancy Kerrigan, “Why? Why?” I also disable UAC to the extent possible so I don’t have to tell Microsoft “Yes, I really did press that button” all the time. I have been sure the last several thousand times that I clicked that icon. Maybe this is dangerous, but I've been using computers for a very long time and have never experienced any malware. UAC couldn't prevent social engineering tactics anyway, and I think we can all agree that those are the primary attack vectors. Some other annoyances seem to go further back. For example, Windows 7 sometimes adds “ – Shortcut” to the name of shortcuts. How does this help anyone, and why isn’t the icon overlay enough? It just looks dirty. Update: I am in Denmark this week, using a Danish keyboard. Microsoft still hasn’t fixed any of the issues with the language bar. It’s as if they expect that there are two keyboards connected to the machine, and it keeps switching randomly between their layouts. It is incredibly frustrating to not be able to type on a computer without several mouse clicks to reset the keyboard layout. Microsoft, you need to accommodate the fact that I use different keyboards at *different* times, but I only use *one keyboard at a time*, regardless of the number of open applications. I would assume that is the most common use case. So when I get to the office I have to log in (not sure which keyboard layout to use when entering special characters in my password), reset the default keyboard, log out, and log back in. And do the same when I go home at night, to use the laptop keyboard. And the same the next morning… Update: I think we may need two versions of Windows, one for people who know how to use computers, and one for people that are learning how to use computers. Microsoft seems to be targeting the learners with Windows 7, where most of their customers are in the other group. I think this is the wrong direction, and I am concerned that the next server version of Windows will have to follow Windows 7. Well, feel free to comment about where I'm wrong, post suggestions to address my annoyances, or add your own suggestions for Sitecore developers transitioning to Windows 7. |
|
|