RSS Feed for ProgrammingCategory: Programming

Windows: Generate WMI Code »

The WMI Code Creator tool allows you to generate VBScript, C#, and VB .NET code that uses WMI to complete a management task such as querying for management data, executing a method from a WMI class, or receiving event notifications using WMI.
The WMI Code Creator tool generates code that uses WMI to obtain management information […]

.NET: Convert to Local Timezone »

You can use the style DateTimeStyles.AssumeLocal to parse the date time string if there is no timezone information contained in the string.
E.g.

1: DateTime.ParseExact(dateString, DateFormats, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);

If datestring contains no time zone information, the DateTime..::.Parse(String, IFormatProvider, DateTimeStyles) method returns a DateTime value whose Kind property is DateTimeKind..::.Unspecified unless a styles flag indicates otherwise. […]

Oracle BPEL: Partner Link Timeout »

Starting version 10.1.3.4, to set time out in seconds for a partner link, it is just configuration in bpel.xml.
E.g. the configuration below sets the timeout to 5 seconds

1: <partnerLinkBinding name="WebService"> 

2:   <property name="timeout">5</property>  

3: <property name="optSoapShortcut">false</property>   

4: <!– other […]

Oracle BPEL: Adding CDATA Section to XML Payload »

In Oracle BPEL, to add a CDATA section to a XML payload looks like not easy.
E.g. if you want to add the CDATA to the XML below, it is not easy as using Java

1: <?xml version = ‘1.0′ encoding = ‘UTF-8′?>

2: <tns:RunTask><xmlRequestDocument><![CDATA[test

3: data]]></xmlRequestDocument></tns:RunTask>

As of version 10.1.3.5, […]

C#: Convert Byte to SByte »

Here is a simple way to convert SByte to Byte in C#. E.g. if you want to convert the value of 129 from data type Byte to –127 in SByte

1: byte byteValue = 129;

2: sbyte sb = unchecked((sbyte)byteValue);

3: Console.WriteLine(sb);

Viewing Outlook Msg File OLE Type Attachment »

This is a bit tricky to view OLE type of attachment in Outlook .msg file. You need to use MsWord library in order to extract the attachment.
Here is the code snippet that does the trick.

1: for(int loop = 1 ; loop < (mItem.Attachments.Count+1) ; loop++){ […]

Facebook SDK from Microsoft »

The Facebook toolkit is provided as a Facebook Client Library similar to Facebook’s PHP Client Library or Facebook’s JavaScript library. The goal is to enable .NET developers to quickly and easily leverage the various features of the Facebook Platform. This toolkit has evolved over time with input from the community and from Microsoft. The latest […]

Asynchronous Web Service using WS-Addressing »

WS-Addressing provides way to specify message addressing information independent of transport layer. WS-Addressing provides a way to specify delivery, reply-to, and fault-handler addressing information in a SOAP envelope. WS-Addressing can be used in conjunction with other specifications such as WS-Security to authenticate and WS-Policy to define policies for the service.
WS-Addressing has two key constructs or […]

Go – A New Systems Programming Language »

Go is a new systems programming language from Google.
The goal of the project, as quoted below
No major systems language has emerged in over a decade, but over that time the computing landscape has changed tremendously. There are several trends:

Computers are enormously quicker but software development is not faster.
Dependency management is a big part […]

Java: Time Synchronization Trick in Programming »

In previous article, I have written about Java Time Sync Problem. JVM time follows the CPU ticks once it is started even though the application servers are time synced with NTP.
With this in mind, if developer does not use a centralized server to retrieve the time, it would pose a problem.
Image the following scenario,

You […]

Java: Detect and Use System Proxy »

Here is a Java class that you use to detect and use the system proxy, or direct connection is available to the Internet.
Basically, it uses java.net.useSystemProxies property which is available starting JDK 5.

1: package com.cdp.proxy.plugins;
2: 
3: 
4: import java.net.InetSocketAddress;
5: import […]

MessagingToolkit – SMS Library Community Edition »

I just released the community edition of MessagingToolkit
messagingtoolkit is a .NET C# messaging library that can be used to send and receive messages using any ETSI 07.05 compliant GSM modem or phone handset connected to the PC serial port through serial cable, infrared or bluetooth.
Some of the features of the library

Send SMS
Read incoming SMS […]

Concurrency Testing Tool »

CHESS is a tool for finding and reproducing Heisenbugs in concurrent programs. CHESS repeatedly runs a concurrent test ensuring that every run takes a different interleaving. If an interleaving results in an error, CHESS can reproduce the interleaving for improved debugging. CHESS is available for both managed and native programs.

Java: Predicate in Commons Collection »

Predicate in Commons Collection is very useful for logic evaluation. The available predicates should fulfills most of your logic requirements, or you can even write your own custom predicate.

AllPredicate
AndPredicate
AnyPredicate
EqualPredicate
ExceptionPredicate
FalsePredicate
IdentityPredicate
InstanceofPredicate
NonePredicate
NotNullPredicate
NotPredicate
NullIsExceptionPredicate
NullIsFalsePredicate
NullIsTruePredicate
NullPredicate
OnePredicate
OrPredicate
TransformedPredicate
TransformerPredicate,
TruePredicate
UniquePredicate

You can combine predicates together to form a compound predicate and also write custom predicate. E.g

public class PredicateTest {
 
static class Student {
[…]

C#: Retrieving and Sorting COM Ports »

In .NET, it is easy to retrieve all existing COM ports and sort them accordingly

string[] portNames = SerialPort.GetPortNames();
var sortedList = portNames.OrderBy(port => Convert.ToInt32(port.Replace(“COM”, string.Empty)));
foreach (string port in sortedList)
{
Console.WriteLine(port);
}

iBatis: SQLNestedException:Cannot get a connection, pool error Timeout waiting for idle object »

When this happened, and you are sure that the connection pool is actually enough to handle all the transactions, then most probably that there is a connection leakage lying within your application. E.g. the connection is not closed properly.
One example in iBATIS is that you start a transaction, but does not end it.

sqlMapClient.startTransaction();
 
// other codes […]

.NET: Detect String Encoding »

Here is a simple way to detect if your content is ASCII or Unicode

public void CheckForEncoding(string content)
{
int i = 0;
for (i = 1; i <= content.Length; […]

Java: Alter Oracle Session Information using iBATIS »

There are times that you may want to alter Oracle session information. If you are using iBATIS, this can be done the following way
Create the update statement. E.g.

<?xml version=“1.0″ encoding=“UTF-8″ ?>
<!DOCTYPE sqlMap PUBLIC “-//ibatis.apache.org//DTD SQL Map 2.0//EN” “http://ibatis.apache.org/dtd/sql-map-2.dtd” >
<sqlMap namespace=“TEST”>

<update id=“update_sort_area_size” parameterClass=“int”>
[…]

.NET String Enumeration »

Normally you cannot use string in enum. However you can bypass using a trick, as shown below.

/// <summary>
/// Response expected from the gateway
/// </summary>
public enum Response
{
/// <summary>
/// No respons expected, just return the result
/// </summary>
[StringValue(“NONE”)]
None,
[…]

Performance Tuning for Embedded System »

Performance tuning for embedded system is quite different from conventional programming

Avoid Creating Objects
Use Native Methods
Prefer Virtual Over Interface
Prefer Static Over Virtual
Avoid Internal Getters/Setters
Cache Field Lookups
Declare Constants Final
Use Enhanced For Loop Syntax With Caution
Avoid Enums
Use Package Scope with Inner Classes
Avoid Float
Some Sample Performance Numbers
Closing Notes