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");

  • 相关阅读:
    【内存泄漏】方法三:利用linux的valgrind命令定位内存泄露(Memory Leak)
    【内存泄漏】方法二:利用linux的mtrace命令定位内存泄露(Memory Leak)
    Windows下sqlmap的使用_01
    关于安装和使用BurpSuite及Java环境的配置问题
    Windows下修改环境变量的几种方法
    OPPO VOOC快充原理
    在线代码运行
    Linux在线学习模拟器
    socket设置为非阻塞模式
    pthread_mutexattr_t设置的相关函数及其说明
  • 原文地址:https://www.cnblogs.com/xinhua327/p/1013747.html
Copyright © 2011-2022 走看看