One of the things I missed when I started to look at Cuyahoga two weeks ago was that it didn’t use NHibernate 1.2. As I was used to NHibernate 1.2 from my work with its support for generics, I wanted to use that with Cuyahoga as well. So I decided to make a patch that would enable me to use it.
Besides using the files from the NHibernate 1.2 release, I had to download the subversion source code for Castle.Facilities.NHibernateIntegration.dll. Then I had to make a few adjustments to the code for it to compile against NHibernate 1.2.
After I had upgraded the dll’s, the Cuyahoga compiled. But when I run it NHibernate complained on some things like missing virtuals and wrong mapping scheme (urn:nhibernate-mapping-2.0 instead of urn:nhibernate-mapping-2.2). After that it seems to be working nice.
You can download the patch for Cuyahoga 1.5 source code here. And for Cuyahoga’s latest trunk here.
Unfortunately, I’ve been having some problem applying the entire patches. It complains about some strange character in the beginning of some of the repository files, so you might have to manually edit some files. (The patch file is actually quite human-readable so it can be of help in the manual process). But for those that start from scratch I’ve also created a ready package of Cuyahoga 1.5 with patch applied. Download it here.
Today I was having quite a bit of problem when I wanted to include javascript from a control inside a Telerik Ajax Panel. The javascript in question was dynamically generated and should only be added sometimes depending on what action was made inside the ajax panel.
The first thing I tried is the standard way of registering javascript blocks, namely using Page.ClientScript.RegisterClientScriptBlock. That didn’t work, which when I thought about it was logical as the script is added high up in the html and not inside the ajax panel.
Secondly, I read a bit on Telerik’s support pages. It suggested that I used RadAjaxPanel.EnableOutsideScripts and RadAjaxPanel.ResponseScripts. I didn’t get this to work either directly, and got outofmemory exception in javascript. Due to time constraints I didn’t investigate this properly. I will try and write and update soon, if I remember.
The last thing I tried was to just include the javascript inside the html of the ajax panel. Like the following code suggested I did this by using a LiteralControl, containing the script, that is inserted in the ajax panel’s control collection.
RadAjaxPanel panel = new RadAjaxPanel();
if (someCondition)
{
string myScript = "function MyAlert() { alert('Hello world'); }";
LiteralControl scriptControl = new LiteralControl();
script.Text = string.Format(
@"<script type=""text/javascript"">{0}</script>",
myFunction);
panel.Controls.Add(scriptControl);
Button alertButton = new Button();
alertButton.OnClientClick("MyAlert(); return false;");
panel.Controls.Add(alertButton);
}
For the sake of simplicity the javascript that is dynamically added in this example is rather static. This turned out to work. I should mention that this trick will work just as well with the standard Microsoft ASP.NET Ajax Update Panel.
In my current project I generate reports by creating Word 2007 files. You know the file format consisting of zipped XML files? This project is web-based and the users can enter information through rich text editors. These rich text editors produce html which in turn is inserted in the reports (with the altChunk tag for those who are interested) . All this can be done without any Word automation which is good (having Office on the server is not supported by Microsoft).
Before today, only textual content with formatting could be entered through these text editors. But today I added the ability to upload and insert images as well. And here the problem started. When generating the reports the images would only be linked to and not embedded inside which is not what I wanted…
So how did I solve this? I cheated! Before today we were using Word automation for converting Word 2007 documents to Word 97 (using a web service) for backwards compatability. I decided to try and modify this web service to automatically embed linked images. I found an article by Rick Strahl which led me to the solution. Besides the things the article mentionend I also needed to perform the same thing with InlineShapes. Here comes the code:
private void EmbedLinkedImages(Document doc)
{
foreach (InlineShape shape in doc.InlineShapes)
{
if (shape.LinkFormat != null)
{
shape.LinkFormat.SavePictureWithDocument = true;
shape.LinkFormat.BreakLink();
doc.UndoClear();
}
}
foreach (Field field in doc.Fields)
{
if (field.Type == WdFieldType.wdFieldIncludePicture)
{
field.LinkFormat.SavePictureWithDocument = true;
field.LinkFormat.BreakLink();
doc.UndoClear();
}
}
foreach (Shape shape in doc.Shapes)
{
if (shape.LinkFormat != null)
{
shape.LinkFormat.SavePictureWithDocument = true;
shape.LinkFormat.BreakLink();
doc.UndoClear();
}
}
}
The code is mostly self-explanatory except the doc.UndoClear(). It is there to clear the undo buffer in Word which otherwise can consume a lot of memory.