Sideways Sliding DIV (Animated Sideways Sliding Panel in Javascript)

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Last week I was in need of a DIV that could slide sideways. My search on the internet led me to an useful article on up and down sliding DIV by Harry Maugans. But I could not find a sideways sliding DIV that could be readily used. So I decided to write my own. The JS code is listed below.

Start out by placing a hyperlink and a DIV on your web page, as shown below.



Next, place the following javascript code within the head tag of your web page. Just remember to remove all the BR tags from the JS code below :)



And of course don't forget to initialize the the DIV on page onload event by calling the Init function.

Auto Incrementing Primary Key in ORACLE

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
You will have to do the following in order to achieve an auto incrementing primary key in oracle. First, create a table with a primary key.

CREATE TABLE OwnerSchema.Users
(
UserId NUMBER NOT NULL,
UserName VARCHAR(30) NOT NULL
)
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
NOMONITORING;

COMMIT;

ALTER TABLE OwnerSchema.Users ADD (
CONSTRAINT Users_PK
PRIMARY KEY
(UserId));

COMMIT;

Then create a sequence, this will be used to read the primary key values from.

CREATE SEQUENCE Users_Seq
START WITH 1
INCREMENT BY 1
NOMAXVALUE;

COMMIT;

Finally, create a trigger to auto increment the primary key using the sequence.

CREATE TRIGGER OwnerSchema.Users_Trigger
BEFORE INSERT ON OwnerSchema.USERS FOR EACH ROW
BEGIN
SELECT Users_Seq.NEXTVAL INTO :NEW.UserId FROM Dual;
END;

How to read server response in C#.NET

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------

The following snippet shows how to read the text/html/xml response from a remote server through .NET code. This technique can be employed as part of a page scrapping service also.

string _strContent = String.Empty;
StreamReader _objSR;
WebResponse _objResponse = null;
WebRequest _objRequest = HttpWebRequest.Create("http://domain.server/Proxy/Controller.aspx?Op=someoperand");
int _contentLength = 0;
_objRequest.Method = "GET";
_objRequest.Credentials = CredentialCache.DefaultCredentials;
_objResponse = _objRequest.GetResponse();
_objSR = new StreamReader(_objResponse.GetResponseStream(), Encoding.ASCII);
_strContent = _objSR.ReadToEnd();
_contentLength = _strContent.Length;
_objSR.Close();
_objResponse.Close();

You can then parse the response as needed for your consumer application.

System.Data.OracleClient requires Oracle client software version 8.1.7 or greater - Resolved!

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
If this .NET exception happens without any reasonable cause, then it might be resolved by re-mapping permissions, at leasyt in my case it did. This error can happen if you have recently upgraded to a newer version of Oracle client (in my case it happenned after I upgraded to 9.2). To resolve this issue follow the following steps.

1. Browse to the Oracle root folder (my case, d:\oracle\Ora92)

2. In this folder's properties window, goto the Security tab and check whether 'Authenticated Users' is present. If not then add this user.

3. Now check the following properties for 'Authenticated Users'. If they are already checked then you must uncheck them first and then re-check them again - this is part of the trick.
-Read & Execute
-List Folder Contents
-Read

4. Next part of the trick is to ensure that in the Advanced permissions section, the 'Authenticated Users' have 'This folder, Sub folder and files' in the Apply To column. Be very careful with what you do in the advanced permissions window as flawed changes might have undesirable effects on rest of the folder hierarchy permissions.

That is all. A system restart was not needed in my case.

How to execute an EXE executable or a BAT file from .NET code?

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
The following code will allow you to invoke and execute an executable file from your program (here it has been written in C#). The WaitForExit() function provides your program control with the capability of synchronous execution. Refer to the 'System.Diagnostics' assembly for utilizing the 'Process' object.

public bool RunExecutable(string strExePath)
{
bool _bSuccess = true; //Assume by default that the executable will run successfully
Process _objProcess = new Process();
_objProcess.EnableRaisingEvents = false;
_objProcess.StartInfo.FileName = strExePath; //Eg, D:\Test\TestProg.exe
try
{
_objProcess.Start();
_objProcess.WaitForExit();
}
catch(Exception e)
{
//If any exception happens during attempted run
_bSuccess = false;
}
return _bSuccess;
}

Website Monitoring Code written in C# .NET

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Today I wrote an alerting tool. The tool would sit as a NotifyIcon on your system tray, and keep monitoring a website to find whether it went down. I will devote writing a windows application to run and be controlled from the system tray at a later post. This post concentrates on just the web URL monitoring.

public bool IsWebSiteDown(string strURL)
{
bool _errorCondition = false;
string _strContent = String.Empty;
StreamReader _objSR;
WebResponse _objResponse = null;
WebRequest _objRequest = HttpWebRequest.Create(strURL);
string _strSource = strServiceIdentifier;
int _contentLength = 0;
try
{
_objResponse = _objRequest.GetResponse();
_objSR = new StreamReader(_objResponse.GetResponseStream(), Encoding.ASCII);
_strContent = _objSR.ReadToEnd();
_contentLength =_strContent.Length;
_strSource = _contentLength.ToString();
_objSR.Close();
_objResponse.Close();
}
catch(Exception e)
{
_errorCondition = true;
}
return _errorCondition;
}

How to determine if a file is being used by another process?

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Here is a utility function written in C#.NET that can be used to determined whether a file is in use by another process. I used it in one of the file routing windows services that I wrote, you can reuse this as needed. The trick is to request exclusive access to the file using 'FileShare.None' enumeration value. The function will throw an exception if the file is already open by another process.

private bool IsFileInUse(FileInfo objFileInfo)
{
FileStream _objFileStream = null;
try
{

if(objFileInfo.Exists)
{
_objFileStream = objFileInfo.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);

}
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread

return true;
}
finally
{
if (_objFileStream != null)
_objFileStream.Close();
}
//file is not locked
return false;
}

IIS 503 Service Unavailable Problem (One of many)

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
The 503 problem can occur due to a variety of reasons. Literature on diferent scenarios is available at the link below. The focus of this article is an issue that occurred with incorrect installation of McAfee Host Intrusion Prevention (disclaimer: this was not a problem with the McAfee software, but is attributed to the way it was installed on the server).
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/55f71614-ef1b-4015-b9c8-a42c1e700c25.mspx?mfr=true

Once you face the 503 issue, the first step is to find out the root cause. First find the actual error logged in the HTTP Error log available on the server path (default location and filename is configurable):
%windir%\System32\LogFiles\HTTPERR

A sample entry is provided below (the IP addresses have been masked for the purpose of my client's privacy):
2009-10-28 16:57:23 10.x.x.xxx 1590 10.xx.xx.xxx 80 HTTP/1.1 GET /testsite/default.aspx?Op=All 503 1 AppOffline TestSiteAppPool

The second last column value 'AppOffline' is of interest as it will tell you exactly why this error occurred. The exact meaning of this word can be found at
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/55f71614-ef1b-4015-b9c8-a42c1e700c25.mspx?mfr=true

For example, 'AppOffline' means the application pool has been put into Rapid Fail Protection and has been disabled automatically. At this point we have pined down the actual issue. In my case this was not sufficient so I looked at the error logs from event viewer and found the following entry:
The HTTP Filter DLL C:\Program Files\McAfee\Host Intrusion Prevention\eng\isapi\IsapiStub.dll failed to load. The data is the error. Data Bytes 7e 00 00 00

Next I checked and found that the above ISAPI filter did not exist. The IIS metabase got modified to route incoming requests to a filter in the Host Intrusion Prevention directory. But the filter was not present on the server due to improper installation performed by our server admin group. We got the Host Intrusion Prevention removed from the server by our server admins and got them to correct their automated installation scripts.

Windows Polling Agent Service

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
In this article the basic framework to write a polling agent as a windows service has been explained. The poller is hosted as a windows service (out of scope of this article), and the poller itself is designed to start up at regular intervals of time and perform a designated activity. The polling mechanism is defined in the 'PollerWorker' function below. Bootstrapping into this PollerWorker function has been accomplished using a Timer object in the service OnStart function. A global variable _keepRunning has been used to break out of the PollerWorker function when the service is manually stopped from the Windows Service Console Manager.

public partial class PollerAgent: ServiceBase
{
Timer _objTimer = new Timer();
bool _keepRunning;
public PollerAgent()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
_keepRunning = true;
_objTimer.Elapsed += new ElapsedEventHandler(PollerWorker);
_objTimer.Interval = 300000;
_objTimer.Enabled = true;
}
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
_keepRunning = false;
_objTimer.Enabled = false;
}
private void PollerWorker(object source, ElapsedEventArgs e)
{
while (_keepRunning == true)
{
//Write code to perform polling activities here

//Suspend the current execution thread
//Polling will resume again after specified amount of time
System.Threading.Thread.Sleep(300000);
}
}
}

Sending SMTP Mail via C# .NET

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
As a pre-requisite, SMTP service must be installed in IIS on the server from which the mail sending program will be running. For more details on SMTP service setup read guidance from Microsoft at http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e4cf06f5-9a36-474b-ba78-3f287a2b88f2.mspx?mfr=true

The main class that you need to refer is:
using System.Web.Mail;

Then you may write the function to send an e-mail as shown below:
public bool SendEMail()
{
//Prepare the e-mail object
MailMessage objMailMessage = new MailMessage();
objMailMessage.BodyFormat = MailFormat.Html;
objMailMessage.Priority = MailPriority.High;
objMailMessage.To = "to@tocompany.com";
objMailMessage.From = "from@yourcompany.com";
objMailMessage.Subject = "Hi - Test Mail";
objMailMessage.Body = "Hello world.";

//Send the e-mail
SmtpMail.SmtpServer = "server.domain.com";

SmtpMail.Send(objMailMessage);
}

Runtime Assembly Binding Redirect (Multiple Websites - Multiple DLLs Dilemma)

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Suppose you have to use the latest version of a DLL without compiling the project. Or it might be that there are mulple versions of a DLL in the web server Global Assemble Cache (GAC) and there are multiple web applications hosted on this server and

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="CrystalDecisions.CrystalReports.Engine"
publicKeyToken="692fbea5521e1304"
culture="neutral" />
<bindingRedirect oldVersion="10.2.3600.0"
newVersion="11.5.3700.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

The beauty of this version redirecting also allows you to provide a range in the oldVersion property, so you could point all previous version of a DLL to a particular version!

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="CrystalDecisions.CrystalReports.Engine"
publicKeyToken="692fbea5521e1304"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-11.0.0.0"
newVersion="11.5.3700.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Migrating .NET 2.0 codebase to 3.5

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Prerequisites for development:
1. Windows XP/Windows 2003
2. Visual Studio 2008
3. .NET 3.5 Framework
4. Add-Ons (like AJAX Extensions, Enterprise Library, Oracle Client, Crystal Reports, etc)

Prerequisites for test server:
1. Windows 2003 Server
2. .NET 3.5 Framework
3. Add-Ons (like AJAX Extensions, Enterprise Library, Oracle Client, Crystal Reports, etc

Migration Method:
1. Make a copy of the codebase (v2.0) and open the codebase using Visual Studio 2008.
2. VS 2008 will do whatever it needs to do and covert the 2.0 code to as much 3.5 as possible.
3. Specify the target framework property. Refer to http://msdn.microsoft.com/en-us/library/bb398202.aspx
4. Now compile the codebase in VS 2008 - it might list errors and warnings.
5. Fix the errors and warnings as needed.

Estimated Effort:
1. Code migration can be as little as under one day to several days depending on size and complexity.
2. The main effort will be Remediation testing.

Migrating .NET 1.1 codebase to 3.5

-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Prerequisites for development:
1. Windows XP/Windows 2003
2. Visual Studio 2008
3. .NET 3.5 Framework
4. Add-Ons (like AJAX Extensions, Enterprise Library, Oracle Client, Crystal Reports, etc)

Prerequisites for test server:
1. Windows 2003 Server
2. .NET 3.5 Framework
3. Add-Ons (like AJAX Extensions, Enterprise Library, Oracle Client, Crystal Reports, etc

Migration Method:
1. Make a copy of the codebase (v1.1) and open the codebase using Visual Studio 2008.
2. VS 2008 will do whatever it needs to do and covert the 1.1 code to as much 3.5 as possible.
3. Now compile the codebase in VS 2008 - it will list errors and warnings.
4. Fix the errors and warnings as needed. You may refer the list of breaking chnages introduced in the .NET Framework's 2.0 onwards.

Reference (of Breaking Changes in .NET)
1. http://msdn.microsoft.com/en-us/netframework/aa570326.aspx

Estimated Effort:
1. Code migration can be as little as under one day to several days depending on size and complexity.
2. The main effort will be Remediation testing.