思归呓语

衣带渐宽终不悔,为伊消得人憔悴
随笔 - 413, 评论 - 2972, 引用 - 245

导航

关于

标签

每月存档

最新留言

广告

【第1页/共2页,19条】
首页
前页
1

Silverlight相关链接 - Reflector插件,Silverlight控件等

1. Ernie Booth的Reflector Silverlight Browser

View Source Reflector tool for .NET Silverlight Sites
http://blogs.msdn.com/ebooth/archive/2007/05/19/view-source-reflector-tool-for-net-silverlight-sites.aspx

允许你在Reflector下查看任何Silverlight应用的代码,无论是托管代码还是Javascript,可以极大地帮助你理解别人的Silverlight应用是怎么工作的

2. Dave Relyea的C#布局控件

Silverlight 1.1 Alpha Layout System and Controls Framework
http://blogs.msdn.com/devdave/archive/2007/05/17/silverlight-1-1-alpha-layout-system-and-controls-framework.aspx

Dave Relyea发表了他编写的布局控件框架项目,补充了Silverlight 1.1中现有控件框架的不足,内容包括

  • 布局框架
  • LayoutControl,LayoutContainerControl控件基类
  • Border
  • StackPanel
  • Grid
  • Label
  • Button
  • TextBox

示范网址:
http://www.simplegeek.com/mharsh/layout/

3. Joe Stegman的博客贴子

Some V1.0 Breaking Changes
http://blogs.msdn.com/jstegman/archive/2007/05/21/some-v1-0-breaking-changes.aspx

提到了V1.0版本中将出现的几个非兼容性变动,包括

  • 接连事件处理函数时不再需要“javascript:” ,他提供了一个更新过的silverlight.js
  • 插件名称从“WPFe Plug-In”改成“Silverlight Plug-In”
  • 动画标识现在要求TargetName和TargetProperty属性

4. Desperately Seeking Love of Sophie(绝望地渴求苏菲之爱)的博客对Silverlight Alpha以及控件样例做了系统的介绍

Basics of Silverlight Alpha Application
http://vivekdalvi.wordpress.com/2007/05/15/basics-of-silverlight-alpha-application/

Using Browser Host to Resize the Page Size
http://vivekdalvi.wordpress.com/2007/05/16/using-browser-host-to-resize-the-page-size/

Silverlight Toolbar
http://vivekdalvi.wordpress.com/2007/05/14/silverlight-toolbar/

Basics of Custom Control in Silverlight
http://vivekdalvi.wordpress.com/2007/05/02/basics-of-custom-control-in-silverlight/

Using ListBox
http://vivekdalvi.wordpress.com/2007/05/10/using-listbox/

Fix for Button control
http://vivekdalvi.wordpress.com/2007/05/18/fix-for-button-control/

相关链接也可以在下面博客上找到
http://blogs.msdn.com/vivekd/default.aspx

5. Jaime Rodriguez的Snoop for Silverlight 1.0
http://blogs.msdn.com/jaimer/archive/2007/05/17/early-version-of-snoop-for-silverlight-1-0.aspx

这个工具可以帮助你理解Silverlight视觉树里元素的组成结构以及元素的属性,跟踪鼠标事件导致的属性变化等。这个工具的示范网页在这里
http://jaimersamples.members.winisp.net/silverlight/10/snoopsample/default.html

6. US ISV Developer Evangelism Team的移植WPF到Silverlight系列,目前发表了4个部分

Porting WPF to Silverlight 1.1 - 1st of a series...
http://blogs.msdn.com/usisvde/archive/2007/05/16/porting-wpf-to-silverlight-1-1-1st-of-a-series.aspx

Porting WPF to Silverlight 1.1 - 2nd of a series...
http://blogs.msdn.com/usisvde/archive/2007/05/19/porting-wpf-to-silverlight-1-1-2nd-of-a-series.aspx

Porting WPF to Silverlight - 3rd of a series...
http://blogs.msdn.com/usisvde/archive/2007/05/19/porting-wpf-to-silverlight-3rd-of-a-series.aspx

Porting WPF to Silverlight - 4th of a series...
http://blogs.msdn.com/usisvde/archive/2007/05/20/porting-wpf-to-silverlight-4th-of-a-series.aspx

7. Mike Harsh的博客上还介绍了一堆很酷的样例
http://blogs.msdn.com/mharsh/default.aspx

posted on 2007-05-22 00:43:00 by saucer  评论(18) 阅读(8506)

微软推出Popfly,一个面向大众的基于Silverlight的web mashup builder应用

Popfly的宗旨是给非专业人员提供一个软件开发工具, 根据Popfly网站

http://www.popfly.ms/Overview/

Popfly可以让大家轻松建造和共享mashups,gadgets, 网页和应用。 Popfly 由两部分组成:

1。 Popfly Creator 是一套建造网页和mashup的在线视觉化工具
2。 Popfly Space 是个在线creators社区,用户可以存放和共享自己的作品,评论和修改其他用户的作品

Popfly提供了一堆预制/连接好的web服务/编程模块可为用户所用,它支持JavaScript/AJAX,Popfly还提供了与Visual Studio的集成

Channel 9 有个采访开发团队和开发人员示范的录像
http://channel9.msdn.com/showpost.aspx?postid=308460

Adam Natham提供了一个screencast录像链接,进一步展示了Popfly的功能
http://go.microsoft.com/fwlink/?LinkID=91175

该项目目前还处于alpha测试阶段,还没有向大众开放。

posted on 2007-05-19 03:14:00 by saucer  评论(13) 阅读(9145)

Silverlight资源链接

今天在MSDN博客上,有个广为传抄 Asli Bilgin 编篡的 Silverlight resources 列表,这是小气的神博客上相关贴子的链接:

Silverlight Resources
http://blogs.msdn.com/ccboy/archive/2007/05/15/silverlight-resources.aspx

posted on 2007-05-16 01:13:00 by saucer  评论(6) 阅读(6686)

Silverlight 相关链接

1. 如果你真对Silverlight感兴趣的话,Mike Harsh的博客不可不读。他最新的一篇博客是关于他的SilverlightPad的,它允许你在浏览器里编写和运行XAML/Javascript代码

SilverlightPad - Now with Javascript Editing and Preview
http://blogs.msdn.com/mharsh/archive/2007/05/14/updated-silverlightpad-now-with-javascript-editing-and-preview.aspx

2. Ian Blackburn的Silverlight Mindmap

图片版本
http://www.bbits.co.uk/playground/silverlight/index.html

Silverlight版本
http://www.bbits.co.uk/playground/silverlight/silverlight_mind_map.htm

3. .NET Security博客发表了4篇关于Silverlight安全模型的贴子

The Silverlight Security Model
http://blogs.msdn.com/shawnfa/archive/2007/05/09/the-silverlight-security-model.aspx

Silverlight Security II: What Makes a Method Critical
http://blogs.msdn.com/shawnfa/archive/2007/05/10/silverlight-security-ii-what-makes-a-method-critical.aspx

Silverlight Security III: Inheritance
http://blogs.msdn.com/shawnfa/archive/2007/05/11/silverlight-security-iii-inheritance.aspx

Silverlight Security Cheat Sheet
http://blogs.msdn.com/shawnfa/archive/2007/05/14/silverlight-security-cheat-sheet.aspx

最后这篇贴子里面,列出了Silverlight安全模型的要点:(其中提到的平台程序集,platform assemblies,是指那些被Microsoft的特别公钥签过名的程序集)

  • 所有Silverlight应用都是security transparent(安全透明的),这意味着它们不能:
    • 含有无法校验的代码
    • 直接调用native代码
  • Silverlight应用可以访问平台程序集呈示的公开方法,只要它们是:
    • Security transparent (所用类或方法没有任何安全特性(security attributes))
    • Security safe critical (所用方法带有SecuritySafeCriticalAttribute特性)
  • Silverlight应用可以含有继承自下述类型的类型:
    • 当前应用中的其他类型
    • 由平台程序集定义的非密封的(Unsealed),而且是公开的,security transparent的类型和接口
  • Silverlight中的类型可以覆盖符合下述条件的虚拟方法或实现接口方法:
    • 当前应用本身定义的方法
    • 由平台程序集定义的,是security transparent或safe critical的方法

4. Reflector作者Lutz Roeder的三个Silverlight 1.1 Alpha样例

Monotone,Digger,Inplay
http://www.aisto.com/roeder/silverlight/

5. MSDN杂志六月份期的关于Silverlight的文章

中文版:SILVERLIGHT - 开始在整个网站积累更深入的体验
http://msdn.microsoft.com/msdnmag/issues/07/06/Silverlight/default.aspx?loc=zh

英文版:SILVERLIGHT - Get Started Building A Deeper Experience Across The Web
http://msdn.microsoft.com/msdnmag/issues/07/06/Silverlight/default.aspx?loc=en

6. Jason Zander 显示机器上运行的进程里CLR版本的代码

Code Sample: Is Your Process Using the Silverlight CLR?
http://blogs.msdn.com/jasonz/archive/2007/05/11/code-sample-is-your-process-using-the-silverlight-clr.aspx

7. Wilco Bauwer的Silverlight 1.1异步文件上传控件样例

Silverlight ASP.NET control: AsyncFileUpload
http://www.wilcob.com/Wilco/View.aspx?NewsID=204

8. Silverlight 1.1 文本框控件样例

Silverlight Alpha 1.1 TextBox
http://dotnetjunkies.com/WebLog/appeng/archive/2007/05/07/silverlight_1_1_alpha_textbox_sample.aspx

posted on 2007-05-15 01:36:00 by saucer  评论(8) 阅读(7559)

SynchronizationContext

在博客园上看到一个贴子

.net3.0 中跨线程访问控件
http://www.cnblogs.com/zhouyinhui/archive/2007/05/10/742134.aspx

 

其实有更简便的方法。。。

在编写桌面程序需要使用多线程时,如果在工作线程里需要更新界面上的东西,因为Windows编程的特性,需要将这个工作放在界面所在的线程来执行。在1.*里,需要使用控件的BeginInvoke和判断控件的InvokeRequired属性来实现。可以参考Chris Sells在MSDN上的文章,

Safe, Simple Multithreading in Windows Forms, Part 2
http://msdn2.microsoft.com/en-us/library/ms951109.aspx

 

.NET 2.0 引进了System.Threading.SynchronizationContext类,
http://msdn2.microsoft.com/en-us/library/system.threading.synchronizationcontext.aspx

这个类 “Provides the basic functionality for propagating a synchronization context in various synchronization models.”

用这个类可以简化要写的编码。譬如,如果有个按钮,点击后启动一个线程,来设置主窗口的背景颜色,如果这么做

static void Button_Clicked(Object sender, RoutedEventArgs e)
{
Thread t = new Thread(RunWorkerThread);
t.Start();
}

static void RunWorkerThread(Object o)
{
SetBackground(null);
}

static void SetBackground(Object o)
{
mainWindow.Background = Brushes.Red;
}

会出错。但如果这么做,

static void Button_Clicked(Object sender, RoutedEventArgs e)
{
Thread t = new Thread(RunWorkerThread);
t.Start(SynchronizationContext.Current);//传入当前的同步上下文
}

static void RunWorkerThread(Object o)
{
//使用传入的上下文把消息发送到原来的线程上去
SynchronizationContext sc = o as SynchronizationContext;
sc.Post(SetBackground,null);
}

static void SetBackground(Object o)
{
mainWindow.Background = Brushes.Red;
}

就工作了。

posted on 2007-05-11 13:15:00 by saucer  评论(7) 阅读(8863)

Silverlight 1.1的CLR可以与任何一个其他版本的CLR在一个进程里面同时运行

根据.NET框架开发团队的主管Jason Zander的博客

Side by Side In Process CLRs Start with Silverlight
http://blogs.msdn.com/jasonz/archive/2007/05/10/side-by-side-in-process-clrs-start-with-silverlight.aspx

自.NET有史以来,不同版本的CLR是不能在同一个进程里面同时运行的,即,每个进程里只允许一个版本的CLR。

但从Silverlight 1.1版本的CLR开始,这情形已经改变了,Silverlight的CLR是可以与任何一个其他版本的CLR在一个进程里面同时运行的。以后版本的CLR也将能与其他版本的CLR在一个进程里同时运行。据他的博客,一开始不允许多个版本的CLR同时运行主要是基于两个考虑,一是怕因多个CLR的GC造成的线程暂挂(thread suspension)会有冲突,二是多个CLR因为各自需要保留GC heap和装载代码,从而造成性能问题。

他有一个演示,展示了Silverlight的CLR是如何在一个WPF桌面程序里与CLR 2.0同时运行的。

下面是这个演示的连接
http://download.microsoft.com/download/E/2/0/E20F14A8-C210-4416-AEDD-2C53DA6F40E8/sxsclr.wmv

posted on 2007-05-11 05:16:00 by saucer  评论(7) 阅读(7121)

Silverlight与北京奥运

看到几个跟北京奥运有关的连接

采访:北京奥运会使用Silverlight
http://visitmix.com/Blogs/Joshua/beijing-olympics-visit-mix07/

据说开心是福娃,在这个采访里,他还说话了呢: Welcome to Beijing!

MIX07上的分会场讲座,是搜狐做的
Citius, Altius, Fortius: Windows Presentation Foundation and the 2008 Olympic Games
http://sessions.visitmix.com/upperlayer.asp?event=&session=&id=1557&year=All&search=xb005&sortChoice=&stype=

但奥运会火炬接力路线图用的却是FLASH
http://torchrelay.beijing2008.cn/en/journey/map/

posted on 2007-05-10 05:06:00 by saucer  评论(8) 阅读(6538)

Jasper中的定制

一。 在Jasper中,针对数据定义的具体情形,一般有三种方案:

1.数据库中的数据定义与应用中的对象模型有一一对应的关系,那么不用做任何改动,直接调用默认的API即可

2.如果数据库中的数据定义与应用中的对象模型结构类同,但名称有所不同,则可以通过Jasper的命名服务(NameService)来做映射

譬如,我想把我以前的例子中的User->Yonghu,Post->Tiezi, UserName->Zhanghao,我可以这么做

>>> import clr
>>> import System
>>> from System import *
>>>
>>> clr.AddReference("Microsoft.Jasper.CTP")
>>> from Microsoft.Jasper import *

要使用NameService,需要引进这个程序集:

>>> clr.AddReference("System.Data.Entity.Design.CTP")
>>> from System.Data.Entity.Design import *

生成一个命名服务对象,在其中的PropertyNameMap和ClassNameMap添加映射,如果需要的话,还可以添加成员变量,方法名,以及参数名的映射

>>> nameService = NameService()
>>> nameService.BaseNameService = NameService.Default
>>> nameService.PropertyNameMap.AddNameMapping("UserName", "Zhanghao")
>>> nameService.ClassNameMap.AddNameMapping("Users", "Yonghus")
>>> nameService.ClassNameMap.AddNameMapping("Posts", "Tiezis")
>>>
>>> connStr = "Provider='System.Data.SqlClient';Provider Connection String='Initial Catalog=Jasper;Data Source=.\SQLExpress;Integrated Security=True;';Generate Default EDM=True"

将命名服务对象作为CreateDynamicContext的第二个参数

>>> ctx = DynamicContext.CreateDynamicContext(connStr,nameService)
>>>

Users不存在了,已经被换掉了

>>> u = ctx.Users[0]
Traceback (most recent call last):
File , line 0, in <string>##45
File , line 0, in _stub_##46
AttributeError: couldn't find member Users

变成了Yonghus和Tiezis:

>>> dir(ctx)
['AcceptAllChanges', 'AddObject', 'Attach', 'AttachTo', 'CodeRepresentation', 'Connection', 'ContextSaved', 'ContextSaving', 'CreateDynamicContext', 'CreateKey', 'CreateQuery', 'DefaultContainerName', 'DelAttrMethod', 'DeleteObject', 'Detach', 'Dispose', 'Equals', 'ExecuteDirectQuery', 'ExecuteFunction', 'ExecuteNativeMethod', 'Finalize', 'GetAttribute', 'GetHashCode', 'GetObjectByKey', 'GetQuery', 'GetType', 'Hash', 'MemberwiseClone', 'MetadataWorkspace', 'ObjectStateManager', 'PythonToString', 'QueryTimeout', 'Reduce', 'ReferenceEquals', 'Refresh', 'SaveChanges', 'SetAttrMethod', 'Tiezis', 'ToString', 'TryGetObjectByKey', 'TryGetQuery', 'Yonghus', '__class__', '__delattr__', '__doc__', '__entityHelper', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '_tiezis', '_yonghus', 'add_ContextSaved', 'add_ContextSaving', 'get_Connection', 'get_DefaultContainerName', 'get_MetadataWorkspace', 'get_ObjectStateManager', 'get_QueryTimeout', 'get_Tiezis', 'get_Yonghus', 'remove_ContextSaved', 'remove_ContextSaving', 'set_DefaultContainerName', 'set_QueryTimeout']

UserName也变成了Zhanghao:

>>> u = ctx.Yonghus[0]
>>> dir(u)
['CodeRepresentation', 'DelAttrMethod', 'EmailAddress', 'EntityKey', 'Equals', 'Finalize', 'GetAttribute', 'GetHashCode', 'GetType', 'Hash', 'LastLogon', 'MemberwiseClone', 'Password', 'PythonToString', 'Reduce', 'ReferenceEquals', 'RelationshipManager', 'SetAttrMethod', 'SetChangeTracker', 'Tiezis', 'ToString', 'UserID', 'Zhanghao', '__class__', '__delattr__', '__doc__', '__entityHelper', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '_emailAddress', '_lastLogon', '_password', '_userID', '_zhanghao', 'get_EmailAddress', 'get_EntityKey', 'get_LastLogon', 'get_Password', 'get_RelationshipManager', 'get_Tiezis', 'get_UserID', 'get_Zhanghao', 'set_EmailAddress', 'set_EntityKey', 'set_LastLogon', 'set_Password', 'set_UserID', 'set_Zhanghao']


>>> u.Zhanghao
'abc'

同样的,Post成了Tiezi:

>>> p = ctx.Tiezis[0]
>>> dir(p)
['CodeRepresentation', 'CreatedDate', 'DelAttrMethod', 'EntityKey', 'Equals', 'Finalize', 'GetAttribute', 'GetHashCode', 'GetType', 'Hash', 'MemberwiseClone', 'Message', 'ModifiedDate', 'PostID', 'PythonToString', 'Reduce', 'ReferenceEquals', 'RelationshipManager', 'SetAttrMethod', 'SetChangeTracker', 'Title', 'ToString', 'Yonghu', '__class__', '__delattr__', '__doc__', '__entityHelper', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '_createdDate', '_message', '_modifiedDate', '_postID', '_title', 'get_CreatedDate', 'get_EntityKey', 'get_Message', 'get_ModifiedDate', 'get_PostID', 'get_RelationshipManager', 'get_Title','get_Yonghu', 'set_CreatedDate', 'set_EntityKey', 'set_Message', 'set_ModifiedDate', 'set_PostID', 'set_Title', 'set_Yonghu']


>>> p.Yonghu.Zhanghao
'abc'

3.如果结构不同的话,那么需要使用实体模型的中的CSDL,SSDL,和MSL来做映射,具体参考样例或文档

二。 除了结构性方面的定制,还能定制对象的行为么?

在Jasper的安装里,有一个VB.NET的Customization的例程,其中的App_Code中的BusinessLogic.vb:

Imports Microsoft.VisualBasic

'Project Jasper will create a Product class based on the Northwind schema
'At class creation time, Jasper will find this class and derive from it
'Jasper will find the SetUnitPrice function and call it from inside of
'the setter for the UnitPrice property on the Product class it creates


Public Class Product
 Public Function SetUnitPrice(ByVal value As Decimal) As Decimal
    If value < 0 Then
            Throw New Exception("Can't set UnitPrice to a negative value")
    Else
            Return value
    End If
 End Function
End Class

其中的注释说,

Project会根据Northwind数据库的数据定义创建一个Product类

在创建类时,Jasper会发现这个类(指上面BusinessLogic.vb里定义的这个Product类),然后从这个类继承

Jasper会发现SetUnitPrice函数,然后在它创建的Product类的UnitPrice属性的setter里调用这个函数

如果你用Reflector看一下,你会发现DynamicContext.SaveChanges()->DynamicContext.SetupEntitiesForChanges()时看实体对象是否拥有OnPersist()方法,如果有的话,就会调用这个方法

让我们来在IronPython里试验一下

>>> import clr
>>> import System
>>> from System import *

创建一个类,继承自System.Object,内含2个方法HelloWorld和SetCreatedDate:

>>> class Post(System.Object):
...           def HelloWorld(self):
...              return 'hello world'
...           def SetCreatedDate(self,dt):
...              if (dt < DateTime.Now):
...                   raise Exception("CreatedDate must be in the future")
...

导入所需类

>>> clr.AddReference("Microsoft.Jasper.CTP")
>>> from Microsoft.Jasper import *

设置连接字符串

>>> connStr = "Provider='System.Data.SqlClient';Provider Connection String='Initial Catalog=Jasper;Data Source=.\SQLExpress;Integrated Security=True;';Generate Default EDM=True"

创建动态上下文,生成实体类

>>> ctx = DynamicContext.CreateDynamicContext(connStr)

取出昨天生成的贴子的一个对象

>>> p = ctx.Posts[0]

看一下其中的方法

>>> for m in p.GetType().GetMethods(): print m.Name
...
set_PostID
set_Title
set_Message
set_CreatedDate
set_ModifiedDate
SetChangeTracker
get_EntityKey
set_EntityKey
get_RelationshipManager
get_PostID
get_Title
get_Message
get_CreatedDate
get_ModifiedDate
get_User
set_User
GetType
ToString
Equals
GetHashCode

好像没有HelloWorld和SetCreatedDate啊,看一下类型

>>> p.GetType().FullName
'dboModel.Post'

其基类

>>> p.GetType().BaseType.FullName
'System.Object'
>>>

没有继承啊,生成一个Post对象,看一下其类型

>>> p2 = Post()
>>> p2.GetType().FullName
'IronPython.NewTypes.System.Object_1'
>>>

类名居然不是Post,而是IronPython.NewTypes.System.Object_1! 看来Python里的类跟.NET里的类还是有区别的啊!

那就用C#写个类吧, dboModel.cs:

using System;
using System.Reflection;

namespace DomainModel
{
public class Post
{

//因为是静态的语言,无法获取还不存在的数据,在这里加一个成员变量保存数据为OnPersist()所用
DateTime _createdDate;

public DateTime SetCreatedDate(DateTime dt)
{
   Console.WriteLine("in memory:{0}, passed in:{1}", _createdDate, dt);

//这里有关校验,传入的时间必须是现在或将来,否则出错
   if (dt < DateTime.Now)
            throw new Exception("CreatedDate must be in the future");

   _createdDate = dt;

   return dt;
}

public void Test()
{
   Console.WriteLine("Test");
}

public void OnPersist()
{

//这是另一个校验,_createdDate不能是明天以后,应该在SetCreatedDate里做的,但。。。。
     if (_createdDate >= DateTime.Now.AddDays(1))
            throw new Exception("CreatedDate cannot go beyond tomorrow");
 }
}
}

编译成dboModel.dll

csc /t:library dboModel.cs

>>> import clr
>>> import System
>>> from System import *
>>>
>>> clr.AddReference("Microsoft.Jasper.CTP")
>>> from Microsoft.Jasper import *
>>>

导入dboModel.dll里的类

>>> clr.AddReference("dboModel.dll")
>>> import DomainModel.Post
>>>
>>> connStr = "Provider='System.Data.SqlClient';Provider Connection String='Initial Catalog=Jasper;Data Source=.\SQLExpress;Integrated Security=True;';Generate Default EDM=True"

>>> ctx = DynamicContext.CreateDynamicContext(connStr)

取出昨天生成的贴子的一个对象

>>> p = ctx.Posts[0]
>>> p.GetType().FullName
'dboModel.Post'

基类

>>> p.GetType().BaseType.FullName
'DomainModel.Post'

这回对了

>>> for m in p.GetType().GetMethods() : print m.Name
...
set_PostID
set_Title
set_Message
set_CreatedDate
SetCreatedDate
set_ModifiedDate
SetChangeTracker
get_EntityKey
set_EntityKey
get_RelationshipManager
get_PostID
get_Title
get_Message
get_CreatedDate
get_ModifiedDate
get_User
set_User
Test
OnPersist
GetType
ToString
Equals
GetHashCode

>>> p = ctx.Posts[0]
>>> p.CreatedDate = DateTime.Now.AddDays(-1)
in memory:1/1/0001 12:00:00 AM, passed in:5/1/2007 4:29:28 PM
Traceback (most recent call last):
File , line 0, in <stdin>##27
File , line 0, in set_CreatedDate##31
File dynamicAssembly1, line unknown, in set_CreatedDate
File Microsoft.Jasper.CTP, line unknown, in CallMethodIfExists
Exception: CreatedDate must be in the future
>>>

看来SetCreatedDate真被调用了

>>> p.CreatedDate = DateTime.Now.AddDays(2)
in memory:1/1/0001 12:00:00 AM, passed in:5/4/2007 4:30:20 PM

试着保存

>>> ctx.SaveChanges()
Traceback (most recent call last):
File dboModel, line unknown, in OnPersist
File , line 0, in <stdin>##33
File , line 0, in SaveChanges##34
File Microsoft.Jasper.CTP, line unknown, in SaveChanges
File Microsoft.Jasper.CTP, line unknown, in SetupEntitiesForChanges
StandardError: Exception has been thrown by the target of an invocation.

出错了,没显示具体错误信息,奇怪

继承法大致如此,虽然还有些细节不是很对,但就到此为止吧

三。但,IronPython是门动态语言,我一定要用继承才行么?我不能动态添加方法么?

譬如在Python里,你可以这么做

>>> class A:
...          def HelloWorld(self):
...                  self.af = "hello"
...          def Print(self):
...                  print self.af
...
>>> A
<class __main__.A at 0x000000000000002C>

>>> a = A()
>>> a.HelloWorld()
>>> a.Print()
hello

定义一个新方法,

>>> def HelloWorld2(self):
...             self.af = "hello 2"
...

使用setattr:

>>> setattr(A, HelloWorld2.__name__, HelloWorld2)

调用新的方法:

>>> a.HelloWorld2()
>>> a.Print()
hello 2

可以给.NET 类动态添加方法么?用上面那个C#写的Post类作为例子:

>>> from DomainModel import *
>>> def HelloWorld2(self):
...             self.af = "hello 2"
...
>>> Post
<type 'Post'>
>>>
>>> setattr(Post,HelloWorld2.__name__,HelloWorld2)
Traceback (most recent call last):
File , line 0, in <stdin>##23
File , line 0, in SetAttr##24
AttributeError: 'Post' object has no attribute 'HelloWorld2'

好像不行!

看来我的IronPython的道行还比较浅,请哪位对IronPython有研究的指点一下,谢谢!

posted on 2007-05-08 12:40:00 by saucer  评论(11) 阅读(6455)

Visual Basic到底有多少个版本

如果你仔细看一下开心贴出的Silverlight 1.1的海报,在框架语言一栏,你会看到 VBx 这个语言,

这个跟VBX(VB早年的组件通称)没什么关系,而是指VB 10.0 (Orcas中的VB版本是9.0)。 微软Visual Basic .NET开发团队的 Paul Vick 对此做了介绍。VBx将是一门基于动态语言运行时(DLR)的动态语言,VBx程序不用预先编译成DLL,动态语言运行时可以在运行时动态将其编译,然后运行。详情参阅Paul Vick的2个贴子:

What the heck is "VBx"?
http://www.panopticoncentral.net/archive/2007/05/01/20383.aspx

After MIX, how many Visual Basic languages are there?
http://www.panopticoncentral.net/archive/2007/05/02/20395.aspx

posted on 2007-05-08 04:28:00 by saucer  评论(6) 阅读(7870)

SharePoint – Silverlight 集成竞赛

微软的Michael Gannotti发起了一个SharePoint – Silverlight集成竞赛。

竞赛详细情况在他的博客上:

Announcing the SharePoint – Silverlight Integration Contest
http://sharepoint.microsoft.com/blogs/mikeg/Lists/Posts/Post.aspx?ID=220

奖品列表在:

The SharePoint – Silverlight Integration Contest Gets Kicked Up a Notch: Way Cooler Prizes
http://sharepoint.microsoft.com/blogs/mikeg/Lists/Posts/Post.aspx?ID=222

推荐使用的工具,资源和样例:
Tools, Resources, and Samples To Help You Create Your Silverlight Content for the SharePoint – Silverlight Integration Contest
http://sharepoint.microsoft.com/blogs/mikeg/Lists/Posts/Post.aspx?ID=223

 

比赛很简单。创造一些Silverlight内容,越酷,越引人入胜,越有创意,就越好。把你的内容直接嵌在SharePoint网页里或如果你真想要挑战极限的话,可以将其嵌于一个可重用的webpart中,当然这样从裁判处得分就越多。想提交你的参与作品的话,你需要:

  • 写一个WORD文档或PowerPoint,对你作品做个全面的介绍,内容是什么,制作和发布过程中都做了些什么,所用的工具,采取的步骤等
  • 提交你的作品。你可以在一个外部的网站上发布,或者如果网站是内部的,就制作一个演示录像 (你可以使用Windows Media Encoder来捕捉演示的录像)

然后将你的参赛作品贴在Michael Gannotti的博客上,竞赛截止期是6月15日,获奖者将在一个星期内公布。微软雇员不能参与这个竞赛。奖品:

一等奖:

  • 1个 白Zune
  • 1年的 Xbox Live Service
  • 1份 Gears of War
  • 1份 Office SharePoint Server 2007 Administrators Companion
  • 1份 Groove 2007
  • 1份 Office Professional 2007

二等奖:

  • 1份 Windows Media Resource kit
  • 1份 2007 Microsoft Office System Inside Out
  • 1份 Office SharePoint Server 2007 Administrations Companion
  • 1份 Groove 2007
  • 1份 Office Professional 2007

posted on 2007-05-08 03:23:00 by saucer  评论(5) 阅读(6397)

使用Visual Studio 2005开发Silverlight 1.1应用

如果你想尝试开发 Silverlight 1.1 应用,又对下载/安装推荐的Visual Studio Orcas Beta 1有点怕怕的话,你可以使用Visual Studio 2005和Expression Blend 2 五月份的预览版 (25.5M)来开发。

根据Bryant Likes的博客,在安装Silverlight 1.1 alpha运行时后,你可以在Visual Studio 2005里,

1. 创建一个类库
2. 删除该项目所有的引用
3. 右击项目,选择属性
4. 在项目属性页的Build页上,点击“高级”按钮,选择“别引用mscorlib.dll”复选框
5. 手工添加对 Silverlight 1.1 alpha 运行时的安装文件夹 (\Program Files\Microsoft Silverlight\ ) 里的 mscorlib, agclr, System, System.Core, System.Silverlight, 和 System.Xml.Core程序集的引用

有一个例程你可以试一下。

posted on 2007-05-06 13:21:00 by saucer  评论(11) 阅读(14433)

Silverlight 1.1 特性之现在和将来

Jamie Cool和Nick Kramer在MIX07上做的《DEV22 - Building Silverlight Applications Using .NET (Part 1 of 2) 》讲座
http://sessions.visitmix.com/default.asp?event=1011&session=2012&pid=DEV22&disc=&id=1531&year=2007&search=DEV22

里,有几页涉及Silverligh1.1 在图像/界面/XAML方面的特性比较,值得拿来看一下。

总的来说,

V1.1=

  • V1.0
  • +托管代码(CLR)
  • +XAML扩展性
  • +Control类(用户控件)
  • +控件样例
    1.1 alpha 1.1 计划 WPF
控件类 Button 有样例
TextBox  没有
Scrollbar 有样例
Slider  有样例
ListBox  有样例
CheckBox 没有
RadioButton 没有
ComboBox 没有
TreeView 没有 没有
Accordion 没有 没有 第三方提供
DataGrid 没有 没有 第三方提供
UserControl
布局类 Canvas
Grid 没有
StackPanel 没有
ViewBox 没有
其它 鼠标事件 部分
键盘事件 部分
<.Resources> 部分
数据绑定 没有
styling(样式化) 没有
3D 没有 没有
硬件加速 没有 没有
浏览器之外 没有 没有
离线 没有 没有
跨平台

 

这个讲座非常值得一看,下半部分讲座的连接在
Building Silverlight Applications Using .NET (Part 2 of 2)
http://sessions.visitmix.com/default.asp?event=1011&session=2012&pid=DEV07&disc=&id=1516&year=2007&search=DEV07

posted on 2007-05-04 07:08:00 by saucer  评论(7) 阅读(7481)

MIX07讲座的录像上线了

【来源:Sam Gentile

http://sessions.visitmix.com/

其中一些录像的链接:
1。 Ray Ozzie和Scott Guthrie的主题演讲
http://sessions.visitmix.com/upperlayer.asp?event=1010&session=2016&id=1532&year=&sortChoice=&stype=

2。 Jim Hugunin和John Lam的《Just Glue It! Ruby and the DLR in Silverlight》
http://sessions.visitmix.com/upperlayer.asp?event=1011&session=2012&id=1511&year=&sortChoice=&stype=

好玩的事是,他们的演示是在MAC上做的! 演示的代码可以在这里下载:
http://www.codeplex.com/dynamicsilverlight/Release/ProjectReleases.aspx?ReleaseId=3809

3。 Scott Guthrie的《What's New for Web Developers in the ASP.NET and Visual Studio Codename "Orcas" Release》
http://sessions.visitmix.com/upperlayer.asp?event=1011&session=2012&id=1560&year=&sortChoice=&stype=

4。 Building Rich, Interactive E-commerce Applications Using ASP.NET and Silverlight
http://sessions.visitmix.com/upperlayer.asp?event=1011&session=2012&id=1567&year=&sortChoice=&stype=

5。 Mike Harsh的《Deep Dive on Silverlight Media Integration》
http://sessions.visitmix.com/upperlayer.asp?event=1011&session=2012&id=1568&year=&sortChoice=&stype=

6。 Anders Hejlsberg 的《Using LINQ to Dramatically Improve Data Driven Development in Web Applications》
http://sessions.visitmix.com/upperlayer.asp?event=1011&session=2012&id=1513&year=&sortChoice=&stype=

7。 High-Speed Development with the AJAX Control Toolkit
http://sessions.visitmix.com/upperlayer.asp?event=1011&session=2012&id=1528&year=&sortChoice=&stype=

8。 Developing Data Driven Applications Using the New Dynamic Data Controls in ASP.NET
http://sessions.visitmix.com/upperlayer.asp?event=1011&session=2012&id=1529&year=&sortChoice=&stype=

posted on 2007-05-02 23:07:00 by saucer  评论(2) 阅读(6375)

使用Jasper和IronPython操作数据 - 补充说明

1.数据模型的Visio是这样的

2.至于实体模型的定义,可以在动态的上下文对象生成后,用反射来看一下

>>> ctx = DynamicContext.CreateDynamicContext(connStr)
>>> from System import *

>>> ut = Type.GetType("dboModel.User")

>>> for p in ut.GetProperties() : print "%s - %s" % (p.Name,p.PropertyType.FullName)
...
EntityKey - System.Data.EntityKey
RelationshipManager - System.Data.Objects.DataClasses.RelationshipManager
UserID - System.Int32
UserName - System.String
Password - System.String
EmailAddress - System.String
LastLogon - System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
Posts - Microsoft.Jasper.Query

>>> pt = Type.GetType("dboModel.Post")

>>> for p in pt.GetProperties() : print "%s - %s" % (p.Name,p.PropertyType.FullName)
...
EntityKey - System.Data.EntityKey
RelationshipManager - System.Data.Objects.DataClasses.RelationshipManager
PostID - System.Int32
Title - System.String
Message - System.String
CreatedDate - System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
ModifiedDate - System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
User - dboModel.User

3. 对数据集合的操作

>>> for ps in ctx.Posts : print "%s - %s" % (ps.Title, ps.CreatedDate)
...
abc - 5/2/2007 9:46:29 AM
def - 5/2/2007 9:46:29 AM
>>> for ps in u.Posts : print "%s - %s" % (ps.Title, ps.CreatedDate)
...
abc - 5/2/2007 9:46:29 AM
def - 5/2/2007 9:46:29 AM
>>>

也可以这么做查询

>>> for ps in ctx.Posts.Select("it.Title,it.User.UserName"): print "%s - %s" % (ps.Title, ps.UserName)
...
abc - joel_cool
def - joel_cool

4. 要删除集合中的对象,应该在集合所在类的实例那里做

>>> u = ctx.Users.First()
>>> u.Posts.Count()
2
>>> p = u.Posts[0]
>>> u.Posts.Delete(p)
True
>>> ctx.Posts.Count()
1
>>> u.Posts.Count()
1
>>> ctx.SaveChanges()
2
>>> u.Posts.Count()
1
>>> ctx.Posts.Count()
1

posted on 2007-05-02 22:03:00 by saucer  评论(2) 阅读(5818)

使用Jasper和IronPython操作数据

1.建立数据库

use master
go

create database Jasper
go

use Jasper
go

CREATE TABLE Users (
UserID int identity NOT NULL,
UserName nvarchar(40) NOT NULL,
Password nvarchar(20) NOT NULL,
EmailAddress nvarchar(40) NOT NULL,
LastLogon datetime,
PRIMARY KEY (UserID)
)
go

CREATE TABLE Posts (
PostID int identity NOT NULL,
Title nvarchar(100) NOT NULL,
Message ntext,
CreatedDate datetime,
ModifiedDate datetime,
UserID int NOT NULL,
PRIMARY KEY (PostID),
FOREIGN KEY (UserID) References Users(UserID)
)
go

2. 运行ipy命令行工具

C:\>ipy
IronPython 1.1 (1.1) on .NET 2.0.50727.1318
Copyright (c) Microsoft Corporation. All rights reserved.

3. 装载所需库

>>> import clr
>>> clr.AddReference("Microsoft.Jasper.CTP")
>>> from Microsoft.Jasper import *

4. 设置连接字符串,注意我们使用了默认的机制来通过实体框架动态生成对象

>>> connStr = "Provider='System.Data.SqlClient';Provider Connection String='Initial Catalog=Jasper;Data Source=.\SQLExpress;Integrated Security=True;';Generate Default EDM=True"

5. 生成动态上下文对象

>>> ctx = DynamicContext.CreateDynamicContext(connStr)

6. 看一下ctx对象的成员

>>> dir(ctx)

['AcceptAllChanges', 'AddObject', 'Attach', 'AttachTo', 'Connection', 'ContextSaved', 'ContextSaving', 'CreateDynamicContext', 'CreateKey', 'CreateQuery', 'DefaultContainerName', 'DeleteObject', 'Detach', 'Dispose', 'Equals', 'ExecuteDirectQuery', 'ExecuteFunction', 'ExecuteNativeMethod', 'Finalize', 'GetHashCode', 'GetObjectByKey', 'GetQuery', 'GetType', 'MakeDynamicType', 'MemberwiseClone', 'MetadataWorkspace', 'ObjectStateManager', 'Posts', 'QueryTimeout', 'Reduce', 'ReferenceEquals', 'Refresh', 'SaveChanges', 'ToString', 'TryGetObjectByKey', 'TryGetQuery', 'Users', '__class__', '__doc__', '__entityHelper', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '_posts', '_users', 'add_ContextSaved', 'add_ContextSaving', 'remove_ContextSaved', 'remove_ContextSaving']

里面有Users和Posts

7. 目前数据库还没有任何数据

>>> ctx.Users.Count()
0
>>> ctx.Posts.Count()
0

8. 让我们来生成一个User对象

>>> u = ctx.Users.Create()
>>> u.UserName = "joel_cool"
>>> u.Password = "abc123"
>>> u.EmailAddress = "joe@cool.com"
>>> u.LastLogon = DateTime.Now
Traceback (most recent call last):
File , line 0, in <stdin>##42
NameError: name 'DateTime' not defined
>>> u.LastLogon = System.DateTime.Now
Traceback (most recent call last):
File , line 0, in <stdin>##43
NameError: name 'System' not defined
>>> from System import *
>>> u.LastLogon = DateTime.Now
>>> ctx.SaveChanges()
1
>>> ctx.Users.Count()
1
>>> u.UserID
1

忘了引进System命名空间

9. 生成几个贴子对象

>>> p = ctx.Posts.Create()
>>> p.User = u
>>> p.Title = "abc"
>>> p.Message = "Hello world"
>>> p.CreatedDate = p.ModifiedDate = DateTime.Now
>>>

>>> p2 = ctx.Posts.Create()
>>> p2.User = u
>>> p2.Title = "def"
>>> p2.Message = "Jasper is fun"
>>> p2.CreatedDate = p2.ModifiedDate = DateTime.Now
>>> ctx.SaveChanges()
4
>>> ctx.Posts.Count()
2
>>> p.PostID
1
>>> p2.PostID
2
>>> u.Posts.Count()
2

10. 查询一个贴子,然后做修改

>>> p3 = ctx.Posts.FindByKey(2)
>>> p3
<Post object at 0x000000000000002B>
>>> p2
<Post object at 0x000000000000002B>
>>>注意p2和p3指向同一个对象ID
>>> p3.Message += ", yes, really fun"
>>> p3.ModifiedDate = DateTime.Now
>>> ctx.SaveChanges()
1
>>> p2.Message
'Jasper is fun, yes, really fun'
>>> p2.CreatedDate
<System.DateTime object at 0x000000000000002C [5/1/2007 8:15:16 PM]>
>>> p2.ModifiedDate
<System.DateTime object at 0x000000000000002D [5/1/2007 8:17:18 PM]>

11. 删除其中一个贴子

>>> p4 = u.Posts.FindByKey(1)
>>> ctx.Posts.Delete(p4)
True
>>> ctx.SaveChanges()
2
>>> ctx.Posts.Count()
1
>>> u.Posts.Count()
2

#!!!好像有问题,用户对象还需要从自己的贴子集合里删除贴子,是特性还是缺陷? 看样子这里需要一个用法模式

>>> p4.User
Traceback (most recent call last):
File , line 0, in <stdin>##106
File , line 0, in get_User##107
File dynamicAssembly1, line unknown, in get_User
File Microsoft.Jasper.CTP, line unknown, in GetRelatedReferenceValue
File System.Data.Entity.CTP, line unknown, in Load
SystemError: Unable to load the EntityReference because it is not attached to a
context.

#但这里p4指向的User已经出问题了,p3呢?

>>> p3.User
<User object at 0x000000000000002E>
>>> p3.User.UserName
'joel_cool'

12.把用户也删除吧

>>> ctx.Users.Delete(u)
True
>>> ctx.SaveChanges()
Traceback (most recent call last):
File , line 0, in <stdin>##116
File , line 0, in SaveChanges##49
File Microsoft.Jasper.CTP, line unknown, in SaveChanges
File System.Data.Entity.CTP, line unknown, in SaveChanges
File System.Data.Entity.CTP, line unknown, in SaveChanges
File System.Data.Entity.CTP, line unknown, in Update
File System.Data.Entity.CTP, line unknown, in Update
File System.Data.Entity.CTP, line unknown, in ValidateConstraints
SystemError: A relationship is being added or deleted from relationship set 'FK__Posts__UserID__7F60ED59'. Given cardinality constraints, a corresponding 'Posts' must also be added or deleted.
>>>

外键约束的关系,无法删除用户,把贴子也全删了!

>>> ctx.Posts.DeleteAll()
>>> ctx.SaveChanges()
3
>>> ctx.Users.Count()
0
>>> ctx.Posts.Count()
0
>>> u.Posts.Count()
2

posted on 2007-05-02 08:38:00 by saucer  评论(15) 阅读(6516)

【第1页/共2页,19条】
首页
前页
1

Powered by: Joycode.MVC引擎 0.5.2.0