private void WorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //change cursor back
            Cursor = Cursors.Default;

            //unsubscribe from the importer's progress updates
            _importer.OnProgressUpdate -= ImportStatusUpdate;

            int errorCount = _importer.ErrorCount;

            _importer = null;
            //clear the status label
            ImportStatusUpdate("");

            //show a message to the user
            if (errorCount == 0)
            {
                MessageBox.Show("Job finished with no errors.");
            }
            else
            {
                MessageBox.Show("Job finished with errors. See the RecordError.log file for more details.");
            }
        }
        /// <summary>
        /// runs the job
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void runButton_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to run this job?", "Confirm run job", MessageBoxButtons.OKCancel);
            if(result==DialogResult.Cancel)
            {
                return;
            }

            //do some basic validations
            if (string.IsNullOrEmpty(sourceTextBox.Text))
            {
                MessageBox.Show("no source connection specified");
                return;
            }
            if (string.IsNullOrEmpty(targetTextBox.Text))
            {
                MessageBox.Show("no target connection specified");
                return;
            }
            if (!(stepListBox.Items.Count>0))
            {
                MessageBox.Show("no steps in job");
                return;
            }

            //change the cursor
            Cursor = Cursors.WaitCursor;

            //prepare the list of GUID mappings to pass to the importer object
            List<GuidMapping> mappings = new List<GuidMapping>();

            foreach (var item in guidMappingGridView.Rows)
            {
                DataGridViewRow dr = (DataGridViewRow)item;
                if (dr.Cells["sourceGuid"].Value != null && dr.Cells["targetGuid"].Value != null)
                {
                    Guid sourceGuid = new Guid(dr.Cells["sourceGuid"].Value.ToString());
                    Guid targetGuid = new Guid(dr.Cells["targetGuid"].Value.ToString());
                    mappings.Add(new GuidMapping { sourceId = sourceGuid, targetId = targetGuid });
                }
            }

            //prepare the list of job steps to pass to the importer object
            List<JobStep> steps = new List<JobStep>();
            foreach (var item in stepListBox.Items)
            {
                JobStep step = (JobStep)item;
                steps.Add(step);
            }

            //instantiate the importer object and set its properties
            _importer = new Importer();
            _importer.GuidMappings = mappings;
            _importer.JobSteps = steps;
            _importer.SourceString = sourceTextBox.Text;
            _importer.TargetString = targetTextBox.Text;
            _importer.MapBaseBu = mapBuCheckBox.Checked;
            _importer.MapBaseCurrency = mapCurrencyCheckBox.Checked;

            //subscribe to the importer object progress update event
            _importer.OnProgressUpdate += ImportStatusUpdate;
            
            //set up and call the backgroundworker to do the CRM queries and writing
            var worker = new BackgroundWorker();
            worker.DoWork += WorkerDoWork;
            worker.RunWorkerCompleted += WorkerRunWorkerCompleted;
            worker.RunWorkerAsync();
        }
Пример #3
0
        static void Main(string[] args)
        {
            var options = new Options();
            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                // consume Options instance properties
                if (options.Verbose)
                {
                    Console.WriteLine("Config file: {0}", options.ConfigFile);
                    Console.WriteLine("Source connection string: {0}", options.Source);
                    Console.WriteLine("Target connection string: {0}", options.Target);
                }

                //parse the config file
                ParseConfig(options.ConfigFile);

                //set source/target connection from parameters if specified - this will overwrite connections from the config file
                if (!string.IsNullOrEmpty(options.Source))
                {
                    _sourceString = options.Source;
                }
                if (!string.IsNullOrEmpty(options.Target))
                {
                    _targetString = options.Target;
                }

                //do some basic validations
                if (string.IsNullOrEmpty(_sourceString))
                {
                    Console.WriteLine("no source connection specified - exiting");
                    return;
                }
                if (string.IsNullOrEmpty(_targetString))
                {
                    Console.WriteLine("no target connection specified - exiting");
                    return;
                }
                if (!(_jobSteps.Count > 0))
                {
                    Console.WriteLine("no steps in job - exiting");
                    return;
                }

                Importer importer = new Importer();
                importer.GuidMappings = _guidMappings;
                importer.JobSteps = _jobSteps;
                importer.SourceString = _sourceString;
                importer.TargetString = _targetString;
                importer.MapBaseBu = _mapBaseBu;
                importer.MapBaseCurrency = _mapBaseCurrency;
                importer.Process();

                int errorCount = importer.ErrorCount;

                importer = null;
                
                //show a message to the user
                if (errorCount == 0)
                {
                    Console.WriteLine("Job finished with no errors.");
                }
                else
                {
                    Console.WriteLine("Job finished with errors. See the RecordError.log file for more details.");
                }
            }
        }