| Fiach's profileNetwork Programming in ....BlogLists | Help |
|
May 26 ASP.NET Crash on "OnBubbleEvent"When debugging an ASP.NET application, I suddenly got an "Object Not Set to a reference of an object" error on OnBubbleEvent, which leads into unmanaged code in the .NET framework.
Simple solution, CTRL-ALT-DELETE, hit asp_wp.exe, and kill the process.
It works fine afterwards.
May 24 Capturing a webcam to an AVI fileI previously wrote an application which captures a webcam in VB.NET (http://www.webtropy.com/articles/art7.asp) However, this only shows a webcam, and has no facilities to record. Therefore, I added a new function to save bitmaps
Public Sub SaveBitmap(ByVal filename As String)
SendMessage(lwndC, WM_CAP_FILE_SAVEDIB, 0&, filename) End Sub
Where WM_CAP_FILE_SAVEDIB is defined as WM_USER+25 - It also requires an overloaded SendMessage declaration, which accepts a string as it's final parameter.
I then found some CS code which converts BMP files to AVI (http://midget3d.com/gabe/AviLib.zip)
then used this to write bitmaps to disk, and build them into an AVI
saveFileDialog.Filter="*.avi|*.avi"; saveFileDialog.ShowDialog(); string strAVI = saveFileDialog.FileName; string strBMP = saveFileDialog.FileName.Replace(".avi",".bmp");AviWriter aviWriter = new AviWriter(strAVI, AviCompression.None, 24, 320, 240);isRecording = true; while(isRecording){ webcamControl1.SaveBitmap(strBMP); aviWriter.WriteFrame( new Bitmap(strBMP));Application.DoEvents(); } aviWriter.Close(); May 12 Compress an AVI movie using C#I was looking for a way to compress an AVI file down without loosing quality, and to do so programatically, in C#. All I found on the web, were commercial components. However, I just found out you can use QuickTime in C#, to compress the files down in size.
private bool ConvertToQuickTime(AxQTOControlLib.AxQTControl Control,string fromFileName,string toFileName){ this.axQTControl1.URL = fromFileName; if (!axQTControl1.Movie.CanExport) return false;QTOLibrary.QTQuickTime qt; qt = axQTControl1.QuickTime; if (qt.Exporters.Count == 0) qt.Exporters.Add();QTOLibrary.QTExporter exp; exp = qt.Exporters[1]; // Set exporter type: AVI, 3G, MPEG-4, PNG, etc.exp.TypeName = "QuickTime Movie"; exp.SetDataSource(axQTControl1.Movie); exp.DestinationFileName = toFileName; exp.ShowProgressDialog = true;exp.BeginExport(); return true;} May 03 Converting HHC files to HTML filesIf you have used HTML Help Workshop, you will see Table of contents files called HHC files being generated. You may want to create HTML versions of these for on-line viewing.
this C# function converts HHC files to HTML files
private string convertHHCtoHTML(string HHC){ string strTitle; string strUrl; string strLink; string strRegex1 = @".param.name..Name..value..(?<Title>[\w \'!]*)..[\r\n\t]*.param.name..Local..value..(?<url>[./%\w \']*).."; string strRegex2 = @".param.name..Name..value..(?<Title>[\w \'!]*)..";MatchCollection mcParams = Regex.Matches(HHC,strRegex1); // convert the links foreach(Match mParam in mcParams){ strTitle = mParam.Groups["Title"].Value; strUrl = mParam.Groups["url"].Value; strLink = "<a href=\"" + strUrl + "\">" + strTitle + "</a>"; HHC = HHC.Replace(mParam.Value,strLink); } string strObjectTag = "<OBJECT type=\"text/sitemap\">"; string strObjectCloseTag = "</OBJECT>";HHC = HHC.Replace(strObjectTag,""); HHC = HHC.Replace(strObjectCloseTag,""); // Now convert the titlesmcParams = Regex.Matches(HHC,strRegex2); foreach(Match mParam in mcParams){ strTitle = mParam.Groups["Title"].Value; strLink = strTitle; HHC = HHC.Replace(mParam.Value,strLink); } return HHC;} Converting a DataTable to a HashtableThis is a handly little C# function to convert a DataTable to a HashTable
(Give credit to this website if you use it!)
private Hashtable convertDataTableToHashTable(DataTable dtIn,string keyField,string valueField){ Hashtable htOut = new Hashtable(); foreach(DataRow drIn in dtIn.Rows){ htOut.Add(drIn[keyField].ToString(),drIn[valueField].ToString()); } return htOut;} May 01 Parsing WindJet routesProbobly a particularly niche field, but I just developed some code to parse airline routes from the website VolaWindJet.
private string GetWindJetRoutes(string HTML){ string outRoutes = ""; // Step 1. Delete between FL_Departure> and /SELECT string strOutboundRoutes = DeleteBetween(HTML,"FL_Departure>","/SELECT");MatchCollection mcDepIata = Regex.Matches(strOutboundRoutes,"value=(?<FromIata>[A-Z]{3})"); // Step 2. extract ToIata Array string strRegex = @"arrayVoli\[(?<IDFrom>\d+)\]\[(?<IDTo>\d+)\]\=new.Option\('\w.*'(?<ToIata>\w{3})";MatchCollection mcDestIata = Regex.Matches(HTML,strRegex); for(int iMatch=0;iMatch<mcDestIata.Count;iMatch++){ int intIDFrom = Convert.ToInt32(mcDestIata[iMatch].Groups["IDFrom"].Value); string strFromIata = mcDepIata[intIDFrom-1].Groups["FromIata"].Value; string strToIata = mcDestIata[iMatch].Groups["ToIata"].Value;outRoutes += "'" + strFromIata + "','" + strToIata + "'\r\n"; } return outRoutes;}
Might be of interest to someone out there.... (or if not, my own personal reference) |
|
|