RSS Feed for ProgrammingCategory: Programming

SubSonic SELECT IN and BETWEEN »

For the SQL “select … from table where value in (v1, v2)”, in SubSonic you need to use the SqlQuery statement 1: // numbers is a List<string> 2: SqlQuery query = new Select().From("Pick44D").Where(Pick44DTable.MatchedNoColumn).In(numbers).OrderDesc(new string[] { "DrawDate" }); 3: List<Pick44D> result = query.ExecuteTypedList<Pick44D>(); To add the BETWEEN clause 1: // SqlDateFormat = yyyy-MM-dd 2: SqlQuery query [...]

SubSonic SQLite Data Mappings »

int maps to Int32 integer maps to Int64 bit maps to boolean guid maps to Guid long maps to Int64 For the complete listing, please see below code snippet from SubSonic 1: switch(sqlType) 2: { 3: case "varchar": 4: return DbType.AnsiString; 5: 6: case "nvarchar": 7: return DbType.String; 8: 9: case "int": 10: return DbType.Int32; [...]

SubSonic: Select Distinct Column Values »

To do a select distinct from a column for a database table using SubSonic, it is very straightforward Below is the code to get the unique customer number from the Customer table, and order them in descending order 1: Customer.All().Select(c => c.CustomerNo).Distinct().OrderByDescending(c => c) .

C# UserControl: Detect Design Mode »

When developing a user control in .NET, if certain codes are not meant to be run in design mode, then you should check for it and avoid executing those code 1: /// <summary> 2: /// Handles the Load event of the MenuPanel control. 3: /// </summary> 4: /// <param name="sender">The source of the event.</param> 5: [...]

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 [...]

.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 PartnerLink properties –> 5: </partnerLinkBinding> If  the WebService is on the SAME host as [...]

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, the ora:toCDATA() is introduced [...]

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++){ 2: attachment = mItem.Attachments[loop]; 3: if(attachment.Type == Outlook.OlAttachmentType.olOLE){ [...]

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 [...]

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 [...]

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 [...]

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 java.net.Proxy; 6: import java.net.ProxySelector; 7: import java.net.SocketAddress; 8: import java.util.List; 9:  [...]

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 [...]

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 [...]

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(); [...]