.NET

Updates on IronRuby

in

Last week I went to Thailand Next Web App and joined in a Rails session. They had a talk and discussed about running Rails in production. Of course, JRuby, Glassfish and other Ruby implementation including IronRuby were mentioned. Then I was asked about it because I was the only .NET guy there. At that time, I didn’t follow the IronRuby for a long time so I replied them that no one other than John Lam and Phil Haacked have used the IronRuby.

Few days ago, while I read the feed about asp.net, I found an open source IronRuby project that aims to help developer implement WPF/Silverlight in rails-like fashion. And that’s mean we, the developers, now can use IronRuby.

After some googling, I’ve recalled that IronRuby, like IronPython, is part of the Microsoft Dynamic Language Runtime. They both are released with full source under Microsoft Public License(MS-PL). Though the source code of IronRuby is hosted on RubyForge and IronPython is on the CodePlex, the license doesn’t mention that they’re open source projects. However, the IronRuby libraries are tended to be open source and are opened to receive the contributions.

From the IronRuby home page, the implementation still does not pass the RubySpecs and can only dispatch some Rails requests. That’s mean it still cannot be used to host a Rails application. But you can utilize .NET framework and create an application with it, like IronNails. If you want to give it a try, you have to compile it yourself from the source. Of course, Windows machine is essential.

In TNWA last week, Sirn said “Don’t host your rails apps with IIS”. I’m sure the situation will change if IronRuby can host Rails app perfectly and I’m waiting for that day.

PS. As for IronPython, I saw how IronPython used with ASP.NET and it was fantastic!! However, I never have chance to try it myself.

The Anatomy of Wave File

in

เนื่องจากจำเป็นจะต้องทำงานกับไฟล์เสียงก็เลยต้องข้อมูลของไฟล์ wav มานั่งย่อยเพื่อเพิ่มความเข้าใจ หลังจากเข้าใจแล้วก็เลยต้องจดไว้ซักเล็กน้อยเผื่อว่าจะมีใครสนใจ

บล็อกนี้จะไม่อธิบายถึงวิธีการสร้างและรายละเอียดของเนื้อหาของไฟล์ Wave เท่าไหร่นะ แต่จะเน้นหนักไปที่เรื่องของโครงสร้างมากกว่า

พร้อมแล้วก็มาเริ่มได้เลย

Attribute

in

จาก Castle Active Record ทั้ง สอง ตอน ทำให้มานึกๆเอาแล้วก็สงสัยว่า ตอนที่ Initialize ตัว ActiveRecord ทำไมต้องมาใส่ข้อมูลของ Type ที่เราจะใช้ด้วยทั้งๆที่่เราก็ระบุ Attribute ActiveRecord ให้กับคลาสอยู่แล้ว ตอนนั้นก็เลยคิดขึ้นมาได้ว่าถ้าใช้ Reflection เข้ามาช่วยก็น่าจะใช้ได้นี่

    Assembly a = Assembly.GetExecutingAssembly();
    Type[] allTypes = a.GetTypes();
    List<Type> selectedType = new List<Type>();
    foreach (Type t in allTypes)
    {
        if (t.GetCustomAttributes(typeof(ActiveRecordAttribute), false) != null)
        {
            selectedType.Add(t);
        }
    }

    ActiveRecordStarter.Initialize(source, selectedType.ToArray());

คือตอนแรกเราก็จัดการดึง Type ทั้งหมดที่อยู่ใน Assembly ขึ้นมาก่อน แล้วก็เลือกเฉาพะที่แปะ Attribute ActiveRecord ขึ้นมาแล้วก็ส่งไปตอน initilize ก็เรียบร้อย

แต่ อ้ะๆๆๆ ยังก่อน

ถ้าเราดูโอเวอร์โหลดของ ActiveRecordStarter.Initialize เราก็จะเห็นว่ามันมีโอเวอร์โหลดที่รับ assembly เข้าไปเหมือนกันดังนั้นก็เลยแก้เป็น

    ActiveRecordStarter.Initialize(Assembly.GetExecutingAssembly(), source);

ง่ายกว่าแยะเลยแฮะ

ยังไงก็ตาม ถ้าเกิดมี type เป็นจำนวนมากแถมส่วนใหญ่ก็ไม่ใช่ type ของ activerecord ล่ะก็ ใส่เพิ่มเองแบบเดิมหรือไม่ก็แยก type เหล่านั้นออกไป assembly อื่น น่าจะให้ผลลัพธ์ที่ดีกว่านะ

Castle Active Record : Relationship

in

ต่อจากตอนที่แล้ว

สำหรับ Relation หรือความสัมพันธ์ที่ใช้ใน ActiveRecord จะมีหลักๆดังนี้

  • BelongsTo - ใช้ระบุความสัมพันธ์แบบ many-to-one หรือ one-to-one
  • HasMany - ใช้ระบุความสัมพันธ์แบบ one-to-many
  • HasAndBelongsToMany - ใช้ระบุความสัมพันธ์แบบ many-to-many