本文整理汇总了C#中Transaction.PushCommand方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.PushCommand方法的具体用法?C# Transaction.PushCommand怎么用?C# Transaction.PushCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.PushCommand方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SmartUpload
private void SmartUpload(SyncEngine client, IPersistenceEngine server)
{
if (server == null)
throw new ArgumentException("The server engine must be not null");
if (client == null)
throw new ArgumentException("The client engine must be not null and a SyncProvider");
IList<Entity> commands = GetPeerMetadataEngine(client, Peer.Client).Load("from " + SyncUtils.COMMAND + " c orderby c.Processed, c.Number select c", 1, 0);
EntitySet commandsToRemove = ((EntitySet)commands).Clone();
Command[] optimized = OptimizeCommands(client, commands);
Transaction t = new Transaction(client.MetadataEngine.Factory.Model);
foreach (Command c in optimized)
{
c.ClientId = client.ClientId;
CompoundCreateCommand ccc = c as CompoundCreateCommand;
if (ccc != null)
foreach (Command cmd in ccc.InnerCommands)
cmd.ClientId = client.ClientId;
t.PushCommand(c);
}
t.Commit(server, false);
// Deletes the metadata once they are processed
t = new Transaction(client.MetadataEngine.Factory.Model);
t.Delete(commandsToRemove);
t.Commit(client.MetadataEngine, false);
}
示例2: SmartUploadDownload
//.........这里部分代码省略.........
else
{
clientCommands.Remove(ce);
ct.Delete(ce);
}
}
}
}
}
ct.Commit(GetPeerMetadataEngine(client, Peer.Client), false);
st.Commit(GetPeerMetadataEngine(server, Peer.Server), false);
EntitySet clientCommandsToRemove = ((EntitySet)clientCommands).Clone();
EntitySet serverCommandsToRemove = ((EntitySet)serverCommands).Clone();
Command[] optimizedClientCommands = OptimizeCommands(client, clientCommands);
Command[] optimizedServerCommands = OptimizeCommands(server, serverCommands);
StringCollection dataToProcess = new StringCollection();
foreach (string filter in filters)
foreach (Entity e in server.Load(filter))
dataToProcess.Add(string.Concat(e.Type, SEPARATOR, e.Id));
t = new Transaction(client.Factory.Model);
foreach (Command c in optimizedServerCommands)
{
string key = string.Empty;
CompoundCreateCommand ccc = c as CompoundCreateCommand;
if (ccc != null)
key = string.Concat(ccc.Type, SEPARATOR, ccc.ParentId);
CompoundUpdateCommand cuc = c as CompoundUpdateCommand;
if (cuc != null)
key = string.Concat(cuc.ParentType, SEPARATOR, cuc.ParentId);
DeleteEntityCommand dec = c as DeleteEntityCommand;
if (dec != null)
key = string.Concat(dec.Type, SEPARATOR, dec.ParentId);
DeleteAttributeCommand dac = c as DeleteAttributeCommand;
if (dac != null)
key = string.Concat(dac.ParentType, SEPARATOR, dac.ParentId);
CreateReferenceCommand crc = c as CreateReferenceCommand;
if (crc != null)
key = string.Concat(crc.ParentType, SEPARATOR, crc.ParentId);
DeleteReferenceCommand drc = c as DeleteReferenceCommand;
if (drc != null)
key = string.Concat(drc.ParentType, SEPARATOR, drc.ParentId);
if (key != null && key != string.Empty && filters.Count > 0 && !dataToProcess.Contains(key))
continue;
c.IgnoreMetadata = true;
t.PushCommand(c);
}
t.Commit(client, false);
#endregion
#region Upload
if (optimizedClientCommands.Length > 0)
{
t = new Transaction(server.Factory.Model);
t.PushCommand(optimizedClientCommands);
t.Commit(server, false);
}
// Updates the last transaction id for the client
Entity info = GetPeerMetadataEngine(server, Peer.Server).Load(SyncUtils.INFO)[0];
connection[SyncUtils.TRANSACTION].Value = info.GetInt32(SyncUtils.TRANSACTION);
t = new Transaction(GetPeerMetadataEngine(server, Peer.Server).Factory.Model);
t.Serialize(connection);
t.Commit(GetPeerMetadataEngine(server, Peer.Server), false);
// Deletes the metadata once they are processed
if (clientCommands.Count > 0)
{
t = new Transaction(GetPeerMetadataEngine(server, Peer.Client).Factory.Model);
t.Delete(clientCommandsToRemove);
t.Commit(GetPeerMetadataEngine(client, Peer.Client), false);
}
// Deletes all tombstoned server commands
if (tombstone != TimeSpan.MaxValue)
{
serverCommands = GetPeerMetadataEngine(server, Peer.Server).Load("from Evaluant.Uss.Sync.Command c where c.Processed > #" + DateTime.Now.Add(-tombstone) + "# select c");
t = new Transaction(GetPeerMetadataEngine(server, Peer.Server).Factory.Model);
t.Delete(serverCommandsToRemove);
t.Commit(GetPeerMetadataEngine(server, Peer.Server), false);
}
#endregion
}
示例3: SmartDownload
private void SmartDownload(IPersistenceEngine client, SyncEngine server, string clientId)
{
if (client == null)
throw new ArgumentException("The client engine must be not null");
if (server == null)
throw new ArgumentException("The server engine must be not null and a SyncProvider");
Entity connection = GetConnection(clientId, server);
int lastSync = connection.GetInt32(SyncUtils.TRANSACTION);
Command[] commands = OptimizeCommands((SyncEngine)client,
GetPeerMetadataEngine(server, Peer.Server).Load("from Evaluant.Uss.Sync.Command c where (c.ClientId!='" + client + "' || c.ClientId==null) and c.Transaction>" + lastSync.ToString() + " orderby c.Processed, c.Number", 1, 0)
);
StringCollection dataToProcess = new StringCollection();
foreach (string filter in filters)
foreach (Entity e in server.Load(filter))
dataToProcess.Add(string.Concat(e.Type, SEPARATOR, e.Id));
Transaction t = new Transaction(client.Factory.Model);
foreach (Command c in commands)
{
string key = string.Empty;
CompoundCreateCommand ccc = c as CompoundCreateCommand;
if (ccc != null)
key = string.Concat(ccc.Type, SEPARATOR, ccc.ParentId);
CompoundUpdateCommand cuc = c as CompoundUpdateCommand;
if (cuc != null)
key = string.Concat(cuc.ParentType, SEPARATOR, cuc.ParentId);
if (key != null && key != string.Empty && filters.Count > 0 && !dataToProcess.Contains(key))
continue;
c.IgnoreMetadata = true;
t.PushCommand(c);
}
t.Commit(client, false);
Entity info = GetPeerMetadataEngine(server, Peer.Server).Load(SyncUtils.INFO)[0];
connection[SyncUtils.TRANSACTION].Value = info.GetInt32(SyncUtils.TRANSACTION);
IPersistenceEngine peerMetadataEngine = GetPeerMetadataEngine(server, Peer.Server);
t = new Transaction(peerMetadataEngine.Factory.Model);
t.Serialize(connection);
t.Commit(peerMetadataEngine, false);
}