Example #1
0
        /**
         * Removes exceptions in preparation for deleting a test
         */
        public bool DeleteExceptionsForTest(dao.QATest test)
        {
            // What's the OperDSName of the incoming errors?
            string dsName = "";

            // Make sure we've got a connection to ISDUT for exceptions
            string path = RestTransactionManager.Instance.BaseTransactionManager.extension().get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

            IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
            IWorkspace theIsdutWorkspace = workspaceFactory.OpenFromFile(path, 0);

            // Initialize an exception storage object
            if (this._exceptions == null || this._exceptions.OperationalDatasetName.Equals(dsName) == false)
                this._exceptions = new QAExceptionStorage(
                    theIsdutWorkspace,
                    this.Extension.get_SystemValue("db.isdut.schema"),
                    dsName);

            return this._exceptions.RemoveAll(test.Name);
        }
Example #2
0
        /**
         * Executes each of the DataQualityTests in order and collects their results
         */
        public int Execute()
        {
            // Establish the place to store the errors
            try
            {
                tm.TransactionManager theTM = this.Extension.TransactionManager;
                string theFCName = this.Extension.get_SystemValue("tm.template.dataerrors.table");

                if (theTM.Current() == null)
                {
                    // This isn't tied to any transaction, so prompt the user to save a pgdb
                    SaveFileDialog theSaveDialog = new SaveFileDialog();

                    theSaveDialog.Filter = "Personal Geodatabase files (*.mdb)|*.mdb";
                    theSaveDialog.FilterIndex = 1;
                    theSaveDialog.RestoreDirectory = true;
                    theSaveDialog.Title = "Save Test Results";

                    if(theSaveDialog.ShowDialog() == DialogResult.OK)
                    {
                        string theTemplate = this.Extension.get_SystemValue("tm.template.tant.pgdb");
                        this._errors = new QAErrorStorage(theTemplate, theSaveDialog.FileName, theFCName);
                    }
                    else
                        return -2;
                }
                else
                {
                    if (this._errors == null || this._errors.StorageWorkspace != theTM.Current().PGDBConnection)
                    {
                        this._errors = new QAErrorStorage(theTM.Current().PGDBConnection, theFCName);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error raised when establishing place to save errors:" + Environment.NewLine
                    + ex.Message,
                    "Error Storage Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                util.Logger.Write("Error raised when establishing place to save errors:" + Environment.NewLine
                    + ex.Message + Environment.NewLine + ex.StackTrace);
                return -1;
            }

            bool bShowErrorManager = false;
            ArrayList theNewErrors = new ArrayList();

            // Initialize log file
            string logDirectory = this.Extension.get_SystemValue(util.Logger.LOG_DIRECTORY_KEY)
                + Path.DirectorySeparatorChar;
            String logFileName = logDirectory + "isdut_qa_" + DateTime.Now.ToString("s").Replace(":", "-") + ".log";

            // Will put up a progress dialog, with a proper CancelTracker
            IProgressDialog2 thePDialog = null;

            try
            {
                ITrackCancel theCancelTracker = new CancelTrackerClass();
                IProgressDialogFactory theFactory = new ProgressDialogFactoryClass();
                thePDialog = (IProgressDialog2)theFactory.Create(theCancelTracker, this._app.hWnd);
                thePDialog.CancelEnabled = true;
                thePDialog.Description = "";
                thePDialog.Title = "Running QA Tests";
                thePDialog.Animation = esriProgressAnimationTypes.esriProgressGlobe;

                IStepProgressor theStepProgressor = (IStepProgressor)thePDialog;
                theStepProgressor.MinRange = 0;
                theStepProgressor.MaxRange = this.TestCount + 2;
                theStepProgressor.StepValue = 1;

                bool bContinue = true;
                bool bProblemWithTest = false;

                for (int i = 0; i < this.TestCount; i++)
                {
                    QATest theQATest = this._tests.get_Test(i);

                    theStepProgressor.Message = theQATest.Name;

                    if (theQATest != null && theQATest.IsActive)
                    {
                        IDataQualityTest theTest = theQATest.Test;
                        if (theTest != null)
                        {
                            int errCount = theTest.Execute(logFileName);

                            bContinue = theCancelTracker.Continue();
                            if (bContinue == false)
                                break;

                            if (errCount < 0)
                            {
                                bProblemWithTest = true;
                            }

                            if (theTest.ErrorCount > 0)
                            {
                                DataQualityError theDQError;
                                for (int j = 0; j < theTest.ErrorCount; j++)
                                {
                                    theDQError = theTest.get_Error(j);
                                    theDQError.Status = DataQualityError.STATUS_NEW;
                                    theNewErrors.Add(theDQError);
                                }
                            }

                            theTest.ClearErrors();
                        }
                    }
                    theStepProgressor.Step();
                }

                theStepProgressor.Message = "Filtering exceptions...";

                string path = RestTransactionManager.Instance.BaseTransactionManager.extension().get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

                IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                IWorkspace theIsdutWorkspace = workspaceFactory.OpenFromFile(path, 0);

                this._exceptions = new QAExceptionStorage(
                    theIsdutWorkspace,
                    this.Extension.get_SystemValue("db.isdut.schema"),
                    this._operationalAreaForLoadedTests);

                // Check each error to see if it is an exception
                foreach (object obj in theNewErrors)
                {
                    DataQualityError theError = (DataQualityError)obj;

                    if (_exceptions != null)
                    {
                        QAException theException = this._exceptions.FindException(theError);
                        if (theException != null) theError.Status = theException.Status;
                    }
                }

                theStepProgressor.Message = "Storing results...";

                // Pass the new errors to the QAErrorStorage
                this._errors.ClearErrors();
                this._errors.SetNewErrors(theNewErrors, this._operationalAreaForLoadedTests); // IsValid is true at this point

                theStepProgressor.Step();

                bShowErrorManager = true;

                // If any of the tests returned an error value, invalidate
                if (bProblemWithTest)
                {
                    this._errors.Invalidate();
                    MessageBox.Show("At least one test returned an error code, The test results have been written, but are not valid.",
                        "Problem Testing",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);
                }
            }
            catch (ErrorStorageException ese)
            {
                MessageBox.Show("There was an error storing the errors:" +Environment.NewLine
                    + ese.Message + Environment.NewLine + ese.StackTrace,
                    "Error Storage Problem",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
            }
            catch (Exception e)
            {
                if (theNewErrors.Count > 0)
                {
                    util.Logger.Write("Error raised while testing data: " + Environment.NewLine
                        + e.Message + Environment.NewLine + e.StackTrace,
                        util.Logger.LogLevel.Debug);
                    DialogResult theResult =
                        MessageBox.Show("An error occurred when testing data. Would you like to store the partial results?",
                        "Partial QA Results", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                    if (theResult == DialogResult.Yes)
                    {
                        this._errors.SetNewErrors(theNewErrors, this._operationalAreaForLoadedTests);
                        bShowErrorManager = true;
                    }
                }
                this._errors.Invalidate();
            }
            finally
            {
                if (thePDialog != null)
                    thePDialog.HideDialog();
                thePDialog = null;
            }

            if (bShowErrorManager)
            {
                UID theUID = new UIDClass();
                theUID.Value = "{73519A57-E89E-4773-87DA-E93661E23F6D}"; //ErrorManagerCmd
                // TODO:
                ICommandItem theCItem = this._app.Document.CommandBars.Find(theUID, false, false);
                if (theCItem != null)
                {
                    ((ui.ErrorManagerCmd)theCItem.Command).Open();
                }
                else
                    MessageBox.Show("Could not locate the Error Manager command button", "COM Registration", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return this.ErrorCount;
        }
Example #3
0
        /**
         * Applies new status, saves errors and creates/deletes exceptions as necessary
         */
        public void ApplyNewStatusToErrors(dao.QAError[] errors, string newStatus)
        {
            if (errors == null || errors.Length == 0)
                return;

            // Make sure we've got a connection to ISDUT for exceptions
            string path = RestTransactionManager.Instance.BaseTransactionManager.extension().get_SystemValue(DAOUtils.ISDUT_SEE_TEMP);

            IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
            IWorkspace theIsdutWorkspace = workspaceFactory.OpenFromFile(path, 0);

            // What's the OperDSName of the incoming errors?
            string dsName = errors[0].OperationalDatasetName;

            // Initialize an exception storage object
            if (this._exceptions == null || this._exceptions.OperationalDatasetName.Equals(dsName) == false)
                this._exceptions = new QAExceptionStorage(
                    theIsdutWorkspace,
                    this.Extension.get_SystemValue("db.isdut.schema"),
                    dsName);

            // Loop through each error
            for (int i = 0; i < errors.Length; i++)
            {
                if (errors[i].Error.Status.Equals(newStatus) == false)
                {
                    // Currently an exception? Remove it.
                    if (errors[i].Error.Status.Equals(DataQualityError.STATUS_EXCEPTION)
                        || errors[i].Error.Status.Equals(DataQualityError.STATUS_DEFERRED)
                        || newStatus.Equals(DataQualityError.STATUS_EXCEPTION)
                        || newStatus.Equals(DataQualityError.STATUS_DEFERRED))
                    {
                        QAException theException = this._exceptions.FindException(errors[i].Error);
                        this._exceptions.RemoveException(theException);
                    }

                    // Update the status
                    errors[i].Error.Status = newStatus;
                    this._errors.StoreError(errors[i]);

                    // New status is an exception? Create one.
                    if (newStatus.Equals(DataQualityError.STATUS_EXCEPTION)
                        || newStatus.Equals(DataQualityError.STATUS_DEFERRED))
                    {
                        this._exceptions.AddException(errors[i], newStatus);
                    }
                }
            }
        }