Archive
HowTo: Remove invalid filename characters in .NET
In ClipFlair Studio I use DotNetZip (Ionic.Zip) library for storing components (like the activity and its nested child components) to ZIP archives (.clipflair or .clipflair.zip files). Inside the ZIP archive its child components have their own .clipflair.zip file and so on (so that you could even nest activities at any depth) which construct their filename based on the component’s Title and ID (a GUID)
However, when the component Title used characters like " (double-quote) which are not allowed in filenames, then although Ionic.Zip created the archive with the double-quotes in the nested .clipflair.zip filenames, when trying to load those ZipEntries into a memory stream it failed. Obviously I had to filter those invalid filename characters (I opted to remove them to make those ZipEntry filenames a bit more readable/smaller).
So I added one more extension method for string type at StringExtensions static class (Utils.Silverlight project), based on info gathered from the links from related stackoverflow question. To calculated version of a string s without invalid file name characters, one can do s.ReplaceInvalidFileNameChars() or optionally pass a replacement token parameter (a string) to insert at the position of each char removed.
public static string ReplaceInvalidFileNameChars(this string s,
string replacement = "") { return Regex.Replace(s, "[" + Regex.Escape(new String(System.IO.Path.GetInvalidPathChars())) + "]", replacement, //can even use a replacement string of any length RegexOptions.IgnoreCase); //not using System.IO.Path.InvalidPathChars (deprecated insecure API) }
For more info on Regular Expressions see http://www.regular-expressions.info/ and http://msdn.microsoft.com/en-us/library/hs600312.aspx
BTW, note that to convert the char[] returned by System.IO.Path.GetInvalidPathChars() to string we use new String(System.IO.Path.GetInvalidPathChars()).
It’s unfortunate that one can’t use ToString() method of char[] (using Visual Studio to go to definition of char[].ToString() takes us to Object.ToString() which means the array types don’t overload the virtual ToString() method of Object class to return something useful).
Another thing to note is that we don’t use System.IO.Path.InvalidPathChars field which is deprecated for security reasons, but use System.IO.Path.GetInvalidPathChars() method instead. MSDN explains the security issue, so better avoid that insecure API to be safe:
Do not use InvalidPathChars if you think your code might execute in the same application domain as untrusted code. InvalidPathChars is an array, so its elements can be overwritten. If untrusted code overwrites elements of InvalidPathChars, it might cause your code to malfunction in ways that could be exploited.
IIS FTP login fails after Windows platform update for Server 2008 R2
I had recently enabled FTP access to the ClipFlair Gallery to easy its maintenance during development and after the Windows Server 2008 R2 platform update last night (together with release for Internet Explorer 10), the FTP login stopped working.
To fix it, from a command prompt with administrator rights (Start/Find, type Command and right click the Command Prompt item found to open as administrator), give the command:
netsh advfirewall set global StatefulFtp disable
It’s easy to copy-paste it from here and right-click on the command prompt title bar, then select Edit>Paste (no shortcut key for that unfortunately), then press the ENTER key and it should reply “Ok”.
Had done this before, but seems the platform update re-enabled filtering for Stateful FTP (also note that at http://www.iis.net/learn/publish/using-the-ftp-service/configuring-ftp-firewall-settings-in-iis-7 it seems to erroneously say that you need to use “enble” instead of “disable” when not using SSL).
PivotViewer for a rich search experience
For ClipFlair, I’m looking into implementing advanced search using Silverlight PivotViewer
Update:
You can now check out ClipFlair Gallery in all its PivotViewer with DeepZoom glory.
A really nice example of PivotViewer search is at:
http://www.appletoncompassion.org/VirtualExhibitViewer
This may take long time to load, since its loading 10000 children art DeepZoom image tiles
You can use the mousewheel to zoom in there or the zoom slider at top-right (can also click an item to zoom to it)
See the filters at the left handside, play with them by selecting items there at the various properties to see the images get rearranged to show only ones selected by the filters.
Has also buttons at the top-right to bin the items based on having same values at properties selected
Another good example is Netflix movie catalog:
http://netflixpivot.cloudapp.net/
e.g. select Sort: Genre at top-right and click Graph View button there instead of the default Grid View to see the items get binned by Genre, then start filtering them down from the left handside bar
Also see a SharePoint sites collection search with PivotViewr:
http://www.wssdemo.com/livepivot/
MSDN magazine collection with PivotViewer:
http://pivot.blob.core.windows.net/msdn-magazine/msdnmagazinepivot.htm
Finally, for a nice series of Silverlight PivotViewer programming articles by Tony Champion see:
http://tonychampion.azurewebsites.net/blog/index.php/tag/pivotviewer/
http://pivotviewerlessons.codeplex.com/ (source code)
http://pivotviewer.championds.com/ (live examples)
BTW, people are also working on HTML5 PivotViewer:
http://www.rogernoble.com/2012/02/02/addressing-the-elephant-in-the-room-the-html5-pivotviewer/
http://lobsterpot.com.au/lobsterpot-html5-pivotviewer-now-open-source
http://lobsterpothtml5pv.codeplex.com/
http://lobsterpot.com.au/pivotviewer/api-reference
http://lobsterpot.com.au/pivotviewer/extending-the-html5-pivotviewer
http://pivot.lobsterpot.com.au/html5.htm (Live HTML5 Sample)
http://examples.hubbardone.com/html5/html5pivotviewer.htm (Live HTML5 Sample)
For developers, here are some direct links to .CXML (Collection XML) files:
http://gallery.clipflair.net/collection/activities.cxml
http://gallery.clipflair.net/collection/video.cxml
http://gallery.clipflair.net/collection/images.cxmlhttp://pivot.blob.core.windows.net/msdn-magazine/msdnmagazine.cxml
http://images.appletoncompassion.org/deepzoomfull/AppletonCompassionFull.cxml
http://www.esrc.ac.uk/Pivot/CXML/Grants/Grants.cxml
http://labs.championds.com/MIX10/MIX10Collection.cxml
http://spscollection.blob.core.windows.net/pivot/SharePoint.cxml
http://www.xpert360.net/SQLBits/Collection.cxml
http://pivot.metia.com/worldcup/wc2010-dz.cxmlBy opening the .CXML file URL in a web browser you can see its XML-based structure.
By using ClipFlair Studio‘s Gallery component you can open most of those .CXML URLs and play with the respective collection (you use the wrench button on the Gallery component’s titlebar to turn it over and set the Source URL, then turn over again to see the collection – just wait a bit if it’s big and takes some time to load). An alternative is to open in your browser a URL of the form http://studio.clipflair.net?gallery=http://spscollection.blob.core.windows.net/pivot/SharePoint.cxml
Not all of these URLs will work in ClipFlair Studio’s Gallery component though, because some servers may be using restrictive access policy files for Silverlight, not allowing a Silverlight app like ClipFlair Studio which is served from http://studio.clipflair.net to download the .CXML file.
text transforms: TemplateFilter, TextCaseConvertion, CharConv, Dos2Unix, Unix2Dos, ClearTextFilter
Added various tools related to text transformations at my tranXform website (30-Sep-2010 update):
TemplateFilter
DOS filter – parses CSV-style multi-column (“;” separator) input text rows (one row per text line) and generates text based on a supplied template that is applied per input row
TextCaseConvertion
simple GUI-based tool to convert string to upper-case, lower-case and camel-case
CharConv
Windows and Microsoft Word GUI for Text transformation given character set mapping (from/to) and calculation of mapping given matching (portions of) source and target text
Useful for deciphering copy-pasted text from PDF documents that ends-up with strange character swaps in it due to encoding reasons
Dos2Unix
DOS filter – converts CRLF (Dos/Windows style) to LF (Unix style) for text ending line markers
Unix2Dos
DOS filter – converts LF (Unix style) to CRLF (Dos/Windows style) for text ending line markers
ClearTextFilter
DOS filter – converts control characters to space chars