|
|
一如既往的好看。 为了Initialize Lazy-Load Proxy,先要Lock一下。但Lock了以后,再Update,就不提交到数据库去了。(为了不新建连接,Initialize和Update用的同一个Session)。 只能Lock了以后再Evict。 搞不懂这么设计为了什么,还是bug。暂且这样。 8月13日 笑死我了,口味很重。  8月4日 还是MSDN最权威,见http://msdn.microsoft.com/zh-cn/library/37899azc%28VS.80%29.aspx。其他都是谣言。 没工夫慢慢看,自己够用了就行。用中出现了一些小问题。 - 设计时的程序目录是IDE目录("…\Common 7\IDE\”),所以配置文件,私有程序集可能会出现找不到的情况。没找到很好的办法,配置文件就拷过去,程序集用AppDomain..AssemblyResolve 事件在程序中载入。
- 如果需要添加控件,不能用反射来直接创建控件(不会保存到*.Designer.cs里),而应该用
IDesignerHost h = (IDesignerHost)GetService(typeof(IDesignerHost)); Label label = (Label)h.CreateComponent(typeof(Label)); 来创建。删除时同样用 h.DestroyComponent(label); - 如何从Component得到主窗体:(component.Site.GetService(typeof(IDesignerHost)) as IDesignerHost).RootComponent as Form
3月12日 You can extend the standard set of ASP.NET configuration settings with XML configuration elements of your own. To do this, you must create your own configuration section handler. The handler must be a .NET Framework class that implements the System.Configuration..::.ConfigurationSection class. Note: In the .NET Framework versions 1.0 and 1.1, a configuration section handler had to implement the System.Configuration..::.IConfigurationSectionHandler interface, which is now deprecated. However, a code example exists in How to: Create Custom Configuration Sections Using IConfigurationSectionHandler. The section handler interprets and processes the settings defined in XML configuration elements within a specific portion of a Web.config file and returns an appropriate configuration object based on the configuration settings. The configuration object that the handler class returns can be any data structure; it is not limited to any base configuration class or configuration format. ASP.NET uses the configuration object to read and write to your custom configuration element. To create a custom configuration section handler -
Create a public class that inherits the System.Configuration..::.ConfigurationSection class, as illustrated in the following code example. Visual Basic Copy Code
Imports System
Imports System.Collections
Imports System.Text
Imports System.Configuration
Imports System.Xml
Namespace MyConfigSectionHandler
Public Class MyHandler
Inherits ConfigurationSection
Public Sub New()
End Sub
' Add declarations for child elements and attributes like this:
'<ConfigurationProperty("<propertyName>", <named parameters>)> _
'Public Property MyAttrib1() As <type>
' Get
' Return CStr(Me("<propertyName>"))
' End Get
' Set(ByVal value As <type>)
' Me("<propertyName>") = value
' End Set
'End Property
End Class
End Namespace
C#
Copy Code
using System;
using System.Collections;
using System.Text;
using System.Configuration;
using System.Xml;
namespace MyConfigSectionHandler
{
public class MyHandler : ConfigurationSection
{
public MyHandler()
{
}
// Add declarations for child elements and attributes like this:
// [ConfigurationProperty("<propertyName>", <named parameters>)]
// public <type> <PropertyName>
// {
// get { return (<type>)this["<propertyName>"]; }
// set { this["<propertyName>"] = value; }
// }
}
}
-
Add your own code to perform the configuration work that you desire.
For example, you can replace the commented code with the following code that obtains the values from your custom section.
Visual Basic
Copy Code
Imports System
Imports System.Collections
Imports System.Text
Imports System.Configuration
Imports System.Xml
Namespace MyConfigSectionHandler
Public Class MyHandler
Inherits ConfigurationSection
Public Sub New()
End Sub
Public Sub New(ByVal attribVal As String)
MyAttrib1 = attribVal
End Sub
<ConfigurationProperty("myAttrib1", DefaultValue:="Clowns", IsRequired:=True)> _
<StringValidator(InvalidCharacters:="~!@#$%^&*()[]{}/;'\|\\", MinLength:=1, MaxLength:=60)> _
Public Property MyAttrib1() As String
Get
Return CStr(Me("myAttrib1"))
End Get
Set(ByVal value As String)
Me("myAttrib1") = value
End Set
End Property
<ConfigurationProperty("myChildSection")> _
Public Property MyChildSection() As MyChildConfigElement
Get
Return CType(Me("myChildSection"), MyChildConfigElement)
End Get
Set(ByVal value As MyChildConfigElement)
Me("myChildSection") = CType(value, MyChildConfigElement)
End Set
End Property
End Class
Public Class MyChildConfigElement
Inherits ConfigurationElement
Public Sub New()
End Sub
Public Sub New( _
ByVal a1 As String, ByVal a2 As String)
MyChildAttribute1 = a1
MyChildAttribute2 = a2
End Sub
<ConfigurationProperty("myChildAttrib1", DefaultValue:="Zippy", IsRequired:=True)> _
<StringValidator(InvalidCharacters:="~!@#$%^&*()[]{}/;'\|\\", MinLength:=1, MaxLength:=60)> _
Public Property MyChildAttribute1() As String
Get
Return CStr(Me("myChildAttrib1"))
End Get
Set(ByVal value As String)
Me("myChildAttrib1") = value
End Set
End Property
<ConfigurationProperty("myChildAttrib2", DefaultValue:="Michael Zawondy", IsRequired:=True)> _
<StringValidator(InvalidCharacters:="~!@#$%^&*()[]{}/;'\|\\", MinLength:=1, MaxLength:=60)> _
Public Property MyChildAttribute2() As String
Get
Return CStr(Me("myChildAttrib2"))
End Get
Set(ByVal value As String)
Me("myChildAttrib2") = value
End Set
End Property
End Class
End Namespace
C#
Copy Code
using System;
using System.Collections;
using System.Text;
using System.Configuration;
using System.Xml;
namespace MyConfigSectionHandler
{
public class MyHandler : ConfigurationSection
{
public MyHandler()
{
}
public MyHandler(String attribVal)
{
MyAttrib1 = attribVal;
}
[ConfigurationProperty("myAttrib1", DefaultValue = "Clowns", IsRequired = true)]
[StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
public String MyAttrib1
{
get
{ return (String)this["myAttrib1"]; }
set
{ this["myAttrib1"] = value; }
}
[ConfigurationProperty("myChildSection")]
public MyChildConfigElement MyChildSection
{
get
{ return (MyChildConfigElement)this["myChildSection"]; }
set
{ this["myChildSection"] = value; }
}
}
public class MyChildConfigElement : ConfigurationElement
{
public MyChildConfigElement()
{
}
public MyChildConfigElement(String a1, String a2)
{
MyChildAttribute1 = a1;
MyChildAttribute2 = a2;
}
[ConfigurationProperty("myChildAttrib1", DefaultValue = "Zippy", IsRequired = true)]
[StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
public String MyChildAttribute1
{
get
{ return (String)this["myChildAttrib1"]; }
set
{ this["myChildAttrib1"] = value; }
}
[ConfigurationProperty("myChildAttrib2", DefaultValue = "Michael Zawondy", IsRequired = true)]
[StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
public String MyChildAttribute2
{
get
{ return (String)this["myChildAttrib2"]; }
set
{ this["myChildAttrib2"] = value; }
}
}
}
This example uses the declarative model. The System.Configuration..::.ConfigurationSection class can also be implemented using the programmatic model. For an example, see the System.Configuration..::.ConfigurationSection class overview topic, and Classes Used to Create Custom Section Handlers.
For the purposes of comparison, this example is similar to the code in How to: Create Custom Configuration Sections Using IConfigurationSectionHandler. However, inheriting from the System.Configuration..::.ConfigurationSection class allows for finer control of your section handler. For example, the configuration file in the next procedure allows for a child element called myChildSection for which the preceding code declares a ConfigurationProperty and defines as a class derived from ConfigurationElement. Additionally, the encapsulation of collection functionality in the ConfigurationElementCollection class allows you to easily create collection elements that can employ add, remove, and clear elements in a configuration file. For more information and examples, see ConfigurationElementCollection.
To add a custom section handler to an ASP.NET configuration file
-
Add a sectionGroup element and a section element to your Web.config file inside the configSections element, as illustrated in the following code example. It is this declaration that associates the custom section handler with the section name.
Note:
Nesting a section element in a sectionGroup is optional, but it is recommended to help better organize configuration data.
You can add the section-handler declaration in a different configuration file than the one where you add your custom configuration elements, providing that the configuration file where the section handler is declared is higher in the configuration file hierarchy. For more information, see ASP.NET Configuration File Hierarchy and Inheritance.
The type attribute of the section element must match the manifest of the assembly or there will be a configuration error. The assembly file itself must be in the same ASP.NET application directory as the Web.config file that defines it.
Copy Code
<configuration>
<!-- Configuration section-handler declaration area. -->
<configSections>
<sectionGroup name="myCustomGroup">
<section
name="myCustomSection"
type="MyConfigSectionHandler.MyHandler, MyCustomConfigurationHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
allowLocation="true"
allowDefinition="Everywhere"
/>
</sectionGroup>
<!-- Other <section> and <sectionGroup> elements. -->
</configSections>
<!-- Configuration section settings area. -->
</configuration>
-
Add your custom configuration elements in the configuration section settings area of your Web.config file.
Copy Code
<configuration>
<!-- Configuration section-handler declaration area. -->
<!-- Configuration section settings area. -->
<myCustomGroup>
<myCustomSection myAttrib1="Clowns">
<myChildSection
myChildAttrib1="Zippy"
myChildAttrib2="Michael Zawondy "/>
</myCustomSection>
</myCustomGroup>
<!-- Other configuration settings, like <system.web> -->
</configuration>
To programmatically access your custom configuration data
-
Obtain an instance of your custom configuration object and use the GetSection method or the GetSection method to populate it.
The following example of an ASPX page works with the previous examples to enumerate the attributes and child elements of the custom configuration section.
C#
Copy Code
<%@ Page Language="C#" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
MyConfigSectionHandler.MyHandler config =
(MyConfigSectionHandler.MyHandler)System.Configuration.ConfigurationManager.GetSection(
"myCustomGroup/myCustomSection");
StringBuilder sb = new StringBuilder();
sb.Append("<h2>Attributes in the myCustomSection Element:</h2>");
sb.AppendFormat("myAttrib1 = {0}<br/>", config.MyAttrib1.ToString());
sb.Append("<h2>Attributes in the myChildSection Element:</h2>");
sb.AppendFormat("myChildAttrib1 = {0}<br/>", config.MyChildSection.MyChildAttribute1.ToString());
sb.AppendFormat("myChildAttrib2 = {0}<br/>", config.MyChildSection.MyChildAttribute2.ToString());
Label1.Text = sb.ToString();
Label1.Visible = true;
}
</script>
<html >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Enumerate MyCustomSection</h1>
<asp:Label ID="Label1" runat="server"
Text="" />
<br />
<asp:Button ID="Button1" runat="server"
Text="Get Custom Config Info"
OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
- Introduction: http://msdn2.microsoft.com/en-us/library/aa480453.aspx
- Homepage: http://msdn2.microsoft.com/zh-cn/practices/default.aspx
- Community: http://www.codeplex.com/entlib
Data Access Application Block Sample 1 - Database db = DatabaseFactory.CreateDatabase();
- DbCommand dbCommand = db.GetStoredProcCommand("GetProductsByCategory");
- db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, 7);
- DataSet productDataSet = db.ExecuteDataSet(dbCommand);
Should know - Dabasebase
- DatabaseFactory
- DbComand
Sample 2 - Database.ExecuteReader,Database.ExecuteDataSet,Databse.ExecuteScalar,Database.ExecuteNonQuery
- Databse.GetStoredProcCommand, Database.GetSqlStringCommand
- DbCommad.AddInParameter, DbCommand.AddOutParameter, AddOutParameter.GetParameterValue
Transaction - using (DbConnection connection = db.CreateConnection())
- {
- connection.Open();
- DbTransaction transaction = connection.BeginTransaction();
- transaction.Commit(); (transaction.Rollback();)
- }
Security Application Block authenticate: use MembershipProvider which is integrated in .Net - bool authenticated = Membership.ValidateUser(username, password);
- IIdentity identity = new GenericIdentity(username, Membership.Provider.Name);
Token: - IToken token = ISecurityCacheProvider.SaveIdentity(this.identity);
- IIdentity savedIdentity = ISecurityCacheProvider.GetIdentity(this.token);
- ISecurityCacheProvider.ExpireIdentity(this.token);
Priciple and authorize: (Roles is integrated in .Net) - string[] roles = Roles.GetRolesForUser(identity);
- IPrincipal principal = new GenericPrincipal(new GenericIdentity(identity), roles);
- bool authorized = this.ruleProvider.Authorize(principal, rule);
- principal.IsInRole(role1);
Profile: (also in integrated in .Net) - ProfileBase userProfile = ProfileBase.Create(this.identity.Name);
- userProfile["FirstName"] = this.profile.FirstName;
- userProfile.Save();
Caching Application Block CacheManager productsCache = CacheFactory.GetCacheManager(); Product product = new Product(id, name, price); productsCache.Add(product.ProductID, product, CacheItemPriority.Normal, null, new SlidingTime(TimeSpan.FromMinutes(5))); product = (Product) productsCache.GetData(id); productsCache.Flush(); productsCache.Remove(id); Expiration: Absolute, Sliding, Extended format, File dependency Scavenging: Low, Normal, High, or Not Removable Cryptography Application Block // String encrypt and decrypt string encryptedContentsBase64 = Cryptographer.EncryptSymmetric("symmProvider", "SensitiveData"); readableString = Cryptographer.DecryptSymmetric("symmProvider", encryptedContentsBase64); // byte encrypt and decrypt byte[] valueToEncrypt = Encoding.Unicode.GetBytes("password"); byte[] encryptedContents = Cryptographer.EncryptSymmetric("symmProvider", valueToEncrypt); // Clear the byte array memory that holds the password. Array.Clear(valueToEncrypt, 0, valueToEncrypt.Length); byte[] decryptedContents = Cryptographer.DecryptSymmetric("symmProvider", encryptedContents); string plainText = (new UnicodeEncoding()).GetString(decryptedContents); // Obtaining a Hash Value byte[] valueToHash = (new UnicodeEncoding()).GetBytes("password"); byte[] generatedHash = Cryptographer.CreateHash("hashProvider", valueToHash); // Clear the byte array memory. Array.Clear(valueToHash, 0, valueToHash.Length); // CompareHash // generatedHash contains a hash value for a previously hashed string. byte[] stringToCompare = (new UnicodeEncoding()).GetBytes("TestValue"); bool comparisonSucceeded = Cryptographer.CompareHash("hashProvider", stringToCompare, generatedHash); Exception Handling Application Block Exception Handlers - Wrap handler. This exception handler wraps one exception around another.
Replace handler. This exception handler replaces one exception with another. - Logging handler. This exception handler formats exception information, such as the message and the stack trace. Then the logging handler gives this information to the Enterprise Library Logging Application Block so that it can be published.
Fault Contract Exception Handler. This exception handler is designed for use at Windows Communication Foundation (WCF) service boundaries, and generates a new Fault Contract from the exception. Exception Policies - Base policy. This policy logs the exception and rethrows the original exception.
- Secure policy. This policy logs the exception, replaces the original exception with a custom exception, and throws the new exception.
- Expressive policy. This policy wraps the original exception inside another exception and throws the new exception.
- Logging Policy
- Replace Policy
- Wrap Policy
- Propagate Policy
Logging Application Block - LogEntry logEntry = new LogEntry();
Logger.Write(logEntry); - Dictionary<string, object> dictionary = new Dictionary<string, object>();
ManagedSecurityContextInformationProvider informationHelper = new ManagedSecurityContextInformationProvider(); informationHelper.PopulateDictionary(dictionary); - using (new Tracer("Log Category"))
{ // Perform processing to be timed here } - if (Logger.ShouldLog(logEntry))
if (Logger.GetFilter<CategoryFilter>().ShouldLog(logEntry)) Validation Application Block - public class Customer
{ [StringLengthValidator(0, 20)] public string CustomerName; [SelfValidation] public void CheckTemperature(ValidationResults results){} } - Customer myCustomer = new Customer("A name that is too long");
ValidationResults r = Validation.Validate<Customer>(myCustomer); // Validator<Customer> validator = ValidationFactory.CreateValidator<Customer>(customerRuleSetCombo.Text); // ValidationResults results = validator.Validate(customer); if (!r.IsValid) { throw new InvalidOperationException("Validation error found."); } - ValidatorComposition(CompositionType.And, CompositionType.Or)
ContainsCharactersValidator DateTimeRangeValidator DomainValidator EnumConversionValidator NotNullValidator ObjectCollectionValidator ObjectValidator PropertyComparisonValidator RangeValidator RegexValidator RelativeDateTimeValidator StringLengthValidator TypeConversionValidator - Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WinForms.ValidationProvider provider
form.ValidateChildren(); 类似于ErrorProvider的使用方式(Extender,在每个控件上都有扩展属性) provider.RuleName provider.SetPerformValidation(control, bool) provider.SetSourcePropertyName(congrol, sourcePropertyName) provider.SetValidatedProperty(control, validatedPropertyName) - You can also specify an instance of the ErrorProvider class for the control. If you do this, the validation errors that result if the validation fails are sent to the error provider as a properly formatted error message.
12月26日 烂片一部,才看了30分钟就不看了,真是浪费了Nicol Kidman。不过好像Nicol也经常接烂片的。 
12月23日 8.0/10。 看了2遍,一遍影院一遍DVD。 在影院看的时候,偌大的影厅里只有我一个人,空旷却看的压抑。但只为王佳芝郁闷,为她爱的人却没勇气去爱她反而要把她拉进一个爬不出来的深坑里,为王这个美好的东西受到一次次的破坏而压抑。易先生? 很正常。 以为看DVD版的时候会更压抑,因为sm型的ml。可是我却看的很舒心,就像看一般的爱情电影,感觉到王和易的感情在一次次的升温发展,感到他们之间真诚、抑制、唯一的感情。以为要失望,因为看的太顺利了。可是在最后王出钻石店后,在镜头里看到三轮车上的风车,看到骑三轮车的男子,听到那么舒缓的音乐的时候,却一下子崩溃了。 电影让我们看到了很多平常看不到的美好事物,可是到最后却总是要把它们撕的粉碎,然后世界又似乎从没发生过这一切一样,仍旧一样的运转。只是,又多了一个可以让我们怀念的故事。 
12月20日 8/10。残酷的黑泽明。从头到尾没有一个人有一丝一毫的希望,即使是瞎子也让他一个人独自留在这个残酷的战乱年代。无论是尔虞我诈还是潜心拜佛,无论是增多功名还是无欲无求,无论是口是心非还是诚实直率,都免不了同样的结局。 
12月11日 实在是忍不住要在这里喊一下,这部电影太好看了。
一堆人在一个有壁炉的房间里jjww,竟然就能jjww个90分钟而让人觉得意犹未尽心满意足心领神会心神向往心有不甘心有灵犀一点通。强烈会看第二遍。
片尾的音乐也好听的很,不过goo不到清晰版的。贴一张Chantelle Duncan的照片以示欣慰。 3月18日 换个东家,终于有个好开局。  2月21日 0. Stranger Than Fiction( 奇幻人生): 8.0/10。
1. Volver( 回归): 7.5/10
2. Casino Royale(皇家赌场): 7.0/10
3. The Departed( 无间行者): 6.5/10
4. Babel( 通天塔): 7.5/10
5. Click( 神奇遥控器): 6.5/10
6. Children of Men(人类之子): 6.0/10
7. The Queen( 女王): 7.5/10
8. Happy Feet( 快乐的大脚): 6.5/10
9. The Black Dahlia( 黑色大丽花): 7.0/10
10. The Devil Wears Prada(时尚女魔头): 6.0/10
11. Flags of Our Fathers( 父辈的旗帜): 7.0/10
12. El Laberinto del Fauno( 潘恩的迷宫): 7.5/10
13. The Prestige( 致命魔术): 7.0/10
14. United.93( 颤慄航班93): 7.0/10
1月10日 David Lynch导演,却发现一点不像David Lynch的风格。  稍微有点复杂的人物关系。喜欢情节有点搞的需要去思考的电影,特别是一时半会还搞不清楚的,例如这部电影中的那个海边的洞。
有时间重看一遍。  80年代的科幻片,今天看来在特效上已经毫无起眼甚至有点粗糙。在情节上似乎也不太引人入胜,不过听说原著更加吸引。大概如“银河系漫游指南”,书中有另外一个世界。  谈论安乐死的一部电影,又牵涉到了生命的意义。太沉重了,无语。  很喜欢有创新性结构的电影,例如深爱的"Mulholland Drive",所以在一个比较空的周末,又找来了这部n久前看过的电影重温了一遍。
重看还是很扣人心弦。  有点类似与“辛德勒名单”的一个故事,只不过发生在卢旺达内战期间。同样是战争的A要对B进行种族灭绝,A中有杰出人士A0为了保护B而进行的斗争。
战争很令人讨厌,令人厌恶。但比正常的战争更让人不能忍受的有目的的对平民的屠杀,如果这种屠杀是全民的行动时,那就更加让人感到痛恨。  意大利电影总让人耳目一新。说话说个不停的人物,古老的石头房子,这些却又让人感觉似曾相识。
前半部是一部很俗套却又百看不厌的爱情故事,偶遇美女,擦出火花,环境不许,坚持不懈,终成眷属。
在后半部中,则看到了更多的男人的责任。对孩子,即使在再艰难的环境中,也要给孩子一个良好的心理环境;对妻子,即使在再危险的情况下,也要互报平安互相支持。总是给爱的人一个乐观向上的环境,时时如此,异常难得。
不喜欢罗罗嗦嗦说话很多的男人,但对这部电影中的主人公,却多了一份敬仰。 
|
|
|
|