Monthly Archives: July 2008
XmlChoiceCollection class to access XSD generated properties for choice XML elements
MSDN XmlChoiceIdentifierAttribute Class article shows example of XSD, generated proxy class and how to fill pairs of arrays:
// of each enumeration type. Set the array to the
// ManyChoices field.
object[] strChoices = new object[]{“Food”, 5, 98.6};
myChoices.ManyChoices=strChoices;
// For each item in the ManyChoices array, add an
// enumeration value.
MoreChoices[] itmChoices = new MoreChoices[]
{MoreChoices.Item,
MoreChoices.Amount,
MoreChoices.Temp};
myChoices.ChoiceArray=itmChoices;
I found that support two arrays for items itself and for EmlementNames is error prone and created helper generic XmlChoiceCollection class, that allows to add items and types inone Add method.
#region Namespace Imports
using System;
using System.Collections.Generic;
using System.Text;
#endregion //Namespace Imports
/// <summary>
/// see http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlchoiceidentifierattribute(printer).aspx
/// </summary>
public class XmlChoiceCollection<TItem,TItemsChoiceEnum>
{
public List<TItem> _items;
public List<TItemsChoiceEnum> _elementNames;
public XmlChoiceCollection()
{
_items=new List<TItem>() ;
_elementNames=new List<TItemsChoiceEnum>();
}
public void Add(TItem item, TItemsChoiceEnum elementName)
{
_items.Add(item);
_elementNames.Add(elementName);
}
public TItem[] ItemsToArray()
{
return _items.ToArray();
}
public TItemsChoiceEnum[] ElementNamesToArray()
{
return _elementNames.ToArray();
}
}
{
request.Items = choiceCollection.ItemsToArray();
request.ItemsElementName = choiceCollection.ElementNamesToArray();
Shortkey Alt-B,U is ambiguous in Visual Studio 2008 team edition
I know that I can assign new shortkeys using Customize, but my hands need to remember this new key, and my preference is to hide-disable shortkey for “Queue new build” , which I am not using anyway.
QuickCode.Net 2008 new TAB shortcut key
QuickCode.Net has a new free 2008 version.
UPDATE: in a new release 3.0.6. it’s possible to assign any shortcut key. In VS 2008 Customise keyboard I’ve selected command QuickCode2008.AddIn.ReplaceQuickCode and assigned a shortcut key Alt-Q.
It uses <TAB> instead of previously assigned Alt-Q hotkey.
<TAB> is consistent with standard VS snippets.
If you press the TAB key after your QuickCode, e.g.
tc<TAB>
the QuickCode will expand.
If the same pattern exists in snippets and QuickCode, the VS snippet goes first. QuickCode deliberately does NOT expand QuickCodes while Intellisense is active.
After some use of new QuickCode.Net 2008 I understood that I prefer old Alt-Q , not new Tab
To support spaces In the following QuickCode macro in the pattern use : not
#r %%desc%%
But
#r %{desc}%.
<?xml version=”1.0″ ?>
<quickcodes version=”3.0″>
<quickcode description=”region” pattern=”#r %{desc}%” priority=”0″>
<expansion language=”Basic”><![CDATA[#region “%%desc%%”
#End Region ‘ %%desc%%]]></expansion>
<expansion language=”CSharp”><![CDATA[#region “%%desc%%”
#endregion // %%desc%%]]></expansion>
</quickcode>
</quickcodes>
And everything works as expected!
Tip: You can copy the XML above to the clipboard and paste it into the QuickCode list to copy this QuickCode to your own collection.
Ideally it would be good if QuickCode will support both keys.
Related link(s):
My older post: QuickCode commands file location
“Login failed for user” may mean “database name is invalid”
Generate C# class from XSD file.
I’ve actually have two XSD files -outer and imported
@call “C:Program FilesMicrosoft Visual Studio 8VCvcvarsall.bat” x86xsd.exe outer.xsd imported.xsd /classes /l:cs /n:MyNamespacerem rename outer_imported.cs as outer.cspause
Another problem with XSD generated classes is that it disables step into debugging even on methods that you extended in partial classes by specifying DebuggerStepThroughAttribute for classes. Workarounds are described in XSD.exe and DebuggerStepThrough post. Issue reported to MS Feedback.
I should try An XSD to .NET language code class generator that adds real punch to Microsoft’s XSD Tool.
or Sample Code Generator 1.4.2.1
That’s pity, that minor changes in XSD file causes different class properties to be generated and essential code changes to access the new properties.
Visual studio 2008 “Build action” properties: Shadow and CodeAnalysisDictionary
Disk Cleanup Utility should delete temporary .Net files.
I noticed that one of our servers with low disk space had a lot of security.config.cch files(or security.config.cch.number) in individual user folders, as well as in .Net.Framework config directories.
According to the thread http://www.pcreview.co.uk/forums/thread-1228604.php -it seems they are safe to delete.
But why they are located in config folder, not in some temporary directory, like NETFramework{version}Temporary ASP.NET Files folders?
And they should be suggested for deletion by standard MS windows Disk cleanup utility.
I’ve submitted this suggestion to MS Connect
Links:How to save html file to PDF
I want to save html file generated by ASP.NET to PDF.
I was pointed to itextsharp open source project.
I found a few links, discussing how to do it:
http://www.velocityreviews.com/forums/t72716-using-itextsharp-to-generate-pdf-from-aspnet.html
iTextSharp Tutorial Chapter 7: XML and (X)HTML
iTextSharp Demo(asp.net 2.0):http://rubypdf.com/itextsharp/tutorial01/ap07Chap0707.cs.html introduces HtmlParser.Parse.(see the source code here)
We tried to use it.
HtmlParser.Parse does NOT throw any error , but the pdf file generated from this could be blank/empty.
Debug output shows the messages from parser, if Html file has invalid structure.
This is a big problem: HtmlParser.Parse is very strict and any minor mistakes in HTML causes exceptions or almost silent creation of empty PDF file.
The post of Creating pdf in .NET from html has a lot of interesting comments, including suggestion to use HTML Agility Pack.
We are going to try how HtmlParser.Parse will be tolerant to html, regenerated from HTML Agility Pack.
The thread [ 1819614 ] Error parsing images in HTML files has description of the fix
Another option is always use XML complient HTML, verified by http://validator.w3.org/#validate_by_input ,but it could take some time to tidy up the HTML generated from ASP.NET
http://www.google.com.au/search?source=ig&hl=en&rlz=&q=HtmlParser.Parse&meta=
Links to other products:
Generate PDF from ASP.NET gives a few references to different products including iTextSharp
Dynamically Generating PDFs in .NET : http://www.developerfusion.co.uk/show/6623/
Another option is to try (and possibly buy) commercial product abcpdf
I saw a suggestion to use http://www.htmldoc.org/ -the command line version of HTMLDoc to convert HTML to PDF, but it is not good for programmatic access.
Call Synchronous Web Services Methods Asynchronously
MyClass.ExecuteDelegate requestDelegate =new MyClass.ExecuteDelegate(myRequest.CallMyWebMethod);
MyAsyncState asyncState =new MyAsyncState (myData);
IAsyncResult asyncResult= requestDelegate.BeginInvoke(null, asyncState);
//and when call will be completed
AsyncResult asyncResult=(AsyncResult)ar;
MyClass.ExecuteDelegate requestDelegate = (MyClass.ExecuteDelegate)asyncResult.AsyncDelegate;
MyResponseClass myResponse =(MyResponseClass )requestDelegate.EndInvoke(asyncResult);
In this case the actual custom application code of CallMyWebMethod function stays unmodified for both sync and async execution.