2010-10-18

Install OS X Snow Leopard from a USB flash drive

Original post from http://www.maciverse.com/install-os-x-snow-leopard-from-usb-flash-drive.html

Install OS X Snow Leopard from a USB flash drive

by Dan 
If you enjoy this article and other information provided here at Maciverse.com, be sure to keep up with the latest Mac hints, tips, and more by following us on twitter @Maciverse or by subscribing to our feed.

The steps below will guide you through how to Install OS X Snow Leopard from a USB Flash Drive. If you want to skip the steps and get your USB installation drive quickly, check out our pre-configured USB Snow Leopard Installation Drive. Read on if you’d like to create a USB Installation yourself.
Apple officially released Snow Leopard yesterday and consumers could find the latest version of OS X at Apple Stores and resellers across the country.
At version 10.6, Snow Leopard, focused more on improving speed and performance than adding new features to OS X. With the operating system available to customers, individuals are ready for their upgrades.

Installing OS X From a USB Drive

Like other versions of OS X, Snow Leopard can be installed from a USB drive. This is especially beneficial to Macbook Air users looking to install the OS without a DVD drive. To do this, you’ll need to prepare your USB drive with the installation files. Like many of our other Mac Help articles, the steps listed below worked particularly for Snow Leopard but should also work for installing OS X from USB on Leopard.
The installation files sit at 6.2gb on the Snow Leopard DVD, so you’ll probably need a drive that has at least 8gb available. If you want your installation files to last against the elements, check out this 8 GB Water/Shock Resistant USB flash drive. Or something a bit more interesting, the USB Humping Dog… Although I don’t believe that has enough disk space.
After you’ve gotten the correct USB device, connect it to your Mac and prepare it with the Snow Leopard installation files by following these steps:
NOTE:Depending on your flash drive, you may need to follow steps 5 – 7 on on installing onto a USB drive to make sure the drive is bootable before you get start.
  1. Open Disk Utility and select the Flash Drive
  2. Select the Erase tab on the right and then set Format to Mac OS Extended (Journaled). Name the partition you’ll be creating Snow Leopard or OS X Install so you can keep track of your installation device. After you’ve done this, click the Erase button.
  3. After Disk Utility finishes erasing your old data on the flash drive and setting it as a new partition, it will be ready for the Snow Leopard install files. Select the Restore tab at the top and then drag the Snow Leopard DVD to the Source field. Select your USB device for the Destination file. Click Restore and wait for the restoration to finish (about 20 minutes).
  4. If the restoration worked correctly you should be able to open your USB device and see the Leopard installation files. If you try and click the Install OS X Snow Leopard icon, you’ll get the message below telling you you can’ install OS X from this volume. IGNORE the message. The next steps will walk you through the installation steps.
  5. Now that the installation files are successfully on your USB device, be sure to remove the Snow Leopard installation DVD from your drive. Next, restart your Mac and when it first starts to reboot, be sure to hold down the option (alt) key on your keyboard. After a few seconds at least two volumes should appear for you to select from for installation. One of those will be the USB drive we just prepared. Select it.
  6. After the Snow Leopard installation software boots from your USB drive, follow the on screen instructions for installation. It took about 38 minutes to install Snow Leopard on my machine from the USB drive. I’m curious to see how this compares to the average Mac users, please leave a post in the comments letting us know how long it took on your machine.
  7. After the installation finishes, it will reboot your computer into your new upgraded version of OS X, version 10.6 Snow Leopard
This method works for installing OS X Snow Leopard onto a Mac from a USB Drive. It should also work for installing Leopard or other older versions of OS X on Intel Based Macs. Check back often for additional help and tips for your Mac

2010-08-19

The future of XForms

Mấy hôm nay mình ngồi research một số nền tảng để build UI cho các dự án sắp tới. Mục tiêu là cross-flatform, chạy trên cả web và desktop environment. Tất nhiên là hướng tới 'rich client', build UI dynamically và có khả năng validate data dựa trên XSD chẳng hạn.

Nói thì vậy thôi chứ thiệt ra chẳng có gì mới. Toàn bộ các ông lớn như Sun, Microsoft, Oracle, IBM, Mozilla ... hiện tại cũng đang có những project nhằm đạt được những điều đó. Và vì nhiều thứ quá nên mình có một chút confused vì căn bản chẳng thể có thời gian thử hết tất cả để biết là cái gì hợp với mình. Đúng là thời đại hỗn loạn XAML/WPF rồi MXML, XUL, XForms...

Rồi có lẽ mình focus vào XUL và XForms. Nhưng chọn XUL thì là có mối lo khác, nếu nó có lỗi thì sao, rà sơ qua stackoverflow thấy ít người recommend XUL? Đến cả Firefox kêu drop XUL (remote XUL) khỏi Firefox 4 khiến bao nhiêu developer vào comment tranh cãi. Dù rằng chỉ là remote XUL nhưng rõ ràng là XUL có một cái gì đó ko chắc chắn (I think ...) mà đáng ra phát triển bao nhiêu năm thì phải có một sự vững chãi?


Bây giờ thì focus vào XForms, đang research XForms engine. Với web thì có lẽ OK rồi còn desktop thì mới tìm hiểu Apogee Project. Giống 1 câu trong guidance của Prism "... although there is no single way to evaluate a solution ..." thật không hề đơn giản. Đơn giản là một khi đã focus thì cố lên.

2010-07-10

WPF and Silverlight Framework - Dùng Prism để xây dựng ứng dụng WPF/Silverlight


Sử dụng Prism để xây dựng ứng dụng WPF/Silverlight

Khi mấy cái projects sẽ làm đụng đến WPF thì mình lại phải đi tìm hiểu trước 1 đám framework mới hy vọng chọn 1 cái khả dĩ dùng được rồi document lại, note lại những thứ cần chú ý rồi viết hướng dẫn ... Tất nhiên là try khác với use vì vậy để sử dụng được hay không cũng try cái đã. Nếu personal thì chắc cũng chẳng cần framework, mình chỉ viết vài cái toy thì túc tắc cái gì không giải quyết được lại Googling. Có thể list ra nhiều framework nhưng có vẻ nổi nhất là Caliburn và Prism hay ít nổi hơn là WAF. Đã định try thật kỹ cái Prism từ 2 năm trước :D nhưng rồi cũng xem sơ sơ. Giờ đã xem được 1 đoạn dài nên ngồi viết lại chút xíu thay đổi không khí. Đến khi xong thằng này thì sẽ coi tiếp Caliburn xem. Nhớ lại cái đám CAB/SCSF giờ cũng quăn 1 đống, hic xung quanh phát triển nhanh quá theo ko kịp.

Giới thiệu
Nối tiếp CAB/SCSF Patterns & Practices phát triển một guidance mới với mục tiêu hỗ trợ việc xây dựng ứng dụng với WPF, phiên bản đầu tiên gọi là Prism 1.0 hay Composite Application Guidance for WPF version 1.0 vào tháng 6 năm 2008. Sau đó Prism được bổ sung Silverlight gọi là Prism 2.1 hay Composite Application Guidance for WPF and Silverlight version 2.1 dành cho Silverlight 3 được ra mắt vào tháng 10 2009. Version tiếp theo là Prism 2.2 dành cho Silverlight 4 vào tháng 5 năm 2010 là một minor update của Prism 2.1 (các project chuyển qua Visual Studio 2010, target vào Silverlight 4 và update Silverlight Toolkit).

Hiện tại Prism có version 4.0 drop 3 dành cho Silverlight 4 vào ngày 1 tháng 7 năm 2010 (bài viết này là ngày 10/7/2010) với Microsoft Visual Studio 2010, Microsoft .NET Framework 4.0, Microsoft Silverlight 4, Microsoft Silverlight 4 Tools for Visual Studio 2010.

Composite Application Guidance là gì?
Là một bộ các guidance tức các chỉ dẫn bao gồm các tham khảo, ví dụ cài đặt (reference implementation), reusable library code được gọi là Composite Application Library, tài liệu, QuickStarts và hand-on labs. Đối tượng hướng tới là các software architects và developers thực hiện xây dựng các enterprise-level applications sử dụng WPF hay Silverlight.

Những loại ứng dụng này thông thường bao gồm nhiều màn hình screens, nhiều tính năng, khả năng tương tác với user linh hoạt, hiển thị dữ liệu trực quan ... Một phần quan trọng là các ứng dụng này có đặc điểm "built to last" và "built for change". Có nghĩa là các ứng dụng được mong đợi là có vòng đời tính bằng nhiều năm và có khả năng thay đổi theo những yêu cầu mới mà các yêu cầu này chưa biết trước (new and unforeseen requirements). Vì vậy ứng dụng ban đầu có thể nhỏ và được tạo thành từ những thành phần liên độc lập, kết yếu với nhau (composed of multiple independent and loosely-coupled pieces).

Các phần có trong Guidance
Guidance bao gồm các thành phần sau:
  • Composite Application Library và Unity binaries hay source code
  • StockTrader Reference Implementation là một ứng dụng mẫu dựa trên yêu cầu thực tế (real-world scenario). Đây là một tham khảo tốt để tìm hiểu những vấn đề được xác định và giải quyết như thế nào khi xây dựng composite applications.
  • 4 QuickStarts: UIComposition QS, EventAggregation QS, Modularity QS và Commanding QS là những ứng dụng nhỏ focus vào một mục tiêu cụ thể như UI composition, modularity, commanding, event aggregation ...
  • Composite Application Guidance Hands-On Lab
  • API Documentation
  • Composite Application Guidance Documentation


Stock Trader RI

Documentation
Có thể dùng diagram dưới đây để xem các thành phần trong Composite Application Guidance Documentation.
Composite Application Guidance

Trong trường hợp đã làm quen với CAB, Prism có một tài liệu riêng cho CAB developer Composite Application Guidance for CAB Developers

Home site
Home site của Prism tại địa chỉ http://compositewpf.codeplex.com/.

System requirements
Các yêu cầu phụ thuộc vào 2 vấn đề chính cần chú ý là phiên bản của Visual Studio và Silverlight.
Nếu dùng Visual Studio 2010 hay Silverlight 4 thì version của Prism tương ứng là Prism 2.2 (for Silverlight 4) - May 2010 hay Prism 4.0 Drop 3.
Nếu dùng Visual Studio 2008 thì chúng ta dùng Prism 2.1. Các yêu cầu cụ thể như sau:
·         Microsoft Visual Studio 2008 SP1
·         Microsoft .NET Framework 3.5 SP1 (.NET Framework 3.5 bao gồm WPF)
·         Microsoft Silverlight (nếu tạo ứng dụng Silverlight)
·         Microsoft Silverlight 3 Tools for Visual Studio 2008 SP1 (nếu tạo ứng dụng Silverlight)

Tham khảo
Article Patterns For Building Composite Applications With WPF - MSDN Magazine September/2008 
Prism resources at Channel9 MSDN



2010-06-17

VisualTreeHelper.HitTest và UserControl

Từ khi chuyển qua WPF nhiều thứ thay đổi, kể cả các thói quen khi code WinForms. Ví dụ trong trường hợp nào đó, mình nghĩ chức năng tương tự của WinForms nhưng WPF lại không có. Ví dụ khi click nghĩ đến bounds của control, rồi nghĩ tới 1 cái gì đó đại loại hit test thế rồi nó sẽ dẫn đến VisualTreeHelper.HitTest của WPF chẳng hạn. Nhưng mọi chuyện đâu có tuần tự tốt đẹp như vậy, sẽ có nhiều thứ để nghĩ hơn.

Ví dụ có UserControl như sau:
-->
<UserControl x:Class="TestHitTest.DemoControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="200">
    <Grid>
        <Label Content="This is a demo control" />
        <Rectangle Fill="#FF1E59C1" Stroke="Black" HorizontalAlignment="Left" Margin="18,18,0,0" VerticalAlignment="Top" Width="93" Height="48" Opacity="0.7"/>
        <Rectangle Fill="#FF83A3DA" Stroke="Black" Margin="71,29,80,0" VerticalAlignment="Top" Height="56" Opacity="0.7"/>
        <Rectangle Fill="#FF2D3441" Stroke="Black" HorizontalAlignment="Left" Margin="53,47,0,0" VerticalAlignment="Top" Width="48" Height="38" Opacity="0.7"/>
        <Rectangle Fill="#FF97A2B5" Stroke="Black" HorizontalAlignment="Left" Margin="18,75,0,0" VerticalAlignment="Top" Width="53" Height="53" Opacity="0.7"/>
        <Rectangle Fill="#FF7AA4EE" Stroke="Black" HorizontalAlignment="Left" Margin="32,96,0,114" Width="55" Opacity="0.7"/>
        <Rectangle Fill="#FF3E547A" Stroke="Black" HorizontalAlignment="Right" Margin="0,56,31,0" VerticalAlignment="Top" Width="102" Height="56" Opacity="0.7"/>
    Grid>
UserControl>

  Trong main win chứa 2 user control: 1 bên trái và một bên phải
-->
<Window x:Class="TestHitTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TestHitTest" Title="Window1" Width="600" Height="300">
    <Grid x:Name="_grid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50*" />
            <ColumnDefinition Width="50*" />
        Grid.ColumnDefinitions>
        <local:DemoControl x:Name="_leftControl" Grid.Column="0" />
        <local:DemoControl x:Name="_rightControl" Grid.Column="1" />
    Grid>
Window>


Dạng như sau:












Bây giờ đơn giản khi click chúng ta cần xác định click vào user control bên phải hay bên trái và chúng ta đang đề cập VisualTreeHelper.HitTest.

Test thử HitTest
-->
namespace TestHitTest
{
    ///
    /// Interaction logic for Window1.xaml
    ///
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            MouseLeftButtonDown += new MouseButtonEventHandler(OnMouseLeftButtonDown);
        }

        void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var pt = e.GetPosition(_grid);
            var area = new EllipseGeometry(pt, 1, 1);
            Debug.WriteLine("--- Demo hit test ---");
            VisualTreeHelper.HitTest(
                _grid,
                filter =>
                {                   
                    Debug.WriteLine("Pass through filter " + filter);
                    return HitTestFilterBehavior.Continue;
                },
                result =>
                {
                    Debug.WriteLine("Pass through result " + result.VisualHit);
                    return HitTestResultBehavior.Continue;
                },
                new GeometryHitTestParameters(area)
            );
        }
    }
}

OK run và click ta được 1 cái kết quả như sau
-->
--- Demo hit test ---
Pass through filter System.Windows.Controls.Grid
Pass through filter TestHitTest.DemoControl
Pass through filter System.Windows.Controls.Border
Pass through filter System.Windows.Controls.ContentPresenter
Pass through filter System.Windows.Controls.Grid
Pass through filter System.Windows.Shapes.Rectangle
Pass through result System.Windows.Shapes.Rectangle
Pass through filter System.Windows.Shapes.Rectangle
Pass through result System.Windows.Shapes.Rectangle
Pass through filter System.Windows.Shapes.Rectangle
Pass through result System.Windows.Shapes.Rectangle
Pass through filter System.Windows.Controls.Label: This is a demo control
Pass through filter System.Windows.Controls.Border
Pass through result System.Windows.Controls.Border

Bây giờ chỉnh 1 chút phần filter. Như đã biết filter sẽ lọc những thứ không cần thực hiện hit test trước khi cho ra kết quả. Theo code bên dưới khi đến DemoControl thì không cần duyệt children nữa.
-->
void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    var pt = e.GetPosition(_grid);
    var area = new EllipseGeometry(pt, 1, 1);
    Debug.WriteLine("--- Demo hit test ---");
    VisualTreeHelper.HitTest(
        _grid,
        filter =>
        {
            Debug.WriteLine("Pass through filter " + filter);

            if (filter.GetType().IsAssignableFrom(typeof(DemoControl)))
            {
                return HitTestFilterBehavior.ContinueSkipChildren;
            }
            else
            {
                return HitTestFilterBehavior.Continue;
            }
        },
        result =>
        {
            Debug.WriteLine("Pass through result " + result.VisualHit);
            return HitTestResultBehavior.Continue;
        },
        new GeometryHitTestParameters(area)
    );
}


Kết quả nghèo nàn như sau:

-->
--- Demo hit test ---
Pass through filter System.Windows.Controls.Grid
Pass through filter TestHitTest.DemoControl

Có nghĩa là sao,  phải chăng VisualTreeHelper.HitTest không nói rõ ràng cho lắm. Trong phần result không thèm đếm xỉa tới UserControl mà coi UserControl là một collection của các base elements. Như vậy filter chỉ dùng để hạn chế còn trong phần hit test result thì không có khái niệm user control. Trong trường hợp như vậy thì xử lý ntn?

Chúng ta sẽ thực hiện tìm parent cho hit test result
-->
public static T FindVisualParent<T>(DependencyObject child)
    where T : DependencyObject
{

    // get parent item
    DependencyObject parentObject = VisualTreeHelper.GetParent(child);

    // we’ve reached the end of the tree
    if (parentObject == null) return null;

    // check if the parent matches the type we’re looking for
    T parent = parentObject as T;

    if (parent != null)
    {
        return parent;
    }
    else
    {

        // use recursion to proceed with next level
        return FindVisualParent<T>(parentObject);
    }
}

OK lúc này hit test result sửa lại như sau (có vẻ tạm ổn):

 
-->
void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    var pt = e.GetPosition(_grid);
    var area = new EllipseGeometry(pt, 1, 1);
    bool isLeft = false;
    bool isRight = false;

    Debug.WriteLine("--- Demo hit test ---");
    VisualTreeHelper.HitTest(
        _grid,
        null,
        result =>
        {
            Debug.WriteLine("Pass through result " + result.VisualHit);
            IntersectionDetail detail = ((GeometryHitTestResult)result).IntersectionDetail;

            switch (detail)
            {

                case IntersectionDetail.FullyContains:
                case IntersectionDetail.Intersects:
                case IntersectionDetail.FullyInside:
                    Debug.WriteLine(result.VisualHit.ToString());
                    DemoControl control = FindVisualParent<DemoControl>(result.VisualHit);

                    if (control != null)
                    {

                        if (control.Equals(_leftControl))
                        {
                            isLeft = true;
                            Debug.WriteLine("Click on left control");
                        }
                        else if (control.Equals(_rightControl))
                        {
                            isRight = true;
                            Debug.WriteLine("Click on right control");
                        }
                        return HitTestResultBehavior.Stop;
                    }
                    return HitTestResultBehavior.Continue;
                default:
                    return HitTestResultBehavior.Stop;
            }
        },
        new GeometryHitTestParameters(area)
    );
}