Exemple #1
0
 public override Expression SortTable <T>(MetaFunctions CFunc, WSDataContext dc, List <PropertyInfo> parents, Expression expression, ref WSStatus iostatus)
 {
     try
     {
         foreach (WSJson json in Value)
         {
             List <PropertyInfo> subParents = new List <PropertyInfo>();
             if (parents != null && parents.Any())
             {
                 subParents.AddRange(parents);
             }
             expression = json.SortTable <T>(CFunc, dc, subParents, expression, ref iostatus);
         }
     }
     catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
     return(expression);
 }
        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);
        }
Exemple #3
0
        public override Expression SortTable <TEntity>(MetaFunctions CFunc, WSDataContext dc, List <PropertyInfo> parents, Expression expression, ref WSStatus iostatus)
        {
            try
            {
                if (dc != null)
                {
                    parents = parents != null ? parents : new List <PropertyInfo>();
                    Type          srcType    = parents.Any() ? parents.LastOrDefault().PropertyType.IsCollection() ? parents.LastOrDefault().PropertyType.GetEntityType() : parents.LastOrDefault().PropertyType : typeof(TEntity);
                    ITable        initSource = srcType == null ? null : dc.GetTable(typeof(TEntity));
                    ITable        source     = srcType == null ? null : dc.GetTable(srcType);
                    WSTableSource schema     = srcType == null ? null : (WSTableSource)CFunc.GetSourceByType(srcType);
                    if (schema != null)
                    {
                        WSParam param = schema.GetXParam(Value);

                        if (param != null && param is WSTableParam)
                        {
                            WSTableParam tParam   = (WSTableParam)param;
                            PropertyInfo property = srcType.GetProperties().FirstOrDefault(p => tParam.WSColumnRef.NAME.Equals(p.Name));
                            if (property == null)
                            {
                                iostatus.AddNote(string.Format("No PropertyInfo found for : [{0}]", tParam.DISPLAY_NAME));
                            }
                            else
                            {
                                parents.Add(property);

                                if (tParam.DataType.IsSimple() && tParam.IsSortable)
                                {
                                    expression = SortPrimitiveType <TEntity>(initSource, source, param, false, parents, expression, ref iostatus);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
            return(expression);
        }
        internal bool GetContext(Type _ContextType, WSRequestID _RequestID, out WSDataContext _Context)
        {
            _Context = null;
            try
            {
                WSDCState             State = _ContextType.GetState(Items);
                Func <WSDCItem, bool> iFunc = (x =>
                                               x.Context != null &&
                                               !x.Context.IsDisposed &&
                                               x.Context.GetType() == _ContextType &&
                                               (State == WSDCState.Closed || State == WSDCState.Open)
                                               );

                WSDCItem DCItem = Items.Any(iFunc) ? Items.FirstOrDefault(iFunc) : CreateIfNotValid(_ContextType, _RequestID, State, iFunc);

                WSDCItem.Open(DCItem);

                _Context = DCItem == null ? null : DCItem.Context;

                return(_Context != null);
            }
            catch (Exception) { return(false); }
        }
        private WSSession ReadWSSession(string dbName)
        {
            WSSession session = null;

            if (!string.IsNullOrEmpty(dbName))
            {
                try
                {
                    WSSecurityMeta meta = SecurityMap[dbName];
                    session = new WSSession(Request.SessionID, meta);

                    /**********************
                     * ANDVO@NOTE:
                     * DO NOT do [ZoneContext = Request.ZoneContext;]
                     * because it will use Request's zone, when it MUST BE zone for the argument:'dbName' !!!
                     * */
                    using (WSDataContext ZoneContext = GetInternalContext(meta.Zone, Request.ID, $"{GetType().Name}.ReadWSSession('{dbName}')"))
                    {
                        if (ZoneContext != null && !ZoneContext.IsDisposed && ZoneContext.Connection.State == System.Data.ConnectionState.Open)
                        {
                            if (meta.SessionType != null)
                            {
                                MethodInfo mInfo = ZoneContext.GetType().GetMethod("GetTable", new Type[] { });

                                var tObj = mInfo.MakeGenericMethod(new Type[] { meta.SessionType }).Invoke(ZoneContext, new object[] { });

                                Func <WSDynamicEntity, bool> func = s => s.readPropertyValue(WSConstants.PARAMS.SESSIONID.NAME, "").ToString().ToLower().Equals(Request.SessionID.ToLower());

                                MethodInfo[] methods = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public);

                                var method = methods.FirstOrDefault(m => m.Name == "FirstOrDefault" && m.GetParameters().Count() == 2).MakeGenericMethod(typeof(WSDynamicEntity));

                                WSDynamicEntity sessionEntity = (WSDynamicEntity)method.Invoke(null, new object[] { tObj, func });

                                if (sessionEntity != null)
                                {
                                    WSDynamicEntity userEntity = (WSDynamicEntity)sessionEntity.GetType().GetProperties().Single(x => x.PropertyType == meta.UserType).GetValue(sessionEntity, null);

                                    if (userEntity != null)
                                    {
                                        object _id        = userEntity.TryReadPropertyValue("UserID", out _id) ? _id : null;
                                        object _email     = userEntity.TryReadPropertyValue("Email", out _email) ? _email : null;
                                        object _firstname = userEntity.TryReadPropertyValue("FirstName", out _firstname) ? _firstname : null;
                                        object _lastname  = userEntity.TryReadPropertyValue("LastName", out _lastname) ? _lastname : null;
                                        object _isactive  = userEntity.TryReadPropertyValue("IsActive", out _isactive) ? _isactive : null;
                                        object _login     = userEntity.TryReadPropertyValue("Login", out _login) ? _login : null;

                                        WSDynamicEntity roleEntity = (WSDynamicEntity)userEntity.GetType().GetProperties().FirstOrDefault(x => x.PropertyType == meta.RoleType).GetValue(userEntity, null);

                                        if (roleEntity != null)
                                        {
                                            object _role     = roleEntity.TryReadPropertyValue("ID", out _role) ? _role : null;
                                            object _roleName = roleEntity.TryReadPropertyValue("Name", out _roleName) ? _roleName : null;

                                            int    id    = int.TryParse(_id.ToString(), out id) ? id : -1;
                                            string email = _email != null?_email.ToString() : string.Empty;

                                            string login = _login != null?_login.ToString() : string.Empty;

                                            string firstname = _firstname != null?_firstname.ToString() : string.Empty;

                                            string lastname = _lastname != null?_lastname.ToString() : string.Empty;

                                            bool   isactive = bool.TryParse(_isactive.ToString(), out isactive) ? isactive : false;
                                            byte   role     = byte.TryParse(_role == null ? null : _role.ToString(), out role) ? role : WSConstants.DEFAULT_USER_ROLE;
                                            string roleName = _roleName != null?_roleName.ToString() : string.Empty;

                                            session.user = new WSUserToken()
                                            {
                                                id        = id,
                                                email     = email,
                                                login     = login,
                                                firstname = firstname,
                                                lastname  = lastname,
                                                isactive  = isactive,
                                                role      = role,
                                                roleName  = roleName
                                            };
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e) { RegError(GetType(), e, ref LoadStatus); }
            }
            return(session);
        }
Exemple #6
0
 public abstract Expression SortTable <T>(MetaFunctions CFunc, WSDataContext dc, List <PropertyInfo> parents, Expression expression, ref WSStatus iostatus);
Exemple #7
0
 public WSRecordJsonConverter(WSParamList _XParams, WSRequest _Request, ClientFunctions _CFunc, WSDataContext _DBContext, params Type[] _types)
 {
     XParams   = _XParams;
     Request   = _Request;
     CFunc     = _CFunc;
     DBContext = _DBContext;
     types     = _types;
 }
Exemple #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);
        }
Exemple #9
0
 public virtual bool Match(WSRequest Request, WSDataContext DBContext, MetaFunctions CFunc, WSSchema schema)
 {
     return(true);
 }
Exemple #10
0
        private WSStatus WriteJProperty(object obj, WSParam xParam, JsonWriter writer, JsonSerializer serializer, WSSchema schema, WSSource xSource, WSParamList outFields, List <Type> printedTypes, WSRequest Request, MetaFunctions CFunc, WSDataContext DBContext)
        {
            WSStatus status = WSStatus.NONE_Copy();

            try
            {
                if (Validate(obj, xParam, writer, serializer, schema, xSource, outFields, ref status, Request, CFunc))
                {
                    if (obj == null)
                    {
                        WritePropName(writer, ((schema != null && !string.IsNullOrEmpty(schema.Name)) ? schema.Name : xParam.NAME), true, PrintMode.ValueCell);
                        serializer.Serialize(writer, obj);
                    }
                    else if (obj is WSStatus || obj is WSStatus_JSON)
                    {
                        #region PRINT WSStatus
                        WSStatus_JSON json = obj is WSStatus_JSON ? (WSStatus_JSON)obj : ((WSStatus)obj).GetJson();
                        if (json != null)
                        {
                            WritePropName(writer, ((schema != null && !string.IsNullOrEmpty(schema.Name)) ? schema.Name : xParam.NAME), true, PrintMode.TableHeader);
                            serializer.Serialize(writer, json);
                        }
                        #endregion
                    }
                    else if (obj.GetType().IsSimple())
                    {
                        #region PRINT PRIMITIVE FIELD

                        if (obj is DateTime)
                        {
                            obj = ((DateTime)obj).ToString(WSConstants.DATE_FORMAT);
                        }
                        else if (obj is TimeSpan)
                        {
                            obj = ((TimeSpan)obj).ToString(WSConstants.TIMESPAN_FORMAT_SIMPLE);
                        }

                        WritePropName(writer, (schema != null && !string.IsNullOrEmpty(schema.Name)) ? schema.Name : xParam.NAME);
                        object _obj = null;
                        serializer.Serialize(writer, xParam.TryReadPrimitiveWithDefault(obj, string.Empty, out _obj) ? _obj : string.Empty);

                        #endregion
                    }
                    else if (obj.GetType().IsSimpleCollection())
                    {
                        #region PRINT PRIMITIVE COLLECTION
                        string key = (schema != null && !string.IsNullOrEmpty(schema.Name)) ? schema.Name : xParam.NAME;
                        status.AddNote("ready to searialize primitive fields (" + key + ")");

                        WritePropName(writer, key);
                        serializer.Serialize(writer, obj);

                        #endregion
                    }
                    else if (obj is WSRecord)
                    {
                        #region PRINT WSRecord

                        string pKey = (schema != null && !string.IsNullOrEmpty(schema.Name)) ? schema.Name : xParam.NAME;
                        WritePropName(writer, pKey);
                        ((WSRecord)obj).WriteJson(writer, serializer, printedTypes, Request, CFunc, DBContext);

                        #endregion
                    }
                    else if (obj.IsCollectionOf <WSRecord>())
                    {
                        #region PRINT WSRecord Collection

                        string pKey = (schema != null && !string.IsNullOrEmpty(schema.Name)) ? schema.Name : xParam.NAME;

                        WritePropName(writer, pKey);
                        writer.WriteStartArray();

                        IList list = obj as IList;
                        foreach (WSRecord record in list)
                        {
                            if (record != null)
                            {
                                record.WriteJson(writer, serializer, printedTypes, Request, CFunc, DBContext);
                            }
                        }

                        writer.WriteEndArray();
                        #endregion
                    }
                    else
                    {
                        #region PRINT ENTITY

                        bool printAllowed =
                            (this is WSStaticEntity)
                            ||
                            (
                                schema is WSEntityBaseSchema
                                &&
                                validateType(writer, xParam, obj, printedTypes, true, Request, CFunc)
                            );

                        if (printAllowed)
                        {
                            string pKey = (schema != null && !string.IsNullOrEmpty(schema.Name)) ? schema.Name : xParam.NAME;
                            WritePropName(writer, pKey, false);

                            #region PRINT WSEntity
                            if (obj is WSEntity)
                            {
                                if (obj is WSDynamicEntity && !((WSDynamicEntity)obj).Match(Request, DBContext, CFunc, schema))
                                {
                                    serializer.Serialize(writer, "NULL");
                                }
                                else
                                {
                                    ((WSEntity)obj).WriteJson(writer, serializer, schema, outFields, printedTypes, Request, CFunc, DBContext);
                                }
                            }
                            #endregion

                            #region PRINT Collection
                            else if (obj.IsCollectionOf <WSEntity>())
                            {
                                IList list  = obj as IList;
                                Type  eType = list.GetEntityType();

                                writer.WriteStartArray();
                                foreach (WSEntity entity in list)
                                {
                                    if (entity != null)
                                    {
                                        if (entity is WSDynamicEntity)
                                        {
                                            WSDynamicEntity dEntity = (WSDynamicEntity)entity;
                                            if (dEntity.Match(Request, DBContext, CFunc, schema))
                                            {
                                                entity.WriteJson(writer, serializer, schema, outFields, printedTypes, Request, CFunc, DBContext);
                                            }
                                        }
                                        else
                                        {
                                            entity.WriteJson(writer, serializer, schema, outFields, printedTypes, Request, CFunc, DBContext);
                                        }
                                    }
                                }
                                writer.WriteEndArray();
                            }
                            #endregion
                        }

                        #endregion
                    }
                    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);
        }
Exemple #11
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);
        }
Exemple #12
0
 public WSDCItem(WSDataContext _Context, WSRequestID _ID)
 {
     Context = _Context;
     ID      = _ID;
 }
        public bool TrySetRecordValue(string colName, object newValue, WSDataContext DBContext, MetaFunctions CFunc, Func <Exception, bool> AddError = null)
        {
            bool done = false;

            if (!string.IsNullOrEmpty(colName))
            {
                PropertyInfo pInfo = GetType().GetProperty(colName);
                if (pInfo != null)
                {
                    object orgValue = pInfo.GetValue(this, null);
                    newValue = fixSpecialCaseValue(colName, newValue, pInfo.PropertyType);
                    try
                    {
                        if (
                            orgValue == newValue ||
                            (orgValue == null && newValue == null) ||
                            (orgValue != null && newValue != null && orgValue.ToString().Equals(newValue.ToString()))
                            )
                        {
                            return(true);
                        }
                        else
                        {
                            if (newValue == null)
                            {
                                if (pInfo.PropertyType.IsNullable())
                                {
                                    pInfo.SetPropertyValue(this, null); done = true;
                                }
                            }
                            else
                            {
                                object newValueConverted = pInfo.PropertyType.IsAssignableFrom(newValue.GetType()) ? newValue : null;
                                if (newValueConverted != null || pInfo.PropertyType.Read(newValue, out newValueConverted, null, null, pInfo.Name))
                                {
                                    try
                                    {
                                        bool           IsAssiciation  = false;
                                        PropertyInfo   association    = null;
                                        WSTableSource  associationSrc = null;
                                        WSTableParam   associationKey = null;
                                        PropertyInfo[] props          = GetType().GetProperties();
                                        foreach (PropertyInfo prop in props)
                                        {
                                            IEnumerable <CustomAttributeData> cAttrs = prop.CustomAttributesData();
                                            foreach (CustomAttributeData cad in cAttrs)
                                            {
                                                CustomAttributeNamedArgument IsForeignKey = cad.NamedArguments.FirstOrDefault(x => x.MemberInfo.Name.Equals("IsForeignKey"));
                                                if (IsForeignKey != null && IsForeignKey.TypedValue.Value != null && (true.ToString()).Equals(IsForeignKey.TypedValue.Value.ToString()))
                                                {
                                                    CustomAttributeNamedArgument cana = cad.NamedArguments.FirstOrDefault(x => x.MemberInfo.Name.Equals("ThisKey"));
                                                    if (cana != null && pInfo.Name.Equals(cana.TypedValue.Value == null ? null : cana.TypedValue.Value.ToString()))
                                                    {
                                                        CustomAttributeNamedArgument canaKey = cad.NamedArguments.FirstOrDefault(x => x.MemberInfo.Name.Equals("OtherKey"));
                                                        if (canaKey != null && canaKey.TypedValue.Value != null)
                                                        {
                                                            IsAssiciation  = true;
                                                            association    = prop;
                                                            associationSrc = (WSTableSource)CFunc.GetSourceByType(association.PropertyType);
                                                            associationKey = (WSTableParam)associationSrc.GetXParam(canaKey.TypedValue.Value.ToString());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (IsAssiciation)
                                        {
                                            string pName = pInfo.Name;

                                            ParameterExpression paramExp = Expression.Parameter(association.PropertyType, "x");
                                            WSCombineFilter     filter   = new WSCombineFilter(WSCombineFilter.SQLMode.AndAlso);

                                            filter.Save(new WSJValue(newValueConverted.ToString()).GetFieldFilter(CFunc, associationKey, paramExp, 0));

                                            object subExpr = (Expression)filter.GetType().GetMethod("ToLambda").MakeGenericMethod(new Type[] { association.PropertyType }).Invoke(filter, new object[] { paramExp });

                                            MethodInfo mInfo = DBContext.GetType().GetMethod("GetTable", new Type[] { });

                                            var tObj = mInfo.MakeGenericMethod(new Type[] { association.PropertyType }).Invoke(DBContext, new object[] { });

                                            Func <WSDynamicEntity, bool> func = s => s.readPropertyValue(associationKey.WSColumnRef.NAME).ToString().Equals(newValueConverted.ToString());

                                            var method = typeof(Enumerable).GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public)
                                                         .FirstOrDefault(m => m.Name == "FirstOrDefault" && m.GetParameters().Count() == 2).MakeGenericMethod(typeof(WSDynamicEntity));

                                            WSDynamicEntity newAssociation = (WSDynamicEntity)method.Invoke(null, new object[] { tObj, func });

                                            if (newAssociation != null)
                                            {
                                                association.SetPropertyValue(this, newAssociation); done = true;
                                            }
                                        }
                                        else
                                        {
                                            pInfo.SetPropertyValue(this, newValueConverted); done = true;
                                        }
                                    }
                                    catch (Exception e1) { AddError(e1); }
                                }
                            }
                        }
                    }
                    catch (Exception e) { AddError(e); }

                    if (!done)
                    {
                        pInfo.SetPropertyValue(this, orgValue);
                    }
                }
            }
            return(done);
        }
Exemple #14
0
        public WSStatus WriteJson(JsonWriter writer, JsonSerializer serializer, List <Type> printedTypes, WSRequest Request, MetaFunctions CFunc, WSDataContext DBContext)
        {
            WSStatus status = WSStatus.NONE_Copy();

            try
            {
                if (entity == null)
                {
                    status.CODE = WSStatus.ERROR.CODE;
                    status.AddNote("WSEntity not known", WSConstants.ACCESS_LEVEL.READ);
                }
                else
                {
                    List <Type> postPrintedTypes = printedTypes.Select(x => x).ToList();
                    postPrintedTypes.Add(entity.GetType());

                    if (entity != null)
                    {
                        status.childs.Add(entity.WriteJson(writer, serializer, schema, outFields, postPrintedTypes, Request, CFunc, DBContext));
                    }
                }
            }
            catch (Exception e) {
                CFunc.RegError(GetType(), e, ref status);
                status.CODE = WSStatus.ERROR.CODE;
                status.AddNote("Error(line" + e.LineNumber() + "- " + e.Message + ")");
            }
            return(status);
        }
Exemple #15
0
        private static WSDataContext GetClientContext(string dbName, WSRequestID RequestID, string _Caller)
        {
            WSDataContext dc = null;

            if (CoreSources == null) /*LoadStatus.AddNote("CS is NULL : [{LoadStatusStatic:" + LoadStatusStatic + "}]");*/ } {
Exemple #16
0
        private static WSSources <WSTableSource> LoadMetaSources()
        {
            LoadStatusStatic.AddNote($"IOSB.LoadMetaSources()");
            WSSources <WSTableSource>        ORG_SOURCES = new WSSources <WSTableSource>();
            Dictionary <Type, WSDataContext> dbList      = new Dictionary <Type, WSDataContext>();

            try
            {
                if (EntityTypes != null && EntityTypes.Any())
                {
                    IEnumerable <string> namespaces_         = EntityTypes.Select(t => t.Namespace).Distinct();
                    Dictionary <string, List <Type> > nsList = namespaces_.ToDictionary(key => key, val => new List <Type>());

                    foreach (Type type in EntityTypes)
                    {
                        nsList[type.Namespace].Add(type);
                    }
                    foreach (KeyValuePair <string, List <Type> > ns in nsList)
                    {
                        if (ns.Value.Any())
                        {
                            foreach (Type type in ns.Value)
                            {
                                try
                                {
                                    Type          DCType = GetDCTypeByEntityType(type);
                                    WSDataContext db     = null;
                                    if (dbList.Any(x => x.Key == DCType))
                                    {
                                        db = dbList.FirstOrDefault(x => x.Key == DCType).Value;
                                    }
                                    else
                                    {
                                        db = GetServerContext(DCType, null, $"{typeof(WSServerMeta).Name}.LoadMetaSources() => [{type.FullName}:{DCType.Name}");
                                        dbList.Add(DCType, db);
                                    }

                                    if (db != null)
                                    {
                                        string        DBName = db.GetType().CustomAttribute <DatabaseAttribute>(true).Name;
                                        WSTableSource tSrc   = new WSTableSource(
                                            type,
                                            SecurityMap.FirstOrDefault(m => m.Key.Equals(DBName)).Value.Zone,
                                            type.Name,
                                            ServerFunctions,
                                            WSConstants.ACCESS_LEVEL.READ
                                            );

                                        #region READ PROPERTIES
                                        List <MetaDataMember> eProps = db.ReadProperties(type, ref LoadStatusStatic);
                                        if (eProps != null && eProps.Any())
                                        {
                                            List <WSTableParam> _params = new List <WSTableParam>();
                                            foreach (MetaDataMember prop in eProps)
                                            {
                                                try
                                                {
                                                    WSTableParam tParam = new WSTableParam(type, next_code, prop.Name, new WSColumnRef(prop.Name), prop.Type, ServerFunctions);

                                                    object[] CustomAttributes = prop.Member.GetCustomAttributes(true);

                                                    IEnumerable <AssociationAttribute> assAttributes = CustomAttributes.OfType <AssociationAttribute>();
                                                    if (assAttributes != null && assAttributes.Any())
                                                    {
                                                        tParam.IsAssociation = true;
                                                    }

                                                    IEnumerable <ColumnAttribute> cAttributes = CustomAttributes.OfType <ColumnAttribute>();
                                                    if (cAttributes != null && cAttributes.Any())
                                                    {
                                                        tParam.IsColumn = true;
                                                        if (cAttributes.FirstOrDefault().IsPrimaryKey)
                                                        {
                                                            tParam.WRITE_ACCESS_MODE = new WSAccessMode(WSConstants.ACCESS_LEVEL.LOCK, false);
                                                            if (!tSrc.Params.Any(p => p.Match(WSConstants.PARAMS.RECORD_ID.NAME)))
                                                            {
                                                                tParam.DISPLAY_NAME = WSConstants.PARAMS.RECORD_ID.NAME;
                                                                if (!tParam.ALIACES.Any(a => a.Equals(WSConstants.PARAMS.RECORD_ID.NAME)))
                                                                {
                                                                    tParam.ALIACES.Add(WSConstants.PARAMS.RECORD_ID.NAME);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    _params.Add(tParam);
                                                }
                                                catch (Exception) { }
                                            }
                                            tSrc.AddParams(_params);
                                            tSrc.ClearDublicatedAliaces();
                                        }
                                        #endregion

                                        if (!ORG_SOURCES.Any(x => x.Match(tSrc)))
                                        {
                                            ORG_SOURCES.Add(tSrc);
                                        }
                                    }
                                }
                                catch (Exception) { }
                            }
                        }
                    }
                }
            }
            catch (Exception) { }
            finally {
                foreach (Type t in dbList.Keys)
                {
                    try {
                        if (dbList[t] != null)
                        {
                            dbList[t].Dispose();
                        }
                    } catch (Exception e) { }
                }
            }
            return(ORG_SOURCES);
        }