Beispiel #1
0
        public int getCounts(SEE see, BusinessArea ba, ArrayList r)
        {
            IWorkspace sdeConn = ext.TransactionManager.ConnectionManager.getConnection(ba);

            ArrayList layers = null; // List<LayerConfig>
            if(ba == BusinessArea.ForAdmBound)
            {
                layers = ext.TransactionManager.transactionConfig().AdminBoundaryLayers;
            }
            else
            {
                if(ba == BusinessArea.Tantalis)
                {
                    layers = ext.TransactionManager.transactionConfig().TantalisLayers;
                }
                else
                {
                    layers = new ArrayList();
                }
                }

            string prefix = null;
            switch(ba)
            {
                case BusinessArea.ForAdmBound:
                    prefix = this.ext.get_SystemValue(DAOUtils.FADM_SCHEMA_KEY);
                    break;
                case BusinessArea.Tantalis:
                    prefix = this.ext.get_SystemValue(DAOUtils.TANT_SCHEMA_KEY);
                    break;
            }

            int rint = 0;
            for(IEnumerator e = layers.GetEnumerator();e.MoveNext();)
            {
                TransactionConfig.LayerConfig layer = (TransactionConfig.LayerConfig)e.Current;
                try
                {
                    int cnt = count(prefix, layer, sdeConn, see);
                    rint += cnt;
                    r.Add(layer.OsdbLayerName + ": " + cnt + " Features ");
                }
                catch (HandledException ex)
                {
                    // ignore
                    System.Diagnostics.Debug.WriteLine(ex.Message + "\n" + ex.StackTrace); //ajw
                }
            }
            return rint;
        }
Beispiel #2
0
        private void SubmitSee(string name, string description, string path, string userName, SEE see, bool generated)
        {
            try
            {
                BaseTransactionManager.startHourGlass("Waiting for SUITT FME server...");

                // get GeoJSON
                string geoJson = GeoJSONConverter.ConvertPolygonToJson(see.Shape);

                string type = @"AreaOfInterestResource";

                JObject job = new JObject();
                job.Add("@type", type);
                job.Add("areaOfInterest", geoJson);

                string json = job.ToString();

                // Submit the SEE/AOI
                RestRequest aoiRequest = ClientRequest("sees/" + see.RestID + "/aoi", Method.POST, true);
                aoiRequest.RequestFormat = DataFormat.Json;
                aoiRequest.AddParameter("application/json", json, ParameterType.RequestBody);

                var aoiResponse = ApplicationClient.Execute(aoiRequest);

                if (aoiResponse.StatusCode == System.Net.HttpStatusCode.Accepted) LoadPGDB(name, description, path, userName, see, generated);
                else
                {
                    App.CurrentTool = null;
                    BaseTransactionManager.endHourGlass();

                    MessageBox.Show("Error submitting SEE to SUITT. " + aoiResponse.StatusDescription);
                }
            }
            catch (Exception e)
            {
                Logger.Warn(e);
                Logger.DeactivateLogger();

                App.CurrentTool = null;
                BaseTransactionManager.endHourGlass();

                throw e;
            }
        }
Beispiel #3
0
        private void LoadPGDB(string name, string description, string path, string userName, SEE see, bool generated)
        {
            // We've successfully submitted the SEE/AOI to SUITT
            // Poll for a status response and retrieve template (async loop and a timer)
            // Once we have a completed transaction download the PGDB
            // Place the PGDB in the 'path' location. Rename the file if necessary
            // finish building template with C, P, and E tables, and complete Transaction object

            bool aoiReady = false;
            bool errorOccured = false;
            string errorMessage = "";
            int attempts = 0;

            BaseTransactionManager.startHourGlass("Waiting for SUITT FME Server...");

            while (!aoiReady && !errorOccured && attempts < 200)
            {
                try
                {
                    // get the status. if it equals complete, then we've got a PGDB ready, so trigger a request for the download
                    // otherwise, keep waiting.
                    string[] transactionStatus = GetTransactionStatus(see.RestID);

                    if (transactionStatus[0].ToUpper().Equals("READY")) aoiReady = true;
                    else if (transactionStatus[0].ToUpper().Equals("ERROR"))
                    {
                        errorOccured = true;
                        errorMessage = transactionStatus[1];
                    }
                    else
                    {
                        attempts++;
                        Thread.Sleep(1000);
                    }
                }
                catch (Exception e)
                {
                    errorOccured = true;
                }
            }

            if (aoiReady && !errorOccured)
            {
                RestRequest aoiFetchRequest = ClientRequest("sees/" + see.RestID + "/features", Method.GET, true);
                aoiFetchRequest.AddHeader("Accept", "application/octet-stream");
                aoiFetchRequest.RequestFormat = DataFormat.Json;

                var aoiFetchResponse = ApplicationClient.Execute(aoiFetchRequest);

                if (aoiFetchResponse.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    try
                    {
                        // create the file and path name for the PGDB
                        String filePath = path + "\\" + name + ".gdb.zip";

                        //copy the PGDB stream to the path
                        File.WriteAllBytes(filePath, aoiFetchResponse.RawBytes);

                        //unzip downloaded zip file (will be a folder)
                        ZipFile zf = new ZipFile(filePath);
                        zf.ExtractAll(path);
                        zf = null;

                        string transactionDir = "";

                        try
                        {
                            transactionDir = Directory.GetDirectories(path).Where(d => d.StartsWith(path + "\\" + see.RestID.Replace("-", "").ToUpper())).ToList().First();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("The zip file returned from the SUITT service contains no data. Please retry your checkout.");
                            throw ex;
                        }

                        // rename the folder
                        Directory.Move(transactionDir, path + "\\" + name + ".gdb");

                        //delete zip file
                        // nulling out of the zf object doesn't release the zip file
                        //File.Delete(filePath);

                        // we have the map downloaded, so create the transaction
                        BaseTransactionManager.Create(path + "\\" + name + ".gdb", generated, see, description, userName);

                        // We have a transaction created, so start initializing the map and returning control
                        // back to the user

                        string mxdPath = path + "\\" + name + ".mxd";
                        BaseTransactionManager.initMap(BusinessArea.Tantalis, mxdPath, description, userName);

                        // flag transaction as checked out
                        SetTransactionStatus("CHECKED_OUT", "Spatial Edit Extent is checked out for processing.", see.RestID);

                        GetMessage(see.RestID);
                    }
                    catch (Exception e)
                    {
                        Logger.Warn(e);
                        Logger.DeactivateLogger();

                        MessageBox.Show("Error submitting SEE to SUITT. " + e.Message);
                    }
                    finally
                    {
                        App.CurrentTool = null;
                        BaseTransactionManager.endHourGlass();
                    }
                }
                else
                {
                    MessageBox.Show("An unknown communication error occured processing the transaction: " + aoiFetchResponse.ErrorMessage);
                }
            }
            else if (!aoiReady && !errorOccured)
            {
                App.CurrentTool = null;
                BaseTransactionManager.endHourGlass();

                DialogResult rslt = MessageBox.Show("The PGDB has not completed generating, but has exceeded the expected time-out. Click Retry to continue waiting, or click cancel to cancel the process?", "Timeout exceeded", MessageBoxButtons.RetryCancel);
                if (rslt == DialogResult.Retry)
                {
                    BaseTransactionManager.startHourGlass("Waiting for SUITT FME Server...");
                    LoadPGDB(name, description, path, userName, see, generated);
                }
            }
            else if(errorOccured)
            {
                App.CurrentTool = null;
                BaseTransactionManager.endHourGlass();

                MessageBox.Show("Error submitting SEE to SUITT. " + errorMessage);
            }
        }
Beispiel #4
0
        public void CreateTransaction(string name, string description, string path, string userName, SEE see, bool generated)
        {
            try
            {
                BaseTransactionManager.startHourGlass("Submitting SEE to SUITT Server at " + BaseApplicationUrl);

                JObject job = new JObject();
                job.Add("@type", RestObjectType);
                job.Add("name", name);
                job.Add("description", description);

                string json = job.ToString();

                // send the SEE to the REST service.
                RestRequest request = ClientRequest("sees", Method.POST, true);
                request.RequestFormat = DataFormat.Json;
                request.AddParameter("application/json", json, ParameterType.RequestBody);

                var response = ApplicationClient.Execute(request);

                if (response.StatusCode == System.Net.HttpStatusCode.Created)
                {
                    Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(response.Content);
                    see.RestID = values["guid"].ToString();
                    NewTransactionSeeID = see.RestID;

                    SubmitSee(name, description, path, userName, see, generated);
                }
                else
                {
                    App.CurrentTool = null;
                    BaseTransactionManager.endHourGlass();

                    throw new Exception("Error submitting SEE to SUITT. " + response.StatusDescription);
                }
            }
            catch (Exception e)
            {
                Logger.Warn(e);
                Logger.DeactivateLogger();

                App.CurrentTool = null;
                BaseTransactionManager.endHourGlass();

                throw e;
            }
        }
Beispiel #5
0
        /**
         *	Inits the current Transaction to the area specified in the SEE token. This
         *  method will import any additional features from the OSDB as required.
         *
         *	My be a lengthy Operation
         *
         *	Throws exceptions when:
         *		-	An IO Error occurs
         */
        public void Init(SEE token, int UTM)
        {
            ISpatialReference utmSR = this.transactionManager.getUTM(UTM);

            SEEDAO dao = new SEEDAO(this.transactionManager.extension());
            // throwing server faults...
            dao.insert(this, token, utmSR);

            // DO we need the extract call here?
            // data should all be previously extracted.

            extract(token.Shape,true);
        }
Beispiel #6
0
        /**
         *	Expands the current Transaction to include the area specified in the SEE token. This
         *  method will import any additional features from the OSDB as required.
         *
         *	My be a lengthy Operation
         *
         *	Throws exceptions when:
         *		-	An IO Error occurs
         */
        public void Expand(SEE token)
        {
            // now handled by a REST request. No expanding stored directly by
            // the application to the database

            // CREATE A NEW TRANSACTION
            // COPY OLD TRANSACTIONAL DATA INTO NEW TRANSACTION
            // DELETE OLD TRANSACTION

            //// order is important here
            IPolygon previous = get_SEE();

            SEEDAO dao = new SEEDAO(this.transactionManager.extension());
            dao.update(this,token);

            if(previous == null)
            {
                // this path is only probably for some odd cases -- and during dev
                extract(token.Shape,true);
                return;
            }

            // buggy
            // http://forums.esri.com/Thread.asp?c=93&f=1170&t=88297#242834

            ITopologicalOperator2 op_original = (ITopologicalOperator2)previous;
            op_original.IsKnownSimple_2 = false;
            try
            {
                op_original.Simplify();
            }
            catch (Exception e)
            {
                Logger.Warn(e);
            }

            ITopologicalOperator2 op_new = (ITopologicalOperator2)token.Shape;
            op_new.IsKnownSimple_2 = false;
            try
            {
                op_new.Simplify();
            }
            catch (Exception e)
            {
                Logger.Warn(e);
            }

            if (previous.SpatialReference == null)
            {
                previous.SpatialReference = this.transactionManager.extension().FocusMap.SpatialReference;
            }

            if (token.Shape.SpatialReference == null)
            {
                token.Shape.SpatialReference = this.transactionManager.extension().FocusMap.SpatialReference;
            }

            token.Shape.Project(previous.SpatialReference);

            previous.SnapToSpatialReference();
            token.Shape.SnapToSpatialReference();

            IPolygon t = null;
            try
            {
                t = (IPolygon)(op_new.Difference((IPolygon)previous));
                if (op_new is ITopologicalOperator2)
                {
                    op_original = (ITopologicalOperator2)t;
                    try
                    {
                        op_new.Simplify();
                    }
                    catch (Exception e)
                    {
                        Logger.Warn(e);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Write(e);
                t = token.Shape; // less efficient
            }
            try
            {
                extract(t, false);
            }
            catch (HandledException he)
            {
                // rethrow -- probably connection related
                throw he;
            }
            catch (Exception e)
            {
                Logger.Write(e);
                // probably a bad shape resulting from subtraction above -- retry.

                extract(token.Shape, false); // less efficient
            }
        }
Beispiel #7
0
        private int count(string prefix, TransactionConfig.LayerConfig layer, IWorkspace sdeConn, SEE see)
        {
            if(prefix !=null && !prefix.Equals("") && !prefix.EndsWith("."))
            {
                prefix = prefix+".";
            }

            Logger.Write("Opening "+prefix+layer.OsdbLayerName);
            IFeatureClass osdb_fc = null;
            try
            {
                osdb_fc = ((IFeatureWorkspace)sdeConn).OpenFeatureClass(prefix+layer.OsdbLayerName);
            }
            catch(Exception e)
            {
                throw new HandledException(e);
            }

            ITable osdb_tbl = (ITable)osdb_fc;
            string[] keys = layer.Keys;

            IRelationshipClass osdb_rltn = null;
            if(layer.JoinName != null)
            {
                Logger.Write("Creating Join");
                IMemoryRelationshipClassFactory memoryRelClassFactory = new MemoryRelationshipClassFactoryClass();

                ITable osdb_jtbl = null;
                try
                {
                    osdb_jtbl = ((IFeatureWorkspace)sdeConn).OpenTable(prefix+layer.JoinTable);
                }
                catch(Exception e)
                {
                    MessageBox.Show("Table "+prefix+layer.JoinTable+" Not Found in OSDB",
                        "EXCEPTION", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    throw new HandledException(e);
                }

                string kprint = null;
                for(int i=0;i<keys.Length;i++)
                {
                    if(kprint == null)
                    {
                        kprint = keys[i];
                    }
                    else
                    {
                        kprint = kprint+","+keys[i];
                    }
                }

                osdb_rltn = memoryRelClassFactory.Open(layer.JoinName,osdb_fc,kprint,(IObjectClass)osdb_jtbl,kprint,
                    "forward","backward",esriRelCardinality.esriRelCardinalityOneToOne);
            }

            ISpatialFilter osdb_filter = new SpatialFilterClass();
            osdb_filter.Geometry = see.Shape;
            osdb_filter.GeometryField = osdb_fc.ShapeFieldName;
            osdb_filter.SubFields = osdb_fc.OIDFieldName;
            osdb_filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelRelation;
            if (layer.isPoint)
            {
                osdb_filter.SpatialRelDescription = Transaction.ExtractPointMask;
            }
            else
            {
                if (layer.isLine)
                {
                    osdb_filter.SpatialRelDescription = Transaction.ExtractLineMask;
                }
                else
                {
                    if (layer.isPoly)
                    {
                        osdb_filter.SpatialRelDescription = Transaction.ExtractPolyMask;
                    }
                    else
                    {
                        // default
                        osdb_filter.SpatialRelDescription = Transaction.ExtractPolyMask;
                    }
                }
            }

            Logger.Write("Create extract cursor");
            ICursor osdb_cursor = null;
            int r = 0;
            try
            {
                osdb_cursor = osdb_tbl.Search(osdb_filter, false);
                for (IRow row = osdb_cursor.NextRow(); row != null; row = osdb_cursor.NextRow())
                {
                    if (row != null)
                        r++;
                }
            }
            finally
            {
                if (osdb_filter != null)
                {
                    Utils.Release(osdb_filter);
                }
                if (osdb_cursor != null)
                {
                    Utils.Release(osdb_cursor);
                }
            }
            return r;
        }