zoukankan      html  css  js  c++  java
  • 自定义用户跟踪 光阴的故事

            static void Main()
            {
                try
                {
                    // Create the tracking profile to track user track points
                    CreateAndInsertTrackingProfile();

                    using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
                    {
                        // Add the SQL tracking service to the run time
                        workflowRuntime.AddService(new SqlTrackingService(connectionString));

                        workflowRuntime.StartRuntime();

                        workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                        workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                        WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(typeof(SimpleWorkflow));
                        workflowInstance.Start();


                        Guid workflowInstanceId = workflowInstance.InstanceId;

                        // Wait for the workflow to complete
                        waitHandle.WaitOne();

                        workflowRuntime.StopRuntime();

                        // Get the tracking events from the database
                        GetUserTrackingEvents(workflowInstanceId);
                        Console.WriteLine("Done Running The workflow.");
                    }
                }

      private static void CreateAndInsertTrackingProfile()
            {
                TrackingProfile profile = new TrackingProfile();

                ActivityTrackPoint trackPoint = new ActivityTrackPoint();
                ActivityTrackingLocation location = new ActivityTrackingLocation(typeof(Activity));
                location.MatchDerivedTypes = true;

                IEnumerable<ActivityExecutionStatus> statuses = Enum.GetValues(typeof(ActivityExecutionStatus)) as IEnumerable<ActivityExecutionStatus>;
                foreach (ActivityExecutionStatus status in statuses)
                {
                    location.ExecutionStatusEvents.Add(status);
                }

                trackPoint.MatchingLocations.Add(location);
                profile.ActivityTrackPoints.Add(trackPoint);
                profile.Version = new Version("3.0.0.0");

               
                // Adding a user track point to the tracking profile
                UserTrackPoint utp = new UserTrackPoint();
               
                // Adding a user location to the track point
                UserTrackingLocation ul = new UserTrackingLocation(typeof(string), typeof(CodeActivity));
                ul.MatchDerivedActivityTypes = true;
                utp.MatchingLocations.Add(ul);
                profile.UserTrackPoints.Add(utp);
               
               
                // Serialize the profile
                TrackingProfileSerializer serializer = new TrackingProfileSerializer();
                StringWriter writer = new StringWriter(new StringBuilder(), CultureInfo.InvariantCulture);
                serializer.Serialize(writer, profile);
                string trackingprofile = writer.ToString();
                InsertTrackingProfile(trackingprofile);
            }

            private static void InsertTrackingProfile(string profile)
            {
                {
                    SqlCommand cmd = new SqlCommand();

                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "dbo.UpdateTrackingProfile";
                    cmd.Connection = new SqlConnection(connectionString);
                    try
                    {
                        cmd.Parameters.Clear();

                        SqlParameter param1 = new SqlParameter();
                        param1.ParameterName = "@TypeFullName";
                        param1.SqlDbType = SqlDbType.NVarChar;
                        param1.SqlValue = typeof(SimpleWorkflow).ToString();
                        cmd.Parameters.Add(param1);

                        SqlParameter param2 = new SqlParameter();
                        param2.ParameterName = "@AssemblyFullName";
                        param2.SqlDbType = SqlDbType.NVarChar;
                        param2.SqlValue = typeof(SimpleWorkflow).Assembly.FullName;
                        cmd.Parameters.Add(param2);


                        SqlParameter param3 = new SqlParameter();
                        param3.ParameterName = "@Version";
                        param3.SqlDbType = SqlDbType.VarChar;
                        param3.SqlValue = "3.0.0.0";
                        cmd.Parameters.Add(param3);

                        SqlParameter param4 = new SqlParameter();
                        param4.ParameterName = "@TrackingProfileXml";
                        param4.SqlDbType = SqlDbType.NText;
                        param4.SqlValue = profile;
                        cmd.Parameters.Add(param4);

                        cmd.Connection.Open();
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("The Tracking Profile Was not Inserted. If You want to add a new one then please increase the version Number\n");
                    }
                    finally
                    {
                        if ((null != cmd) && (null != cmd.Connection) && (ConnectionState.Closed != cmd.Connection.State))
                            cmd.Connection.Close();
                    }
                }
            }



            private static void GetUserTrackingEvents(Guid workflowInstanceId)
            {
                SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(connectionString);

                SqlTrackingWorkflowInstance sqlTrackingWorkflowInstance;
                if (sqlTrackingQuery.TryGetWorkflow(workflowInstanceId, out sqlTrackingWorkflowInstance))
                {
                    foreach (UserTrackingRecord userTrackingRecord in sqlTrackingWorkflowInstance.UserEvents)
                    {
                        Console.WriteLine("\nUser Tracking Event : Event Date Time : {0}, Event Data : {1}\n", userTrackingRecord.EventDateTime.ToString(), userTrackingRecord.UserData.ToString());
                    }
                }
                else
                {
                    throw new Exception("\nFailed to retrieve workflow instance\n");
                }
            }

    //使用 
    this.TrackData("Tracking the execution of the code activity");

  • 相关阅读:
    Salesforce LWC学习(三十七) Promise解决progressindicator的小问题
    Salesforce Consumer Goods Cloud 浅谈篇三之 行动计划(Action Plan)相关配置
    python 3.7环境安装并使用csv
    分享数据库优化文章
    php 5.4 var_export的改进
    CentOS7 启动 firewalld 防火墙失败,查看日志提示超时
    使用 SSL 加密的 JDBC 连接 SAP HANA 数据库
    CAS学习笔记一:CAS 授权服务器简易搭建
    202110期自考总结
    自定义 OpenShift s2i 镜像与模板——OracleJDK8
  • 原文地址:https://www.cnblogs.com/xinhua327/p/1013747.html
Copyright © 2011-2022 走看看