Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 3
0
        private ICommand Replace(XTablePortable table, ICommand command)
        {
            ReplaceCommand cmd = (ReplaceCommand)command;

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

            return(null);
        }
Esempio n. 4
0
        private ICommand InsertOrIgnore(XTablePortable table, ICommand command)
        {
            InsertOrIgnoreCommand cmd = (InsertOrIgnoreCommand)command;

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

            return(null);
        }
Esempio n. 5
0
        private ICommand DeleteRange(XTablePortable table, ICommand command)
        {
            DeleteRangeCommand cmd = (DeleteRangeCommand)command;

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

            return(null);
        }
Esempio n. 6
0
        private ICommand Delete(XTablePortable table, ICommand command)
        {
            DeleteCommand cmd = (DeleteCommand)command;

            table.Delete(cmd.Key);

            return(null);
        }
Esempio n. 7
0
        private ICommand GetXIndexDescriptor(XTablePortable table, ICommand command)
        {
            XTableDescriptorGetCommand cmd = (XTableDescriptorGetCommand)command;

            cmd.Descriptor = table.Descriptor;

            return(new XTableDescriptorGetCommand(cmd.Descriptor));
        }
Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 13
0
        private ICommand InsertOrIgnore(XTablePortable table, ICommand command)
        {
            InsertOrIgnoreCommand cmd = (InsertOrIgnoreCommand)command;
            table.InsertOrIgnore(cmd.Key, cmd.Record);

            return null;
        }
Esempio n. 14
0
        private ICommand Clear(XTablePortable table, ICommand command)
        {
            table.Clear();

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

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

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

            return null;
        }
Esempio n. 18
0
        private ICommand Clear(XTablePortable table, ICommand command)
        {
            table.Clear();

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

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

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

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

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

            return new CountCommand(count);
        }
Esempio n. 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);
            }
        }