Bài giảng Lập trình Windows - Chương 1: Giới thiệu Microsoft .Net Platform

Tóm tắt Bài giảng Lập trình Windows - Chương 1: Giới thiệu Microsoft .Net Platform: ...***************************************************** // Console.WriteLine("Hello, World)"; // ***************************************************** ldstr "Hello, World" // load string onto stack // Call static System.Console.Writeline function // (function pops string from the stack) call vo... khi không cần thiếtMã quản lý – Mã không quản lý: Bất kỳ mã chương trình nào được thiết kế để thực thi trong CLR được gọi là mã quản lý Những mã khác chạy ngoài .NET gọi là mã không quản lý.NET Framework Class Library – FCL –.NET Framework Class LibraryMột tập thư viện lớp trong .NET.Net Framework...05Visual Studio 20089.015.002.0, 3.0, 3.5November 19, 2007Visual Studio 201010.016.002.0 – 4.0April 12, 2010Visual Studio 201211.017.002.0 – 4.5.2September 12, 2012Visual Studio 201312.018.002.0 – 4.5.2October 17, 2013Visual Studio 201514.019.002.0 – 4.6July 20, 2015Visual Studio 201715.019.102.0 – ...

pptx68 trang | Chia sẻ: havih72 | Lượt xem: 248 | Lượt tải: 0download
Nội dung tài liệu Bài giảng Lập trình Windows - Chương 1: Giới thiệu Microsoft .Net Platform, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
Lập trình WindowsChương 1. Giới thiệu Microsoft .Net Platform1Mục tiêuGiới thiệu .NET Platform Giới thiệu .NET Framework Những thuận lợi của .NET FrameworkCác thành phần của .NET FrameworkCác loại ngôn ngữ lập trình trên .NETCác loại ứng dụng có thể viết với .NETQuá trình tạo, biên dịch và chạy chương trình2Microsoft .NET Platform.Net PlatformLà một tập các công cụ và công nghệ giúp xây dựng dễ dàng các ứng dụng InternetĐơn giản hóa việc phát triển các ứng dụng trong môi trường phân bố của Internet4.NET PlatformCác thành phần của .NET Platform.NET Framework.NET My Services.NET Enterprise ServersVisual Studio .NET.NET Platform.NETFramework InternetCOM+ Orchestration Windows.NET EnterpriseServersBuildingBlockServices Visual Studio .NETWith .NETEnhancementsNewCapabilitiesAvailableTodayInternet.NET PlatformMôi trường chung cho việc xây dựng, triển khai và thực thi các ứng dụng Không gắn chặt vào hệ điều hành Không gắn chặt vào ngôn ngữ Nhiều tiện ích khác giúp cho việc phát triển các ứng dụng nhanh, hiệu quả hơn.NET My ServicesMột tập XML Web Service cho phép user truy cập thông tin qua Internet Dùng các .NET My Service các ứng dụng có thể truyền thông trực tiếp bằng giao thức SOAP và XMLMột số services.NET Calendar .NET Contacts .NET Inbox.NET Documents.NET Enterprise ServersMột nhóm các sản phẩm của MicrosoftMỗi sản phẩm phụ trách một thành phần then chốt cho kiến trúc ứng dụng đang phát triểnMột số sản phẩm Microsoft SQL ServerMicrosoft Biztalk ServerMicrosoft Host integration Server.Visual Studio .NETLà môi trường tích hợp để xây dựng các ứng dụng trên .NET Framework. Microsoft .NET Framework.Net FrameworkMô hình lập trình thống nhấtĐơn giản việc phát triển ứng dụngMôi trường thực thi code an toànĐộc lập ngôn ngữ (hỗ trợ nhiều ngôn ngữ lập trình)Hỗ trợ XML Web Service (Dựa trên các công nghệ chuẩn: HTTP, XML, SOAP)Mô hình lập trình thống nhấtWindows API.NET FrameworkAPI nhất quán bất chấp ngôn ngữ và mô hình lập trìnhASPStateless,Code được nhúng vào các trang HTMLMFC/ATLSubclassing,Power,ExpressivenessVB FormsRAD,Composition,DelegationĐơn giản việc phát triển ứng dụngHWND hwndMain = CreateWindowEx( 0, "MainWClass", "Main Window", WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, (HWND)NULL, (HMENU)NULL, hInstance, NULL); ShowWindow(hwndMain, SW_SHOWDEFAULT); UpdateWindow(hwndMain);Form form = new Form();form.Text = "Main Window";form.Show();Windows API.NET Framework.NET FrameworkCác phiên bản .NET Framework.NET Framework 1.0 – Visual Studio 2002.NET Framework 1.1 – Visual Studio 2003.NET Framework 2.0 – Visual Studio 2005.NET Framework 3.0 – Visual Studio 2005.NET Framework 3.5 – Visual Studio 2008.NET Framework 4.0 – Visual Studio 2010.NET Framework 4.5 – Visual Studio 2012.NET Framework 4.5 – Visual Studio 2013.NET Framework 4.6 – Visual Studio 2015Gồm có 2 thành phần chínhCommon Language Runtime (CLR)Framework Class Library (FCL).NET Framework WindowsLINUXCommon Language RuntimeFramework Class LibraryCommon Language SpecificationMicrosoft Visual Basic® .NETC++C#Microsoft JScript®Microsoft Visual Studio® .NET.NET FrameworkCommon Language Runtime – CLR –Common Language RuntimeBase Class Library SupportThread SupportCOM MarshalerType CheckerException ManagerIL to NativeCompilersCodeManagerGarbageCollectorSecurity EngineDebug EngineClass LoaderCommon Language Runtime – CLRMôi trường thực thi cho ngôn ngữ chung và các dịch vụ trong quá trình thực thiBiên dịchQuản lý bộ nhớQuản lý threadQuản lý ngoại lệBảo mậtKiểm tra an toàn kiểuCommon Language RuntimeCompilationTrước khi installation hay khi mỗi phương thức lần đầu tiên được gọiExecutionJIT CompilerNativeCodeMSILCodeMetadataSource CodeLanguage CompilerCommon Language RuntimeCác loại code trong .NETSource codeMSILOptIL Native machine code (mã máy thuần túy)Common Language Runtimepublic static void Main(){ Console.WriteLine("Hello, World);}.method static public void Main(string[] args ) il managed{ .entrypoint // this function is the application entry point .maxstack 8 // ***************************************************** // Console.WriteLine("Hello, World)"; // ***************************************************** ldstr "Hello, World" // load string onto stack // Call static System.Console.Writeline function // (function pops string from the stack) call void [mscorlib]System.Console::WriteLine(class System.String) // ***************************************************** ldstr "Press Enter to continue“ call void [mscorlib]System.Console::WriteLine(class System.String) // Call the System.Console.Read function call int32 [mscorlib]System.Console::Read() // The pop instruction removes the top element from the stack. // (remove number returned by Read() function) pop // ***************************************************** ret}Common Language RuntimeMSILMSIL là tập các lệnh, mã lệnh cấp thấp do Microsoft sáng tạo ra.Các source code được viết bằng nhiều loại ngôn ngữ khác nhau đều phải dịch sang MSILOptILOptIL là tập con của MSIL có thể được sinh bằng trình biên dịch tối ưu. OptIL giúp cho việc sinh nhanh native code Common Language RuntimeC#CodeC#CompilerVisual BasicCodeVisual BasicCompilerCOBOLCodeCOBOLCompilerILJITCompilerNativeCodeRunTimeCommon Language Runtime AssemblyAssemblyLà một phần thư viện code đã được biên dịch để dùng cho triển khaiĐược lưu trong một file PE (portable executable)Phân loạiProcess assemblies (EXE) Library assemblies (DLL)Common Language Runtime AssemblyCác thành phần trong assemblyCommon Language Runtime AssemblyMột assemply chứa nhiều fileCommon Language Runtime AssemblyMột assembly có thể gồm một hay nhiều fileCác code file được gọi là các modules. Một assembly có thể có chứa nhiều code module Có thể dùng nhiều ngôn ngữ khác nhau để tạo ra các code module nên về mặc kỹ thuật có thể dùng nhiều ngôn ngữ khác nhau để tạo một assembly Common Language Runtime AssemblyAssemblyManifestIL CodeMetadataNhiều managed modules và resource files Được biên dịch Thành một assemblyManaged Module(MSIL và Metadata)Managed Module(MSIL và Metadata).html.gifResource FilesCommon Language RuntimeJust In Time (JIT) CompilerTrình biên dịch JIT là trình biên dịch lúc thực thi với nhiệm vụ chuyển đổi MSIL (assemplies) sang native codeĐặc điểm cơ bản của JITJIP độc lập ngôn ngữ lập trìnhJIT phụ thuộc kiến trúc CPUJIT biên dịch cho mỗi phương thức lần đầu tiên chạyNative code được lưu lại để dùng lại sau nàyCommon Language RuntimeBase Class Library SupportThread SupportCOM MarshalerType CheckerException ManagerIL to NativeCompilersCodeManagerGarbageCollectorSecurity EngineDebug EngineClass LoaderCommon Language RuntimeGarbage collector – GC: định vị, cấp phát bộ nhớ, giải phóng tự động các vùng nhớ khi không cần thiếtMã quản lý – Mã không quản lý: Bất kỳ mã chương trình nào được thiết kế để thực thi trong CLR được gọi là mã quản lý Những mã khác chạy ngoài .NET gọi là mã không quản lý.NET Framework Class Library – FCL –.NET Framework Class LibraryMột tập thư viện lớp trong .NET.Net Framework thay thế phần lớn các tập Windows API bằng thư viện lớp hướng đối tượng và được quản lý tốtSystem.GlobalizationSystem.DiagnosticsSystem.ConfigurationSystem.CollectionsSystem.IOSystem.ReflectionSystem.NetSystemSystem.ThreadingSystem.TextSystem.SecuritySystem.Runtime.InteropServices.NET Framework Class LibraryPhân loạiHỗ trợ chức năng chính: tương tác với các kiểu dữ liệu cơ bản và collection; console, network và file I/O; và tương tác dễ dàng với các runtimeHỗ trợ tương tác cơ sở dữ liệu; dùng và sinh dữ liệu XML; và cấu trúc dữ liệuHỗ trợ xây dựng các ứng dụng web (thin client)Hỗ trợ xây dựng các ứng dụng desktop (thick client) Hỗ trợ xây dựng các ứng dụng XML web service.Net Framework Class Library - FCLWeb Forms và XML Web ServicesASP.NETSystem.WebConfigurationSessionStateCaching	SecurityServicesDescriptionDiscoveryProtocolsUIHtmlControlsWebControlsUser Interface cho WindowsSystem.DrawingSystem.Windows.FormsCác ngôn ngữ trong .NET FrameworkC# (C-Sharp) – được thiết kế cho .NET	Ngôn ngữ hướng thành phần (component-oriented)C++ .NET Các mở rộng code được quản lý cho C++ Visual Basic .NETVersion mới của Visual Basic, có nhiều đổi mớiJScript .NETVersion mới của Jscript, tăng cường sự thực thiJ# .NET	Ngôn ngữ Java cho .NETF# .NET	Ngôn ngữ lập trình hàm cho .NETCác ngôn ngữ trong .NET FrameworkNgôn ngữ hãng thứ ba (Third-party)APL, COBOL, Pascal, Eiffel, Haskell, ML, Oberon, Perl, Python, Scheme, SmalltalkCác loại ứng dụng có thể viết với .NETCác loại ứng dụngDesktop application Windows FormConsole ApplicationWeb application (ASP.NET)ServicesASP.NET Web serviceWindows ServiceLibrary Class libraryWindows control libraryWeb control libraryCác bước phát triển ứng dụngViết mã nguồn bằng 1 trong các ngôn ngữ được .NET hỗ trợ (C#, VB.NET, )Dịch mã nguồn sang file *.dll hay *.exe chứa mã trung gian bằng chương trình csc.exeKhi chương trình được chạy trong CLR, JIT sẽ dịch các mã trung gian sang native code và thực thiNative code được thực thi trong ngữ cảnh của CLRCác bước phát triển ứng dụng bằng C#Solutions và Projects trong .NETCác phiên bản của Visual Studio .NetProduct nameVersion numberVersion of cl.exeSupported .NETFramework versionsRelease dateVisual Studio 975.0N/AN/AFebruary 1997Visual Studio 6.06.012.00N/AJune 1998Visual Studio .NET (2002)7.013.001.0February 13, 2002Visual Studio .NET 20037.113.101.1April 24, 2003Visual Studio 20058.014.002.0, 3.0November 7, 2005Visual Studio 20089.015.002.0, 3.0, 3.5November 19, 2007Visual Studio 201010.016.002.0 – 4.0April 12, 2010Visual Studio 201211.017.002.0 – 4.5.2September 12, 2012Visual Studio 201312.018.002.0 – 4.5.2October 17, 2013Visual Studio 201514.019.002.0 – 4.6July 20, 2015Visual Studio 201715.019.102.0 – 4.6.2; Core 1.0TBAProject Visual .NetGiúp tổ chức và thi hành trên các item chúng ta đang phát triển để quản lý, build và debug các item trong ứng dụngBao gồm:Project filesRessource filesCác định nghĩa lược đồ Dataset (Dataset schema)Icons và bitmapsOutput của project thường là chương trình thực thi (.exe), file thư viện liên kết động (.dll) hay moduleSolution trong Visual .NetChứa các projects và các solution items sẽ được build vào trong ứng dụngMột solution thường chứa một hay nhiều project có liên quanTạo Project trong .NetChọn một Project TemplateThiết lập các Project ReferencesViết codeBuild Projects và SolutionsChọn Project TemplateWindows ApplicationConsole ApplicationClass LibraryWindows Control LibraryWindows ServiceASP .NET Web Application / Service / Control LibraryThiết lập các Project References.NET AssembliesCOM ComponentsProjectsBuild Projects và Solutions132Tiến trình thực thi trong .NET Class LoaderJIT Compilerwith optionalverificationExecutionSecurity ChecksEXE/DLL(MSIL and metadata)ClassLibraries(MSIL and metadata)Trusted,pre-JITedcode onlyCall to anuncompiledmethodRuntime EngineManagedNative CodeCompilerSourceCodeIntegrated Development EnvironmentMô tả Integrated Development EnvironmentChỉ có một IDE cho mọi .NET Projects Các Projects có thể chứa nhiều ngôn ngữ lập trìnhVí dụ: Visual Basic .NET và C# trong cùng projectIDE có thể tùy biến qua “My Profile”IDE có sẵn Internet BrowserDùng Integrated Development EnvironmentDùng Solution ExplorerDùng Server ExplorerDùng Object BrowserDùng Task ListDùng XML FeaturesDùng IntellisenseRecording và dùng MacrosDùng Solution ExplorerHệ thống phân cấp ProjectProject referencesForms, classes, modulesFolders chứa subitemsChế độ “Show All Files”Thao tác ProjectsDrag-and-drop Context menusDùng Server ExplorerQuản lý Data ConnectionsXem và quản lý ServersDùng kỹ thuật Drag-and-DropDùng the Object BrowserKiểm tra các Objects và các thành viênTruy cập các Lower-level ItemsHiện các inheritance và interfacesKiểm tra làm thế nào các thư viện lớp .NET Framework dùngDùng the Task ListTương tự Tasks Feature trong Microsoft OutlookĐược lưu với Solution trong file.suoThêm vào Task ListCó thể thêm tasks bằng tay bằng cách đánh vào field thích hợpVisual Basic .NET thêm build errors, upgrade comments, etc. Có thể dùng token strings để thêm comments trong code Dùng XML FeaturesCửa sổ phác thảo tài liệu HTML và XMLAutoCompleteColor-CodingData View cho thao tác dữ liệuDùng IntellisenseCho phép truy cập dễ dàng vào Properties, Methods và EventsAutoCompleteColor-CodingRecording và dùng MacrosCài đặt https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.MacrosforVisualStudio	Cho các nhiệm vụ lặp đi lặp lại như chèn CommentsMacro Explorer cung cấp Macro NavigationIDE cung cấp các mẫu:Toggle line numberingSaving/loading Window ViewsDebugging macrosĐể ghi Macros mới, Vào Tools/Macros MenuCâu hỏi Ôn tậpGiải thích các khái niệm mới (và ý nghĩa các từ viết tắt): .Net Platform, .Net Framework, CLR, FCL, IL, Metadata, Assembly, JIT, GCLiệt kê các phần tử chính của .NET PlatformNêu tên hai phần chính của .NET FrameworkLiệt kê một số ngôn ngữ được hỗ trợ trong .NET FrameworkLiệt kê các phiên bản .NET Framework, C#, Visual Studio.NETChúng ta gọi code thực thi trong Common Language Runtime là gìGiải thích quy trình biên dịch và thực thi ứng dụng trong .NETCó bao nhiêu cách dịch MSIL sang native codeCâu hỏi Ôn tậpCho biết một số thư viện về ADO.NETCho biết một số thư viện về ASP.NETCho biết một số thư viện về lập trình Windows FormLiệt kê một số ứng dụng có thể viết trên .NETKhái niệm solution, project trong Visual Studio.NETThao tác dùng Project ReferencesSau khi tạo assembly để thực thi assembly trên một hệ thống khác cần có yêu cầu gìQ&A68

File đính kèm:

  • pptxbai_giang_lap_trinh_windows_chuong_1_gioi_thieu_microsoft_ne.pptx
Ebook liên quan