public static Component GetComponentByType(int type, Guid id)
        {
            Component c = null;

            switch (type)
            {
            case 29:
                c = Context.WorkflowComponents.Where(x => x.Id == id).FirstOrDefault();
                break;

            case 90:
                c = ComponentDA.GetPluginTypeById(id);
                c.ComponentType = Component.ComponentTypes.PluginType;
                break;
            }

            return(c);
        }
        public void ProcessRetrieveWorkflows()
        {
            Context.Service = Service;

            tsbCancel.Enabled = true;

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Retrieving Workflows...",
                Work    = (bw, ea) =>
                {
                    if (bw.CancellationPending)
                    {
                        ea.Cancel = true;
                    }

                    Context.PluginAssemblies   = new List <Component>();
                    Context.WorkflowComponents = new List <Component>();

                    EntityCollection wCollection = ComponentDA.GetWorkflows();

                    foreach (Entity w in wCollection.Entities)
                    {
                        Component workflow = new Component();

                        int category = w.GetAttributeValue <OptionSetValue>("category").Value;
                        workflow.WorkflowCategory = (Component.WorkflowCategories)category;
                        workflow.ComponentType    = Component.ComponentTypes.Workflow;
                        workflow.Id   = w.Id;
                        workflow.Name = w.GetAttributeValue <string>("name");
                        workflow.PrimaryEntityName = w.GetAttributeValue <string>("primaryentity");

                        Context.WorkflowComponents.Add(workflow);
                    }

                    foreach (var wc in Context.WorkflowComponents)
                    {
                        DataCollection <Entity> requiredComponents = ComponentDA.RetrieveRequiredComponents(wc.Id, wc.Name);

                        foreach (var rc in requiredComponents)
                        {
                            int componentType = rc.GetAttributeValue <OptionSetValue>("requiredcomponenttype").Value;

                            Guid requiredComponentId = rc.GetAttributeValue <Guid>("requiredcomponentobjectid");

                            if (componentType == (int)Component.ComponentTypes.Workflow || componentType == (int)Component.ComponentTypes.PluginType)
                            {
                                Component w = ComponentDA.GetComponentByType(componentType, requiredComponentId);

                                if (w != null)
                                {
                                    wc.ChildComponents.Add(w);
                                }
                                else
                                {
                                    Console.WriteLine("Component with ID {0} not found", requiredComponentId);
                                }
                            }
                        }
                    }

                    ea.Result = Context.WorkflowComponents;
                },
                PostWorkCallBack = ea =>
                {
                    Console.WriteLine("Work completed");
                    tsbCancel.Enabled           = false;
                    List <Component> components = (List <Component>)ea.Result;
                    if (!ea.Cancelled)
                    {
                        DisplayByEntity(components);
                    }
                },
                AsyncArgument = null,
                IsCancelable  = true,
                MessageWidth  = 340,
                MessageHeight = 150
            });
        }