private DefaultActivity CreateCRMActivity(string ActName, DataField dfEntityid, DataField dfEntityName, int x, ref int y)
        {
            DefaultActivity actCRMReview = WorkflowFactory.CreateActivity <DefaultActivity>(ActName + " Review", WizardNames.DefaultActivity);

            process.Activities.Add(actCRMReview);
            actCRMReview.MetaData         = "Generated by K2 for Dynamics CRM 2011 Process Generation Tool";
            actCRMReview.ExpectedDuration = 1440;
            actCRMReview.Priority         = 2;
            actCRMReview.Slots            = 1;
            actCRMReview.Type             = ActivityTypes.DestinationInstanceParralel;
            WorkflowHelpers.PositionActivity(actCRMReview, x, y);
            y += 100;

            DesignCRMClient.CRMClientEvent crmClientEvent = WorkflowFactory.CreateEvent <DesignCRMClient.CRMClientEvent>(ActName + " Review", WizardNames.CRMClientEvent);

            crmClientEvent.EventItem.CRMCustomSNParameter.Parts.Add("k2_sn");
            crmClientEvent.EventItem.CRMEntityId.Parts.Add(dfEntityid);
            crmClientEvent.EventItem.CRMEntityType.Parts.Add(dfEntityName);
            crmClientEvent.EventItem.CRMFunctionsSmartObject.Parts.Add("K2_CRM_Functions");
            crmClientEvent.EventItem.CRMOrganisation.Parts.Add("Denallix");

            // Add some destination users
            SimpleDestinationRule destinationRule       = new SimpleDestinationRule();
            DestinationSet        defaultDestinationSet = new DestinationSet();
            Destination           destination1          = new Destination();

            destination1.Type = DestinationTypes.User;

            SourceCode.Workflow.Design.WorkflowContextFieldPart fpProcOrigName = new WorkflowContextFieldPart();
            fpProcOrigName.WfProps = "ProcessOriginatorName";
            fpProcOrigName.WorkflowContextProperty = WorkflowContextProperty.ProcessOriginatorName;

            destination1.Value = new K2Field(fpProcOrigName);

            defaultDestinationSet.Destinations.Add(destination1);
            destinationRule.DestinationSets.Add(defaultDestinationSet);
            actCRMReview.DestinationRule         = destinationRule;
            destinationRule.ResolveQueuesToUsers = true;

            crmClientEvent.EventItem.TaskSubject.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ProcessFolio));
            crmClientEvent.EventItem.TaskSubject.Parts.Add(" - ");
            crmClientEvent.EventItem.TaskSubject.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceName));

            crmClientEvent.EventItem.TaskDescription.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ProcessFolio));
            crmClientEvent.EventItem.TaskDescription.Parts.Add(" - ");
            crmClientEvent.EventItem.TaskDescription.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceName));

            crmClientEvent.EventItem.TaskOwnerFQN.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceDestUserName));
            crmClientEvent.EventItem.ProcessName.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ProcessName));
            crmClientEvent.EventItem.ActivityName.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceName));
            crmClientEvent.EventItem.TaskCategory.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ProcessName));
            crmClientEvent.EventItem.TaskSubcategory.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceName));


            actCRMReview.SucceedingRule   = new DesignCRMClient.CRMClientActivitySucceedingRule();
            crmClientEvent.SucceedingRule = new DesignCRMClient.CRMClientEventSucceedingRule();

            actCRMReview.Events.Add(crmClientEvent);

            // Add two actions for the client event
            EventAction approveAction = WorkflowFactory.CreateK2Object <EventAction>("Approve");

            approveAction.ActionItem = new DefaultOutcomeAction();
            EventAction declineAction = WorkflowFactory.CreateK2Object <EventAction>("Decline");

            declineAction.ActionItem = new DefaultOutcomeAction();
            crmClientEvent.Actions.Add(approveAction);
            crmClientEvent.Actions.Add(declineAction);


            // Find the default succeeding rule property wizard definition,
            // and replace it with the default outcome succeeding rule
            //PropertyWizardDefinition propWizDefSimple = WorkflowHelpers.FindOfType<SimpleSucceedingRulePropertyWizardDefinition>(actCRMReview.WizardDefinition.PropertyWizardDefinitions);
            //PropertyWizardDefinition propWizDefOutcome = WorkflowHelpers.FindOfType<OutcomeSucceedingRulePropertyWizardDefinition>(actCRMReview.WizardDefinition.PropertyWizardDefinitions);
            //if (propWizDefSimple != null && propWizDefOutcome == null)
            //{
            //    actCRMReview.WizardDefinition.PropertyWizardDefinitions.Remove(propWizDefSimple);
            //    actCRMReview.WizardDefinition.PropertyWizardDefinitions.Add(
            //        WorkflowFactory.CreatePropertyWizardDefinition(PropertyWizardNames.OutcomeSucceedingRule));
            //}

            SourceCode.Workflow.Design.Outcome.Common.GenerateDefaultOutcomesForActions(crmClientEvent);
            SourceCode.Workflow.Design.Outcome.Common.GenerateDefaultLinesForOutcomes(actCRMReview.SucceedingRule as DesignCRMClient.CRMClientActivitySucceedingRule);
            SourceCode.Workflow.Design.Outcome.Common.SyncActivityAndEventSucceedingRule(crmClientEvent);
            return(actCRMReview);
        }
        private DefaultActivity CreateCRMActivity(string ActName, DataField dfEntityid, DataField dfEntityName, int x, ref int y)
        {

            DefaultActivity actCRMReview = WorkflowFactory.CreateActivity<DefaultActivity>(ActName + " Review", WizardNames.DefaultActivity);
            process.Activities.Add(actCRMReview);
            actCRMReview.MetaData = "Generated by K2 for Dynamics CRM 2011 Process Generation Tool";
            actCRMReview.ExpectedDuration = 1440;
            actCRMReview.Priority = 2;
            actCRMReview.Slots = 1;
            actCRMReview.Type = ActivityTypes.DestinationInstanceParralel;
            WorkflowHelpers.PositionActivity(actCRMReview, x, y);
            y += 100;

            DesignCRMClient.CRMClientEvent crmClientEvent = WorkflowFactory.CreateEvent<DesignCRMClient.CRMClientEvent>(ActName + " Review", WizardNames.CRMClientEvent);
            
            crmClientEvent.EventItem.CRMCustomSNParameter.Parts.Add("k2_sn");
            crmClientEvent.EventItem.CRMEntityId.Parts.Add(dfEntityid);
            crmClientEvent.EventItem.CRMEntityType.Parts.Add(dfEntityName);
            crmClientEvent.EventItem.CRMFunctionsSmartObject.Parts.Add("K2_CRM_Functions");
            crmClientEvent.EventItem.CRMOrganisation.Parts.Add("Denallix");

            // Add some destination users
            SimpleDestinationRule destinationRule = new SimpleDestinationRule();
            DestinationSet defaultDestinationSet = new DestinationSet();
            Destination destination1 = new Destination();
            destination1.Type = DestinationTypes.User;

            SourceCode.Workflow.Design.WorkflowContextFieldPart fpProcOrigName = new WorkflowContextFieldPart();
            fpProcOrigName.WfProps = "ProcessOriginatorName";
            fpProcOrigName.WorkflowContextProperty = WorkflowContextProperty.ProcessOriginatorName;

            destination1.Value = new K2Field(fpProcOrigName);

            defaultDestinationSet.Destinations.Add(destination1);
            destinationRule.DestinationSets.Add(defaultDestinationSet);
            actCRMReview.DestinationRule = destinationRule;
            destinationRule.ResolveQueuesToUsers = true;

            crmClientEvent.EventItem.TaskSubject.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ProcessFolio));
            crmClientEvent.EventItem.TaskSubject.Parts.Add(" - ");
            crmClientEvent.EventItem.TaskSubject.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceName));

            crmClientEvent.EventItem.TaskDescription.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ProcessFolio));
            crmClientEvent.EventItem.TaskDescription.Parts.Add(" - ");
            crmClientEvent.EventItem.TaskDescription.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceName));

            crmClientEvent.EventItem.TaskOwnerFQN.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceDestUserName));
            crmClientEvent.EventItem.ProcessName.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ProcessName));
            crmClientEvent.EventItem.ActivityName.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceName));
            crmClientEvent.EventItem.TaskCategory.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ProcessName));
            crmClientEvent.EventItem.TaskSubcategory.Parts.Add(new WorkflowContextFieldPart(WorkflowContextProperty.ActivityInstanceName));


            actCRMReview.SucceedingRule = new DesignCRMClient.CRMClientActivitySucceedingRule();
            crmClientEvent.SucceedingRule = new DesignCRMClient.CRMClientEventSucceedingRule();

            actCRMReview.Events.Add(crmClientEvent);

            // Add two actions for the client event
            EventAction approveAction = WorkflowFactory.CreateK2Object<EventAction>("Approve");
            approveAction.ActionItem = new DefaultOutcomeAction();
            EventAction declineAction = WorkflowFactory.CreateK2Object<EventAction>("Decline");
            declineAction.ActionItem = new DefaultOutcomeAction();
            crmClientEvent.Actions.Add(approveAction);
            crmClientEvent.Actions.Add(declineAction);


            // Find the default succeeding rule property wizard definition,
            // and replace it with the default outcome succeeding rule
            //PropertyWizardDefinition propWizDefSimple = WorkflowHelpers.FindOfType<SimpleSucceedingRulePropertyWizardDefinition>(actCRMReview.WizardDefinition.PropertyWizardDefinitions);
            //PropertyWizardDefinition propWizDefOutcome = WorkflowHelpers.FindOfType<OutcomeSucceedingRulePropertyWizardDefinition>(actCRMReview.WizardDefinition.PropertyWizardDefinitions);
            //if (propWizDefSimple != null && propWizDefOutcome == null)
            //{
            //    actCRMReview.WizardDefinition.PropertyWizardDefinitions.Remove(propWizDefSimple);
            //    actCRMReview.WizardDefinition.PropertyWizardDefinitions.Add(
            //        WorkflowFactory.CreatePropertyWizardDefinition(PropertyWizardNames.OutcomeSucceedingRule));
            //}
            
            SourceCode.Workflow.Design.Outcome.Common.GenerateDefaultOutcomesForActions(crmClientEvent);
            SourceCode.Workflow.Design.Outcome.Common.GenerateDefaultLinesForOutcomes(actCRMReview.SucceedingRule as DesignCRMClient.CRMClientActivitySucceedingRule);
            SourceCode.Workflow.Design.Outcome.Common.SyncActivityAndEventSucceedingRule(crmClientEvent);
            return actCRMReview;

        }