Esempio n. 1
0
        public bool OpenErrorFeatureClass()
        {
            // Open stored 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 open a pgdb
                    OpenFileDialog theOpenDialog = new OpenFileDialog();

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

                    if(theOpenDialog.ShowDialog() == DialogResult.OK)
                    {
                        IWorkspaceFactory2 theFactory = new FileGDBWorkspaceFactoryClass();
                        IWorkspace thePersonalGDB = theFactory.OpenFromFile(theOpenDialog.FileName, 0);
                        this._errors = new QAErrorStorage(thePersonalGDB, theFCName);
                        this._errors.FetchErrors();
                    }
                    else
                        return false;
                }
                else
                {
                    if (this._errors == null || this._errors.StorageWorkspace != theTM.Current().PGDBConnection)
                    {
                        this._errors = new QAErrorStorage(theTM.Current().PGDBConnection, theFCName);
                        this._errors.FetchErrors();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error raised when opening error storage:" + Environment.NewLine
                    + ex.Message,
                    "Error Storage Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                util.Logger.Write("Error raised when opening error storage:" + Environment.NewLine
                    + ex.Message + Environment.NewLine + ex.StackTrace);
                return false;
            }
            return true;
        }
Esempio n. 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;
        }