By Sumit Gupta on April 26, 2013
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.
Posted in .NET, C#.NET, VB.NET/VB, WPF | Tagged Self Hosted Web service, ServiceHost, WebServiceHost |
By Sumit Gupta on April 10, 2013
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
1
2
3
4
| 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.
Posted in .NET, C#.NET, VB.NET/VB, WPF | Tagged ComboBox, DataBinding, DataTable, WPF |
By Sumit Gupta on April 8, 2013
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
| namespace MyCommonLibrary
{
/// <summary>
/// Deletgate for Tab Closing
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public delegate void CloseTab(ITabbedWindow sender, EventArgs e);
/// <summary>
/// Delegate to reload Tab Data.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public delegate void ReloadTabData(ITabbedWindow sender, EventArgs e);
/// <summary>
/// Interface for Tabbed Windows Style MDI.
/// </summary>
public interface ITabbedWindow
{
/// <summary>
/// Event for Closing Tab handle
/// </summary>
event CloseTab CloseInitiated;
/// <summary>
/// Event to reload Tab Data
/// </summary>
event ReloadTabData Reload;
/// <summary>
/// Name of the Tab Window
/// </summary>
string TabName { get; set; }
/// <summary>
/// Title of the Tab Window
/// </summary>
string TabTitle { get; set; }
/// <summary>
/// If Tab is loaded fully.
/// </summary>
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
| #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.
Posted in C#.NET, Concept/algorithm, Programming, VB.NET/VB | Tagged MDI, Tab, TabControl |
By Sumit Gupta on February 13, 2013
This is one of best birthday I had. I was to attend my in-law’s marriage eve and there I got this surprise party by my in-laws. Really grateful and happy to get such a surprise. Never celebrate my birthday with so much noise and happy cheers all around. Feels like special person. Hardly much to say especially with words. Funny thing I cut two cakes to share the joy from all around, when I wasn’t expecting even one.
Sometime break from work and having such surprise makes your day and put a mark on your life. I really cannot forgot all the love and wishes and happy face from that day. I miss few people who too like me are not known of event and were not present, but that is part of surprise parties. Thanks again for all those who planned celebration and make me feel special.
Thanks for all and god bless everyone.
Posted in Joyous |
By Sumit Gupta on January 30, 2013
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.
Posted in HTML/CSS | Tagged css tricks, z-index |
By Sumit Gupta on January 10, 2013
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 …
Posted in Joyous, PHP, Programming, Wordpress | Tagged Developer, Plugin, Wordpress |
By Sumit Gupta on December 29, 2012
This is quick steps on how to create your own Language file for wordpress plugin. I hope you know that you can call wordpress localization functions as
1
| echo __('text your want to display', 'your-unique-language-textdomain'); |
This localization is done using internal function of wordpress, where it load language file for given language wordpress is set, and then loading relevant language files for translation Since you are making your own plugin you need to create your own language file. So to do that simply do this:
1. Download POEdit software from : http://sourceforge.net/projects/poedit
2. Now create a new catalogue and define the Source Path as your plugin folder.
3. Define keywords as “__” double underscore and “_e” .
4. Once done click “Update” or “parse code” to prepare dictionary of text.
5. Simply select text and edit it in your language.
6. Now save the file in a folder within your plugin folder with any name just add dash followed by Language code as you define in “WPLANG” i.e. -hi-IN for Hindi-India.
7. Add or call following if you have your language file in “lang” folder or change path as per your language file path.
1
| load_plugin_textdomain('your-unique-language-textdomain', false, basename( dirname( __FILE__ ) ) . '/lang'); |
8. Enjoy
Posted in Wordpress | Tagged Globalization, Internationalization, Language, Localization, Wordpress |
Recent Comments