本文整理汇总了C#中Transaction.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.Serialize方法的具体用法?C# Transaction.Serialize怎么用?C# Transaction.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.Serialize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldCRUD
public void ShouldCRUD()
{
IPersistenceProvider provider = new SqlMapper.SqlMapperProvider();
((SqlMapper.SqlMapperProvider)provider).ConnectionString = "Data Source=.;Initial Catalog=uss2;Integrated Security=true";
((SqlMapper.SqlMapperProvider)provider).UseDefaultMapping = true;
provider.RegisterMetaData(MetaData.MetaDataFactory.FromAssembly(GetType().Assembly, "Evaluant.Uss.Tests.Model"));
provider.InitializeConfiguration();
IPersistenceEngine engine = provider.CreatePersistenceEngine();
engine.InitializeRepository();
Transaction t = new Transaction(provider.Model);
Entity a = new Entity(typeof(Address).FullName);
//a.Model = provider.Model.Entities[typeof(Evaluant.Uss.Tests.Model.Address).FullName];
a.Add("City", "Mulhouse");
t.Serialize(a);
t.Commit(engine);
IList<Domain.Entity> entities = engine.Load("from Evaluant.Uss.Tests.Model.Address a in context select a");
if (entities.Count > 0)
{
Assert.AreEqual("Evaluant.Uss.Tests.Model.Address", entities[0].Type);
Assert.AreEqual("Mulhouse", entities[0].GetString("City"));
}
}
示例2: BeginInitializeInfo
private void BeginInitializeInfo(AsyncCallback callback, IPersistenceEngineAsync engine)
{
Entity e = new Entity(SyncUtils.INFO);
e.SetValue(SyncUtils.TRANSACTION, 0);
e.SetValue(SyncUtils.CLIENTID, String.Empty);
Transaction t = new Transaction(engine.FactoryAsync.Model);
t.Serialize(e);
t.BeginCommit(callback, engine, false, t);
}
示例3: InitializeInfo
/// <summary>
/// Initializes information about the last transaction number
/// </summary>
/// <param name="engine"></param>
private void InitializeInfo(IPersistenceEngine engine)
{
Entity e = new Entity(SyncUtils.INFO);
e.SetValue(SyncUtils.TRANSACTION, 0);
e.SetValue(SyncUtils.CLIENTID, String.Empty);
Transaction t = new Transaction(engine.Factory.Model);
t.Serialize(e);
t.Commit(engine, false);
}
示例4: GenerateTransactionId
/// <summary>
/// Generates a TimeStamp like number representing an ordered transaction number
/// </summary>
/// <param name="metadataengine"></param>
private void GenerateTransactionId(IPersistenceEngine engine)
{
Entity info;
string guid;
IList<Entity> es = engine.Load(SyncUtils.INFO);
if (es.Count == 0)
{
InitializeInfo(engine);
es = engine.Load(SyncUtils.INFO);
}
info = es[0];
guid = Guid.NewGuid().ToString();
do
{
lastTransactionId = info.GetInt32(SyncUtils.TRANSACTION);
info.SetValue(SyncUtils.TRANSACTION, ++lastTransactionId);
info.SetValue(SyncUtils.CLIENTID, guid);
Transaction t = new Transaction(engine.Factory.Model);
t.Serialize(info);
t.Commit(engine, false);
es = engine.Load(SyncUtils.INFO);
if (es.Count == 0)
{
InitializeInfo(engine);
es = engine.Load(SyncUtils.INFO);
}
info = es[0];
} while (info.GetInt32(SyncUtils.TRANSACTION) != lastTransactionId || info.GetString(SyncUtils.CLIENTID) != guid);
}
示例5: FullDownload
private void FullDownload(IPersistenceEngine client, IPersistenceEngine server, bool bulk)
{
if (client is SyncEngine)
{
((SyncEngine)client).IgnoreClientMetadata = true;
}
// Contains id translation table
Hashtable translationTable = new Hashtable();
Hashtable reverseTable = new Hashtable();
Transaction t = new Transaction(client.Factory.Model);
StringCollection queries = new StringCollection();
// Creates the list of items to load depending whether filters are set or not
if (filters.Count > 0)
{
queries = filters;
}
else
{
foreach (Model.Entity entity in server.Factory.Model.Entities.Values)
{
// Process only root types as it will load all children
if (entity.Inherit != String.Empty && entity.Inherit != null && server.Factory.Model.Entities.ContainsKey(entity.Inherit))
continue;
queries.Add("from " + entity.Type + " e select e");
}
}
if (Progressed != null)
{
// Returns opaths.Count * 2 so that half the processed is reached once entities are processed
Progressed(this, new ProgressEventArgs(0, "Synchronization started", queries.Count * 2));
}
int position = 0;
// Import all entities
foreach (string filter in queries)
{
if (Progressed != null)
{
// Returns opaths.Count * 2 so that half the processed is reached once entities are processed
ProgressEventArgs args = new ProgressEventArgs(position++, "Processing " + filter, queries.Count * 2);
Progressed(this, args);
if (args.Cancel)
{
return;
}
}
int count = Convert.ToInt32(server.LoadScalar(String.Concat("(", filter, ").Count()")));
// System.Diagnostics.Trace.WriteLine("Processing " + opaths + "(" + count.ToString() + ")");
// Loads a set of entities (span)
if (count > 0)
{
t = new Transaction(client.Factory.Model);
IList<Entity> entities = server.Load(filter);
foreach (Entity e in entities)
{
e.State = State.New;
t.Serialize(e);
}
t.Commit(client, false);
// Retrieves the translated ids
foreach (KeyValuePair<string, string> de in t.NewIds)
{
translationTable.Add(String.Concat(entities[0].Type, ".", de.Key), de.Value);
reverseTable.Add(String.Concat(entities[0].Type, ".", de.Value), de.Key);
}
}
}
if (bulk)
{
t = new Transaction(client.Factory.Model);
}
position = 0;
// Import all relationships
foreach (Model.Entity entity in client.Factory.Model.Entities.Values)
{
if (Progressed != null)
{
ProgressEventArgs args = new ProgressEventArgs(queries.Count + position++, "Processing " + entity.Type + " relationships", queries.Count + client.Factory.Model.Entities.Count);
Progressed(this, args);
if (args.Cancel)
{
//.........这里部分代码省略.........
示例6: 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
}
示例7: 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);
}