private void btnGenerateCRMProcess_Click(object sender, RoutedEventArgs e)
        {
            SourceCode.SmartObjects.Client.SmartObjectClientServer smoServer = new SmartObjectClientServer();
            smoServer.CreateConnection();
            smoServer.Connection.Open("Integrated=True;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;Host=localhost;Port=5555");

            SmartObject smoCRM = smoServer.GetSmartObject("Demo_K2_CRM_Functions");

            smoCRM.MethodToExecute = "GetAllEntities";

            SmartObjectList smoEntities = smoServer.ExecuteList(smoCRM);


            // get state status details
            CRMPicklist pl = new CRMPicklist();

//            pl.AttributeLogicalName = att.LogicalName;
            pl.EntityLogicalName = "lead";

            CRMPicklist cp = functions.CRMGetStateStatus(pl);

            int seq = 0;

            foreach (CRMPicklistOption plo in cp.Picklist.OrderBy(p => p.PicklistParentValue).OrderBy(p => p.PicklistValue))
            {
                StateStatus ss = new StateStatus();
                ss.State      = plo.PicklistParentValue;
                ss.StateName  = plo.PicklistParentLabel;
                ss.Status     = plo.PicklistValue;
                ss.StatusName = plo.PicklistLabel;
                ss.Sequence   = seq;
                seq++;
                CRMSS.Add(ss);
            }


            bool ActiveOnly = true;


            string nowish = DateTime.Now.ToString("yyyyMMddHHmmss");

            // Create new process
            process = WorkflowFactory.CreateProcess <DefaultProcess>(nowish, WizardNames.DefaultProcess);

            DataField dfEntityId   = new DataField("Entity Id", "");
            DataField dfEntityName = new DataField("Entity Name", "");

            process.DataFields.Add(dfEntityId);
            process.DataFields.Add(dfEntityName);


            var dimensions = WorkflowHelpers.GetActivityDimensions(process.StartActivity);
            int x          = Convert.ToInt32(Math.Round(dimensions.X + dimensions.Width + 40D));
            int y          = Convert.ToInt32(dimensions.Y) + 100;

            DefaultActivity PrevStatAct   = null;
            DefaultActivity PrevReviewAct = null;

            PrevStatAct = CreateStartActivity("", dfEntityId, dfEntityName, x, ref y);

            SourceCode.Workflow.Authoring.Line startLine = WorkflowFactory.CreateLine("StartLine");
            startLine.StartActivity  = process.StartActivity;
            startLine.FinishActivity = PrevStatAct;
            process.Lines.Add(startLine);

            int c = 0;

            foreach (StateStatus ss in CRMSS.OrderBy(p => p.Sequence))
            {
                DefaultActivity act = CreateStatusActivity(ss.StateName + " - " + ss.StatusName, dfEntityId, dfEntityName, x, ref y);
                if (PrevReviewAct != null)
                {
                    PrevReviewAct.FinishLines[0].FinishActivity = act;
                }

                if (c == 0)
                {
                    SourceCode.Workflow.Authoring.Line firstline = WorkflowFactory.CreateLine("Firstline");
                    firstline.StartActivity  = PrevStatAct;
                    firstline.FinishActivity = act;
                    process.Lines.Add(firstline);
                }
                c++;

                DefaultActivity act1 = null;
                if (!ActiveOnly || ActiveOnly && ss.State == 0)
                {
                    act1 = CreateCRMActivity(ss.StateName + " - " + ss.StatusName, dfEntityId, dfEntityName, x, ref y);

                    SourceCode.Workflow.Authoring.Line line = WorkflowFactory.CreateLine("Line " + ss.Sequence);
                    line.StartActivity  = act;
                    line.FinishActivity = act1;
                    process.Lines.Add(line);

                    if (PrevStatAct != null)
                    {
                        act1.FinishLines[1].FinishActivity = PrevStatAct;
                    }
                }

                if (act1 == null && PrevStatAct.FinishLines.Count == 0)
                {
                    PrevReviewAct = null;
                    SourceCode.Workflow.Authoring.Line updateLine = WorkflowFactory.CreateLine("Update Line " + ss.Sequence);
                    updateLine.StartActivity  = PrevStatAct;
                    updateLine.FinishActivity = act;
                    process.Lines.Add(updateLine);
                }


                if (act != null)
                {
                    WorkflowHelpers.AutoPositionLines(act.StartLines);
                    WorkflowHelpers.AutoPositionLines(act.FinishLines);
                }
                if (act1 != null)
                {
                    WorkflowHelpers.AutoPositionLines(act1.StartLines);
                    WorkflowHelpers.AutoPositionLines(act1.FinishLines);
                }

                PrevReviewAct = act1;
                PrevStatAct   = act;
            }



            process.FinishRule = new DesignCRMClient.CRMClientProcessFinishRule();

            process.SaveAs(txtProcessPath.Text + nowish + ".kprx");

            process = null;
        }
Exemplo n.º 2
0
        public static DefaultProcess CreateSampleProcess()
        {
            // Create new process
            DefaultProcess process = WorkflowFactory.CreateProcess <DefaultProcess>("Sample Approval Process", WizardNames.DefaultProcess);

            // Add some data fields with default values
            DataField fromEmailDataField = new DataField("From Email", "*****@*****.**");
            DataField toEmailDataField   = new DataField("To Email", "*****@*****.**");

            process.DataFields.Add(fromEmailDataField);
            process.DataFields.Add(toEmailDataField);

            // Create 3 activities and add them to the process
            DefaultActivity awaitApprovalActivity = WorkflowFactory.CreateActivity <DefaultActivity>("Await approval", WizardNames.DefaultActivity);
            DefaultActivity approvedActivity      = WorkflowFactory.CreateActivity <DefaultActivity>("Approved", WizardNames.DefaultActivity);
            DefaultActivity declinedActivity      = WorkflowFactory.CreateActivity <DefaultActivity>("Declined", WizardNames.DefaultActivity);

            process.Activities.Add(awaitApprovalActivity);
            process.Activities.Add(approvedActivity);
            process.Activities.Add(declinedActivity);

            // Create a client event
            ClientEvent approvalClientEvent = WorkflowFactory.CreateEvent <ClientEvent>("Get client approval", WizardNames.DefaultClientEvent);

            SourceCode.Workflow.Design.DefaultClientWizardDefinition a = new DefaultClientWizardDefinition();


            // Configure the client event
            approvalClientEvent.EventItem.InternetPlatform = "ASP";
            approvalClientEvent.EventItem.SendToInternet   = true;
            approvalClientEvent.EventItem.InternetUrl      = K2FieldFactory.CreateK2Field(
                typeof(string),
                new ValueTypePart("http://webserver/page.aspx?"),
                new SerialNoFieldPart());

            // Add event to the activity so that the helper methods for generating
            // the default outcomes will work correctly
            awaitApprovalActivity.Events.Add(approvalClientEvent);

            // 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();
            approvalClientEvent.Actions.Add(approveAction);
            approvalClientEvent.Actions.Add(declineAction);

            // Set the activity succeeding rule to the outcome succeeding rule
            awaitApprovalActivity.SucceedingRule = new DefaultOutcomeSucceedingRule();

            // Find the default succeeding rule property wizard definition,
            // and replace it with the default outcome succeeding rule
            PropertyWizardDefinition propWizDefSimple  = WorkflowHelpers.FindOfType <SimpleSucceedingRulePropertyWizardDefinition>(awaitApprovalActivity.WizardDefinition.PropertyWizardDefinitions);
            PropertyWizardDefinition propWizDefOutcome = WorkflowHelpers.FindOfType <OutcomeSucceedingRulePropertyWizardDefinition>(awaitApprovalActivity.WizardDefinition.PropertyWizardDefinitions);

            if (propWizDefSimple != null && propWizDefOutcome == null)
            {
                awaitApprovalActivity.WizardDefinition.PropertyWizardDefinitions.Remove(propWizDefSimple);
                awaitApprovalActivity.WizardDefinition.PropertyWizardDefinitions.Add(
                    WorkflowFactory.CreatePropertyWizardDefinition(PropertyWizardNames.OutcomeSucceedingRule));
            }
            SourceCode.Workflow.Design.Outcome.Common.GenerateDefaultOutcomesForActions(approvalClientEvent);
            SourceCode.Workflow.Design.Outcome.Common.GenerateDefaultLinesForOutcomes(awaitApprovalActivity.SucceedingRule as DefaultOutcomeSucceedingRule);

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

            destination1.Type  = DestinationTypes.User;
            destination1.Value = K2FieldFactory.CreateK2Field("K2:Domain\\User1");
            Destination destination2 = new Destination();

            destination2.Type  = DestinationTypes.User;
            destination2.Value = K2FieldFactory.CreateK2Field("K2:Domain\\User2");

            defaultDestinationSet.Destinations.Add(destination1);
            defaultDestinationSet.Destinations.Add(destination2);

            destinationRule.DestinationSets.Add(defaultDestinationSet);


            // Set the destination rule of the activity
            awaitApprovalActivity.DestinationRule = destinationRule;

            // Create the approved email event
            MailEvent approvedMail = WorkflowFactory.CreateEvent <MailEvent>("Send approved email", WizardNames.MailEvent);

            // Use string values for the email addresses
            approvedMail.EventItem.To      = K2FieldFactory.CreateK2Field("*****@*****.**");
            approvedMail.EventItem.From    = K2FieldFactory.CreateK2Field("*****@*****.**");
            approvedMail.EventItem.Subject = K2FieldFactory.CreateK2Field("Leave Approved");
            approvedMail.EventItem.Body    = K2FieldFactory.CreateK2Field("Your leave has been approved.");

            // Create the declined email event
            MailEvent declinedMail = WorkflowFactory.CreateEvent <MailEvent>("Send declined email", WizardNames.MailEvent);

            // Use process data fields for the email addresses
            declinedMail.EventItem.To      = K2FieldFactory.CreateK2Field(toEmailDataField);
            declinedMail.EventItem.From    = K2FieldFactory.CreateK2Field(fromEmailDataField);
            declinedMail.EventItem.Subject = K2FieldFactory.CreateK2Field("Leave Declined");
            declinedMail.EventItem.Body    = K2FieldFactory.CreateK2Field("Your leave has been declined.");

            // Add the events to the activities
            approvedActivity.Events.Add(approvedMail);
            declinedActivity.Events.Add(declinedMail);

            // Link the lines created by the "GenerateDefaultLinesForOutcomes" method to the approved and declined activities
            process.Lines["Approve"].FinishActivity = approvedActivity;
            process.Lines["Decline"].FinishActivity = declinedActivity;

            // Link the start activity with the await approval activity
            Line startLine = WorkflowFactory.CreateLine("StartLine");

            startLine.StartActivity  = process.StartActivity;
            startLine.FinishActivity = awaitApprovalActivity;
            process.Lines.Add(startLine);

            // Position the activities and lines
            WorkflowHelpers.PositionActivity(process.StartActivity, 208, 16);
            WorkflowHelpers.PositionActivity(awaitApprovalActivity, 208, 112);
            WorkflowHelpers.PositionActivity(approvedActivity, 32, 224);
            WorkflowHelpers.PositionActivity(declinedActivity, 368, 224);

            // FinishLines are the lines that flows out from the activity
            // when the activity has finished
            WorkflowHelpers.AutoPositionLines(awaitApprovalActivity.FinishLines);

            return(process);
        }