private void GetStateStatusPicklist(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];

            CRMPicklist picklist = new CRMPicklist();

            picklist.Config = crmconfig;

            try
            {
                picklist.EntityLogicalName = NotNull(so.Properties["EntityLogicalName"].Value);

                CRMPicklist response = CRMFunctions.CRMGetStateStatus(picklist);

                so.Properties.InitResultTable();
                foreach (CRMPicklistOption ret in response.Picklist)
                {
                    for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                    {
                        Property prop = so.Properties[meth.ReturnProperties[c]];
                        prop = SetGetPicklistOptionProperties(prop, ret);
                    }
                    so.Properties.BindPropertiesToResultTable();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void GetAllEntities(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];

            CRMEntityList entitymetadata = new CRMEntityList();

            entitymetadata.Config = crmconfig;

            try
            {
                CRMEntityList response = CRMFunctions.CRMGetAllEntities(entitymetadata);

                so.Properties.InitResultTable();
                foreach (CRMEntityMetadata ret in response.Entities)
                {
                    for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                    {
                        Property prop = so.Properties[meth.ReturnProperties[c]];
                        prop = SetEntityMetadataProperties(prop, ret);
                    }
                    so.Properties.BindPropertiesToResultTable();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void GetEntityAttributes(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];

            CRMEntityMetadata entitymetadata = new CRMEntityMetadata();

            entitymetadata.Config = crmconfig;

            try
            {
                entitymetadata.LogicalName       = NotNull(so.Properties["EntityLogicalName"].Value);
                entitymetadata.IncludeAttributes = true;

                CRMEntityMetadata response = CRMFunctions.CRMGetEntityMetadata(entitymetadata);

                so.Properties.InitResultTable();
                foreach (CRMAttribute ret in response.Attributes)
                {
                    for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                    {
                        Property prop = so.Properties[meth.ReturnProperties[c]];
                        prop = SetGetEntityAttributeProperties(prop, ret);
                    }
                    so.Properties.BindPropertiesToResultTable();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void GetCRMUser(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];

            CRMUser user = new CRMUser();

            user.Config = crmconfig;

            try
            {
                user.UserFQN = NotNull(so.Properties["UserFQN"].Value);

                CRMUser response = CRMFunctions.CRMGetUser(user);

                so.Properties.InitResultTable();

                for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                {
                    Property prop = so.Properties[meth.ReturnProperties[c]];
                    prop = SetCRMUserProperties(prop, response);
                }

                so.Properties.BindPropertiesToResultTable();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void StartCRMWorkflow(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];

            CRMWorkflow crmWF = new CRMWorkflow();

            crmWF.Config = crmconfig;

            try
            {
                crmWF.EntityId     = NotNull(so.Properties["EntityId"].Value);
                crmWF.WorkflowName = NotNull(so.Properties["WorkflowName"].Value);

                CRMWorkflow response = CRMFunctions.CRMStartWorkflow(crmWF);

                so.Properties.InitResultTable();

                for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                {
                    Property prop = so.Properties[meth.ReturnProperties[c]];
                    prop = SetCRMWorkflowProperties(prop, response);
                }

                so.Properties.BindPropertiesToResultTable();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void SetStateStatus(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];

            CRMState state = new CRMState();

            state.Config = crmconfig;

            try
            {
                state.Entity   = NotNull(so.Properties["Entity"].Value);
                state.EntityId = NotNull(so.Properties["EntityId"].Value);
                state.State    = int.Parse(NotNull(so.Properties["State"].Value));
                state.Status   = int.Parse(NotNull(so.Properties["Status"].Value));

                CRMState response = CRMFunctions.CRMSetStateStatus(state);

                so.Properties.InitResultTable();

                for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                {
                    Property prop = so.Properties[meth.ReturnProperties[c]];
                    prop = SetStateStatusProperties(prop, response);
                }

                so.Properties.BindPropertiesToResultTable();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void GetEntities(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];

            CRMFetchXML fetch = new CRMFetchXML();

            fetch.Config = crmconfig;

            try
            {
                fetch.FetchXML = NotNull(so.Properties["FetchXML"].Value);

                CRMFetchXML response = CRMFunctions.CRMGetEntities(fetch);

                so.Properties.InitResultTable();

                if (response.Entities != null)
                {
                    foreach (CRMState state in response.Entities)
                    {
                        for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                        {
                            Property prop = so.Properties[meth.ReturnProperties[c]];
                            prop = SetGetEntitiesProperties(prop, state);
                            prop = SetGetEntitiesRESTProperties(prop, response);
                        }
                        so.Properties.BindPropertiesToResultTable();
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void GetPicklist(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];
            //K2CRMHelper helper = new K2CRMHelper();
            WizardFunctions helper   = new WizardFunctions();
            CRMPicklist     picklist = new CRMPicklist();

            picklist.Config = crmconfig;

            try
            {
                picklist.EntityLogicalName    = NotNull(so.Properties["EntityLogicalName"].Value);
                picklist.AttributeLogicalName = NotNull(so.Properties["AttributeLogicalName"].Value);

                RestResponse <CRMPicklist> response = helper.GetPicklist(picklist, config);

                so.Properties.InitResultTable();
                foreach (CRMPicklistOption ret in response.Data.Picklist)
                {
                    for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                    {
                        Property prop = so.Properties[meth.ReturnProperties[c]];
                        prop = SetGetPicklistOptionProperties(prop, ret);
                    }
                    so.Properties.BindPropertiesToResultTable();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void ChangeOwner(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];

            CRMEntityOwnership owner = new CRMEntityOwnership();

            owner.Config = crmconfig;

            try
            {
                owner.Assignee   = NotNull(so.Properties["Assignee"].Value);
                owner.AssigneeId = NotNull(so.Properties["AssigneeId"].Value);
                owner.Target     = NotNull(so.Properties["Target"].Value);
                owner.TargetId   = NotNull(so.Properties["TargetId"].Value);

                CRMEntityOwnership response = CRMFunctions.CRMChangeOwner(owner);

                so.Properties.InitResultTable();

                for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                {
                    Property prop = so.Properties[meth.ReturnProperties[c]];
                    prop = SetChangeOwnerProperties(prop, response);
                }

                so.Properties.BindPropertiesToResultTable();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void GetEntityMetadata(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];
            //K2CRMHelper helper = new K2CRMHelper();
            WizardFunctions   helper         = new WizardFunctions();
            CRMEntityMetadata entitymetadata = new CRMEntityMetadata();

            entitymetadata.Config = crmconfig;

            try
            {
                entitymetadata.LogicalName       = NotNull(so.Properties["EntityLogicalName"].Value);
                entitymetadata.IncludeAttributes = false;
                RestResponse <CRMEntityMetadata> response = helper.GetEntityMetadata(entitymetadata, config);

                so.Properties.InitResultTable();

                for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                {
                    Property prop = so.Properties[meth.ReturnProperties[c]];
                    prop = SetEntityMetadataProperties(prop, response);
                }

                so.Properties.BindPropertiesToResultTable();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void CreateTask(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];
            WizardFunctions helper = new WizardFunctions();

            bool async = false;

            bool.TryParse(NotNull(so.Properties["ExecuteAsync"].Value), out async);
            config.Async = async;


            CRMTask task = new CRMTask();

            task.Config = crmconfig;

            task.Category            = NotNull(so.Properties["Category"].Value);
            task.Description         = NotNull(so.Properties["Description"].Value);
            task.DueDate             = DateTime.Parse(NotNull(so.Properties["DueDate"].Value));
            task.Duration            = int.Parse(NotNull(so.Properties["Duration"].Value));
            task.OwnerFQN            = NotNull(so.Properties["OwnerFQN"].Value);
            task.OwnerId             = NotNull(so.Properties["OwnerId"].Value);
            task.Owner               = NotNull(so.Properties["Owner"].Value);
            task.Priority            = int.Parse(NotNull(so.Properties["Priority"].Value));
            task.Regarding           = NotNull(so.Properties["Regarding"].Value);
            task.RegardingId         = NotNull(so.Properties["RegardingId"].Value);
            task.State               = int.Parse(NotNull(so.Properties["State"].Value));
            task.Status              = int.Parse(NotNull(so.Properties["Status"].Value));
            task.Subcategory         = NotNull(so.Properties["Subcategory"].Value);
            task.Subject             = NotNull(so.Properties["Subject"].Value);
            task.K2SerialNumber      = NotNull(so.Properties["K2SerialNumber"].Value);
            task.K2ActivityName      = NotNull(so.Properties["K2ActivityName"].Value);
            task.K2ProcessName       = NotNull(so.Properties["K2ProcessName"].Value);
            task.K2ProcessInstanceId = int.Parse(NotNull(so.Properties["K2ProcessInstanceId"].Value));

            try
            {
                RestResponse <CRMTask> response = helper.CreateTask(task, config);

                if (response != null)
                {
                    so.Properties.InitResultTable();

                    for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                    {
                        Property prop = so.Properties[meth.ReturnProperties[c]];
                        prop = SetTaskProperties(prop, response);
                    }
                    so.Properties.BindPropertiesToResultTable();
                }
                {
                    // do something for async call
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void BulkActionTasksSetCriteria(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];

            CRMBulkActionTask fetch = new CRMBulkActionTask();

            fetch.Config = crmconfig;

            try
            {
                string fetchstring = string.Empty;
                if (!string.IsNullOrEmpty(NotNull(so.Properties["K2ActivityName"])))
                {
                    fetchstring = Resources.K2CRMTaskCleanUpFinishRule.Replace("[entityid]", NotNull(so.Properties["RegardingId"].Value)).Replace("[entityname]", NotNull(so.Properties["Regarding"].Value));
                    fetchstring = fetchstring.Replace("[processname]", NotNull(so.Properties["K2ProcessName"].Value));
                    fetchstring = fetchstring.Replace("[statecode]", NotNull(so.Properties["FromState"].Value));
                    fetchstring = fetchstring.Replace("[processinstanceid]", NotNull(so.Properties["K2ProcessInstanceId"].Value));
                }
                else
                {
                    fetchstring = Resources.K2CRMTaskCleanUpState0FetchXML.Replace("[entityid]", NotNull(so.Properties["RegardingId"].Value)).Replace("[entityname]", NotNull(so.Properties["Regarding"].Value));
                    fetchstring = fetchstring.Replace("[activityname]", NotNull(so.Properties["K2ActivityName"].Value));
                    fetchstring = fetchstring.Replace("[processname]", NotNull(so.Properties["K2ProcessName"].Value));
                    fetchstring = fetchstring.Replace("[statecode]", NotNull(so.Properties["FromState"].Value));
                    fetchstring = fetchstring.Replace("[processinstanceid]", NotNull(so.Properties["K2ProcessInstanceId"].Value));
                }

                fetch.FetchXML   = fetchstring;
                fetch.FromState  = int.Parse(NotNull(so.Properties["FromState"].Value));
                fetch.FromStatus = int.Parse(NotNull(so.Properties["FromStatus"].Value));
                fetch.ToState    = int.Parse(NotNull(so.Properties["ToState"].Value));
                fetch.ToStatus   = int.Parse(NotNull(so.Properties["ToStatus"].Value));

                CRMBulkActionTask response = CRMFunctions.CRMBulkActionTasks(fetch);

                so.Properties.InitResultTable();

                if (response.Entities != null)
                {
                    foreach (CRMState state in response.Entities)
                    {
                        for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                        {
                            Property prop = so.Properties[meth.ReturnProperties[c]];
                            prop = SetGetEntitiesProperties(prop, state);
                            prop = SetBulkActionTasksRESTProperties(prop, response);
                        }
                        so.Properties.BindPropertiesToResultTable();
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void BulkActionTasks(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];
            WizardFunctions helper = new WizardFunctions();

            CRMBulkActionTask fetch = new CRMBulkActionTask();

            fetch.Config = crmconfig;

            try
            {
                fetch.FetchXML   = NotNull(so.Properties["FetchXML"].Value);
                fetch.FromState  = int.Parse(NotNull(so.Properties["FromState"].Value));
                fetch.FromStatus = int.Parse(NotNull(so.Properties["FromStatus"].Value));
                fetch.ToState    = int.Parse(NotNull(so.Properties["ToState"].Value));
                fetch.ToStatus   = int.Parse(NotNull(so.Properties["ToStatus"].Value));

                RestResponse <CRMBulkActionTask> response = helper.BulkActionTasks(fetch, config);

                so.Properties.InitResultTable();

                if (response.Data != null && response.Data.Entities != null)
                {
                    foreach (CRMState state in response.Data.Entities)
                    {
                        for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                        {
                            Property prop = so.Properties[meth.ReturnProperties[c]];
                            prop = SetGetEntitiesProperties(prop, state);
                            prop = SetBulkActionTasksRESTProperties(prop, response);
                        }
                        so.Properties.BindPropertiesToResultTable();
                    }
                }
                else
                {
                    for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                    {
                        Property prop = so.Properties[meth.ReturnProperties[c]];
                        prop = SetBulkActionTasksRESTProperties(prop, response);
                    }
                    so.Properties.BindPropertiesToResultTable();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void RetrieveMultiple(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];
            //K2CRMHelper helper = new K2CRMHelper();
            WizardFunctions     helper   = new WizardFunctions();
            CRMRetrieveMultiple multiple = new CRMRetrieveMultiple();

            multiple.Config = crmconfig;

            try
            {
                multiple.LinkFromEntityName     = NotNull(so.Properties["LinkFromEntityName"].Value);
                multiple.LinkFromAttributeName  = NotNull(so.Properties["LinkFromAttributeName"].Value);
                multiple.LinkToEntityName       = NotNull(so.Properties["LinkToEntityName"].Value);
                multiple.LinkToAttributeName    = NotNull(so.Properties["LinkToAttributeName"].Value);
                multiple.ConditionAttributeName = NotNull(so.Properties["ConditionAttributeName"].Value);
                multiple.ConditionOperator      = NotNull(so.Properties["ConditionOperator"].Value);
                multiple.ConditionValue         = NotNull(so.Properties["ConditionValue"].Value);
                multiple.ReturnAttributes       = NotNull(so.Properties["ReturnAttributes"].Value);

                RestResponse <CRMRetrieveMultiple> response = helper.RetrieveMultiple(multiple, config);

                so.Properties.InitResultTable();

                foreach (CRMRetrieveMultipleReturn ret in response.Data.Results)
                {
                    for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                    {
                        Property prop = so.Properties[meth.ReturnProperties[c]];
                        prop = SetRetrieveMultipleProperties(prop, response);
                        prop = SetRetrieveMultipleReturnProperties(prop, ret);
                    }
                    so.Properties.BindPropertiesToResultTable();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 15
0
        private void CreateTask(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];
            K2CRMHelper helper = new K2CRMHelper();

            CRMTask task = new CRMTask();

            task.Category    = NotNull(so.Properties["Category"].Value);
            task.Description = NotNull(so.Properties["Description"].Value);
            task.DueDate     = DateTime.Parse(NotNull(so.Properties["DueDate"].Value));
            task.Duration    = int.Parse(NotNull(so.Properties["Duration"].Value));
            task.OwnerFQN    = NotNull(so.Properties["OwnerFQN"].Value);
            task.OwnerId     = NotNull(so.Properties["OwnerId"].Value);
            task.Owner       = NotNull(so.Properties["Owner"].Value);
            task.Priority    = int.Parse(NotNull(so.Properties["Priority"].Value));
            task.Regarding   = NotNull(so.Properties["Regarding"].Value);
            task.RegardingId = NotNull(so.Properties["RegardingId"].Value);
            task.State       = int.Parse(NotNull(so.Properties["State"].Value));
            task.Status      = int.Parse(NotNull(so.Properties["Status"].Value));
            task.Subcategory = NotNull(so.Properties["Subcategory"].Value);
            task.Subject     = NotNull(so.Properties["Subject"].Value);

            try
            {
                RestResponse <CRMTask> response = helper.CreateTask(task, config);

                so.Properties.InitResultTable();

                for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                {
                    Property prop = so.Properties[meth.ReturnProperties[c]];
                    prop = SetTaskProperties(prop, response);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public void DescribeSchema()
        {
            string       schemaPath   = Environment.CurrentDirectory + @"\K2.Demo.CRM.Functions.ServiceBroker.xml";
            SchemaObject schemaObject = SchemaManager.LoadSchemaXMLFile(schemaPath);

            //Populate the details of the current instance of the service base and create an instance of the service object

            SvcI.Name = schemaObject.ServiceInstanceName;
            SvcI.MetaData.DisplayName = schemaObject.ServiceInstanceDisplayName;
            SvcI.MetaData.Description = schemaObject.ServiceInstanceDescription;

            //Create the service object instance
            ServiceObject SO = new ServiceObject(schemaObject.ServiceInstanceName);

            SO.MetaData.DisplayName = schemaObject.ServiceInstanceDisplayName;
            SO.Active = true;

            //Create the properties for the serviceObject
            //Create a property for the serviceObject
            Property prop = null;

            //Dynamic Properties;
            foreach (SchemaObject.SchemaProperty sProp in schemaObject.SchemaProperties)
            {
                prop = SchemaManager.CreateProperty(sProp.Name, sProp.DisplayName, sProp.Description, sProp.TrueType, sProp.K2Type);
                //Add this property to the service object properties collection
                SO.Properties.Add(prop);
            }

            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = null;
            foreach (SchemaObject.SchemaMethod sMeth in schemaObject.SchemaMethods)
            {
                meth = SchemaManager.CreateMethod(sMeth.Name, sMeth.DisplayName, sMeth.Description, sMeth.K2Type, sMeth.InputProperties, sMeth.RequiredProperties, sMeth.ReturnProperties);
                SO.Methods.Add(meth);
            }

            SvcI.ServiceObjects.Add(SO);
        }