private void CreateUserTrackingLocations(XmlReader reader, UserTrackingLocationCollection user) { if (null == reader) throw new ArgumentNullException("reader"); if (null == user) throw new ArgumentNullException("user"); if (reader.IsEmptyElement) return; string startName = reader.Name; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (0 == string.Compare(reader.Name, "UserTrackingLocation", StringComparison.Ordinal)) { UserTrackingLocation location = new UserTrackingLocation(); CreateUserTrackingLocation(reader, location); user.Add(location); } break; case XmlNodeType.EndElement: if (0 == string.Compare(startName, reader.Name, StringComparison.Ordinal)) return; break; } } // // Only valid exit is on an EndElement that matches the element that is passed in. throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationCloseElementNotFound + startName + "."); }
private void WriteUserTrackingLocation(UserTrackingLocation loc, XmlTextWriter writer) { // // Validate this element's required fields if ((null == loc.ActivityType) && ((null == loc.ActivityTypeName) || (0 == loc.ActivityTypeName.Trim().Length))) throw new ArgumentException(ExecutionStringManager.MissingActivityType); if ((null == loc.ArgumentType) && ((null == loc.ArgumentTypeName) || (0 == loc.ArgumentTypeName.Trim().Length))) throw new ArgumentException(ExecutionStringManager.MissingArgumentType); writer.WriteStartElement("UserTrackingLocation"); // // Write the Acctivity node writer.WriteStartElement("Activity"); if (null != loc.ActivityType) writer.WriteElementString("Type", loc.ActivityType.AssemblyQualifiedName); else writer.WriteElementString("TypeName", loc.ActivityTypeName); writer.WriteElementString("MatchDerivedTypes", loc.MatchDerivedActivityTypes.ToString().ToLower(CultureInfo.InvariantCulture)); writer.WriteEndElement(); // // Write the key name node if it is non null if (null != loc.KeyName) writer.WriteElementString("KeyName", loc.KeyName); // // Write the Argument node writer.WriteStartElement("Argument"); if (null != loc.ArgumentType) writer.WriteElementString("Type", loc.ArgumentType.AssemblyQualifiedName); else writer.WriteElementString("TypeName", loc.ArgumentTypeName); writer.WriteElementString("MatchDerivedTypes", loc.MatchDerivedArgumentTypes.ToString().ToLower(CultureInfo.InvariantCulture)); writer.WriteEndElement(); if ((null != loc.Conditions) && (loc.Conditions.Count > 0)) WriteConditions(loc.Conditions, writer); writer.WriteEndElement(); }
private void CreateUserTrackingLocation(XmlReader reader, UserTrackingLocation location) { if (null == reader) throw new ArgumentNullException("reader"); if (null == location) throw new ArgumentNullException("location"); if (0 != string.Compare(reader.Name, "UserTrackingLocation", StringComparison.Ordinal)) throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationInvalidPosition + "UserTrackingLocation."); if (reader.IsEmptyElement) return; string name = null, type = null; bool derived = false, seenAct = false, seenArg = false; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (0 == string.Compare(reader.Name, "Activity", StringComparison.Ordinal)) seenAct = true; else if (0 == string.Compare(reader.Name, "KeyName", StringComparison.Ordinal)) location.KeyName = reader.ReadString(); else if (0 == string.Compare(reader.Name, "Argument", StringComparison.Ordinal)) seenArg = true; else if (0 == string.Compare(reader.Name, "TypeName", StringComparison.Ordinal)) name = reader.ReadString(); else if (0 == string.Compare(reader.Name, "Type", StringComparison.Ordinal)) type = reader.ReadString(); else if (0 == string.Compare(reader.Name, "MatchDerivedTypes", StringComparison.Ordinal)) derived = reader.ReadElementContentAsBoolean(); else if (0 == string.Compare(reader.Name, "Conditions", StringComparison.Ordinal)) CreateConditions(reader, location.Conditions); break; case XmlNodeType.EndElement: if (0 == string.Compare(reader.Name, "UserTrackingLocation", StringComparison.Ordinal)) { if (!seenAct) { location.ActivityType = typeof(Activity); location.MatchDerivedActivityTypes = true; } if (!seenArg) { location.ArgumentType = typeof(object); location.MatchDerivedArgumentTypes = true; } if ((null == location.ActivityType) && ((null == location.ActivityTypeName) || (0 == location.ActivityTypeName.Trim().Length)) && (null == location.ArgumentType) && ((null == location.ArgumentTypeName) || (0 == location.ArgumentTypeName.Trim().Length))) throw new TrackingProfileDeserializationException(ExecutionStringManager.MissingActivityType); return; } else if (0 == string.Compare(reader.Name, "Activity", StringComparison.Ordinal)) { if (!seenAct) { location.ActivityType = typeof(Activity); location.MatchDerivedActivityTypes = true; } else { if ((null != type) && (type.Trim().Length > 0)) location.ActivityType = Type.GetType(type, true); else location.ActivityTypeName = name; location.MatchDerivedActivityTypes = derived; } name = null; type = null; derived = false; } else if (0 == string.Compare(reader.Name, "Argument", StringComparison.Ordinal)) { if (!seenArg) { location.ArgumentType = typeof(object); location.MatchDerivedArgumentTypes = true; } else { if ((null != type) && (type.Trim().Length > 0)) location.ArgumentType = Type.GetType(type, true); else location.ArgumentTypeName = name; location.MatchDerivedArgumentTypes = derived; } name = null; type = null; derived = false; } break; } } // // Something bad happened throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationCloseElementNotFound + "UserTrackingLocation."); }
private void CreateUserTrackingLocations(XmlReader reader, UserTrackingLocationCollection user) { if (reader == null) { throw new ArgumentNullException("reader"); } if (user == null) { throw new ArgumentNullException("user"); } if (!reader.IsEmptyElement) { string name = reader.Name; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (string.Compare(reader.Name, "UserTrackingLocation", StringComparison.Ordinal) == 0) { UserTrackingLocation location = new UserTrackingLocation(); this.CreateUserTrackingLocation(reader, location); user.Add(location); } break; case XmlNodeType.EndElement: goto Label_006A; } continue; Label_006A: if (string.Compare(name, reader.Name, StringComparison.Ordinal) == 0) { return; } } throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationCloseElementNotFound + name + "."); } }
static TrackingProfile GetProfileWithUserTrackPoint() { TrackingProfile trackingProfile = new TrackingProfile(); trackingProfile.Version = new Version("1.0.0"); // 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); trackingProfile.UserTrackPoints.Add(userTrackPoint); return trackingProfile; }
private void CreateUserTrackingLocation(XmlReader reader, UserTrackingLocation location) { if (reader == null) { throw new ArgumentNullException("reader"); } if (location == null) { throw new ArgumentNullException("location"); } if (string.Compare(reader.Name, "UserTrackingLocation", StringComparison.Ordinal) != 0) { throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationInvalidPosition + "UserTrackingLocation."); } if (!reader.IsEmptyElement) { string str = null; string typeName = null; bool flag = false; bool flag2 = false; bool flag3 = false; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (string.Compare(reader.Name, "Activity", StringComparison.Ordinal) == 0) { flag2 = true; break; } if (string.Compare(reader.Name, "KeyName", StringComparison.Ordinal) == 0) { location.KeyName = reader.ReadString(); break; } if (string.Compare(reader.Name, "Argument", StringComparison.Ordinal) == 0) { flag3 = true; break; } if (string.Compare(reader.Name, "TypeName", StringComparison.Ordinal) == 0) { str = reader.ReadString(); break; } if (string.Compare(reader.Name, "Type", StringComparison.Ordinal) == 0) { typeName = reader.ReadString(); break; } if (string.Compare(reader.Name, "MatchDerivedTypes", StringComparison.Ordinal) == 0) { flag = reader.ReadElementContentAsBoolean(); } else if (string.Compare(reader.Name, "Conditions", StringComparison.Ordinal) == 0) { this.CreateConditions(reader, location.Conditions); } break; case XmlNodeType.EndElement: if (string.Compare(reader.Name, "UserTrackingLocation", StringComparison.Ordinal) != 0) { goto Label_01FD; } if (!flag2) { location.ActivityType = typeof(Activity); location.MatchDerivedActivityTypes = true; } if (!flag3) { location.ArgumentType = typeof(object); location.MatchDerivedArgumentTypes = true; } if (((null == location.ActivityType) && ((location.ActivityTypeName == null) || (location.ActivityTypeName.Trim().Length == 0))) && ((null == location.ArgumentType) && ((location.ArgumentTypeName == null) || (location.ArgumentTypeName.Trim().Length == 0)))) { throw new TrackingProfileDeserializationException(ExecutionStringManager.MissingActivityType); } return; } continue; Label_01FD: if (string.Compare(reader.Name, "Activity", StringComparison.Ordinal) == 0) { if (!flag2) { location.ActivityType = typeof(Activity); location.MatchDerivedActivityTypes = true; } else { if ((typeName != null) && (typeName.Trim().Length > 0)) { location.ActivityType = Type.GetType(typeName, true); } else { location.ActivityTypeName = str; } location.MatchDerivedActivityTypes = flag; } str = null; typeName = null; flag = false; } else if (string.Compare(reader.Name, "Argument", StringComparison.Ordinal) == 0) { if (!flag3) { location.ArgumentType = typeof(object); location.MatchDerivedArgumentTypes = true; } else { if ((typeName != null) && (typeName.Trim().Length > 0)) { location.ArgumentType = Type.GetType(typeName, true); } else { location.ArgumentTypeName = str; } location.MatchDerivedArgumentTypes = flag; } str = null; typeName = null; flag = false; } } throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationCloseElementNotFound + "UserTrackingLocation."); } }
private void WriteUserTrackingLocation(UserTrackingLocation loc, XmlTextWriter writer) { if ((null == loc.ActivityType) && ((loc.ActivityTypeName == null) || (loc.ActivityTypeName.Trim().Length == 0))) { throw new ArgumentException(ExecutionStringManager.MissingActivityType); } if ((null == loc.ArgumentType) && ((loc.ArgumentTypeName == null) || (loc.ArgumentTypeName.Trim().Length == 0))) { throw new ArgumentException(ExecutionStringManager.MissingArgumentType); } writer.WriteStartElement("UserTrackingLocation"); writer.WriteStartElement("Activity"); if (null != loc.ActivityType) { writer.WriteElementString("Type", loc.ActivityType.AssemblyQualifiedName); } else { writer.WriteElementString("TypeName", loc.ActivityTypeName); } writer.WriteElementString("MatchDerivedTypes", loc.MatchDerivedActivityTypes.ToString().ToLower(CultureInfo.InvariantCulture)); writer.WriteEndElement(); if (loc.KeyName != null) { writer.WriteElementString("KeyName", loc.KeyName); } writer.WriteStartElement("Argument"); if (null != loc.ArgumentType) { writer.WriteElementString("Type", loc.ArgumentType.AssemblyQualifiedName); } else { writer.WriteElementString("TypeName", loc.ArgumentTypeName); } writer.WriteElementString("MatchDerivedTypes", loc.MatchDerivedArgumentTypes.ToString().ToLower(CultureInfo.InvariantCulture)); writer.WriteEndElement(); if ((loc.Conditions != null) && (loc.Conditions.Count > 0)) { this.WriteConditions(loc.Conditions, writer); } writer.WriteEndElement(); }
// Profile creation private static TrackingProfile GetProfile() { // Create a Tracking Profile that covers all user track points. TrackingProfile profile = new TrackingProfile(); profile.Version = new Version("1.0.0"); // Add a TrackPoint to cover all user track points. // We want to receive user events generated by any Activity, with any argument type. // We could restrict the ActivityType to be PolicyActivity and // ArgumentType to be RuleActionTrackingEvent if we wanted to only get // tracking events from policy execution. 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; }
// 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 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); }