private void btnRun_Click(object sender, EventArgs e)
        {
            if (toolToExecute == null)
            {
                return;
            }

            toolToExecute.Initialize();
            if (!toolToExecute.Initialized)
            {
                return;
            }

            DotSpatial.Modeling.Forms.ToolProgress progForm = new DotSpatial.Modeling.Forms.ToolProgress(1);
            if (toolToExecute.MultiThreadRequired)
            {
                //We create a background worker thread to execute the tool
                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork             += BwDoWork;
                bw.RunWorkerCompleted += ExecutionComplete;

                object[] threadParameter = new object[2];
                threadParameter[0] = toolToExecute;
                threadParameter[1] = progForm;

                // Show the progress dialog and kick off the Async thread
                progForm.Show(this);
                bw.RunWorkerAsync(threadParameter);
            }
            else
            {
                try
                {
                    System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
                    toolToExecute.Execute(progForm);
                    toolToExecute.AfterExecution(null);
                    System.Windows.Forms.Cursor.Current = Cursors.Default;
                }
                catch (Exception ex)
                {
                    _MessageService.ShowError(null, ex.Message);
                }
            }
        }
示例#2
0
        private void DoDoubleClick(TreeNode theNode)
        {
            // Checks if the user double clicked a node and not a white spot
            if (theNode == null)
                return;

            // checks if the user clicked a tool or a category

            // Get an instance of the tool and dialog box to go with it
            toolToExecute = GetTool(theNode.Name);
            if (toolToExecute != null)
            {
                Extent ex = new Extent(-180, -90, 180, 90);

                // it wasn't a category?
                if (_legend != null)
                {
                    IMapFrame mf = _legend.RootNodes[0] as IMapFrame;
                    if (mf != null) ex = mf.ViewExtents;
                }

                ToolDialog td = new ToolDialog(toolToExecute, DataSets, ex);
                DialogResult tdResult = td.ShowDialog(this);
                while (tdResult == DialogResult.OK && td.ToolStatus != ToolStatus.Ok)
                {
                    MessageBox.Show(MessageStrings.ToolSetupIncorectly);
                    tdResult = td.ShowDialog(this);
                }
                if (tdResult == DialogResult.OK && td.ToolStatus == ToolStatus.Ok)
                {
                    //This fires when the user clicks the "OK" button on a tool dialog
                    //First we create the progress form
                    ToolProgress progForm = new ToolProgress(1);

                    //We create a background worker thread to execute the tool
                    BackgroundWorker bw = new BackgroundWorker();
                    bw.DoWork += BwDoWork;
                    bw.RunWorkerCompleted += executionComplete;

                    object[] threadParameter = new object[2];
                    threadParameter[0] = toolToExecute;
                    threadParameter[1] = progForm;

                    // Show the progress dialog and kick off the Async thread
                    progForm.Show(this);
                    bw.RunWorkerAsync(threadParameter);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Executes a model after verifying that it is ready
        /// </summary>
        /// <param name="error">A string parameter which will contains a error string if one is generated</param>
        /// <returns>Returns true if it executed succesfully</returns>
        public bool ExecuteModel(out string error)
        {
            //Make sure all the tools are ready for execution
            foreach (ToolElement te in _modelElements.FindAll(o => (o as ToolElement != null)))
            {
                if (te.ToolStatus == ToolStatus.Error || te.ToolStatus == ToolStatus.Empty)
                {
                    error = te.Name + " is not ready for execution";
                    return false;
                }
            }

            //The number of tools to execute
            _toolToExeCount = _modelElements.FindAll(o => (o as ToolElement != null)).Count;

            //First we create the progress form
            ToolProgress progForm = new ToolProgress(_toolToExeCount);

            //We create a background worker thread to execute the tool
            BackgroundWorker bw = new BackgroundWorker();
            bw.DoWork += BwToolThreader;

            object[] threadParamerter = new object[1];
            threadParamerter[0] = progForm;

            // Show the progress dialog and kick off the Async thread
            bw.RunWorkerAsync(threadParamerter);
            progForm.ShowDialog(this);

            error = string.Empty;

            //Make sure all the tools are ready for execution
            foreach (ToolElement te in _modelElements.FindAll(o => (o as ToolElement != null)))
                te.ExecutionStatus = ToolExecuteStatus.NotRun;

            return true;
        }