Exemple #1
0
        private void Export(string alias, Dictionary <esriGeometryType, IFeatureClass> fcs)
        {
            // Connect to the WMX Repository
            IJTXDatabaseManager dbMgr = new JTXDatabaseManager();

            db = dbMgr.GetDatabase(alias);

            IJTXTransactionManager transactionMgr = db.TransactionManager;

            // Get all transactions and insert into the appropriate ouput feature class
            IJTXTransactionSet transactions = transactionMgr.GetLoggedTransactions(new QueryFilter());

            for (int i = 0; i < transactions.Count; i++)
            {
                try
                {
                    IJTXTransaction2 trans = transactions.get_Item(i) as IJTXTransaction2;
                    InsertTransaction(trans, fcs);
                }
                catch (Exception)
                {
                    bInsertErrors = true;
                }
            }
            db = null;
        }
Exemple #2
0
        private void InsertTransaction(IJTXTransaction2 trans, Dictionary <esriGeometryType, IFeatureClass> fcs)
        {
            // Currently does not do anythign with the annotation elements

            // Add and Delete transactions will only have a single geometry
            // But Modify transactions will have a before and an After geometry
            for (int i = 0; i < trans.Geometry.GeometryCount; i++)
            {
                IGeometry     geom = trans.Geometry.get_Geometry(i);
                IFeatureClass fc   = fcs[geom.GeometryType];
                IFeature      feat = fc.CreateFeature();

                // Figure out the more detailed transaction type for modified (Before or After feature)
                jtxTransactionType transType = trans.TransactionType;
                if (transType == jtxTransactionType.jtxTransactionTypeModify)
                {
                    if (i == 0) // The first item is the before
                    {
                        transType = jtxTransactionType.jtxTransactionTypeModify | jtxTransactionType.jtxTransactionTypeDelete;
                    }
                    else // There should only be 2 items
                    {
                        transType = jtxTransactionType.jtxTransactionTypeModify | jtxTransactionType.jtxTransactionTypeAdd;
                    }
                }

                // Set the basic values
                feat.set_Value(idIdx, trans.GFID);
                feat.set_Value(idFieldIdx, trans.GFIDField);
                feat.set_Value(jobIdIdx, trans.JobID);
                feat.set_Value(loggedByIdx, trans.LoggedBy);
                feat.set_Value(tabNameIdx, trans.TableName);
                feat.set_Value(transTypeIdx, transType);
                feat.set_Value(transDateIdx, trans.TransactionDate);
                feat.set_Value(sessionIdIdx, trans.SessionID);

                IJTXTransactionAttributeSet attribs = trans.Attributes;

                // Convert the attributes to a basic XML fragment
                // This will be of the form:
                // <Attributes>
                //   <Attribute>
                //     <FieldName>Field1</FieldName>
                //     <Value>SomeValue</Value>
                //   </Attribute>
                //   ...
                // </Attributes>
                XElement attribsXML = new XElement("Attributes");
                for (int j = 0; j < attribs.Count; j++)
                {
                    IJTXTransactionAttribute attribute = attribs.get_Item(j);
                    string val;
                    // Attributes also have before and after values. Based on the transaction type, see if we need the before or after value
                    if ((transType & jtxTransactionType.jtxTransactionTypeDelete) != 0)
                    {
                        val = attribute.PreviousValue;
                    }
                    else
                    {
                        val = attribute.NewValue;
                    }

                    attribsXML.Add(
                        new XElement("Attribute",
                                     new XElement("FieldName", attribute.FieldName),
                                     new XElement("Value", val)
                                     ));
                }
                string attribString = attribsXML.ToString(SaveOptions.DisableFormatting);
                feat.set_Value(attributesIdx, attribString == null ? DBNull.Value : (object)attribString);

                // Set the spatial reference of the geometry
                var sourceSR = GetSpatialReference(trans.TableName);
                geom.SpatialReference = sourceSR;
                var targetSR = ((IGeoDataset)fc).SpatialReference;
                if (sourceSR != null && targetSR != null && sourceSR.Name != targetSR.Name)
                {
                    geom.Project(targetSR); // Project to the right SR
                }
                feat.Shape = geom;

                feat.Store();
            }
        }