Categories
Bookmarked Wordpress

Some Cool WordPress Plugin

Lately, I got lot of wordpress site, that were not just blog or business website. But they are ecommerce, Restaurant Ordering, Video streaming and much more. Been a developer I always remain engage in making some sort of plugin for them. Though following list of plugin assist me a big time in saving time to do some of works I usually have to do to make some really nasty site in wordpress:

The list is of plugin I usually use, but not restricted to. There are couple more of plugin but currently I am unable to recall them. Meanwhile we also create a small plugin used for very limited set of user:

https://github.com/Vikasumit/wpl [Allow only members to see the complete site].

I have few other plugin coming up, but still not ready to launch them in public as they are not yet finish or are mature products. Love the fact that WordPress plugin development is as cool as working on any other project. Just need some good idea to make it possible.

Categories
Blog: My thoughts MS SQL Server Programming SQL SQlite

Reading Large Binary Files: Child Play

Yes, that was funny title, but after your experience it you will agree to me. So, here is the story. I have been working on a software that read some recording from hardware device to database, we have 45 records per second for 30 days, so it is about 30x24x60x60 record entry with 45 columns in it. We have to make a desktop application so we choose .NET for it. The first version of software was released by my company 3 yrs ago, and the reading well, we were inexperience at that time to manage that data, and what we get is about 2 hrs to read all that data to database. Oh, I forgot to tell that 30 days entry was from one hardware device and we have 3-4 device :), so we took 2 hr to read all say 4 devices. Now that is not acceptable thing. So, we decide to rewrite the complete software to make use of some parallelism, as that is only way my team thing it is going to work.

I start the rewrite, and with only hope to reduce to 2 hr work to 30-45 minute I start writing code, but this time we make a exception from last time, instead of using TEXT ascii file or SQLite database, we opt to use SQL Server to store our data. Reason, well first pre-release version of software use Text file, we never get that part working for more than 15 days, and it always get out of memory for one or other reason. Then we start using Sqlite which is 5 times lighter on hardware and speed the reading and information access, however, there is part which still use text file. So, in order to avoid two source we opt for database only, and Since client already have Sql Server on seperate machine, we thought it is good to have seperate machine storing database, for long term and obviously LAN benefits. Since client already have SQL Server and we are using .NET I decide to go with Sql Server, only.

So, we start reading binary file, and start putting insert query for each record [just for testing the lowest speed], and it goes through in 12-13 minutes. wow, we already reduce 30-40 minute job to 12 minutes, just by using full time database. Now, the next challenge is to speed it up with known bulk import methods. couple of them that I tried are

1. Using Dataaset and Update feature of Dataset,

2. Using Long Insert query to send 100 or 1000 records in one “Execute”

3. Using SqlBulkCopy feature in .NET. This is obvious choice on speed, but in few cases it fails for me, so I have to look for first two options as well.

So, at end we get SqlBulkCopy as our tool to go with, now it doesn’t simply import the data in Database. We have to prepare background for it, SqlBulkCopy is used to send data from CSV files, so we create CSV file from binary read, than import this file to Staging Sql Table, and then transfer data from Staging Table to main table, all this is done in 2-3 minute flat. Yes, a 40 minute work is done in 3 minutes. Period.

The trick is, we reduce the number of operation needed to write to disk, we still create CSV, but perviously we are creating XML File, secondly, we have multiple file write procedure going, we remove all this. Infact to achieve that speed we even stop writing LOG file to trace error, we use SQL server to record those error for us. Infact removing Log Text file with SQL error log, itself speed things from 5 minutes to 3 minutes. though logs ar enot that long, but disk writing is very slow as compare to database insert.

All said, I will hardly use plain text file in future for long data read, it will be some sort of database for sure.

Categories
.NET C#.NET VB.NET/VB WPF

Self Hosted Web Service: WebServiceHost

So today I learn about WebServiceHost. Just a normal class but it does a lot for me today. This host the web service within you Desktop/Windows Service application. i.e. you don’t need to install any Web server or other stuff, just create a Service Contract Class and use WebServiceHost to host it within your application. 

I need this as part of my project, because I have to pass some server information to my application. I initially create a Seperete web application for this, but why maintain another application and increase setup time when I can host it within. I need it for just one particular value to be pass in JSON format to my client side. However one thing I must tell here is that the Host server application must be running as Administrative privilege or the service won’t start. For Windows Service run application as “LocalSystem” rather than default LocalService to keep it working.

It solve lot of problem and architectural issue I had in my project.  

Categories
.NET C#.NET VB.NET/VB WPF

WPF ComboBox: DataBinding with DataTable

Well it seems easy thing, but it took a while for me to get it working. Frankly I still don’t know why it works this way, but at least it works. With WPF I was expecting something as easy as giving DataTable object to ComboBox by it’s property and define the Data Field and Value field as in ASP.NET dropdownlist and it will bind, but this was not the case or at least the syntax is little different. So it goes like

ComboBox cb = new ComboBox(); /// You might already have object of it, so I just create it for sake of understanding here.
cb.ItemSource = MyDataTable.Rows; /// Yup, DataTable will not bind but it's rows collection will.
cb.DisplayMemberPath = ".[" + YourColumnNameVariable + "]"; ///in other other ".[columnname]" is what is expected;
cb.SelectedValuePath = ".[" + YourColumnNameVariable2 + "]"; ///in other other ".[columnname]" is what is expected;

This is all we need to do to get it working.

Categories
C#.NET Concept/algorithm Programming VB.NET/VB

MDI Window: C# way

So how can we make MDI Parent and Child Window in C#. The answer I found was that there is nothing inbuilt for it. So, I have two choice, either I modify the Window class and add MDI [Multiple Document Interface] coding in them or I found a alternative interface. 

It took less than 5 minute to decide that I can go with alternative interface after googling, the interface is TAB. Yup, much like your browser, they use TABs too, we create tab in  web portal, browser and lot of other things. So, they are perfect replacement for MDI window needs. The logic is as simple as, 

1. Create a TabControl on Main window.

2. Add couple of function, that search for TabItem in Tabcontrol if they exists or not, if exists focus them or add a new Tab Dynamically. Same logic on deletion of tab.

3. Create User Control from your Common custom Interface class and default UserControl object. Add these user control on Tab content when adding new tab.

I again didn’t keep the URL, but there is good example on it is available on MSDN and few other tutorial site. I try to post main component of logic below

namespace MyCommonLibrary
{
    /// 
    /// Deletgate for Tab Closing
    /// 
    /// 
    /// 
    public delegate void CloseTab(ITabbedWindow sender, EventArgs e);

    /// 
    /// Delegate to reload Tab Data.
    /// 
    /// 
    /// 
    public delegate void ReloadTabData(ITabbedWindow sender, EventArgs e);

    /// 
    /// Interface for Tabbed Windows Style MDI.
    /// 
    public interface ITabbedWindow
    {
        /// 
        /// Event for Closing Tab handle
        /// 
        event CloseTab CloseInitiated;

        /// 
        /// Event to reload Tab Data
        /// 
        event ReloadTabData Reload;

        /// 
        /// Name of the Tab Window
        /// 
        string TabName { get; set; }

        /// 
        /// Title of the Tab Window
        /// 
        string TabTitle { get; set; }

        /// 
        /// If Tab is loaded fully.
        /// 
        bool IsAllowRefresh { get; set; }


        void ReloadData();
    }
}

Above one is my common Interface which I use to implement in my User Control. After this all I have to do is add below function in my Parent window which has TabControl added to it.

#region Tab Functions
 #region Tab Functions

        public void AddChildWindow(ITabbedWindow childWndow)
        {
            if (childWindows.ContainsKey(childWndow.TabName))
            {
                foreach (TabItem tabItem in MDIContainer.Items)
                {
                    if (tabItem.Name == childWndow.TabName)
                    {                        
                        tabItem.Focus();
                        if (childWndow.IsAllowRefresh)
                        {
                            childWndow.CloseInitiated += new CloseTab(childWndow_CloseInitiated);
                            tabItem.Content = childWndow;
                        }
                        ITabbedWindow uc = tabItem.Content as ITabbedWindow;
                        try
                        {
                            if (uc != null )
                            {
                                uc.ReloadData();
                            }
                        }
                        catch { }
                        break;
                    }
                }
            }
            else
            {
                TabItem tabItem = new TabItem();
                tabItem.Name = childWndow.TabName;
                tabItem.Header = childWndow.TabTitle;
                tabItem.Content = childWndow;

                childWndow.CloseInitiated += new CloseTab(childWndow_CloseInitiated);

                MDIContainer.Items.Add(tabItem);
                MDIContainer.SelectedItem = tabItem;
                ITabbedWindow uc = tabItem.Content as ITabbedWindow;
                try
                {
                    if (uc != null)
                    {
                        uc.ReloadData();
                    }
                }
                catch { }
                
                childWindows.Add(childWndow.TabName, childWndow.TabTitle);
            }
        }

        public void RefreshTabContent(string mTabName)
        {
            foreach (TabItem tabItem in MDIContainer.Items)
            {
                if (tabItem.Name == mTabName)
                {
                    tabItem.Focus();
                    ITabbedWindow uc = tabItem.Content as ITabbedWindow;
                    try
                    {
                        if (uc != null)
                        {
                            uc.ReloadData();
                        }
                    }
                    catch { }
                    break;
                }
            }
        }

        void childWndow_CloseInitiated(ITabbedWindow sender, EventArgs e)
        {
            foreach (TabItem tabItem in MDIContainer.Items)
            {
                if (tabItem.Name == sender.TabName)
                {
                    MDIContainer.Items.Remove(tabItem);
                    childWindows.Remove(sender.TabName);
                    break;
                }
            }
        }
        #endregion

I just paste the portion where I control Tab, but it goes to code behind of mainwindow.xaml. One thing to note here is I use a SortedDictionary object to store the name of Tab in it for searching and retrieval of it. Rest is clear I guess.

 

Categories
HTML/CSS

z-Index: Short note

It is been sometime I try my hand to CSS. But today when I got a chance to work on Jquery Animation to make it smoother than what it was, I realise that I never work with Z-index property. It is not that I don’t know about it, but it always is pain and I work around than using Z-Index. Today I decide to take a dig on it and did use it to make it work smooth. There is nothing much to tell about Z-index, that it just only align your Object in 3D [yup], for some saying it on layer is easier. However there are few things to note:

1. z-index is calculated relate to Sibling elements. i.e. if you set z-index on element from different parent element, then it is waste.

2. z-index doesn’t used up if elements are static or relatively positioned as in both case you already tell browser to calculate element position relative to other and or in default manner. However I read some where that it does work for few case with relative position. But it never for me. 

Once I know those things it is easier for me to use it fully. So I thought to document it here. 

Categories
Joyous PHP Programming Wordpress

Video Shopping Plugin

Just finish coding major stuff of Video plugin for wordpress that enable Purchase of Video and then view to only registered members. This use Paypal Express Checkout as payment gateway. Love coding on wordpress at time, though it is not as good as doing in custom CMS, but still very much a home for me now. I use couple of other plugin to support my plugin, but in all just love the expendability of WordPress. The hooks, filter they are all awesome. 

I love the concept of Hooks in wordpress than any other open source software I worked on. However still trying to figure why wordpress use so much of database query and why they do not certain function outside the loop. 

Telling more about my plugin, it allow admin to upload Video files, put their price. Then on front end choose filter to find video and add to cart using AJAX. once in cart you can proceed with checkout as wordpress user only and pay through paypal. View purchased video in MY Video pages, unless you are logged in you cannot view the video not from direct link too. 

Unfortunately this plugin is built on contract and need lot of work to make it generic to release under my belt, but if anyone need it I can still help with it :). Someday probably I can release this plugin under my name. What you think shall I release it free or paid …