Exemple #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);
        }
        private void CreateWorkflowTrackPoint(XmlReader reader, TrackingProfile profile)
        {
            if (null == reader)
                throw new ArgumentNullException("reader");

            if (null == profile)
                throw new ArgumentNullException("profile");

            if (0 != string.Compare(reader.Name, "WorkflowTrackPoint", StringComparison.Ordinal))
                throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationInvalidPosition + "WorkflowTrackPoint.");

            if (reader.IsEmptyElement)
                return;

            WorkflowTrackPoint point = new WorkflowTrackPoint();
            point.MatchingLocation = new WorkflowTrackingLocation();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (0 == string.Compare(reader.Name, "Annotations", StringComparison.Ordinal))
                            CreateAnnotations(reader, point.Annotations);
                        else if (0 == string.Compare(reader.Name, "TrackingWorkflowEvent", StringComparison.Ordinal))
                            point.MatchingLocation.Events.Add((TrackingWorkflowEvent)Enum.Parse(typeof(TrackingWorkflowEvent), reader.ReadString()));
                        //
                        // Xsd validation will catch unknown elements
                        break;
                    case XmlNodeType.EndElement:
                        if (0 == string.Compare(reader.Name, "WorkflowTrackPoint", StringComparison.Ordinal))
                        {
                            profile.WorkflowTrackPoints.Add(point);
                            return;
                        }
                        break;
                }
            }
            //
            // Only valid exit is on an EndElement that matches the element that is passed in.
            throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationCloseElementNotFound + "WorkflowTrackPoint.");
        }
        private void WriteWorkflowTrackPoint(WorkflowTrackPoint point, XmlTextWriter writer)
        {
            //
            // Validate this element's required fields
            if (null == point.MatchingLocation)
                throw new ArgumentException(ExecutionStringManager.NoMatchingLocation);

            writer.WriteStartElement("WorkflowTrackPoint");

            WriteWorkflowTrackingLocation(point.MatchingLocation, writer);
            //
            // Write annotations, not a required field
            WriteAnnotations(point.Annotations, writer);

            writer.WriteEndElement();
        }
Exemple #4
0
        static TrackingProfile GetProfileAllWorkflowEvents()
        {
            TrackingProfile trackingProfile = new TrackingProfile();
            trackingProfile.Version = new Version("1.0.0");

            // Add a TrackPoint to cover all user track points
            WorkflowTrackPoint workflowTrackPoint = new WorkflowTrackPoint();
            IEnumerable<TrackingWorkflowEvent> statuses = Enum.GetValues(typeof(TrackingWorkflowEvent)) as IEnumerable<TrackingWorkflowEvent>;
            foreach (TrackingWorkflowEvent status in statuses)
            {
                workflowTrackPoint.MatchingLocation.Events.Add(status);
            }
            trackingProfile.WorkflowTrackPoints.Add(workflowTrackPoint);

            return trackingProfile;
        }
        private void CreateWorkflowTrackPoint(XmlReader reader, TrackingProfile profile)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }
            if (string.Compare(reader.Name, "WorkflowTrackPoint", StringComparison.Ordinal) != 0)
            {
                throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationInvalidPosition + "WorkflowTrackPoint.");
            }
            if (!reader.IsEmptyElement)
            {
                WorkflowTrackPoint item = new WorkflowTrackPoint {
                    MatchingLocation = new WorkflowTrackingLocation()
                };
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (string.Compare(reader.Name, "Annotations", StringComparison.Ordinal) == 0)
                            {
                                this.CreateAnnotations(reader, item.Annotations);
                            }
                            else if (string.Compare(reader.Name, "TrackingWorkflowEvent", StringComparison.Ordinal) == 0)
                            {
                                item.MatchingLocation.Events.Add((TrackingWorkflowEvent) Enum.Parse(typeof(TrackingWorkflowEvent), reader.ReadString()));
                            }
                            break;

                        case XmlNodeType.EndElement:
                            goto Label_00D9;
                    }
                    continue;
                Label_00D9:
                    if (string.Compare(reader.Name, "WorkflowTrackPoint", StringComparison.Ordinal) == 0)
                    {
                        profile.WorkflowTrackPoints.Add(item);
                        return;
                    }
                }
                throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationCloseElementNotFound + "WorkflowTrackPoint.");
            }
        }
 private void WriteWorkflowTrackPoint(WorkflowTrackPoint point, XmlTextWriter writer)
 {
     if (point.MatchingLocation == null)
     {
         throw new ArgumentException(ExecutionStringManager.NoMatchingLocation);
     }
     writer.WriteStartElement("WorkflowTrackPoint");
     this.WriteWorkflowTrackingLocation(point.MatchingLocation, writer);
     this.WriteAnnotations(point.Annotations, writer);
     writer.WriteEndElement();
 }
        // Profile creation
        private static TrackingProfile GetProfile()
        {
            // Create a Tracking Profile
            TrackingProfile profile = new TrackingProfile();
            profile.Version = new Version("3.0.0");

            // Add a TrackPoint to cover all activity status events
            ActivityTrackPoint activityTrackPoint = new ActivityTrackPoint();
            ActivityTrackingLocation activityLocation = new ActivityTrackingLocation(typeof(Activity));
            activityLocation.MatchDerivedTypes = true;
            WorkflowTrackingLocation wLocation = new WorkflowTrackingLocation();

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

            activityTrackPoint.MatchingLocations.Add(activityLocation);
            profile.ActivityTrackPoints.Add(activityTrackPoint);

            // Add a TrackPoint to cover all workflow status events
            WorkflowTrackPoint workflowTrackPoint = new WorkflowTrackPoint();
            workflowTrackPoint.MatchingLocation = new WorkflowTrackingLocation();
            foreach (TrackingWorkflowEvent workflowEvent in Enum.GetValues(typeof(TrackingWorkflowEvent)))
            {
                workflowTrackPoint.MatchingLocation.Events.Add(workflowEvent);
            }
            profile.WorkflowTrackPoints.Add(workflowTrackPoint);
            
            // Add a TrackPoint to cover all user track points
            UserTrackPoint userTrackPoint = new UserTrackPoint();
            UserTrackingLocation userLocation = new UserTrackingLocation();
            userLocation.ActivityType = typeof(Activity);
            userLocation.MatchDerivedActivityTypes = true;
            userLocation.ArgumentType = typeof(object);
            userLocation.MatchDerivedArgumentTypes = true;
            userTrackPoint.MatchingLocations.Add(userLocation);
            profile.UserTrackPoints.Add(userTrackPoint);

            return profile;
        }
        private TrackingProfile GetProfile()
        {
            //
            // We shouldn't hit this point without the host ignoring an earlier exception.
            // However if we're here and the source doesn't exist we can't function.
            // Throwing an exception from here will block instance creation
            // but that is better than failing silently on termination 
            // and having the admin think everything is OK because the event log is clear.
            if (!sourceExists)
                throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "EventLog Source with the name '{0}' does not exist", source));

            //
            // The profile for this instance will never change
            if (null == profile)
            {
                lock (typeof(TerminationTrackingService))
                {
                    if (null == profile)
                    {
                        profile = new TrackingProfile();
                        profile.Version = new Version("3.0.0.0");
                        WorkflowTrackPoint point = new WorkflowTrackPoint();
                        point.MatchingLocation = new WorkflowTrackingLocation();
                        point.MatchingLocation.Events.Add(TrackingWorkflowEvent.Terminated);
                        profile.WorkflowTrackPoints.Add(point);
                    }
                }
            }
            return profile;
        }