WWF的TrackingService?

今天随便看了一下,workflow的TrackingService.原来和WorkflowPersistenceService还是相似的。
首先作为一个服务将TrackingService添加到Runtime
workflowRuntime.AddService(new MyTrackingService());
你需要重写TrackingService的几个方法
protected override bool TryGetProfile(Type workflowType, out TrackingProfile profile)
        {
            profile = GetProfile();
            return true;
        }      

        protected override TrackingProfile GetProfile(Guid workflowInstanceId)
        {
            throw new NotImplementedException("The method or operation is not implemented.");
        }

        protected override TrackingProfile GetProfile(Type workflowType, Version profileVersionId)
        {
            return GetProfile();
        }

        protected override bool TryReloadProfile(Type workflowType, Guid workflowInstanceId, out TrackingProfile profile)
        {       
            profile = null;
            return false;
        }

        protected override TrackingChannel GetTrackingChannel(TrackingParameters parameters)
        {
            return new SimpleTrackingChannel(parameters);
        }

        #region Tracking Profile Creation

        // Reads a file containing an XML representation of a Tracking Profile
        private static TrackingProfile GetProfile()
        {
            FileStream fileStream = null;
            try
            {
                string trackingProfileFile = Environment.CurrentDirectory + "\\profile.xml";
                Console.WriteLine("trackingProfileFile is {0}", trackingProfileFile);
                if (File.Exists(trackingProfileFile))
                {
                    Console.WriteLine("Reading trackingProfile from {0}", trackingProfileFile);
                    fileStream = File.OpenRead(trackingProfileFile);
                    if (null == fileStream)
                    {
                        Console.WriteLine("fileStream is null");
                        return null;
                    }
                    StreamReader reader = new StreamReader(fileStream);
                    TrackingProfile profile;
                    TrackingProfileSerializer trackingProfileSerializer = new TrackingProfileSerializer();
                    profile = trackingProfileSerializer.Deserialize(reader);
                   
                    return profile;
                }
                else
                {
                    Console.WriteLine("trackingProfileFile {0} doesn't exist", trackingProfileFile);
                    return null;
                }
            }
            catch (TrackingProfileDeserializationException tpex)
            {
                Console.WriteLine("Encountered a deserialization exception.");
                foreach (ValidationEventArgs validationError in tpex.ValidationEventArgs)
                {
                    Console.WriteLine("Exception Message: {0}", validationError.Message);
                }
                return null;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Encountered an exception. Exception Source: {0}, Exception Message: {1}", ex.Source, ex.Message);
                return null;
            }
            finally
            {
                if (fileStream != null)
                    fileStream.Close();
            }
        }
在GetTrackingChannel方法中注册一个新的TrackingChannel
然后你可以重写
protected override void Send(TrackingRecord record)
protected override void InstanceCompletedOrTerminated()
实现你的功能。当然如果你想自己在活动中添加记录可以使用Activity.TrackData进行添加
关于SQLTrackingService的数据库脚本大家可以到下看到
C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\EN\Tracking_Schema.sql
C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\EN\Tracking_Logic.sql

posted on 2007-05-30 15:38  梁朝伟  阅读(307)  评论(0编辑  收藏  举报

导航