http://oscardelben.com/seven-languages-io-day-1
我刚买了Seven languages in seven weeks这本书的Beta版,真是一本好书。
公司内部学习使用,转载请注明。
DotNet introduction release DotNet introduction release pdf file
操作excel
1: require "Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
2:
3: include Microsoft::Office::Interop::Excel
4: excel = ApplicationClass.new
5: excel.Visible = true
6: workbook = excel.Workbooks.Add()
7: worksheet = workbook.Worksheets.Add()
8: worksheet.Name = "aaaaa"
9:
10: cell1 = worksheet.Cells(1,1)
11: cell1.Value = 42
如何获得assembly的strong name?
1: load_assembly 'Microsoft.Office.Interop.Excel'
2:
3: System::AppDomain.current_domain.get_assemblies.each{|x| puts x};
RPC 解决方案(http://www.ruby-forum.com/topic/206314)
Very CLR centric:
You can create a proxy to your webservice using visual studio, compile to a dll and use the proxy from your ruby code.
CLR centric:
You can use System.Net.HttpWebRequest to make the request and System.Xml.XmlDocument to parse the response
Very Ruby centric:
Use Net::HTTP to perform the request and REXML to parse the response
IronRuby下载最新版本解压,然后把目录加入系统Path。
IronRuby使用Sinatra
1)igem install sinatra –no-rdoc –no-ri
2) 应该提示rack和sinatra都安装完毕
3)写代码如下:
1: require 'rubygems'
2: require 'sinatra'
3: get '/' do
4: "My machine name is #{System::Environment::machine_name}"
5: end
保存为mysinatra1.rb
4) 运行 ir mysinatra1.rb,应该提示类似pid=xxxx port=4567,打开浏览器,输入http://localhost:4567/ 就可以看到期望的信息了。
注意,在我测试过程中,最新版本下,不需要对sinatra做任何patch,跟ironruby官网提到的不一样。
IronRuby使用Rails,参考http://www.ironruby.net/Documentation/Real_Ruby_Applications/Rails
1)安装 "igem install rake rails activerecord-adonet-sqlserver –no-rdoc –no-ri"
2)如果自己测试,可使用sqlite3-ironruby,"igem install sqlite3-ironruby –no-ri –no-rdoc”
3)建立一个IronRuby rail程序, "ir -S rails IronFirst"
4)修改config/environment.rb,可以看到有类似的代码,改成 config.gem "sqlite3-ironruby", :lib => "sqlite3" ,使用sqlserver有另外的修改方式,大家自己看网页吧。
5)ir script\generate scaffold post title:string body:text published:boolean
ir -S rake db:migrate
6)ir script\server
这时候可以看到http://localhost:3000 是rails的默认界面,进入http://localhost:3000/posts 可以进行添删改操作。不过我测试,默认下不支持中文,应该是要修改一些参数才行。
all done.
最近准备学习dotnet,要有一些代码练练手。看好了sliverlight或者wpf,毕竟是下一代显示技术。
基本设想如下,客户端运行程序,读取数据,动态生成投票(或者是survey)界面,运行,保存,然后将数据传回服务器端。
技术问题不算多,也有,比如sliverlight其实是没法直接连接数据库的,这个从安全角度也说得通。所以就要引入WCF或者RIAService技术,又多了一层曲线要学。
如何让读取保存数据过程更简单,容易实现?我想到了ironpython。
下载了最新版本的ironpython,搜索一下xmlrpc就能找到这篇文章:
http://www.ibm.com/developerworks/library/ws-pyth10.html
其中服务器代码如下:
import calendar, SimpleXMLRPCServer
#The server object
class Calendar:
def getMonth(self, year, month):
return calendar.month(year, month)
def getYear(self, year):
return calendar.calendar(year)
calendar_object = Calendar()
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8888))
server.register_instance(calendar_object)
#Go into the main listener loop
print "Listening on port 8888"
server.serve_forever()
客户端代码如下
import xmlrpclib
server = xmlrpclib.ServerProxy("http://localhost:8888")
month = server.getMonth(2002, 8)
print month
主要是python的标准库实现了xmlrpc机制,而WCF技术说白了,也就是类似XMLRPC这样的remote process calling技术,换个马甲我就不认识你了么?
应该也可以通过dotnet framework,没那兴趣继续研究,就到这里吧。
ironpython应用于WPF的文章也很多,有机会试验了以后写出来。