private ICommand FindBefore(XTablePortable table, ICommand command) { FindBeforeCommand cmd = (FindBeforeCommand)command; KeyValuePair <IData, IData>?keyValue = table.FindBefore(cmd.Key); return(new FindBeforeCommand(cmd.Key, keyValue)); }
private ICommand Backward(XTablePortable table, ICommand command) { BackwardCommand cmd = (BackwardCommand)command; List <KeyValuePair <IData, IData> > list = table.Backward(cmd.FromKey, cmd.FromKey != null, cmd.ToKey, cmd.ToKey != null).Take(cmd.PageCount).ToList(); return(new BackwardCommand(cmd.PageCount, cmd.FromKey, cmd.ToKey, list)); }
private ICommand Replace(XTablePortable table, ICommand command) { ReplaceCommand cmd = (ReplaceCommand)command; table.Replace(cmd.Key, cmd.Record); return(null); }
private ICommand InsertOrIgnore(XTablePortable table, ICommand command) { InsertOrIgnoreCommand cmd = (InsertOrIgnoreCommand)command; table.InsertOrIgnore(cmd.Key, cmd.Record); return(null); }
private ICommand DeleteRange(XTablePortable table, ICommand command) { DeleteRangeCommand cmd = (DeleteRangeCommand)command; table.Delete(cmd.FromKey, cmd.ToKey); return(null); }
private ICommand Delete(XTablePortable table, ICommand command) { DeleteCommand cmd = (DeleteCommand)command; table.Delete(cmd.Key); return(null); }
private ICommand GetXIndexDescriptor(XTablePortable table, ICommand command) { XTableDescriptorGetCommand cmd = (XTableDescriptorGetCommand)command; cmd.Descriptor = table.Descriptor; return(new XTableDescriptorGetCommand(cmd.Descriptor)); }
private ICommand TryGet(XTablePortable table, ICommand command) { TryGetCommand cmd = (TryGetCommand)command; IData record = null; bool exist = table.TryGet(cmd.Key, out record); return(new TryGetCommand(cmd.Key, record)); }
private ICommand SetXIndexDescriptor(XTablePortable table, ICommand command) { XTableDescriptorSetCommand cmd = (XTableDescriptorSetCommand)command; Descriptor descriptor = (Descriptor)cmd.Descriptor; if (descriptor.Tag != null) { table.Descriptor.Tag = descriptor.Tag; } return(new XTableDescriptorSetCommand(descriptor)); }
private ICommand FindBefore(XTablePortable table, ICommand command) { FindBeforeCommand cmd = (FindBeforeCommand)command; KeyValuePair<IData, IData>? keyValue = table.FindBefore(cmd.Key); return new FindBeforeCommand(cmd.Key, keyValue); }
private ICommand TryGet(XTablePortable table, ICommand command) { TryGetCommand cmd = (TryGetCommand)command; IData record = null; bool exist = table.TryGet(cmd.Key, out record); return new TryGetCommand(cmd.Key, record); }
private ICommand Backward(XTablePortable table, ICommand command) { BackwardCommand cmd = (BackwardCommand)command; List<KeyValuePair<IData, IData>> list = table.Backward(cmd.FromKey, cmd.FromKey != null, cmd.ToKey, cmd.ToKey != null).Take(cmd.PageCount).ToList(); return new BackwardCommand(cmd.PageCount, cmd.FromKey, cmd.ToKey, list); }
private ICommand InsertOrIgnore(XTablePortable table, ICommand command) { InsertOrIgnoreCommand cmd = (InsertOrIgnoreCommand)command; table.InsertOrIgnore(cmd.Key, cmd.Record); return null; }
private ICommand Clear(XTablePortable table, ICommand command) { table.Clear(); return null; }
private ICommand Delete(XTablePortable table, ICommand command) { DeleteCommand cmd = (DeleteCommand)command; table.Delete(cmd.Key); return null; }
private ICommand DeleteRange(XTablePortable table, ICommand command) { DeleteRangeCommand cmd = (DeleteRangeCommand)command; table.Delete(cmd.FromKey, cmd.ToKey); return null; }
private ICommand Replace(XTablePortable table, ICommand command) { ReplaceCommand cmd = (ReplaceCommand)command; table.Replace(cmd.Key, cmd.Record); return null; }
private ICommand Clear(XTablePortable table, ICommand command) { table.Clear(); return(null); }
private ICommand SetXIndexDescriptor(XTablePortable table, ICommand command) { XTableDescriptorSetCommand cmd = (XTableDescriptorSetCommand)command; Descriptor descriptor = (Descriptor)cmd.Descriptor; if (descriptor.Tag != null) table.Descriptor.Tag = descriptor.Tag; return new XTableDescriptorSetCommand(descriptor); }
private ICommand LastRow(XTablePortable table, ICommand command) { KeyValuePair<IData, IData> cmd = table.LastRow; return new LastRowCommand(cmd); }
private ICommand LastRow(XTablePortable table, ICommand command) { KeyValuePair <IData, IData> cmd = table.LastRow; return(new LastRowCommand(cmd)); }
private ICommand GetXIndexDescriptor(XTablePortable table, ICommand command) { XTableDescriptorGetCommand cmd = (XTableDescriptorGetCommand)command; cmd.Descriptor = table.Descriptor; return new XTableDescriptorGetCommand(cmd.Descriptor); }
private ICommand Count(XTablePortable table, ICommand command) { long count = table.Count(); return(new CountCommand(count)); }
private ICommand Count(XTablePortable table, ICommand command) { long count = table.Count(); return new CountCommand(count); }
private void PacketExecute(object state) { try { KeyValuePair <ServerConnection, Packet> order = (KeyValuePair <ServerConnection, Packet>)state; BinaryReader reader = new BinaryReader(order.Value.Request); Message msgRequest = Message.Deserialize(reader, (id) => StorageEngine.Find(id)); IDescriptor clientDescription = msgRequest.Description; CommandCollection resultCommands = new CommandCollection(1); try { var commands = msgRequest.Commands; if (msgRequest.Description != null) // XTable commands { XTablePortable table = (XTablePortable)StorageEngine.OpenXTablePortable(clientDescription.Name, clientDescription.KeyDataType, clientDescription.RecordDataType); table.Descriptor.Tag = clientDescription.Tag; for (int i = 0; i < commands.Count - 1; i++) { ICommand command = msgRequest.Commands[i]; CommandsIIndexExecute[command.Code](table, command); } ICommand resultCommand = CommandsIIndexExecute[msgRequest.Commands[commands.Count - 1].Code](table, msgRequest.Commands[commands.Count - 1]); if (resultCommand != null) { resultCommands.Add(resultCommand); } table.Flush(); } else //Storage engine commands { ICommand command = msgRequest.Commands[commands.Count - 1]; var resultCommand = CommandsStorageEngineExecute[command.Code](command); if (resultCommand != null) { resultCommands.Add(resultCommand); } } } catch (Exception e) { resultCommands.Add(new ExceptionCommand(e.Message)); } MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); Descriptor responseClientDescription = new Descriptor(-1, "", StructureType.RESERVED, DataType.Boolean, DataType.Boolean, null, null, DateTime.Now, DateTime.Now, DateTime.Now, null); Message msgResponse = new Message(msgRequest.Description == null ? responseClientDescription : msgRequest.Description, resultCommands); msgResponse.Serialize(writer); ms.Position = 0; order.Value.Response = ms; order.Key.PendingPackets.Add(order.Value); } catch (Exception exc) { TcpServer.LogError(exc); } }