Tuesday, May 25, 2010

Install Windows Azure SDK on Windows XP

To play with Azure on visual studio 2010, the cloud service project page will give you a button to download Windows Azure Tools For Microsoft Visual Studio.

As my OS is Windows XP, the install program will give me a error page saying "To install this software, you must be running a 32-bit edition of Windows Server 2008 or a 32-bit edition of Windows Vista with Service Pack 1."

A search on this topic took me to here . I followed the steps in this post to be able to install the tools on XP.

1. Create an empty directory somewhere on your file system called Exported.

2. Navigate to the Tools folder under the install directory for the Windows Installer SDK.
In my case, this is under C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin

3. Launch MsiDb.exe

4.) In the MsiTable - Select Database for Import/Export dialog, browse to and select the WindowsAzureSDK-x86.msi file.

5.) In the MsiTable - Select Folder containing Text Files dialog, browse to and select the Exported directory you created earlier.

6.) In the MsiTable - Database table import/export window, click the Export radio button.

7.) In the list, select LaunchCondition, and then click OK.

8.) Click the Quit button.

8.) Open "...\Exported\LaunchCondition.idt" in Notepad

9.) Remove the following lines in this file:
(VersionNT = 600 AND ServicePackLevel >= 1) OR (VersionNT > 600) To install this software, you must be running a 32-bit edition of Windows Server 2008 or a 32-bit edition of Windows Vista with Service Pack 1.
IISVERSION AND ASPNET To use this software, you must enable Internet Information Services 7.0 with ASP.NET support. See the product release notes for details.

10.) Save the file.

11.) Navigate to the Tools folder under the install directory for the Windows Installer SDK

12.) Launch MsiDb.exe

13.) In the MsiTable - Select Database for Import/Export dialog, browse to and select the WindowsAzureSDK-x86.msi file.

14.) In the MsiTable - Select Folder containing Text Files dialog, browse to and select the Exported directory you created earlier.

15.) In the MsiTable - Database table import/export window, click the Import radio button.

16.) In the list, select LaunchCondition.idt, and then click OK.

17.) Click the Quit button.

18.) Launch the WindowsAzureSDK-x86.msi file, and enjoy.

Thursday, May 13, 2010

How to remove ANTI MALWARE DOCTOR

  • 重启到安全模式, 删除对应的文件和注册项
  • \enemies-names.txt
    \Antimalware Doctor.exe

    HKEY_CURRENT_USER\Software\Antimalware Doctor Inc\Antimalware Doctor
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\Antimalware Doctor
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run "Antimalware Doctor.exe"

  • 注意病毒文件是隐藏的, 要在"Folder Options"里显示隐藏文件才能看到病毒文件
  • 如果"Folder Options"被禁止, 使用如下注册表恢复:

    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
    "NoFolderOptions"=dword:0000000
    [HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Restrictions]
    "NoBrowserOptions"=dword:00000000
  • 如果注册表工具已经被禁止
  • 把以下内容存成vbs后缀的文件, 并运行它:

    'Enable/Disable Registry Editing tools
    '?Doug Knox - rev 12/06/99

    Option Explicit

    'Declare variables
    Dim WSHShell, n, MyBox, p, t, mustboot, errnum, vers
    Dim enab, disab, jobfunc, itemtype

    Set WSHShell = WScript.CreateObject("WScript.Shell")
    p = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\"
    p = p & "DisableRegistryTools"
    itemtype = "REG_DWORD"
    mustboot = "Log off and back on, or restart your pc to" & vbCR & "effect the changes"
    enab = "ENABLED"
    disab = "DISABLED"
    jobfunc = "Registry Editing Tools are now "

    'This section tries to read the registry key value. If not present an
    'error is generated. Normal error return should be 0 if value is
    'present
    t = "Confirmation"
    Err.Clear
    On Error Resume Next
    n = WSHShell.RegRead (p)
    On Error Goto 0
    errnum = Err.Number

    if errnum <> 0 then
    'Create the registry key value for DisableRegistryTools with value 0
    WSHShell.RegWrite p, 0, itemtype
    End If

    'If the key is present, or was created, it is toggled
    'Confirmations can be disabled by commenting out
    'the two MyBox lines below

    If n = 0 Then
    n = 1
    WSHShell.RegWrite p, n, itemtype
    Mybox = MsgBox(jobfunc & disab & vbCR & mustboot, 4096, t)
    ElseIf n = 1 then
    n = 0
    WSHShell.RegWrite p, n, itemtype
    Mybox = MsgBox(jobfunc & enab & vbCR & mustboot, 4096, t)
    End If

Tuesday, June 16, 2009

WCF Serialization

WCF中的序列化


[DataContract(Namespace = "http://webabcd.cnblogs.com/")]
public class DataContractSerializerObject
{
   // Name - 数据成员的名称
   // Order - 数据成员的序列化和反序列化的顺序
   [DataMember(Name = "UniqueID", Order = 0)]
   public Guid ID { get; set; }
  
   [DataMember(Order = 1)]
   public string Name { get; set; }
  
   [DataMember(Order = 2)]
   public int Age { get; set; }
  
   [DataMember(Order = 3)]
   public DateTime Time { get; set; }
}

生成XML是怎样的? 以下的Mapping关系:

1、Root Element为对象的Type Name——DataContractOrder
2、Type的Namespace会被加到XML根节点的Namespace中http://schemas.datacontract.org/2004/07/Artech.WCFSerialization
3、对象的所有成员以XML Element的形式而不是以XML Attribute的形式输出。
4、所以对象在XML的输出顺序是按照字母排序。
5、所有成员的Elelement 名称为成员名称。
6、不论成员设置怎样的作用域(public,protected,internal,甚至市Private),所有运用了DataMemberAttribute的成员均被序列化到XML中——private string ProducingArea。
7、Type和成员必须运用DataContractAttribute和DataMemberAttribute才能被序列化。

上面这些都是默认的Mapping关系,在通常情况下我们用默认的这种Mapping往往不能满足我们的需求,为了 把.NET序列化成我们需要的XML 结构(比如我们的XmL必须于我们预先定义的XSD一致),我们可以在这两个Attribute(DataContractAttribute和 DataMemberAttribute)制定相关的参数来实现。具体做法如下。

1、Root Element可以通过DataContractAttribute中的Name参数定义。
2、Namespace可以通过DataContractAttribute中的NameSpace参数定义。
3、对象的成员只能以XML Element的形式被序列化。
4、对象成员对应的XML Element在XML出现的位置可以通过DataMemberAttribute的Order参数来定义。
5、对象成员对应的Element的名称可以通过DataMemberAttribute中的Name定义。
6、如果不希望某个成员输出到XML中,可以去掉成员对应的DataMemberAttribute Attribute。
此外DataMemberAttribute还有连个额外的参数:
1、IsRequired:制定该成员为必须的,如果通过工具生成XSD的话,对应的Element的minOccur=“1”。
2、EmitDefaultValue:制定是否输入没有赋值的成员(值为默认值)是否出现在XML中。

Friday, August 08, 2008

Use Castle Windsor as IoC container in Microsoft.MVC

 

There are already some articles talking about how to use Unity IoC and StructureMap in Microsoft.MVC. I've used Windsor container for quite a while. Here I want to show you how to add the Castle Windsor IoC Container to an ASP.NET MVC Framework Application to create controllers and inject their dependencies.

1. First, let's implement our WindsorContainer, here we add each MVC controller as normal Component.

// *********************
// WebContainer.cs
// *********************

using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;
using Castle.Core.Resource;

using Shop.Frontend.Controllers;

namespace Duplium.Shop.Frontend
{
    public class WebContainer : WindsorContainer
    {
        public WebContainer() //: base(new XmlInterpreter(new ConfigResource()))
        {
            AddFacilities();
            AddComponents();
        }

        private void AddFacilities()
        {

        }

        private void AddComponents()
        {
            base.AddComponent<DemoProductsDataContext>();

            base.AddComponent<ProductController>();
            base.AddComponent<HomeController>();
        }
    }
}

 

2. Then, implement a ControllerFactory class. It'll be used and replace MVC default controller factory.

// *********************
// ControllerFactory.cs
// *********************

using System.Web.Mvc;

using Castle.Core;
using Castle.Windsor;

namespace Shop.Frontend
{
    public class ControllerFactory : DefaultControllerFactory
    {
        protected override IController GetControllerInstance(Type controllerType)
        {
            if (controllerType == null)
                return (IController)null;

            IWindsorContainer container = null;
            try
            {
                container = ((GlobalApplication)(this.RequestContext.HttpContext.ApplicationInstance)).Container;
                return (Controller)container.Resolve(controllerType);

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                throw;
            }
        }

    }
}

3. At last, assembly them together in Global.asax

 

// *********************
// Global.asax.cs
// *********************

using Castle.Core;
using Castle.Windsor;

namespace Shop.Frontend
{
    public class GlobalApplication : System.Web.HttpApplication, IContainerAccessor
    {
        private static IWindsorContainer container;

        #region IContainerAccessor

        public IWindsorContainer Container
        {
            get { return container; }
        }

        #endregion

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            container = new WebContainer();
            RegisterRoutes(RouteTable.Routes);
            ControllerBuilder.Current.SetControllerFactory(
                new ControllerFactory()
                );
        }

        protected void Application_End(object sender, EventArgs e)
        {
            container.Dispose();
        }
    }
}