Monday, April 30, 2012

Microsoft Intermediate Language (MSIL)


When compiling to managed code, the compiler translates your source code into
Microsoft intermediate language (MSIL), which is a CPU-independent set of
instructions that can be efficiently converted to native code. MSIL includes
instructions for loading, storing, initializing, and calling methods on objects, as well
as instructions for arithmetic and logical operations, control flow, direct memory
access, exception handling, and other operations. Before code can be executed, MSIL
must be converted to CPU-specific code by a just in time (JIT) compiler. Because the
runtime supplies one or more JIT compilers, for each computer architecture it
supports, the same set of MSIL can be JIT-compiled and executed on any supported
architecture.
When a compiler produces MSIL, it also produces metadata. The MSIL and metadata
are contained in a portable executable (PE file) that is based on and extends the
published Microsoft PE and Common Object File Format (COFF) used historically for
executable content. This file format, which accommodates MSIL or native code as
well as metadata, enables the operating system to recognize common language
runtime images. The presence of metadata in the file along with the MSIL enables
your code to describe itself, which means that there is no need for type libraries or
Interface Definition Language (IDL). The runtime locates and extracts the metadata
from the file as needed during execution.

The .NET Class Framework


The next layer up in the framework is called the .NET Class Framework also referred
as .NET base class library. The .NET Class Framework consists of several thousand
type definitions, where each type exposes some functionality. All in all, the CLR and
the .NET Class Framework allow developers to build the following kinds of
applications:

• Web Services. Components that can be accessed over the Internet very easily.

• Web Forms. HTML based applications (Web Sites).

• Windows Forms. Rich Windows GUI applications. Windows form applications can
take advantage of controls, mouse and keyboard events and can talk directly to
the underlying OS.

• Windows Console Applications. Compilers, utilities and tools are typically
implemented as console applications.

• Windows Services. It is possible to build service applications controllable via the
Windows Service Control Manager (SCM) using the .NET Framework.

• Component Library. .NET Framework allows you to build stand-alone components
(types) that may be easily incorporated into any of the above mentioned
application types.

The Common Language Runtime (CLR)


At the base is the CLR. It is considered as the heart of the .NET framework. .NET
applications are compiled to a common language known as Microsoft Intermediate
Language or “IL”. The CLR, then, handles the compiling the IL to machine language,
at which point the program is executed.
The CLR environment is also referred to as a managed environment, in which
common services, such as garbage collection and security, are automatically
provided.
More information on CLR is available at
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconthecommonlanguageruntime.asp

Features of .NET


Now that we know some basics of .NET, let us see what makes .NET a wonderful
platform for developing modern applications.

• Rich Functionality out of the box


.NET framework provides a rich set of functionality out of the box. It contains
hundreds of classes that provide variety of functionality ready to use in your
applications. This means that as a developer you need not go into low level details
of many operations such as file IO, network communication and so on.

• Easy development of web applications


ASP.NET is a technology available on .NET platform for developing dynamic
and data driven web applications. ASP.NET provides an event driven
programming model (similar to Visual Basic 6 that simplify development of web
pages (now called as web forms) with complex user interface. ASP.NET server
controls provide advanced user interface elements (like calendar and grids) that
save lot of coding from programmer’s side.

• OOPs Support


The advantages of Object Oriented programming are well known. .NET provides
a fully object oriented environment. The philosophy of .NET is – “Object is
mother of all.” Languages like Visual Basic.NET now support many of the OO
features that were lacking traditionally. Even primitive types like integer and
characters can be treated as objects – something not available even in OO
languages like C++.

• Multi-Language Support


Generally enterprises have varying skill sets. For example, a company might have
people with skills in Visual Basic, C++, and Java etc. It is an experience that
whenever a new language or environment is invented existing skills are outdated.
This naturally increases cost of training and learning curve. .NET provides
something attractive in this area. It supports multiple languages. This means that
if you have skills in C++, you need not throw them but just mould them to suit
.NET environment. Currently four languages are available right out of the box
namely – Visual Basic.NET, C# (pronounced as C-sharp), Jscript.NET and
Managed C++ (a dialect of Visual C++). There are many vendors that are
working on developing language compilers for other languages (20+ language
compilers are already available). The beauty of multi language support lies in the
fact that even though the syntax of each language is different, the basic
capabilities of each language remain at par with one another.

• Multi-Device Support


Modern lift style is increasingly embracing mobile and wireless devices such as
PDAs, mobiles and handheld PCs. . . .NET provides promising platform for
programming such devices. .NET Compact Framework and Mobile Internet
Toolkit are step ahead in this direction.

• Automatic memory management


While developing applications developers had to develop an eye on system
resources like memory. Memory leaks were major reason in failure of
applications. .NET takes this worry away from developer by handling memory on
its own. The garbage collector takes care of freeing unused objects at appropriate
intervals.

• Compatibility with COM and COM+


Before the introduction of .NET, COM was the de-facto standard for
componentized software development. Companies have invested lot of money and
efforts in developing COM components and controls. The good news is – you can
still use COM components and ActiveX controls under .NET. This allows you to
use your existing investment in .NET applications. .NET still relies on COM+ for
features like transaction management and object pooling. In fact it provides
enhanced declarative support for configuring COM+ application right from your
source code. Your COM+ knowledge still remains as a valuable asset.

• No more DLL Hell


If you have worked with COM components, you probably are aware of “DLL
hell”. DLL conflicts are a common fact in COM world. The main reason behind
this was the philosophy of COM – “one version of component across machine”.
Also, COM components require registration in the system registry. .NET ends this
DLL hell by allowing applications to use their own copy of dependent DLLs.
Also, .NET components do not require any kind of registration in system registry.

• Strong XML support


Now days it is hard to find a programmer who is unaware of XML. XML has
gained such a strong industry support that almost all the vendors have released
some kind of upgrades or patches to their existing software to make it “XML
compatible”. Currently, .NET is the only platform that has built with XML right
into the core framework. .NET tries to harness power of XML in every possible
way. In addition to providing support for manipulating and transforming XML
documents, .NET provides XML web services that are based on standards like
HTTP, XML and SOAP.

• Ease of deployment and configuration


Deploying windows applications especially that used COM components were
always been a tedious task. Since .NET does not require any registration as such,
much of the deployment is simplified. This makes XCOPY deployment viable.
Configuration is another area where .NET – especially ASP.NET – shines over
traditional languages. The configuration is done via special files having special
XML vocabulary. Since, most of the configuration is done via configuration files,
there is no need to sit in front of actual machine and configure the application
manually. This is more important for web applications; simply FTPing new
configuration file makes necessary changes.

• Security


Windows platform was always criticized for poor security mechanisms. Microsoft
has taken great efforts to make .NET platform safe and secure for enterprise
applications. Features such as type safety, code access security and role based
authentication make overall application more robust and secure.

Speech Recognition using Interop.SpeechLib.dll with C#


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
using System.Threading;
using SpeechLib;
using MediaPlayer;
using WMPLib;
using System.Diagnostics;



 private SpeechLib.SpSharedRecoContext objRecoContext;
        private SpeechLib.ISpeechRecoGrammar grammar = null;
        private SpeechLib.ISpeechGrammarRule menuRule = null;
        SpVoice spo = new SpVoice();
        bool saved = false;
        bool enable_speach = false;
        bool speach_diabletime_out = false;



     private void Form1_Load(object sender, EventArgs e)
        {
         
            try
            {
                objRecoContext = new SpSharedRecoContext();
           
                spo.Speak("Welcome", SpeechVoiceSpeakFlags.SVSFlagsAsync);
                spo.WaitUntilDone(1000);
           
                enable_speach = false;
                objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
           
            }
            catch (Exception exp)
            {

                MessageBox.Show("Install speech Before Statring Akku", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                Application.Exit();
            }

       
           
   
        }




 string result = "";

        private void Reco_Event(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
        {


            result = Result.PhraseInfo.GetText(0, -1, true);
       
            if (result == Properties.Settings.Default.start)
            {
             
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                //p.StartInfo.FileName = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                p.StartInfo.FileName = @"C:\Program Files\Internet Explorer\IEXPLORE.EXE";
                p.Start();
                p.StartInfo.FileName = @"C:\\Windows";
                p.Start();
                //System.Diagnostics.Process("C:\\Windows");

            }
            if (result == Properties.Settings.Default.explorer)
            {
             
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = @"C:\Program Files\Internet Explorer\IEXPLORE.EXE";
                p.Start();

             
            }
            if (result == Properties.Settings.Default.player)
            {
                result = "";
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = @"C:\Program Files\Windows Media Player\wmplayer.exe" ;
                p.Start();
                System.Diagnostics.Process.Start(@"D:\virtulamouse\virtulamouse\01 - Kya Mujhe Pyaar Hai (Kay Kay).mp3");

            }
            if (result == Properties.Settings.Default.notepad)
            {
                result = "";
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = @"notepad.exe";
                p.Start();
                //System.Diagnostics.Process.Start(@"%SystemRoot%\system32\notepad.exe");

            }
            if (result == Properties.Settings.Default.keyboard)
            {
                result = "";
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = @"osk.exe";
                p.Start();
                //System.Diagnostics.Process.Start(@"%SystemRoot%\system32\notepad.exe");

            }
            serialPort1.Close();

            //System.Windows.Forms.SendKeys.SendWait("This text was entered ");
            //Thread.Sleep(1000);
            //System.Windows.Forms.SendKeys.SendWait("{TAB}");
            //Thread.Sleep(1000);
            //System.Windows.Forms.SendKeys.SendWait("using the System.Windows.");
            //Thread.Sleep(1000);

        }

        private void btnenablespeech_Click(object sender, EventArgs e)
        {
            try
            {
                grammar = objRecoContext.CreateGrammar(0);
                menuRule = grammar.Rules.Add("MenuCommands", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
                object PropValue = "";

            menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.start, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.start, 2, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.explorer, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.explorer, 3, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.player, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.player, 4, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.notepad, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.notepad, 5, ref PropValue, 1.0F);
            menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.keyboard, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.keyboard, 5, ref PropValue, 1.0F);
         
            //menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.start, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.start, 2, ref PropValue, 1.0F);
            //menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.explorer, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.explorer, 3, ref PropValue, 1.0F);
            //menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.player, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.player, 4, ref PropValue, 1.0F);
            //menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.notepad, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.notepad, 5, ref PropValue, 1.0F);
            //menuRule.InitialState.AddWordTransition(null, Properties.Settings.Default.keyboard, " ", SpeechGrammarWordType.SGLexical, Properties.Settings.Default.keyboard, 5, ref PropValue, 1.0F);
                grammar.Rules.Commit();
                grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);
            }
            catch (Exception exp)
            {

                MessageBox.Show(exp.Message);
                if (serialPort1.IsOpen == true)
                {
                    serialPort1.Close();
                }
                return;
            }

            spo.Speak("start", SpeechVoiceSpeakFlags.SVSFlagsAsync);
            spo.WaitUntilDone(1000);
            if (button2.Text == "Enable Speech")
            {
                button2.Text = "Disable Speech";
            }
            else if (button2.Text == "Disable Speech")
            {
                objRecoContext.EndStream += new _ISpeechRecoContextEvents_EndStreamEventHandler(wavRecoContext_EndStream);
                button2.Text = "Enable Speech";
            }
        }

  private void wavRecoContext_EndStream(int StreamNumber, object StreamPosition, bool f)
        {

            // ' Disable dictation

            grammar.DictationSetState(SpeechRuleState.SGDSInactive);

        }

MIFARE Protocol


                                          MF700 MIFARE READER PROTOCOL

BAUD RATE : 19200 BITS/SEC



01 00 00 00 c0 71 01 00 01 00 50 70 01 00 3f 00 30 60   : AUTO SCAN

01 00 06 00 60 72 01 00 06 1a 50 47 4d 2d 54 30 37 32 34 20 56 31 2e 30 52 34 20 28 30 36 30 35 31 38 29 00 6c 2a 01 00 06 01 01 75 20 : RESPONSE

01 00 3f 01 00 b8 31     : OK

01 00 06 01 00 b5 e1  : RESPONSE

AUTO SCAN AND OK ARE FOR INITIALISATION OF READER.
SO THESE QUERIES SHOULD BE SEND BEFORE CARD INSERT AND SHOULD CHECK POSITIVE RESPONSE ('06' THIRD BYTE OF RESPONSE)FOR PROCEEDING.

QUERIES AND RESPONSE AFTER CARD INSERT

01 00 20 00 00 68         : REQUEST

01 00 06 02 04 00 88 87   : RESPONSE

ALWAYS SEND REQUEST QUERY AND CHECK +VE RESPONSE FOR PROCEEDING

01 00 21 00 90 69         : CARD ID

01 00 06 04 3a 6f ce 42 32 02  : RESPONSE

01 00 22 04 3a 6f ce 42 d6 04        :SELECT

01 00 06 01 08 73 e0   : RESPONSE

01 00 23 02 60 00 44 a6 : AUTHENTICATE WITH SECTOR 0 AND KEYA

01 00 06 01 00 b5 e1 :  RESPONSE

01 00 28 05 01 00 00 00 00 9c d5 01 00 24 01 01 7f 80      :   VALUE FORMAT

01 00 06 01 00 b5 e1 01 00 06 10 00 00 00 00 ff ff ff ff 00 00 00 00 01 fe 01 fe 71 3d  : RESPONSE

01 00 26 06 01 c1 00 00 00 64 29 d3
01 00 24 01 01 7f 80   : VALUE INCREMENT FOR 100

01 00 06 01 00 b5 e1 01 00 06 10 64 00 00 00 9b ff ff ff 64 00 00 00 01 fe 01 fe 0e 61  : RESPONSE

01 00 27 01 01 7f 70 : READ VALUE

01 00 06 04 00 00 00 64 4d eb : RESPONSE WITH 100

01 00 26 06 01 c0 00 00 00 64 e9 ee
 01 00 24 01 01 7f 80   : VALUE DECREMENT 100

01 00 06 01 00 b5 e1 01 00 06 10 00 00 00 00 ff ff ff ff 00 00 00 00 01 fe 01 fe 71 3d : RESPONSE

01 00 25 15 01 73 61 6e 6f 6f 6e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 76 c5 : WRITE BLOCK 'xxxx'  IN BLOCK 1

01 00 06 01 00 b5 e1 : RESPONSE

01 00 24 01 01 7f 80 : READ FROM BLOCK 1

01 00 06 10 73 61 6e 6f 6f 6e 00 00 00 00 00 00 00 00 00 00 29 a9 : RESPONSE FOR READ (xxxxx)
                                     
01 00 2a 00 a0 6e    : HALT

01 00 06 01 00 b5 e1 : RESPONSE

Successplus Online Consultancy Office Automation Software



Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...