diff --git a/..svnbridge/Granfeldt.FIM.ActivityLibrary.v11.suo b/..svnbridge/Granfeldt.FIM.ActivityLibrary.v11.suo new file mode 100644 index 0000000..81efb3c --- /dev/null +++ b/..svnbridge/Granfeldt.FIM.ActivityLibrary.v11.suo @@ -0,0 +1 @@ +svn:mime-typeapplication/octet-stream \ No newline at end of file diff --git a/..svnbridge/Granfeldt.FIM.ActivityLibrary.v12.suo b/..svnbridge/Granfeldt.FIM.ActivityLibrary.v12.suo new file mode 100644 index 0000000..81efb3c --- /dev/null +++ b/..svnbridge/Granfeldt.FIM.ActivityLibrary.v12.suo @@ -0,0 +1 @@ +svn:mime-typeapplication/octet-stream \ No newline at end of file diff --git a/.vs/Granfeldt.FIM.ActivityLibrary/v14/..svnbridge/.suo b/.vs/Granfeldt.FIM.ActivityLibrary/v14/..svnbridge/.suo new file mode 100644 index 0000000..81efb3c --- /dev/null +++ b/.vs/Granfeldt.FIM.ActivityLibrary/v14/..svnbridge/.suo @@ -0,0 +1 @@ +svn:mime-typeapplication/octet-stream \ No newline at end of file diff --git a/.vs/Granfeldt.FIM.ActivityLibrary/v14/.suo b/.vs/Granfeldt.FIM.ActivityLibrary/v14/.suo new file mode 100644 index 0000000..53b64d8 Binary files /dev/null and b/.vs/Granfeldt.FIM.ActivityLibrary/v14/.suo differ diff --git a/Granfeldt.FIM.ActivityLibrary.v11.suo b/Granfeldt.FIM.ActivityLibrary.v11.suo new file mode 100644 index 0000000..d7a02e3 Binary files /dev/null and b/Granfeldt.FIM.ActivityLibrary.v11.suo differ diff --git a/Granfeldt.FIM.ActivityLibrary.v12.suo b/Granfeldt.FIM.ActivityLibrary.v12.suo new file mode 100644 index 0000000..2545fa7 Binary files /dev/null and b/Granfeldt.FIM.ActivityLibrary.v12.suo differ diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/BackReferenceUpdateMemberActivity.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/BackReferenceUpdateMemberActivity.cs new file mode 100644 index 0000000..ee814dc --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/BackReferenceUpdateMemberActivity.cs @@ -0,0 +1,197 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Linq; +using System.Workflow.Activities; +using System.Workflow.Activities.Rules; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Compiler; +using System.Workflow.ComponentModel.Design; +using System.Workflow.ComponentModel.Serialization; +using System.Workflow.Runtime; +using Microsoft.ResourceManagement.WebServices.WSResourceManagement; +using Microsoft.ResourceManagement.Workflow.Activities; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class BackReferenceUpdateMemberActivity : SequenceActivity + { + public BackReferenceUpdateMemberActivity() + { + InitializeComponent(); + } + + public static DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(BackReferenceUpdateMemberActivity)); + + [Description("Title")] + [Category("Title Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string Title + { + get + { + return ((string)(base.GetValue(BackReferenceUpdateMemberActivity.TitleProperty))); + } + set + { + base.SetValue(BackReferenceUpdateMemberActivity.TitleProperty, value); + } + } + + public static DependencyProperty ActionProperty = DependencyProperty.Register("Action", typeof(string), typeof(BackReferenceUpdateMemberActivity)); + [Description("Action")] + [Category("Action Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string Action + { + get + { + return ((string)(base.GetValue(BackReferenceUpdateMemberActivity.ActionProperty))); + } + set + { + base.SetValue(BackReferenceUpdateMemberActivity.ActionProperty, value); + } + } + + public static DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(string), typeof(BackReferenceUpdateMemberActivity)); + [Description("Source")] + [Category("Source Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string Source + { + get + { + return ((string)(base.GetValue(BackReferenceUpdateMemberActivity.SourceProperty))); + } + set + { + base.SetValue(BackReferenceUpdateMemberActivity.SourceProperty, value); + } + } + + public static DependencyProperty DestinationProperty = DependencyProperty.Register("Destination", typeof(string), typeof(BackReferenceUpdateMemberActivity)); + [Description("Destination")] + [Category("Destination Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string Destination + { + get + { + return ((string)(base.GetValue(BackReferenceUpdateMemberActivity.DestinationProperty))); + } + set + { + base.SetValue(BackReferenceUpdateMemberActivity.DestinationProperty, value); + } + } + + public List GroupToUpdate = null; + public Guid CurrentGroupToUpdate; + + private void ForEveryAdd_Condition(object sender, ConditionalEventArgs e) + { + Debugging.Log("Enter::ForEveryAdd_Condition"); + // if not initialized, then initialize and load value into List + if (GroupToUpdate == null) + { + GroupToUpdate = new List(this.GetReferenceUpdates.AddedReferences); + } + + Debugging.Log(string.Format("Count: {0}", GroupToUpdate.Count)); + if (GroupToUpdate.Count > 0) + { + // removed processed item + CurrentGroupToUpdate = GroupToUpdate[0]; + GroupToUpdate.RemoveAt(0); + e.Result = true; + } + else + { + // no more items to process + e.Result = false; + } + Debugging.Log("Exit::ForEveryAdd_Condition"); + } + + private void PrepareGroupOperation_ExecuteCode(object sender, EventArgs e) + { + Debugging.Log("Enter::PrepareGroupOperation_ExecuteCode"); + try + { + // since we're in a while loop, we have to grab the instantiated workflow activity UpdateResourceActivity + SequenceActivity currentParentSequenceActivity = (SequenceActivity)((CodeActivity)sender).Parent; + + UpdateReferenceAttributesAsNeededActivity currentUpdateResourceActivity = currentParentSequenceActivity.Activities.OfType().First(); + + SequentialWorkflow containingWorkflow = null; + if (!SequentialWorkflow.TryGetContainingWorkflow(this, out containingWorkflow)) + { + throw new InvalidOperationException("Could not get parent workflow!"); + } + + Debugging.Log(string.Format("Resource Id: {0}", CurrentGroupToUpdate)); + currentUpdateResourceActivity.ActorId = WellKnownGuids.BuiltInSynchronizationAccount; + currentUpdateResourceActivity.ResourceId = CurrentGroupToUpdate; + currentUpdateResourceActivity.AttributeName = this.Destination; + if (this.Action.ToLower() == "add") + { + Debugging.Log(string.Format("Add member: {0}", this.GetReferenceUpdates.ResourceId.ToString())); + currentUpdateResourceActivity.UpdateMode = UpdateMode.Insert; + } + else + { + Debugging.Log(string.Format("Remove member: {0}", this.GetReferenceUpdates.ResourceId.ToString())); + currentUpdateResourceActivity.UpdateMode = UpdateMode.Remove; + } + currentUpdateResourceActivity.Values = new Guid[] { this.GetReferenceUpdates.ResourceId }; + } + catch (Exception ex) + { + Debugging.Log(string.Format("Error: {0}", ex.Message)); + } + Debugging.Log("Exit::PrepareGroupOperation_ExecuteCode"); + } + + private void SetupClearMV_ExecuteCode(object sender, EventArgs e) + { + Debugging.Log("Enter::SetupClearMV_ExecuteCode"); + try + { + SequentialWorkflow containingWorkflow = null; + if (!SequentialWorkflow.TryGetContainingWorkflow(this, out containingWorkflow)) + { + throw new InvalidOperationException("Could not get parent workflow!"); + } + ClearMVOnResource.ActorId = WellKnownGuids.BuiltInSynchronizationAccount; + ClearMVOnResource.ResourceId = containingWorkflow.TargetId; + int numOfElements = this.GetReferenceUpdates.AddedReferences.ToList().Count; + Debugging.Log(string.Format("List count: {0}", this.GetReferenceUpdates.AddedReferences.ToList().Count)); + Debugging.Log(string.Format("Remove elements: {0}", numOfElements)); + + List ps = new List(); + foreach (Guid value in this.GetReferenceUpdates.AddedReferences.ToList()) + { + Debugging.Log(string.Format("Removing: {0}", value)); + UpdateRequestParameter p = new UpdateRequestParameter(); + p.PropertyName = this.Source; + p.Mode = UpdateMode.Remove; + p.Value = value; + ps.Add(p); + } + ClearMVOnResource.UpdateParameters = ps.ToArray(); + } + catch (Exception ex) + { + Debugging.Log(string.Format("Error: {0}", ex.Message)); + } + Debugging.Log("Exit::SetupClearMV_ExecuteCode"); + } + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/BackReferenceUpdateMemberActivity.designer.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/BackReferenceUpdateMemberActivity.designer.cs new file mode 100644 index 0000000..a560017 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/BackReferenceUpdateMemberActivity.designer.cs @@ -0,0 +1,206 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Collections; +using System.Reflection; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using System.Workflow.ComponentModel.Compiler; +using System.Workflow.ComponentModel.Serialization; +using System.Workflow.Runtime; +using System.Workflow.Activities; +using System.Workflow.Activities.Rules; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class BackReferenceUpdateMemberActivity + { + #region Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + [System.Diagnostics.DebuggerNonUserCode] + [System.CodeDom.Compiler.GeneratedCode("", "")] + private void InitializeComponent() + { + this.CanModifyActivities = true; + System.Workflow.Activities.CodeCondition codecondition1 = new System.Workflow.Activities.CodeCondition(); + System.Workflow.Activities.CodeCondition codecondition2 = new System.Workflow.Activities.CodeCondition(); + System.Workflow.Activities.Rules.RuleConditionReference ruleconditionreference1 = new System.Workflow.Activities.Rules.RuleConditionReference(); + System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind(); + this.RemoveFromTarget = new Granfeldt.FIM.ActivityLibrary.UpdateReferenceAttributesAsNeededActivity(); + this.PrepareGroupRemoveOperation = new System.Workflow.Activities.CodeActivity(); + this.AddToTarget = new Granfeldt.FIM.ActivityLibrary.UpdateReferenceAttributesAsNeededActivity(); + this.PrepareGroupAddOperation = new System.Workflow.Activities.CodeActivity(); + this.RemoveActivity = new System.Workflow.Activities.SequenceActivity(); + this.AddingActivity = new System.Workflow.Activities.SequenceActivity(); + this.ForEachMemberToRemove = new System.Workflow.Activities.WhileActivity(); + this.ForEachMemberToAdd = new System.Workflow.Activities.WhileActivity(); + this.ClearMVOnResource = new Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity(); + this.SetupClearMV = new System.Workflow.Activities.CodeActivity(); + this.Remove = new System.Workflow.Activities.IfElseBranchActivity(); + this.Add = new System.Workflow.Activities.IfElseBranchActivity(); + this.ClearMultivalueAttribute = new System.Workflow.Activities.SequenceActivity(); + this.ifElseActivity1 = new System.Workflow.Activities.IfElseActivity(); + this.GetReferenceUpdates = new Granfeldt.FIM.ActivityLibrary.GetUpdatesToReferenceAttributeActivity(); + // + // RemoveFromTarget + // + this.RemoveFromTarget.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.RemoveFromTarget.AttributeName = null; + this.RemoveFromTarget.Name = "RemoveFromTarget"; + this.RemoveFromTarget.ResourceId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.RemoveFromTarget.UpdateMode = Microsoft.ResourceManagement.WebServices.WSResourceManagement.UpdateMode.Modify; + this.RemoveFromTarget.Values = null; + // + // PrepareGroupRemoveOperation + // + this.PrepareGroupRemoveOperation.Name = "PrepareGroupRemoveOperation"; + this.PrepareGroupRemoveOperation.ExecuteCode += new System.EventHandler(this.PrepareGroupOperation_ExecuteCode); + // + // AddToTarget + // + this.AddToTarget.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.AddToTarget.AttributeName = null; + this.AddToTarget.Name = "AddToTarget"; + this.AddToTarget.ResourceId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.AddToTarget.UpdateMode = Microsoft.ResourceManagement.WebServices.WSResourceManagement.UpdateMode.Modify; + this.AddToTarget.Values = null; + // + // PrepareGroupAddOperation + // + this.PrepareGroupAddOperation.Name = "PrepareGroupAddOperation"; + this.PrepareGroupAddOperation.ExecuteCode += new System.EventHandler(this.PrepareGroupOperation_ExecuteCode); + // + // RemoveActivity + // + this.RemoveActivity.Activities.Add(this.PrepareGroupRemoveOperation); + this.RemoveActivity.Activities.Add(this.RemoveFromTarget); + this.RemoveActivity.Name = "RemoveActivity"; + // + // AddingActivity + // + this.AddingActivity.Activities.Add(this.PrepareGroupAddOperation); + this.AddingActivity.Activities.Add(this.AddToTarget); + this.AddingActivity.Name = "AddingActivity"; + // + // ForEachMemberToRemove + // + this.ForEachMemberToRemove.Activities.Add(this.RemoveActivity); + codecondition1.Condition += new System.EventHandler(this.ForEveryAdd_Condition); + this.ForEachMemberToRemove.Condition = codecondition1; + this.ForEachMemberToRemove.Name = "ForEachMemberToRemove"; + // + // ForEachMemberToAdd + // + this.ForEachMemberToAdd.Activities.Add(this.AddingActivity); + codecondition2.Condition += new System.EventHandler(this.ForEveryAdd_Condition); + this.ForEachMemberToAdd.Condition = codecondition2; + this.ForEachMemberToAdd.Name = "ForEachMemberToAdd"; + // + // ClearMVOnResource + // + this.ClearMVOnResource.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.ClearMVOnResource.Name = "ClearMVOnResource"; + this.ClearMVOnResource.ResourceId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.ClearMVOnResource.UpdateParameters = null; + // + // SetupClearMV + // + this.SetupClearMV.Name = "SetupClearMV"; + this.SetupClearMV.ExecuteCode += new System.EventHandler(this.SetupClearMV_ExecuteCode); + // + // Remove + // + this.Remove.Activities.Add(this.ForEachMemberToRemove); + this.Remove.Name = "Remove"; + // + // Add + // + this.Add.Activities.Add(this.ForEachMemberToAdd); + ruleconditionreference1.ConditionName = "Condition1"; + this.Add.Condition = ruleconditionreference1; + this.Add.Name = "Add"; + // + // ClearMultivalueAttribute + // + this.ClearMultivalueAttribute.Activities.Add(this.SetupClearMV); + this.ClearMultivalueAttribute.Activities.Add(this.ClearMVOnResource); + this.ClearMultivalueAttribute.Name = "ClearMultivalueAttribute"; + // + // ifElseActivity1 + // + this.ifElseActivity1.Activities.Add(this.Add); + this.ifElseActivity1.Activities.Add(this.Remove); + this.ifElseActivity1.Name = "ifElseActivity1"; + // + // GetReferenceUpdates + // + this.GetReferenceUpdates.AddedReferences = null; + activitybind1.Name = "BackReferenceUpdateMemberActivity"; + activitybind1.Path = "Source"; + this.GetReferenceUpdates.ModifiedReferences = null; + this.GetReferenceUpdates.Name = "GetReferenceUpdates"; + this.GetReferenceUpdates.OperationType = Microsoft.ResourceManagement.WebServices.WSResourceManagement.OperationType.Create; + this.GetReferenceUpdates.RemovedReferences = null; + this.GetReferenceUpdates.ResourceId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.GetReferenceUpdates.SetBinding(Granfeldt.FIM.ActivityLibrary.GetUpdatesToReferenceAttributeActivity.AttributeNameProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1))); + // + // BackReferenceUpdateMemberActivity + // + this.Activities.Add(this.GetReferenceUpdates); + this.Activities.Add(this.ifElseActivity1); + this.Activities.Add(this.ClearMultivalueAttribute); + this.Name = "BackReferenceUpdateMemberActivity"; + this.CanModifyActivities = false; + + } + + #endregion + + private CodeActivity SetupClearMV; + + private SequenceActivity ClearMultivalueAttribute; + + private Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity ClearMVOnResource; + + private IfElseBranchActivity Remove; + + private IfElseBranchActivity Add; + + private IfElseActivity ifElseActivity1; + + private UpdateReferenceAttributesAsNeededActivity RemoveFromTarget; + + private CodeActivity PrepareGroupRemoveOperation; + + private SequenceActivity RemoveActivity; + + private WhileActivity ForEachMemberToRemove; + + private UpdateReferenceAttributesAsNeededActivity AddToTarget; + + private CodeActivity PrepareGroupAddOperation; + + private SequenceActivity AddingActivity; + + private WhileActivity ForEachMemberToAdd; + + private GetUpdatesToReferenceAttributeActivity GetReferenceUpdates; + + + + + + + + + + + + + + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/BackReferenceUpdateMemberActivity.rules b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/BackReferenceUpdateMemberActivity.rules new file mode 100644 index 0000000..9b9296b --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/BackReferenceUpdateMemberActivity.rules @@ -0,0 +1,32 @@ + + + + + + + + + add + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/BackReferenceUpdateMemberSettingsPart.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/BackReferenceUpdateMemberSettingsPart.cs new file mode 100644 index 0000000..300b2f0 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/BackReferenceUpdateMemberSettingsPart.cs @@ -0,0 +1,197 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web.UI; +using System.Web.UI.WebControls; +using System.Workflow.ComponentModel; +using Microsoft.IdentityManagement.WebUI.Controls; +using Microsoft.ResourceManagement.Workflow.Activities; + +namespace Granfeldt.FIM.ActivityLibrary.WebUIs +{ + class BackReferenceUpdateMemberActivitySettingsPart : ActivitySettingsPart + { + + /// + /// Creates a Table that contains the controls used by the activity UI + /// in the Workflow Designer of the FIM portal. Adds that Table to the + /// collection of Controls that defines each activity that can be selected + /// in the Workflow Designer of the FIM Portal. Calls the base class of + /// ActivitySettingsPart to render the controls in the UI. + /// + protected override void CreateChildControls() + { + Table controlLayoutTable; + controlLayoutTable = new Table(); + + //Width is set to 100% of the control size + controlLayoutTable.Width = Unit.Percentage(100.0); + controlLayoutTable.BorderWidth = 0; + controlLayoutTable.CellPadding = 2; + //Add a TableRow for each textbox in the UI + controlLayoutTable.Rows.Add(this.AddTableRowTextBox("Title:", "txtTitle", 400, 100, false, "")); + controlLayoutTable.Rows.Add(this.AddTableRowTextBox("Source reference attribute:", "txtSource", 400, 100, false, "")); + controlLayoutTable.Rows.Add(this.AddTableRowTextBox("Destination attribute:", "txtDestination", 400, 100, false, "")); + controlLayoutTable.Rows.Add(this.AddTableRowTextBox("Action (type 'add' or 'remove'):", "txtAction", 400, 100, false, "")); + this.Controls.Add(controlLayoutTable); + + base.CreateChildControls(); + } + + #region Utility Functions + + //Create a TableRow that contains a label and a textbox. + private TableRow AddTableRowTextBox(String labelText, String controlID, int width, int maxLength, Boolean multiLine, String defaultValue) + { + TableRow row = new TableRow(); + TableCell labelCell = new TableCell(); + TableCell controlCell = new TableCell(); + Label oLabel = new Label(); + TextBox oText = new TextBox(); + + oLabel.Text = labelText; + oLabel.CssClass = base.LabelCssClass; + labelCell.Controls.Add(oLabel); + oText.ID = controlID; + oText.CssClass = base.TextBoxCssClass; + oText.Text = defaultValue; + oText.MaxLength = maxLength; + oText.Width = width; + if (multiLine) + { + oText.TextMode = TextBoxMode.MultiLine; + oText.Rows = System.Math.Min(6, (maxLength + 60) / 60); + oText.Wrap = true; + } + controlCell.Controls.Add(oText); + row.Cells.Add(labelCell); + row.Cells.Add(controlCell); + return row; + } + + string GetText(string textBoxID) + { + TextBox textBox = (TextBox)this.FindControl(textBoxID); + return textBox.Text ?? String.Empty; + } + void SetText(string textBoxID, string text) + { + TextBox textBox = (TextBox)this.FindControl(textBoxID); + if (textBox != null) + textBox.Text = text; + else + textBox.Text = ""; + } + + //Set the text box to read mode or read/write mode + void SetTextBoxReadOnlyOption(string textBoxID, bool readOnly) + { + TextBox textBox = (TextBox)this.FindControl(textBoxID); + textBox.ReadOnly = readOnly; + } + #endregion + + /// + /// Called when a user clicks the Save button in the Workflow Designer. + /// Returns an instance of the RequestLoggingActivity class that + /// has its properties set to the values entered into the text box controls + /// used in the UI of the activity. + /// + public override Activity GenerateActivityOnWorkflow(SequentialWorkflow workflow) + { + if (!this.ValidateInputs()) + { + return null; + } + BackReferenceUpdateMemberActivity ThisActivity = new BackReferenceUpdateMemberActivity(); + ThisActivity.Title = this.GetText("txtTitle"); + ThisActivity.Source = this.GetText("txtSource"); + ThisActivity.Destination = this.GetText("txtDestination"); + ThisActivity.Action = this.GetText("txtAction"); + return ThisActivity; + } + + public override void LoadActivitySettings(Activity activity) + { + BackReferenceUpdateMemberActivity ThisActivity = activity as BackReferenceUpdateMemberActivity; + if (ThisActivity != null) + { + this.SetText("txtTitle", ThisActivity.Title); + this.SetText("txtSource", ThisActivity.Source); + this.SetText("txtDestination", ThisActivity.Destination); + this.SetText("txtAction", ThisActivity.Action); + } + } + + /// + /// Saves the activity settings. + /// + public override ActivitySettingsPartData PersistSettings() + { + ActivitySettingsPartData data = new ActivitySettingsPartData(); + data["Title"] = this.GetText("txtTitle"); + data["Source"] = this.GetText("txtSource"); + data["Attribute"] = this.GetText("txtDestination"); + data["Action"] = this.GetText("txtAction"); + return data; + } + + /// + /// Restores the activity settings in the UI + /// + public override void RestoreSettings(ActivitySettingsPartData data) + { + if (null != data) + { + this.SetText("txtTitle", (string)data["Title"]); + this.SetText("txtSource", (string)data["Source"]); + this.SetText("txtDestination", (string)data["Attribute"]); + this.SetText("txtAction", (string)data["Action"]); + } + } + + /// + /// Switches the activity between read only and read/write mode + /// + public override void SwitchMode(ActivitySettingsPartMode mode) + { + bool readOnly = (mode == ActivitySettingsPartMode.View); + this.SetTextBoxReadOnlyOption("txtTitle", readOnly); + this.SetTextBoxReadOnlyOption("txtDestination", readOnly); + this.SetTextBoxReadOnlyOption("txtSource", readOnly); + this.SetTextBoxReadOnlyOption("txtAction", readOnly); + } + + /// + /// Returns the activity name. + /// + public override string Title + { + get + { + return string.Format("Add Remove Value: {0}", this.GetText("txtTitle")); + } + } + + /// + /// In general, this method should be used to validate information entered + /// by the user when the activity is added to a workflow in the Workflow + /// Designer. + /// We could add code to verify that the log file path already exists on + /// the server that is hosting the FIM Portal and check that the activity + /// has permission to write to that location. However, the code + /// would only check if the log file path exists when the + /// activity is added to a workflow in the workflow designer. This class + /// will not be used when the activity is actually run. + /// For this activity we will just return true. + /// + public override bool ValidateInputs() + { + return true; + } + + } + + +} diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/GetReferenceValuesFromObjectActivity.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/GetReferenceValuesFromObjectActivity.cs new file mode 100644 index 0000000..eb84ca1 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/GetReferenceValuesFromObjectActivity.cs @@ -0,0 +1,147 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Linq; +using System.Workflow.Activities; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; + +namespace Granfeldt.FIM.ActivityLibrary +{ + [Designer(typeof(ActivityDesigner), typeof(IDesigner))] + public partial class GetReferenceValuesFromObjectActivity: SequenceActivity + { + #region Properties + + + public static DependencyProperty ObjectIDProperty = DependencyProperty.Register("ObjectID", typeof(Guid), typeof(GetReferenceValuesFromObjectActivity)); + + [Description("ObjectID")] + [Category("Input")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Guid ObjectID + { + get + { + return ((Guid)(base.GetValue(GetReferenceValuesFromObjectActivity.ObjectIDProperty))); + } + set + { + base.SetValue(GetReferenceValuesFromObjectActivity.ObjectIDProperty, value); + } + } + + public static DependencyProperty AttributeNameProperty = DependencyProperty.Register("AttributeName", typeof(String), typeof(GetReferenceValuesFromObjectActivity)); + + [Description("AttributeName")] + [Category("Input")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public String AttributeName + { + get + { + return ((String)(base.GetValue(GetReferenceValuesFromObjectActivity.AttributeNameProperty))); + } + set + { + base.SetValue(GetReferenceValuesFromObjectActivity.AttributeNameProperty, value); + } + } + + public static DependencyProperty ActorIdProperty = DependencyProperty.Register("ActorId", typeof(Guid), typeof(GetReferenceValuesFromObjectActivity)); + + [Description("ActorId")] + [Category("Input")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Guid ActorId + { + get + { + return ((Guid)(base.GetValue(GetReferenceValuesFromObjectActivity.ActorIdProperty))); + } + set + { + base.SetValue(GetReferenceValuesFromObjectActivity.ActorIdProperty, value); + } + } + + public static DependencyProperty CurrentValuesProperty = DependencyProperty.Register("CurrentValues", typeof(Guid[]), typeof(GetReferenceValuesFromObjectActivity)); + + [Description("CurrentValues")] + [Category("Output")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Guid[] CurrentValues + { + get + { + return ((Guid[])(base.GetValue(GetReferenceValuesFromObjectActivity.CurrentValuesProperty))); + } + set + { + base.SetValue(GetReferenceValuesFromObjectActivity.CurrentValuesProperty, value); + } + } + + #endregion + + public GetReferenceValuesFromObjectActivity() + { + InitializeComponent(); + } + + public String[] SelectionAttributes = default(System.String[]); + public Microsoft.ResourceManagement.WebServices.WSResourceManagement.ResourceType CurrentResource = new Microsoft.ResourceManagement.WebServices.WSResourceManagement.ResourceType(); + + private void PrepareReading_ExecuteCode(object sender, EventArgs e) + { + this.SelectionAttributes = new string[] {this.AttributeName}; + } + + private void ProcessResults_ExecuteCode(object sender, EventArgs e) + { + object PropertyValue = this.CurrentResource[this.AttributeName]; + List currentValues = new List(); + + if (null != PropertyValue) + { + if (PropertyValue.GetType().FullName.StartsWith("System.Collections.Generic.List") || + PropertyValue.GetType().FullName.EndsWith("[]")) + { + foreach (object myObject in (IEnumerable) PropertyValue) + { + if (myObject is Microsoft.ResourceManagement.WebServices.UniqueIdentifier) + { + currentValues.Add( + ((Microsoft.ResourceManagement.WebServices.UniqueIdentifier) myObject).GetGuid()); + } + if (myObject is System.Guid) + { + currentValues.Add((System.Guid) myObject); + } + + } + } + else + { + if (PropertyValue is Microsoft.ResourceManagement.WebServices.UniqueIdentifier) + { + currentValues.Add( + ((Microsoft.ResourceManagement.WebServices.UniqueIdentifier) PropertyValue).GetGuid()); + } + if (PropertyValue is System.Guid) + { + currentValues.Add((System.Guid) PropertyValue); + } + } + } + + this.CurrentValues = currentValues.Distinct().ToArray(); + } + } +} \ No newline at end of file diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/GetReferenceValuesFromObjectActivity.designer.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/GetReferenceValuesFromObjectActivity.designer.cs new file mode 100644 index 0000000..4a043b7 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/GetReferenceValuesFromObjectActivity.designer.cs @@ -0,0 +1,75 @@ +using System.Workflow.Activities; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class GetReferenceValuesFromObjectActivity + { + #region Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + [System.Diagnostics.DebuggerNonUserCode] + private void InitializeComponent() + { + this.CanModifyActivities = true; + System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind2 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind3 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind4 = new System.Workflow.ComponentModel.ActivityBind(); + this.ProcessResults = new System.Workflow.Activities.CodeActivity(); + this.ReadResource = new Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity(); + this.PrepareReading = new System.Workflow.Activities.CodeActivity(); + // + // ProcessResults + // + this.ProcessResults.Name = "ProcessResults"; + this.ProcessResults.ExecuteCode += new System.EventHandler(this.ProcessResults_ExecuteCode); + // + // ReadResource + // + activitybind1.Name = "GetReferenceValuesFromObjectActivity"; + activitybind1.Path = "ActorId"; + this.ReadResource.Name = "ReadResource"; + activitybind2.Name = "GetReferenceValuesFromObjectActivity"; + activitybind2.Path = "CurrentResource"; + activitybind3.Name = "GetReferenceValuesFromObjectActivity"; + activitybind3.Path = "ObjectID"; + activitybind4.Name = "GetReferenceValuesFromObjectActivity"; + activitybind4.Path = "SelectionAttributes"; + this.ReadResource.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity.ActorIdProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1))); + this.ReadResource.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity.ResourceIdProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind3))); + //this.ReadResource.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity.SelectionAttributesProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind4))); + this.ReadResource.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity.ResourceProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind2))); + // + // PrepareReading + // + this.PrepareReading.Name = "PrepareReading"; + this.PrepareReading.ExecuteCode += new System.EventHandler(this.PrepareReading_ExecuteCode); + // + // GetReferenceValuesFromObjectActivity + // + this.Activities.Add(this.PrepareReading); + this.Activities.Add(this.ReadResource); + this.Activities.Add(this.ProcessResults); + this.Name = "GetReferenceValuesFromObjectActivity"; + this.CanModifyActivities = false; + + } + + #endregion + + private CodeActivity PrepareReading; + private CodeActivity ProcessResults; + private Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity ReadResource; + + + + + + + + + } +} \ No newline at end of file diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/GetUpdatesToReferenceAttributeActivity.Designer.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/GetUpdatesToReferenceAttributeActivity.Designer.cs new file mode 100644 index 0000000..83a9cc1 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/GetUpdatesToReferenceAttributeActivity.Designer.cs @@ -0,0 +1,48 @@ +using System.Workflow.Activities; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class GetUpdatesToReferenceAttributeActivity + { + #region Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + [System.Diagnostics.DebuggerNonUserCode] + private void InitializeComponent() + { + this.CanModifyActivities = true; + System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind(); + this.ExtractDataFromRequest = new System.Workflow.Activities.CodeActivity(); + this.GetCurrentRequest = new Microsoft.ResourceManagement.Workflow.Activities.CurrentRequestActivity(); + // + // ExtractDataFromRequest + // + this.ExtractDataFromRequest.Name = "ExtractDataFromRequest"; + this.ExtractDataFromRequest.ExecuteCode += new System.EventHandler(this.ExtractDataFromRequest_ExecuteCode); + // + // GetCurrentRequest + // + activitybind1.Name = "GetUpdatesToReferenceAttributeActivity"; + activitybind1.Path = "CurrentRequest"; + this.GetCurrentRequest.Name = "GetCurrentRequest"; + this.GetCurrentRequest.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.CurrentRequestActivity.CurrentRequestProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1))); + // + // GetUpdatesToReferenceAttributeActivity + // + this.Activities.Add(this.GetCurrentRequest); + this.Activities.Add(this.ExtractDataFromRequest); + this.Name = "GetUpdatesToReferenceAttributeActivity"; + this.CanModifyActivities = false; + + } + + #endregion + + private CodeActivity ExtractDataFromRequest; + private Microsoft.ResourceManagement.Workflow.Activities.CurrentRequestActivity GetCurrentRequest; + + } +} \ No newline at end of file diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/GetUpdatesToReferenceAttributeActivity.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/GetUpdatesToReferenceAttributeActivity.cs new file mode 100644 index 0000000..ffd6c5d --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/GetUpdatesToReferenceAttributeActivity.cs @@ -0,0 +1,289 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Linq; +using System.Workflow.Activities; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using Microsoft.ResourceManagement.WebServices.WSResourceManagement; + +namespace Granfeldt.FIM.ActivityLibrary +{ + [Designer(typeof(ActivityDesigner), typeof(IDesigner))] + public partial class GetUpdatesToReferenceAttributeActivity : SequenceActivity + { + + #region Properties + public static DependencyProperty AddedReferencesProperty = DependencyProperty.Register("AddedReferences", typeof(Guid[]), typeof(GetUpdatesToReferenceAttributeActivity)); + + [Description("AddedReferences")] + [Category("Output")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Guid[] AddedReferences + { + get + { + return ((Guid[])(base.GetValue(GetUpdatesToReferenceAttributeActivity.AddedReferencesProperty))); + } + set + { + base.SetValue(GetUpdatesToReferenceAttributeActivity.AddedReferencesProperty, value); + } + } + + public static DependencyProperty ModifiedReferencesProperty = DependencyProperty.Register("ModifiedReferences", typeof(Guid[]), typeof(GetUpdatesToReferenceAttributeActivity)); + + [DescriptionAttribute("ModifiedReferences")] + [CategoryAttribute("Output")] + [BrowsableAttribute(true)] + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] + public Guid[] ModifiedReferences + { + get + { + return ((Guid[])(base.GetValue(GetUpdatesToReferenceAttributeActivity.ModifiedReferencesProperty))); + } + set + { + base.SetValue(GetUpdatesToReferenceAttributeActivity.ModifiedReferencesProperty, value); + } + } + + public static DependencyProperty RemovedReferencesProperty = DependencyProperty.Register("RemovedReferences", typeof(Guid[]), typeof(GetUpdatesToReferenceAttributeActivity)); + + public static DependencyProperty ResourceIdProperty = DependencyProperty.Register("ResourceId", typeof(Guid), typeof(GetUpdatesToReferenceAttributeActivity)); + + [Description("ResourceId")] + [Category("Output")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Guid ResourceId + { + get + { + return ((Guid)(base.GetValue(GetUpdatesToReferenceAttributeActivity.ResourceIdProperty))); + } + set + { + base.SetValue(GetUpdatesToReferenceAttributeActivity.ResourceIdProperty, value); + } + } + + [Description("RemovedReferences")] + [Category("Output")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Guid[] RemovedReferences + { + get + { + return ((Guid[])(base.GetValue(GetUpdatesToReferenceAttributeActivity.RemovedReferencesProperty))); + } + set + { + base.SetValue(GetUpdatesToReferenceAttributeActivity.RemovedReferencesProperty, value); + } + } + + public static DependencyProperty AttributeNameProperty = DependencyProperty.Register("AttributeName", typeof(string), typeof(GetUpdatesToReferenceAttributeActivity)); + + [Description("AttributeName")] + [Category("Input")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string AttributeName + { + get + { + return ((string)(base.GetValue(GetUpdatesToReferenceAttributeActivity.AttributeNameProperty))); + } + set + { + base.SetValue(GetUpdatesToReferenceAttributeActivity.AttributeNameProperty, value); + } + } + + public static DependencyProperty OperationTypeProperty = DependencyProperty.Register("OperationType", typeof(OperationType), typeof(GetUpdatesToReferenceAttributeActivity)); + + [Description("OperationType")] + [Category("Output")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public OperationType OperationType + { + get + { + return ((OperationType)(base.GetValue(GetUpdatesToReferenceAttributeActivity.OperationTypeProperty))); + } + set + { + base.SetValue(GetUpdatesToReferenceAttributeActivity.OperationTypeProperty, value); + } + } + + #endregion + + public GetUpdatesToReferenceAttributeActivity() + { + InitializeComponent(); + } + + public Microsoft.ResourceManagement.WebServices.WSResourceManagement.RequestType CurrentRequest = null; + + private void ExtractDataFromRequest_ExecuteCode(object sender, EventArgs e) + { + this.ResourceId = this.CurrentRequest.Target.GetGuid(); + this.OperationType = this.CurrentRequest.Operation; + List toAdd = new List(); + List toRemove = new List(); + List toModify = new List(); + + if (this.CurrentRequest.Operation == OperationType.Create) + { + ReadOnlyCollection myParameters = + this.CurrentRequest.ParseParameters(); + + foreach (CreateRequestParameter myParameter in myParameters) + { + if (String.Equals(this.AttributeName, myParameter.PropertyName, + StringComparison.InvariantCultureIgnoreCase)) + { + if (myParameter.Value.GetType().FullName.StartsWith("System.Collections.Generic.List") || + myParameter.Value.GetType().FullName.EndsWith("[]")) + { + foreach (object myObject in (IEnumerable)myParameter.Value) + { + + if (myObject is Microsoft.ResourceManagement.WebServices.UniqueIdentifier) + toAdd.Add( + ((Microsoft.ResourceManagement.WebServices.UniqueIdentifier)myObject).GetGuid()); + if (myObject is System.Guid) + toAdd.Add((System.Guid)myObject); + } + } + else + { + if (myParameter.Value is Microsoft.ResourceManagement.WebServices.UniqueIdentifier) + toAdd.Add( + ((Microsoft.ResourceManagement.WebServices.UniqueIdentifier)myParameter.Value). + GetGuid()); + if (myParameter.Value is System.Guid) + toAdd.Add((System.Guid)myParameter.Value); + } + } + } + } + + if (this.CurrentRequest.Operation == OperationType.Put) + { + ReadOnlyCollection myParameters = + this.CurrentRequest.ParseParameters(); + + foreach (UpdateRequestParameter myParameter in myParameters) + { + if (myParameter.Mode == UpdateMode.Insert) + { + if (String.Equals(this.AttributeName, myParameter.PropertyName, + StringComparison.InvariantCultureIgnoreCase)) + { + if (myParameter.Value.GetType().FullName.StartsWith("System.Collections.Generic.List") || + myParameter.Value.GetType().FullName.EndsWith("[]")) + { + foreach (object myObject in (IEnumerable)myParameter.Value) + { + if (myObject is Microsoft.ResourceManagement.WebServices.UniqueIdentifier) + toAdd.Add( + ((Microsoft.ResourceManagement.WebServices.UniqueIdentifier)myObject). + GetGuid()); + if (myObject is System.Guid) + toAdd.Add((System.Guid)myObject); + } + } + else + { + if (myParameter.Value is Microsoft.ResourceManagement.WebServices.UniqueIdentifier) + toAdd.Add( + ((Microsoft.ResourceManagement.WebServices.UniqueIdentifier)myParameter.Value). + GetGuid()); + if (myParameter.Value is System.Guid) + toAdd.Add((System.Guid)myParameter.Value); + } + } + } + + if (myParameter.Mode == UpdateMode.Modify) + { + if (String.Equals(this.AttributeName, myParameter.PropertyName, + StringComparison.InvariantCultureIgnoreCase)) + { + // Actually never going to happen, but who knows ? + if (myParameter.Value.GetType().FullName.StartsWith("System.Collections.Generic.List") || + myParameter.Value.GetType().FullName.EndsWith("[]")) + { + foreach (object myObject in (IEnumerable)myParameter.Value) + { + + if (myObject is Microsoft.ResourceManagement.WebServices.UniqueIdentifier) + toModify.Add( + ((Microsoft.ResourceManagement.WebServices.UniqueIdentifier)myObject). + GetGuid()); + if (myObject is System.Guid) + toModify.Add((System.Guid)myObject); + } + } + else + { + if (myParameter.Value is Microsoft.ResourceManagement.WebServices.UniqueIdentifier) + toModify.Add( + ((Microsoft.ResourceManagement.WebServices.UniqueIdentifier)myParameter.Value). + GetGuid()); + if (myParameter.Value is System.Guid) + toModify.Add((System.Guid)myParameter.Value); + } + } + } + + + if (myParameter.Mode == UpdateMode.Remove) + { + if (String.Equals(this.AttributeName, myParameter.PropertyName, + StringComparison.InvariantCultureIgnoreCase)) + { + if (myParameter.Value.GetType().FullName.StartsWith("System.Collections.Generic.List") || + myParameter.Value.GetType().FullName.EndsWith("[]")) + { + foreach (object myObject in (IEnumerable)myParameter.Value) + { + + if (myObject is Microsoft.ResourceManagement.WebServices.UniqueIdentifier) + toRemove.Add( + ((Microsoft.ResourceManagement.WebServices.UniqueIdentifier)myObject). + GetGuid()); + if (myObject is System.Guid) + toRemove.Add((System.Guid)myObject); + } + } + else + { + if (myParameter.Value is Microsoft.ResourceManagement.WebServices.UniqueIdentifier) + toRemove.Add( + ((Microsoft.ResourceManagement.WebServices.UniqueIdentifier)myParameter.Value). + GetGuid()); + if (myParameter.Value is System.Guid) + toRemove.Add((System.Guid)myParameter.Value); + } + } + } + + } + } + this.AddedReferences=toAdd.Distinct().ToArray(); + this.RemovedReferences=toRemove.Distinct().ToArray(); + this.ModifiedReferences = toModify.Distinct().ToArray(); + } + } +} \ No newline at end of file diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/UpdateReferenceAttributeActivity.Designer.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/UpdateReferenceAttributeActivity.Designer.cs new file mode 100644 index 0000000..9305d43 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/UpdateReferenceAttributeActivity.Designer.cs @@ -0,0 +1,90 @@ +using System.Workflow.Activities; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class UpdateReferenceAttributeActivity + { + #region Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + [System.Diagnostics.DebuggerNonUserCode] + private void InitializeComponent() + { + this.CanModifyActivities = true; + System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind2 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind3 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.Activities.CodeCondition codecondition1 = new System.Workflow.Activities.CodeCondition(); + this.UpdateResource = new Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity(); + this.PrepareUpdate = new System.Workflow.Activities.CodeActivity(); + this.ValuesAreNotPresent = new System.Workflow.Activities.IfElseBranchActivity(); + this.ValuesPresent = new System.Workflow.Activities.IfElseBranchActivity(); + this.CheckIfAnyValuesPresent = new System.Workflow.Activities.IfElseActivity(); + // + // UpdateResource + // + activitybind1.Name = "UpdateReferenceAttributeActivity"; + activitybind1.Path = "ActorId"; + this.UpdateResource.Name = "UpdateResource"; + activitybind2.Name = "UpdateReferenceAttributeActivity"; + activitybind2.Path = "ResourceId"; + activitybind3.Name = "UpdateReferenceAttributeActivity"; + activitybind3.Path = "UpdateParameters"; + this.UpdateResource.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity.ActorIdProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1))); + this.UpdateResource.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity.ResourceIdProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind2))); + this.UpdateResource.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity.UpdateParametersProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind3))); + // + // PrepareUpdate + // + this.PrepareUpdate.Name = "PrepareUpdate"; + this.PrepareUpdate.ExecuteCode += new System.EventHandler(this.PrepareUpdate_ExecuteCode); + // + // ValuesAreNotPresent + // + this.ValuesAreNotPresent.Name = "ValuesAreNotPresent"; + // + // ValuesPresent + // + this.ValuesPresent.Activities.Add(this.PrepareUpdate); + this.ValuesPresent.Activities.Add(this.UpdateResource); + codecondition1.Condition += new System.EventHandler(this.AreValuesPresent); + this.ValuesPresent.Condition = codecondition1; + this.ValuesPresent.Name = "ValuesPresent"; + // + // CheckIfAnyValuesPresent + // + this.CheckIfAnyValuesPresent.Activities.Add(this.ValuesPresent); + this.CheckIfAnyValuesPresent.Activities.Add(this.ValuesAreNotPresent); + this.CheckIfAnyValuesPresent.Name = "CheckIfAnyValuesPresent"; + // + // UpdateReferenceAttributeActivity + // + this.Activities.Add(this.CheckIfAnyValuesPresent); + this.Name = "UpdateReferenceAttributeActivity"; + this.CanModifyActivities = false; + + } + + #endregion + + private IfElseBranchActivity ValuesAreNotPresent; + private IfElseBranchActivity ValuesPresent; + private IfElseActivity CheckIfAnyValuesPresent; + private CodeActivity PrepareUpdate; + private Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity UpdateResource; + + + + + + + + + + + + } +} \ No newline at end of file diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/UpdateReferenceAttributeActivity.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/UpdateReferenceAttributeActivity.cs new file mode 100644 index 0000000..513527d --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/UpdateReferenceAttributeActivity.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Workflow.Activities; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using Microsoft.ResourceManagement.WebServices.WSResourceManagement; + +namespace Granfeldt.FIM.ActivityLibrary +{ + [Designer(typeof(ActivityDesigner), typeof(IDesigner))] + public partial class UpdateReferenceAttributeActivity : SequenceActivity + { + #region Properties + public static DependencyProperty ActorIdProperty = DependencyProperty.Register("ActorId", typeof(Guid), typeof(UpdateReferenceAttributeActivity)); + + [Description("ActorId")] + [Category("ActorId Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Guid ActorId + { + get + { + return ((Guid)(base.GetValue(UpdateReferenceAttributeActivity.ActorIdProperty))); + } + set + { + base.SetValue(UpdateReferenceAttributeActivity.ActorIdProperty, value); + } + } + + public static DependencyProperty ResourceIdProperty = DependencyProperty.Register("ResourceId", typeof(Guid), typeof(UpdateReferenceAttributeActivity)); + + [Description("ResourceId")] + [Category("ResourceId Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Guid ResourceId + { + get + { + return ((Guid)(base.GetValue(UpdateReferenceAttributeActivity.ResourceIdProperty))); + } + set + { + base.SetValue(UpdateReferenceAttributeActivity.ResourceIdProperty, value); + } + } + + public static DependencyProperty ValuesProperty = DependencyProperty.Register("Values", typeof(Guid[]), typeof(UpdateReferenceAttributeActivity)); + + public static DependencyProperty AttributeNameProperty = DependencyProperty.Register("AttributeName", typeof(string), typeof(UpdateReferenceAttributeActivity)); + + [Description("AttributeName")] + [Category("AttributeName Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string AttributeName + { + get + { + return ((string)(base.GetValue(UpdateReferenceAttributeActivity.AttributeNameProperty))); + } + set + { + base.SetValue(UpdateReferenceAttributeActivity.AttributeNameProperty, value); + } + } + + [Description("Values")] + [Category("Values Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Guid[] Values + { + get + { + return ((Guid[])(base.GetValue(UpdateReferenceAttributeActivity.ValuesProperty))); + } + set + { + base.SetValue(UpdateReferenceAttributeActivity.ValuesProperty, value); + } + } + + public static DependencyProperty UpdateModeProperty = DependencyProperty.Register("UpdateMode", typeof(Microsoft.ResourceManagement.WebServices.WSResourceManagement.UpdateMode), typeof(UpdateReferenceAttributeActivity)); + + [Description("UpdateMode")] + [Category("UpdateMode Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public UpdateMode UpdateMode + { + get + { + return ((Microsoft.ResourceManagement.WebServices.WSResourceManagement.UpdateMode)(base.GetValue(UpdateReferenceAttributeActivity.UpdateModeProperty))); + } + set + { + base.SetValue(UpdateReferenceAttributeActivity.UpdateModeProperty, value); + } + } + #endregion + + public UpdateReferenceAttributeActivity() + { + InitializeComponent(); + } + + private void PrepareUpdate_ExecuteCode(object sender, EventArgs e) + { + List tempParameters = new List(); + foreach (Guid guid in this.Values) + { + tempParameters.Add(new UpdateRequestParameter(this.AttributeName, this.UpdateMode, guid)); + } + + this.UpdateParameters = tempParameters.ToArray(); + } + + public UpdateRequestParameter[] UpdateParameters = null; + + private void AreValuesPresent(object sender, ConditionalEventArgs e) + { + if (this.Values != null && this.Values.Length > 0) + e.Result = true; + else + e.Result = false; + } + } +} \ No newline at end of file diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/UpdateReferenceAttributesAsNeededActivity.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/UpdateReferenceAttributesAsNeededActivity.cs new file mode 100644 index 0000000..6cd8ea8 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/UpdateReferenceAttributesAsNeededActivity.cs @@ -0,0 +1,141 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Linq; +using System.Workflow.Activities; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; + +namespace Granfeldt.FIM.ActivityLibrary +{ + [Designer(typeof(ActivityDesigner), typeof(IDesigner))] + public partial class UpdateReferenceAttributesAsNeededActivity: SequenceActivity + { + public UpdateReferenceAttributesAsNeededActivity() + { + InitializeComponent(); + } + + public static DependencyProperty ActorIdProperty = DependencyProperty.Register("ActorId", typeof(System.Guid), typeof(UpdateReferenceAttributesAsNeededActivity)); + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + [Browsable(true)] + [Category("ActorId Category")] + public Guid ActorId + { + get + { + return ((System.Guid)(base.GetValue(UpdateReferenceAttributesAsNeededActivity.ActorIdProperty))); + } + set + { + base.SetValue(UpdateReferenceAttributesAsNeededActivity.ActorIdProperty, value); + } + } + + public static DependencyProperty ResourceIdProperty = DependencyProperty.Register("ResourceId", typeof(System.Guid), typeof(UpdateReferenceAttributesAsNeededActivity)); + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + [Browsable(true)] + [Category("ResourceId Category")] + public Guid ResourceId + { + get + { + return ((System.Guid)(base.GetValue(UpdateReferenceAttributesAsNeededActivity.ResourceIdProperty))); + } + set + { + base.SetValue(UpdateReferenceAttributesAsNeededActivity.ResourceIdProperty, value); + } + } + + public static DependencyProperty UpdateModeProperty = DependencyProperty.Register("UpdateMode", typeof(Microsoft.ResourceManagement.WebServices.WSResourceManagement.UpdateMode), typeof(UpdateReferenceAttributesAsNeededActivity)); + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + [Browsable(true)] + [Category("UpdateMode Category")] + public Microsoft.ResourceManagement.WebServices.WSResourceManagement.UpdateMode UpdateMode + { + get + { + return ((Microsoft.ResourceManagement.WebServices.WSResourceManagement.UpdateMode)(base.GetValue(UpdateReferenceAttributesAsNeededActivity.UpdateModeProperty))); + } + set + { + base.SetValue(UpdateReferenceAttributesAsNeededActivity.UpdateModeProperty, value); + } + } + + public static DependencyProperty ValuesProperty = DependencyProperty.Register("Values", typeof(System.Guid[]), typeof(UpdateReferenceAttributesAsNeededActivity)); + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + [Browsable(true)] + [Category("Values Category")] + public Guid[] Values + { + get + { + return ((System.Guid[])(base.GetValue(UpdateReferenceAttributesAsNeededActivity.ValuesProperty))); + } + set + { + base.SetValue(UpdateReferenceAttributesAsNeededActivity.ValuesProperty, value); + } + } + + public static DependencyProperty AttributeNameProperty = DependencyProperty.Register("AttributeName", typeof(System.String), typeof(UpdateReferenceAttributesAsNeededActivity)); + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + [Browsable(true)] + [Category("AttributeName Category")] + public String AttributeName + { + get + { + return ((string)(base.GetValue(UpdateReferenceAttributesAsNeededActivity.AttributeNameProperty))); + } + set + { + base.SetValue(UpdateReferenceAttributesAsNeededActivity.AttributeNameProperty, value); + } + } + + public Guid[] ValuesToSet = default(System.Guid[]); + + private void FindOutIfThereIsAPointInDoingAnything(object sender, ConditionalEventArgs e) + { + if(null==this.Values || this.Values.Length==0) + { + e.Result = false; + return; + } + switch (this.UpdateMode) + { + case Microsoft.ResourceManagement.WebServices.WSResourceManagement.UpdateMode.Insert: + this.ValuesToSet = this.Values.Except(this.CurrentValues).ToArray(); + e.Result = true; + break; + case Microsoft.ResourceManagement.WebServices.WSResourceManagement.UpdateMode.Modify: + if (this.CurrentValues.Except(this.Values).Count()>0 || + this.Values.Except(this.CurrentValues).Count()>0) + { + this.ValuesToSet = this.Values; + e.Result = true; + + } + else + { + e.Result = false; + } + break; + case Microsoft.ResourceManagement.WebServices.WSResourceManagement.UpdateMode.Remove: + this.ValuesToSet = this.Values.Intersect(this.CurrentValues).ToArray(); + e.Result = true; + break; + } + } + + public Guid[] CurrentValues = default(System.Guid[]); + } +} \ No newline at end of file diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/UpdateReferenceAttributesAsNeededActivity.designer.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/UpdateReferenceAttributesAsNeededActivity.designer.cs new file mode 100644 index 0000000..85c2412 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddBackReference/UpdateReferenceAttributesAsNeededActivity.designer.cs @@ -0,0 +1,102 @@ +using System.Workflow.Activities; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class UpdateReferenceAttributesAsNeededActivity + { + #region Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + [System.Diagnostics.DebuggerNonUserCode] + private void InitializeComponent() + { + this.CanModifyActivities = true; + System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind2 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind3 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind4 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind5 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.Activities.CodeCondition codecondition1 = new System.Workflow.Activities.CodeCondition(); + System.Workflow.ComponentModel.ActivityBind activitybind6 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind7 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind8 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind9 = new System.Workflow.ComponentModel.ActivityBind(); + this.UpdateReferences = new UpdateReferenceAttributeActivity(); + this.NotAtAll = new System.Workflow.Activities.IfElseBranchActivity(); + this.Probably = new System.Workflow.Activities.IfElseBranchActivity(); + this.IsTherePointInDoingAnything = new System.Workflow.Activities.IfElseActivity(); + this.GetCurrentReferences = new Granfeldt.FIM.ActivityLibrary.GetReferenceValuesFromObjectActivity(); + // + // UpdateReferences + // + activitybind1.Name = "UpdateReferenceAttributesAsNeededActivity"; + activitybind1.Path = "ActorId"; + activitybind2.Name = "UpdateReferenceAttributesAsNeededActivity"; + activitybind2.Path = "AttributeName"; + this.UpdateReferences.Name = "UpdateReferences"; + activitybind3.Name = "UpdateReferenceAttributesAsNeededActivity"; + activitybind3.Path = "ResourceId"; + activitybind4.Name = "UpdateReferenceAttributesAsNeededActivity"; + activitybind4.Path = "UpdateMode"; + activitybind5.Name = "UpdateReferenceAttributesAsNeededActivity"; + activitybind5.Path = "ValuesToSet"; + this.UpdateReferences.SetBinding(UpdateReferenceAttributeActivity.ActorIdProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1))); + this.UpdateReferences.SetBinding(UpdateReferenceAttributeActivity.ResourceIdProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind3))); + this.UpdateReferences.SetBinding(UpdateReferenceAttributeActivity.UpdateModeProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind4))); + this.UpdateReferences.SetBinding(UpdateReferenceAttributeActivity.ValuesProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind5))); + this.UpdateReferences.SetBinding(UpdateReferenceAttributeActivity.AttributeNameProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind2))); + // + // NotAtAll + // + this.NotAtAll.Name = "NotAtAll"; + // + // Probably + // + this.Probably.Activities.Add(this.UpdateReferences); + codecondition1.Condition += new System.EventHandler(this.FindOutIfThereIsAPointInDoingAnything); + this.Probably.Condition = codecondition1; + this.Probably.Name = "Probably"; + // + // IsTherePointInDoingAnything + // + this.IsTherePointInDoingAnything.Activities.Add(this.Probably); + this.IsTherePointInDoingAnything.Activities.Add(this.NotAtAll); + this.IsTherePointInDoingAnything.Name = "IsTherePointInDoingAnything"; + // + // GetCurrentReferences + // + activitybind6.Name = "UpdateReferenceAttributesAsNeededActivity"; + activitybind6.Path = "ActorId"; + activitybind7.Name = "UpdateReferenceAttributesAsNeededActivity"; + activitybind7.Path = "AttributeName"; + activitybind8.Name = "UpdateReferenceAttributesAsNeededActivity"; + activitybind8.Path = "CurrentValues"; + this.GetCurrentReferences.Name = "GetCurrentReferences"; + activitybind9.Name = "UpdateReferenceAttributesAsNeededActivity"; + activitybind9.Path = "ResourceId"; + this.GetCurrentReferences.SetBinding(Granfeldt.FIM.ActivityLibrary.GetReferenceValuesFromObjectActivity.ActorIdProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind6))); + this.GetCurrentReferences.SetBinding(Granfeldt.FIM.ActivityLibrary.GetReferenceValuesFromObjectActivity.AttributeNameProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind7))); + this.GetCurrentReferences.SetBinding(Granfeldt.FIM.ActivityLibrary.GetReferenceValuesFromObjectActivity.CurrentValuesProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind8))); + this.GetCurrentReferences.SetBinding(Granfeldt.FIM.ActivityLibrary.GetReferenceValuesFromObjectActivity.ObjectIDProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind9))); + // + // UpdateReferenceAttributesAsNeededActivity + // + this.Activities.Add(this.GetCurrentReferences); + this.Activities.Add(this.IsTherePointInDoingAnything); + this.Name = "UpdateReferenceAttributesAsNeededActivity"; + this.CanModifyActivities = false; + + } + + #endregion + + private GetReferenceValuesFromObjectActivity GetCurrentReferences; + private IfElseBranchActivity NotAtAll; + private IfElseBranchActivity Probably; + private IfElseActivity IsTherePointInDoingAnything; + private UpdateReferenceAttributeActivity UpdateReferences; + } +} \ No newline at end of file diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddRemoveFromMultivalue/Activity.AddRemoveFromMultiValue.Designer.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddRemoveFromMultivalue/Activity.AddRemoveFromMultiValue.Designer.cs new file mode 100644 index 0000000..b46c0d8 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddRemoveFromMultivalue/Activity.AddRemoveFromMultiValue.Designer.cs @@ -0,0 +1,204 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Collections; +using System.Reflection; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using System.Workflow.ComponentModel.Compiler; +using System.Workflow.ComponentModel.Serialization; +using System.Workflow.Runtime; +using System.Workflow.Activities; +using System.Workflow.Activities.Rules; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class AddRemoveFromMultiValueActivity + { + #region Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + [System.Diagnostics.DebuggerNonUserCode] + [System.CodeDom.Compiler.GeneratedCode("", "")] + private void InitializeComponent() + { + this.CanModifyActivities = true; + System.Workflow.Activities.CodeCondition codecondition1 = new System.Workflow.Activities.CodeCondition(); + System.Collections.Generic.List list_11 = new System.Collections.Generic.List(); + System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind2 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind3 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind4 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind5 = new System.Workflow.ComponentModel.ActivityBind(); + this.LogException = new System.Workflow.Activities.CodeActivity(); + this.LogArgumentException = new System.Workflow.Activities.CodeActivity(); + this.faultHandlerGeneralException = new System.Workflow.ComponentModel.FaultHandlerActivity(); + this.faultHandlerArgumentException = new System.Workflow.ComponentModel.FaultHandlerActivity(); + this.UpdateMVOnTarget = new Granfeldt.FIM.ActivityLibrary.AddRemoveMultiValueActivityAsNeeded(); + this.faultHandlersActivity1 = new System.Workflow.ComponentModel.FaultHandlersActivity(); + this.LoopAndUpdateAllTargets = new System.Workflow.Activities.WhileActivity(); + this.Enumerate = new Granfeldt.FIM.ActivityLibrary.FindResourcesActivity(); + this.SetupVariablesActivity = new System.Workflow.Activities.CodeActivity(); + this.ResolveValueToAdd = new Microsoft.ResourceManagement.Workflow.Activities.ResolveGrammarActivity(); + this.ResolveLookupXPath = new Microsoft.ResourceManagement.Workflow.Activities.ResolveGrammarActivity(); + this.GetCurrentRequest = new Microsoft.ResourceManagement.Workflow.Activities.CurrentRequestActivity(); + // + // LogException + // + this.LogException.Name = "LogException"; + this.LogException.ExecuteCode += new System.EventHandler(this.LogException_ExecuteCode); + // + // LogArgumentException + // + this.LogArgumentException.Name = "LogArgumentException"; + this.LogArgumentException.ExecuteCode += new System.EventHandler(this.LogArgumentException_ExecuteCode); + // + // faultHandlerGeneralException + // + this.faultHandlerGeneralException.Activities.Add(this.LogException); + this.faultHandlerGeneralException.FaultType = typeof(System.Exception); + this.faultHandlerGeneralException.Name = "faultHandlerGeneralException"; + // + // faultHandlerArgumentException + // + this.faultHandlerArgumentException.Activities.Add(this.LogArgumentException); + this.faultHandlerArgumentException.FaultType = typeof(System.ArgumentException); + this.faultHandlerArgumentException.Name = "faultHandlerArgumentException"; + // + // UpdateMVOnTarget + // + this.UpdateMVOnTarget.Action = null; + this.UpdateMVOnTarget.Destination = null; + this.UpdateMVOnTarget.Name = "UpdateMVOnTarget"; + this.UpdateMVOnTarget.TargetIdToUpdate = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.UpdateMVOnTarget.TargetResource = null; + this.UpdateMVOnTarget.ValueToAddOrRemove = null; + // + // faultHandlersActivity1 + // + this.faultHandlersActivity1.Activities.Add(this.faultHandlerArgumentException); + this.faultHandlersActivity1.Activities.Add(this.faultHandlerGeneralException); + this.faultHandlersActivity1.Name = "faultHandlersActivity1"; + // + // LoopAndUpdateAllTargets + // + this.LoopAndUpdateAllTargets.Activities.Add(this.UpdateMVOnTarget); + codecondition1.Condition += new System.EventHandler(this.MoreTargetsToUpdate_Condition); + this.LoopAndUpdateAllTargets.Condition = codecondition1; + this.LoopAndUpdateAllTargets.Name = "LoopAndUpdateAllTargets"; + // + // Enumerate + // + this.Enumerate.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.Enumerate.Attributes = null; + this.Enumerate.EnumeratedResourceIDs = null; + this.Enumerate.EnumeratedResources = list_11; + this.Enumerate.Name = "Enumerate"; + this.Enumerate.PageSize = 0; + this.Enumerate.SortingAttributes = null; + this.Enumerate.TotalResultsCount = 0; + this.Enumerate.XPathFilter = null; + // + // SetupVariablesActivity + // + this.SetupVariablesActivity.Name = "SetupVariablesActivity"; + this.SetupVariablesActivity.ExecuteCode += new System.EventHandler(this.SetupVariablesActivity_ExecuteCode); + // + // ResolveValueToAdd + // + activitybind1.Name = "AddRemoveFromMultiValueActivity"; + activitybind1.Path = "ValueToAddRemove"; + this.ResolveValueToAdd.Name = "ResolveValueToAdd"; + activitybind2.Name = "AddRemoveFromMultiValueActivity"; + activitybind2.Path = "ValueToAddRemoveResolved"; + this.ResolveValueToAdd.WorkflowDictionaryKey = null; + this.ResolveValueToAdd.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.ResolveGrammarActivity.GrammarExpressionProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1))); + this.ResolveValueToAdd.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.ResolveGrammarActivity.ResolvedExpressionProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind2))); + // + // ResolveLookupXPath + // + activitybind3.Name = "AddRemoveFromMultiValueActivity"; + activitybind3.Path = "LookupXPath"; + this.ResolveLookupXPath.Name = "ResolveLookupXPath"; + activitybind4.Name = "AddRemoveFromMultiValueActivity"; + activitybind4.Path = "ResolvedLookupXPath"; + this.ResolveLookupXPath.WorkflowDictionaryKey = null; + this.ResolveLookupXPath.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.ResolveGrammarActivity.GrammarExpressionProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind3))); + this.ResolveLookupXPath.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.ResolveGrammarActivity.ResolvedExpressionProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind4))); + // + // GetCurrentRequest + // + activitybind5.Name = "AddRemoveFromMultiValueActivity"; + activitybind5.Path = "CurrentRequest"; + this.GetCurrentRequest.Name = "GetCurrentRequest"; + this.GetCurrentRequest.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.CurrentRequestActivity.CurrentRequestProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind5))); + // + // AddRemoveFromMultiValueActivity + // + this.Activities.Add(this.GetCurrentRequest); + this.Activities.Add(this.ResolveLookupXPath); + this.Activities.Add(this.ResolveValueToAdd); + this.Activities.Add(this.SetupVariablesActivity); + this.Activities.Add(this.Enumerate); + this.Activities.Add(this.LoopAndUpdateAllTargets); + this.Activities.Add(this.faultHandlersActivity1); + this.Name = "AddRemoveFromMultiValueActivity"; + this.CanModifyActivities = false; + + } + + #endregion + + private CodeActivity LogException; + + private FaultHandlerActivity faultHandlerGeneralException; + + private CodeActivity LogArgumentException; + + private FaultHandlerActivity faultHandlerArgumentException; + + private FaultHandlersActivity faultHandlersActivity1; + + private Microsoft.ResourceManagement.Workflow.Activities.ResolveGrammarActivity ResolveValueToAdd; + + private AddRemoveMultiValueActivityAsNeeded UpdateMVOnTarget; + + private WhileActivity LoopAndUpdateAllTargets; + + private Microsoft.ResourceManagement.Workflow.Activities.CurrentRequestActivity GetCurrentRequest; + + private FindResourcesActivity Enumerate; + + private CodeActivity SetupVariablesActivity; + + private Microsoft.ResourceManagement.Workflow.Activities.ResolveGrammarActivity ResolveLookupXPath; + + + + + + + + + + + + + + + + + + + + + + + + + + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddRemoveFromMultivalue/Activity.AddRemoveFromMultiValue.SettingsPart.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddRemoveFromMultivalue/Activity.AddRemoveFromMultiValue.SettingsPart.cs new file mode 100644 index 0000000..b1dbfd7 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddRemoveFromMultivalue/Activity.AddRemoveFromMultiValue.SettingsPart.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Web.UI.WebControls; +using System.Workflow.ComponentModel; +using Microsoft.IdentityManagement.WebUI.Controls; +using Microsoft.ResourceManagement.Workflow.Activities; + +namespace Granfeldt.FIM.ActivityLibrary.WebUIs +{ + class AddRemoveFromMultiValueActivitySettingsPart : BaseActivitySettingsPart + { + + const string LookupXPath = "TargetObjects"; + const string ValueToAddRemove = "ValueToAddRemove"; + const string MultivalueAttributeName = "TargetMultivalueAttributename"; + const string HandleDuplicates = "HandleDuplicates"; + const string Action = "Action"; + const string Actor = "Actor"; + + protected override void CreateChildControls() + { + Table layoutTable; + layoutTable = new Table(); + + // width is set to 100% of the control size + layoutTable.Width = Unit.Percentage(100.0); + layoutTable.BorderWidth = 0; + layoutTable.CellPadding = 2; + + // add a TableRow for each textbox in the UI + layoutTable.Rows.Add(this.AddTableRowTextBox("Target object(s) (XPath Filter):", "txt" + LookupXPath, 400, 1000, false, "")); + layoutTable.Rows.Add(this.AddTableRowTextBox("Value to add, i.e. [//Target/ObjectID]:", "txt" + ValueToAddRemove, 400, 100, false, "")); + layoutTable.Rows.Add(this.AddTableRowTextBox("Target multi-value attributename:", "txt" + MultivalueAttributeName, 400, 100, false, "")); + layoutTable.Rows.Add(this.AddAddRemoveDropDownList("Action:", "txt" + Action, 400, "Add")); + layoutTable.Rows.Add(this.AddCheckbox("Add/remove duplicates", "txt" + HandleDuplicates, false)); + layoutTable.Rows.Add(this.AddActorDropDownList("Actor (run as):", "txt" + Actor, 400, WellKnownGuids.FIMServiceAccount.ToString())); + this.Controls.Add(layoutTable); + base.CreateChildControls(); + } + + public override Activity GenerateActivityOnWorkflow(SequentialWorkflow workflow) + { + Debugging.Log("GenerateActivityOnWorkflow"); + if (!this.ValidateInputs()) + { + return null; + } + AddRemoveFromMultiValueActivity act = new AddRemoveFromMultiValueActivity(); + act.ValueToAddRemove = this.GetText("txt" + ValueToAddRemove); + act.LookupXPath = this.GetText("txt" + LookupXPath); + act.MultivalueAttributeName = this.GetText("txt" + MultivalueAttributeName); + act.Actor = this.GetActorDropDownList("txt" + Actor); + act.AddRemoveAction = this.GetAddRemoveDropDownList("txt" + Action); + return act; + } + + public override void LoadActivitySettings(Activity activity) + { + Debugging.Log("LoadActivitySettings"); + AddRemoveFromMultiValueActivity thisActivity = activity as AddRemoveFromMultiValueActivity; + if (thisActivity != null) + { + this.SetText("txt" + LookupXPath, thisActivity.LookupXPath); + this.SetText("txt" + ValueToAddRemove, thisActivity.ValueToAddRemove); + this.SetText("txt" + MultivalueAttributeName, thisActivity.MultivalueAttributeName); + this.SetActorDropDownList("txt" + Actor, thisActivity.Actor); + this.SetAddRemoveDropDownList("txt" + Action, thisActivity.AddRemoveAction); + } + } + + public override ActivitySettingsPartData PersistSettings() + { + Debugging.Log("PersistSettings"); + ActivitySettingsPartData data = new ActivitySettingsPartData(); + data[LookupXPath] = this.GetText("txt" + LookupXPath); + data[MultivalueAttributeName] = this.GetText("txt" + MultivalueAttributeName); + data[ValueToAddRemove] = this.GetText("txt" + ValueToAddRemove); + data[Actor] = this.GetActorDropDownList("txt" + Actor); + data[Action] = this.GetAddRemoveDropDownList("txt" + Action); + return data; + } + + public override void RestoreSettings(ActivitySettingsPartData data) + { + Debugging.Log("RestoreSettings"); + if (null != data) + { + this.SetText("txt" + LookupXPath, (string)data[LookupXPath]); + this.SetText("txt" + MultivalueAttributeName, (string)data[MultivalueAttributeName]); + this.SetText("txt" + ValueToAddRemove, (string)data[ValueToAddRemove]); + this.SetActorDropDownList("txt" + Actor, (string)data[Actor]); + this.SetAddRemoveDropDownList("txt" + Action, (string)data[Action]); + } + } + + public override void SwitchMode(ActivitySettingsPartMode mode) + { + Debugging.Log("SwitchMode"); + bool isDisabled = (mode != ActivitySettingsPartMode.Edit); + this.SetTextBoxReadOnlyOption("txt" + LookupXPath, isDisabled); + this.SetTextBoxReadOnlyOption("txt" + MultivalueAttributeName, isDisabled); + this.SetTextBoxReadOnlyOption("txt" + ValueToAddRemove, isDisabled); + this.SetDropDownListDisabled("txt" + Actor, isDisabled); + this.SetDropDownListDisabled("txt" + Action, isDisabled); + } + + public override string Title + { + get { return "Add or Remove to/from multi-value"; } + } + + public override bool ValidateInputs() + { + Debugging.Log("ValidateInputs"); + return true; + } + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.AddRemoveFromMultivalue/Activity.AddRemoveFromMultiValue.cs b/Granfeldt.FIM.ActivityLibrary/Activity.AddRemoveFromMultivalue/Activity.AddRemoveFromMultiValue.cs new file mode 100644 index 0000000..381c7c7 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.AddRemoveFromMultivalue/Activity.AddRemoveFromMultiValue.cs @@ -0,0 +1,230 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Collections; +using System.Linq; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using System.Workflow.ComponentModel.Compiler; +using System.Workflow.ComponentModel.Serialization; +using System.Workflow.Runtime; +using System.Workflow.Activities; +using System.Workflow.Activities.Rules; +using Microsoft.ResourceManagement.WebServices.WSResourceManagement; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class AddRemoveFromMultiValueActivity : SequenceActivity + { + + #region Properties + + public AddRemoveFromMultiValueActivity() + { + InitializeComponent(); + } + + public static DependencyProperty HandleDuplicateProperty = DependencyProperty.Register("HandleDuplicate", typeof(string), typeof(AddRemoveFromMultiValueActivity)); + [Description("HandleDuplicate")] + [Category("HandleDuplicate Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string HandleDuplicate + { + get + { + return ((string)(base.GetValue(AddRemoveFromMultiValueActivity.HandleDuplicateProperty))); + } + set + { + base.SetValue(AddRemoveFromMultiValueActivity.HandleDuplicateProperty, value); + } + } + + public static DependencyProperty ActorProperty = DependencyProperty.Register("Actor", typeof(string), typeof(AddRemoveFromMultiValueActivity)); + [Description("Actor")] + [Category("Actor Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string Actor + { + get + { + return ((string)(base.GetValue(AddRemoveFromMultiValueActivity.ActorProperty))); + } + set + { + base.SetValue(AddRemoveFromMultiValueActivity.ActorProperty, value); + } + } + + public static DependencyProperty LookupXPathProperty = DependencyProperty.Register("LookupXPath", typeof(System.String), typeof(AddRemoveFromMultiValueActivity)); + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] + [BrowsableAttribute(true)] + [CategoryAttribute("Misc")] + public String LookupXPath + { + get + { + return ((string)(base.GetValue(LookupXPathProperty))); + } + set + { + base.SetValue(LookupXPathProperty, value); + } + } + + public static DependencyProperty ResolvedLookupXPathProperty = DependencyProperty.Register("ResolvedLookupXPath", typeof(System.String), typeof(AddRemoveFromMultiValueActivity)); + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] + [BrowsableAttribute(true)] + [CategoryAttribute("Misc")] + public String ResolvedLookupXPath + { + get + { + return ((string)(base.GetValue(AddRemoveFromMultiValueActivity.ResolvedLookupXPathProperty))); + } + set + { + base.SetValue(AddRemoveFromMultiValueActivity.ResolvedLookupXPathProperty, value); + } + } + + public static DependencyProperty ValueToAddRemoveProperty = DependencyProperty.Register("ValueToAddRemove", typeof(string), typeof(AddRemoveFromMultiValueActivity)); + [Description("ValueToAddRemove")] + [Category("ValueToAddRemove Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string ValueToAddRemove + { + get + { + return ((string)(base.GetValue(AddRemoveFromMultiValueActivity.ValueToAddRemoveProperty))); + } + set + { + base.SetValue(AddRemoveFromMultiValueActivity.ValueToAddRemoveProperty, value); + } + } + + public static DependencyProperty MultivalueAttributeNameProperty = DependencyProperty.Register("MultivalueAttributeName", typeof(string), typeof(AddRemoveFromMultiValueActivity)); + [Description("MultivalueAttributeName")] + [Category("MultivalueAttributeName Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string MultivalueAttributeName + { + get + { + return ((string)(base.GetValue(AddRemoveFromMultiValueActivity.MultivalueAttributeNameProperty))); + } + set + { + base.SetValue(AddRemoveFromMultiValueActivity.MultivalueAttributeNameProperty, value); + } + } + + public static DependencyProperty AddRemoveActionProperty = DependencyProperty.Register("AddRemoveAction", typeof(string), typeof(AddRemoveFromMultiValueActivity)); + [Description("AddRemoveAction")] + [Category("AddRemoveAction Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string AddRemoveAction + { + get + { + return ((string)(base.GetValue(AddRemoveFromMultiValueActivity.AddRemoveActionProperty))); + } + set + { + base.SetValue(AddRemoveFromMultiValueActivity.AddRemoveActionProperty, value); + } + } + + + public static DependencyProperty CurrentRequestProperty = DependencyProperty.Register("CurrentRequest", typeof(Microsoft.ResourceManagement.WebServices.WSResourceManagement.RequestType), typeof(AddRemoveFromMultiValueActivity)); + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] + [BrowsableAttribute(true)] + [CategoryAttribute("Misc")] + public RequestType CurrentRequest + { + get + { + return ((Microsoft.ResourceManagement.WebServices.WSResourceManagement.RequestType)(base.GetValue(CurrentRequestProperty))); + } + set + { + base.SetValue(CurrentRequestProperty, value); + } + } + + #endregion + + private void SetupVariablesActivity_ExecuteCode(object sender, EventArgs e) + { + foreach (CreateRequestParameter u in this.CurrentRequest.ParseParameters()) + { + } + + Debugging.Log("Enter SetupVariablesActivity_ExecuteCode"); + Enumerate.ActorId = new Guid(this.Actor); + Debugging.Log("XPath (resolved)", this.ResolvedLookupXPath); + Enumerate.XPathFilter = this.ResolvedLookupXPath; + Enumerate.Attributes = new string[] { this.MultivalueAttributeName }; + Enumerate.PageSize = 100; + Debugging.Log("Leave SetupVariablesActivity_ExecuteCode"); + } + + private void MoreTargetsToUpdate_Condition(object sender, ConditionalEventArgs e) + { + Debugging.Log("Enter SetupVariablesActivity_ExecuteCode"); + // return true if there are any more source values to resolve + e.Result = Enumerate.EnumeratedResources != null ? Enumerate.EnumeratedResources.Count() > 0 : false; + + if (e.Result) + { + Debugging.Log("Update target(s) left", Enumerate.EnumeratedResources.Count()); + ResourceType resource = Enumerate.EnumeratedResources[0]; + Enumerate.EnumeratedResources.RemoveAt(0); + + UpdateMVOnTarget.Action = this.AddRemoveAction; + UpdateMVOnTarget.Destination = this.MultivalueAttributeName; + UpdateMVOnTarget.ValueToAddOrRemove = this.ValueToAddRemoveResolved; + UpdateMVOnTarget.TargetIdToUpdate = resource.ObjectID.GetGuid(); + } + else + { + Debugging.Log("No more source values to resolve"); + } + } + + public static DependencyProperty ValueToAddRemoveResolvedProperty = DependencyProperty.Register("ValueToAddRemoveResolved", typeof(object), typeof(Granfeldt.FIM.ActivityLibrary.AddRemoveFromMultiValueActivity)); + + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] + [BrowsableAttribute(true)] + [CategoryAttribute("Misc")] + public String ValueToAddRemoveResolved + { + get + { + return ((string)(base.GetValue(Granfeldt.FIM.ActivityLibrary.AddRemoveFromMultiValueActivity.ValueToAddRemoveResolvedProperty))); + } + set + { + base.SetValue(Granfeldt.FIM.ActivityLibrary.AddRemoveFromMultiValueActivity.ValueToAddRemoveResolvedProperty, value); + } + } + + private void LogArgumentException_ExecuteCode(object sender, EventArgs e) + { + Debugging.Log(sender.ToString()); + Debugging.Log(faultHandlerArgumentException.Fault); + } + + private void LogException_ExecuteCode(object sender, EventArgs e) + { + Debugging.Log(sender.ToString()); + Debugging.Log(faultHandlerGeneralException.Fault); + } + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.ClearSingleValueAttribute/Activity.ClearSingleValuedAttribute.Designer.cs b/Granfeldt.FIM.ActivityLibrary/Activity.ClearSingleValueAttribute/Activity.ClearSingleValuedAttribute.Designer.cs new file mode 100644 index 0000000..1d09bda --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.ClearSingleValueAttribute/Activity.ClearSingleValuedAttribute.Designer.cs @@ -0,0 +1,133 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Collections; +using System.Drawing; +using System.Reflection; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using System.Workflow.ComponentModel.Compiler; +using System.Workflow.ComponentModel.Serialization; +using System.Workflow.Runtime; +using System.Workflow.Activities; +using System.Workflow.Activities.Rules; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class ClearSingleValuedAttributeActivity + { + #region Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + [System.Diagnostics.DebuggerNonUserCode] + private void InitializeComponent() + { + this.CanModifyActivities = true; + System.Workflow.Activities.CodeCondition codecondition1 = new System.Workflow.Activities.CodeCondition(); + System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind(); + this.UpdateResource = new Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity(); + this.NoActionNeeded = new System.Workflow.Activities.IfElseBranchActivity(); + this.ThereWasValue = new System.Workflow.Activities.IfElseBranchActivity(); + this.EndGracefully = new System.Workflow.Activities.CodeActivity(); + this.IsRemovalNeeded = new System.Workflow.Activities.IfElseActivity(); + this.ReadResource = new Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity(); + this.PrepareReading = new System.Workflow.Activities.CodeActivity(); + this.GetCurrentRequest = new Microsoft.ResourceManagement.Workflow.Activities.CurrentRequestActivity(); + // + // UpdateResource + // + this.UpdateResource.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.UpdateResource.ApplyAuthorizationPolicy = false; + this.UpdateResource.Name = "UpdateResource"; + this.UpdateResource.ResourceId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.UpdateResource.UpdateParameters = null; + // + // NoActionNeeded + // + this.NoActionNeeded.Name = "NoActionNeeded"; + // + // ThereWasValue + // + this.ThereWasValue.Activities.Add(this.UpdateResource); + codecondition1.Condition += new System.EventHandler(this.ThereWasValue_Condition); + this.ThereWasValue.Condition = codecondition1; + this.ThereWasValue.Name = "ThereWasValue"; + // + // EndGracefully + // + this.EndGracefully.Name = "EndGracefully"; + this.EndGracefully.ExecuteCode += new System.EventHandler(this.EndGracefully_ExecuteCode); + // + // IsRemovalNeeded + // + this.IsRemovalNeeded.Activities.Add(this.ThereWasValue); + this.IsRemovalNeeded.Activities.Add(this.NoActionNeeded); + this.IsRemovalNeeded.Name = "IsRemovalNeeded"; + // + // ReadResource + // + this.ReadResource.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.ReadResource.Name = "ReadResource"; + this.ReadResource.Resource = null; + this.ReadResource.ResourceId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.ReadResource.SelectionAttributes = null; + // + // PrepareReading + // + this.PrepareReading.Name = "PrepareReading"; + this.PrepareReading.ExecuteCode += new System.EventHandler(this.PrepareReading_ExecuteCode); + // + // GetCurrentRequest + // + activitybind1.Name = "ClearSingleValuedAttributeActivity"; + activitybind1.Path = "CurrentRequest"; + this.GetCurrentRequest.Name = "GetCurrentRequest"; + this.GetCurrentRequest.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.CurrentRequestActivity.CurrentRequestProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1))); + // + // ClearSingleValuedAttributeActivity + // + this.Activities.Add(this.GetCurrentRequest); + this.Activities.Add(this.PrepareReading); + this.Activities.Add(this.ReadResource); + this.Activities.Add(this.IsRemovalNeeded); + this.Activities.Add(this.EndGracefully); + this.Name = "ClearSingleValuedAttributeActivity"; + this.CanModifyActivities = false; + + } + + + + + + + + + + + + + + + + + + + + + + #endregion + + private Microsoft.ResourceManagement.Workflow.Activities.CurrentRequestActivity GetCurrentRequest; + private CodeActivity EndGracefully; + private Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity ReadResource; + private Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity UpdateResource; + private IfElseBranchActivity ThereWasValue; + private IfElseActivity IsRemovalNeeded; + private IfElseBranchActivity NoActionNeeded; + private CodeActivity PrepareReading; + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.ClearSingleValueAttribute/Activity.ClearSingleValuedAttribute.cs b/Granfeldt.FIM.ActivityLibrary/Activity.ClearSingleValueAttribute/Activity.ClearSingleValuedAttribute.cs new file mode 100644 index 0000000..dee99fe --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.ClearSingleValueAttribute/Activity.ClearSingleValuedAttribute.cs @@ -0,0 +1,180 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Collections; +using System.Drawing; +using System.Linq; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using System.Workflow.ComponentModel.Compiler; +using System.Workflow.ComponentModel.Serialization; +using System.Workflow.Runtime; +using System.Workflow.Activities; +using System.Workflow.Activities.Rules; +using Microsoft.ResourceManagement.Workflow.Activities; +using Microsoft.ResourceManagement.WebServices.WSResourceManagement; + +namespace Granfeldt.FIM.ActivityLibrary +{ + + public partial class ClearSingleValuedAttributeActivity : SequenceActivity + { + + #region Properties + + public static DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(System.String), typeof(ClearSingleValuedAttributeActivity)); + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] + [BrowsableAttribute(true)] + [CategoryAttribute("Misc")] + public String Title + { + get + { + return ((string)(base.GetValue(TitleProperty))); + } + set + { + base.SetValue(TitleProperty, value); + } + } + + public static DependencyProperty CurrentRequestProperty = DependencyProperty.Register("CurrentRequest", typeof(Microsoft.ResourceManagement.WebServices.WSResourceManagement.RequestType), typeof(ClearSingleValuedAttributeActivity)); + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] + [BrowsableAttribute(true)] + [CategoryAttribute("Misc")] + public Microsoft.ResourceManagement.WebServices.WSResourceManagement.RequestType CurrentRequest + { + get + { + return ((Microsoft.ResourceManagement.WebServices.WSResourceManagement.RequestType)(base.GetValue(CurrentRequestProperty))); + } + set + { + base.SetValue(CurrentRequestProperty, value); + } + } + + public static DependencyProperty AttributeNameProperty = DependencyProperty.Register("AttributeName", typeof(string), typeof(ClearSingleValuedAttributeActivity)); + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + [Category("Properties")] + public string AttributeName + { + get + { + return (string)base.GetValue(AttributeNameProperty); + } + set + { + base.SetValue(AttributeNameProperty, value); + } + } + + public static DependencyProperty TargetIdProperty = DependencyProperty.Register("TargetId", typeof(Guid), typeof(ClearSingleValuedAttributeActivity)); + [Description("TargetId")] + [Category("TargetId Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Guid TargetId + { + get + { + return ((Guid)(base.GetValue(ClearSingleValuedAttributeActivity.TargetIdProperty))); + } + set + { + base.SetValue(ClearSingleValuedAttributeActivity.TargetIdProperty, value); + } + } + + #endregion + + public ClearSingleValuedAttributeActivity() + { + InitializeComponent(); + } + + void ActivityStatus(object sender, ActivityExecutionStatusChangedEventArgs e) + { + Tracer.TraceInformation("execution-status name: {0}, status: {1}, result: {2}", e.Activity.Name, e.ExecutionStatus, e.ExecutionResult); + } + + private void PrepareReading_ExecuteCode(object sender, EventArgs e) + { + Tracer.Enter("preparereading_executecode"); + try + { + ReadResource.ActorId = WellKnownGuids.FIMServiceAccount; + Tracer.TraceInformation("actor-objectid: {0}", ReadResource.ActorId); + ReadResource.ResourceId = CurrentRequest.Target.GetGuid(); + Tracer.TraceInformation("target-objectid: {0}", ReadResource.ResourceId); + ReadResource.SelectionAttributes = new string[] { this.AttributeName, "DisplayName" }; + Tracer.TraceInformation("attribute: {0}", ReadResource.SelectionAttributes.FirstOrDefault()); + + ReadResource.Executing += new System.EventHandler(ActivityStatus); + ReadResource.Faulting += new System.EventHandler(ActivityStatus); + ReadResource.StatusChanged += new System.EventHandler(ActivityStatus); + ReadResource.Canceling += new System.EventHandler(ActivityStatus); + ReadResource.Compensating += new System.EventHandler(ActivityStatus); + ReadResource.Closed += new System.EventHandler(ActivityStatus); + } + catch (Exception ex) + { + Tracer.TraceError("preparereading_executecode", ex); + } + Tracer.Exit("preparereading_executecode"); + } + + private void ThereWasValue_Condition(object sender, ConditionalEventArgs e) + { + try + { + Tracer.Enter("therewasvalue_condition"); + object displayName = ReadResource.Resource["DisplayName"]; + object myValue = ReadResource.Resource[this.AttributeName]; + Tracer.TraceInformation("target-displayname {0}", displayName); + if (null != myValue) + { + Tracer.TraceInformation("current-value: {0}", ReadResource.Resource[this.AttributeName]); + UpdateResource.ActorId = WellKnownGuids.FIMServiceAccount; + Tracer.TraceInformation("actor-objectid: {0}", UpdateResource.ActorId); + UpdateResource.ResourceId = CurrentRequest.Target.GetGuid(); + Tracer.TraceInformation("target-objectid: {0}", UpdateResource.ResourceId); + UpdateRequestParameter[] UpdateParameters = new UpdateRequestParameter[] { + new UpdateRequestParameter( + this.AttributeName, + UpdateMode.Remove, + myValue)}; + UpdateResource.UpdateParameters = UpdateParameters; + + UpdateResource.Executing += new System.EventHandler(ActivityStatus); + UpdateResource.Faulting += new System.EventHandler(ActivityStatus); + UpdateResource.StatusChanged += new System.EventHandler(ActivityStatus); + UpdateResource.Canceling += new System.EventHandler(ActivityStatus); + UpdateResource.Compensating += new System.EventHandler(ActivityStatus); + UpdateResource.Closed += new System.EventHandler(ActivityStatus); + + e.Result = true; + } + else + { + Tracer.TraceInformation("no-current-value-to-remove"); + e.Result = false; + } + } + catch (Exception ex) + { + Tracer.TraceError("therewasvalue_condition'", ex); + } + Tracer.Exit("therewasvalue_condition"); + } + + private void EndGracefully_ExecuteCode(object sender, EventArgs e) + { + Tracer.TraceInformation("done"); + } + + + } + +} diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.ClearSingleValueAttribute/ClearSingleValuedAttributeActivitySettingsPart.cs b/Granfeldt.FIM.ActivityLibrary/Activity.ClearSingleValueAttribute/ClearSingleValuedAttributeActivitySettingsPart.cs new file mode 100644 index 0000000..26445a9 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Activity.ClearSingleValueAttribute/ClearSingleValuedAttributeActivitySettingsPart.cs @@ -0,0 +1,182 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text; +using System.Web.UI.WebControls; +using System.Workflow.ComponentModel; +using Microsoft.IdentityManagement.WebUI.Controls; +using Microsoft.ResourceManagement.Workflow.Activities; + +namespace Granfeldt.FIM.ActivityLibrary.WebUIs +{ + + class ClearSingleValuedAttributeActivitySettingsPart : ActivitySettingsPart + { + + /// + /// Creates a Table that contains the controls used by the activity UI + /// in the Workflow Designer of the FIM portal. Adds that Table to the + /// collection of Controls that defines each activity that can be selected + /// in the Workflow Designer of the FIM Portal. Calls the base class of + /// ActivitySettingsPart to render the controls in the UI. + /// + protected override void CreateChildControls() + { + Table controlLayoutTable; + controlLayoutTable = new Table(); + + //Width is set to 100% of the control size + controlLayoutTable.Width = Unit.Percentage(100.0); + controlLayoutTable.BorderWidth = 0; + controlLayoutTable.CellPadding = 2; + //Add a TableRow for each textbox in the UI + controlLayoutTable.Rows.Add(this.AddTableRowTextBox("Title:", "txtTitle", 400, 100, false, "")); + controlLayoutTable.Rows.Add(this.AddTableRowTextBox("Attribute:", "txtDestination", 400, 100, false, "")); + this.Controls.Add(controlLayoutTable); + + base.CreateChildControls(); + } + + #region Utility Functions + + //Create a TableRow that contains a label and a textbox. + private TableRow AddTableRowTextBox(String labelText, String controlID, int width, int maxLength, Boolean multiLine, String defaultValue) + { + TableRow row = new TableRow(); + TableCell labelCell = new TableCell(); + TableCell controlCell = new TableCell(); + Label oLabel = new Label(); + TextBox oText = new TextBox(); + + oLabel.Text = labelText; + oLabel.CssClass = base.LabelCssClass; + labelCell.Controls.Add(oLabel); + oText.ID = controlID; + oText.CssClass = base.TextBoxCssClass; + oText.Text = defaultValue; + oText.MaxLength = maxLength; + oText.Width = width; + if (multiLine) + { + oText.TextMode = TextBoxMode.MultiLine; + oText.Rows = System.Math.Min(6, (maxLength + 60) / 60); + oText.Wrap = true; + } + controlCell.Controls.Add(oText); + row.Cells.Add(labelCell); + row.Cells.Add(controlCell); + return row; + } + + string GetText(string textBoxID) + { + TextBox textBox = (TextBox)this.FindControl(textBoxID); + return textBox.Text ?? String.Empty; + } + void SetText(string textBoxID, string text) + { + TextBox textBox = (TextBox)this.FindControl(textBoxID); + if (textBox != null) + textBox.Text = text; + else + textBox.Text = ""; + } + + //Set the text box to read mode or read/write mode + void SetTextBoxReadOnlyOption(string textBoxID, bool readOnly) + { + TextBox textBox = (TextBox)this.FindControl(textBoxID); + textBox.ReadOnly = readOnly; + } + #endregion + + /// + /// Called when a user clicks the Save button in the Workflow Designer. + /// Returns an instance of the RequestLoggingActivity class that + /// has its properties set to the values entered into the text box controls + /// used in the UI of the activity. + /// + public override Activity GenerateActivityOnWorkflow(SequentialWorkflow workflow) + { + if (!this.ValidateInputs()) + { + return null; + } + ClearSingleValuedAttributeActivity ThisActivity = new ClearSingleValuedAttributeActivity(); + ThisActivity.Title = this.GetText("txtTitle"); + ThisActivity.AttributeName = this.GetText("txtDestination"); + return ThisActivity; + } + + public override void LoadActivitySettings(Activity activity) + { + ClearSingleValuedAttributeActivity ThisActivity = activity as ClearSingleValuedAttributeActivity; + if (ThisActivity != null) + { + this.SetText("txtTitle", ThisActivity.Title); + this.SetText("txtDestination", ThisActivity.AttributeName); + } + } + + /// + /// Saves the activity settings. + /// + public override ActivitySettingsPartData PersistSettings() + { + ActivitySettingsPartData data = new ActivitySettingsPartData(); + data["Title"] = this.GetText("txtTitle"); + data["Attribute"] = this.GetText("txtDestination"); + return data; + } + + /// + /// Restores the activity settings in the UI + /// + public override void RestoreSettings(ActivitySettingsPartData data) + { + if (null != data) + { + this.SetText("txtTitle", (string)data["Title"]); + this.SetText("txtDestination", (string)data["Attribute"]); + } + } + + /// + /// Switches the activity between read only and read/write mode + /// + public override void SwitchMode(ActivitySettingsPartMode mode) + { + bool readOnly = (mode == ActivitySettingsPartMode.View); + this.SetTextBoxReadOnlyOption("txtTitle", readOnly); + this.SetTextBoxReadOnlyOption("txtDestination", readOnly); + } + + /// + /// Returns the activity name. + /// + public override string Title + { + get + { + return string.Format("Clear single-valued attribute: {0}", this.GetText("txtTitle")); + } + } + + /// + /// In general, this method should be used to validate information entered + /// by the user when the activity is added to a workflow in the Workflow + /// Designer. + /// We could add code to verify that the log file path already exists on + /// the server that is hosting the FIM Portal and check that the activity + /// has permission to write to that location. However, the code + /// would only check if the log file path exists when the + /// activity is added to a workflow in the workflow designer. This class + /// will not be used when the activity is actually run. + /// For this activity we will just return true. + /// + public override bool ValidateInputs() + { + return true; + } + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Activity.CodeRun/Activity.CodeRun.cs b/Granfeldt.FIM.ActivityLibrary/Activity.CodeRun/Activity.CodeRun.cs index 6335e96..1469e0c 100644 --- a/Granfeldt.FIM.ActivityLibrary/Activity.CodeRun/Activity.CodeRun.cs +++ b/Granfeldt.FIM.ActivityLibrary/Activity.CodeRun/Activity.CodeRun.cs @@ -5,6 +5,8 @@ // due to clashes with built-in naming convention // January 18, 2013 | Soren Granfeldt // - changed update to use helper update activity +// December 16, 2015 | soren granfeldt +// - changed logging to tuse tracer using System; using System.CodeDom.Compiler; @@ -41,7 +43,7 @@ namespace Granfeldt.FIM.ActivityLibrary { get { - return ((Microsoft.ResourceManagement.WebServices.WSResourceManagement.ResourceType)(base.GetValue(Granfeldt.FIM.ActivityLibrary.CodeRunActivity.TargetResourceProperty))); + return ((ResourceType)(base.GetValue(Granfeldt.FIM.ActivityLibrary.CodeRunActivity.TargetResourceProperty))); } set { @@ -187,19 +189,19 @@ namespace Granfeldt.FIM.ActivityLibrary private void MoreParametersToResolve_Condition(object sender, ConditionalEventArgs e) { - Debugging.Log("Activity initialized"); + Tracer.Enter("Activity initialized"); // we need to convert the string array to a list to // be able to remove values if (UnresolvedParameters == null) { UnresolvedParameters = this.Parameters.ToList(); - Debugging.Log("Resolving parameters"); + Tracer.TraceInformation("Resolving parameters"); } e.Result = false; if (UnresolvedParameters.Count > 0) { this.ResolveParameterValue.GrammarExpression = UnresolvedParameters[0]; - Debugging.Log("Resolving", UnresolvedParameters[0]); + Tracer.TraceInformation("Resolving {0}", UnresolvedParameters[0]); UnresolvedParameters.RemoveAt(0); e.Result = true; } @@ -208,15 +210,15 @@ namespace Granfeldt.FIM.ActivityLibrary private void SaveResolvedValue_ExecuteCode(object sender, EventArgs e) { ResolvedParameters.Add(HttpUtility.HtmlDecode(this.ResolveParameterValue.ResolvedExpression)); - Debugging.Log("Resolved to", HttpUtility.HtmlDecode(this.ResolveParameterValue.ResolvedExpression)); + Tracer.TraceInformation("Resolved to {0}", HttpUtility.HtmlDecode(this.ResolveParameterValue.ResolvedExpression)); } private void NonExistingGrammarException_ExecuteCode(object sender, EventArgs e) { - // if we get here, the resolve has failed. If the value that we're - // trying to resolve doesn't exist, we also get here. We - // assume that there is no value and set value to null - Debugging.Log("Missing value or invalid XPath reference (returning [null])", this.ResolveParameterValue.GrammarExpression); + // if we get here, the resolve has failed. If the value that we're + // trying to resolve doesn't exist, we also get here. We + // assume that there is no value and set value to null + Tracer.TraceError("Missing value or invalid XPath reference (returning [null]) {0}", this.ResolveParameterValue.GrammarExpression); ResolvedParameters.Add(null); } @@ -246,7 +248,7 @@ namespace Granfeldt.FIM.ActivityLibrary { compileErrors.AppendFormat("Compile Error: {0} in Ln {2} Col {3}-{1}\r\n", ce.ErrorNumber, ce.ErrorText, ce.Line, ce.Column); } - Debugging.Log(new Exception("Couldn't compile\r\n" + compileErrors)); + Tracer.TraceError("Couldn't compile {0}\r\n" + compileErrors); } Assembly assembly = cr.CompiledAssembly; compiled = assembly.CreateInstance("FIMDynamicClass"); @@ -256,18 +258,18 @@ namespace Granfeldt.FIM.ActivityLibrary { if (compiled == null) { - Debugging.Log(new NullReferenceException("Code must contain a class named FIMDynamicClass and that class must contain a method called FIMDynamicFunction")); + Tracer.TraceError("Code must contain a class named FIMDynamicClass and that class must contain a method called FIMDynamicFunction"); } - Debugging.Log("Parameter count", ResolvedParameters.Count); + Tracer.TraceInformation("Parameter count {0}", ResolvedParameters.Count); foreach (object param in ResolvedParameters) { - Debugging.Log("Adding parameter", param); + Tracer.TraceInformation("Adding parameter {0}", param); } MethodInfo mi = compiled.GetType().GetMethod("FIMDynamicFunction"); - Debugging.Log("Executing code"); + Tracer.TraceInformation("Executing code"); codeReturnValue = mi.Invoke(compiled, ResolvedParameters.ToArray()); - Debugging.Log("Code executed"); - Debugging.Log("Code return value", codeReturnValue); + Tracer.TraceInformation("Code executed"); + Tracer.TraceInformation("Code return value {0}", codeReturnValue); } private void ShouldUpdateTarget_Condition(object sender, ConditionalEventArgs e) @@ -275,7 +277,9 @@ namespace Granfeldt.FIM.ActivityLibrary // try to get parent workflow. if (!SequentialWorkflow.TryGetContainingWorkflow(this, out containingWorkflow)) { - throw new InvalidOperationException("Could not get parent workflow"); + string errorMessage = "Could not get parent workflow"; + Tracer.TraceError(errorMessage); + throw new InvalidOperationException(errorMessage); } StringUtilities.ExtractWorkflowExpression(this.Destination, out destinationObject, out destinationAttribute); @@ -300,7 +304,7 @@ namespace Granfeldt.FIM.ActivityLibrary } else { - Debugging.Log(new Exception("Could not resolved destination. Please specify as [//Target/Attribute] or [//WorkflowData/Parameter]")); + Tracer.TraceError("Could not resolved destination. Please specify as [//Target/Attribute] or [//WorkflowData/Parameter]"); } } @@ -311,12 +315,12 @@ namespace Granfeldt.FIM.ActivityLibrary // assume that there is no value and set source value to null // which effectively results in a 'Delete' operation on // the target attribute value (if present) - Debugging.Log("Error: Argument Exception"); + Tracer.TraceError("Error: Argument Exception"); } private void ExitGracefully_ExecuteCode(object sender, EventArgs e) { - Debugging.Log("Activity exited"); + Tracer.TraceInformation("Activity exited"); } } } diff --git a/Granfeldt.FIM.ActivityLibrary/Base/Base.ActivitySettings/Base.ActivitySettings.cs b/Granfeldt.FIM.ActivityLibrary/Base/Base.ActivitySettings/Base.ActivitySettings.cs index 489367c..eeb3d65 100644 --- a/Granfeldt.FIM.ActivityLibrary/Base/Base.ActivitySettings/Base.ActivitySettings.cs +++ b/Granfeldt.FIM.ActivityLibrary/Base/Base.ActivitySettings/Base.ActivitySettings.cs @@ -12,11 +12,6 @@ namespace Granfeldt.FIM.ActivityLibrary class BaseActivitySettingsPart : ActivitySettingsPart { - #region Utility Functions - - /// - /// Create a TableRow that contains a label and a textbox. - /// protected TableRow AddTableRowTextBox(String labelText, String controlID, int width, int maxLength, Boolean multiLine, String defaultValue) { TableRow row = new TableRow(); @@ -45,8 +40,60 @@ namespace Granfeldt.FIM.ActivityLibrary return row; } - #region Lookup Action Dropdown + protected void SetDropdownSelectedValue(string dropDownListID, string value) + { + DropDownList ddl = (DropDownList)this.FindControl(dropDownListID); + if (ddl != null) + { + if (!string.IsNullOrEmpty(value)) + ddl.SelectedValue = value; + } + else + Debugging.Log("Cannot find control with ID '" + dropDownListID + "'"); + } + protected TableRow AddAddRemoveDropDownList(string labelText, string controlID, int width, string defaultValue) + { + TableRow row = new TableRow(); + TableCell labelCell = new TableCell(); + TableCell controlCell = new TableCell(); + + Label oLabel = new Label(); + oLabel.Text = labelText; + oLabel.CssClass = base.LabelCssClass; + labelCell.Controls.Add(oLabel); + + DropDownList ddl = new DropDownList(); + ddl.ID = controlID; + ddl.Width = width; + + ddl.Items.Add(new ListItem("Add", "Add")); + ddl.Items.Add(new ListItem("Remove", "Remove")); + ddl.SelectedValue = defaultValue; + controlCell.Controls.Add(ddl); + + row.Cells.Add(labelCell); + row.Cells.Add(controlCell); + + return row; + } + protected void SetAddRemoveDropDownList(string dropDownListID, string value) + { + SetDropdownSelectedValue(dropDownListID, value); + } + protected string GetAddRemoveDropDownList(string dropDownListID) + { + string g = ""; + DropDownList ddl = (DropDownList)this.FindControl(dropDownListID); + if (ddl != null) + { + if (!string.IsNullOrEmpty(ddl.SelectedValue)) + g = ddl.SelectedValue.ToString(); + } + else + Debugging.Log("Cannot find control with ID '" + dropDownListID + "'"); + return g; + } protected TableRow AddLookupActionDropDownList(String labelText, String controlID, int width, String defaultValue) { TableRow row = new TableRow(); @@ -91,20 +138,9 @@ namespace Granfeldt.FIM.ActivityLibrary protected void SetLookupActionDropDownList(string dropDownListID, string value) { - DropDownList ddl = (DropDownList)this.FindControl(dropDownListID); - if (ddl != null) - { - if (!string.IsNullOrEmpty(value)) - ddl.SelectedValue = value; - } - else - Debugging.Log("Cannot find control with ID '" + dropDownListID + "'"); + SetDropdownSelectedValue(dropDownListID, value); } - #endregion - - #region Actor Dropdown - protected TableRow AddActorDropDownList(String labelText, String controlID, int width, String defaultValue) { TableRow row = new TableRow(); @@ -151,20 +187,11 @@ namespace Granfeldt.FIM.ActivityLibrary return g; } - protected void SetActorDropDownList(string dropDownListID, object Guid) + protected void SetActorDropDownList(string dropDownListID, object value) { - DropDownList ddl = (DropDownList)this.FindControl(dropDownListID); - if (ddl != null) - { - if (Guid != null) - ddl.SelectedValue = Guid.ToString(); - } - else - Debugging.Log("Cannot find control with ID '" + dropDownListID + "'"); + SetDropdownSelectedValue(dropDownListID, value.ToString()); } - #endregion - protected TableRow AddCheckbox(String labelText, String controlID, bool defaultValue) { TableRow row = new TableRow(); @@ -266,7 +293,6 @@ namespace Granfeldt.FIM.ActivityLibrary Debugging.Log("Cannot find control with ID '" + dropDownListID + "'"); } - #endregion /// /// Called when a user clicks the Save button in the Workflow Designer. diff --git a/Granfeldt.FIM.ActivityLibrary/Base/Base.AttributeValue/Base.AttributeValue.cs b/Granfeldt.FIM.ActivityLibrary/Base/Base.AttributeValue/Base.AttributeValue.cs index e4abb25..94a38f1 100644 --- a/Granfeldt.FIM.ActivityLibrary/Base/Base.AttributeValue/Base.AttributeValue.cs +++ b/Granfeldt.FIM.ActivityLibrary/Base/Base.AttributeValue/Base.AttributeValue.cs @@ -7,182 +7,180 @@ using Microsoft.ResourceManagement.WebServices.WSResourceManagement; namespace Granfeldt.FIM.ActivityLibrary { - public class AttributeValue - { - //Constructors - /// - /// Creates a new instance of the object type AttributeValue. - /// - public AttributeValue() - { - this.IsResolved = false; - } - /// - /// Creates a new instance of the object type AttributeValue, and sets source and target attribute name. - /// - /// Name of the source attribute. - /// Name of the target attribute. - public AttributeValue(string sourceAttributeName, string targetAttributeName) - { - this.SourceAttributeName = sourceAttributeName; - this.TargetAttributeName = targetAttributeName; - this.IsResolved = false; - } - //Fields - private object _sourceAttributeValue; + public class AttributeValue + { + //Constructors + /// + /// Creates a new instance of the object type AttributeValue. + /// + public AttributeValue() + { + this.IsResolved = false; + } + /// + /// Creates a new instance of the object type AttributeValue, and sets source and target attribute name. + /// + /// Name of the source attribute. + /// Name of the target attribute. + public AttributeValue(string sourceAttributeName, string targetAttributeName) + { + this.SourceAttributeName = sourceAttributeName; + this.TargetAttributeName = targetAttributeName; + this.IsResolved = false; + } + //Fields + private object _sourceAttributeValue; - //Properties - public string SourceAttributeName { get; set; } - public object SourceAttributeValue - { - get - { - return this._sourceAttributeValue; - } - set - { - this._sourceAttributeValue = value; - this.IsResolved = true; - } - } - public string TargetAttributeName { get; set; } - public object TargetAttributeValue { get; set; } - public bool IsDelete { get; private set; } - /// - /// Indicates if the SourceAttributeName have been resolved. - /// This is set when SourceAttributeValue is set. - /// - public bool IsResolved { get; private set; } - /// - /// Tells if the SourceAttributeValue should be resolved from SourceAttributeName. - /// It is decided by testing if the SourceAttributeName contains a resolveable string. - /// - public bool ShouldResolve - { - get - { - if (this.IsResolved) - { - return false; - } - else - { - if (this.SourceAttributeName != null) - return this.SourceAttributeName.Trim().Contains("[//"); - else - return false; - } - } - } + //Properties + public string SourceAttributeName { get; set; } + public object SourceAttributeValue + { + get + { + return this._sourceAttributeValue; + } + set + { + this._sourceAttributeValue = value; + this.IsResolved = true; + } + } + public string TargetAttributeName { get; set; } + public object TargetAttributeValue { get; set; } + public bool IsDelete { get; private set; } + /// + /// Indicates if the SourceAttributeName have been resolved. + /// This is set when SourceAttributeValue is set. + /// + public bool IsResolved { get; private set; } + /// + /// Tells if the SourceAttributeValue should be resolved from SourceAttributeName. + /// It is decided by testing if the SourceAttributeName contains a resolveable string. + /// + public bool ShouldResolve + { + get + { + if (this.IsResolved) + { + return false; + } + else + { + if (this.SourceAttributeName != null) + return this.SourceAttributeName.Trim().Contains("[//"); + else + return false; + } + } + } - #region Methods - /// - /// Returns this AttributeValue as an UpdateRequestParameter used for updating resources in FIM. - /// - /// ObjectID of the resource being updated. - /// Tells the method what type of update to return. - /// If isDelete is true a UpdateMode is set to: Remove. - /// - /// - public UpdateRequestParameter ToUpdateRequestParameter(Guid objectId,bool isDelete) - { - if (!isDelete) - return new UpdateRequestParameter(objectId, this.TargetAttributeName, UpdateMode.Modify, FIMAttributeUtilities.FormatValue(this.SourceAttributeValue), false); - else - { - return new UpdateRequestParameter(objectId, this.TargetAttributeName, UpdateMode.Remove, this.TargetAttributeValue, false); - } - } - /// - /// Returns this AttributeValue as an UpdateRequestParameter used for updating resources in FIM, without specifying which object to update. - /// - /// Tells the method what type of update to return. - /// If isDelete is true a UpdateMode is set to: Remove. - /// - public UpdateRequestParameter ToUpdateRequestParameter(bool isDelete) - { + #region Methods + /// + /// Returns this AttributeValue as an UpdateRequestParameter used for updating resources in FIM. + /// + /// ObjectID of the resource being updated. + /// Tells the method what type of update to return. + /// If isDelete is true a UpdateMode is set to: Remove. + /// + /// + public UpdateRequestParameter ToUpdateRequestParameter(Guid objectId, bool isDelete) + { + if (!isDelete) + return new UpdateRequestParameter(objectId, this.TargetAttributeName, UpdateMode.Modify, FIMAttributeUtilities.FormatValue(this.SourceAttributeValue), false); + else + { + return new UpdateRequestParameter(objectId, this.TargetAttributeName, UpdateMode.Remove, this.TargetAttributeValue, false); + } + } + /// + /// Returns this AttributeValue as an UpdateRequestParameter used for updating resources in FIM, without specifying which object to update. + /// + /// Tells the method what type of update to return. + /// If isDelete is true a UpdateMode is set to: Remove. + /// + public UpdateRequestParameter ToUpdateRequestParameter(bool isDelete) + { - if (!isDelete) - return new UpdateRequestParameter(this.TargetAttributeName, UpdateMode.Modify, FIMAttributeUtilities.FormatValue(this.SourceAttributeValue), false); - else - { - return new UpdateRequestParameter(this.TargetAttributeName, UpdateMode.Remove, this.TargetAttributeValue, false); - } - - } - /// - /// Compares the source value with the supplied readValue parameter. - /// Also sets IsDelete to true or false - /// - /// A value to compare with the SourceValue. - /// - public virtual bool ShouldUpdate(object readValue) - { - + if (!isDelete) + return new UpdateRequestParameter(this.TargetAttributeName, UpdateMode.Modify, FIMAttributeUtilities.FormatValue(this.SourceAttributeValue), false); + else + { + return new UpdateRequestParameter(this.TargetAttributeName, UpdateMode.Remove, this.TargetAttributeValue, false); + } - // we need the original (non-converted) value if we are doing a removal as we must specify the original value (even a local date/time) - // object originalTargetValue = this.TargetAttributeValue; - object target = FIMAttributeUtilities.FormatValue(readValue); - object source = FIMAttributeUtilities.FormatValue(this.SourceAttributeValue); + } + /// + /// Compares the source value with the supplied readValue parameter. + /// Also sets IsDelete to true or false + /// + /// A value to compare with the SourceValue. + /// + public virtual bool ShouldUpdate(object readValue) + { + // we need the original (non-converted) value if we are doing a removal as we must specify the original value (even a local date/time) + // object originalTargetValue = this.TargetAttributeValue; + object target = FIMAttributeUtilities.FormatValue(readValue); + object source = FIMAttributeUtilities.FormatValue(this.SourceAttributeValue); - return getShouldUpdate(target, source); - } - /// - /// Compares the Target attribute value with the existing source attribute value. If the source attribute value is not set, - /// it will be compared on as a null value. - /// - /// Result of compare - public virtual bool ShouldUpdate() - { - object target = FIMAttributeUtilities.FormatValue(this.TargetAttributeValue); - object source = FIMAttributeUtilities.FormatValue(this.SourceAttributeValue); + return getShouldUpdate(target, source); + } + /// + /// Compares the Target attribute value with the existing source attribute value. If the source attribute value is not set, + /// it will be compared on as a null value. + /// + /// Result of compare + public virtual bool ShouldUpdate() + { + object target = FIMAttributeUtilities.FormatValue(this.TargetAttributeValue); + object source = FIMAttributeUtilities.FormatValue(this.SourceAttributeValue); - Debugging.Log(String.Format("Comparing source: {0} and target: {1}, containing the values: {2} / {3}", this.SourceAttributeName, this.TargetAttributeName, this.SourceAttributeValue, this.TargetAttributeValue)); - bool result = getShouldUpdate(target, source); - Debugging.Log(String.Format("Comparison resulted in: {0}",result)); - return result; - } - /// - /// Private method for comparing Source and Target attributes - /// - /// Taget value - /// Source value - /// Whether or not the target attribute should be updated. - private bool getShouldUpdate(object target, object source) - { - if (FIMAttributeUtilities.ValuesAreDifferent(source, target)) - { - if (source == null) - { - // we are in a delete state - Debugging.Log(string.Format("Deleting value '{1}' from {0}", this.TargetAttributeName, target == null ? "(null)" : target)); - this.IsDelete = true; - } - else - { - // we are in an update state - Debugging.Log(string.Format("Updating {0} from '{1}' to '{2}'", this.TargetAttributeName, target == null ? "(null)" : target, source)); - this.IsDelete = false; - } - return true; - } - else - { - Debugging.Log(string.Format("No need to update {0}. Value is already {1}", this.TargetAttributeName, this.TargetAttributeValue == null ? "(null)" : this.TargetAttributeValue)); - this.IsDelete = false; - return false; - } - } - /// - /// Sets the TargetAttributeValue on this AttributeValue based on the it's current TargetAttributeName. - /// - /// the ResourceType object to pull the attribute value from. - internal virtual void SetValues(ResourceType resource) - { - TargetAttributeValue = resource[this.TargetAttributeName] != null ? resource[this.TargetAttributeName] : null; - Debugging.Log(this.TargetAttributeName, this.TargetAttributeValue); - } - #endregion - } + Debugging.Log(String.Format("Comparing source: {0} and target: {1}, containing the values: {2} / {3}", this.SourceAttributeName, this.TargetAttributeName, this.SourceAttributeValue, this.TargetAttributeValue)); + bool result = getShouldUpdate(target, source); + Debugging.Log(String.Format("Comparison resulted in: {0}", result)); + return result; + } + /// + /// Private method for comparing Source and Target attributes + /// + /// Taget value + /// Source value + /// Whether or not the target attribute should be updated. + private bool getShouldUpdate(object target, object source) + { + if (FIMAttributeUtilities.ValuesAreDifferent(source, target)) + { + if (source == null) + { + // we are in a delete state + Debugging.Log(string.Format("Deleting value '{1}' from {0}", this.TargetAttributeName, target == null ? "(null)" : target)); + this.IsDelete = true; + } + else + { + // we are in an update state + Debugging.Log(string.Format("Updating {0} from '{1}' to '{2}'", this.TargetAttributeName, target == null ? "(null)" : target, source)); + this.IsDelete = false; + } + return true; + } + else + { + Debugging.Log(string.Format("No need to update {0}. Value is already {1}", this.TargetAttributeName, this.TargetAttributeValue == null ? "(null)" : this.TargetAttributeValue)); + this.IsDelete = false; + return false; + } + } + /// + /// Sets the TargetAttributeValue on this AttributeValue based on the it's current TargetAttributeName. + /// + /// the ResourceType object to pull the attribute value from. + internal virtual void SetValues(ResourceType resource) + { + TargetAttributeValue = resource[this.TargetAttributeName] != null ? resource[this.TargetAttributeName] : null; + Debugging.Log(this.TargetAttributeName, this.TargetAttributeValue); + } + #endregion + } } diff --git a/Granfeldt.FIM.ActivityLibrary/Base/Base.Common/Base.Common.cs b/Granfeldt.FIM.ActivityLibrary/Base/Base.Common/Base.Common.cs index c14e487..ad59b64 100644 --- a/Granfeldt.FIM.ActivityLibrary/Base/Base.Common/Base.Common.cs +++ b/Granfeldt.FIM.ActivityLibrary/Base/Base.Common/Base.Common.cs @@ -10,7 +10,6 @@ using Microsoft.Win32; namespace Granfeldt.FIM.ActivityLibrary { - public class WellKnownGuids { public static Guid BuiltInSynchronizationAccount = new Guid("fb89aefa-5ea1-47f1-8890-abe7797d6497"); diff --git a/Granfeldt.FIM.ActivityLibrary/Base/Helper.AddRemoveMultiValueAsNeededActivity.Designer.cs b/Granfeldt.FIM.ActivityLibrary/Base/Helper.AddRemoveMultiValueAsNeededActivity.Designer.cs new file mode 100644 index 0000000..c1c9cf2 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Base/Helper.AddRemoveMultiValueAsNeededActivity.Designer.cs @@ -0,0 +1,119 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Collections; +using System.Reflection; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using System.Workflow.ComponentModel.Compiler; +using System.Workflow.ComponentModel.Serialization; +using System.Workflow.Runtime; +using System.Workflow.Activities; +using System.Workflow.Activities.Rules; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class AddRemoveMultiValueActivityAsNeeded + { + #region Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + [System.Diagnostics.DebuggerNonUserCode] + [System.CodeDom.Compiler.GeneratedCode("", "")] + private void InitializeComponent() + { + this.CanModifyActivities = true; + System.Workflow.Activities.CodeCondition codecondition1 = new System.Workflow.Activities.CodeCondition(); + System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind(); + this.UpdateTarget = new Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity(); + this.NothingToDo = new System.Workflow.Activities.IfElseBranchActivity(); + this.DoUpdate = new System.Workflow.Activities.IfElseBranchActivity(); + this.ShouldUpdate = new System.Workflow.Activities.IfElseActivity(); + this.ReadTarget = new Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity(); + this.PrepareReadResource = new System.Workflow.Activities.CodeActivity(); + // + // UpdateTarget + // + this.UpdateTarget.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.UpdateTarget.ApplyAuthorizationPolicy = false; + this.UpdateTarget.Name = "UpdateTarget"; + this.UpdateTarget.ResourceId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.UpdateTarget.UpdateParameters = null; + // + // NothingToDo + // + this.NothingToDo.Name = "NothingToDo"; + // + // DoUpdate + // + this.DoUpdate.Activities.Add(this.UpdateTarget); + codecondition1.Condition += new System.EventHandler(this.ShouldUpdate_Condition); + this.DoUpdate.Condition = codecondition1; + this.DoUpdate.Name = "DoUpdate"; + // + // ShouldUpdate + // + this.ShouldUpdate.Activities.Add(this.DoUpdate); + this.ShouldUpdate.Activities.Add(this.NothingToDo); + this.ShouldUpdate.Name = "ShouldUpdate"; + // + // ReadTarget + // + this.ReadTarget.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.ReadTarget.Name = "ReadTarget"; + activitybind1.Name = "AddRemoveMultiValueActivityAsNeeded"; + activitybind1.Path = "TargetResource"; + this.ReadTarget.ResourceId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.ReadTarget.SelectionAttributes = null; + this.ReadTarget.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity.ResourceProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1))); + // + // PrepareReadResource + // + this.PrepareReadResource.Name = "PrepareReadResource"; + this.PrepareReadResource.ExecuteCode += new System.EventHandler(this.PrepareReadResource_ExecuteCode); + // + // AddRemoveMultiValueActivityAsNeeded + // + this.Activities.Add(this.PrepareReadResource); + this.Activities.Add(this.ReadTarget); + this.Activities.Add(this.ShouldUpdate); + this.Name = "AddRemoveMultiValueActivityAsNeeded"; + this.CanModifyActivities = false; + + } + + #endregion + + private CodeActivity PrepareReadResource; + + private Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity ReadTarget; + + private IfElseBranchActivity NothingToDo; + + private IfElseBranchActivity DoUpdate; + + private IfElseActivity ShouldUpdate; + + private Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity UpdateTarget; + + + + + + + + + + + + + + + + + + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Base/Helper.AddRemoveMultiValueAsNeededActivity.cs b/Granfeldt.FIM.ActivityLibrary/Base/Helper.AddRemoveMultiValueAsNeededActivity.cs new file mode 100644 index 0000000..09dbd4e --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Base/Helper.AddRemoveMultiValueAsNeededActivity.cs @@ -0,0 +1,221 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using System.Workflow.ComponentModel.Compiler; +using System.Workflow.ComponentModel.Serialization; +using System.Workflow.Runtime; +using System.Workflow.Activities; +using System.Workflow.Activities.Rules; +using Microsoft.ResourceManagement.Workflow.Activities; +using System.Collections.ObjectModel; +using Microsoft.ResourceManagement.WebServices; +using Microsoft.ResourceManagement.WebServices.WSResourceManagement; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class AddRemoveMultiValueActivityAsNeeded : SequenceActivity + { + public static DependencyProperty ActionProperty = DependencyProperty.Register("Action", typeof(System.String), typeof(AddRemoveMultiValueActivityAsNeeded)); + public static DependencyProperty TargetResourceProperty = DependencyProperty.Register("TargetResource", typeof(Microsoft.ResourceManagement.WebServices.WSResourceManagement.ResourceType), typeof(AddRemoveMultiValueActivityAsNeeded)); + public static DependencyProperty DestinationProperty = DependencyProperty.Register("Destination", typeof(string), typeof(AddRemoveMultiValueActivityAsNeeded)); + + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] + [BrowsableAttribute(true)] + [CategoryAttribute("Misc")] + public String Action + { + get + { + return ((string)(base.GetValue(ActionProperty))); + } + set + { + base.SetValue(ActionProperty, value); + } + } + + public static DependencyProperty TargetIdToUpdateProperty = DependencyProperty.Register("TargetIdToUpdate", typeof(Guid), typeof(AddRemoveMultiValueActivityAsNeeded)); + [Description("TargetIdToUpdate")] + [Category("TargetIdToUpdate Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Guid TargetIdToUpdate + { + get + { + return ((Guid)(base.GetValue(AddRemoveMultiValueActivityAsNeeded.TargetIdToUpdateProperty))); + } + set + { + base.SetValue(AddRemoveMultiValueActivityAsNeeded.TargetIdToUpdateProperty, value); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + [Category("Properties")] + public string Destination + { + get + { + return (string)base.GetValue(DestinationProperty); + } + set + { + base.SetValue(DestinationProperty, value); + } + } + + public static DependencyProperty ValueToAddOrRemoveProperty = DependencyProperty.Register("ValueToAddOrRemove", typeof(object), typeof(AddRemoveMultiValueActivityAsNeeded)); + [Description("ValueToAddOrRemove")] + [Category("ValueToAddOrRemove Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public object ValueToAddOrRemove + { + get + { + return ((object)(base.GetValue(AddRemoveMultiValueActivityAsNeeded.ValueToAddOrRemoveProperty))); + } + set + { + base.SetValue(AddRemoveMultiValueActivityAsNeeded.ValueToAddOrRemoveProperty, value); + } + } + + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] + [BrowsableAttribute(true)] + [CategoryAttribute("Parameters")] + public Microsoft.ResourceManagement.WebServices.WSResourceManagement.ResourceType TargetResource + { + get + { + return ((Microsoft.ResourceManagement.WebServices.WSResourceManagement.ResourceType)(base.GetValue(TargetResourceProperty))); + } + set + { + base.SetValue(TargetResourceProperty, value); + } + } + + SequentialWorkflow containingWorkflow; + List NewValues = new List(); + + public AddRemoveMultiValueActivityAsNeeded() + { + InitializeComponent(); + } + + private void PrepareReadResource_ExecuteCode(object sender, EventArgs e) + { + Debugging.Log("Enter AddRemoveMultiValue-PrepareReadResource_ExecuteCode"); + try + { + if (!SequentialWorkflow.TryGetContainingWorkflow(this, out containingWorkflow)) + { + throw new InvalidOperationException("Could not get parent workflow!"); + } + ReadTarget.ActorId = WellKnownGuids.FIMServiceAccount; + ReadTarget.ResourceId = this.TargetIdToUpdate; + ReadTarget.SelectionAttributes = new string[] { this.Destination }; + } + catch (Exception ex) + { + Debugging.Log(string.Format("Error: '{0}'", ex.Message)); + } + Debugging.Log("Exit AddRemoveMultiValue-PrepareReadResource_ExecuteCode"); + } + + private void ShouldUpdate_Condition(object sender, ConditionalEventArgs e) + { + Debugging.Log("Enter :: AddRemoveMultiValue-ShouldUpdate_Condition"); + NewValues.Add(this.ValueToAddOrRemove); + Debugging.Log("New value", this.NewValues == null ? "(null)" : this.NewValues.FirstOrDefault().ToString()); + + Debugging.Log(string.Format("Action: {0}", Action)); + try + { + // convert list of unique identifiers to list of guids + Debugging.Log("Begin converting to list"); + List currentvalues = new List(); + if (this.ReadTarget.Resource[this.Destination] != null) + { + Debugging.Log("Type", this.ReadTarget.Resource[this.Destination].GetType()); + foreach (UniqueIdentifier u in (List)this.ReadTarget.Resource[this.Destination]) + { + Debugging.Log(string.Format("Guid: {0}", u.ToString())); + currentvalues.Add(u.GetGuid()); + } + } + Debugging.Log("End converting to list"); + + e.Result = false; + if (this.Action.Equals("add", StringComparison.InvariantCultureIgnoreCase)) + { + if (currentvalues == null) + { + Debugging.Log("There is an add and no current values"); + e.Result = true; + } + else + { + if (NewValues.Except(currentvalues).Count() > 0) + { + Debugging.Log("There is an add"); + e.Result = true; + } + else + { + Debugging.Log("There is a add but its already included"); + e.Result = false; + } + } + } + else + { + if (currentvalues == null) + { + Debugging.Log("There is a remove but target value is already empty"); + e.Result = false; + } + else + { + if (currentvalues.Intersect(NewValues).Count() > 0) + { + Debugging.Log("There is a remove"); + e.Result = true; + } + else + { + Debugging.Log("There is a remove but target value is currently included"); + e.Result = false; + } + } + } + if (e.Result) + { + // prepare update request + UpdateTarget.ActorId = WellKnownGuids.FIMServiceAccount; + UpdateTarget.ResourceId = this.TargetIdToUpdate; + UpdateRequestParameter[] UpdateParameters = new UpdateRequestParameter[] { + new Microsoft.ResourceManagement.WebServices.WSResourceManagement.UpdateRequestParameter( + this.Destination, + this.Action.Equals("add", StringComparison.OrdinalIgnoreCase) ? UpdateMode.Insert : UpdateMode.Remove, + NewValues.First())}; + UpdateTarget.UpdateParameters = UpdateParameters; + } + } + catch (Exception ex) + { + Debugging.Log(string.Format("AddRemoveMultiValue-ShouldUpdate_Condition, error: '{0}'", ex.Message)); + } + Debugging.Log("Exit AddRemoveMultiValue-ShouldUpdate_Condition"); + } + + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Customer.ReconcileSoftwareGroupMembers/Customer.ReconcileSoftwareGroupMembers.Designer.cs b/Granfeldt.FIM.ActivityLibrary/Customer.ReconcileSoftwareGroupMembers/Customer.ReconcileSoftwareGroupMembers.Designer.cs new file mode 100644 index 0000000..068e650 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Customer.ReconcileSoftwareGroupMembers/Customer.ReconcileSoftwareGroupMembers.Designer.cs @@ -0,0 +1,152 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Collections; +using System.Reflection; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using System.Workflow.ComponentModel.Compiler; +using System.Workflow.ComponentModel.Serialization; +using System.Workflow.Runtime; +using System.Workflow.Activities; +using System.Workflow.Activities.Rules; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class ReconcileSoftwareGroupMembersActivity + { + #region Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + [System.Diagnostics.DebuggerNonUserCode] + [System.CodeDom.Compiler.GeneratedCode("", "")] + private void InitializeComponent() + { + this.CanModifyActivities = true; + System.Workflow.Activities.CodeCondition codecondition1 = new System.Workflow.Activities.CodeCondition(); + System.Collections.Generic.List list_11 = new System.Collections.Generic.List(); + System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind2 = new System.Workflow.ComponentModel.ActivityBind(); + this.UpdateExplicitComputerMembers = new Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity(); + this.NothingToDo = new System.Workflow.Activities.IfElseBranchActivity(); + this.UpdateExplicitMember = new System.Workflow.Activities.IfElseBranchActivity(); + this.EnumerateComputers = new Granfeldt.FIM.ActivityLibrary.FindResourcesActivity(); + this.UpdateMembers = new System.Workflow.Activities.IfElseActivity(); + this.FindUsersComputers = new System.Workflow.Activities.ReplicatorActivity(); + this.ReadTarget = new Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity(); + this.PrepareReadTarget = new System.Workflow.Activities.CodeActivity(); + // + // UpdateExplicitComputerMembers + // + this.UpdateExplicitComputerMembers.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.UpdateExplicitComputerMembers.ApplyAuthorizationPolicy = false; + this.UpdateExplicitComputerMembers.Name = "UpdateExplicitComputerMembers"; + this.UpdateExplicitComputerMembers.ResourceId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.UpdateExplicitComputerMembers.UpdateParameters = null; + // + // NothingToDo + // + this.NothingToDo.Name = "NothingToDo"; + // + // UpdateExplicitMember + // + this.UpdateExplicitMember.Activities.Add(this.UpdateExplicitComputerMembers); + codecondition1.Condition += new System.EventHandler(this.UpdateTarget_Condition); + this.UpdateExplicitMember.Condition = codecondition1; + this.UpdateExplicitMember.Name = "UpdateExplicitMember"; + // + // EnumerateComputers + // + this.EnumerateComputers.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.EnumerateComputers.Attributes = null; + this.EnumerateComputers.EnumeratedResourceIDs = null; + this.EnumerateComputers.EnumeratedResources = list_11; + this.EnumerateComputers.Name = "EnumerateComputers"; + this.EnumerateComputers.PageSize = 0; + this.EnumerateComputers.SortingAttributes = null; + this.EnumerateComputers.TotalResultsCount = 0; + this.EnumerateComputers.XPathFilter = null; + // + // UpdateMembers + // + this.UpdateMembers.Activities.Add(this.UpdateExplicitMember); + this.UpdateMembers.Activities.Add(this.NothingToDo); + this.UpdateMembers.Name = "UpdateMembers"; + activitybind1.Name = "ReconcileSoftwareGroupMembersActivity"; + activitybind1.Path = "usermembers"; + // + // FindUsersComputers + // + this.FindUsersComputers.Activities.Add(this.EnumerateComputers); + this.FindUsersComputers.ExecutionType = System.Workflow.Activities.ExecutionType.Sequence; + this.FindUsersComputers.Name = "FindUsersComputers"; + this.FindUsersComputers.ChildInitialized += new System.EventHandler(this.FindUsersComputers_ChildInitialized); + this.FindUsersComputers.ChildCompleted += new System.EventHandler(this.FindUsersComputers_ChildCompleted); + this.FindUsersComputers.Completed += new System.EventHandler(this.FindUsersComputers_Completed); + this.FindUsersComputers.Initialized += new System.EventHandler(this.FindUsersComputers_Initialized); + this.FindUsersComputers.SetBinding(System.Workflow.Activities.ReplicatorActivity.InitialChildDataProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1))); + // + // ReadTarget + // + this.ReadTarget.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.ReadTarget.Name = "ReadTarget"; + activitybind2.Name = "ReconcileSoftwareGroupMembersActivity"; + activitybind2.Path = "TargetResource"; + this.ReadTarget.ResourceId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.ReadTarget.SelectionAttributes = null; + this.ReadTarget.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity.ResourceProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind2))); + // + // PrepareReadTarget + // + this.PrepareReadTarget.Name = "PrepareReadTarget"; + this.PrepareReadTarget.ExecuteCode += new System.EventHandler(this.PrepareReadTarget_ExecuteCode); + // + // ReconcileSoftwareGroupMembersActivity + // + this.Activities.Add(this.PrepareReadTarget); + this.Activities.Add(this.ReadTarget); + this.Activities.Add(this.FindUsersComputers); + this.Activities.Add(this.UpdateMembers); + this.Name = "ReconcileSoftwareGroupMembersActivity"; + this.CanModifyActivities = false; + + } + + #endregion + + private Microsoft.ResourceManagement.Workflow.Activities.UpdateResourceActivity UpdateExplicitComputerMembers; + + private IfElseBranchActivity NothingToDo; + + private IfElseBranchActivity UpdateExplicitMember; + + private IfElseActivity UpdateMembers; + + private FindResourcesActivity EnumerateComputers; + + private ReplicatorActivity FindUsersComputers; + + private Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity ReadTarget; + + private CodeActivity PrepareReadTarget; + + + + + + + + + + + + + + + + + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Customer.ReconcileSoftwareGroupMembers/Customer.ReconcileSoftwareGroupMembers.SettingsPart.cs b/Granfeldt.FIM.ActivityLibrary/Customer.ReconcileSoftwareGroupMembers/Customer.ReconcileSoftwareGroupMembers.SettingsPart.cs new file mode 100644 index 0000000..bd93d32 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Customer.ReconcileSoftwareGroupMembers/Customer.ReconcileSoftwareGroupMembers.SettingsPart.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Web.UI.WebControls; +using System.Workflow.ComponentModel; +using Microsoft.IdentityManagement.WebUI.Controls; +using Microsoft.ResourceManagement.Workflow.Activities; + +namespace Granfeldt.FIM.ActivityLibrary.WebUIs +{ + class ReconcileSoftwareGroupMembersActivitySettingsPart : BaseActivitySettingsPart + { + + const string UserMembersAttributeName = "UserMembersAttributeName"; + const string ComputerMembersAttributeName = "ComputerMembersAttributeName"; + + protected override void CreateChildControls() + { + Table layoutTable; + layoutTable = new Table(); + + // width is set to 100% of the control size + layoutTable.Width = Unit.Percentage(100.0); + layoutTable.BorderWidth = 0; + layoutTable.CellPadding = 2; + + // add a TableRow for each textbox in the UI + layoutTable.Rows.Add(this.AddTableRowTextBox("User members attributename:", "txt" + UserMembersAttributeName, 400, 100, false, "ExplicitMemberComputerOwners")); + layoutTable.Rows.Add(this.AddTableRowTextBox("Computer members attributename:", "txt" + ComputerMembersAttributeName, 400, 100, false, "ExplicitMember")); + this.Controls.Add(layoutTable); + base.CreateChildControls(); + } + + public override Activity GenerateActivityOnWorkflow(SequentialWorkflow workflow) + { + if (!this.ValidateInputs()) + { + return null; + } + ReconcileSoftwareGroupMembersActivity act = new ReconcileSoftwareGroupMembersActivity(); + act.ComputerMembersAttributeName = this.GetText("txt" + ComputerMembersAttributeName); + act.UserMembersAttributeName = this.GetText("txt" + UserMembersAttributeName); + return act; + } + + public override void LoadActivitySettings(Activity activity) + { + ReconcileSoftwareGroupMembersActivity thisActivity = activity as ReconcileSoftwareGroupMembersActivity; + if (thisActivity != null) + { + this.SetText("txt" + UserMembersAttributeName, thisActivity.UserMembersAttributeName); + this.SetText("txt" + ComputerMembersAttributeName, thisActivity.ComputerMembersAttributeName); + } + } + + public override ActivitySettingsPartData PersistSettings() + { + ActivitySettingsPartData data = new ActivitySettingsPartData(); + data[UserMembersAttributeName] = this.GetText("txt" + UserMembersAttributeName); + data[ComputerMembersAttributeName] = this.GetText("txt" + ComputerMembersAttributeName); + return data; + } + + public override void RestoreSettings(ActivitySettingsPartData data) + { + if (null != data) + { + this.SetText("txt" + UserMembersAttributeName, (string)data[UserMembersAttributeName]); + this.SetText("txt" + ComputerMembersAttributeName, (string)data[ComputerMembersAttributeName]); + } + } + + public override void SwitchMode(ActivitySettingsPartMode mode) + { + bool isDisabled = (mode != ActivitySettingsPartMode.Edit); + this.SetTextBoxReadOnlyOption("txt" + UserMembersAttributeName, isDisabled); + this.SetTextBoxReadOnlyOption("txt" + ComputerMembersAttributeName, isDisabled); + } + + public override string Title + { + get { return "Reconcile software group members"; } + } + + public override bool ValidateInputs() + { + return true; + } + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Customer.ReconcileSoftwareGroupMembers/Customer.ReconcileSoftwareGroupMembers.cs b/Granfeldt.FIM.ActivityLibrary/Customer.ReconcileSoftwareGroupMembers/Customer.ReconcileSoftwareGroupMembers.cs new file mode 100644 index 0000000..f4b111a --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Customer.ReconcileSoftwareGroupMembers/Customer.ReconcileSoftwareGroupMembers.cs @@ -0,0 +1,219 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Collections; +using System.Linq; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using System.Workflow.ComponentModel.Compiler; +using System.Workflow.ComponentModel.Serialization; +using System.Workflow.Runtime; +using System.Workflow.Activities; +using System.Workflow.Activities.Rules; +using Microsoft.ResourceManagement.Workflow.Activities; +using System.Collections.Generic; +using Microsoft.ResourceManagement.WebServices; +using Microsoft.ResourceManagement.WebServices.WSResourceManagement; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class ReconcileSoftwareGroupMembersActivity : SequenceActivity + { + + #region Properties + + // ExplicitMemberComputerOwners + public static DependencyProperty UserMembersAttributeNameProperty = DependencyProperty.Register("UserMembersAttributeName", typeof(string), typeof(ReconcileSoftwareGroupMembersActivity)); + [Description("UserMembersAttributeName")] + [Category("UserMembersAttributeName Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string UserMembersAttributeName + { + get + { + return ((string)(base.GetValue(ReconcileSoftwareGroupMembersActivity.UserMembersAttributeNameProperty))); + } + set + { + base.SetValue(ReconcileSoftwareGroupMembersActivity.UserMembersAttributeNameProperty, value); + } + } + + // ExplicitMember + public static DependencyProperty ComputerMembersAttributeNameProperty = DependencyProperty.Register("ComputerMembersAttributeName", typeof(string), typeof(ReconcileSoftwareGroupMembersActivity)); + [Description("ComputerMembersAttributeName")] + [Category("ComputerMembersAttributeName Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string ComputerMembersAttributeName + { + get + { + return ((string)(base.GetValue(ReconcileSoftwareGroupMembersActivity.ComputerMembersAttributeNameProperty))); + } + set + { + base.SetValue(ReconcileSoftwareGroupMembersActivity.ComputerMembersAttributeNameProperty, value); + } + } + + public static DependencyProperty TargetResourceProperty = DependencyProperty.Register("TargetResource", typeof(Microsoft.ResourceManagement.WebServices.WSResourceManagement.ResourceType), typeof(Granfeldt.FIM.ActivityLibrary.ReconcileSoftwareGroupMembersActivity)); + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] + [BrowsableAttribute(true)] + [CategoryAttribute("Parameters")] + public Microsoft.ResourceManagement.WebServices.WSResourceManagement.ResourceType TargetResource + { + get + { + return ((Microsoft.ResourceManagement.WebServices.WSResourceManagement.ResourceType)(base.GetValue(Granfeldt.FIM.ActivityLibrary.ReconcileSoftwareGroupMembersActivity.TargetResourceProperty))); + } + set + { + base.SetValue(Granfeldt.FIM.ActivityLibrary.ReconcileSoftwareGroupMembersActivity.TargetResourceProperty, value); + } + } + + #endregion + + SequentialWorkflow containingWorkflow = null; + public List usermembers = new List(); + public List currentcomputermembers = new List(); + public List expectedcomputermembers = new List(); + + public ReconcileSoftwareGroupMembersActivity() + { + InitializeComponent(); + } + + void ReadTarget_Closed(object sender, ActivityExecutionStatusChangedEventArgs e) + { + Debugging.Log(string.Format("Activity {0} result", e.Activity.Name), e.ExecutionResult); + try + { + // pick up the value of the multivalue attributes read from the target + if (this.ReadTarget.Resource[this.UserMembersAttributeName] != null) + { + foreach (UniqueIdentifier u in this.ReadTarget.Resource[this.UserMembersAttributeName] as List) + { + Debugging.Log("current user member objectid", u); + usermembers.Add(u.GetGuid()); + } + } + else + { + Debugging.Log("no current user members"); + } + + if (this.ReadTarget.Resource[this.ComputerMembersAttributeName] != null) + { + foreach (UniqueIdentifier u in this.ReadTarget.Resource[this.ComputerMembersAttributeName] as List) + { + Debugging.Log("current computer member objectid", u); + currentcomputermembers.Add(u.GetGuid()); + } + } + else + { + Debugging.Log("no current computer members"); + } + } + catch (Exception ex) + { + Debugging.Log(ex); + } + } + + void EnumerateComputersClosed(object sender, ActivityExecutionStatusChangedEventArgs e) + { + Debugging.Log(string.Format("{0} {1} with result: {2}", e.ExecutionStatus, e.Activity.Name, e.ExecutionResult)); + } + + private void PrepareReadTarget_ExecuteCode(object sender, EventArgs e) + { + if (!SequentialWorkflow.TryGetContainingWorkflow(this, out containingWorkflow)) + { + throw new InvalidOperationException("Could not get parent workflow!"); + } + ReadTarget.ActorId = WellKnownGuids.FIMServiceAccount; + ReadTarget.ResourceId = containingWorkflow.TargetId; + ReadTarget.SelectionAttributes = new string[] { this.UserMembersAttributeName, this.ComputerMembersAttributeName }; + ReadTarget.Closed += new System.EventHandler(ReadTarget_Closed); + } + + private void FindUsersComputers_ChildInitialized(object sender, ReplicatorChildEventArgs e) + { + Debugging.Log("child initialized"); + Debugging.Log("activity", e.Activity.Name); + Debugging.Log("instancedata", e.InstanceData); + + // get the correct instance of the child activity + FindResourcesActivity fc = e.Activity as FindResourcesActivity; + + fc.ActorId = WellKnownGuids.FIMServiceAccount; + fc.XPathFilter = string.Format("/Computer[ComputerLocalAdministrator='{0}']", e.InstanceData as Guid?); + Debugging.Log("enumeration filter", fc.XPathFilter); + fc.Attributes = new string[] { "ObjectID" }; + fc.PageSize = 100; + fc.StatusChanged += new System.EventHandler(EnumerateComputersClosed); + fc.Faulting += new System.EventHandler(EnumerateComputersClosed); + } + + private void FindUsersComputers_ChildCompleted(object sender, ReplicatorChildEventArgs e) + { + Debugging.Log("child completed"); + // get the correct instance of the child activity + FindResourcesActivity fc = e.Activity as FindResourcesActivity; + if (fc != null) + { + Debugging.Log("enumerate computers result count", fc.TotalResultsCount); + if (fc.EnumeratedResourceIDs != null) + { + foreach (Guid computer in fc.EnumeratedResourceIDs.ToList()) + { + Debugging.Log("expected member", computer); + expectedcomputermembers.Add(computer); + } + } + } + } + + private void FindUsersComputers_Completed(object sender, EventArgs e) + { + Debugging.Log("completed"); + } + + private void FindUsersComputers_Initialized(object sender, EventArgs e) + { + Debugging.Log("initialized"); + } + + private void UpdateTarget_Condition(object sender, ConditionalEventArgs e) + { + List updateparameters = new List(); + + e.Result = false; + foreach (Guid member in currentcomputermembers.Except(expectedcomputermembers)) + { + Debugging.Log("remove currentmember", member); + e.Result = true; + updateparameters.Add( + new UpdateRequestParameter(this.ComputerMembersAttributeName, UpdateMode.Remove, member) + ); + } + foreach (Guid member in expectedcomputermembers.Except(currentcomputermembers)) + { + Debugging.Log("add expected member", member); + e.Result = true; + updateparameters.Add( + new UpdateRequestParameter(this.ComputerMembersAttributeName, UpdateMode.Insert, member) + ); + } + UpdateExplicitComputerMembers.ActorId = WellKnownGuids.FIMServiceAccount; + UpdateExplicitComputerMembers.ResourceId = containingWorkflow.TargetId; + UpdateExplicitComputerMembers.UpdateParameters = updateparameters.ToArray(); + UpdateExplicitComputerMembers.StatusChanged += new System.EventHandler(EnumerateComputersClosed); + } + + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Customer.UpdateReferenceOnRegExMatch/UpdateReferenceOnRegExMatchActivity.Designer.cs b/Granfeldt.FIM.ActivityLibrary/Customer.UpdateReferenceOnRegExMatch/UpdateReferenceOnRegExMatchActivity.Designer.cs new file mode 100644 index 0000000..758b5a7 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Customer.UpdateReferenceOnRegExMatch/UpdateReferenceOnRegExMatchActivity.Designer.cs @@ -0,0 +1,164 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Collections; +using System.Reflection; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using System.Workflow.ComponentModel.Compiler; +using System.Workflow.ComponentModel.Serialization; +using System.Workflow.Runtime; +using System.Workflow.Activities; +using System.Workflow.Activities.Rules; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public partial class UpdateReferenceOnRegExMatchActivity + { + #region Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + [System.Diagnostics.DebuggerNonUserCode] + [System.CodeDom.Compiler.GeneratedCode("", "")] + private void InitializeComponent() + { + this.CanModifyActivities = true; + System.Collections.Generic.List list_11 = new System.Collections.Generic.List(); + System.Workflow.Activities.CodeCondition codecondition1 = new System.Workflow.Activities.CodeCondition(); + System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind(); + System.Workflow.ComponentModel.ActivityBind activitybind2 = new System.Workflow.ComponentModel.ActivityBind(); + this.PrepareClearingReference = new System.Workflow.Activities.CodeActivity(); + this.PrepareUpdateReference = new System.Workflow.Activities.CodeActivity(); + this.FindUser = new Granfeldt.FIM.ActivityLibrary.FindResourcesActivity(); + this.NoClearReference = new System.Workflow.Activities.IfElseBranchActivity(); + this.YesUpdateReference = new System.Workflow.Activities.IfElseBranchActivity(); + this.UpdateUserReference = new Granfeldt.FIM.ActivityLibrary.UpdateSingleValueAttributeAsNeededActivity(); + this.DoesComputerNameContainUsername = new System.Workflow.Activities.IfElseActivity(); + this.ReadTarget = new Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity(); + this.PrepareReadTarget = new System.Workflow.Activities.CodeActivity(); + this.GetCurrentRequest = new Microsoft.ResourceManagement.Workflow.Activities.CurrentRequestActivity(); + // + // PrepareClearingReference + // + this.PrepareClearingReference.Name = "PrepareClearingReference"; + this.PrepareClearingReference.ExecuteCode += new System.EventHandler(this.PrepareClearingReferenceCode); + // + // PrepareUpdateReference + // + this.PrepareUpdateReference.Name = "PrepareUpdateReference"; + this.PrepareUpdateReference.ExecuteCode += new System.EventHandler(this.PrepareUpdateReferenceCode); + // + // FindUser + // + this.FindUser.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.FindUser.Attributes = null; + this.FindUser.EnumeratedResourceIDs = null; + this.FindUser.EnumeratedResources = list_11; + this.FindUser.Name = "FindUser"; + this.FindUser.PageSize = 0; + this.FindUser.SortingAttributes = null; + this.FindUser.TotalResultsCount = 0; + this.FindUser.XPathFilter = null; + // + // NoClearReference + // + this.NoClearReference.Activities.Add(this.PrepareClearingReference); + this.NoClearReference.Name = "NoClearReference"; + // + // YesUpdateReference + // + this.YesUpdateReference.Activities.Add(this.FindUser); + this.YesUpdateReference.Activities.Add(this.PrepareUpdateReference); + codecondition1.Condition += new System.EventHandler(this.IfComputerNameContainsUsername); + this.YesUpdateReference.Condition = codecondition1; + this.YesUpdateReference.Name = "YesUpdateReference"; + // + // UpdateUserReference + // + this.UpdateUserReference.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.UpdateUserReference.AttributeName = null; + this.UpdateUserReference.Name = "UpdateUserReference"; + this.UpdateUserReference.NewValue = null; + this.UpdateUserReference.TargetId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.UpdateUserReference.TargetResource = null; + // + // DoesComputerNameContainUsername + // + this.DoesComputerNameContainUsername.Activities.Add(this.YesUpdateReference); + this.DoesComputerNameContainUsername.Activities.Add(this.NoClearReference); + this.DoesComputerNameContainUsername.Name = "DoesComputerNameContainUsername"; + // + // ReadTarget + // + this.ReadTarget.ActorId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.ReadTarget.Name = "ReadTarget"; + activitybind1.Name = "UpdateReferenceOnRegExMatchActivity"; + activitybind1.Path = "TargetResource"; + this.ReadTarget.ResourceId = new System.Guid("00000000-0000-0000-0000-000000000000"); + this.ReadTarget.SelectionAttributes = null; + this.ReadTarget.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity.ResourceProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1))); + // + // PrepareReadTarget + // + this.PrepareReadTarget.Name = "PrepareReadTarget"; + this.PrepareReadTarget.ExecuteCode += new System.EventHandler(this.PrepareReadTargetCode); + // + // GetCurrentRequest + // + activitybind2.Name = "UpdateReferenceOnRegExMatchActivity"; + activitybind2.Path = "CurrentRequest"; + this.GetCurrentRequest.Name = "GetCurrentRequest"; + this.GetCurrentRequest.SetBinding(Microsoft.ResourceManagement.Workflow.Activities.CurrentRequestActivity.CurrentRequestProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind2))); + // + // UpdateReferenceOnRegExMatchActivity + // + this.Activities.Add(this.GetCurrentRequest); + this.Activities.Add(this.PrepareReadTarget); + this.Activities.Add(this.ReadTarget); + this.Activities.Add(this.DoesComputerNameContainUsername); + this.Activities.Add(this.UpdateUserReference); + this.Name = "UpdateReferenceOnRegExMatchActivity"; + this.CanModifyActivities = false; + + } + + #endregion + + private CodeActivity PrepareUpdateReference; + + private CodeActivity PrepareClearingReference; + + private UpdateSingleValueAttributeAsNeededActivity UpdateUserReference; + + private FindResourcesActivity FindUser; + + private IfElseBranchActivity NoClearReference; + + private IfElseBranchActivity YesUpdateReference; + + private IfElseActivity DoesComputerNameContainUsername; + + private CodeActivity PrepareReadTarget; + + private Microsoft.ResourceManagement.Workflow.Activities.ReadResourceActivity ReadTarget; + + private Microsoft.ResourceManagement.Workflow.Activities.CurrentRequestActivity GetCurrentRequest; + + + + + + + + + + + + + + + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Customer.UpdateReferenceOnRegExMatch/UpdateReferenceOnRegExMatchActivity.SettingsPart.cs b/Granfeldt.FIM.ActivityLibrary/Customer.UpdateReferenceOnRegExMatch/UpdateReferenceOnRegExMatchActivity.SettingsPart.cs new file mode 100644 index 0000000..6c7ab98 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Customer.UpdateReferenceOnRegExMatch/UpdateReferenceOnRegExMatchActivity.SettingsPart.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Web.UI.WebControls; +using System.Workflow.ComponentModel; +using Microsoft.IdentityManagement.WebUI.Controls; +using Microsoft.ResourceManagement.Workflow.Activities; + +namespace Granfeldt.FIM.ActivityLibrary.WebUIs +{ + class UpdateReferenceOnRegExMatchActivitySettingsPart : BaseActivitySettingsPart + { + + const string RegExFilter = "RegExFilter"; + const string PositiveRegExFilter = "PositiveRegExFilter"; + const string ComputerNameAttributeName = "ComputerNameAttribute"; + const string UserNameAttributeName = "UserNameAttributeName"; + const string TargetReferenceAttributeName = "TargetReferenceAttributeName"; + const string Actor = "Actor"; + + protected override void CreateChildControls() + { + Table layoutTable; + layoutTable = new Table(); + + // width is set to 100% of the control size + layoutTable.Width = Unit.Percentage(100.0); + layoutTable.BorderWidth = 0; + layoutTable.CellPadding = 2; + + // add a TableRow for each textbox in the UI + layoutTable.Rows.Add(this.AddTableRowTextBox("Regex Filter:", "txt" + RegExFilter, 400, 100, false, "")); + layoutTable.Rows.Add(this.AddTableRowTextBox("Positive Regex Filter:
if computername match filter, username is always updated", "txt" + PositiveRegExFilter, 400, 100, false, "")); + layoutTable.Rows.Add(this.AddTableRowTextBox("ComputerName attribute:", "txt" + ComputerNameAttributeName, 400, 100, false, "")); + layoutTable.Rows.Add(this.AddTableRowTextBox("UserName attribute:", "txt" + UserNameAttributeName, 400, 100, false, "")); + layoutTable.Rows.Add(this.AddTableRowTextBox("User reference attribute:", "txt" + TargetReferenceAttributeName, 400, 100, false, "")); + layoutTable.Rows.Add(this.AddActorDropDownList("Actor (run as):", "txt" + Actor, 400, WellKnownGuids.FIMServiceAccount.ToString())); + this.Controls.Add(layoutTable); + base.CreateChildControls(); + } + + public override Activity GenerateActivityOnWorkflow(SequentialWorkflow workflow) + { + Debugging.Log("GenerateActivityOnWorkflow"); + if (!this.ValidateInputs()) + { + return null; + } + UpdateReferenceOnRegExMatchActivity act = new UpdateReferenceOnRegExMatchActivity(); + act.RegExFilter = this.GetText("txt" + RegExFilter); + act.PositiveRegExFilter = this.GetText("txt" + PositiveRegExFilter); + act.ComputerNameAttributeName = this.GetText("txt" + ComputerNameAttributeName); + act.UserNameAttributeName = this.GetText("txt" + UserNameAttributeName); + act.TargetReferenceAttributeName = this.GetText("txt" + TargetReferenceAttributeName); + act.Actor = this.GetActorDropDownList("txt" + Actor); + return act; + } + + public override void LoadActivitySettings(Activity activity) + { + Debugging.Log("LoadActivitySettings"); + UpdateReferenceOnRegExMatchActivity act = activity as UpdateReferenceOnRegExMatchActivity; + if (act != null) + { + this.SetText("txt" + RegExFilter, act.RegExFilter); + this.SetText("txt" + PositiveRegExFilter, act.PositiveRegExFilter); + this.SetText("txt" + ComputerNameAttributeName, act.ComputerNameAttributeName); + this.SetText("txt" + UserNameAttributeName, act.UserNameAttributeName); + this.SetText("txt" + TargetReferenceAttributeName, act.TargetReferenceAttributeName); + this.SetActorDropDownList("txt" + Actor, act.Actor); + } + } + + public override ActivitySettingsPartData PersistSettings() + { + Debugging.Log("PersistSettings"); + ActivitySettingsPartData data = new ActivitySettingsPartData(); + data[RegExFilter] = this.GetText("txt" + RegExFilter); + data[PositiveRegExFilter] = this.GetText("txt" + PositiveRegExFilter); + data[UserNameAttributeName] = this.GetText("txt" + UserNameAttributeName); + data[ComputerNameAttributeName] = this.GetText("txt" + ComputerNameAttributeName); + data[TargetReferenceAttributeName] = this.GetText("txt" + TargetReferenceAttributeName); + data[Actor] = this.GetActorDropDownList("txt" + Actor); + return data; + } + + public override void RestoreSettings(ActivitySettingsPartData data) + { + Debugging.Log("RestoreSettings"); + if (null != data) + { + this.SetText("txt" + RegExFilter, (string)data[RegExFilter]); + this.SetText("txt" + PositiveRegExFilter, (string)data[PositiveRegExFilter]); + this.SetText("txt" + UserNameAttributeName, (string)data[UserNameAttributeName]); + this.SetText("txt" + ComputerNameAttributeName, (string)data[ComputerNameAttributeName]); + this.SetText("txt" + TargetReferenceAttributeName, (string)data[TargetReferenceAttributeName]); + this.SetActorDropDownList("txt" + Actor, (string)data[Actor]); + } + } + + public override void SwitchMode(ActivitySettingsPartMode mode) + { + Debugging.Log("SwitchMode"); + bool isDisabled = (mode != ActivitySettingsPartMode.Edit); + this.SetTextBoxReadOnlyOption("txt" + RegExFilter, isDisabled); + this.SetTextBoxReadOnlyOption("txt" + PositiveRegExFilter, isDisabled); + this.SetTextBoxReadOnlyOption("txt" + UserNameAttributeName, isDisabled); + this.SetTextBoxReadOnlyOption("txt" + ComputerNameAttributeName, isDisabled); + this.SetTextBoxReadOnlyOption("txt" + TargetReferenceAttributeName, isDisabled); + this.SetDropDownListDisabled("txt" + Actor, isDisabled); + } + + public override string Title + { + get { return "Update Reference on regular expression match"; } + } + + public override bool ValidateInputs() + { + Debugging.Log("ValidateInputs"); + return true; + } + } +} diff --git a/Granfeldt.FIM.ActivityLibrary/Customer.UpdateReferenceOnRegExMatch/UpdateReferenceOnRegExMatchActivity.cs b/Granfeldt.FIM.ActivityLibrary/Customer.UpdateReferenceOnRegExMatch/UpdateReferenceOnRegExMatchActivity.cs new file mode 100644 index 0000000..9e8d554 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Customer.UpdateReferenceOnRegExMatch/UpdateReferenceOnRegExMatchActivity.cs @@ -0,0 +1,259 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Collections; +using System.Linq; +using System.Workflow.ComponentModel; +using System.Workflow.ComponentModel.Design; +using System.Workflow.ComponentModel.Compiler; +using System.Workflow.ComponentModel.Serialization; +using System.Workflow.Runtime; +using System.Workflow.Activities; +using System.Workflow.Activities.Rules; +using System.Text.RegularExpressions; +using Microsoft.ResourceManagement.WebServices.WSResourceManagement; + +namespace Granfeldt.FIM.ActivityLibrary +{ + + public partial class UpdateReferenceOnRegExMatchActivity : SequenceActivity + { + + + #region Properties + + public static DependencyProperty CurrentRequestProperty = DependencyProperty.Register("CurrentRequest", typeof(RequestType), typeof(UpdateReferenceOnRegExMatchActivity)); + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] + [BrowsableAttribute(true)] + [CategoryAttribute("Misc")] + public RequestType CurrentRequest + { + get + { + return ((Microsoft.ResourceManagement.WebServices.WSResourceManagement.RequestType)(base.GetValue(Granfeldt.FIM.ActivityLibrary.UpdateReferenceOnRegExMatchActivity.CurrentRequestProperty))); + } + set + { + base.SetValue(Granfeldt.FIM.ActivityLibrary.UpdateReferenceOnRegExMatchActivity.CurrentRequestProperty, value); + } + } + + // ^w8(ab|fe)pc|[1|2|3]*[w|t]$ + public static DependencyProperty RegExFilterProperty = DependencyProperty.Register("RegExFilter", typeof(string), typeof(UpdateReferenceOnRegExMatchActivity)); + [Description("RegExFilter")] + [Category("RegExFilter Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string RegExFilter + { + get + { + return ((string)(base.GetValue(UpdateReferenceOnRegExMatchActivity.RegExFilterProperty))); + } + set + { + base.SetValue(UpdateReferenceOnRegExMatchActivity.RegExFilterProperty, value); + } + } + + public static DependencyProperty PositiveRegExFilterProperty = DependencyProperty.Register("PositiveRegExFilter", typeof(string), typeof(UpdateReferenceOnRegExMatchActivity)); + [Description("PositiveRegExFilter")] + [Category("PositiveRegExFilter Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string PositiveRegExFilter + { + get + { + return ((string)(base.GetValue(UpdateReferenceOnRegExMatchActivity.PositiveRegExFilterProperty))); + } + set + { + base.SetValue(UpdateReferenceOnRegExMatchActivity.PositiveRegExFilterProperty, value); + } + } + + public static DependencyProperty ComputerNameAttributeNameProperty = DependencyProperty.Register("ComputerNameAttributeName", typeof(string), typeof(UpdateReferenceOnRegExMatchActivity)); + [Description("ComputerNameAttributeName")] + [Category("ComputerNameAttributeName Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string ComputerNameAttributeName + { + get + { + return ((string)(base.GetValue(UpdateReferenceOnRegExMatchActivity.ComputerNameAttributeNameProperty))); + } + set + { + base.SetValue(UpdateReferenceOnRegExMatchActivity.ComputerNameAttributeNameProperty, value); + } + } + + public static DependencyProperty UserNameAttributeNameProperty = DependencyProperty.Register("UserNameAttributeName", typeof(string), typeof(UpdateReferenceOnRegExMatchActivity)); + [Description("UserNameAttributeName")] + [Category("UserNameAttribute Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string UserNameAttributeName + { + get + { + return ((string)(base.GetValue(UpdateReferenceOnRegExMatchActivity.UserNameAttributeNameProperty))); + } + set + { + base.SetValue(UpdateReferenceOnRegExMatchActivity.UserNameAttributeNameProperty, value); + } + } + + public static DependencyProperty TargetReferenceAttributeNameProperty = DependencyProperty.Register("TargetReferenceAttributeName", typeof(string), typeof(UpdateReferenceOnRegExMatchActivity)); + [Description("TargetReferenceAttributeName")] + [Category("TargetReferenceAttributeName Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string TargetReferenceAttributeName + { + get + { + return ((string)(base.GetValue(UpdateReferenceOnRegExMatchActivity.TargetReferenceAttributeNameProperty))); + } + set + { + base.SetValue(UpdateReferenceOnRegExMatchActivity.TargetReferenceAttributeNameProperty, value); + } + } + + public static DependencyProperty TargetResourceProperty = DependencyProperty.Register("TargetResource", typeof(Microsoft.ResourceManagement.WebServices.WSResourceManagement.ResourceType), typeof(Granfeldt.FIM.ActivityLibrary.UpdateReferenceOnRegExMatchActivity)); + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] + [BrowsableAttribute(true)] + [CategoryAttribute("Parameters")] + public ResourceType TargetResource + { + get + { + return ((Microsoft.ResourceManagement.WebServices.WSResourceManagement.ResourceType)(base.GetValue(Granfeldt.FIM.ActivityLibrary.UpdateReferenceOnRegExMatchActivity.TargetResourceProperty))); + } + set + { + base.SetValue(Granfeldt.FIM.ActivityLibrary.UpdateReferenceOnRegExMatchActivity.TargetResourceProperty, value); + } + } + + public static DependencyProperty ActorProperty = DependencyProperty.Register("Actor", typeof(string), typeof(UpdateReferenceOnRegExMatchActivity)); + [Description("Actor")] + [Category("Actor Category")] + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string Actor + { + get + { + return ((string)(base.GetValue(UpdateReferenceOnRegExMatchActivity.ActorProperty))); + } + set + { + base.SetValue(UpdateReferenceOnRegExMatchActivity.ActorProperty, value); + } + } + + #endregion + + public UpdateReferenceOnRegExMatchActivity() + { + InitializeComponent(); + } + + private void PrepareReadTargetCode(object sender, EventArgs e) + { + Debugging.Log("Enter PrepareReadTargetCode"); + Debugging.Log("Actor", this.Actor); + Debugging.Log("Computername attribute", this.ComputerNameAttributeName); + Debugging.Log("Usernamename attribute", this.UserNameAttributeName); + Debugging.Log("Request targetid", CurrentRequest.Target.GetGuid()); + + ReadTarget.ActorId = new Guid(this.Actor); + ReadTarget.SelectionAttributes = new string[] { this.ComputerNameAttributeName, this.UserNameAttributeName }; + ReadTarget.ResourceId = CurrentRequest.Target.GetGuid(); + ReadTarget.StatusChanged += new System.EventHandler(Activity_StatusChanged); + + Debugging.Log("Exit PrepareReadTargetCode"); + } + + void Activity_StatusChanged(object sender, ActivityExecutionStatusChangedEventArgs e) + { + Debugging.Log(string.Format("{0} {1} with result: {2}", e.ExecutionStatus, e.Activity.Name, e.ExecutionResult)); + } + + + private void IfComputerNameContainsUsername(object sender, ConditionalEventArgs e) + { + Debugging.Log("Enter IfComputerNameContainsUsername"); + + // always setup defaults for updating + UpdateUserReference.ActorId = new Guid(this.Actor); + UpdateUserReference.AttributeName = this.TargetReferenceAttributeName; + UpdateUserReference.TargetId = CurrentRequest.Target.GetGuid(); + UpdateUserReference.NewValue = null; + UpdateUserReference.StatusChanged += new System.EventHandler(Activity_StatusChanged); + + if (ReadTarget.Resource == null) + { + Debugging.Log("Could not read request target"); + e.Result = false; + return; + } + + object computername = ReadTarget.Resource[this.ComputerNameAttributeName]; + object username = ReadTarget.Resource[this.UserNameAttributeName]; + + Debugging.Log("Computername", computername); + Debugging.Log("Username", username); + + e.Result = false; + if ((username == null) || (computername == null)) + { + Debugging.Log(string.Format("{0} or {1} is null. No match", this.ComputerNameAttributeName, this.UserNameAttributeName)); + return; + } + + string computerusername = Regex.Replace(computername as string, this.RegExFilter, "", RegexOptions.IgnoreCase); + Debugging.Log("Regex trimmed computername", computerusername); + if ((computerusername.Equals(username as string, StringComparison.OrdinalIgnoreCase)) || (Regex.IsMatch(computername as string, this.PositiveRegExFilter, RegexOptions.IgnoreCase))) + { + Debugging.Log("We got a match; doing lookup for user", username); + e.Result = true; + + // set up lookup code + FindUser.ActorId = WellKnownGuids.FIMServiceAccount; + FindUser.Attributes = new string[] { "ObjectID" }; + FindUser.XPathFilter = string.Format("/Person[AccountName='{0}']", username); + FindUser.PageSize = 100; + FindUser.StatusChanged += new System.EventHandler(Activity_StatusChanged); + return; + } + Debugging.Log("Exit IfComputerNameContainsUsername"); + } + + private void PrepareUpdateReferenceCode(object sender, EventArgs e) + { + Debugging.Log("Enter PrepareUpdateReferenceCode"); + if (FindUser.TotalResultsCount == 1) + { + ResourceType r; + r = FindUser.EnumeratedResources[0]; + UpdateUserReference.NewValue = r["ObjectID"]; + } + Debugging.Log("Exit PrepareUpdateReferenceCode"); + } + + private void PrepareClearingReferenceCode(object sender, EventArgs e) + { + Debugging.Log("Enter PrepareClearingReferenceCode"); + // all setup for clearing is done in IfComputerNameContainsUsername + Debugging.Log("Exit PrepareClearingReferenceCode"); + } + + } + +} diff --git a/Granfeldt.FIM.ActivityLibrary/Granfeldt.FIM.ActivityLibrary.csproj b/Granfeldt.FIM.ActivityLibrary/Granfeldt.FIM.ActivityLibrary.csproj index 911b566..14812d9 100644 --- a/Granfeldt.FIM.ActivityLibrary/Granfeldt.FIM.ActivityLibrary.csproj +++ b/Granfeldt.FIM.ActivityLibrary/Granfeldt.FIM.ActivityLibrary.csproj @@ -36,23 +36,19 @@ False - .\Microsoft.IdentityManagement.Activities.dll - - - ..\..\..\..\..\..\Program Files\Microsoft Forefront Identity Manager\2010\Service\Microsoft.IdentityManagement.SettingsContract.dll - False + FIMDLLs\Microsoft.IdentityManagement.Activities.dll False - .\Microsoft.IdentityManagement.WebUI.Controls.dll + FIMDLLs\Microsoft.IdentityManagement.WebUI.Controls.dll False - .\Microsoft.IdentityManagement.WFExtensionInterfaces.dll + FIMDLLs\Microsoft.IdentityManagement.WFExtensionInterfaces.dll False - ..\..\..\..\..\..\Program Files\Microsoft Forefront Identity Manager\2010\Service\Microsoft.ResourceManagement.dll + FIMDLLs\Microsoft.ResourceManagement.dll @@ -68,6 +64,20 @@ + + Component + + + Activity.AddRemoveFromMultiValue.cs + + + + Component + + + Activity.ClearSingleValuedAttribute.cs + + Component @@ -108,6 +118,12 @@ + + Component + + + Helper.AddRemoveMultiValueAsNeededActivity.cs + Component @@ -126,6 +142,7 @@ True Settings.settings + Always diff --git a/Granfeldt.FIM.ActivityLibrary/Install-Workflows.ps1 b/Granfeldt.FIM.ActivityLibrary/Install-Workflows.ps1 index 5eecca2..86fc6b4 100644 --- a/Granfeldt.FIM.ActivityLibrary/Install-Workflows.ps1 +++ b/Granfeldt.FIM.ActivityLibrary/Install-Workflows.ps1 @@ -1,5 +1,7 @@ # January 30, 2013 | Soren Granfeldt # - changed LookupAttributeValue to LookupValueActivity +# december 16, 2015 | soren granfeldt +# - added ClearSingleValueActivity PARAM ( @@ -8,6 +10,7 @@ PARAM [switch] $CreateLookupValueActivity, [switch] $CreateCopyValuesActivity, [switch] $CreateCreateObjectActivity, + [switch] $CreateClearSingleValueActivity, [switch] $CreateDeleteObjectActivity ) @@ -95,6 +98,19 @@ PROCESS .\New-FIMActivityInformationConfigurationObject.ps1 @Params } + if ($CreateClearSingleValueActivity) + { + $Params = @{ ` + DisplayName = 'Clear Single Value' + Description = 'Clears a single value attribute' + ActivityName = "$ManifestModule.ClearSingleValuedAttributeActivity" + TypeName = "$ManifestModule.WebUIs.ClearSingleValuedAttributeActivitySettingsPart" + IsActionActivity = $true + AssemblyName = $LoadedAssembly.Fullname + } + $Params + .\New-FIMActivityInformationConfigurationObject.ps1 @Params + } } END diff --git a/Granfeldt.FIM.ActivityLibrary/Properties/AssemblyInfo.cs b/Granfeldt.FIM.ActivityLibrary/Properties/AssemblyInfo.cs index aec7822..b81fddc 100644 --- a/Granfeldt.FIM.ActivityLibrary/Properties/AssemblyInfo.cs +++ b/Granfeldt.FIM.ActivityLibrary/Properties/AssemblyInfo.cs @@ -30,4 +30,4 @@ using System.Runtime.InteropServices; //NOTE: When updating the namespaces in the project please add new or update existing the XmlnsDefinitionAttribute //You can add additional attributes in order to map any additional namespaces you have in the project //[assembly: System.Workflow.ComponentModel.Serialization.XmlnsDefinition("http://schemas.com/Granfeldt.FIM.ActivityLibrary", "Granfeldt.FIM.ActivityLibrary")] -[assembly: AssemblyFileVersionAttribute("1.5.0.0")] +[assembly: AssemblyFileVersion("1.6.0.1612")] diff --git a/Granfeldt.FIM.ActivityLibrary/Tracer.cs b/Granfeldt.FIM.ActivityLibrary/Tracer.cs new file mode 100644 index 0000000..d8f68f1 --- /dev/null +++ b/Granfeldt.FIM.ActivityLibrary/Tracer.cs @@ -0,0 +1,75 @@ +using System; +using System.Diagnostics; +using System.Text; + +namespace Granfeldt.FIM.ActivityLibrary +{ + public static class Tracer + { + //TODO: convert ident to stringbuilder + const string SwitchName = "WFL"; + const string SourceName = "WFL"; + public static TraceSource Trace = new TraceSource(SourceName, SourceLevels.All); + static string IndentText = ""; + + public static int IndentLevel + { + get + { + return IndentText.Length; + } + set + { + IndentText = ""; + } + } + public static void Indent() + { + IndentText = IndentText + " "; + } + public static void Unindent() + { + IndentText = IndentText.EndsWith(" ") ? IndentText.Remove(IndentText.Length - 2) : IndentText; + } + public static void Enter(string entryPoint) + { + TraceInformation("enter {0}", entryPoint); + Indent(); + //Process currentProc = Process.GetCurrentProcess(); + //Tracer.TraceInformation("memory-usage {0:n0}Kb, private memomry {1:n0}Kb", GC.GetTotalMemory(true) / 1024, currentProc.PrivateMemorySize64 / 1024); + } + public static void Exit(string entryPoint) + { + //Process currentProc = Process.GetCurrentProcess(); + //Tracer.TraceInformation("memory-usage {0:n0}Kb, private memory {1:n0}Kb", GC.GetTotalMemory(true) / 1024, currentProc.PrivateMemorySize64 / 1024); + Unindent(); + TraceInformation("exit {0}", entryPoint); + } + public static void TraceInformation(string message, params object[] param) + { + Trace.TraceInformation(IndentText + message, param); + } + public static void TraceWarning(string message, params object[] param) + { + Trace.TraceEvent(TraceEventType.Warning, -1, IndentText + message, param); + } + public static void TraceError(string message, int id, params object[] param) + { + Trace.TraceEvent(TraceEventType.Error, id, IndentText + message, param); + } + public static void TraceError(string message, Exception ex) + { + Trace.TraceEvent(TraceEventType.Error, ex.GetHashCode(), IndentText + "{0}, {1}", message, ex.Message); + } + public static void TraceError(string message, params object[] param) + { + TraceError(message, -2, param); + } + static Tracer() + { + SourceSwitch sw = new SourceSwitch(SwitchName, SwitchName); + sw.Level = SourceLevels.All; + Trace.Switch = sw; + } + } +}