Exemplo n.º 1
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.";
                }
            }
        }
        /// <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.";
                }
            }
        }