Esempio n. 1
0
        protected void RaiseEvent(FieldCommand fieldCommand, FieldEvent @event)
        {
            SimpleMapper.Map(fieldCommand, @event);

            if (schema.FieldsById.TryGetValue(fieldCommand.FieldId, out var field))
            {
                @event.FieldId = new NamedId <long>(field.Id, field.Name);
            }

            RaiseEvent(@event);
        }
Esempio n. 2
0
        private void RaiseEvent(FieldCommand fieldCommand, FieldEvent @event)
        {
            SimpleMapper.Map(fieldCommand, @event);

            if (Snapshot.SchemaDef.FieldsById.TryGetValue(fieldCommand.FieldId, out var field))
            {
                @event.FieldId = new NamedId <long>(field.Id, field.Name);
            }

            RaiseEvent(@event);
        }
Esempio n. 3
0
        protected void RaiseEvent(FieldCommand fieldCommand, FieldEvent @event)
        {
            SimpleMapper.Map(fieldCommand, @event);

            if (schema.FieldsById.TryGetValue(fieldCommand.FieldId, out var field))
            {
                @event.FieldId = new NamedId <long>(field.Id, field.Name);
            }
            else
            {
                throw new DomainObjectNotFoundException(fieldCommand.FieldId.ToString(), "Fields", typeof(Field));
            }

            RaiseEvent(@event);
        }
Esempio n. 4
0
        private async Task CallbackField(Nuid id, string field_name, FieldEvent field_event, NList args)
        {
            string entity_type = Global.NULL_STRING;
            Entity entity      = EntityManager.Get(id);

            if (entity != null)
            {
                entity_type = entity.Type;
            }
            else
            {
                entity_type = await GetCacheType(id);
            }

            EntityPrefab entity_prefab = Prefabs.GetEntity(entity_type);

            if (entity_prefab == null)
            {
                return;
            }

            if (entity_prefab.ancestors != null && entity_prefab.ancestors.Count > 0)
            {
                for (int i = entity_prefab.ancestors.Count - 1; i >= 0; i--)
                {
                    string parent_type = entity_prefab.ancestors[i];

                    await NModule.CallbackField(this, id, parent_type, field_name, field_event, args);
                }
            }

            await NModule.CallbackField(this, id, entity_type, field_name, field_event, args);

            FieldPrefab field_prefab = entity_prefab.fields[field_name];

            if (field_prefab != null && field_prefab.sync)
            {
                NList msg = NList.New().Add(id).Add(field_name).Add((int)field_event).Append(args);
                await SyncField(id, msg);
            }
        }
Esempio n. 5
0
        private void RaiseEvent(FieldCommand fieldCommand, FieldEvent @event)
        {
            SimpleMapper.Map(fieldCommand, @event);

            if (fieldCommand.ParentFieldId.HasValue)
            {
                if (Snapshot.SchemaDef.FieldsById.TryGetValue(fieldCommand.ParentFieldId.Value, out var field))
                {
                    @event.ParentFieldId = NamedId.Of(field.Id, field.Name);

                    if (field is IArrayField arrayField && arrayField.FieldsById.TryGetValue(fieldCommand.FieldId, out var nestedField))
                    {
                        @event.FieldId = NamedId.Of(nestedField.Id, nestedField.Name);
                    }
                }
            }
            else
            {
                @event.FieldId = GetFieldId(fieldCommand.FieldId);
            }

            RaiseEvent(@event);
        }
Esempio n. 6
0
        public void GetField(Type type, string line)
        {
            var obj = Activator.CreateInstance(type);

            PropertyInfo[] props = type.GetProperties();
            foreach (PropertyInfo prop in props)
            {
                var att =
                    prop.GetCustomAttribute(typeof(StringRangeAttribute)) as StringRangeAttribute;
                if (att == null || (att.StartIndex + att.Length) > line.Length)
                {
                    continue;
                }

                string valueStr = line.Substring(att.StartIndex, att.Length).Trim();
                if (string.IsNullOrEmpty(valueStr))
                {
                    prop.SetValue(type, null);
                    continue;
                }
                if (prop.PropertyType == typeof(decimal) || prop.PropertyType == typeof(float))
                {
                    valueStr = valueStr.Insert(valueStr.Length - 2, ".");
                }

                if (prop.PropertyType.IsEnum)
                {
                    valueStr = GetEnum(prop.PropertyType, valueStr).ToString();
                }

                TypeConverter typeConverter = TypeDescriptor.GetConverter(prop.PropertyType);
                var           value         = typeConverter.ConvertFromString(valueStr);
                prop.SetValue(obj, value);
            }

            FieldEvent?.Invoke(this, new FieldEventArgs(obj));
        }
Esempio n. 7
0
 public static async Task CallbackField(INode node, Nuid id, string entity_type, string field_name, FieldEvent field_event, NList args)
 {
     await _FieldEvents.Callback(new Tuple <string, string, FieldEvent>(entity_type, field_name, field_event), node, id, args);
 }
Esempio n. 8
0
 protected void RCField(string entity_type, string field_name, FieldEvent field_event, NEventCallback handler, int priority = 1)
 {
     _FieldEvents.Register(new Tuple <string, string, FieldEvent>(entity_type, field_name, field_event), handler, priority);
 }