/// <summary>
 /// Sets the source conneciton.
 /// </summary>
 /// <remarks>
 /// The SourceConnectionName must be previously set.
 /// </remarks>
 public void setSourceConneciton()
 {
     if (!string.IsNullOrEmpty(SourceConnectionName))
     {
         SourceConnection = cm.getConnection(SourceConnectionName);
     }
 }
Пример #2
0
        /// <summary>
        /// Downloads the env structure.
        /// </summary>
        /// <param name="connectionName">Name of the connection.</param>
        /// <returns></returns>
        private List <List <string> > downloadEnvStructure(string connectionName)
        {
            try
            {
                toolStripStatusLabel1.Text = "Loading entities from source. Please wait...";
                Application.DoEvents();
                this.entitiesNames = new List <List <string> >();
                MSCRMConnection connection = cm.getConnection(connectionName);
                _serviceProxy = cm.connect(connection);
                IOrganizationService       service = (IOrganizationService)_serviceProxy;
                RetrieveAllEntitiesRequest request = new RetrieveAllEntitiesRequest()
                {
                    EntityFilters         = EntityFilters.Entity,
                    RetrieveAsIfPublished = false
                };

                // Retrieve the MetaData.
                RetrieveAllEntitiesResponse         AllEntitiesResponse = (RetrieveAllEntitiesResponse)_serviceProxy.Execute(request);
                IOrderedEnumerable <EntityMetadata> EMD = AllEntitiesResponse.EntityMetadata.OrderBy(ee => ee.LogicalName);

                foreach (EntityMetadata currentEntity in EMD)
                {
                    if (currentEntity.IsIntersect.Value == false && currentEntity.IsValidForAdvancedFind.Value)
                    {
                        entitiesNames.Add(new List <string> {
                            currentEntity.LogicalName, currentEntity.PrimaryIdAttribute
                        });
                    }
                }

                WriteEnvStructure(connectionName, entitiesNames);
                toolStripStatusLabel1.Text = "Entities loaded from source.";
                return(entitiesNames);
            }
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
            {
                toolStripStatusLabel1.Text = "Error.";
                MessageBox.Show("Error:" + ex.Detail.Message + "\n" + ex.Detail.TraceText, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                toolStripStatusLabel1.Text = "Error.";
                if (ex.InnerException != null)
                {
                    MessageBox.Show("Error:" + ex.Message + "\n" + ex.InnerException.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Error:" + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return(null);
        }