Ejemplo n.º 1
0
    public static unsafe AsyncReply EnumParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
    {
        var classId = data.GetGuid(offset);

        offset += 16;
        var index = data[offset++];

        var template = Warehouse.GetTemplateByClassId((Guid)classId, TemplateType.Enum);

        if (template != null)
        {
            return(new AsyncReply(template.Constants[index].Value));
        }
        else
        {
            var reply = new AsyncReply();

            connection.GetTemplate((Guid)classId).Then(tmp =>
            {
                reply.Trigger(tmp.Constants[index].Value);
            }).Error(x => reply.TriggerError(x));

            return(reply);
        }
    }
Ejemplo n.º 2
0
    public static unsafe AsyncReply RecordParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
    {
        var reply = new AsyncReply <IRecord>();

        var classId = data.GetGuid(offset);

        offset += 16;
        length -= 16;


        var template = Warehouse.GetTemplateByClassId((Guid)classId, TemplateType.Record);

        var initRecord = (TypeTemplate template) =>
        {
            ListParser(data, offset, length, connection, requestSequence).Then(r =>
            {
                var ar = (object[])r;

                if (template.DefinedType != null)
                {
                    var record = Activator.CreateInstance(template.DefinedType) as IRecord;
                    for (var i = 0; i < template.Properties.Length; i++)
                    {
                        try
                        {
                            var v = Convert.ChangeType(ar[i], template.Properties[i].PropertyInfo.PropertyType);
                            template.Properties[i].PropertyInfo.SetValue(record, v);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }

                    reply.Trigger(record);
                }
                else
                {
                    var record = new Record();

                    for (var i = 0; i < template.Properties.Length; i++)
                    {
                        record.Add(template.Properties[i].Name, ar[i]);
                    }

                    reply.Trigger(record);
                }
            });
        };

        if (template != null)
        {
            initRecord(template);
        }
        else
        {
            connection.GetTemplate((Guid)classId).Then(tmp =>
            {
                ListParser(data, offset, length, connection, requestSequence).Then(r =>
                {
                    if (tmp == null)
                    {
                        reply.TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.TemplateNotFound,
                                                              "Template not found for record."));
                    }
                    else
                    {
                        initRecord(tmp);
                    }
                });
            }).Error(x => reply.TriggerError(x));
        }

        return(reply);
    }