TechEd Demo 4: SelectUnique.cs

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.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using Microsoft.ResourceManagement.WebServices.WSResourceManagement;
using Microsoft.ResourceManagement.Workflow.Activities;

namespace FIM.CustomActivityLibrary.Activities
{
    public partial class SelectUnique : SequenceActivity
    {

        SequentialWorkflow containingWorkflow = null;
        Boolean found = false;
        Boolean done = false;
        int i = 0;
        List<string> sortedOptions = new List<string>();

        public SelectUnique()
        {
            InitializeComponent();
        }

        #region Code Activities

        private void GetWorkflowData_ExecuteCode(System.Object sender, System.EventArgs e)
        {
            // Get containing Workflow
            if (!SequentialWorkflow.TryGetContainingWorkflow(this, out containingWorkflow))
            {
                throw new InvalidOperationException(“Could not get parent workflow!”);
            }

            // Find OptionN WorkflowData values
            var list = containingWorkflow.WorkflowDictionary.Keys.ToList();
            list.Sort();
            int count = 0;

            object OptionValue;
            foreach (string item in list)
            {
                if (item.StartsWith(“Option”))
                {
                    containingWorkflow.WorkflowDictionary.TryGetValue(item, out OptionValue);
                    count += 1;
                    sortedOptions.Add(OptionValue.ToString());
                }
            }

            if (sortedOptions.Count() == 0)
            {
                throw new WorkflowTerminatedException(“No Options found in WorkflowData”);
            }
        }

        private void PrepareEnumeration_ExecuteCode(object sender, EventArgs e)
        {
            EnumerateMatches_ActorId1 = new System.Guid(“00000000-0000-0000-0000-000000000000”);
            EnumerateMatches_PageSize1 = 100;
            EnumerateMatches_Selection1 = new string[] { “DisplayName” };
            EnumerateMatches_SortingAttributes1 = null;
            EnumerateMatches_TotalResultsCount1 = 0;
            string filter = “/” + this.ObjectType + “[” + this.Attribute + “='” + sortedOptions[i] + “‘]”;
            EnumerateMatches_XPathFilter1 = filter;
        }

        private void EvaluateEnumeration_ExecuteCode(object sender, EventArgs e)
        {
            if (EnumerateMatches_TotalResultsCount1 == 0)
            {
                found = true;
                done = true;
            }

            i += 1;
            if (sortedOptions.Count() == i)
            {
                done = true;
            }
        }

        private void ReturnResult_ExecuteCode(object sender, EventArgs e)
        {
            if (found)
            {
                containingWorkflow.WorkflowDictionary.Add(“Result”, sortedOptions[i – 1]);
            }
            else
            {
                throw new WorkflowTerminatedException(“Could not find a unique value for ” + this.Attribute);
            }
        }
        #endregion
        #region Workflow Properties
        public static DependencyProperty EnumerateMatches_ActorId1Property = DependencyProperty.Register(“EnumerateMatches_ActorId1”, typeof(System.Guid), typeof(FIM.CustomActivityLibrary.Activities.SelectUnique));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute(“Misc”)]
        public Guid EnumerateMatches_ActorId1
        {
            get
            {
                return ((System.Guid)(base.GetValue(FIM.CustomActivityLibrary.Activities.SelectUnique.EnumerateMatches_ActorId1Property)));
            }
            set
            {
                base.SetValue(FIM.CustomActivityLibrary.Activities.SelectUnique.EnumerateMatches_ActorId1Property, value);
            }
        }

        public static DependencyProperty EnumerateMatches_PageSize1Property = DependencyProperty.Register(“EnumerateMatches_PageSize1”, typeof(System.Int32), typeof(FIM.CustomActivityLibrary.Activities.SelectUnique));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute(“Misc”)]
        public Int32 EnumerateMatches_PageSize1
        {
            get
            {
                return ((int)(base.GetValue(FIM.CustomActivityLibrary.Activities.SelectUnique.EnumerateMatches_PageSize1Property)));
            }
            set
            {
                base.SetValue(FIM.CustomActivityLibrary.Activities.SelectUnique.EnumerateMatches_PageSize1Property, value);
            }
        }

        public static DependencyProperty EnumerateMatches_Selection1Property = DependencyProperty.Register(“EnumerateMatches_Selection1”, typeof(System.String[]), typeof(FIM.CustomActivityLibrary.Activities.SelectUnique));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute(“Misc”)]
        public String[] EnumerateMatches_Selection1
        {
            get
            {
                return ((string[])(base.GetValue(FIM.CustomActivityLibrary.Activities.SelectUnique.EnumerateMatches_Selection1Property)));
            }
            set
            {
                base.SetValue(FIM.CustomActivityLibrary.Activities.SelectUnique.EnumerateMatches_Selection1Property, value);
            }
        }

        public static DependencyProperty EnumerateMatches_SortingAttributes1Property = DependencyProperty.Register(“EnumerateMatches_SortingAttributes1”, typeof(Microsoft.ResourceManagement.WebServices.WSEnumeration.SortingAttribute[]), typeof(FIM.CustomActivityLibrary.Activities.SelectUnique));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute(“Misc”)]
        public Microsoft.ResourceManagement.WebServices.WSEnumeration.SortingAttribute[] EnumerateMatches_SortingAttributes1
        {
            get
            {
                return ((Microsoft.ResourceManagement.WebServices.WSEnumeration.SortingAttribute[])(base.GetValue(FIM.CustomActivityLibrary.Activities.SelectUnique.EnumerateMatches_SortingAttributes1Property)));
            }
            set
            {
                base.SetValue(FIM.CustomActivityLibrary.Activities.SelectUnique.EnumerateMatches_SortingAttributes1Property, value);
            }
        }

        public static DependencyProperty EnumerateMatches_TotalResultsCount1Property = DependencyProperty.Register(“EnumerateMatches_TotalResultsCount1”, typeof(System.Int32), typeof(FIM.CustomActivityLibrary.Activities.SelectUnique));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute(“Misc”)]
        public Int32 EnumerateMatches_TotalResultsCount1
        {
            get
            {
                return ((int)(base.GetValue(FIM.CustomActivityLibrary.Activities.SelectUnique.EnumerateMatches_TotalResultsCount1Property)));
            }
            set
            {
                base.SetValue(FIM.CustomActivityLibrary.Activities.SelectUnique.EnumerateMatches_TotalResultsCount1Property, value);
            }
        }

        public static DependencyProperty EnumerateMatches_XPathFilter1Property = DependencyProperty.Register(“EnumerateMatches_XPathFilter1”, typeof(System.String), typeof(FIM.CustomActivityLibrary.Activities.SelectUnique));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute(“Misc”)]
        public String EnumerateMatches_XPathFilter1
        {
            get
            {
                return ((string)(base.GetValue(FIM.CustomActivityLibrary.Activities.SelectUnique.EnumerateMatches_XPathFilter1Property)));
            }
            set
            {
                base.SetValue(FIM.CustomActivityLibrary.Activities.SelectUnique.EnumerateMatches_XPathFilter1Property, value);
            }
        }
        #endregion
        #region UI Properties

        /// <summary>
        ///  Identifies the Log File Path
        /// </summary>
        public static DependencyProperty AttributeProperty = DependencyProperty.Register(“Attribute”, typeof(System.String), typeof(SelectUnique));
        [Description(“Please specify the Attribute”)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [Browsable(true)]
        public string Attribute
        {
            get
            {
                return ((String)(base.GetValue(SelectUnique.AttributeProperty)));
            }
            set
            {
                base.SetValue(SelectUnique.AttributeProperty, value);
            }
        }

        /// <summary>
        ///  Identifies the Log File Name
        /// </summary>
        public static DependencyProperty ObjectTypeProperty = DependencyProperty.Register(“ObjectType”,
             typeof(System.String), typeof(SelectUnique));
        [Description(“Please specify the Object Type”)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [Browsable(true)]
        public string ObjectType
        {
            get
            {
                return ((String)(base.GetValue(SelectUnique.ObjectTypeProperty)));
            }
            set
            {
                base.SetValue(SelectUnique.ObjectTypeProperty, value);
            }
        }
        #endregion
    }
}


Leave a Reply

Your email address will not be published. Required fields are marked *


*