Пример #1
0
        void Receive_RequestField(XConnection connection, GenericPacket request)
        {
            // received by server from client

            // get client
            SyncClient client;

            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request field: Instance request received, but sync client not found");
                return;
            }

            // get thread - client can have multiple ui threads viewing instances
            var threadID = int.Parse(request.Data["ThreadID"]);

            InstanceModel instance;

            if (!client.SelectedInstances.TryGetValue(threadID, out instance))
            {
                Log("Request field: instance not found " + threadID.ToString());
                return;
            }

            // get field
            var fieldID = int.Parse(request.Data["FieldID"]);

            IFieldModel field;

            if (!instance.FieldMap.TryGetValue(fieldID, out field))
            {
                Log("Request field: field not found " + fieldID.ToString());
                return;
            }

            field.ExpandField();

            // create packet with expanded results and send
            var response = new InstancePacket()
            {
                Type     = InstancePacketType.Field,
                ThreadID = threadID,
                FieldID  = fieldID,
                Fields   = field.Nodes
            };

            client.Connection.SendPacket(response);
        }
Пример #2
0
        void Receive_RequestInstanceRefresh(XConnection connection, GenericPacket request)
        {
            // received by server from client

            SyncClient client;

            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request Instance Refresh: Sync client not found");
                return;
            }

            var threadID = int.Parse(request.Data["ThreadID"]);

            InstanceModel instance;

            if (!client.SelectedInstances.TryGetValue(threadID, out instance))
            {
                Log("Request field: instance not found " + threadID.ToString());
                return;
            }

            instance.BeginUpdateTree(true);

            // send columns if updated
            var response = new InstancePacket();

            response.Type     = InstancePacketType.Refresh;
            response.ThreadID = threadID;
            // flag as a refresh?

            if (instance.ColumnsUpdated)
            {
                response.Columns = instance.Columns;
            }

            // iterate fields, send any marked as changed
            response.Fields = instance.FieldMap.Values.Where(f => instance.UpdatedFields.Contains(f.ID)).ToList();

            client.Connection.SendPacket(response);
        }
Пример #3
0
        void Receive_RequestInstance(XConnection connection, GenericPacket request)
        {
            // received by server from client

            SyncClient client;

            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request Instance: Sync client not found");
                return;
            }

            var threadID = int.Parse(request.Data["ThreadID"]);

            var node = XRay.Nodes[int.Parse(request.Data["NodeID"])];

            string filter = null;

            request.Data.TryGetValue("Filter", out filter);

            var model = new InstanceModel(node, filter);

            client.SelectedInstances[threadID] = model;
            Log("Request Instance: Model added for thread " + threadID.ToString());

            model.BeginUpdateTree(false);

            // send back details, columns, and nodes
            var response = new InstancePacket()
            {
                Type     = InstancePacketType.Root,
                ThreadID = threadID,
                Details  = model.DetailsLabel,
                Columns  = model.Columns,
                Fields   = model.RootNodes
            };

            client.Connection.SendPacket(response);
        }
Пример #4
0
        public static InstancePacket Decode(G2Header root)
        {
            var instance = new InstancePacket();

            instance.Fields = new List<IFieldModel>(); // needs to be initd

            foreach (var child in G2Protocol.EnumerateChildren(root))
                switch (child.Name)
                {
                    case Packet_Type:
                        instance.Type = (InstancePacketType) BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_ThreadID:
                        instance.ThreadID = BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_FieldID:
                        instance.FieldID = BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_Details:
                        instance.Details = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Column:
                        if (instance.Columns == null)
                            instance.Columns = new List<string>();

                        instance.Columns.Add(UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize));
                        break;

                    case Packet_Field:
                        if(instance.Fields == null)
                            instance.Fields = new List<IFieldModel>();

                        var field = new RemoteFieldModel();

                        foreach (var sub in G2Protocol.EnumerateChildren(child))
                            switch (sub.Name)
                            {
                                case Packet_SubNodesFlag:
                                    field.PossibleSubNodes = BitConverter.ToBoolean(sub.Data, sub.PayloadPos);
                                    break;

                                case Packet_FieldID:
                                    field.ID = BitConverter.ToInt32(sub.Data, sub.PayloadPos);
                                    break;

                                case Packet_Cell:
                                    if(field.Cells == null)
                                        field.Cells = new List<string>();

                                    field.Cells.Add(UTF8Encoding.UTF8.GetString(sub.Data, sub.PayloadPos, sub.PayloadSize));
                                    break;
                            }

                        instance.Fields.Add(field);

                        break;
                }

            return instance;
        }
Пример #5
0
        public static InstancePacket Decode(G2Header root)
        {
            var instance = new InstancePacket();

            instance.Fields = new List <IFieldModel>(); // needs to be initd

            foreach (var child in G2Protocol.EnumerateChildren(root))
            {
                switch (child.Name)
                {
                case Packet_Type:
                    instance.Type = (InstancePacketType)BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_ThreadID:
                    instance.ThreadID = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_FieldID:
                    instance.FieldID = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_Details:
                    instance.Details = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Column:
                    if (instance.Columns == null)
                    {
                        instance.Columns = new List <string>();
                    }

                    instance.Columns.Add(UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize));
                    break;

                case Packet_Field:
                    if (instance.Fields == null)
                    {
                        instance.Fields = new List <IFieldModel>();
                    }

                    var field = new RemoteFieldModel();

                    foreach (var sub in G2Protocol.EnumerateChildren(child))
                    {
                        switch (sub.Name)
                        {
                        case Packet_SubNodesFlag:
                            field.PossibleSubNodes = BitConverter.ToBoolean(sub.Data, sub.PayloadPos);
                            break;

                        case Packet_FieldID:
                            field.ID = BitConverter.ToInt32(sub.Data, sub.PayloadPos);
                            break;

                        case Packet_Cell:
                            if (field.Cells == null)
                            {
                                field.Cells = new List <string>();
                            }

                            field.Cells.Add(UTF8Encoding.UTF8.GetString(sub.Data, sub.PayloadPos, sub.PayloadSize));
                            break;
                        }
                    }

                    instance.Fields.Add(field);

                    break;
                }
            }

            return(instance);
        }
Пример #6
0
        private void Receive_Instance(XConnection connection, G2ReceivedPacket rawPacket)
        {
            // received by client from server

            var packet = InstancePacket.Decode(rawPacket.Root);

            XUI ui;

            if (!XRay.UIs.TryGetValue(packet.ThreadID, out ui))
            {
                Log("Receive Instance: UI not found for instance result");
                return;
            }

            if (ui.CurrentInstance == null)
            {
                Log("Receive Instance: Field not set");
                return;
            }

            bool        updateTree   = false;
            bool        updateFields = false;
            IFieldModel expandField  = null;

            var instance = ui.CurrentInstance;

            if (packet.Details != null)
            {
                instance.DetailsLabel = packet.Details;
            }

            if (packet.Columns != null)
            {
                instance.Columns = packet.Columns;
                updateTree       = true;
            }

            if (packet.Type == InstancePacketType.Root)
            {
                instance.RootNodes = packet.Fields;
                updateTree         = true;
                updateFields       = true;
            }
            else if (packet.Type == InstancePacketType.Field)
            {
                IFieldModel field;
                if (instance.FieldMap.TryGetValue(packet.FieldID, out field))
                {
                    field.Nodes = packet.Fields;
                }

                updateFields = true;
                expandField  = field;
            }
            else if (packet.Type == InstancePacketType.Refresh)
            {
                foreach (var field in packet.Fields)
                {
                    if (instance.FieldMap.ContainsKey(field.ID))
                    {
                        instance.FieldMap[field.ID].Cells = field.Cells;
                    }
                }

                updateTree = true; // cause recursive update of cells
                // dont update fields because already added, and would orphen fields associated with nodes
            }

            if (updateFields)
            {
                foreach (var field in packet.Fields)
                {
                    instance.FieldMap[field.ID] = field;
                }
            }

            // if we're geting fresh info, or refresh info with new columns
            if (updateTree && instance.UpdatedTree != null)
            {
                ui.Window.BeginInvoke(new Action(() => instance.UpdatedTree()));
            }

            if (expandField != null && instance.ExpandedField != null)
            {
                ui.Window.BeginInvoke(new Action(() => instance.ExpandedField(expandField)));
            }
        }
Пример #7
0
        void Receive_RequestInstanceRefresh(XConnection connection, GenericPacket request)
        {
            // received by server from client

            SyncClient client;
            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request Instance Refresh: Sync client not found");
                return;
            }

            var threadID = int.Parse(request.Data["ThreadID"]);

            InstanceModel instance;
            if (!client.SelectedInstances.TryGetValue(threadID, out instance))
            {
                Log("Request field: instance not found " + threadID.ToString());
                return;
            }

            instance.BeginUpdateTree(true);

            // send columns if updated
            var response = new InstancePacket();
            response.Type = InstancePacketType.Refresh;
            response.ThreadID = threadID;
            // flag as a refresh?

            if (instance.ColumnsUpdated)
                response.Columns = instance.Columns;

            // iterate fields, send any marked as changed
            response.Fields = instance.FieldMap.Values.Where(f => instance.UpdatedFields.Contains(f.ID)).ToList();

            client.Connection.SendPacket(response);
        }
Пример #8
0
        void Receive_RequestInstance(XConnection connection, GenericPacket request)
        {
            // received by server from client

            SyncClient client;
            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request Instance: Sync client not found");
                return;
            }

            var threadID = int.Parse(request.Data["ThreadID"]);

            var node = XRay.Nodes[int.Parse(request.Data["NodeID"])];

            string filter = null;
            request.Data.TryGetValue("Filter", out filter);

            var model = new InstanceModel(node, filter);
            client.SelectedInstances[threadID] = model;
            Log("Request Instance: Model added for thread " + threadID.ToString());

            model.BeginUpdateTree(false);

            // send back details, columns, and nodes
            var response = new InstancePacket()
            {
                Type = InstancePacketType.Root,
                ThreadID = threadID,
                Details = model.DetailsLabel,
                Columns = model.Columns,
                Fields = model.RootNodes
            };

            client.Connection.SendPacket(response);
        }
Пример #9
0
        void Receive_RequestField(XConnection connection, GenericPacket request)
        {
            // received by server from client

            // get client
            SyncClient client;
            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request field: Instance request received, but sync client not found");
                return;
            }

            // get thread - client can have multiple ui threads viewing instances
            var threadID = int.Parse(request.Data["ThreadID"]);

            InstanceModel instance;
            if (!client.SelectedInstances.TryGetValue(threadID, out instance))
            {
                Log("Request field: instance not found " + threadID.ToString());
                return;
            }

            // get field
            var fieldID = int.Parse(request.Data["FieldID"]);

            IFieldModel field;
            if (!instance.FieldMap.TryGetValue(fieldID, out field))
            {
                Log("Request field: field not found " + fieldID.ToString());
                return;
            }

            field.ExpandField();

            // create packet with expanded results and send
            var response = new InstancePacket()
            {
                Type = InstancePacketType.Field,
                ThreadID = threadID,
                FieldID = fieldID,
                Fields = field.Nodes
            };

            client.Connection.SendPacket(response);
        }