在此页上的 ActiveX 控件和本页上的其它部份的交互可能不安全。你想允许这种交互

如果采用VC++开发的ActiveX,那么第一次运行的时候,IE中就会提示,“在此页上的ActiveX控件和本页上的其他部分 的交互可能不安全,你想允许这种交互吗?”在网上找了很多资料,原理介绍的多,但是真正如何做,介绍的比较少,因此这里把实际的步骤一步一步的记录下来 了,供大家参考。
1.1 去除ActiveX访问时的安全提示
当ActiveX第一次被访问时,会出现如下提示框:

这是IE浏览器的安全机制造成的,我们可以采用下面的步骤来去除这个提示信息:
1.1.1 在CDemoCtl的头文件.h中增加对objsave的引用
#include <objsafe.h>
1.1.2 在其protected声明区增加如下内容:
//去掉安全警告 BEGIN
DECLARE_INTERFACE_MAP()
BEGIN_INTERFACE_PART(ObjectSafety, IObjectSafety)
STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid, DWORD __RPC_FAR *pdwSupportedOptions, DWORD __RPC_FAR *pdwEnabledOptions);
STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions);
END_INTERFACE_PART(ObjectSafety)
//去掉安全警告 END
1.1.3 在CDemoCtl的实现类.cpp的IMPLEMENT_DYNCREATE(CActivexFirstCtrl, COleControl)这一行后增加如下内容:
    
//去掉安全警告 BEGIN
BEGIN_INTERFACE_MAP(CDemoCtl, COleControl)
INTERFACE_PART(CDemoCtl, IID_IObjectSafety, ObjectSafety)
END_INTERFACE_MAP()
// Implementation of IObjectSafety
STDMETHODIMP CDemoCtl::XObjectSafety::GetInterfaceSafetyOptions(
REFIID riid,
DWORD __RPC_FAR *pdwSupportedOptions,
DWORD __RPC_FAR *pdwEnabledOptions)
{
METHOD_PROLOGUE_EX(CDemoCtl, ObjectSafety)
if (!pdwSupportedOptions || !pdwEnabledOptions)
{
return E_POINTER;
}
*pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;
*pdwEnabledOptions = 0;
if (NULL == pThis->GetInterface(&riid))
{
TRACE(“Requested interface is not supported./n”);
return E_NOINTERFACE;
}
// What interface is being checked out anyhow?
OLECHAR szGUID[39];
int i = StringFromGUID2(riid, szGUID, 39);
if (riid == IID_IDispatch)
{
// Client wants to know if object is safe for scripting
*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;
return S_OK;
}
else if (riid == IID_IPersistPropertyBag
|| riid == IID_IPersistStreamInit
|| riid == IID_IPersistStorage
|| riid == IID_IPersistMemory)
{
// Those are the persistence interfaces COleControl derived controls support
// as indicated in AFXCTL.H
// Client wants to know if object is safe for initializing from persistent data
*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA;
return S_OK;
}
else
{
// Find out what interface this is, and decide what options to enable
TRACE(“We didn”t account for the safety of this interface, and it”s one we support…/n”);
return E_NOINTERFACE;
}
}
STDMETHODIMP CDemoCtl::XObjectSafety::SetInterfaceSafetyOptions(
REFIID riid,
DWORD dwOptionSetMask,
DWORD dwEnabledOptions)
{
METHOD_PROLOGUE_EX(CDemoCtl, ObjectSafety)
OLECHAR szGUID[39];
// What is this interface anyway?
// We can do a quick lookup in the registry under HKEY_CLASSES_ROOT/Interface
int i = StringFromGUID2(riid, szGUID, 39);
if (0 == dwOptionSetMask && 0 == dwEnabledOptions)
{
// the control certainly supports NO requests through the specified interface
// so it”s safe to return S_OK even if the interface isn”t supported.
return S_OK;
}
// Do we support the specified interface?
if (NULL == pThis->GetInterface(&riid))
{
TRACE1(“%s is not support./n”, szGUID);
return E_FAIL;
}
if (riid == IID_IDispatch)
{
TRACE(“Client asking if it”s safe to call through IDispatch./n”);
TRACE(“In other words, is the control safe for scripting?/n”);
if (INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwEnabledOptions)
{
return S_OK;
}
else
{
return E_FAIL;
}
}
else if (riid == IID_IPersistPropertyBag
|| riid == IID_IPersistStreamInit
|| riid == IID_IPersistStorage
|| riid == IID_IPersistMemory)
{
TRACE(“Client asking if it”s safe to call through IPersist*./n”);
TRACE(“In other words, is the control safe for initializing from persistent data?/n”);
if (INTERFACESAFE_FOR_UNTRUSTED_DATA == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_DATA == dwEnabledOptions)
{
return NOERROR;
}
else
{
return E_FAIL;
}
}
else
{
TRACE1(“We didn”t account for the safety of %s, and it”s one we support…/n”, szGUID);
return E_FAIL;
}
}
STDMETHODIMP_(ULONG) CDemoCtl::XObjectSafety::AddRef()
{
METHOD_PROLOGUE_EX_(CDemoCtl, ObjectSafety)
return (ULONG)pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) CDemoCtl::XObjectSafety::Release()
{
METHOD_PROLOGUE_EX_(CDemoCtl, ObjectSafety)
return (ULONG)pThis->ExternalRelease();
}
STDMETHODIMP CDemoCtl::XObjectSafety::QueryInterface(
REFIID iid, LPVOID* ppvObj)
{
METHOD_PROLOGUE_EX_(CDemoCtl, ObjectSafety)
return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
}
//去掉安全警告 END

 

Customizing the new FitNesse parser

FitNesse began its life using the ‘simplest thing that works’ to parse wiki markup and render it as HTML: a set of regular expressions. Over the years, FitNesse functionality has grown, and the regex-based parser has had to support more and more complex tasks.  More and more hacks have been added to work around regex limitations and performance has suffered as bigger and more complex wiki pages have been thrown at it. So last spring, I started on a project to re-write the entire FitNesse parser, using classic grammar theory approaches.

Although the realities of earning a living slowed progress at times, and the challenges of replicating all the quirks of the original parser tested my resolve, we have finally merged the new parser into the main code base.  Thanks to a number of beta users, it has been tested on some major FitNesse test suites and the next FitNesse release, coming soon, will use the new parser.

One of the features of the original parser was the ability to extend the wiki syntax by plugging in your own custom wiki ‘widgets’. This is described here : you write a class that extends WikiWidget and you add a line to a plugins.properties file.

WikiWidgets=className

James Carr wrote a nice post describing a detailed example of this.

The new parser also has this feature, but the plug-in class that you write is different. I’m going to show a very simple example here. Let’s imagine we want to write !pi in our wiki pages and have it rendered with the value of pi in the HTML.

public class PiSymbolType extends SymbolType implements Translation {
    public PiSymbolType () {
        super ( "Pi" );
        wikiMatcher ( new Matcher (). string ( "!pi" ));
        htmlTranslation ( this );
    }
    public String toTarget ( Translator translator , Symbol symbol ) {
        return Double . toString ( Math . PI );
    }
}

The plug-in class must extend SymbolType . A plug-in class can specify up to four pieces of information for the parser. Our simple example only needs to supply three of these.

The first is a name, specified in the super constructor. The name is just used for error reporting and debugging and so it can be any descriptive string.

The second is the wikiMatcher . This is an object that knows how to identify the symbol type in the source string. The Matcher class provides a lot of common matching behavior, so we can just tell it that our symbol type is recognized by the string “!pi”. You can look at the Matcher source to find other matching behavior.

The third is the wikiRule , which our symbol type doesn’t require. This is an object that implements a grammar production rule if our symbol type is composed of other symbol types (a non-terminal, in grammar-speak). Our symbol type is a terminal so we don’t need a production rule. Look at the fitnesse.wikitext.parser package to see examples of how production rule classes are written.

The fourth is the htmlTranslation . This is an object that renders the symbol type as a string in the HTML output. We can implement the Translation interface and specify this as our translation object. The toTarget method renders our output, a string containing the value of pi.

We add a line to the plugins.properties file.

SymbolTypes=PiSymbolType

That’s it!

Posted by Mike at 12:43

Labels: FitNesse , Java , parser

SQL Server 触发器

    触发器是一种特殊类型的存储过程,它不同于之前的我们介绍的存储过程。触发器主要是通过事件进行触发被自动调用执行的。而存储过程可以通过存储过程的名称被调用。

    触发器对表进行插入、更新、删除的时候会自动执行的特殊存储过程。触发器一般用在check约束更加复杂的约束上面。触发器和普通的存储过程的区别是:触发器是当对某一个表进行操作。诸如:update、insert、delete这些操作的时候,系统会自动调用执行该表上对应的触发器。SQL Server 2005中触发器可以分为两类:DML触发器和DDL触发器,其中DDL触发器它们会影响多种数据定义语言语句而激发,这些语句有create、alter、drop语句。

    DML触发器分为:

    1、 after触发器(之后触发)

        a、 insert触发器

        b、 update触发器

        c、 delete触发器 

    2、 instead of 触发器 (之前触发)

    其中after触发器要求只有执行某一操作insert、update、delete之后触发器才被触发,且只能定义在表上。而instead of触发器表示并不执行其定义的操作(insert、update、delete)而仅是执行触发器本身。既可以在表上定义instead of触发器,也可以在视图上定义。

    触发器有两个特殊的表:插入表(instered表)和删除表(deleted表)。这两张是逻辑表也是虚表。有系统在内存中创建者两张表,不会存储在数据库中。而且两张表的都是只读的,只能读取数据而不能修改数据。这两张表的结果总是与被改触发器应用的表的结构相同。当触发器完成工作后,这两张表就会被删除。Inserted表的数据是插入或是修改后的数据,而deleted表的数据是更新前的或是删除的数据。 

对表的操作

Inserted逻辑表

Deleted逻辑表

增加记录(insert)

存放增加的记录

删除记录(delete)

存放被删除的记录

修改记录(update)

存放更新后的记录

存放更新前的记录

    Update数据的时候就是先删除表记录,然后增加一条记录。这样在inserted和deleted表就都有update后的数据记录了。注意的是:触发器本身就是一个事务,所以在触发器里面可以对修改数据进行一些特殊的检查。如果不满足可以利用事务回滚,撤销操作。

Ø 创建触发器

    1、语法

create trigger tgr_name
on table_name
with encrypion –加密触发器
for update...
as
Transact-SQL

   

    2、 创建insert类型触发器

--创建insert插入类型触发器
if (object_id('tgr_classes_insert', 'tr') is not null)
drop trigger tgr_classes_insert
go
create trigger tgr_classes_insert
on classes
for insert --插入触发
as
--定义变量
declare @id int, @name varchar(20), @temp int;
--在inserted表中查询已经插入记录信息
select @id = id, @name = name from inserted;
set @name = @name + convert(varchar, @id);
set @temp = @id / 2;
insert into student values(@name, 18 + @id, @temp, @id);
print '添加学生成功!';
go
--插入数据
insert into classes values('5班', getDate());
--查询数据
select * from classes;
select * from student order by id;

     insert触发器,会在inserted表中添加一条刚插入的记录。

 

    3、创建delete类型触发器

--delete删除类型触发器
if (object_id('tgr_classes_delete', 'TR') is not null)
drop trigger tgr_classes_delete
go
create trigger tgr_classes_delete
on classes
for delete --删除触发
as
print '备份数据中……';
if (object_id('classesBackup', 'U') is not null)
--存在classesBackup,直接插入数据
insert into classesBackup select name, createDate from deleted;
else
--不存在classesBackup创建再插入
select * into classesBackup from deleted;
print '备份数据成功!';
go
--
--不显示影响行数
--set nocount on;
delete classes where name = '5班';
--查询数据
select * from classes;
select * from classesBackup;

   delete触发器会在删除数据的时候,将刚才删除的数据保存在deleted表中。

 

    4、 创建update类型触发器

--update更新类型触发器
if (object_id('tgr_classes_update', 'TR') is not null)
drop trigger tgr_classes_update
go
create trigger tgr_classes_update
on classes
for update
as
declare @oldName varchar(20), @newName varchar(20);
--更新前的数据
select @oldName = name from deleted;
if (exists (select * from student where name like '%'+ @oldName + '%'))
begin
--更新后的数据
select @newName = name from inserted;
update student set name = replace(name, @oldName, @newName) where name like '%'+ @oldName + '%';
print '级联修改数据成功!';
end
else
print '无需修改student表!';
go
--查询数据
select * from student order by id;
select * from classes;
update classes set name = '五班' where name = '5班';

     update触发器会在更新数据后,将更新前的数据保存在deleted表中,更新后的数据保存在inserted表中。

 

   5、 update更新列级触发器

if (object_id('tgr_classes_update_column', 'TR') is not null)
drop trigger tgr_classes_update_column
go
create trigger tgr_classes_update_column
on classes
for update
as
--列级触发器:是否更新了班级创建时间
if (update(createDate))
begin
raisError('系统提示:班级创建时间不能修改!', 16, 11);
rollback tran;
end
go
--测试
select * from student order by id;
select * from classes;
update classes set createDate = getDate() where id = 3;
update classes set name = '四班' where id = 7;

     更新列级触发器可以用update是否判断更新列记录;

 

    6、 instead of类型触发器

       instead of触发器表示并不执行其定义的操作(insert、update、delete)而仅是执行触发器本身的内容。

       创建语法

create trigger tgr_name
on table_name
with encryption
instead of update...
as
T-SQL

   

   7、创建instead of触发器

if (object_id('tgr_classes_inteadOf', 'TR') is not null)
drop trigger tgr_classes_inteadOf
go
create trigger tgr_classes_inteadOf
on classes
instead of delete/*, update, insert*/
as
declare @id int, @name varchar(20);
--查询被删除的信息,病赋值
select @id = id, @name = name from deleted;
print 'id: ' + convert(varchar, @id) + ', name: ' + @name;
--先删除student的信息
delete student where cid = @id;
--再删除classes的信息
delete classes where id = @id;
print '删除[ id: ' + convert(varchar, @id) + ', name: ' + @name + ' ] 的信息成功!';
go
--test
select * from student order by id;
select * from classes;
delete classes where id = 7;

   

      # 显示自定义消息raiserror

if (object_id('tgr_message', 'TR') is not null)
drop trigger tgr_message
go
create trigger tgr_message
on student
after insert, update
as raisError('tgr_message触发器被触发', 16, 10);
go
--test
insert into student values('lily', 22, 1, 7);
update student set sex = 0 where name = 'lucy';
select * from student order by id;

   8、 修改触发器

alter trigger tgr_message
on student
after delete
as raisError('tgr_message触发器被触发', 16, 10);
go
--test
delete from student where name = 'lucy';

   9、 启用、禁用触发器

--禁用触发器
disable trigger tgr_message on student;
--启用触发器
enable trigger tgr_message on student;

    10、查询创建的触发器信息

--查询已存在的触发器
select * from sys.triggers;
select * from sys.objects where type = 'TR';

--查看触发器触发事件
select te.* from sys.trigger_events te join sys.triggers t
on t.object_id = te.object_id
where t.parent_class = 0 and t.name = 'tgr_valid_data';

--查看创建触发器语句
exec sp_helptext 'tgr_message';

 

    # 示例,验证插入数据

if ((object_id('tgr_valid_data', 'TR') is not null))
drop trigger tgr_valid_data
go
create trigger tgr_valid_data
on student
after insert
as
declare @age int,
@name varchar(20);
select @name = s.name, @age = s.age from inserted s;
if (@age < 18)
begin
raisError('插入新数据的age有问题', 16, 1);
rollback tran;
end
go
--test
insert into student values('forest', 2, 0, 7);
insert into student values('forest', 22, 0, 7);
select * from student order by id;

    # 示例,操作日志

 

 

 

 

 

 

 

 

 

 

 

 

if (object_id('log', 'U') is not null)
drop table log
go
create table log(
id int identity(1, 1) primary key,
action varchar(20),
createDate datetime default getDate()
)
go
if (exists (select * from sys.objects where name = 'tgr_student_log'))
drop trigger tgr_student_log
go
create trigger tgr_student_log
on student
after insert, update, delete
as
if ((exists (select 1 from inserted)) and (exists (select 1 from deleted)))
begin
insert into log(action) values('updated');
end
else if (exists (select 1 from inserted) and not exists (select 1 from deleted))
begin
insert into log(action) values('inserted');
end
else if (not exists (select 1 from inserted) and exists (select 1 from deleted))
begin
insert into log(action) values('deleted');
end
go
--test
insert into student values('king', 22, 1, 7);
update student set sex = 0 where name = 'king';
delete student where name = 'king';
select * from log;
select * from student order by id;

How to Map database table without id with grails domain

http://www.intelligrape.com/blog/2010/09/07/how-to-map-database-table-without-id-with-grails-domain/

How to Map database table without id with grails domain

Posted by Uday Pratap Singh

Recently I got a query regarding mapping a database table which do not have any id and version. For example the table have two varchar fields username and password nothing more than that.
Although it was something strange for me that table doesn’t have the id field. The good thing is that the username is a primary key in the table and this is not auto incremented user want to create it by his own method.

The good thing about grails is, in most of the cases you get your answer in the docs http://grails.org/doc/latest/ . So in this case we just need to change the id field in grails domain like this

class  Test {      String  username     String  password       static  mapping =  {          id name: 'username'          version false          id generator: 'assigned'      }      static  constraints =  {          username( nullable: true )      }  } 

and we are done How to Map database table without id with grails domain .
Hope it helps
## Uday Pratap Singh ##
uday@intelligrape.com

http://www.IntelliGrape.com/
http://in.linkedin.com/in/meudaypratap

Swift编程语言资料合集

在本周二凌晨召开的苹果年度开发者大会WWDC上,苹果公司推出了全新的编程语言Swift。Swift 基于C和Objective-C,是供iOS和OS X应用编程的全新语言,更加高效、现代、安全,可以提升应用性能,同时降低开发难度。

Swift编程语言资料合集

据称,Swift仍然处于beta测试的阶段,会在iOS 8发布的时一同推出市场,用来取代现有的Objective-C语言。Swift推出之后,苹果公司也不会停止对Objective-C的支持,开发工具会同时支持两种语言。

WWDC刚刚结束,在不到24小时的时间内,已经有开发者使用 Switf 编程语言完成了一款克隆 Flappy Bird 的小游戏,并开源在Github上。刚刚,2048游戏也来了:Github地址

目前,这个项目已经收获了3000多个称赞和800多个派生。

继Flappy Bird之后,越来越多的开源应用迅速的完成了向Swift语言的转换, 这里是Github上使用Swift语言的开源项目列表,目测已经有200多个了!

下面是我们收集的一些Swift编程语言的相关资料:

 

adb命令

1、adb forward tcp:6100 tcp:7100 // PC上所有6100端口通信数据将被重定向到手机端7100端口server上

2、adb forward tcp:6100 local:logd // PC上所有6100端口通信数据将被重定向到手机端UNIX类型socket上

为数据库重新生成log文件

1.新建一个同名的数据库

2.再停掉sql server(注意不要分离数据库)

3.用原数据库的数据文件覆盖掉这个新建的数据库

4.再重启sql server

5.此时打开企业管理器时会出现置疑,先不管,执行下面的语句(注意修改其中的数据库名)

USE MASTER
GO

SP_CONFIGURE ‘ALLOW UPDATES’,1 RECONFIGURE WITH OVERRIDE
GO

UPDATE SYSDATABASES SET STATUS =32768 WHERE NAME=’置疑的数据库名’
Go

sp_dboption ‘置疑的数据库名’, ‘single user’, ‘true’
Go

DBCC CHECKDB(‘置疑的数据库名’)
Go

update sysdatabases set status =28 where name=’置疑的数据库名’
Go

sp_configure ‘allow updates’, 0 reconfigure with override
Go

sp_dboption ‘置疑的数据库名’, ‘single user’, ‘false’
Go