示例#1
0
        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));
        }
示例#2
0
        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));
        }
示例#3
0
        private ICommand Replace(XTablePortable table, ICommand command)
        {
            ReplaceCommand cmd = (ReplaceCommand)command;

            table.Replace(cmd.Key, cmd.Record);

            return(null);
        }
示例#4
0
        private ICommand InsertOrIgnore(XTablePortable table, ICommand command)
        {
            InsertOrIgnoreCommand cmd = (InsertOrIgnoreCommand)command;

            table.InsertOrIgnore(cmd.Key, cmd.Record);

            return(null);
        }
示例#5
0
        private ICommand DeleteRange(XTablePortable table, ICommand command)
        {
            DeleteRangeCommand cmd = (DeleteRangeCommand)command;

            table.Delete(cmd.FromKey, cmd.ToKey);

            return(null);
        }
示例#6
0
        private ICommand Delete(XTablePortable table, ICommand command)
        {
            DeleteCommand cmd = (DeleteCommand)command;

            table.Delete(cmd.Key);

            return(null);
        }
示例#7
0
        private ICommand GetXIndexDescriptor(XTablePortable table, ICommand command)
        {
            XTableDescriptorGetCommand cmd = (XTableDescriptorGetCommand)command;

            cmd.Descriptor = table.Descriptor;

            return(new XTableDescriptorGetCommand(cmd.Descriptor));
        }
示例#8
0
        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));
        }
示例#9
0
        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));
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
        private ICommand InsertOrIgnore(XTablePortable table, ICommand command)
        {
            InsertOrIgnoreCommand cmd = (InsertOrIgnoreCommand)command;
            table.InsertOrIgnore(cmd.Key, cmd.Record);

            return null;
        }
示例#14
0
        private ICommand Clear(XTablePortable table, ICommand command)
        {
            table.Clear();

            return null;
        }
示例#15
0
        private ICommand Delete(XTablePortable table, ICommand command)
        {
            DeleteCommand cmd = (DeleteCommand)command;
            table.Delete(cmd.Key);

            return null;
        }
示例#16
0
        private ICommand DeleteRange(XTablePortable table, ICommand command)
        {
            DeleteRangeCommand cmd = (DeleteRangeCommand)command;
            table.Delete(cmd.FromKey, cmd.ToKey);

            return null;
        }
示例#17
0
        private ICommand Replace(XTablePortable table, ICommand command)
        {
            ReplaceCommand cmd = (ReplaceCommand)command;
            table.Replace(cmd.Key, cmd.Record);

            return null;
        }
示例#18
0
        private ICommand Clear(XTablePortable table, ICommand command)
        {
            table.Clear();

            return(null);
        }
示例#19
0
        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);
        }
示例#20
0
        private ICommand LastRow(XTablePortable table, ICommand command)
        {
            KeyValuePair<IData, IData> cmd = table.LastRow;

            return new LastRowCommand(cmd);
        }
示例#21
0
        private ICommand LastRow(XTablePortable table, ICommand command)
        {
            KeyValuePair <IData, IData> cmd = table.LastRow;

            return(new LastRowCommand(cmd));
        }
示例#22
0
        private ICommand GetXIndexDescriptor(XTablePortable table, ICommand command)
        {
            XTableDescriptorGetCommand cmd = (XTableDescriptorGetCommand)command;
            cmd.Descriptor = table.Descriptor;

            return new XTableDescriptorGetCommand(cmd.Descriptor);
        }
示例#23
0
        private ICommand Count(XTablePortable table, ICommand command)
        {
            long count = table.Count();

            return(new CountCommand(count));
        }
示例#24
0
        private ICommand Count(XTablePortable table, ICommand command)
        {
            long count = table.Count();

            return new CountCommand(count);
        }
示例#25
0
        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);
            }
        }