This Blog

Syndication

News

Awards

Microsoft MVP Logo
Grab this badge here!

Certificates

Transcript ID#: 6724122
Brainbench ASP.NET Certificate
 
Brainbench ASP.NET 2.0 Certificate
 
Brainbench .NET Framework 2.0 Certificate

Ahmad Masykur

var myObject = { "languages" : [ "C#", "VB.NET", "ASP.NET", "Javascript", "SDCC", "Assembler" ] }; //

April 2007 - Posts

  • Sorting pada Generics Datasource

    Di .NET Frameworks 2.0 terdapat Generics List yang dapat digunakan sebagai datasource. Dibandingkan dengan dataset, generics lebih ringan dan cepat. Pada dataset terdapat fitur2 mubadzir yang tidak dibutuhkan. Dengan menggunakan List kita dapat definisikan sesuai dengan kebutuhan.

    Karena ringan dan sederhana, datasource menggunakan List tidak dapat diurutkan dengan mengeset Allow Sorting pada GridView dan memasukkan SortExpression begitu saja. Berikut salah satu cara untuk dapat menggunakan List sebagai datasource yang dapat diurutkan.

    Pertama buat class SortableList yang di-inherit dari System.Collection.Generics.List dan PropertyComparer

    VB.NET

    Imports System
    Imports System.Collections
    Imports System.Collections.Generic
    Imports System.Reflection

    Public Class SortableList(Of T)
        Inherits List(Of T)
        Private _propertyName As String
        Private _ascending As Boolean

        Public Sub New()

        End Sub

        Public Sub New(ByVal collection As IEnumerable(Of T))
            Me.AddRange(collection)
        End Sub

        Public Overloads Sub Sort(ByVal propertyName As String, (ByVal ascending As Boolean)

            'Flip the properties if the parameters are the same
            If (_propertyName = propertyName And _ascending = ascending) Then
                _ascending = Not ascending
                'Else, new properties are set with the new values
            Else
                _propertyName = propertyName
                _ascending = ascending
            End If

            Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(GetType(T))
            Dim propertyDesc As PropertyDescriptor = properties.Find(propertyName, True)

            ' Apply and set the sort, if items to sort
            Dim pc As PropertyComparer(Of T)
            If _ascending Then
                pc = New PropertyComparer(Of T)(propertyName, ListSortDirection.Ascending)
            Else
                pc = New PropertyComparer(Of T)(propertyName, ListSortDirection.Descending)
            End If
            Me.Sort(pc)
        End Sub
    End Class

    Public Class PropertyComparer(Of T)
        Implements IComparer(Of T)

        Private ReadOnly _propertyInfo As System.Reflection.PropertyInfo
        Private ReadOnly _sortDirection As ListSortDirection
        ' Constructor
        Public Sub New(ByVal propertyToSort As String, ByVal direction As ListSortDirection)
            _sortDirection = direction
            _propertyInfo = GetType(T).GetProperty(propertyToSort, _
               System.Reflection.BindingFlags.Instance Or _
               System.Reflection.BindingFlags.Public Or _
               System.Reflection.BindingFlags.FlattenHierarchy Or _
               System.Reflection.BindingFlags.IgnoreCase)
        End Sub
        ' IComparer(Of T) interface
        Public Function Compare(ByVal x As T, ByVal y As T) _
           As Integer _
             Implements IComparer(Of T).Compare
            Dim xValue As Object = _propertyInfo.GetValue(x, Nothing)
            Dim yValue As Object = _propertyInfo.GetValue(y, Nothing)
            If _sortDirection = ListSortDirection.Ascending Then
               Return System.Collections.Comparer.Default.Compare( _
                xValue, yValue)
            Else
               Return System.Collections.Comparer.Default.Compare( _
                   yValue, xValue)
            End If
        End Function
    End Class

    Sebagai contoh dibuat class sebagai representasi tabel di database sebagai berikut:

    Public Class Contact
        Private _Name As String
        Private _Address As String
        Private _Phone As String
        Public Sub New(ByVal Name As String, ByVal Address As String, ByVal Phone As String)
            _Name = Name
            _Address = Address
            _Phone = Phone
        End Sub
        Public Property Name() As String
            Get
                Return _Name
            End Get
            Set(ByVal value As String)
                _Name = value
            End Set
        End Property
        Public Property Address() As String
            Get
                Return _Address
            End Get
            Set(ByVal value As String)
                _Address = value
            End Set
        End Property
        Public Property Telp() As String
            Get
                Return _Telp
            End Get
            Set(ByVal value As String)
                _Telp = value
            End Set
        End Property
    End Class


     Contoh pada code behind 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
        Dim list As SortableList(Of Contact) = BuildList()
        Cache.Insert("Contact", list, Nothing, _
            System.Web.Caching.Cache.NoAbsoluteExpiration, _
            System.Web.Caching.Cache.NoSlidingExpiration, _
            System.Web.Caching.CacheItemPriority.High, _
            Nothing)
        contactsGridView.DataSource = list
        UsersGridView.DataBind()
    End Sub

    Protected Sub contactsGridView_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles contactsGridView.PageIndexChanging
        Dim list As SortableList(Of Contact) = CType(Cache("Users"), SortableList(Of Contact))
        UsersGridView.PageIndex = e.NewPageIndex
        UsersGridView.DataSource = list
        UsersGridView.DataBind()
    End Sub

    Protected Sub contactsGridView_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles contactsGridView.Sorting
        Dim list As SortableList(Of Contact) = CType(Cache("Users"), SortableList(Of Contact))
        list.Sort(e.SortExpression, CBool(e.SortDirection = SortDirection.Ascending))
        'Add the sorted collection back to the cache
        Cache.Insert("Users", list, Nothing, _
            System.Web.Caching.Cache.NoAbsoluteExpiration, _
            System.Web.Caching.Cache.NoSlidingExpiration, _
            System.Web.Caching.CacheItemPriority.High, _
            Nothing)
           
        UsersGridView.DataSource = list
        UsersGridView.DataBind()
    End Sub 

    Share this post: | | | |
  • Visual Studio Code Name "Orcas" March 2007 CTP

    Microsoft per-release Software Visual Studio Code Name "Orcas" March 2007 CTP telah tersedia untuk diunduh. Siapa yang mau unduh? Total berkas sekitar 6GB. Di dalamnya sudah termasuk .NET Framework 3.5

    Beberapa fitur yang tersedia diantaranya:

    • LINQ
      The LINQ Project: this CTP represents a major milestone in the LINQ project. For more information about LINQ click here.
      • VB 9.0 Language Support: This CTP contains the following language features:
        • Query Expressions: Basic querying, filtering, and ordering support
        • Object Initializers
        • Extension Methods
        • Local Variable Type Inference
        • Anonymous Types
        • XML literals
        • XML properties
        • New Line and Expression IntelliSense
      • C# 3.0 Language Support: This CTP implements all of the C#3.0 language features from the May LINQ CTP including:

        • Query Expressions
        • Object and Collection Initializers
        • Extension Methods
        • Local Variable Type Inference and Anonymous Types
        • Lambdas bound to Delegates and Expression trees
        • Complete design-time support: Intellisense, Formatting, Colorization
      • LINQ to ADO.NET
        • ADO.NET is fully integrated with LINQ and offers many options for using LINQ in various scenarios: LINQ to SQL provides direct access to database tables from the programming environment, LINQ to Entities enables developers to use LINQ over EDM models, and LINQ to DataSet allows the full expressivity of LINQ to be used over DataSets.
        • LINQ to Entities enables developers to program against a relational database using a view of the data that is appropriate for the application they are building, independent of the structure of the underlying database. The use of the Entity Data Model (EDM) enables developers to design models that follow the concepts built into the application, instead of having to map them to constructs available in relational stores. LINQ to Entities is built on the ADO.NET Provider model and will support working against different back end relational stores in addition to Microsoft SQL Server. This CTP includes a LINQ to Entities provider for SQL Server and SQL Server Compact Edition.
        • LINQ to SQL (previous name DLinq) has enhanced the functionality from the May 2006 LINQ CTP. You can find it in System.Data.Linq namespace in System.Data.Linq.dll. New in this release is that DataContext provides optimized modes for read-only use and serialization . Also new is that DataShape streamlines eager loading capabilities and adds the ability to set queries on relationships
      • LINQ To SQL Designer
        • Methods can be created from stored procedures and functions within the designer.
        • Better handling of database schemas.
        • Improved inheritance support in the designer.
      • LINQ over XML (XLinq)
        • System.Xml Bridge Classes added – There is a set of extension methods allowing XPath / XSLT to be used over LINQ to XML trees, allow XSLT transformations to produce an LINQ to XML tree, and to validate an XElement tree against an XML Schema.
        • Event Model - This allows LINQ to XML trees to be efficiently synchronized with a GUI, e.g. a Windows Presentation Foundation application
        • Class hierarchy changes - XObject class added, XStreamingElement class (temporarily) removed
        • Various understandability / usability improvements – There have been a number of relatively minor changes done in response to internal reviews, usability studies, and external feedback to make the API more clean and consistent.
      • LINQ to Objects API
        • The LINQ to Objects API supports queries over any .NET collection, such as arrays and Generic Lists. This API is defined in the System.Linq namespaces inside System.Core.dll.
    • ADO.NET
      • Extended, more powerful data APIs with the ADO.NET Entity Framework
        • With the ADO.NET Entity Framework developers will be able to model the view of the data that is appropriate for each one of the applications they are building, independently of the structure of the data in the underlying database. The use of the Entity Data Model (EDM) enables developers to design models that follow the concepts built into the application, instead of having to map them to constructs available in relational stores. Once the model is in place, the powerful ADO.NET Entity Framework API is used to access and manipulate the data as .NET classes or as rows and columns, whatever is appropriate for each application.
      • Added paging and stored procedures for update (“update customization”) for ADO.NET Entity Framework:
        • Paging: the paging support in the ADO.NET Entity Framework allows developers to “page” over data in a database by indicating the start row and number of rows to be included in the result. Paging is available through Entity SQL (using the LIMIT AND SKIP keywords) and through the query-builder methods in the ObjectQuery &ltT> class (Top and Skip). In a future CTP the feature will also be enabled to be used in LINQ queries by means of the standard Take and Skip LINQ operators.
        • Stored-procedures for update customization: the Entity Framework by default automatically generates SQL statements for insert, update and delete operations when processing changes to entities in memory to be sent to the database. With the stored-procedures update customization feature developers have the option to override the automatic SQL generation and instead provide stored-procedures that will perform the insert, update and delete operations, which the system will call during entity change processing. Among other things, this enables scenarios where direct access to tables is restricted in the database and the only way to make changes to the data is through stored-procedures.
      • Microsoft Synchronization Services for ADO.NET
        • Provides an application programming interface (API) to synchronize data between data services and a local store. The Synchronization Services API is modeled after the ADO.NET data access APIs and gives you an intuitive way to synchronize data. It makes building applications for occasionally connected environments a logical extension of building applications where you can depend on a consistent network connection. For details please visit http://go.microsoft.com/fwlink/?LinkId=80742 .
    • Web
      • Improvements for web development in this CTP include:
        • New ASP.NET WebForms design-surface with advanced XHTML and CSS features
        • JScript intellisense for ASP.NET AJAX and browser DOM
        • Multi-targetting for .NET Framework 2.0, 3.0, and 3.5 in websites and web applications
        • LINQ to SQL designer integration in websites and web applications
    • Client App-Level Services
      • Enable client application developers to use the same user profile and login services as your Web applications. This enables customers to utilize on set of backend storage for user personalization and authentication regardless of the applications type.
    • C# Workflow Rules
      • Workflow Rules allows users to enter rules (and conditions) in a code-like manner
        • Support the use of the new C# Extension methods features in their rules
        • Enable operator overloading and the new operators in their rules
    • XML
      • XML Tools: XSLT Debugger
        • Enables Input Data Breakpoints allowing the user to break the execution of the style-sheet whenever a certain node in input document is hit.
      • XML Editor Performance Improvements
        • Performance in the Xml Editor for Intellisense, schema validation etc is improved by implementing incremental parsing of the XML Document.
      • Seamless transition between XML Editor and XSD Designer
        • Improves the experience a user has when working with an XML Schema in textual and graphical mode at the same time.
    • MSBuild
      • Parallel/Multi-Processor Builds
        • Building multiple projects in parallel, as much as possible based on the use of dependency information in projects to parallelize
        • Allowing the developer/builder to control the parallelism by providing them the ability to specify the number of processors to use for build.
    • UAC Manifests in the Managed Build Process
      • Support for manifests that are embedded into the final executable via the Build process.
    • IDE
      • Windows Presentation Foundation (WPF) Designer (“Cider”) & Application Tools to deliver the ability to:
        • Create, edit, build, run and debug WPF projects
        • Use the WPF Designer to:
          • Preview any XAML in the designer including user defined controls and types
          • Design Windows, Pages and UserControls
          • Do basic layout tasks in a Grid
          • Do basic property editing using the new property browser
          • Easily understand and navigate “document structure” using the Document Outli
          • See changes in the designer immediately in the XAML
        • Use the XAML Editor to:
          • Edit XAML with intellisense
          • See changes in the XAML immediately in the designer
          • Build design time for WPF controls
      • UAC manifests in the IDE for Windows Vista applications
        • Enable developers on Windows Vista to easily include the UAC manifest as an embedded resource.
    • CLR
      • Add IRI support (RFC 3987) to URI related classes
        • This allows resource identifiers to be specified using a character set that supports all languages.
      • New Async model on Socket class
        • A new Async model is reduces the per I/O overhead compared to the current I/O model
      • Peer Networking Classes
        • Delivers a set of peer-to-peer network APIs that allow a developer to easily extend an application with compelling collaboration functionality.
      • WMI.NET Provider Extension 2.0
        • WMI.NET Provider Extension 2.0 simplifies and enhances the development of WMI providers in the .Net framework to enable the management of the .NET applications while minimizing the impact on the development time.
          • Delivers equivalent access to WMI features and functions available to native code providers.
          • Exposes property updates and methods to managed code.
          • Improved scalability for large collections of WMI entities.
    • Office
      • Enable ClickOnce deployment for Microsoft Office applications
      • Developers now have an easy to use and version resilient security model for their applications that will exist for future versions of Visual Studio and Office. With full support for ClickOnce deployment of all Office 2007 customizations and applications, developers and administrators now have the right tools and framework for easy deployment and maintenance of their Office solutions.
    • Team Architect
      • Top-down service design
        • Top-down system design allows an application architect/lead developer to perform the design of a business solution without having to be confronted with technology decisions. It enables the user to progressively refine a high-level system design, designing new sub-systems and applications in the context of the system in which they are to be used.
      • Architectural Roles on System, Applications and Endpoints
        • Enables an architect, while working on the high-level design of a system’s architecture using the System Designer, to introduce elements into the design that play a specific pre-defined architectural role(s) within architectural patterns.
    • Team Developer
      • Profiler Support for WCF Applications
        • Enable profiling of WCF based applications to improve application performance
      • Customize and extend code correctness policies
        • Code Analysis Check-in Policy improvements to communicate to a developer why the check-in policy failed and to provide guidance on how to pass the policy requirements.
      • Customize and extend code correctness policies
        • Code Analysis Check-in Policy improvements to communicate to a developer why the check-in policy failed and to provide guidance on how to pass the policy requirements.
      • Performance tune an enterprise application
        • Enables developers to run profiling during load and test procedures for a system, to see how it behaves, and use integrated tools to profile, debug and tune. This also enables performance base-lining, so that users can save a baseline profile and then, if the performance degrades, compare up-to-date traces to identify the source of the regression
    • Team Test
      • Unit Test Generation Improvements
        • Improvements to unit test generation provide an easy way for the user to specify what methods to test, and generate test methods and helper code to do unit testing, as well as providing unit test support for generics.
      • Web Test Validation Rule Improvements
        • Web Test rules improvements enable testers to create more comprehensive validation rules for the application being tested. These improvements include the following functions:
          • Stop test on error
          • Search request and response
          • Add validation rule for title
          • Redirect validation
          • Provide test level validation rules
          • Expected HTTP code
          • Warning level for errors on dependents
      • Better Web Test Data Binding
        • This feature allows users to data bind .CSV and XML files, as well as databases to a web test, using a simple databinding wizard.
      • Improved Load Test Results Management
        • With this feature user can open or remove an existing load test result from the load test repository. User can also import and export load test results files.
    • Team Foundation Server
      • Team Build
        • Support multi-threaded builds with the new MSBuild.
        • Continuous Integration – There are many components to this, including build queuing and queue management, drop management (so that users can set policies for when builds should be automatically deleted), and build triggers that allows configuration of exactly how when CI builds should be triggered, for example – every checkin, rolling build (completion of one build starts the next), etc.
        • Improved ability to specify what source, versions of source, etc to include in a build.
        • Improved ability to manage multiple build machines.
        • Simplified ability to specify what tests get run as part of a build
      • Version Control support
        • Destroy- The version control destroy operation provides administrators with the ability to remove files and folders from the version control system. The destroyed files and folders cannot be recovered once they are destroyed. Destroy allows administrators to achieve SQL server disk space usage goals without constantly needing to add more disks to the data tier machine. Destroy also facilitates removing versioned file contents that must be permanently removed from the system for any other reason.
        • Annotate - Annotate is a feature that allows developers to inspect a source code file and see at line-by-line level of detail who last changed each section of code. It brings together changeset data with difference technology to enable developers to quickly learn change history inside a source file.
        • Folder Diff - Team Foundation Server now supports compare operations on folders, whereby the contents of the folder are recursively compared to identify files that differ. Folder diff can compare local folders to local folders, local folders to server folders, and server folders to server folders. It’s a great way of identifying differences between branches, files that you’ve changed locally, and files that have changed between two points in time.
        • Get Latest on Checkout - As an optional setting on a team project or on an individual basis, you can have Team Foundation Server always download the latest version of a file when you check it out. This helps ensure that you don’t have to merge your changes with somebody else’s when you check the file back in.
      • Performance and Scale
        • This release includes numerous improvements in performance and scalability of Team Foundation Server.
    • Visual C++
      • Easily add the Windows Vista “Look and Feel” to native C++ applications
        • Developers can use Visual Studio to build ISV applications that exhibit the Windows Vista “look & feel”. A number of the Windows Vista “look & feel” features are available simply by recompiling an MFC application. Deeper integration that requires more coding or design work on the part of the developer is also simplified with Visual Studio’s integrated support for the Windows Vista native APIs.
    Share this post: | | | |
    Posted Apr 14 2007, 09:52 PM by cahnom with no comments
    Filed under:
  • Convert ArrayList to String

    Kemaren sore saya ditanya teman kantor bagaimana melakukan konversi dari ArrayList ke string dengan delimiter (pembatas) karakter atau string. Saya buatkan fungsi sederhana untuk memenuhi kebutuhan tersebut.

    Berikut penggalan fungsi yang saya tulis dalam bahasa C# dan VB.NET

    C#

    public string ArrayListToString(System.Collections.ArrayList ar)
    {
        return ArrayListToString(ar, ',');
    }
    public string ArrayListToString(System.Collections.ArrayList ar, char delim)
    {
        return ArrayListToString(ar, delim.ToString());
    }
    public string ArrayListToString(System.Collections.ArrayList ar, string delim)
    {
        return string.Join(delim, (string []) ar.ToArray(typeof(string)));
    }

    VB.NET

    Public Overloads Function ArrayListToString(ByVal ar As System.Collections.ArrayList) As String
        Return ArrayListToString(ar, ","C)
    End Function

    Public Overloads Function ArrayListToString(ByVal ar As System.Collections.ArrayList, ByVal delim As Char) As String
        Return ArrayListToString(ar, delim.ToString)
    End Function

    Public Overloads Function ArrayListToString(ByVal ar As System.Collections.ArrayList, ByVal delim As String) As String
        Return String.Join(delim, CType(ar.ToArray(GetType(String)), String()))
    End Function

    Share this post: | | | |
  • Kesan LOVE Jakarta Membingungkan

    Hari ini, Microsoft Indonesia menggelar acara Love (Launch Office Vista Exchange) di JCC (JakartaConvention Center). Acara diikuti oleh ribuan peserta dari mahasiswa sampai praktisi IT Indonesia.

    Pagi tadi saya berangkat dari kantor jam 8:00 sampai tujuan sekitar jam 9:15. Yang agak membingungkan adalah kita di sana harus masuk ke ruangan mana. Ada banyak ruangan dan masing-masing ruangan materinya berbeda. Padahal saya pengen mengikuti acara untuk developer eh... nyasar di Microsoft Office. Gimana nih EO-nya koq gak ngasih petunjuk di masing-masing ruangan. Bingung deh, setelah agak siang baru saya ketemu sama Pak Agung, dia nunjukin ruangan di mana materi untuk developer. Yach... dah kelewat jauh, kenapa gak dari awal dikasih tahu sama mbak-mbak-nya yang cantiq-cantik itu kalo Office di sini, developer di sana.

    Acara demi acara dibawakan oleh beberapa MVP Indonesia tampak mendapat perhatian dari audience. Ada beberapa yang menarik bagi saya mengenai demo robot dan aplikasi pada Windows Mobile.

    Pada jam makan siang saya menuju area lunch (makan siang), saya beserta teman kantor lansung aja ambil makanan yang ada di situ. Setelah itu buset dah.... ternyata HARUS BAYAR 100.000 untuk dua orang. Karena dah capek dan merasa ketipu ma warung tegel (tega Stick out tongue) serta ditanyain melulu ma boss di Belanda, yach... pulang deh....

    Laen kali kalo ngadain acara, petunjuk untuk masing-masing ruangan yang jelas donk biar gak salah kamar. Kalo mau makan juga harus hati-hati, ntar disuruh bayar 1 juta bisa tekor Sad. Untungnya sampai kator diganti sama boss. Hehehe... gak jadi tekor Smile

    Share this post: | | | |
    Posted Apr 11 2007, 02:12 PM by cahnom with 4 comment(s)
    Filed under:
  • Register ASP.NET 2.0 pada IIS7 (Vista)

    Register ASP.NET ke IIS (Internet Information Services) 7 di Windows Vista sebenarnya sama dengan versi sebelumnya yaitu menggunakan tool aspnet_regiis di command prompt. Perbedaannya adalah pada cara menjalankan command prompt.

    Pada Windows selain Vista, proses registrasi dilakukan dengan login sebagai user yang memiliki hak Administrator. Jalankan command prompt dan masuk ke direktori %WINDIR%\Microsoft.NET\Framework\<Net Version> dengan <Net Version> adalah versi .NET yang digunakan. Selanjutnya jalankan perintah aspnet_regiis -i untuk melakukan instalasi ASP.NET pada IIS, sebagai contoh:

    C:\Windows\System32> cd %WINDIR%\Microsoft.NET\Framework\v2.0.50727
    C:\Windows\Microsoft.NET\Framework\v2.0.50727> aspnet_regiis -i
    Start installing ASP.NET (2.0.50727).
    ................................................................................
    ..............................................................
    Finished installing ASP.NET (2.0.50727).

    Pada Windows Vista, jika dilakukan langkah-langkah seperti di atas, akan muncul pesan sebagai berikut:

    C:\Windows\System32> cd %WINDIR%\Microsoft.NET\Framework\v2.0.50727
    C:\Windows\Microsoft.NET\Framework\v2.0.50727> aspnet_regiis -i
    Start installing ASP.NET (2.0.50727).
    .
    An error has occurred: 0x800702e4 The requested operation requires elevation.

    Error tesebut dikarenakan command prompt dijalankan sebagai normal user walaupun login sebagai administrator. Untuk menjalankan command prompt sebagai administrator, klik Start (Logo Windows Vista di pojok kiri bawah). Pada start search ketik cmd, link command prompt akan muncul daftar program. Klik kanan pada cmd (di bawah program), klik run as administrator. Nah, sekarang command prompt dijalankan dengan hak administrator (tidak sebagai normal user). Jalankan aspnet_regiis -i seperti biasa untuk melakukan registrasi ASP.NET di IIS. Selesai dech.

    Share this post: | | | |
    Posted Apr 02 2007, 12:00 PM by cahnom with 14 comment(s)
    Filed under: ,