本文整理汇总了C#中DataSet.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.Clone方法的具体用法?C# DataSet.Clone怎么用?C# DataSet.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSet
的用法示例。
在下文中一共展示了DataSet.Clone方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddToCache
private void AddToCache(DataSet ds)
{
string tempPath = Path.GetTempFileName();
long sizeOfDS = 0;
try
{
string targetUri = String.Format("msds:csv?file={0}&openMode=create&appendMetadata=true", tempPath);
ds.Clone(targetUri);
string hash = null;
if (ds.Metadata.ContainsKey(Namings.metadataNameHash))
{
hash = (string)ds.Metadata[Namings.metadataNameHash];
}
else
{
hash = DataSetDiskCache.ComputeHash(ds);
}
string targetPath = Path.Combine(cacheFolder, String.Format("{0}.csv", hash));
if (File.Exists(targetPath))
File.Delete(targetPath);
File.Move(tempPath, targetPath);
tempPath = null;
//File.SetAttributes(targetPath, FileAttributes.ReadOnly);
sizeOfDS = (new FileInfo(targetPath)).Length;
}
catch (Exception ex)
{
Trace.WriteLineIf(Tracer.TraceError, "Failed to save cache. " + ex.ToString());
return;
}
finally
{
if (tempPath != null)
File.Delete(tempPath);
}
ScheduleCacheClearCheck(sizeOfDS);
}
示例2: CloneCopy_TestForeignKeyConstraints
public void CloneCopy_TestForeignKeyConstraints()
{
DataTable dirTable = new DataTable("Directories");
DataColumn dir_UID = new DataColumn("UID", typeof(int));
dir_UID.Unique = true;
dir_UID.AllowDBNull = false;
dirTable.Columns.Add(dir_UID);
// Build a simple Files table
DataTable fileTable = new DataTable("Files");
DataColumn file_DirID = new DataColumn("DirectoryID", typeof(int));
file_DirID.Unique = false;
file_DirID.AllowDBNull = false;
fileTable.Columns.Add(file_DirID);
// Build the DataSet
DataSet ds = new DataSet("TestDataset");
ds.Tables.Add(dirTable);
ds.Tables.Add(fileTable);
// Add a foreign key constraint
DataColumn[] parentColumns = new DataColumn[1];
parentColumns[0] = ds.Tables["Directories"].Columns["UID"];
DataColumn[] childColumns = new DataColumn[1];
childColumns[0] = ds.Tables["Files"].Columns["DirectoryID"];
ForeignKeyConstraint fk = new ForeignKeyConstraint("FK_Test", parentColumns, childColumns);
ds.Tables["Files"].Constraints.Add(fk);
ds.EnforceConstraints = true;
Assert.Equal(1, ds.Tables["Directories"].Constraints.Count);
Assert.Equal(1, ds.Tables["Files"].Constraints.Count);
// check clone works fine
DataSet cloned_ds = ds.Clone();
Assert.Equal(1, cloned_ds.Tables["Directories"].Constraints.Count);
Assert.Equal(1, cloned_ds.Tables["Files"].Constraints.Count);
ForeignKeyConstraint clonedFk = (ForeignKeyConstraint)cloned_ds.Tables["Files"].Constraints[0];
Assert.Equal("FK_Test", clonedFk.ConstraintName);
Assert.Equal(1, clonedFk.Columns.Length);
Assert.Equal("DirectoryID", clonedFk.Columns[0].ColumnName);
UniqueConstraint clonedUc = (UniqueConstraint)cloned_ds.Tables["Directories"].Constraints[0];
UniqueConstraint origUc = (UniqueConstraint)ds.Tables["Directories"].Constraints[0];
Assert.Equal(origUc.ConstraintName, clonedUc.ConstraintName);
Assert.Equal(1, clonedUc.Columns.Length);
Assert.Equal("UID", clonedUc.Columns[0].ColumnName);
// check copy works fine
DataSet copy_ds = ds.Copy();
Assert.Equal(1, copy_ds.Tables["Directories"].Constraints.Count);
Assert.Equal(1, copy_ds.Tables["Files"].Constraints.Count);
ForeignKeyConstraint copyFk = (ForeignKeyConstraint)copy_ds.Tables["Files"].Constraints[0];
Assert.Equal("FK_Test", copyFk.ConstraintName);
Assert.Equal(1, copyFk.Columns.Length);
Assert.Equal("DirectoryID", copyFk.Columns[0].ColumnName);
UniqueConstraint copyUc = (UniqueConstraint)copy_ds.Tables["Directories"].Constraints[0];
origUc = (UniqueConstraint)ds.Tables["Directories"].Constraints[0];
Assert.Equal(origUc.ConstraintName, copyUc.ConstraintName);
Assert.Equal(1, copyUc.Columns.Length);
Assert.Equal("UID", copyUc.Columns[0].ColumnName);
}
示例3: CloneCopy2
public void CloneCopy2()
{
var ds = new DataSet();
ds.ReadXmlSchema(new StringReader(DataProvider.store));
ds.Clone();
}
示例4: CloneCopy
public void CloneCopy()
{
DataTable table = new DataTable("pTable");
DataTable table1 = new DataTable("cTable");
DataSet set = new DataSet();
set.Tables.Add(table);
set.Tables.Add(table1);
DataColumn col = new DataColumn();
col.ColumnName = "Id";
col.DataType = Type.GetType("System.Int32");
table.Columns.Add(col);
UniqueConstraint uc = new UniqueConstraint("UK1", table.Columns[0]);
table.Constraints.Add(uc);
col = new DataColumn();
col.ColumnName = "Name";
col.DataType = Type.GetType("System.String");
table.Columns.Add(col);
col = new DataColumn();
col.ColumnName = "Id";
col.DataType = Type.GetType("System.Int32");
table1.Columns.Add(col);
col = new DataColumn();
col.ColumnName = "Name";
col.DataType = Type.GetType("System.String");
table1.Columns.Add(col);
ForeignKeyConstraint fc = new ForeignKeyConstraint("FK1", table.Columns[0], table1.Columns[0]);
table1.Constraints.Add(fc);
DataRow row = table.NewRow();
row["Id"] = 147;
row["name"] = "Row1";
row.RowError = "Error#1";
table.Rows.Add(row);
// Set column to RO as commonly used by auto-increment fields.
// ds.Copy() has to omit the RO check when cloning DataRows
table.Columns["Id"].ReadOnly = true;
row = table1.NewRow();
row["Id"] = 147;
row["Name"] = "Row1";
table1.Rows.Add(row);
//Setting properties of DataSet
set.CaseSensitive = true;
set.DataSetName = "My DataSet";
set.EnforceConstraints = false;
set.Namespace = "Namespace#1";
set.Prefix = "Prefix:1";
DataRelation dr = new DataRelation("DR", table.Columns[0], table1.Columns[0]);
set.Relations.Add(dr);
set.ExtendedProperties.Add("TimeStamp", DateTime.Now);
CultureInfo cultureInfo = new CultureInfo("ar-SA");
set.Locale = cultureInfo;
//Testing Copy ()
DataSet copySet = set.Copy();
Assert.Equal(set.CaseSensitive, copySet.CaseSensitive);
Assert.Equal(set.DataSetName, copySet.DataSetName);
Assert.Equal(set.EnforceConstraints, copySet.EnforceConstraints);
Assert.Equal(set.HasErrors, copySet.HasErrors);
Assert.Equal(set.Namespace, copySet.Namespace);
Assert.Equal(set.Prefix, copySet.Prefix);
Assert.Equal(set.Relations.Count, copySet.Relations.Count);
Assert.Equal(set.Tables.Count, copySet.Tables.Count);
Assert.Equal(set.ExtendedProperties["TimeStamp"], copySet.ExtendedProperties["TimeStamp"]);
for (int i = 0; i < copySet.Tables.Count; i++)
{
Assert.Equal(set.Tables[i].Rows.Count, copySet.Tables[i].Rows.Count);
Assert.Equal(set.Tables[i].Columns.Count, copySet.Tables[i].Columns.Count);
}
//Testing Clone ()
copySet = set.Clone();
Assert.Equal(set.CaseSensitive, copySet.CaseSensitive);
Assert.Equal(set.DataSetName, copySet.DataSetName);
Assert.Equal(set.EnforceConstraints, copySet.EnforceConstraints);
Assert.False(copySet.HasErrors);
Assert.Equal(set.Namespace, copySet.Namespace);
Assert.Equal(set.Prefix, copySet.Prefix);
Assert.Equal(set.Relations.Count, copySet.Relations.Count);
Assert.Equal(set.Tables.Count, copySet.Tables.Count);
Assert.Equal(set.ExtendedProperties["TimeStamp"], copySet.ExtendedProperties["TimeStamp"]);
for (int i = 0; i < copySet.Tables.Count; i++)
{
Assert.Equal(0, copySet.Tables[i].Rows.Count);
Assert.Equal(set.Tables[i].Columns.Count, copySet.Tables[i].Columns.Count);
}
}
示例5: PublishAverage
/// <summary>
/// Take the last ensemble as the parameter. Fill in
/// the averaged data to the ensemble. Then publish
/// it to all the subscribers.
/// </summary>
/// <param name="ensemble">Last ensemble that was accumulated.</param>
private void PublishAverage(DataSet.Ensemble ensemble)
{
// Clone the ensemble
DataSet.Ensemble avgEnsemble = ensemble.Clone();
// Set the num of samples and the first ping time to the ensemble
SetAveragedEnsembleParameters(ref avgEnsemble);
// Correlation Averaging
if (IsCorrelationAveraging)
{
_correlationAverager.SetAverage(ref avgEnsemble, _options.CorrelationScale);
}
// Amplitude averaging
if (IsAmplitudeAveraging)
{
_amplitudeAverager.SetAverage(ref avgEnsemble, _options.AmplitudeScale);
}
// Beam Velocity Averging
if (IsBeamVelocityAveraging)
{
_beamVelAverager.SetAverage(ref avgEnsemble, _options.BeamVelocityScale);
}
// Instrument Velocity Averging
if (IsInstrumentVelocityAveraging)
{
_instrumentVelAverager.SetAverage(ref avgEnsemble, _options.InstrumentVelocityScale);
}
// Earth Velocity Averging
if (IsEarthVelocityAveraging)
{
_earthVelAverager.SetAverage(ref avgEnsemble, _options.EarthVelocityScale);
}
// Bottom Track Averging
if (IsBottomTrackAveraging)
{
_bottomTrackAverager.SetAverage(ref avgEnsemble, _options.BottomTrackRangeScale, _options.BottomTrackSnrScale,
_options.BottomTrackAmplitudeScale, _options.BottomTrackCorrelationScale,
_options.BottomTrackBeamVelocityScale, _options.BottomTrackInstrumentVelocityScale, _options.BottomTrackEarthVelocityScale);
}
// Reference Layer Averaging
if (IsReferenceLayerAveraging)
{
_refLayerAverager.SetAverage(ref avgEnsemble, 1.0f);
}
// Publish the ensemble to all the subscribers
PublishAveragedEnsemble(avgEnsemble);
// Clear the accumulated data if not a running average
if (!IsSampleRunningAverage)
{
// Clear the accumulated data
ClearAccumulatedData();
}
}
示例6: AddEnsemble
/// <summary>
/// Accumulate ensembles to average. This will pass the ensemble to all the
/// different averagers to accumulate the data. When the NumSamples has been met,
/// an event will be sent with the averaged ensemble.
/// </summary>
/// <param name="ensemble"></param>
public void AddEnsemble(DataSet.Ensemble ensemble)
{
// Clone the ensemble
var cloneEnsemble = ensemble.Clone();
// Correlation averager
if (IsCorrelationAveraging)
{
_correlationAverager.AddEnsemble(cloneEnsemble);
}
// Amplitude averager
if (IsAmplitudeAveraging)
{
_amplitudeAverager.AddEnsemble(cloneEnsemble);
}
// Beam Velocity Averager
if (IsBeamVelocityAveraging)
{
_beamVelAverager.AddEnsemble(cloneEnsemble);
}
// Instrument Velocity Averager
if (IsInstrumentVelocityAveraging)
{
_instrumentVelAverager.AddEnsemble(cloneEnsemble);
}
// Earth Velocity Averager
if (IsEarthVelocityAveraging)
{
_earthVelAverager.AddEnsemble(cloneEnsemble);
}
// Reference layer averaging
if (IsReferenceLayerAveraging)
{
_refLayerAverager.AddEnsemble(cloneEnsemble);
}
// Bottom Track averaging
if (IsBottomTrackAveraging)
{
_bottomTrackAverager.AddEnsemble(cloneEnsemble);
}
// Set the first ping time if it has not been set
if (ensemble.IsAncillaryAvail && _firstPingTime == DEFAULT_FIRST_PING_TIME)
{
_firstPingTime = cloneEnsemble.AncillaryData.FirstPingTime;
}
// Set the previous ensemble
_lastEnsemble = cloneEnsemble;
// Increment the ensemble count
_ensCount++;
// Running average
// This will continously average the incoming data
if(IsAvgRunning)
{
// Publish the averaged data
PublishAverage(cloneEnsemble);
}
// If we have met the number of samples
// Publish the number of samples
else if (IsAvgByNumSamples && _ensCount >= NumSamples)
{
// Publish the averaged data
PublishAverage(cloneEnsemble);
// If we are not doing a running average
// Then clear the ensemble count so we
// can start over counting
if (!IsSampleRunningAverage)
{
ClearCount();
}
else
{
// Set the new first ping time for running average
_firstPingTime = cloneEnsemble.AncillaryData.FirstPingTime;
// Keep the _ensCount the same as the NumSamples so the
// number does not overflow
_ensCount = NumSamples;
// Remove the first ensemble
RemoveFirstEnsemble();
}
}
}
示例7: _adcpCodec_ProcessDataEvent
/// <summary>
/// Receive the ensemble from the codec.
/// Then set the ensemble size in bytes
/// so that the next ensemble can be found quicker.
/// Set the flag that the ensemble was found.
/// Then store the ensemble for playback.
/// </summary>
/// <param name="ensembleRaw">Ensemble binary data.</param>
/// <param name="ensemble">Ensemble object.</param>
private void _adcpCodec_ProcessDataEvent(byte[] ensembleRaw, DataSet.Ensemble ensemble)
{
// Set the length of an ensemble to find the next ensemble
// quicker
BytesPerEnsemble = ensembleRaw.Length;
// Copy the data
var ens = ensemble.Clone();
byte[] raw = new byte[ensembleRaw.Length];
Buffer.BlockCopy(ensembleRaw, 0, raw, 0, ensembleRaw.Length);
// Create the velocity vectors for the ensemble
DataSet.VelocityVectorHelper.CreateVelocityVector(ref ens);
// Store the found ensemble
_ensembleList.Add(new EnsembleData(raw, ens));
// Set total number of ensembles
// Subtract because 0 based
TotalEnsembles = _ensembleList.Count() - 1;
}
示例8: Clone
public void Clone()
{
DataSet ds = new DataSet(), dsTarget = null;
ds.Tables.Add(DataProvider.CreateParentDataTable());
ds.Tables.Add(DataProvider.CreateChildDataTable());
ds.Relations.Add(new DataRelation("myRelation", ds.Tables[0].Columns[0], ds.Tables[1].Columns[0]));
ds.Tables[0].Rows.Add(new object[] { 9, "", "" });
ds.Tables[1].Columns[2].ReadOnly = true;
ds.Tables[0].PrimaryKey = new DataColumn[] { ds.Tables[0].Columns[0], ds.Tables[0].Columns[1] };
//copy schema only, no data
// Clone 1
dsTarget = ds.Clone();
//Assert.Equal(ds.GetXmlSchema(), dsTarget.GetXmlSchema() );
//use my function because GetXmlSchema not implemented in java
Assert.Equal(DataProvider.GetDSSchema(ds), DataProvider.GetDSSchema(dsTarget));
// Clone 2
Assert.Equal(false, dsTarget.GetXml() == ds.GetXml());
}
示例9: CopyClone_RelationWithoutConstraints
public void CopyClone_RelationWithoutConstraints()
{
DataSet ds = new DataSet();
DataTable table1 = ds.Tables.Add("table1");
DataTable table2 = ds.Tables.Add("table2");
DataColumn pcol = table1.Columns.Add("col1", typeof(int));
DataColumn ccol = table2.Columns.Add("col1", typeof(int));
DataRelation rel = ds.Relations.Add("rel1", pcol, ccol, false);
DataSet ds1 = ds.Copy();
DataSet ds2 = ds.Clone();
Assert.Equal(1, ds1.Relations.Count);
Assert.Equal(1, ds2.Relations.Count);
Assert.Equal(0, ds1.Tables[0].Constraints.Count);
Assert.Equal(0, ds1.Tables[1].Constraints.Count);
Assert.Equal(0, ds2.Tables[0].Constraints.Count);
Assert.Equal(0, ds2.Tables[1].Constraints.Count);
}