public override FlowStepToolboxInformation[] GetStepsInformation(string[] nodes, string flowId, string folderId) { // return step info if (nodes == null || nodes.Length != 4 || nodes[0] != "Data" || nodes[1] != PARENT_NODE) { return(new FlowStepToolboxInformation[0]); } List <FlowStepToolboxInformation> list = new List <FlowStepToolboxInformation>(); CRM2011Connection connection = CRM2011Connection.GetCRMConnectionForName(nodes[2]); if (connection == null) { return(new FlowStepToolboxInformation[0]); } ORM <CRM2011Entity> orm = new ORM <CRM2011Entity>(); CRM2011Entity[] crmEntities = orm.Fetch(new WhereCondition[] { new FieldWhereCondition("connection_id", QueryMatchType.Equals, connection.connectionId), new FieldWhereCondition("crm_entity_display_name", QueryMatchType.Equals, nodes[3]) }); foreach (CRM2011Entity entity in crmEntities) { list.Add(new FlowStepToolboxInformation("Get All Entities", nodes, string.Format(GET_ALL_STEP_INFO + "${0}", entity.entityId))); list.Add(new FlowStepToolboxInformation("Get Entity By Id", nodes, string.Format(GET_STEP_INFO + "${0}", entity.entityId))); list.Add(new FlowStepToolboxInformation("Add Entity", nodes, string.Format(ADD_STEP_INFO + "${0}", entity.entityId))); list.Add(new FlowStepToolboxInformation("Update Entity", nodes, string.Format(UPDATE_STEP_INFO + "${0}", entity.entityId))); list.Add(new FlowStepToolboxInformation("Delete Entity", nodes, string.Format(DELETE_STEP_INFO + "${0}", entity.entityId))); } return(list.ToArray()); }
public override string[] GetSubCategories(string[] nodes, string flowId, string folderId) { if (nodes == null || nodes.Length == 0) { return(new string[0]); } if (nodes[0] == "Data") { if (nodes.Length == 1) { return new string[] { PARENT_NODE } } ; if (nodes[1] == PARENT_NODE) { if (nodes.Length == 2) { return(ModuleSettingsAccessor <CRM2011Settings> .Instance.Connections.Select(x => x.ConnectionName).ToArray()); } else if (nodes.Length == 3) { CRM2011Connection connection = CRM2011Connection.GetCRMConnectionForName(nodes[2]); if (connection == null) { return(new string[0]); } ORM <CRM2011Entity> orm = new ORM <CRM2011Entity>(); CRM2011Entity[] crmEntities = orm.Fetch(new WhereCondition[] { new FieldWhereCondition("connection_id", QueryMatchType.Equals, connection.connectionId) }); return(crmEntities.Select(t => t.CRMEntityDisplayName).ToArray()); } } } return(new string[0]); }
public override void BeforeSave() { CRM2011Connection specifiedConnection = connection; if (specifiedConnection == null) { // If 'connection' is null, this might be an import. log.Debug("sConnection is null, fetching by ID"); specifiedConnection = CRM2011Connection.GetCRMConnectionById(connectionId); if (specifiedConnection != null) { Connection = specifiedConnection; } } // If a connection exists at this point, make sure this entity name doesn't already exist for this connection: if (specifiedConnection != null) { SetNamesFromSelectedName(); log.Debug($"Checking whether entity already exists with connection_id '{specifiedConnection.connectionId}' and crm_entity_name '{CRMEntityName}'."); ORM <CRM2011Entity> orm = new ORM <CRM2011Entity>(); var conditions = new List <WhereCondition> { new FieldWhereCondition("connection_id", QueryMatchType.Equals, specifiedConnection.connectionId), new FieldWhereCondition("crm_entity_name", QueryMatchType.Equals, this.CRMEntityName) }; if (!string.IsNullOrWhiteSpace(this.entityId)) { // (if ID is the same, this is an edit) conditions.Add(new FieldWhereCondition("entity_id", QueryMatchType.DoesNotEqual, this.entityId)); } CRM2011Entity otherEntity = orm.Fetch(conditions.ToArray()).FirstOrDefault(); log.Debug($"entity: {otherEntity?.CRMEntityDisplayName ?? "(null)"}"); if (otherEntity != null) { throw new InvalidOperationException("This entity already exists for this connection."); } } if (specifiedConnection == null) { // If the ID is missing, this might be an import. Check for a matching name: log.Debug("sConnection is null, fetching by name"); specifiedConnection = CRM2011Connection.GetCRMConnectionForName(connectionName); } if (specifiedConnection == null) { // If no connection was found by ID or by name, create one: log.Debug("sConnection is null, creating"); specifiedConnection = new CRM2011Connection() { ConnectionName = connectionName, OrganisationUrl = organisationUrl, Domain = domain, UserName = userName, Password = password }; // Add new connection to settings: CRM2011Connection[] oldConnections = ModuleSettingsAccessor <CRM2011Settings> .Instance.Connections; ModuleSettingsAccessor <CRM2011Settings> .Instance.Connections = oldConnections.Concat(new[] { specifiedConnection }).ToArray(); log.Debug($"about to save new connections..."); ModuleSettingsAccessor <CRM2011Settings> .SaveSettings(); specifiedConnection = CRM2011Connection.GetCRMConnectionForName(connectionName); if (specifiedConnection == null) { throw new EntityNotFoundException("CRMConnection was not created successfully."); } log.Debug("new connections saved."); } if (specifiedConnection != null) { // Update our data to match the connection's data: log.Debug("sConnection exists, updating data to match it..."); Connection = specifiedConnection; connectionId = specifiedConnection.connectionId; connectionName = specifiedConnection.ConnectionName; organisationUrl = specifiedConnection.OrganisationUrl; domain = specifiedConnection.Domain; userName = specifiedConnection.UserName; password = specifiedConnection.Password; } SetNamesFromSelectedName(); base.BeforeSave(); AddOrUpdateCRMEntity(); }