I am invited to be а speaker at the upcomming seminar for PHP and Web developers that will focus on the integration of PHP with the Microsoft technologies and platforms. The speakers will demonstrate how to run PHP in IIS and how to integrate PHP and .NET applications.
My talk will focus on the technologies for using .NET Framework functionality and code from PHP applications. I will demonstrate how to write a plug-in for WordPress in C#.
The event will be held on 30 June 2009, 17:00 h at Ilieff Center, Students town, Sofia. All Web developers are welcome. The seminar is free.
Download my presenetation here: Nakov-Integrating-PHP-and-MS.NET-v1.0.ppt.
Download my demo project - WordPress plugin for downloading a blog post as PDF document (written in C#): Web2Pdf-WordPress-Plugin-in-CSharp-Demo.zip
Posted by nakov as blog at 12:51 PM EEST
Comments Off
Today I researched how to implement in C# a method that forces a COM port to close when it is open by another process. This was found to be a complex task that involves using undocumented Win32 API functions. I didn’t finish it because I found another way to workaround the problem but the idea is the following:
1) Enumarate all Win32 processes.
2) In each process enumerate all its handles and find the handle to be closed (e.g. \Device\Serial0).
3) Close the handle.
The first task is trivial. We can use System.Diagnostics.Process.GetProcesses(). The second is possible with the Windows NT undocumented function NtQuerySystemInformation. The third task is simple. Once we have the process ID (pid) and the handle of the open COM port, we can close it with the following CloseHandleEx function:
Posted by nakov as blog at 6:09 PM EEST
Comments Off
I am working on an ActiveX control that allows using a device for scanning personal ID cards in a Web application (based on ASP.NET). The card scanning device (called RTE reader) is accessed using a native DLL that communicates with the device through the COM port by using a proprietary protocol. It is pretty complicated to get this working in all Web browsers so we conviced the customer to use Internet Explorer only.
The typical way to implement this functionality in Internet Explorer is to write an ActiveX control. I created the ActiveX control in C# using .NET Framework 2.0, Windows Forms and few native DLLs. How to create an ActiveX in C# in another interesting story, but once I got ready with the ActiveX control, I needed to write an installation program that changes the security policy of Internet Explorer to ensure the control is allowed to run without security restrictions. The control uses native DLL calls so it needs special permissions that can be assigned by the .NET Framework 2.0 Configuration Tool or its console version (caspol.exe).
There are two steps needed to get running an ActiveX control implemented as .NET assembly without security restrictions in Internet Explorer:
- Add the Web site to the “Trusted sites” security zone in Internet Explorer. This allows this Web site to install and run ActiveX controls.
- Assign full trust permission set to the assembly implementing the ActiveX in the .NET Security Policy.
While the first task is less challengeable (we just need to add few registry values), the second requires to run the following command:
The caspol.exe is standard part of .NET Framework 2.0 and hence is available in any machine that has .NET 2.0, 3.0 or 3.5 (because all of the use CRL 2.0). It is typically located here:
The following source code (implemented as Windows Forms desktop application) performs the above mentioned two steps to allow an ActiveX written in C# to run without security limitations in Internet Explorer:
Posted by nakov as blog at 2:12 AM EEST
Comments Off
I needed to enumerate all COM ports in C# and get their name (e.g. COM1, COM2, …) and their description shown in the Windows Device Manager (e.g. “Communications Port”, “RT USB MRTD Reader”). You could find lots of unmanaged code for doing this but I think this C# code could be helpful to people who perform communication through the serial interface in .NET:
Posted by nakov as .net at 6:17 PM EEST
Comments Off

Recently my team of 20 authors and few editors working on creating a contemporary book about the fundamentals of computer programming, data structures and algorithms is ready with the public official release of the book: http://introjavabook.googlecode.com/files/Introduction-to-Programing-with-Java-Book-v1.0.pdf.
The book “Introduction to Programming with Java” focuses on the fundamentals of computer programming, logical, algorithmical thinking, problem solving, data structures and algorithms. It uses a contemporary object-oriented approach and language but is valuable for any non-Java programmer in the begginning of his career. The book is free and open-source.
The contents of the book:
- Chapter 0. Preface
- Chapter 1. Introduction to Programming
- Chapter 2. Primitive Types and Variables
- Chapter 3. Operators and Expressions
- Chapter 4. Console Input and Output
- Chapter 5. Conditional Statements
- Chapter 6. Loops
- Chapter 7. Arrays
- Chapter 8. Numeral Systems
- Chapter 9. Methods
- Chapter 10. Recursion
- Chapter 11. Creating and Using Objects
- Chapter 12. Exceptions Handling
- Chapter 13. Strings
- Chapter 14. Defining Classes
- Chapter 15. Text Files
- Chapter 16. Linear Data Structures
- Chapter 17. Trees and Graphs
- Chapter 18. Dictionaries, Hash Tables and Sets
- Chapter 19. Data Structures: Comparison and Best Practices
- Chapter 20. Object-Oriented Programming Principles
- Chapter 21. High-Quality Programming Code
- Chapter 22. How to Solve Programming Tasks?
- Chapter 23. Example Topic from Exam in NASD – 30.09.2005
- Chapter 24. Example Topic from Exam in NASD – 8.04.2006
- Chapter 25. Example Topic from Exam in NASD – 11.12.2005
|
More information is available on the book’s official Web site: http://academy.devbg.org/books/intro-java/.
Posted by nakov as news, java, blog at 3:36 PM EET
Comments Off
Last few nights I was debugging very strange bug. Few months ago we shipped Java applet signing Web forms in the client’s Web browser. It was tested under IE 6, IE 7, Firefox 2, Firefox 3, Opera 9 and Safari 3 for Windows. We tested with Java 5 and Java 6 in Windows and Linux environment. We didn’t tested the applet in Mac OS X because we didn’t have Mac machine.
Few days ago our customer reported that the applet does not work in Safari and Firefox in Mac OS X. My nightmare started. First I needed to install and run Mac OS X in a virtual machine. It takes a lot of time, runs very slowly and networking is unstable but this is another story.
I found 2 great bugs when using JSObject to access the Web page DOM from java applet in Firefox 3 on Mac OS X and Safari 3 on Mac OS X.
JSObject.getMember() Always Returns Null in Firefox on Mac OS X
The first problem was with Firefox 3 on Mac OS X. When you call JSObject.getMember() to get some property from an object inside the Web page DOM, it always returns null. This method is not supported in Mac OS X and the only information you can find in Internet is that other developers have the same problem and there is no solution. This bug in not published and there is not fix. It just does not work.
The second bug was even more strange.
JSObject.getMember() Hangs in Safari in Mac OS X Unless You Move the Mouse
Sounds strange but this was the exact behaviour: in Safari 3 in Mac OS X 10.4.2 calling JSObject.getMember() blocks for unlimited time until you move the mouse over the applet. It was very strange. When you move the method call returns with the correct result. If you don’t move the mouse over the applet, it hangs for unlimited time. The first thing I did was to configure the JVM for remote debugging, to compile the applet with debug infor and to attach remote debugger form my desktop machine to debug the applet running inside the virtual machine. The strange behaviour was confirmed. Calls to JSObject.getMember() were henging until you move the mouse. I tried lots of ways to overcome this (e.g. adding synchronization, invoking the operations accessing DOM from the AWT dispatch thread and through the main applet thread). Nothing helped.
I found in Internet that others have the same problem and have partial solution with running seperate thread. When I run separate thread for the job accessing the DOM tree, my problem was solved. Nice workaround and works for all browsers. I added additional code to prevent the job accessing the DOM tree to start several times in parallel. Finally, after few other fixes my applet for signing Web forms runs in Safari under Mac OS X.
For some reason the AWT dispatcher thread is put into sleep by Safari during the calls of JSObject.getMember() and moving the mouse wakes it up to process the mouse events inside the applet and that’s why it behaves strangely. I don’t have complete explaination why seperate thread works differently, but it works. Debugging applets’s threading issues was challengeable task but I hope this to be my last project for developing applets.
Posted by nakov as blog at 2:24 AM EET
Comments Off
For development purposes and small applications I prefer using Oracle Database 10g Express Edition instead of the heavyweight Oracle Database 10g / 11g Enterprise. It can be installed and run for just 2-3 minutes but it has a small problem: by default the TNS Listener listens for connections on port 1521 from the local machine only and thus remote clients can not connect. A quick fix for this issue is to edit the LISTENER.ORA file located typically in here:
C:\oraclexe\app\oracle\product\10.2.0\server\NETWORK\ADMIN
You should change the socket bind address to 0.0.0.0. The LISTENER configuration should look like this:
Posted by nakov as blog at 1:53 PM EET
Comments Off
Last week I was invited by InterConsult Bulgaria (ICB) as speaker at their 6-th annual software engineering conference in 12-13 September in Pomorie. My talk was about the Service Oriented Architecture (SOA) trends in 2008:
- SOA and Web 2.0
- SOA in Internet (Web-Oriented Architecture)
- SOA in the enterprises
- SOA adoption
- Virtualization and computing clouds
Download my presentation here: Nakov-SOA-Trends-2008.ppt.
Posted by nakov as news, blog at 1:42 PM EEST
Comments Off
Today I needed to optimize the file size for a commercial Java applet (Web form signer) that my team is developing in the last month. We use few external libraries (Bouncy Castle Crypto API and few others) and these libraries are above 2 MB in several JAR files. If we were developing server side application, it would not be a problem, but when we are building an applet, the size of the applet and all its JARs matters.
I needed to remove all unused classes from the JARs that my applet was including a part of itself. For example the Bouncy Castle JARs were about 1,6 MB but the applet used only a small part of all algorithms and standards implemented by these JARs.
Extracting All Classes Loaded in the JVM
My final goal was not only to remove all unused classes from all JAR files but also merge these JARs along with the applet classes into a single JAR file that has the smallest possible size. I came with the idea to run the applet, to go through all its functionality and to get a list of all classes currently loaded into the JVM executing the applet. At this moment all classes required by the applet for its normal work will be loaded in the JVM and all classes that was never used by the applet will not be loaded in the JVM. If I package all these classes into a new JARs, it will contain the minimal set of classes nedded by the applet along with the applet classes.
As fas as I know how the JVM and the class loaders behave, this should be correct - we can expect all classes required by the applet to be loaded in the JVM after its entire functionality is accessed at least once.
I had a serious problem: how to get a list of all classes loaded in the JVM.
List All Classes Loaded in the JVM
Geting a list of all classes that are loaded in the JVM at some moment is not easy job. We can write Java agent through the java.lang.instrument API but I needed to do this at runtime (just to add few lines to the applet). I found in Google a very nice class for accessing all classes loaded in the JVM written by Vladimir Roubtsov and published in Java World (http://www.javaworld.com/javaworld/javaqa/2003-07/01-qa-0711-classsrc.html). With few modifications it successfully listed all classes loaded in my applet.
Create a Single JAR with All Classes Loaded in the JVM
The next step was to create a single JAR with all classes loaded in the JVM. This was not complex. I created a class with few methods for copying all currently loaded classes into some directory specified as parameter. Here is the source code:
It is not a rocket science. I go through all classes loaded by the current class loader and by the system class loader, get their fully qualified name (e.g. org.bouncycastle.cms.CMSSignedData) and their source URL location (e.g. jar:file:/C:/PROJECTS/GeneratePKCS7andVerify/lib/bcmail-jdk15-140.zip!/org/bouncycastle/cms/CMSSignedData.class) and I copy their binary contents (from the URL) to the destination folder (into a .class file). In the mean time I recreate the package structure (following the full class name with all its packages). Finally I get a directory containing all class files loaded in the JVM at the time of caling my method and I can manually package them in a JAR (removing beforehand all system Java classes). That’s all. I use slightly modified version of ClassScope.java.
You can download a fully functional example here (Eclipse project): ExtractAllClassesFromJVMIntoJAR.zip.
Posted by nakov as java, blog at 11:32 PM EEST
Comments Off
The next meeting of the Bulgarian Java Users Group (BGJUG) will be held on 28 August 2008 in the Chemistry Faculty, Hall 210 in Sofia, starting at 18:30.
The topicwill be the Java FX technology. Speaker will be Naiden Gochev.
Posted by nakov as news, java at 2:08 PM EEST
Comments Off