Phoenix's Blog

博客园 首页 新随笔 联系 订阅 管理
  25 Posts :: 3 Stories :: 25 Comments :: 0 Trackbacks

公告

2008年8月20日 #

Some steps might help:

1. Run devenv /resetsettings and click View->Server Explorer

2. If step 1 is useless. try to run devenv /safemode and click View->Server Explorer.

posted @ 2008-08-20 13:33 Phoenix 阅读(110) 评论(0) 编辑

2007年12月26日 #

同事有个这样的需求:需要判断一个对象的event是否已经被注册过了,如果没有,则注册一个事件来执行默认操作。
比方说类ClassA
    public class ClassA
    
{
        
public event EventHandler Event1;

        
public EventHandler Delegate1;
        
private string id;

        
protected virtual void OnEvent()
        
{
            
if (this.Event1 != null)
            
{
                
this.Event1(this, EventArgs.Empty);
            }

        }


        
public ClassA()
        
{
            
this.Delegate1 = delegate(object sender, EventArgs e)
            
{
                Console.WriteLine(
"Delegate");
            }
;
        }


        
public void Test()
        
{
            OnEvent();
        }

    }

现在在代码中已经得到一个ClassA的实例,但是如果得到其Event1的情况呢,我们首先想到了使用Reflection, 查到在Reflection中有个EventInfo类型
ClassA a = new ClassA();

EventInfo ei 
= typeof(ClassA).GetEvent("Event1");

可是这个EventInfo只能通过
void AddEventHandler(object target, Delegate handler);
void RemoveEventHandler(object target, Delegate handler);
这两个方法对已知的target进行事件的Hook up (http://msdn2.microsoft.com/zh-cn/library/ms228976.aspx),无法使用如PropertyInfo, FieldInfo之类的GetValue方法得到一个MulticastDelegate实例。

后来想想,事件的声明和公有Field的声明一样,唯独多了一个event关键字,但是采用这种方式还是不能得到一个FieldInfo
FieldInfo fi = typeof(ClassA).GetField("Event1", BindingFlags.Public | BindingFlags.Instance);

不甘心之余用ildasm查看了一下,终于发现一个简单的event声明,编译器实际上处理了如下操作:
        private event EventHandler Event1;

    
        
public void add_Event1(EventHandler value)
        
{
            
// Do addition.
        }


        
public void remove_Event1(EventHandler value)
        
{
            
// Do removal.
        }

所以实际上我们必须是得到一个私有的Field Event1,于是将代码改了改
FieldInfo fi = typeof(ClassA).GetField("Event1", BindingFlags.NonPublic | BindingFlags.Instance);
呵呵,终于能够得到一个FieldInfo的实例了,接下来使用FieldInfo.GetValue方法得到一个MulticastDelegate (未注册事件时为null). 这样我们可以对这个MulticastDelegate对象进行操作,实现真正的事件Hook up.

奇怪的是类似的代码在同事那边执行不过,用反编译工具查看了一下,发现其事件是采用自定义的方式

        public event EventHandler Event2
        
{
            add
            
{

            }


            remove
            
{

            }

        }

真正的事件delegate是存放在一个EventHandlerList中 (请参阅MSDN: .Net Framework Developer's Guide: Handle multiple events using event properties.)
所以接下来的就是找到这个EventHandlerList和MulticastDelegate的key,然后取得这个MulticastDelegate.

使用EventHandlerList易于管理,例如在Dispose资源时,统一Fire事件时等等,但是EventHandlerList本身是线性列表的对象,当这个List里面的delegate变得非常多时,查询的效率会变得非常差. :)
posted @ 2007-12-26 15:01 Phoenix 阅读(1535) 评论(9) 编辑

2007年4月26日 #

摘要: 在FlashGet官方网站下载了一个1.82版的,安装后发现在IE插件中多了一个奇虎的东东,当时也没在意,结果发现过了不久经常弹出小说,色情之类的网站。
原来对FlashGet感觉蛮好的,一时也没想到是由于安装了FlashGet的问题,但后面发现打开的网站一般会出现下载FlashGet的广告。心想难不成FlashGet也堕落到了
与流氓软件同流合污的地步了吗?
首先就将FlashGet卸载,发现还是不时弹出网页,查看进程也没发现特别的进程。
于是就下载了瑞星卡卡,安装之后发现瑞星运行不了,运行后就自动关闭。心想肯定是哪个流氓软件使的鬼,专门针对瑞星卡卡做了手脚。
后来查了查,发现唯一有疑点的就是附在Explorer.exe进程上有个safe360,是奇虎安全卫生360的一个升级东东,反正在添加删除程序中看不到,而在Program Files中多了一个safe360的文件夹,同时这个升级程序还会附在IE进程上。

于是首先将Explorer.exe和IExplorer.exe两个进程强行关闭,然后在命令提示符下将safe360下所有阅读全文
posted @ 2007-04-26 21:47 Phoenix 阅读(525) 评论(5) 编辑

2007年2月15日 #

画立体柱图应该非常的简单,就是两个截面+柱体。所以我就不做多的描述了,请直接看代码吧:

 1/// <summary>
 2    /// Draw Bar Chart
 3    /// </summary>
 4    /// <param name="g"></param>
 5    /// <param name="value"></param>

 6    private void DrawBarChart(Graphics g, double value)
 7    {
 8        double val = value > 100 ? 100 : value;
 9
10        // Compute size and location
11        Point pt = new Point();
12        int width = 100;
13        int height = 16;
14        int eclipseWidth = 4;
15
16        Rectangle r1 = new Rectangle(pt, new Size(eclipseWidth, height));
17        Rectangle r2 = r1;
18        r2.X += width;
19        Rectangle r3 = r1;
20        r3.X = r1.X + (int)(width * (val / 100.0));
21
22        Rectangle r4 = r1;
23        r4.X = pt.X + (eclipseWidth / 2);
24        r4.Width = width;
25
26        Rectangle r5 = r4;
27        r5.Width = (int)(width * (val / 100.0));
28
29        Pen redPen = new Pen(Color.Red);
30        Pen greenPen = new Pen(Color.Green);
31
32        GraphicsPath gp1 = new GraphicsPath();
33        gp1.AddEllipse(r1);
34        GraphicsPath gp2 = new GraphicsPath();
35        gp2.AddEllipse(r2);
36
37        Region rgn1 = new Region(r4);
38        rgn1.Exclude(gp1);
39        rgn1.Union(gp2);
40
41
42        gp1 = new GraphicsPath();
43        gp1.AddEllipse(r1);
44        gp2 = new GraphicsPath();
45        gp2.AddEllipse(r3);
46
47        Region rgn2 = new Region(r5);
48        rgn2.Exclude(gp1);
49        rgn2.Union(gp2);
50
51        LinearGradientBrush lgb = new LinearGradientBrush(pt, new Point(pt.X, pt.Y + height), Color.Black, Color.Yellow);
52        lgb.SetBlendTriangularShape(0.5f1.0f);
53        
54        g.FillRegion(lgb, rgn1);
55
56        lgb = new LinearGradientBrush(pt, new Point(pt.X, pt.Y + height), Color.Navy, Color.Green);
57        if (value > 100)
58        {
59            lgb = new LinearGradientBrush(pt, new Point(pt.X, pt.Y + height), Color.Navy, Color.Red);
60        }

61        lgb.SetBlendTriangularShape(0.5f1.0f);
62        g.FillRegion(lgb, rgn2);
63
64
65        PathGradientBrush pb = new PathGradientBrush(gp1);
66        pb.SurroundColors = new Color[] { Color.Gray };
67        pb.CenterColor = pb.CenterColor = Color.LightYellow;
68
69        g.FillEllipse(pb, r1);
70
71        Font f = new Font(FontFamily.GenericSansSerif,9.0f);
72
73        string text = string.Format("{0}%", value);
74        if (value > 100)
75        {
76            text = "过期未完成";
77        }

78        
79        Color fntColor = Color.White;
80        if (val < 50)
81        {
82            fntColor = Color.Purple;
83        }

84        
85        RectangleF textRect = this.ComputeTextRectangle(g, r4, f, text);
86        g.DrawString(text, f, new SolidBrush(fntColor), textRect, StringFormat.GenericTypographic); 
87
88    }

需要把所画的图像由页面展示出来:

 1    protected void Page_Load(object sender, EventArgs e)
 2    {
 3        Response.Clear();
 4        Response.ContentType = "image/jpeg";
 5
 6        string error = Request["error"];
 7        string progress = Request["progress"];
 8
 9        MemoryStream ms = new MemoryStream();
10
11        Bitmap bmp = new Bitmap(110,17);
12        using (Graphics g = Graphics.FromImage(bmp))
13        {
14            g.Clear(Color.White);
15
16            if (string.IsNullOrEmpty(progress))
17            {
18                error = "1";
19            }

20
21            if (!string.IsNullOrEmpty(error))
22            {
23                this.DrawError(g, int.Parse(error));
24            }

25            else
26            {
27                this.DrawBarChart(g, double.Parse(progress));
28            }

29        }

30
31        bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
32    }

效果图如下,里面有比较明显的锯齿,主要是所选取的位图尺寸比较小,如果取大一些再来缩小展现的话,效果应该会好些。
posted @ 2007-02-15 11:28 Phoenix 阅读(204) 评论(0) 编辑

2007年2月14日 #

数据对于企业来说及其重要,像前几天的一个晚上,我们公司突然断电,CRM服务器没有UPS电源,所以造成两块硬盘出现Media Error,我们的磁盘采用RAID5的方式,将其中一块Force Online后,还是不能Rebuild,进不了操作系统. 幸亏装了双系统,从另外一个OS启动将数据全部取出来了.算是有惊无险的一次吧.

现在我将其进行自动备份到其他机器上去,作一个双保险.

1. 在Master数据库中建一个格式化时间的函数
Create function FormatDate(
@date smalldatetime
)
returns nvarchar(10)
begin
declare @dt nvarchar(10);
set @dt = SubString(Convert(nvarchar(20),@date,120),1,10); --格式化为yyyy-MM-dd HH:mm:ss格式,与后面的批处理日期格式保持一致
return @dt
end

2. 创建一个备份数据库的存储过程
/*
* 在磁盘上根据日期创建一个文件夹,并将数据库备份到文件夹内
*/

Create Proc BackupCRM
as
begin

declare @path nvarchar(200);
declare @crmfilename nvarchar(200);
declare @metafilename nvarchar(200);
declare @cmd nvarchar(1000);

set @path = 'E:\Backup\' + dbo.formatdate(getdate()) + '\';
set @crmfilename = @path + 'CRM.bak';
set @metafilename = @path + 'Meta.bak';
set @cmd = 'md ' + @path;

--为了安全,建议还是将xp_cmdshell改名

exec xp_cmdshell @cmd,NO_OUTPUT

backup database _0105237670_MSCRM to disk = @crmfilename;
backup database _0105237670_METABASE to disk = @metafilename
end

3. 创建清空文件和复制文件的批处理命令
a.用于备份数据库前清空文件的批处理文件clearfiles.bat
del E:\Backup\%date:~10,4%-%date:~4,2%-%date:~7,2%\CRM.bak
del E:\Backup\%date:~10,4%-%date:~4,2%-%date:~7,2%\Meta.bak

说明: %date%可以获得日期的字符串,但我们需要用~ index,len来截断并组合成yyyy-MM-dd格式的字符串,这和SubString函数类似,index表示字符串的起始索引位置,len表示要截取的长度.
如果想看到自己Server的%date%输出格式是什么,可以输入 echo %date%,我们的Server输出是Wed 02/14/2007
b. 复制文件至远程机器批处理文件copyfiles.bat

md \\10.89.53.250\e$\backup\%date:~10,4%-%date:~4,2%-%date:~7,2%\
del \\10.89.53.250\e$\backup\%date:~10,4%-%date:~4,2%-%date:~7,2%\CRM.bak
del \\10.89.53.250\e$\backup\%date:~10,4%-%date:~4,2%-%date:~7,2%\Meta.bak

copy E:\Backup\%date:~10,4%-%date:~4,2%-%date:~7,2%\CRM.bak \\10.89.53.250\e$\backup\%date:~10,4%-%date:~4,2%-%date:~7,2%
copy E:\Backup\%date:~10,4%-%date:~4,2%-%date:~7,2%\Meta.bak \\10.89.53.250\e$\backup\%date:~10,4%-%date:~4,2%-%date:~7,2%

4. 启动SQL Agent服务,并设为开机自动运行,然后新建一个备份的Job

注意将批处理执行失败后的动作设为"执行下一步操作",否则如果文件不存在等可能会导致Job不能正常运行


最后在Schedules中新建一个Schedule,当然选择的运行的时间点就是那种风高月黑夜深人静的时候罗:)

posted @ 2007-02-14 12:38 Phoenix 阅读(2483) 评论(0) 编辑

2006年11月25日 #

摘要: 为了在Vista中用imagex创建wim镜像,在Command Prompt模式下发现运行后出现下列错误提示:ERROR: The current logged on user does not have administrative privileges.我的用户本身就是属于Administrators Group的,可是不知道为何没有全部的管理员的权限,于是到网上找资料。可惜并没有找到正确的...阅读全文
posted @ 2006-11-25 23:22 Phoenix 阅读(897) 评论(0) 编辑

2006年8月8日 #

摘要: 这几天一个CRM把我折腾死了,想把一个Domain中的CRM数据部署到另外一个域,运行CRM的DeploymentTool之后,在Importing AD...处就停下来了,然后也没有任何提示,经过无数次的不同测试,最后才发现由于没有完全match域用户,奇怪的是在执行之前工具怎么也不提示一下呢?阅读全文
posted @ 2006-08-08 11:20 Phoenix 阅读(89) 评论(0) 编辑

2006年6月16日 #

摘要: 我的T60 B14,安装VMware时机器中途会重启,而且重启后在登录时又自动重启,当我以安全模式启动后可以进入系统,或不安装显卡驱动时安装VMware就没事。我在查看中断时发现显卡,网卡都是使用16号IRQ,而且还被一些红外线什么的共六个设备使用。如果我不安装显卡驱动时ATI显卡的IRQ就没有。因为是笔记本,不好拆机器换插口。通过设备查看器不能手工改显卡等的IRQ,所以看看哪位大虾有没有其它办法...阅读全文
posted @ 2006-06-16 22:17 Phoenix 阅读(488) 评论(3) 编辑

2006年2月10日 #

摘要: 无聊的时候在.Net下用API写了一个Window窗户.简单比较了一下,纯API的窗体运行启动要快点,起始占用内存也少点,大概6M,但比起用asm创建的一般才2M多点还是看得出.Net确实是吃内存的大户啊.^_^代码/**//*SnippetCompiler*Author:PhoenixChen*Date:2006-02-10*Comment:*/usingSystem;usingSystem.R...阅读全文
posted @ 2006-02-10 23:52 Phoenix 阅读(584) 评论(0) 编辑

2006年2月5日 #

摘要: Oracle 10G Server不在本机上,我希望安装SQLPlus的帮助。安装SQLPlus需要使用System User登录,但System已经被Lock掉了。还好有dba的权限。先Unlock System账号,并修改密码:-- UnlockALTER USER SYSTEM ACCOUNT UNLOCK;-- Modify PasswordALTER USER SYSTEM IDENTI...阅读全文
posted @ 2006-02-05 18:40 Phoenix 阅读(1530) 评论(0) 编辑

仅列出标题  下一页