private void PopulateDefaults(Entity e, Command c) { e.SetValue(SyncUtils.CLIENTID, c.ClientId); e.SetValue(SyncUtils.PROCESSED, DateTime.Now); e.SetValue(SyncUtils.NUMBER, order++); e.SetValue(SyncUtils.TRANSACTION, transactionId); }
public void Process(Command c) { }
public ConflictEventArgs(Command client, Command server, SyncConflict conflict) { this.client = client; this.server = server; this.conflict = conflict; }
/// <summary> /// Creates Compound commands if necessary /// </summary> /// <param name="commands"></param> private Command[] OptimizeCommands(SyncEngine engine, IList<Entity> commands) { if (commands == null) throw new ArgumentNullException("commands"); if (commands.Count == 0) return new Command[0]; HashedList<Command> optimizedCommands = new HashedList<Command>(); System.Collections.Generic.List<CompoundCreateCommand> createdCommands = new System.Collections.Generic.List<CompoundCreateCommand>(); int j; for (int i = 0; i < commands.Count; i++) { Entity e = commands[i]; string currentId = e.GetString(SyncUtils.PARENTID); int transaction = e.GetInt32(SyncUtils.TRANSACTION); switch (e.Type) { case SyncUtils.CREATE_ENTITY: string createType = e.GetString(SyncUtils.TYPE); j = i + 1; CompoundCreateCommand ccc = new CompoundCreateCommand(currentId, createType, new List<AttributeCommand>()); CompoundCreateCommand actual = createdCommands.Find(delegate(CompoundCreateCommand toFind) { return toFind.ClientId == ccc.ClientId && toFind.ParentId == ccc.ParentId && toFind.Type == ccc.Type; }); if (actual == null) { createdCommands.Add(ccc); optimizedCommands.Add(ccc); while (j < commands.Count) { string subType = commands[j].GetString(SyncUtils.PARENTTYPE); string subId = commands[j].GetString(SyncUtils.PARENTID); int subTransaction = commands[j].GetInt32(SyncUtils.TRANSACTION); string subCommand = commands[j].Type; if (commands[j].Type == SyncUtils.CREATE_ATTRIBUTE && subId == currentId && subType == createType) { if (subTransaction != transaction) break; ccc.InnerCommands.Add((AttributeCommand)engine.CreateCommand(commands[j])); commands.RemoveAt(j); } else { j++; } } } else { optimizedCommands.Remove(actual); optimizedCommands.Add(ccc); createdCommands.Remove(actual); createdCommands.Add(ccc); } break; case SyncUtils.UPDATE_ATTRIBUTE: string updateType = e.GetString(SyncUtils.PARENTTYPE); j = i + 1; CompoundUpdateCommand cuc = new CompoundUpdateCommand(currentId, updateType, new List<AttributeCommand>()); cuc.InnerCommands.Add((AttributeCommand)engine.CreateCommand(commands[i])); optimizedCommands.Add(cuc); while (j < commands.Count) { string subType = commands[j].GetString(SyncUtils.PARENTTYPE); string subId = commands[j].GetString(SyncUtils.PARENTID); int subTransaction = commands[j].GetInt32(SyncUtils.TRANSACTION); string subCommand = commands[j].Type; if (commands[j].Type == SyncUtils.UPDATE_ATTRIBUTE && subId == currentId && subType == updateType) { if (subTransaction != transaction) break; cuc.InnerCommands.Add((AttributeCommand)engine.CreateCommand(commands[j])); commands.RemoveAt(j); } else { j++; } } break; default: optimizedCommands.Add(engine.CreateCommand(e)); break; } } Command[] result = new Command[optimizedCommands.Count]; for (int i = 0; i < result.Length; i++) result[i] = (Command)optimizedCommands[i]; return result; }