I’ve decided to 1-up the game from my previous post and zip something that isn’t really a real file but rather a blob in a Sitecore database. The script below is based heavily on the last post but instead of just zipping content of a flat folder traverses the Sitecore item tree and zips all files beneath the current folder.
If you have downloaded the 2.1 version of the Sitecore PowerShell Console from the Sitecore Marketplace you will actually have the script deployed on your system already.
Here’s how it looks like for your user in the Content Editor:
Last night I needed to reproduce really quickly a site structure we will be moving from another CMS and create a matching item hierarchy in my Sitecore instance… I could face an hour or so of boring clicking and copying and pasting and hoping I’ve not missed anything or… I could write a short PowerShell script to do the work for me… Guess which path I chose?
Before you use the script you should customize the script parameters:
I’m realizing time and time again that the learning curve for PowerShell can be steep without a proper guidance. While most people I talk to are very excited about the concept they become discouraged after a having some tries and not realizing its full potential. Therefore I decided it’s worth spending some time introducing some basic principles to help scripting alleviate some of the initial pains.
Sitecore is built from the grounds up with extendibility in mind. Be that plugging into any place in its internal pipelines or any aspect of its User eXperience, therefore when I’ve managed to extend it’s context menu, I expected to have no problems whatsoever doing the same to its ribbon. Mind you I was right?
Using the PowerShell Console Module it took me less than 10 minutes total to add a nice piece of functionality that I thought was missing – Publish items I have modified.
We had a situation in the company this week which required us to deliver the whole EPiServer virtual path provider file structure to the client – zipped. Easy enough? go to the EpiServer VPP directory and? well? ok? hmm? so the path provider is versioning and as a consequence the physical organization of files on the disk does not make any sense for a human trying to browse it.
Fine! So let’s create a native provider and do a copy and paste within the file manager?. hmm an exception complaining about the provider incompatibility?
Naturally, my knee-jerk reaction is – let’s do it with the PowerShell? which I recall was doing something like this in it’s previous version? The example I’ve tested and placed in the ?Samples? tab was:
Most of this post is also based on the Microsoft’s Windows PowerShell Quick Reference however despite the sharing scripting runtimes the nature of the both shells differ considerably as described in the previous post: PowerShell for EPiServer - cheat sheet - Part 1. In all cases where it made sense I’ve converted the samples to establish them in EPiServer scenarios.
How to Write Conditional Statements
To write an If statement use code similar to this:
It’s been a while since I had a chance to do any coding… turns out leading a development division tends to not have much to do with development… who knew?!
But I’ve finally got a moment to sit down and refresh the EPiServer PowerShell console and make it compatible with both CMS versions 5 & 6. You could technically use it before on CMS 6 but the looks of it was broken. (previous version available here)
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:
Last week or so ago a couple of friends in another project in Cognifide has run into a wall while trying to load test their website. the problem was as follows: The website is highly AJAX based – the page merely loads a stub in the initial request but then loads the rest of its data in a dynamic matter therefore a traditional web testing tools are fairly useless. What they tried was to setup a number of Selenium clients to pound the server, but that turned out to be fairly challenging to the machine doing the testing. It was not possible to set up more than 10 clients on a fairly strong machine.
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?
Once you’ll update the framework to the extended one, you will immediately notice that… nothing has changed. Hmm… did something go wrong?
Well, not really. By default the framework will be run in the “legacy mode”. Thanks to an old article by our own Marek Blotny, I’ve learned how to build Plugin settings which are just perfect for the purpose!
So to configure and enable the new features you need to open your admin UI and in the “Config” click on the “Plugin Manager” item and select our framework plugin as shown in the picture
Back in the day when we started designing our last project we’ve been presented with a following problem – a big number of templates with slightly different sidebars.
Hmm…
Is sidebar a part of content? No, rather not. We don’t want the editors to have to setup the sidebar for every article they write (and the site has a few dozens of articles created on it every day).
Is sidebar more of a template thing? Well… more like it, but still… we have articles all over the site with different sidebar elements when the articles are in different parts of the site (ok so we could add rules what controls display in which part of the site). But wait! There’s more! The sidebar will be different for every language (region). Now we’re talking a dozen of templates or a rules engine just to make the sidebar different. Customising the template with properties isn’t ideal either as it makes EPiServer UI very cluttered. Additionally we want to change sidebars across many templates so the whole branch/section of the site will be able to share the same sidebar.
The configuration of the module is a descendant of any EPiServer Virtual Path Provider configuration. This aspect is fairly well described on EPiServer pages.
A sample configuration for the TextImageVirtualPathProvider can look as follows
physicalPath is where the cached version of images will be stored
shownInFileManager is “false” as there is nothing to present for the user in the file manager.
allowedReferrers is the regular expression containing the filter for sites that are allowed to access the path provider and get images. This has been added so that your server does not turn into the internet’s text-image open service :)
allowNullReferrer should be set to false in production environment but allows for testing by directly creating URL’s without using a page to fill in the referrer.
replacementStrings – this one actually turned out to be very useful since some characters are invalid and not even reaching the VPP if EPiServer or ASP detects them. so to allow for characters like colon or < or even a dot (which would make it hard to form regular expression if it was explicitly available) or * you need to create an escape token for them. The string is a coma separated list of token,value,token,value,…
virtualPath is something you need to change if you want your VPP to serve images under a different root level folder. (e.g. if you have a page with that name already)
Additionally for IIS6 (most common scenario) you need to add node to configuration for the VPP to work.
We’ve not been talking much about it and that’s partially my fault as well (busy with other projects), but Cognifide has a really cool initiative called Cognifide Labs that we intend to grow over time. The plan is to devote up to 10% company time into side projects that help us grow expertise and allow our devs to dwell into interesting technologies, methodologies and languages and develop their skills.
One of the first projects (that I took part in) is CogniScale - an app that allows FlexiScale users to manage their servers. Here’s the story…
Since my effort towards making this control final has been somewhat limited lately, I’ve decided to simply release the code at its current stage so that others can play with it and perhaps we can have something decent done together. The control operation is described in my previous article therefore I will not be going much into it any longer. the deployment of it is something worth mention though…
Download the control form here. Extract the contents of the zip file to a folder and attach the project to your solution, make sure you have the proper EPiServer libraries referenced form the project or it may complain about the references being broken.
To finalize my mini series on the object store I’d like to put a simple page comments library. The library takes care of everything that is required for you to post and retrieve a list of comments. It does not (so far) offer any moderation functionality or even facilitates any comments removal. It’s something that I will most probably be added in the process.
I am in the process of figuring out how I can contribute it through the Community EpiCode effort on CodeResort. As soon as I get some answers from Steve, I’ll get it uploaded there. In the mean time let me document how to start using it.
It’s a real joy to work in a international company, the problem we face are hardly ever matched by some locally based endeavours…
As some of our friends here at work, you may choose to reveal your current location to your skype buddies. This is nice and easy since you can just put it in your name or description and everyone will see where you are.This poses a problem should you really travel frequently, it is more likely than not, that your location tag will be out of sync.
As this is a something that happens for them once in a while I found it an interesting concept, fun enough to be worth solving it :)
So how does one establish his location? Short of installing a GPS on your machine, I would suggest checking your IP address and translating it based on one of the available databases.
The thought process goes as follows… [Read about the technical guts of the application in my article at Code Project]
Most of us here use Pandora for the listening to the music with their headphones.
The keyboards we have at the office do not have any sound volume adjusting keys.
It’s mildly annoying that you need to take off your headphones every time someone talks to you or click the system tray every time the musinc is too quiet or too loud. But hey! What do we have CodeProject and Visual Studio for?
Quick investigation on CP allows to determine that there is a way for a DotNet app to both control the system volume and hook the keyboard events fairly easily.
Half an hour later…
We have a little tray application for adjusting the system volume control
The only visual indication of the app running is a tray icon. While it is running you can:
1PerformanceCounterpc=newPerformanceCounter("System","System Up Time"); 2 3//Normally starts with zero. do Next Value always. 4pc.NextValue(); 5 6TimeSpants=TimeSpan.FromSeconds(pc.NextValue()); 7 8MessageBox.Show(Environment.MachineName+ 9" has been up for \n\n"+10(ts.Days<1?"":ts.Days+" days, ")+11(ts.Hours<1?"":ts.Hours+" hours, ")+12(ts.Minutes<1?"":ts.Minutes+" minutes ")+13" and "+ts.Seconds+" seconds.");
[Edit: I’ve posted it on CodeProject and there are some greatl people commenting on it that did the investigation on ho to wrap it in a STA Thread and make it a part of your ASP.Net solution - really cool stuff!]
An interesting use case. Darek (our beloved sys admin - we all bow to him and worship his skills) has recently asked if it’s possible to write a .net application to make a thumbnail of a website. Which is pretty trivial with Windows forms actually.
All you really need to do is drop a WebBrowser on your form and once it’s loaded the page call:
[Updated 11 May 2005] Read at the end of the article.
I’ve been on a quest to improve a skin today and to do so I needed to extract a big archive in a proprietary and not widely supported format and get the images out of it and into the skin. Turned out the first part was not as bad as I expected as I’ve found some tools on the net to do this and Kris helped with the tool to convert the images in the proprietary format into TGA’s. Now here’s where the pain begun.