简体   繁体   English

系统在C#中提供的工作流活动的GUID

[英]GUID for System provided workflow activities in C#

Is there a way to have a guid for system activities in re-hosted workflow designer? 在重新托管的工作流设计器中是否有办法指导系统活动?

I would like to have a GUID for each and every activity I create and also for the system provided (assign, for, switch, etc,). 我想为我创建的每个活动以及所提供的系统(分配,用于,切换等)提供一个GUID。

I have read that IAttachedPropertyStore is the way to go but none of the system provided activties implement these I think. 我读过IAttachedPropertyStore是要走的路,但是我所提供的活动都无法实现这些系统。 http://blogs.msdn.com/b/bursteg/archive/2009/05/18/xaml-in-net-4-0-attached-properties-iattachedpropertystore-and-attachablepropertyservices.aspx http://blogs.msdn.com/b/bursteg/archive/2009/05/18/xaml-in-net-4-0-attached-properties-iattachedpropertystore-and-attachablepropertyservices.aspx

Any suggestion or ideas is welcome. 欢迎任何建议或想法。 These guids are necessary to import these flows into other tools and be able to modify them. 这些指导是将这些流导入其他工具并能够对其进行修改所必需的。

Please do ask if any other information is required to answer this. 请问是否需要其他任何信息来回答此问题。

If all you need is a 1:1 map from Activity to Guid, consider just hashing the Assembly Qualified name. 如果您需要的只是从Activity到Guid的1:1映射,请考虑仅对Assembly Qualified名称进行哈希处理。 With such a small set of inputs, I would not guess you would get collisions in a 16 byte hash. 有了这么少的输入,我想不到您会在16字节的哈希中遇到冲突。

var targetAssemblies = new[] { typeof(Activity).Assembly };
var knownActivities = new Dictionary<Guid, Type>();
var baseType = typeof(Activity);
var sha1 = new SHA1CryptoServiceProvider();

foreach (var t in targetAssemblies.SelectMany(a => a.GetTypes()))
{
    if (t.IsPublic && !t.IsAbstract && baseType.IsAssignableFrom(t))
    {
        var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(t.AssemblyQualifiedName));

        // hash is 20 bytes long, we are truncating it to 16 to fit the guid
        var guidData = new byte[16];
        Buffer.BlockCopy(hash, 0, guidData, 0, 16);
        var typeGuid = new Guid(hash.Take(16).ToArray());

        if (knownActivities.ContainsKey(typeGuid))
        {
            throw new InvalidOperationException("Collision");
        }
        knownActivities.Add(typeGuid, t);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM