Beispiel #1
0
        internal static void CreateAndInsertTrackingProfile()
        {
            TrackingProfile profile = new TrackingProfile();

            ActivityTrackPoint activityTrack = new ActivityTrackPoint();
            ActivityTrackingLocation activityLocation = new ActivityTrackingLocation(typeof(Activity));
            activityLocation.MatchDerivedTypes = true;
            IEnumerable<ActivityExecutionStatus> statuses = Enum.GetValues(typeof(ActivityExecutionStatus)) as IEnumerable<ActivityExecutionStatus>;
            foreach (ActivityExecutionStatus status in statuses)
            {
                activityLocation.ExecutionStatusEvents.Add(status);
            }

            activityTrack.MatchingLocations.Add(activityLocation);
            profile.ActivityTrackPoints.Add(activityTrack);
            profile.Version = version;

            WorkflowTrackPoint workflowTrack = new WorkflowTrackPoint();
            WorkflowTrackingLocation workflowLocation = new WorkflowTrackingLocation();
            IEnumerable<TrackingWorkflowEvent> eventStatuses = Enum.GetValues(typeof(TrackingWorkflowEvent)) as IEnumerable<TrackingWorkflowEvent>;
            foreach (TrackingWorkflowEvent status in eventStatuses)
            {
                workflowLocation.Events.Add(status);
            }

            workflowTrack.MatchingLocation = workflowLocation;
            profile.WorkflowTrackPoints.Add(workflowTrack);

            TrackingProfileSerializer serializer = new TrackingProfileSerializer();
            StringWriter writer = new StringWriter(new StringBuilder(), CultureInfo.InvariantCulture);
            serializer.Serialize(writer, profile);
            String trackingprofile = writer.ToString();
            InsertTrackingProfile(trackingprofile);
        }
Beispiel #2
0
        private static Version GetTrackingProfileVersion(Version version)
        {
            TrackingProfile profile = null;
            SqlDataReader reader = null;
            using (SqlCommand command = new SqlCommand())
            {
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "dbo.GetTrackingProfile";
                command.Connection = new SqlConnection(connectionString);
                SqlParameter typeFullName = new SqlParameter();
                typeFullName.ParameterName = "@TypeFullName";
                typeFullName.SqlDbType = SqlDbType.NVarChar;
                typeFullName.SqlValue = typeof(SimpleWorkflow).FullName;
                command.Parameters.Add(typeFullName);

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

                SqlParameter versionId = new SqlParameter();
                versionId.ParameterName = "@Version";
                versionId.SqlDbType = SqlDbType.VarChar;
                command.Parameters.Add(versionId);

                SqlParameter createDefault = new SqlParameter();
                createDefault.ParameterName = "@CreateDefault";
                createDefault.SqlDbType = SqlDbType.Bit;
                createDefault.SqlValue = 0;
                command.Parameters.Add(createDefault);

                command.Connection.Open();
                reader = command.ExecuteReader();
                if (reader.Read())
                {
                    string profileXml = reader[0] as string;
                    if (null != profileXml)
                    {
                        TrackingProfileSerializer serializer = new TrackingProfileSerializer();
                        StringReader stringReader = null;
                        try
                        {
                            stringReader = new StringReader(profileXml);
                            profile = serializer.Deserialize(stringReader);
                        }
                        finally
                        {
                            if (stringReader != null)
                                stringReader.Close();
                        }
                    }
                }
            }
            if (profile != null)
                return new Version(profile.Version.Major, profile.Version.MajorRevision, profile.Version.Minor, profile.Version.MinorRevision + 1);
            else
                return new Version(version.Major, version.MajorRevision, version.Minor, version.MinorRevision + 1);
        }
Beispiel #3
0
 /// <summary>
 /// Read profile from path
 /// </summary>
 /// <param name="path"></param>
 public void ReadProfile(string path)
 {
     using (StreamReader reader = new StreamReader(path))
     {
         TrackingProfileSerializer serializer = new TrackingProfileSerializer();
         TrackingProfile = serializer.Deserialize(reader);
     }
 }
Beispiel #4
0
        static void SerializeTrackingProfileAndWriteToConsole(TrackingProfile trackingProfile)
        {
            TrackingProfileSerializer trackingProfileSerializer = new TrackingProfileSerializer();
            StringBuilder             trackingProfileString     = new StringBuilder();

            using (StringWriter writer = new StringWriter(trackingProfileString, CultureInfo.InvariantCulture))
            {
                trackingProfileSerializer.Serialize(writer, trackingProfile);
                Console.WriteLine(writer.ToString());
            }
        }
        /// <summary>
        /// Primary constructor
        /// </summary>
        /// <param name="root"></param>
        /// <param name="workflowType"></param>
        /// <param name="profile"></param>
        internal RTTrackingProfile(TrackingProfile profile, Activity root, Type serviceType)
        {
            if (null == profile)
            {
                throw new ArgumentNullException("profile");
            }
            if (null == root)
            {
                throw new ArgumentNullException("root");
            }
            if (null == serviceType)
            {
                throw new ArgumentNullException("serviceType");
            }

            _workflowType = root.GetType();
            _serviceType  = serviceType;
            //
            // "Clone" a private copy in case the tracking service holds a reference to
            // the profile it gave us and attempts to modify it at a later point
            TrackingProfileSerializer tps = new TrackingProfileSerializer();

            StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
            StringReader reader = null;

            TrackingProfile privateProfile = null;

            try
            {
                //
                // Let exceptions bubble back to the tracking service -
                // the profile must be valid per the schema.
                tps.Serialize(writer, profile);
                reader         = new StringReader(writer.ToString());
                privateProfile = tps.Deserialize(reader);
            }
            finally
            {
                if (null != reader)
                {
                    reader.Close();
                }

                if (null != writer)
                {
                    writer.Close();
                }
            }
            _profile = privateProfile;

            CheckAllActivities((Activity)root);
        }
Beispiel #6
0
        /// <summary>
        /// Retrieve the tracking profile for the workflow type
        /// </summary>
        /// <param name="workflowType"></param>
        /// <returns></returns>
        public TrackingProfile RetrieveProfile(Type workflowType)
        {
            TrackingProfile profile = null;

            try
            {
                String profileXml = null;
                using (SqlConnection conn
                           = new SqlConnection(_connectionString))
                {
                    SqlCommand command = new SqlCommand(
                        "GetTrackingProfile", conn);
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add(new SqlParameter(
                                               "@TypeFullName", workflowType.FullName));
                    command.Parameters.Add(new SqlParameter(
                                               "@AssemblyFullName", workflowType.Assembly.FullName));
                    command.Parameters.Add(new SqlParameter(
                                               "@Version", null));
                    command.Parameters.Add(new SqlParameter(
                                               "@CreateDefault", true));

                    command.Connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            profileXml = reader["TrackingProfile"] as String;
                        }
                        reader.Close();
                    }
                }

                if (profileXml != null)
                {
                    TrackingProfileSerializer serializer
                        = new TrackingProfileSerializer();
                    using (StringReader reader = new StringReader(profileXml))
                    {
                        profile = serializer.Deserialize(reader);
                    }
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(
                    "SqlException in RetrieveProfile: {0}", e.Message);
                throw;
            }

            return(profile);
        }
Beispiel #7
0
        // 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();
                }
            }
        }
Beispiel #8
0
        private static void CreateAndInsertTrackingProfile()
        {
            TrackingProfile profile = new TrackingProfile();

            // Create an activity track point, used for tracking data from Code Activities.
            ActivityTrackPoint codeActivityTrackPoint = new ActivityTrackPoint();

            // Create an ActivityTrackingLocation to be added to the track point.
            ActivityTrackingLocation codeActivityTrackingLocation = new ActivityTrackingLocation("CodeActivity");

            codeActivityTrackingLocation.MatchDerivedTypes = true;
            // Add the location "Closed" event to track.
            codeActivityTrackingLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Closed);
            codeActivityTrackPoint.MatchingLocations.Add(codeActivityTrackingLocation);

            // Create a WorkflowDataTrackingExtract for extracting data from the Balance property.
            WorkflowDataTrackingExtract balanceWorkflowTrackingExtract = new WorkflowDataTrackingExtract();

            balanceWorkflowTrackingExtract.Member = "Balance";

            // Create an activity track point, used for tracking data in the custom activity "ServiceCharge".
            ActivityTrackPoint       customActivityTrackPoint       = new ActivityTrackPoint();
            ActivityTrackingLocation customActivityTrackingLocation = new ActivityTrackingLocation("ServiceCharge");

            // Create an ActivityTrackingLocation to be added to the track point
            customActivityTrackingLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Closed);
            customActivityTrackPoint.MatchingLocations.Add(customActivityTrackingLocation);

            // Create an ActivityDataTrackingExtract for extracting Fee property data from the ServiceCharge activity.
            ActivityDataTrackingExtract feeActivityTrackingExtract = new ActivityDataTrackingExtract();

            feeActivityTrackingExtract.Member = "Fee";

            // Add extracts to the activity tracking points.
            codeActivityTrackPoint.Extracts.Add(balanceWorkflowTrackingExtract);
            customActivityTrackPoint.Extracts.Add(feeActivityTrackingExtract);

            profile.ActivityTrackPoints.Add(codeActivityTrackPoint);
            profile.ActivityTrackPoints.Add(customActivityTrackPoint);
            profile.Version = new Version("3.0.0.0");

            // 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);
        }
        internal RTTrackingProfile(TrackingProfile profile, Activity root, Type serviceType)
        {
            this._activities       = new Dictionary <string, List <ActivityTrackPointCacheItem> >();
            this._activitiesIgnore = new List <string>();
            this._user             = new Dictionary <string, List <UserTrackPoint> >();
            this._userIgnore       = new List <string>();
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }
            if (null == serviceType)
            {
                throw new ArgumentNullException("serviceType");
            }
            this._workflowType = root.GetType();
            this._serviceType  = serviceType;
            TrackingProfileSerializer serializer = new TrackingProfileSerializer();
            StringWriter    writer   = new StringWriter(CultureInfo.InvariantCulture);
            StringReader    reader   = null;
            TrackingProfile profile2 = null;

            try
            {
                serializer.Serialize(writer, profile);
                reader   = new StringReader(writer.ToString());
                profile2 = serializer.Deserialize(reader);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
            this._profile = profile2;
            this.CheckAllActivities(root);
        }
Beispiel #10
0
        private void CreateAndInsertTrackingProfile()
        {
            TrackingProfile          profile    = new TrackingProfile();
            ActivityTrackPoint       trackPoint = new ActivityTrackPoint();
            ActivityTrackingLocation location   = new ActivityTrackingLocation(typeof(Activity));

            // Specify tracking locations
            location.MatchDerivedTypes = true;

            foreach (ActivityExecutionStatus status in Enum.GetValues(typeof(ActivityExecutionStatus)))
            {
                location.ExecutionStatusEvents.Add(status);
            }

            trackPoint.MatchingLocations.Add(location);

            // Specify workflow properties to track
            WorkflowDataTrackingExtract dataExtract = new WorkflowDataTrackingExtract();

            dataExtract.Member = "UserId";
            trackPoint.Extracts.Add(dataExtract);

            dataExtract        = new WorkflowDataTrackingExtract();
            dataExtract.Member = "SessionId";
            trackPoint.Extracts.Add(dataExtract);

            dataExtract        = new WorkflowDataTrackingExtract();
            dataExtract.Member = "RegistrationStatus";
            trackPoint.Extracts.Add(dataExtract);

            // Update profile
            profile.ActivityTrackPoints.Add(trackPoint);
            profile.Version = new Version("3.0.0.1");

            // 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);
        }
Beispiel #11
0
        /// <summary>
        /// Update a tracking profile
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="workflowType"></param>
        public void UpdateProfile(TrackingProfile profile, Type workflowType)
        {
            try
            {
                String profileXml = null;
                TrackingProfileSerializer serializer
                    = new TrackingProfileSerializer();
                using (StringWriter writer = new StringWriter(new StringBuilder()))
                {
                    serializer.Serialize(writer, profile);
                    profileXml = writer.ToString();
                }

                if (profileXml != null)
                {
                    using (SqlConnection conn
                               = new SqlConnection(_connectionString))
                    {
                        SqlCommand command = new SqlCommand(
                            "UpdateTrackingProfile", conn);
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.Add(new SqlParameter(
                                                   "@TypeFullName", workflowType.FullName));
                        command.Parameters.Add(new SqlParameter(
                                                   "@AssemblyFullName", workflowType.Assembly.FullName));
                        command.Parameters.Add(new SqlParameter(
                                                   "@Version", profile.Version.ToString()));
                        command.Parameters.Add(new SqlParameter(
                                                   "@TrackingProfileXml", profileXml));

                        command.Connection.Open();
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(
                    "SqlException in UpdateProfile: {0}", e.Message);
                throw;
            }
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
        static void DeserializeTrackingProfileString()
        {
            string workflowTerminatedTrackingProfile            = @"<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>
<TrackingProfile xmlns=""http://schemas.microsoft.com/winfx/2006/workflow/trackingprofile"" version=""2.0.0"">
    <TrackPoints>
        <WorkflowTrackPoint>
            <MatchingLocation>
                <WorkflowTrackingLocation>
                    <TrackingWorkflowEvents>
                        <TrackingWorkflowEvent>Terminated</TrackingWorkflowEvent>
                    </TrackingWorkflowEvents>
                </WorkflowTrackingLocation>
            </MatchingLocation>
        </WorkflowTrackPoint>
    </TrackPoints>
</TrackingProfile>";
            TrackingProfileSerializer trackingProfileSerializer = new TrackingProfileSerializer();

            using (StringReader stringReader = new StringReader(workflowTerminatedTrackingProfile))
            {
                TrackingProfile trackingProfile = trackingProfileSerializer.Deserialize(stringReader);
                Console.WriteLine("Tracking Profile Version " + trackingProfile.Version);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Retrieves a profile from the SQL Tracking Database
        /// </summary>
        /// <param name="workflowType">The workflow type to retrieve the profile for</param>
        /// /// <param name="version">The version of the workflow to retrieve.  If null, the version is ignored.</param>
        /// <param name="createDefault">When true, creates a default tracking profile if no profile currently exists</param>
        /// <returns></returns>
        private TrackingProfile GetWorkflowProfile(Type workflowType, Version version, bool createDefault)
        {
            SqlDataReader   reader  = null;
            TrackingProfile profile = null;

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    using (SqlCommand command = new SqlCommand())
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.CommandText = "[dbo].[GetTrackingProfile]";
                        command.Connection  = connection;

                        SqlParameter typeFullName           = new SqlParameter("@TypeFullName", workflowType.FullName);
                        SqlParameter assemblyFullName       = new SqlParameter("@AssemblyFullName", workflowType.Assembly.FullName);
                        SqlParameter createDefaultParameter = new SqlParameter("@CreateDefault", createDefault ? 1 : 0);

                        command.Parameters.Add(typeFullName);
                        command.Parameters.Add(assemblyFullName);
                        command.Parameters.Add(createDefaultParameter);

                        //Filter by version as well, if specified
                        if (version != null)
                        {
                            SqlParameter versionParameter = new SqlParameter("@Version", version.ToString());
                            command.Parameters.Add(versionParameter);
                        }

                        connection.Open();
                        reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        if (reader.Read())
                        {
                            if (reader.IsDBNull(0))
                            {
                                return(null);
                            }

                            string tmp = reader.GetString(0);
                            TrackingProfileSerializer serializer = new TrackingProfileSerializer();
                            StringReader pReader = null;

                            try
                            {
                                pReader = new StringReader(tmp);
                                profile = serializer.Deserialize(pReader);
                            }
                            finally
                            {
                                if (null != pReader)
                                {
                                    pReader.Close();
                                }
                            }
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(string.Format("Error retrieving profile: {0}", ex.Message), "Error");
            }
            return(profile);
        }
Beispiel #15
0
        /// <summary>
        /// Serialize the profile to a text writer
        /// </summary>
        /// <param name="writer"></param>
        public void SerializeProfile(TextWriter writer)
        {
            TrackingProfileSerializer serializer = new TrackingProfileSerializer();

            serializer.Serialize(writer, TrackingProfile);
        }