コード例 #1
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);
        }
コード例 #2
0
        private void mapDefaultTransactionCurrencyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                dataGridView1.EndEdit();
                Guid SourceTransactionCurrencyId = Guid.Empty;
                Guid TargetTransactionCurrencyId = Guid.Empty;
                //Get Source Default Transaction Currency
                string          fetchCurrency    = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' count='1'>
                                  <entity name='transactioncurrency'>
                                    <attribute name='transactioncurrencyid' />
                                    <attribute name='createdon' />
                                    <order attribute='createdon' descending='false' />
                                  </entity>
                                </fetch> ";
                MSCRMConnection connectionSource = rdt.currentProfile.getSourceConneciton();
                _serviceProxySource = cm.connect(connectionSource);

                EntityCollection resultSource = _serviceProxySource.RetrieveMultiple(new FetchExpression(fetchCurrency));
                foreach (var s in resultSource.Entities)
                {
                    SourceTransactionCurrencyId = (Guid)s.Attributes["transactioncurrencyid"];
                }

                //Get Target Default Transaction Currency
                MSCRMConnection connectionTarget = rdt.currentProfile.getTargetConneciton();
                _serviceProxyTarget = cm.connect(connectionTarget);

                EntityCollection resultTarget = _serviceProxyTarget.RetrieveMultiple(new FetchExpression(fetchCurrency));
                foreach (var t in resultTarget.Entities)
                {
                    TargetTransactionCurrencyId = (Guid)t.Attributes["transactioncurrencyid"];
                }

                //Add the mapping
                RecordMapping rr = new RecordMapping();
                rr.EntityName     = "transactioncurrency";
                rr.SourceRecordId = SourceTransactionCurrencyId;
                rr.TargetRecordId = TargetTransactionCurrencyId;
                rm.Add(rr);
                dataGridView1.DataSource = null;
                dataGridView1.DataSource = rm;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Mapping error: " + ex.Message);
            }
        }
コード例 #3
0
        private void buttonLoadReports_Click(object sender, EventArgs e)
        {
            if (comboBoxConnectionSource.SelectedItem == null)
            {
                MessageBox.Show("You must select a connection before loading Reports!");
                return;
            }

            toolStripStatusLabel1.Text = "Loading reports. Please wait...";
            Application.DoEvents();

            reportsList = new List <MSCRMReport>();
            dataGridView1.DataSource = reportsList;

            try
            {
                MSCRMConnection connection = cm.MSCRMConnections[comboBoxConnectionSource.SelectedIndex];
                _serviceProxy = cm.connect(connection);

                QueryExpression queryReports = new QueryExpression
                {
                    EntityName = "report",
                    ColumnSet  = new ColumnSet(true),
                    Criteria   = new FilterExpression(),
                };

                EntityCollection reports = _serviceProxy.RetrieveMultiple(queryReports);

                foreach (Entity report in reports.Entities)
                {
                    string      description = report.Attributes.Contains("description") ? (string)report["description"] : "";
                    MSCRMReport MSCRMReport = new MSCRMReport
                    {
                        Id          = report.Id,
                        Name        = (string)report["name"],
                        Description = description
                    };
                    reportsList.Add(MSCRMReport);
                }
                man.WriteReports(comboBoxConnectionSource.SelectedItem.ToString(), reportsList);
                dataGridView1.DataSource   = reportsList.ToList();
                toolStripStatusLabel1.Text = "Reports loaded.";
            }
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
            {
                MessageBox.Show("Error:" + ex.Detail.Message + "\n" + ex.Detail.TraceText);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    MessageBox.Show("Error:" + ex.Message + "\n" + ex.InnerException.Message);
                }
                else
                {
                    MessageBox.Show("Error:" + ex.Message);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Handles the Click event of the buttonLoadSolutionsImportJobs control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void buttonLoadSolutionsImportJobs_Click(object sender, EventArgs e)
        {
            try
            {
                List <MSCRMSolutionImportJob> Lst = new List <MSCRMSolutionImportJob>();
                dataGridView1.DataSource = Lst;

                if (comboBoxConnectionSource.SelectedItem == null)
                {
                    MessageBox.Show("You must select a connection before loading the Solution Import Jobs!");
                    return;
                }

                toolStripStatusLabel1.Text = "Loading Solution Import Jobs. Please wait...";
                Application.DoEvents();

                MSCRMConnection connection = cm.MSCRMConnections[comboBoxConnectionSource.SelectedIndex];
                _serviceProxy = cm.connect(connection);

                //Get Source Default Transaction Currency
                string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                      <entity name='importjob'>
                                        <attribute name='completedon' />
                                        <attribute name='createdby' />
                                        <attribute name='data' />
                                        <attribute name='importjobid' />
                                        <attribute name='modifiedon' />
                                        <attribute name='progress' />
                                        <attribute name='solutionname' />
                                        <attribute name='startedon' />
                                        <order attribute='createdon' descending='true' />
                                      </entity>
                                    </fetch> ";


                EntityCollection result = _serviceProxy.RetrieveMultiple(new FetchExpression(fetchXml));

                if (result.Entities.Count < 1)
                {
                    MessageBox.Show("There are no Solution Import Jobs!");
                    return;
                }
                List <MSCRMSolutionImportJob> ImportJobsList = new List <MSCRMSolutionImportJob>();
                foreach (Entity ImportJob in result.Entities)
                {
                    MSCRMSolutionImportJob job = new MSCRMSolutionImportJob();
                    if (ImportJob.Contains("completedon"))
                    {
                        job.completedon = (DateTime)ImportJob["completedon"];
                    }
                    if (ImportJob.Contains("createdby"))
                    {
                        job.createdby = ((EntityReference)ImportJob["createdby"]).Name;
                    }
                    if (ImportJob.Contains("data"))
                    {
                        job.data = (String)ImportJob["data"];
                    }
                    if (ImportJob.Contains("importjobid"))
                    {
                        job.importjobid = (Guid)ImportJob["importjobid"];
                    }
                    if (ImportJob.Contains("modifiedon"))
                    {
                        job.modifiedon = (DateTime)ImportJob["modifiedon"];
                    }
                    if (ImportJob.Contains("progress"))
                    {
                        job.progress = Math.Round((Double)ImportJob["progress"], 2);
                    }
                    if (ImportJob.Contains("solutionname"))
                    {
                        job.solutionname = (String)ImportJob["solutionname"];
                    }
                    if (ImportJob.Contains("startedon"))
                    {
                        job.startedon = (DateTime)ImportJob["startedon"];
                    }

                    if (job.importjobid != null && job.importjobid != Guid.Empty)
                    {
                        ImportJobsList.Add(job);
                    }
                }

                SortableBindingList <MSCRMSolutionImportJob> sorted = new SortableBindingList <MSCRMSolutionImportJob>(ImportJobsList);
                dataGridView1.DataSource = sorted;

                toolStripStatusLabel1.Text = "Loaded " + result.Entities.Count + " Import Jobs.";
            }
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
            {
                MessageBox.Show("Error:" + ex.Detail.Message + "\n" + ex.Detail.TraceText);
                toolStripStatusLabel1.Text = "Error.";
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    MessageBox.Show("Error:" + ex.Message + "\n" + ex.InnerException.Message);
                    toolStripStatusLabel1.Text = "Error.";
                }
                else
                {
                    MessageBox.Show("Error:" + ex.Message);
                    toolStripStatusLabel1.Text = "Error.";
                }
            }
        }
コード例 #5
0
        private void buttonLoadWorkflows_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBoxConnectionSource.SelectedItem == null)
                {
                    MessageBox.Show("You must select a connection before loading workflows!");
                    return;
                }

                toolStripStatusLabel1.Text = "Loading workflows. Please wait...";
                Application.DoEvents();

                string fetchXMLQuery = @"
                    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                    <entity name='workflow'><attribute name='workflowid' /><attribute name='name' />
                    <order attribute='name' descending='false' /><filter type='and'>
                    <condition attribute='type' operator='eq' value='1' />
                    <condition attribute='category' operator='eq' value='0' />
                    <condition attribute='statecode' operator='eq' value='1' />
                    <condition attribute='ondemand' operator='eq' value='1' />
                    </filter></entity></fetch>";

                MSCRMConnection connection = cm.MSCRMConnections[comboBoxConnectionSource.SelectedIndex];
                man._serviceProxy = cm.connect(connection);

                EntityCollection result = man._serviceProxy.RetrieveMultiple(new FetchExpression(fetchXMLQuery));

                List <MSCRMWorkflow> workflows = new List <MSCRMWorkflow>();
                foreach (var workflow in result.Entities)
                {
                    //this.comboBoxWorkflows.Items.AddRange(new object[] { (string)workflow["name"] });
                    workflows.Add(new MSCRMWorkflow {
                        Id = (Guid)workflow["workflowid"], Name = (string)workflow["name"]
                    });
                }
                man.WriteWorkflows(comboBoxConnectionSource.SelectedItem.ToString(), workflows);

                //Read workflows
                this.comboBoxWorkflows.Items.Clear();
                List <MSCRMWorkflow> readedWorkflows = man.ReadWorkflows(comboBoxConnectionSource.SelectedItem.ToString());
                foreach (MSCRMWorkflow workflow in readedWorkflows)
                {
                    this.comboBoxWorkflows.Items.AddRange(new object[] { workflow.Name });
                }
                this.Workflows = readedWorkflows;

                toolStripStatusLabel1.Text = "Workflows loaded.";
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    MessageBox.Show("Error:" + ex.Message + "\n" + ex.InnerException.Message);
                    toolStripStatusLabel1.Text = "Error.";
                }
                else
                {
                    MessageBox.Show("Error:" + ex.Message);
                    toolStripStatusLabel1.Text = "Error.";
                }
            }
        }