Tuesday, 26 August 2014
Satellite Assembly Example in C# (Step by Step)
Satellite Assembly Example in C# (Step by Step)
Download source code (TestApp.zip) - 47.2 KB
Introduction
This article is about how to understand and implement a satellite assembly.Background
A satellite assembly is a .NET Framework assembly containing resources specific to a given language. Using satellite assemblies, you can place resources for different languages in different assemblies, and the correct assembly is loaded into memory only if the user selects to view the application in that language.(Source: http://vb.net-informations.com/framework/satellite-assembly.htm)
Using the code
Here is the step by step procedure to create an application with a satellite assembly:1.Create a new Windows project (say: TestApp).
2.Add a ComboBox (name it
cmbLanguage) and two Labels (one label for “Select Language” and the other for Displaying the Result (name it lblMultiLangResult)) as shown below:1. Add three Resx files (string.en-US.resx, string.he.resx, and string.ar-sa.resx for English, Hindi, and Arabic, respectively). Note: For other language codes, visit: http://msdn.microsoft.com/en-us/library/ms533052(v=vs.85).aspx
2. In the resx files, enter the values shown below:
5. Next, open the code file (.cs file) and create the object for the resource manager at class level:
System.Resources.ResourceManager rm = new System.Resources.ResourceManager("TestApp.string", Assembly.GetExecutingAssembly());
Here in the first parameter: TestApp is the name of your Windows Application and string
is the name of the Resource file part before the language code. Second
parameter is the Main Assembly for the resources (for this you have to
add the namespace: using System.Reflection;).
6. Write the following function for the culture: private void ChangeCulture(string sLangCode)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(sLangCode);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(sLangCode);
lblMultiLangResult.Text = rm.GetString("lblResult");
}
For the above function to run, please add the following namespaces:
using System.Threading; //For Threading
using System.Globalization; //For CultureInfo
7. On the ComboBox item change event, add the following code: private void cmbLanguage_SelectedIndexChanged(object sender, EventArgs e)
{
string sLangCode;
if (cmbLanguage.SelectedIndex == 0)
{
sLangCode = "en-US";
ChangeCulture(sLangCode);
}
else if (cmbLanguage.SelectedIndex == 1)
{
sLangCode = "he";
ChangeCulture(sLangCode);
}
else if (cmbLanguage.SelectedIndex == 2)
{
sLangCode = "ar-sa";
ChangeCulture(sLangCode);
}
}
8. On page load, add the following line of code: ChangeCulture("en-US");
9. Run the application and see the output as below:Points of Interest
When you look at ApplicationFolder/bin/release (check bin/debug if you are running in debug mode), there are three folders containing the same name of the DLL but each for different culture. The correct one will load when the user selects one of them.GROUPING SETS in SQL Server 2008
First, let's see how we rewrite simple WITH ROLLUP and CUBE queries
using the new syntax. I'll use the same schema and queries as in my
previous posts:
The new GROUPING SETS syntax is considerably more powerful. It allows us to specify precisely which aggregations we want to compute. As the following table illustrates, our simple two dimensional schema has a total of only four possible aggregations:
ROLLUP and CUBE are just shorthand for two common usages of GROUPING SETS. We can express the above ROLLUP query as:
As with any other aggregation query, if a column appears in the SELECT list and is not part of an aggregate function, it must appear somewhere in the GROUP BY clause. Thus, the following is not valid:
We can nest CUBE and ROLLUP within a GROUPING SETS clause as shorthand for expressing more complex GROUPING SETS. This shorthand is most useful when we have more than three dimensions in our schema. For example, suppose we add a month column to our sales table:
The new GROUPING SETS syntax is available in all of SQL Server 2008 Community Technology Preview (CTP) releases.
CREATE TABLE Sales (EmpId INT, Yr INT, Sales MONEY)We can rewrite these two queries using the new syntax as:
INSERT Sales VALUES(1, 2005, 12000)
INSERT Sales VALUES(1, 2006, 18000)
INSERT Sales VALUES(1, 2007, 25000)
INSERT Sales VALUES(2, 2005, 15000)
INSERT Sales VALUES(2, 2006, 6000)
INSERT Sales VALUES(3, 2006, 20000)
INSERT Sales VALUES(3, 2007, 24000)
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY EmpId, Yr WITH ROLLUP
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY EmpId, Yr WITH CUBE
SELECT EmpId, Yr, SUM(Sales) AS SalesThese new queries are semantically equivalent to and use the same query plans as the original queries. Note that the new ROLLUP and CUBE syntax is only available in compatibility level 100. The more general GROUPING SETS syntax, which I will discuss next, is also available in earlier compatibility levels.
FROM Sales
GROUP BY ROLLUP(EmpId, Yr)
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY CUBE(EmpId, Yr)
The new GROUPING SETS syntax is considerably more powerful. It allows us to specify precisely which aggregations we want to compute. As the following table illustrates, our simple two dimensional schema has a total of only four possible aggregations:
Yr
| |||||
| 2005 | 2006 | 2007 | ALL | ||
| EmpId | 1 | GROUP BY (EmpId, Yr) | GROUP BY (EmpId) | ||
| 2 | |||||
| 3 | |||||
| ALL | GROUP BY (Yr) | GROUP BY () | |||
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr), (EmpId), ())
EmpId Yr Sales ----------- ----------- --------------------- 1 2005 12000.00 1 2006 18000.00 1 2007 25000.00 1 NULL 55000.00 2 2005 15000.00 2 2006 6000.00 2 NULL 21000.00 3 2006 20000.00 3 2007 24000.00 3 NULL 44000.00 NULL NULL 120000.00This query explicitly asks SQL Server to aggregate sales by employee and year, to aggregate by employee only, and to compute the total for all employees for all years. The () syntax with no GROUP BY columns denotes the total. Similarly, we can express the above CUBE query by asking SQL Server to compute all possible aggregate combinations:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr), (EmpId), (Yr), ())
EmpId Yr Sales ----------- ----------- --------------------- 1 2005 12000.00 2 2005 15000.00 NULL 2005 27000.00 1 2006 18000.00 2 2006 6000.00 3 2006 20000.00 NULL 2006 44000.00 1 2007 25000.00 3 2007 24000.00 NULL 2007 49000.00 NULL NULL 120000.00 1 NULL 55000.00 2 NULL 21000.00 3 NULL 44000.00We can also use GROUPING SETS to compute other results. For example, we can perform a partial rollup aggregating sales by employee and year and by employee only but without computing the total for all employees for all years:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr), (EmpId))
EmpId Yr Sales ----------- ----------- --------------------- 1 2005 12000.00 1 2006 18000.00 1 2007 25000.00 1 NULL 55000.00 2 2005 15000.00 2 2006 6000.00 2 NULL 21000.00 3 2006 20000.00 3 2007 24000.00 3 NULL 44000.00We can skip certain rollup levels. For example, we can compute the total sales by employee and year and the total sales for all employees and all years without computing any of the intermediate results:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr), ())
EmpId Yr Sales ----------- ----------- --------------------- 1 2005 12000.00 1 2006 18000.00 1 2007 25000.00 2 2005 15000.00 2 2006 6000.00 3 2006 20000.00 3 2007 24000.00 NULL NULL 120000.00We can even compute multiple unrelated aggregations along disparate dimensions. For example, we can compute the total sales by employee and the total sales by year:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId), (Yr))
EmpId Yr Sales ----------- ----------- --------------------- NULL 2005 27000.00 NULL 2006 44000.00 NULL 2007 49000.00 1 NULL 55000.00 2 NULL 21000.00 3 NULL 44000.00Note that we could also write GROUPING SETS (EmpId, Yr) without the extra set of parenthesis, but the extra parenthesis make the intent of the query more explicit and clearly differentiate the previous query from the following query which just performs a normal aggregation by employee and year:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr))
EmpId Yr Sales ----------- ----------- --------------------- 1 2005 12000.00 2 2005 15000.00 1 2006 18000.00 2 2006 6000.00 3 2006 20000.00 1 2007 25000.00 3 2007 24000.00Here are some additional points worth noting about the GROUPING SETS syntax:
As with any other aggregation query, if a column appears in the SELECT list and is not part of an aggregate function, it must appear somewhere in the GROUP BY clause. Thus, the following is not valid:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId), ())
Msg 8120, Level 16, State 1, Line 1The order of the columns within each GROUPING SET and the order of the GROUPING SETS does not matter. So both of the following queries compute the same CUBE although the order that the rows are output differs:
Column 'Sales.Yr' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr), (EmpId), (Yr), ())
SELECT EmpId, Yr, SUM(Sales) AS SalesIf the order that the rows are output matters, use an explicit ORDER BY clause to enforce that order.
FROM Sales
GROUP BY GROUPING SETS((), (Yr), (EmpId), (Yr, EmpId))
We can nest CUBE and ROLLUP within a GROUPING SETS clause as shorthand for expressing more complex GROUPING SETS. This shorthand is most useful when we have more than three dimensions in our schema. For example, suppose we add a month column to our sales table:
CREATE TABLE Sales (EmpId INT, Month INT, Yr INT, Sales MONEY)Now, suppose we want to compute sales for each employee by month and year, by year, and total. We could write out all of the GROUPING SETS explicitly:
SELECT EmpId, Month, Yr, SUM(Sales) AS SalesOr we can use ROLLUP to simplify the query:
FROM Sales
GROUP BY GROUPING SETS((EmpId, Yr, Month), (EmpId, Yr), (EmpId))
SELECT EmpId, Month, Yr, SUM(Sales) AS SalesNote that once again the correct use of parenthesis is critical. If we omit one set of parenthesis from the above query, the meaning changes significantly and we end up separately aggregating by employee and then computing the year and month ROLLUP for all employees.
FROM Sales
GROUP BY GROUPING SETS((EmpId, ROLLUP(Yr, Month)))
The new GROUPING SETS syntax is available in all of SQL Server 2008 Community Technology Preview (CTP) releases.
What is the difference between Web Farm and Web Garden?
What is the difference between Web Farm and Web Garden?
I
have been asked this question many times by different readers of my
blog. They wanted to know about the fundamentals of Web Farms and Web
Garden. In this blog post, I am going to explain the exact difference
between web farm and web garden, and the advantages and disadvantages of
using them. I have also described how to create web garden in different
version of IIS.
Overview
Visual Studio has its own integrated ASP.NET engine which is used to run the ASP.NET Web application from Visual Studio. ASP.NET Development Server is responsible
for executing all the requests and responses from the client. Now after
the end of development, when you want to host the site on some server
to allow other people to access, concept of web servers comes in
between. A web server is responsible for providing the response for all
the requests that are coming from clients. The below diagram shows the
typical deployment structure of an ASP.NET Web application with a single
IIS.
Clients request for resources and IIS process the request and send back to clients. If you want to know more details on How IIS Processes the request, please read one of my articles about “How IIS Process ASP.NET Request?”.
Web Farm
This
is the case where you have only one web server and multiple clients
requesting for resources from the same server. But when are is huge
amount of incoming traffic for your web sites, one standalone server is
not sufficient to process the request. You may need to use multiple
servers to host the application and divide the traffic among them. This
is called “Web Farm”. So when you are hosting your single web site on multiple web servers over load balancer is called “Web Farm”. The below diagram shows the overall representation of Web Farms.
In
general web farm architecture, a single application is hosted on
multiple IIS Server and those are connected with the VIP (Virtual IP)
with Load Balancer. Load Balancer IPs are exposed to external world to
access. So whenever some request will come to server from clients, it
will first hit the Load Balancer, then based on the traffic on each
server, LB distributes the request to the corresponding web server.
These web servers may share the same DB server or may be they can use a
replicated server in the back end.
So,
in a single statement, when we host a web application over multiple web
servers to distribute the load among them, it is called Web Farm.
Web Garden
Now,
let’s have a look at what is Web Garden? Both the terms sound the same,
but they are totally different from each other. Before starting with
Web Garden, I hope you have a fundamental idea of what an Application
Pool is and what a Worker Process is. If you have already read the
article, “How IIS Processes ASP.NET Request ?”, then I can expect that you now have a good idea about both of them.
Just to recall, when we are talking about requesting processing within IIS, Worker Process (w3wp.exe)
takes care of all of these. Worker Process runs the ASP.NET application
in IIS. All the ASP.NET functionality inside IIS runs under the scope
of worker process. Worker Process is responsible for handling all kinds
of request, response, session data, cache data. Application Pool is the
container of worker process. Application pool is used to separate sets
of IIS worker processes and enables a better security, reliability, and availability for any web application.
Now,
by default, each and every Application pool contains a single worker
process. Application which contains the multiple worker process is
called “Web Garden”. Below is the typical diagram for a web garden application.
In the above diagram, you can see one of the applications containing the multiple worker processes, which is now a web garden.
So,
a Web application hosted on multiple servers and access based on the
load on servers is called Web Farms and when a single application pool
contains multiple Worker processes, it is called a web garden.
Create Web Garden in IIS 6 and IIS 7
Now,
I am going to show how you can change the Number of Worker processes in
both IIS 6 and IIS 7. For IIS 6, Right Click on Application Pool >
Properties > Goto Performance Tab.
In
the “Performance Tab” section, you would have one option called “Web
Garden” where worker process sets to “1”, you can set the number of
worker processes that you required.
For
IIS 7, Right Click on Application Pool > Go To Advance Settings >
In Process Model section, you will have “Maximum Worker Processes”. You
can change it more than 1 to make it as a web garden.
In the above image, you can also check the definition of Web Garden.
You can find one of my previous articles on the basics of the same over here.
Advantages of Web Farm and Web Garden
Now, let’s have a look into the advantages of both the Web Farms and Web Gardens.
Advantages of Web Farm
- It provides high availability. If any of the servers in the farm goes down, Load balancer can redirect the requests to other servers.
- Provides high performance response for client requests.
- Provides better scalability of the web application and reduces the failure of the application.
- Session and other resources can be stored in a centralized location to access by all the servers.
Advantages of Web Garden
- Provides better application availability by sharing requests between multiple worker process.
- Web garden uses processor affinity where application can be swapped out based on preference and tag setting.
- Less consumption of physical space for web garden configuration.
How to Manage Session in Web Farm Mode?
While
using session, requests are distributed among different servers. By
default, session mode is set to In Proc where session data is stored
inside worker process memory. But, in Web farm mode, we can share the
session among all the servers using a single session store location by
making it Out proc (State Server or SQL Server Mode). So, if some of the
servers go down and request is transferred to the other server by the
Load balancer, session data should be available for that request.
In
the above diagram, you can see that we can both the IIS server sharing
the same session data which is stored in out of worker process. You can
read one of my previous articles “Exploring Session in ASP.NET” where I have explained how you can configure session mode for Out Process mode.
How to Manage Session in Web Garden Mode?
When
we are using Web garden where request is being taken care of by
different worker process, we have to make the session mode as out
process session mode as described earlier. For Web Garden, we have to
configure the out process within the same server but for different
worker process.
While using Web garden with your application, you need make a couple of configuration settings inweb.config in
<process Model> section where you need to set certain properties like cpuMask,RequestLimit, webGarden, ClientConnectCheck, etc.Summary
When
we host a web application over multiple web servers to distribute the
load among them, it is called Web Farm and when one application has
multiple worker processes, it is called a Web garden.
In
this blog post, I have explained the very basics of what a Web Farm is
and what a Web Garden is. As this blog post contains the basic
information to understand the fundamentals of web farms and web garden
concept, I will be posting a separate article with details configuration
setting for web garden and web farm. You can read the following
articles for more information:
- Boosting performance using an IIS web garden
- How-To Configure Session State in a Windows Web Farm
- Role of Web gardens and web farms in ASP.NET
Hope this will help you.
Subscribe to:
Posts (Atom)
C# LINQ Joins With SQL
There are Different Types of SQL Joins which are used to query data from more than one database tables. In this article, you will learn a...
-
Top 80 + SQL Query Interview Questions and Answers with Examples Interview Questions on SQL are based on following two tables, Employ...
-
ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer PRB: ThreadAbortException Occurs If You Use R...
-
SQL Server Interview Questions : Database What is DBMS ? What is RDBMS ? What are the ACID properties? What is Normalization? What i...