Ejemplo n.º 1
0
        /// <summary>
        ///     Exports the version differences to the specified export file.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="exportFileName">Name of the export file.</param>
        /// <param name="exportOption">The export option.</param>
        /// <param name="overwrite">if set to <c>true</c> when the delta file should be overwritten when it exists.</param>
        public static void ExportDataChanges(this IVersion source, IVersion target, string exportFileName, esriExportDataChangesOption exportOption, bool overwrite)
        {
            IVersionDataChangesInit vdci         = new VersionDataChangesClass();
            IWorkspaceName          wsNameSource = (IWorkspaceName)((IDataset)source).FullName;
            IWorkspaceName          wsNameTarget = (IWorkspaceName)((IDataset)target).FullName;

            vdci.Init(wsNameSource, wsNameTarget);

            IExportDataChanges2 edc = new DataChangesExporterClass();

            edc.ExportDataChanges(exportFileName, exportOption, (IDataChanges)vdci, overwrite);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Gets the differences between the <paramref name="source" /> and <paramref name="target" /> versions.
        /// </summary>
        /// <param name="source">The source (or child) version.</param>
        /// <param name="target">The target (or parent) version.</param>
        /// <param name="filter">The predicate to filter the results.</param>
        /// <param name="predicate">
        ///     The predicate that defines a set of criteria and determines whether the specified differences
        ///     will be loaded.
        /// </param>
        /// <param name="differenceTypes">The type of differences that will be determined.</param>
        /// <returns>
        ///     Returns a <see cref="Dictionary{String, DifferenceRow}" /> representing the differences for the
        ///     table (or key).
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     target
        ///     or
        ///     differenceTypes
        /// </exception>
        public static Dictionary <string, IEnumerable <DifferenceRow> > GetDifferences(this IVersion source, IVersion target, IQueryFilter filter, Func <string, ITable, bool> predicate, params esriDifferenceType[] differenceTypes)
        {
            if (source == null)
            {
                return(null);
            }
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (differenceTypes == null)
            {
                throw new ArgumentNullException("differenceTypes");
            }

            var list = new Dictionary <string, IEnumerable <DifferenceRow> >();

            IVersionDataChangesInit vdci         = new VersionDataChangesClass();
            IWorkspaceName          wsNameSource = (IWorkspaceName)((IDataset)source).FullName;
            IWorkspaceName          wsNameTarget = (IWorkspaceName)((IDataset)target).FullName;

            vdci.Init(wsNameSource, wsNameTarget);

            IDataChanges           dataChanges = (IDataChanges)vdci;
            IEnumModifiedClassInfo enumMci     = dataChanges.GetModifiedClassesInfo();

            enumMci.Reset();
            IModifiedClassInfo mci;

            while ((mci = enumMci.Next()) != null)
            {
                // The table references are not disposed due to the enumerable return which would result in an RCW exception.
                string tableName   = mci.ChildClassName;
                ITable sourceTable = ((IFeatureWorkspace)source).OpenTable(tableName);
                if (predicate(tableName, sourceTable))
                {
                    IVersionedTable versionedTable = sourceTable as IVersionedTable;
                    ITable          table          = ((IFeatureWorkspace)target).OpenTable(tableName);
                    if (versionedTable != null && table != null)
                    {
                        var rows = versionedTable.GetDifferences(table, filter, differenceTypes);
                        list.Add(tableName, rows);
                    }
                }
            }

            return(list);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Exports or imports the version edits as XML files.
        /// </summary>
        /// <param name="args">The arguments.</param>
        internal void Run(ProgramArguments args)
        {
            using (EsriRuntimeAuthorization lic = new EsriRuntimeAuthorization(ProductCode.EngineOrDesktop))
            {
                if (lic.Initialize(esriLicenseProductCode.esriLicenseProductCodeStandard))
                {
                    var workspace          = WorkspaceFactories.Open(Path.GetFullPath(args.ConnectionFile));
                    var versionedWorkspace = (IVersionedWorkspace)workspace;

                    switch (args.Task)
                    {
                    case ProgramTask.Import:

                        var version       = versionedWorkspace.DefaultVersion.CreateVersion(args.VersionName);
                        var workspaceName = (IWorkspaceName)((IDataset)version).FullName;

                        string changesFileName = Path.GetFullPath(args.Path);

                        IDeltaDataChangesInit2 ddci = new DeltaDataChangesClass();
                        ddci.Init2(changesFileName, esriExportDataChangesOption.esriExportToXML, false);

                        IImportDataChanges idc = new DataChangesImporterClass();
                        idc.ImportDataChanges(workspaceName, (IDeltaDataChanges)ddci, true, true);

                        break;

                    case ProgramTask.Export:

                        var source = versionedWorkspace.FindVersion(args.VersionName);
                        var target = source.GetParent();

                        IWorkspaceName wsNameSource = (IWorkspaceName)((IDataset)source).FullName;
                        IWorkspaceName wsNameTarget = (IWorkspaceName)((IDataset)target).FullName;

                        var exportFileName = Path.Combine(Path.GetFullPath(args.Path), args.VersionName + ".xml");

                        IVersionDataChangesInit vdci = new VersionDataChangesClass();
                        vdci.Init(wsNameSource, wsNameTarget);

                        IExportDataChanges2 edc = new DataChangesExporterClass();
                        edc.ExportDataChanges(exportFileName, esriExportDataChangesOption.esriExportToXML, (IDataChanges)vdci, true);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Gets the differences between the <paramref name="source" /> and <paramref name="target" /> versions that need to be
        ///     checked-in or exported.
        /// </summary>
        /// <param name="source">The source (or child) version.</param>
        /// <param name="target">The target (or parent) version.</param>
        /// <param name="predicate">
        ///     The predicate that defines a set of criteria and determines whether the specified differences
        ///     will be loaded.
        /// </param>
        /// <param name="dataChangeTypes">The data change types.</param>
        /// <returns>
        ///     Returns a <see cref="Dictionary{String, DeltaRow}" /> representing the differences for the table (or
        ///     key).
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     target
        ///     or
        ///     predicate
        ///     or
        ///     dataChangeTypes
        /// </exception>
        public static Dictionary <string, DeltaRowCollection> GetDataChanges(this IVersion source, IVersion target, Func <IModifiedClassInfo, bool> predicate, params esriDataChangeType[] dataChangeTypes)
        {
            if (source == null)
            {
                return(null);
            }
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }
            if (dataChangeTypes == null)
            {
                throw new ArgumentNullException("dataChangeTypes");
            }

            var list = new Dictionary <string, DeltaRowCollection>(StringComparer.Create(CultureInfo.InvariantCulture, true));

            IVersionDataChangesInit vdci         = new VersionDataChangesClass();
            IWorkspaceName          wsNameSource = (IWorkspaceName)((IDataset)source).FullName;
            IWorkspaceName          wsNameTarget = (IWorkspaceName)((IDataset)target).FullName;

            vdci.Init(wsNameSource, wsNameTarget);

            IDataChanges     dataChanges = (IDataChanges)vdci;
            IDataChangesInfo dci         = (IDataChangesInfo)vdci;

            var tasks = new List <Action>();

            IEnumModifiedClassInfo enumMci = dataChanges.GetModifiedClassesInfo();

            foreach (var mci in enumMci.AsEnumerable())
            {
                // Validate that the table needs to be loaded.
                if (predicate(mci))
                {
                    string tableName = mci.ChildClassName;
                    tasks.Add(() =>
                    {
                        var rows    = new DeltaRowCollection(mci, source, target);
                        var actions = new List <Action>();

                        // Determines if the table represents a feature class.
                        bool isFeatureClass = mci.DatasetType == esriDatasetType.esriDTFeatureClass;

                        // Iterate through all of the data change types.
                        foreach (var dataChangeType in dataChangeTypes)
                        {
                            actions.Add(() =>
                            {
                                // IRow objects returned from a difference cursor are meant to be a read only. Thus, only the OIDs are being loaded and
                                // the rows are hydrated from the struct.
                                IFIDSet set = dci.ChangedIDs[tableName, dataChangeType];
                                set.Reset();

                                int oid;
                                set.Next(out oid);
                                while (oid != -1)
                                {
                                    var row = new DeltaRow(dataChangeType, oid, tableName, isFeatureClass);
                                    rows.Add(row);

                                    set.Next(out oid);
                                }
                            });
                        }

                        if (actions.Any())
                        {
                            Task.WaitAll(actions);
                        }

                        list.Add(tableName, rows);
                    });
                }
            }

            if (tasks.Any())
            {
                Task.WaitAll(tasks);
            }

            return(list);
        }