コード例 #1
0
        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());
        }
コード例 #2
0
        public override void BeforeSave()
        {
            CRM2011Connection otherConn = ModuleSettingsAccessor <CRM2011Settings> .Instance.Connections
                                          .FirstOrDefault(x => x.connectionId != this.connectionId && x.connectionName == this.connectionName);

            if (otherConn != null)
            {
                throw new InvalidOperationException("Another connection already exists with this name, please choose another name.");
            }
            base.BeforeSave();
            RetrieveEntityList();
        }
コード例 #3
0
 private IOrganizationService GetCRMClientServiceProxy()
 {
     try
     {
         IOrganizationService service = CRM2011Connection.GetServiceProxy(Connection.GetConnectionString());
         log.Info("Successfully connected to CRM client service");
         return(service);
     }
     catch (System.IO.FileNotFoundException)
     {
         // FileNotFound is sometimes thrown from within Microsoft.Xrm.Tooling.Connector, probably when the connection info is invalid.
         // (This Dynamics 2011 version no longer uses Microsoft.Xrm.Tooling.Connector, but it's unknown whether CrmConnection will throw the same exception.)
         throw new InvalidOperationException("Connection could not be made - check connection info or retry.");
     }
 }
コード例 #4
0
        public void RetrieveEntityList()
        {
            try
            {
                Log    log = new Log("CRMConnection");
                string trimmedConnectionString = GetConnectionString();
                trimmedConnectionString = trimmedConnectionString.Substring(0, trimmedConnectionString.IndexOf("Password"));
                log.Debug($"Making connection for '{this.connectionName}' ({this.connectionId}) with connection info \"{trimmedConnectionString}\".");

                IOrganizationService serviceProxy = CRM2011Connection.GetServiceProxy(GetConnectionString());

                if (serviceProxy != null)
                {
                    RetrieveAllEntitiesRequest req = new RetrieveAllEntitiesRequest()
                    {
                        EntityFilters = EntityFilters.Entity
                    };
                    RetrieveAllEntitiesResponse res = (RetrieveAllEntitiesResponse)serviceProxy.Execute(req);
                    this.allEntityNames        = res.EntityMetadata.Select(x => x.LogicalName).ToArray();
                    this.allEntityDisplayNames = res.EntityMetadata.Select(x =>
                    {
                        string displayName;
                        if (x.DisplayName.LocalizedLabels != null && x.DisplayName.LocalizedLabels.Count > 0)
                        {
                            displayName = x.DisplayName.LocalizedLabels[0].Label;
                        }
                        else
                        {
                            displayName = x.LogicalName;
                        }
                        return(displayName);
                    }).ToArray();

                    /*log.Debug($"Checksum for all entity names: {allEntityNames.SelectMany(x => x).Select(x => (int)x).Sum()}");
                     * log.Debug($"All entity names: {string.Join(", ", allEntityNames)}");*/
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                // FileNotFound is sometimes thrown from within Microsoft.Xrm.Tooling.Connector, probably when the connection info is invalid.
                this.allEntityNames        = null;
                this.allEntityDisplayNames = null;
                throw new InvalidOperationException("Connection could not be made - check connection info or retry.");
            }
        }
コード例 #5
0
 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]);
 }
コード例 #6
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();
        }
コード例 #7
0
 protected IOrganizationService GetServiceProxy()
 {
     return(CRM2011Connection.GetServiceProxy(GetConnectionString()));
 }
コード例 #8
0
 public CRM2011Settings()
 {
     EntityName  = "MSCRM Settings (2011)";
     Connections = new CRM2011Connection[0];
 }
コード例 #9
0
        internal static CRM2011Connection GetCRMConnectionForName(string connectionName)
        {
            CRM2011Connection connection = ModuleSettingsAccessor <CRM2011Settings> .Instance.Connections.FirstOrDefault(x => x.connectionName == connectionName);

            return(connection);
        }