Exemple #1
0
        static void DoMerge(string[] URIs, string output)
        {
            DataSetUri dstUri = DataSetUri.Create(output);

            if (dstUri.ProviderName.StartsWith("memory"))
            {
                throw new NotSupportedException("Copying to memory is not supported by the utility.");
            }

            DataSet[] dss = new DataSet[URIs.Length];
            int       i   = 0;

            try
            {
                for (i = 0; i < dss.Length; i++)
                {
                    dss[i] = DataSet.Open(URIs[i]);
                }
            }
            catch
            {
                for (; --i >= 0;)
                {
                    dss[i].Dispose();
                }
                throw;
            }

            using (DataSet mds = DataSet.Open("msds:memory"))
            {
                mds.IsAutocommitEnabled = false;
                IMetadataConflictResolver conflictResolver = new WarningConflictResolver();
                foreach (var ds in dss)
                {
                    // Global metadata
                    foreach (var attr in ds.Metadata)
                    {
                        object val;
                        if (mds.Metadata.ContainsKey(attr.Key, SchemaVersion.Recent))
                        {
                            val = conflictResolver.Resolve(attr.Key, mds.Metadata[attr.Key, SchemaVersion.Recent], attr.Value);
                        }
                        else
                        {
                            val = attr.Value;
                        }
                        mds.Metadata[attr.Key] = val;
                    }

                    // Variables
                    foreach (var var in ds.Variables)
                    {
                        mds.AddVariableByReference(var);
                    }
                }
                try
                {
                    mds.Commit();
                }
                catch (DistributedCommitFailedException dex)
                {
                    if (dex.InnerException is ConstraintsFailedException)
                    {
                        string error = String.Format("Input DataSets are incompatible: {0}", ((ConstraintsFailedException)(dex.InnerException)).Message);
                        WriteError(error);
                        return;
                    }
                    throw;
                }
                catch (ConstraintsFailedException cex)
                {
                    string error = String.Format("Input DataSets are incompatible: {0}", cex.Message);
                    WriteError(error);
                    return;
                }
                Microsoft.Research.Science.Data.Utilities.DataSetCloning.Clone(mds, dstUri,
                                                                               Microsoft.Research.Science.Data.Utilities.DataSetCloning.DefaultUpdater).Dispose();
            }
        }
Exemple #2
0
        static void DoMerge(string[] URIs, string output)
        {
            DataSetUri dstUri = DataSetUri.Create(output);
            if (dstUri.ProviderName.StartsWith("memory"))
                throw new NotSupportedException("Copying to memory is not supported by the utility.");

            DataSet[] dss = new DataSet[URIs.Length];
            int i = 0;
            try
            {
                for (i = 0; i < dss.Length; i++)
                    dss[i] = DataSet.Open(URIs[i]);
            }
            catch
            {
                for (; --i >= 0; )
                    dss[i].Dispose();
                throw;
            }

            using (DataSet mds = DataSet.Open("msds:memory"))
            {
                mds.IsAutocommitEnabled = false;
                IMetadataConflictResolver conflictResolver = new WarningConflictResolver();
                foreach (var ds in dss)
                {
                    // Global metadata
                    foreach (var attr in ds.Metadata)
                    {
                        object val;
                        if (mds.Metadata.ContainsKey(attr.Key, SchemaVersion.Recent))
                            val = conflictResolver.Resolve(attr.Key, mds.Metadata[attr.Key, SchemaVersion.Recent], attr.Value);
                        else
                            val = attr.Value;
                        mds.Metadata[attr.Key] = val;
                    }

                    // Variables
                    foreach (var var in ds.Variables)
                        mds.AddVariableByReference(var);
                }
                try
                {
                    mds.Commit();
                }
                catch (DistributedCommitFailedException dex)
                {
                    if (dex.InnerException is ConstraintsFailedException)
                    {
                        string error = String.Format("Input DataSets are incompatible: {0}", ((ConstraintsFailedException)(dex.InnerException)).Message);
                        WriteError(error);
                        return;
                    }
                    throw;
                }
                catch (ConstraintsFailedException cex)
                {
                    string error = String.Format("Input DataSets are incompatible: {0}", cex.Message);
                    WriteError(error);
                    return;
                }
                Microsoft.Research.Science.Data.Utilities.DataSetCloning.Clone(mds, dstUri,
                    Microsoft.Research.Science.Data.Utilities.DataSetCloning.DefaultUpdater).Dispose();
            }
        }