Monday, July 30, 2012

REST



REST stands for Representational State
Transfer and was looked at in the dissertation
by Roy Thomas Fielding.
Some of the most important aspects of the
REST environment are uniquely addressable
resources, their different characteristics
and formats, a uniform and easy - to - follow programming interface, and the facilitation of a highly
scalable environment.
Implemented today, REST mainly entails the use of technologies which are already well established
in practice on the Web and which have been used to outline the advantages of REST. HTTP or
HTTPS, for example, may be used as the transfer protocol. URLs including query strings are
used to address resources, and the representation formats supported range from HTML and XML
to JSON and ATOM, as well as to sound and video fi les. The simple and intuitive programming
interface previously mentioned is achieved by using HTTP verbs and status codes.
If, for example, you point your browser at the URL http://p2p.wrox.com/content/blogs ,
status code 200 is returned and your browser displays the returned HTML in the form of a
web site. In keeping with normal web practices, the following page also contains links to other
resources and topics:
In the URL above you can also see how intuitively these URLs are structured. Or use the following
URL to receive an RSS feed:
In contrast to SOA with SOAP, REST is not concerned with the defi nition of messages and the
design of methods; central components are resources and actions which can affect those resources.
The actions which affect resources are mainly CRUD (Create, Read, Update, and Delete) methods.
What should be done with a resource is determined by means of an HTTP verb, and the success of
the action is ascertained by querying the HTTP status code.
In the following example, a GET at http://localhost:1234/CarPool shows all the cars in the
fl eet in the form of an XML document. Status code 200 indicates success.
URL: http://localhost:1234/CarPool
Verb: GET
Status-Code: 200
Response-Body:
< Cars xmlns="http://schemas.datacontract.org/2004/07/Wrox"
xmlsn:i="http://www.w3.org/2001/XMLSchemainstance"
> < Car > < Make > Dodge < /Make > < Name > Dakota < /Name > < Seats > 8 < /Seats > < Type > Pickup
Truck < /Type > < /Car > < Car > < Make > Audi < /Make > < Name > TT < /Name > < Seats > 2 < /Seats > < Type > Sport
Car < /Type > < /Car > < Car > < Make > Seat < /Make > < Name > Leon < /Name > < Seats > 5 < /Seats > < Type > Sport
Car < /Type > < /Car > < /Cars >
In the following example, a GET at http://localhost:1234/CarPool/TT shows the Audi TT in the
form of an XML document. Status code 200 indicates success. Status code 404, for example, would
mean not found.
http://localhost:1234/CarPool/TT
Verb: GET
Status-Code: 200
Response-Body:
< Car xmlns="http://schemas.datacontract.org/2004/07/Wrox"
xmlsn:i="http://www.w3.org/2001/XMLSchemainstance"
> < Make > Audi < /Make > < Name > TT < /Name > < Seats > 2 < /Seats > < Type > Sport
Car < /Type > < /Car >
In the following example, a GET at http://localhost:1234/CarPool/TT?format=json shows the
Audi TT in the form of a JSON document. Status code 200 indicates success. Status code 404, for
example, would mean not found.
URL: http://localhost:1234/CarPool/TT?format=json
Verb: GET
Status-Code: 200 (OK)
Response-Body:
{"Make":"Audi","Name":"TT","Seats":2,"Type":"Sport Car"}
In the following example, a PUT at http://localhost:1234/CarPool/Leon with the requisite
XML data in the request body would mean that the car is to be added to the car pool. Status code201 means created. As a result of the POST action, the added object is normally returned, along with
any further details or links to other objects.
URL: http://localhost:1234/CarPool/Leon
Verb: PUT
Request-Body:
< Car xmlns="http://schemas.datacontract.org/2004/07/Wrox"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance" >
< Make > Seat < /Make > < Name > Leon < /Name > < Seats > 4 < /Seats > < Type > Sport
Car < /Type > < /Car >
Status-Code: 201 (Created)
Response-Body:
< Car xmlns="http://schemas.datacontract.org/2004/07/Wrox"
xmlsn:i="http://www.w3.org/2001/XMLSchemainstance"
> < Make > Seat < /Make > < Name > Leon < /Name > < Seats > 4 < /Seats > < Type > Sport
Car < /Type > < /Car >
Apart from GET and PUT , which have already been seen, the verbs most commonly used also include
DELETE and POST .
GET is used exclusively to retrieve data and, therefore, the result can also be buffered without any
concerns. It also offers a major advantage over SOAP messages in which the actual call cannot be
identifi ed straight away as a reading call. Therefore, they are also diffi cult to buffer.
DELETE is used for deleting resources. It should be called up as often as you wish without any
concerns about side effects. When http://localhost:1234/CarPool/Leon is called up for the fi rst
time, for example, the Leon is deleted. The next time the same URL is called up, the resource is no
longer available and can, therefore, not be deleted either.
PUT is used to add or change a resource if you can defi ne the URL yourself. For example, a PUT at
http://localhost:1234/CarPool/Leon along with corresponding details in the request body
means that this resource is added anew with the URL used. If you assign a PUT to this URL with
other values in the request body, it would lead to an update in the resource.
POST is an exception in certain regards. First of all, POST is frequently misused as DELETE and
PUT , because the use of DELETE and PUT is either not permitted or technically impossible from the
browser ’ s perspective. Secondly, POST is used to add new resources to a container without having
control of the URL created. Thus, for example, a POST to http://localhost:1234/CarPool
with corresponding details in the body would mean that a new car is being added to the carpool.
However, in this case the POST call would have to return the URL of the newly created resource.
In any event, the REST is stateless. Therefore, whenever a call is made, all the requisite values are
either transferred in the address of the resource or as additional parameters. This behavior also
means that REST applications are generally much easier to scale because there is no need to be
concerned about which server to send the query to in a load - balanced environment.
REST and WCF
WCF not only provides a platform for SOAP messages, it is also a means of offering RESTful
services.
The essential components that allow you to create a REST application can be found in System.
ServiceModel.Web.dll . The most important elements of a REST application include the [WebGet]
and [WebInvoke] attributes and the new binding webHttpBinding in connection with the webHttp
endpoint behavior.
If you use [WebGet] or [WebInvoke] , the [OperationContract] attribute is
optional.
Should you wish to create a RESTful solution from your SOAP - based solution, theoretically you
would simply have to change the binding to webHttpBinding and confi gure the endpoint with the
webHttp behavior.
This binding has the following effect: If you send a SOAP message to an endpoint in a classical SOA
environment, the content of the message will normally be checked fi rst. The correct operation will
be called up depending on the content of the message.
In REST, however, the method which is called up is dependent on the URL and on the verb used.
This altered dispatch behavior is made possible by the binding webHttpBinding and the webHttp
endpoint behavior. Furthermore, the WebHttpBehavior class or the endpoint behavior also enables
you to choose from two different serialization formats:
POX (Plain old XML) uses XML alone without the SOAP overhead.
JSON (JavaScript Object Notation) is a very compact and effi cient format, primarily in connection
with JavaScript.

Saturday, July 28, 2012

POLLINGDUPLEXHTTPBINDING: HTTP POLLING

POLLINGDUPLEXHTTPBINDING: HTTP POLLING
The changing needs of users have led to the creation of web sites being increasingly interactive.
In this context, Silverlight offers a powerful development platform to create rich, interactive
applications. Silverlight runtime runs as a client in the user ’ s browser process. As with any clients, it
needs to access data remotely, often exposed as service. The more convenient and obvious platform
to develop this service is WCF.
The most common scenario enables a request - reply message exchange pattern where the Silverlight
client sends a request and receives a reply from the service. But sometimes, the service needs to
inform or notify the client when something happens on the other side. The service needs to push
data to the client. PollingDuplexHttpBinding , available since Silverlight v3 in the System.
ServiceModel.PollingDuplex.dll, is designed to accomplish this communication protocol.
PollingDuplexHttpBinding is the implementation of the WS - MakeConnection v1.1 OASIS
Specifi cation ( http://docs.oasis - open.org/ws - rx/wsmc/v1.1/wsmc.html ). In practice, when
a session is established, the client sends the request to the service and the service replies with an
Http response only when it needs to push data to the client — meaning only when there are data
for the client. This is done with a mechanism already known as long polling . If there aren ’ t data for
the client, the service holds on to the latest Http request until there are available data or a timeout
is reached. If the client wants to get more information after receiving one, it re - sends a new Http
request. The communication goes on until an active Http request is alive.
On client side you have to reference the client version of the PollingDuplexHttpBinding from the
System.ServiceModel.PollingDuplex.dll in the Silverlight v3 SDK Libraries path.

Sunday, July 8, 2012

Java Persian Calendar Class


package bixolonprint;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

 public class CalendarTool {


 public CalendarTool()
 {
 Calendar calendar = new GregorianCalendar();
 setGregorianDate(calendar.get(Calendar.YEAR),
 calendar.get(Calendar.MONTH)+1,
 calendar.get(Calendar.DAY_OF_MONTH));
 }

 public String getCurrentTimeStamp() {
    SimpleDateFormat sdfDate = new SimpleDateFormat("HH:mm:ss");//dd/MM/yyyy //yyyy-MM-dd
    Date now = new Date();
    String strDate = sdfDate.format(now);
    return strDate;
}
 public int getCurrentDay() {
    SimpleDateFormat sdfDate = new SimpleDateFormat("dd");//dd/MM/yyyy //yyyy-MM-dd HH:mm:ss
    Date now = new Date();
    String strDate = sdfDate.format(now);
    return Integer.parseInt( strDate );
}

 public CalendarTool(int year, int month, int day)
 {
 setGregorianDate(year,month,day);
 }

 public int getIranianYear() {
 return irYear;
 }

 public int getIranianMonth() {
 return irMonth;
 }

 public int getIranianDay() {
 return irDay;
 }

 public int getGregorianYear() {
 return gYear;
 }

 public int getGregorianMonth() {
 return gMonth;
 }

 public int getGregorianDay() {
 return gDay;
 }

 public int getJulianYear() {
 return juYear;
 }

 public int getJulianMonth() {
 return juMonth;
 }

 public int getJulianDay() {
 return juDay;
 }

 public String getIranianDate()
 {
 return (irYear+"/"+irMonth+"/"+irDay);
 }

 public String getGregorianDate()
 {
 return (gYear+"/"+gMonth+"/"+gDay);
 }

 public String getJulianDate()
 {
 return (juYear+"/"+juMonth+"/"+juDay);
 }

 public String getWeekDayStr()
 {
 String weekDayStr[]={
 "Monday",
 "Tuesday",
 "Wednesday",
 "Thursday",
 "Friday",
 "Saturday",
 "Sunday"};
 return (weekDayStr[getDayOfWeek()]);
 }

 public String toString()
 {
 return (getWeekDayStr()+
 ", Gregorian:["+getGregorianDate()+
 "], Julian:["+getJulianDate()+
 "], Iranian:["+getIranianDate()+"]");
 }

 public int getDayOfWeek()
 {
 return (JDN % 7);
 }

 public void nextDay()
 {
 JDN++;
 JDNToIranian();
 JDNToJulian();
 JDNToGregorian();
 }

 public void nextDay(int days)
 {
 JDN+=days;
 JDNToIranian();
 JDNToJulian();
 JDNToGregorian();
 }

 public void previousDay()
 {
 JDN--;
 JDNToIranian();
 JDNToJulian();
 JDNToGregorian();
 }

 public void previousDay(int days)
 {
 JDN-=days;
 JDNToIranian();
 JDNToJulian();
 JDNToGregorian();
 }

 public void setIranianDate(int year, int month, int day)
 {
 irYear =year;
 irMonth = month;
 irDay = day;
 JDN = IranianDateToJDN();
 JDNToIranian();
 JDNToJulian();
 JDNToGregorian();
 }

 public void setGregorianDate(int year, int month, int day)
 {
 gYear = year;
 gMonth = month;
 gDay = day;
 JDN = gregorianDateToJDN(year,month,day);
 JDNToIranian();
 JDNToJulian();
 JDNToGregorian();
 }

 public void setJulianDate(int year, int month, int day)
 {
 juYear = year;
 juMonth = month;
 juDay = day;
 JDN = julianDateToJDN(year,month,day);
 JDNToIranian();
 JDNToJulian();
 JDNToGregorian();
 }

 private void IranianCalendar()
 {
 // Iranian years starting the 33-year rule
 int Breaks[]=
 {-61, 9, 38, 199, 426, 686, 756, 818,1111,1181,
 1210,1635,2060,2097,2192,2262,2324,2394,2456,3178} ;
 int jm,N,leapJ,leapG,jp,j,jump;
 gYear = irYear + 621;
 leapJ = -14;
 jp = Breaks[0];
 // Find the limiting years for the Iranian year 'irYear'
 j=1;
 do{
 jm=Breaks[j];
 jump = jm-jp;
 if (irYear >= jm)
 {
 leapJ += (jump / 33 * 8 + (jump % 33) / 4);
 jp = jm;
 }
 j++;
 } while ((j<20) && (irYear >= jm));
 N = irYear - jp;
 // Find the number of leap years from AD 621 to the begining of the current
 // Iranian year in the Iranian (Jalali) calendar
 leapJ += (N/33 * 8 + ((N % 33) +3)/4);
 if ( ((jump % 33) == 4 ) && ((jump-N)==4))
 leapJ++;
 // And the same in the Gregorian date of Farvardin the first
 leapG = gYear/4 - ((gYear /100 + 1) * 3 / 4) - 150;
 march = 20 + leapJ - leapG;
 // Find how many years have passed since the last leap year
 if ( (jump - N) < 6 )
 N = N - jump + ((jump + 4)/33 * 33);
 leap = (((N+1) % 33)-1) % 4;
 if (leap == -1)
 leap = 4;
 }


 public boolean IsLeap(int irYear1)
 {
 // Iranian years starting the 33-year rule
 int Breaks[]=
 {-61, 9, 38, 199, 426, 686, 756, 818,1111,1181,
 1210,1635,2060,2097,2192,2262,2324,2394,2456,3178} ;
 int jm,N,leapJ,leapG,jp,j,jump;
 gYear = irYear1 + 621;
 leapJ = -14;
 jp = Breaks[0];
 // Find the limiting years for the Iranian year 'irYear'
 j=1;
 do{
 jm=Breaks[j];
 jump = jm-jp;
 if (irYear1 >= jm)
 {
 leapJ += (jump / 33 * 8 + (jump % 33) / 4);
 jp = jm;
 }
 j++;
 } while ((j<20) && (irYear1 >= jm));
 N = irYear1 - jp;
 // Find the number of leap years from AD 621 to the begining of the current
 // Iranian year in the Iranian (Jalali) calendar
 leapJ += (N/33 * 8 + ((N % 33) +3)/4);
 if ( ((jump % 33) == 4 ) && ((jump-N)==4))
 leapJ++;
 // And the same in the Gregorian date of Farvardin the first
 leapG = gYear/4 - ((gYear /100 + 1) * 3 / 4) - 150;
 march = 20 + leapJ - leapG;
 // Find how many years have passed since the last leap year
 if ( (jump - N) < 6 )
 N = N - jump + ((jump + 4)/33 * 33);
 leap = (((N+1) % 33)-1) % 4;
 if (leap == -1)
 leap = 4;
 if (leap==4 || leap==0)
 return true;
 else
 return false;

}

 private int IranianDateToJDN()
 {
 IranianCalendar();
 return (gregorianDateToJDN(gYear,3,march)+ (irMonth-1) * 31 - irMonth/7 * (irMonth-7) + irDay -1);
 }

 private void JDNToIranian()
 {
 JDNToGregorian();
 irYear = gYear - 621;
 IranianCalendar(); // This invocation will update 'leap' and 'march'
 int JDN1F = gregorianDateToJDN(gYear,3,march);
 int k = JDN - JDN1F;
 if (k >= 0)
 {
 if (k <= 185)
 {
 irMonth = 1 + k/31;
 irDay = (k % 31) + 1;
 return;
 }
 else
 k -= 186;
 }
 else
 {
 irYear--;
 k += 179;
 if (leap == 1)
 k++;
 }
 irMonth = 7 + k/30;
 irDay = (k % 30) + 1;
 }

 private int julianDateToJDN(int year, int month, int day)
 {
 return (year + (month - 8) / 6 + 100100) * 1461/4 + (153 * ((month+9) % 12) + 2)/5 + day - 34840408;
 }

 private void JDNToJulian()
 {
 int j= 4 * JDN + 139361631;
 int i= ((j % 1461)/4) * 5 + 308;
 juDay = (i % 153) / 5 + 1;
 juMonth = ((i/153) % 12) + 1;
 juYear = j/1461 - 100100 + (8-juMonth)/6;
 }

 private int gregorianDateToJDN(int year, int month, int day)
 {
 int jdn = (year + (month - 8) / 6 + 100100) * 1461/4 + (153 * ((month+9) % 12) + 2)/5 + day - 34840408;
 jdn = jdn - (year + 100100+(month-8)/6)/100*3/4+752;
 return (jdn);
 }

 private void JDNToGregorian()
 {
 int j= 4 * JDN + 139361631;
 j = j + (((((4* JDN +183187720)/146097)*3)/4)*4-3908);
 int i= ((j % 1461)/4) * 5 + 308;
 gDay = (i % 153) / 5 + 1;
 gMonth = ((i/153) % 12) + 1;
 gYear = j/1461 - 100100 + (8-gMonth)/6;
 }

private int irYear;
 private int irMonth;
 private int irDay;
 private int gYear;
 private int gMonth;
 private int gDay;
 private int juYear;
 private int juMonth;
 private int juDay;
 private int leap;
 private int JDN;
 private int march;
 }

Saturday, July 7, 2012

Host a JAVA Application as Windows Service with Apache Commons Daemon

Enjoy it , works correctly  :

http://commons.apache.org/daemon/procrun.html

Procrun is a set of applications that allow Windows users to wrap (mostly) Java applications (e.g. Tomcat) as a Windows service.

The service can be set to automatically start when the machine boots and will continue to run with no user logged onto the machine.

Prunmgr is a GUI application for monitoring and configuring procrun services.
Each command line directive is in the form of //XX[//ServiceName]
If the //ServiceName parameter is omitted, then the service name is assumed to be the name of the file.
The Prunsrv application behaves in the same way, so to allow both applications to reside in the same directory, the Prunmgr application will remove a trailing w (lower-case w) from the name.
For example if the Prunmgr application is renamed as TestService.exe - or as TestServicew.exe - then the default service name is TestService.
 ---
linux distributions
http://en.wikipedia.org/wiki/List_of_Linux_distributions

Sunday, July 1, 2012

WHAT IS SOA?


WHAT IS SOA?
SOA or service - oriented architecture is a style of programming, an architectural approach in
software development, where an application is organized in functional units of code with a
given behavior called services.
Services are a group of methods that share a common set of requirements and functional
goals. They are called by other parts that need to execute its logic, depending on the outcome
(such as data, results of calculations, and so on). The functions have a clearly defi ned and
public signature which is published so other code (service clients) can use the functions in the
service as a black box. The service operations are invisible — there is no direct interaction
with a user and the work is executed as instructed by the given input parameters. SOA allows
distributed applications to be organized. This means that the service consumers are running on
different machines than the services. This allows the business logic and run user interfaces to be
centralized or other consumers to be decentralized across the network. To make this happen in
SOA, structured messages are sent between machines containing data.

The main idea behind SOA is to create a loosely coupled system where the only element a consumer
of a service and the implementation of the services have in common is the list of public service
operations and the defi nition of the structures of the parameters.
The client only knows the signatures describing the name, names and types of input parameters,
and return type of the functions of the service. There ’ s no other dependency. The application
platform and programming language can be different on both client and service.
It ’ s clear that this dependency is a functional one and is not based on technical infrastructure. This
makes it possible to interact easily from different platforms with a service. A technical cornerstone
in the SOA paradigm is the use of the SOAP standard. SOAP is the XML language that defi nes the
content of messages sent to and received by a service operation.
Messages are formed out of the value of the parameters or return values and the data is
formatted by SOAP. Every development platform has a SOAP stack, so working with service is
supported in many environments. Supporting multiple environments is the goal of working in a
SOA style.
This approach makes it possible to create systems that are built out of services. The services make
up the building blocks for the application which can be composed out of the service operations.
Either an end user application or another service can make use of these building blocks. SOA
makes it possible to defi ne a workfl ow of a business process in which they make calls to service
operations.
Implementing an application in this architecture is the way to make code and the functional
behavior of it reusable for unknown uses in the future. As the business logic is not coupled to some
kind of user interface technology, it ’ s possible to access these functions from clients that use newer
technologies for creating user interfaces.
Separation of concerns is also an advantage. When structuring a development team for a project,
different sub teams or individual members can be assigned to both sides of the service boundaries.
One team concentrates on building only the user interaction experience without concern about the
code dealing with the business logic and data access. The UI team receives the service interface and
can start coding against this interface. Meanwhile, another team works out the implementation of
the defi ned service interface without the need to build a user interface. This means a developer is no
longer responsible for the code end - to - end, including user interface, business logic, and data access
for a given requirement. This results in assigning developers which can focus their knowledge of
technology for one layer of the complete application.
Separation of concerns also means that the development of UI and services can be started at the
same time directly after the publication of the agreed service interfaces. This is a huge advantage
that allows the creation of the UI to be outsourced and keeps the creation of the real business logic
in - house.
SOA is a way to build distributed systems where autonomous logic is called using loosely coupled
messages via a well - defi ned interface.

Having a stable defi nition of a service interface is absolutely needed. The advantages of SOA are only
present when the service contract is agreed on by multiple parties and is not subjected to changes
during development. It ’ s the business, defi ning the requirements, that has to have a clear view of the
needed functionality. This is done in combination with a functional architect that defi nes the interface
on a technical level. Of course this is not always easy or even possible as business requirements
tend to change a lot in most environments. To solve this contradiction, it ’ s wise to have an iterative
development process that typically lasts 1 to 4 weeks. The service interface is not changed and the
modifi cations to the interface are clearly discussed and reported to the development teams at every
new iteration.
As application and software systems get bigger and more complex, a strict development architecture
is needed that supports a great maintainability with a reusability of components. In the more
distributed environments we see today — with applications implemented on different platforms —
the need for a simple development approach that supports interconnectivity is a big value.
Implementing a SOA architecture is needed to solve problems that object orientation alone cannot
solve for very large systems with integration between multiple parts. Integration of existing
components needs a well - thought - out and industry - wide paradigm in the form of SOA.

FOUR TENETS OF SOA
To have a good and deeper defi nition of SOA, some principles need to be described in more detail.
Tenets in the software industry are the way to do this. In SOA, the four tenets of service orientation
are discussed.
These tenets include the following:
Boundaries are explicit
Services are autonomous
Services share schema and contract, not class
Service compatibility is based on policy

c# config helper load save form state

    private void Form1_Load(object sender, EventArgs e)
        {
            if (!System.IO.File.Exists(@"app.config"))
            {
                TextWriter tw = new StreamWriter("app.config");
                tw.Write(str1);
                tw.Close();
            }
           
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = @"app.config";

            Configuration config =
               ConfigurationManager.OpenMappedExeConfiguration(fileMap,
               ConfigurationUserLevel.None);

            if (config.AppSettings.Settings["WindowState"] != null)
                this.WindowState = (FormWindowState)Enum.Parse(typeof(FormWindowState), config.AppSettings.Settings["WindowState"].Value.ToString());
            if (config.AppSettings.Settings["LocationX"] != null && config.AppSettings.Settings["LocationY"] != null )
                this.Location = new Point(int.Parse ( config.AppSettings.Settings["LocationX"].Value) , int.Parse ( config.AppSettings.Settings["LocationY"].Value )) ;
            if (config.AppSettings.Settings["Width"] != null && config.AppSettings.Settings["Height"] != null)
                this.Size = new Size (int.Parse(config.AppSettings.Settings["Width"].Value) ,  int.Parse(config.AppSettings.Settings["Height"].Value) );
            if (config.AppSettings.Settings["TrackBarValue"] != null)
                trackBar1.Value = int.Parse(config.AppSettings.Settings["TrackBarValue"].Value) ;
        }

        string str1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "\r\n" +
        "<configuration>" + "\r\n" +
        "<appSettings file=\"\">" + "\r\n" +
        "<clear />" + "\r\n" +
        "<add key=\"WindowState\" value=\"0\" />" + "\r\n" +
        "<add key=\"LocationX\" value=\"0\" />" + "\r\n" +
        "<add key=\"LocationY\" value=\"0\" />" + "\r\n" +
        "<add key=\"Width\" value=\"300\" />" + "\r\n" +
        "<add key=\"Height\" value=\"300\" />" + "\r\n" +
        "<add key=\"TrackBarValue\" value=\"0\" />" + "\r\n" +
        "</appSettings>" + "\r\n" +
        "</configuration>";

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = @"app.config";

            Configuration config1 =
            ConfigurationManager.OpenMappedExeConfiguration(fileMap,
            ConfigurationUserLevel.None);

            config1.AppSettings.Settings["WindowState"].Value = ((int)this.WindowState).ToString() ;
            config1.AppSettings.Settings["LocationX"].Value = this.Location.X.ToString();
            config1.AppSettings.Settings["LocationY"].Value = this.Location.Y.ToString();
            config1.AppSettings.Settings["Width"].Value = this.Width.ToString();
            config1.AppSettings.Settings["Height"].Value = this.Height.ToString() ;
            config1.AppSettings.Settings["TrackBarValue"].Value = this.trackBar1.Value.ToString();
            config1.Save(ConfigurationSaveMode.Modified);
        }