示例#1
0
        private bool MatchFields(WSRequest request, MetaFunctions cFunc, WSEntitySchema eSchema)
        {
            bool match = true;

            try
            {
            }
            catch (Exception) { }
            return(match);
        }
示例#2
0
        private bool MatchFilters(WSRequest request, MetaFunctions cFunc, WSEntitySchema eSchema)
        {
            bool match = true;

            try
            {
                //eSchema.Filters.Match(this);
            }
            catch (Exception) { }
            return(match);
        }
示例#3
0
        internal override WSMemberSchema Clone(WSTableSource src)
        {
            WSEntitySchema _Schema = new WSEntitySchema(Func)
            {
                Source       = src,
                Name         = src.NAME.ToLower(),
                CombineMode  = CombineMode,
                Filters      = Filters,
                Fields       = Fields.Clone(src),
                OriginalJson = OriginalJson,
                Failed       = Failed,
                Func         = Func
            };

            return(_Schema);
        }
示例#4
0
        public override bool Match(WSRequest Request, WSDataContext DBContext, MetaFunctions CFunc, WSSchema schema)
        {
            bool ok = false;

            try
            {
                WSEntitySchema eSchema = null;
                if (schema is WSEntitySchema)
                {
                    eSchema = (WSEntitySchema)schema;
                }
                else if (schema is WSEntityListSchema)
                {
                    eSchema = ((WSEntityListSchema)schema).EntitySchema;
                }

                if (eSchema != null)
                {
                    bool baseFilterMatch = true;
                    if (eSchema.Source.BaseFilter != null && eSchema.Source.BaseFilter.IsValid && eSchema.Source.BaseFilter.apply(Request, CFunc))
                    {
                        baseFilterMatch = eSchema.Source.BaseFilter.MatchEntity(CFunc, this, ((WSTableSource)CFunc.GetSourceByType(GetType())));
                    }

                    bool dynamicFilterMatch = true;
                    if (eSchema.Fields != null || eSchema.Fields != null)
                    {
                        dynamicFilterMatch = MatchFields(Request, CFunc, eSchema) && MatchFilters(Request, CFunc, eSchema);
                    }

                    ok = baseFilterMatch && dynamicFilterMatch;
                }
            }
            catch (Exception e) {
                if (Request != null)
                {
                    CFunc.RegError(GetType(), e, ref Request.status, $"Match():434");
                }
                else
                {
                    WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status, $"Match():435");
                }
            }
            return(ok);
        }
示例#5
0
 public WSMemberSchema(MetaFunctions _Func, WSEntitySchema _Parent) : base(_Func, _Parent)
 {
 }
示例#6
0
 public WSSchema(MetaFunctions _Func, WSEntitySchema _Parent) { Func = _Func; Parent = _Parent; }
示例#7
0
 public WSFieldSchema(MetaFunctions _Func, WSTableParam _param, WSJProperty _Json, WSEntitySchema _Parent) : base(_Func, _Parent)
 {
     param = _param;
     if (_Json != null)
     {
         Name = _Json.Key;
         IOBaseOptions.Save(_Json.Value);
     }
 }
示例#8
0
        public WSStatus WriteJson(JsonWriter writer, JsonSerializer serializer, WSSchema schema, WSParamList outFields, List <Type> printedTypes, WSRequest Request, MetaFunctions CFunc, WSDataContext DBContext)
        {
            WSStatus status = WSStatus.NONE_Copy();

            WSEntitySchema eSchema = null;
            WSSource       xSource = CFunc.GetSourceByType(GetType());

            if (schema != null && schema is WSEntityBaseSchema)
            {
                if (schema is WSEntitySchema)
                {
                    eSchema = (WSEntitySchema)schema;
                }
                else if (schema is WSEntityListSchema)
                {
                    eSchema = ((WSEntityListSchema)schema).EntitySchema;
                }
            }

            if (eSchema == null && this is WSDynamicEntity)
            {
                if (xSource != null && xSource is WSTableSource && ((WSTableSource)xSource).BaseSchema != null)
                {
                    eSchema = ((WSTableSource)xSource).BaseSchema;
                }
            }

            #region Read if in 'COLLAPSED' mode
            bool collapsedMode = false;
            if (eSchema != null)
            {
                IEnumerable <WSJObject>  _JOptions = eSchema.IOBaseOptions.Value.OfType <WSJObject>();
                Func <WSJProperty, bool> func      = v => WSConstants.ALIACES.OPTION_COLLECT.Match(v.Key);
                WSJObject takeJOption = _JOptions.FirstOrDefault(x => x.Value.Any(func));
                if (takeJOption != null && takeJOption.IsValid)
                {
                    collapsedMode = true;
                    status.childs.Add(WriteCollapsedValues(writer, serializer, this, xSource, takeJOption.Value.FirstOrDefault(func).Value, Request, CFunc));
                }
            }
            #endregion

            if (!collapsedMode)
            {
                writer.WriteStartObject();
                if (this is WSStaticEntity || (eSchema != null && eSchema.Fields.Any()))
                {
                    List <Type> postPrintedTypes = printedTypes.Select(x => x).ToList();
                    if (!postPrintedTypes.Any(x => x == GetType()))
                    {
                        postPrintedTypes.Add(GetType());
                    }
                    status.childs.Add(
                        WriteJMembers(
                            GetType().GetMembers(BindingFlags.Public | BindingFlags.Instance).Where(m => m is PropertyInfo || m is FieldInfo),
                            writer,
                            serializer,
                            eSchema,
                            xSource,
                            outFields,
                            printedTypes,
                            Request,
                            CFunc,
                            DBContext
                            )
                        );
                }
                writer.WriteEndObject();
            }
            return(status);
        }
示例#9
0
        private WSStatus WriteJMembers(IEnumerable <MemberInfo> members, JsonWriter writer, JsonSerializer serializer, WSEntitySchema eSchema, WSSource xSource, WSParamList outFields, List <Type> printedTypes, WSRequest Request, MetaFunctions CFunc, WSDataContext DBContext)
        {
            WSStatus status = WSStatus.NONE_Copy();

            try
            {
                Type    eType = GetType();
                object  obj   = null;
                WSParam param = null;
                if (this is WSDynamicEntity)
                {
                    foreach (WSSchema fieldSchema in eSchema.Fields /*.Items*/)
                    {
                        if (fieldSchema is WSFieldSchema)
                        {
                            param = ((WSFieldSchema)fieldSchema).param;
                        }
                        else if (fieldSchema is WSEntityBaseSchema)
                        {
                            param = GetParam(xSource, fieldSchema.Name);
                        }
                        //else if (childSchema is WSEntitySchema) { param = GetParam(childSchema.Name); }
                        //else if (childSchema is WSEntityListSchema) { param = GetParam(((WSEntityListSchema)childSchema).EntitySchema.Name); }

                        MemberInfo member = param == null ? null : members.FirstOrDefault(p => param.Match(p.Name, null, null, false));
                        obj = member == null ? null : member is PropertyInfo ? ((PropertyInfo)member).GetValue(this, null) : member is FieldInfo ? ((FieldInfo)member).GetValue(this) : null;

                        if (param != null)
                        {
                            status.childs.Add(WriteJProperty(obj, param, writer, serializer, fieldSchema, xSource, outFields, printedTypes, Request, CFunc, DBContext));
                        }
                    }
                }
                else if (this is WSStaticEntity)
                {
                    foreach (MemberInfo member in members)
                    {
                        param = GetParam(xSource, member.Name, member.ReflectedType);
                        obj   = member is PropertyInfo ? ((PropertyInfo)member).GetValue(this, null) : member is FieldInfo ? ((FieldInfo)member).GetValue(this) : null;

                        if (param != null)
                        {
                            status.childs.Add(WriteJProperty(obj, param, writer, serializer, null, xSource, outFields, printedTypes, Request, CFunc, DBContext));
                        }
                    }
                }

                status.AddNote("done", WSConstants.ACCESS_LEVEL.READ);
            }
            catch (Exception e)
            {
                status.CODE = WSStatus.ERROR.CODE;
                status.AddNote("Error(line" + e.LineNumber() + "- " + e.Message + ")");
                CFunc.RegError(GetType(), e, ref status);
            }
            return(status);
        }
示例#10
0
 public WSEntityFieldSchema(MetaFunctions _Func, WSTableParam _Param, WSJProperty _Json, WSEntitySchema _Parent) : base(_Func, _Param, _Json, _Parent)
 {
 }
示例#11
0
 public WSEntityListSchema(WSTableParam _Param, WSJProperty _Json, MetaFunctions _Func, WSEntitySchema _Parent) : base(_Func, _Parent)
 {
     Param = _Param;
     if (_Json != null && !_Json.IsEmpty)
     {
         if (WSEntityFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(_Json.Key)))
         {
             IOBaseOptions.Save(new WSJObject(new List <WSJProperty>()
             {
                 _Json
             }));
         }
         else if (_Json.Value != null)
         {
             if (_Json.Value is WSJArray)
             {
                 WSJArray arr  = (WSJArray)_Json.Value;
                 WSJArray temp = new WSJArray();
                 foreach (WSJson item in arr.Value)
                 {
                     if (item is WSJValue && WSEntityFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(((WSJValue)item).Value)))
                     {
                         IOBaseOptions.Save(item);
                     }
                     else
                     {
                         temp.Value.Add(item);
                     }
                 }
                 _Json.Value = temp;
             }
             else if (_Json.Value is WSJObject)
             {
                 WSJObject          obj       = (WSJObject)_Json.Value;
                 List <WSJProperty> tempItems = new List <WSJProperty>();
                 WSJObject          temp      = new WSJObject(tempItems);
                 WSJObject          baseLocal = new WSJObject(tempItems);
                 foreach (WSJProperty item in obj.Value)
                 {
                     if (WSEntityFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(item.Key)))
                     {
                         baseLocal.Value.Add(item);
                     }
                     else if (item.Value is WSJValue && WSEntityFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(((WSJValue)item.Value).Value)))
                     {
                         baseLocal.Value.Add(item);
                     }
                     else if (item.Value is WSJArray && !item.Value.IsEmpty && !((WSJArray)item.Value).Value.Any(v => !(v is WSJValue) || !WSEntityFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(((WSJValue)v).Value))))
                     {
                         baseLocal.Value.Add(item);
                     }
                     else if (item.Value is WSJObject && !item.Value.IsEmpty && !((WSJObject)item.Value).Value.Any(p => !(p.Value is WSJValue) || !WSEntityFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(((WSJValue)p.Value).Value))))
                     {
                         baseLocal.Value.Add(item);
                     }
                     else
                     {
                         temp.Value.Add(item);
                     }
                 }
                 _Json.Value = temp;
                 if (!baseLocal.IsEmpty)
                 {
                     IOBaseOptions.Save(baseLocal);
                 }
             }
         }
     }
     if (Param != null)
     {
         EntitySchema = new WSEntitySchema((WSTableSource)Func.GetSourceByType(Param.DataType.GetEntityType()), _Json, Func, Parent);
         if (EntitySchema != null)
         {
             Name = EntitySchema.Name;
         }
     }
 }
示例#12
0
 public WSEntitySchema(WSTableSource _Source, WSJProperty _Json, MetaFunctions _Func, WSEntitySchema _Parent = null, bool _IsValidSchema = true) : base(_Func, _Parent)
 {
     try
     {
         IsValidSchema = _IsValidSchema;
         Source        = _Source;
         setUp(_Json);
     }
     catch (Exception e) { Failed = true; WSStatus status = WSStatus.NONE.clone(); Func.RegError(GetType(), e, ref status); }
 }
示例#13
0
        public override void proceedCall()
        {
            try
            {
                WSSystemEntity entity = new WSSystemEntity()
                {
                };
                WSSystemRecord rec = new WSSystemRecord(meta.ClientFunctions, entity, meta.Request.Security.AuthToken.User.role);

                if (WSConstants.ALIACES.ACTION_READ.Match(meta.Request.ACTION))
                {
                    entity.status = WSServerMeta.LoadStatusStatic;
                }
                else if (WSConstants.ALIACES.ACTION_WRITE.Match(meta.Request.ACTION))
                {
                    WSEntitySchema USchema = meta.Request.SOURCE != null && meta.Request.SOURCE is WSTableSource? ((WSTableSource)meta.Request.SOURCE).DynamicSchema : null;

                    if (USchema != null && USchema is WSEntitySchema)
                    {
                        WSEntitySchema schema = USchema;
                    }
                }
                else if (WSConstants.ALIACES.ACTION_FLUSH.Match(meta.Request.ACTION))
                {
                    try
                    {
                        if (reloadCoreSources())
                        {
                            entity.status.AddNote($"Reset succeeded.", WSConstants.ACCESS_LEVEL.READ, WSStatus.SUCCESS.CODE);
                        }
                        else
                        {
                            entity.status.AddNote("Reset failed.", WSConstants.ACCESS_LEVEL.READ, WSStatus.ERROR.CODE);
                        }
                    }
                    catch (Exception e) { meta.RegError(GetType(), e, ref iostatus); }
                }
                else if (WSConstants.ALIACES.ACTION_CREATE.Match(meta.Request.ACTION))
                {
                    string ENTITY = meta.Request.INPUT.ReadValue(WSConstants.ALIACES.ENTITY, out ENTITY) ? ENTITY : null;

                    if (!string.IsNullOrEmpty(ENTITY))
                    {
                        if (WSConstants.ALIACES.ACCESS_KEY.Match(ENTITY))
                        {
                            entity.data = meta.GenerateWSAccessKey();
                        }
                    }
                }

                #region VERSION 0
                if (WSConstants.PARAMS.IOVERSION.VERSION0.Match(meta.Request.VERSION))
                {
                    response = rec;
                }
                #endregion

                #region VERSION 1
                else if (WSConstants.PARAMS.IOVERSION.VERSION1.Match(meta.Request.VERSION))
                {
                    response = new V1SystemResponseRecord(meta.ClientFunctions, new V1SystemResponseEntity()
                    {
                        status  = (rec == null || rec.entity == null) ? WSStatus.ERROR.NAME : iostatus.NAME,
                        data    = rec,
                        message = iostatus.NOTES
                    }, meta.Request.Security.AuthToken.User.role);
                    if (response == null)
                    {
                        response = new V1SystemResponseRecord(meta.ClientFunctions, new V1SystemResponseEntity()
                        {
                            status = WSStatus.ERROR.NAME, message = iostatus.NOTES
                        }, meta.Request.Security.AuthToken.User.role);
                    }
                }
                #endregion
            }
            catch (Exception e) { meta.RegError(GetType(), e, ref iostatus); }
        }