Esempio n. 1
0
        public void OnReturn(IListRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                !handler.ShouldSelectField(Target) ||
                handler.Response.Entities.IsEmptyOrNull())
            {
                return;
            }

            var idField = (Field)((handler.Row as IIdRow).IdField);

            var listHandler = listHandlerFactory();

            var listRequest = new ListRequest
            {
                ColumnSelection = ColumnSelection.KeyOnly,
                IncludeColumns  = new HashSet <string>
                {
                    itemKeyField.PropertyName ?? itemKeyField.Name,
                    thisKeyField.PropertyName ?? thisKeyField.Name
                }
            };

            var thisKeyCriteria = new Criteria(thisKeyField.PropertyName ?? thisKeyField.Name);

            var enumerator = handler.Response.Entities.Cast <Row>();

            while (true)
            {
                var part = enumerator.Take(1000);
                if (!part.Any())
                {
                    break;
                }

                enumerator = enumerator.Skip(1000);

                listRequest.Criteria = thisKeyCriteria.In(
                    part.Select(x => idField.AsObject(x)));

                IListResponse response = listHandler.Process(
                    handler.Connection, listRequest);

                var lookup = response.Entities.Cast <Row>()
                             .ToLookup(x => thisKeyField.AsObject(x).ToString());

                foreach (var row in part)
                {
                    var list     = listFactory();
                    var matching = lookup[idField.AsObject(row).ToString()];
                    foreach (var x in matching)
                    {
                        list.Add(itemKeyField.AsObject(x));
                    }

                    Target.AsObject(row, list);
                }
            }
        }
Esempio n. 2
0
        public void OnPrepareQuery(IListRequestHandler handler, SqlQuery query)
        {
            var user = (UserDefinition)Authorization.UserDefinition;

            if (!Authorization.HasPermission(PermissionKeys.Comercio))
            {
                query.Where(fldIdComercio == user.Id_Comercio);
            }
        }
Esempio n. 3
0
        public void OnPrepareQuery(IListRequestHandler handler, SqlQuery query)
        {
            var user = (UserDefinition)Authorization.UserDefinition;

            if (!Authorization.HasPermission(PermissionKeys.Tenants))
            {
                query.Where(fldTenantId == user.TenantId);
            }
        }
        public void OnReturn(IListRequestHandler handler)
        {
            if (Target is null ||
                !handler.AllowSelectField(Target) ||
                !handler.ShouldSelectField(Target) ||
                handler.Response.Entities.IsEmptyOrNull())
            {
                return;
            }

            var idField = handler.Row.IdField;

            var listHandler = handlerFactory.CreateHandler <IListRequestProcessor>(rowType);
            var listRequest = listHandler.CreateRequest();

            listRequest.ColumnSelection = ColumnSelection.KeyOnly;
            listRequest.IncludeColumns  = new HashSet <string>
            {
                itemKeyField.PropertyName ?? itemKeyField.Name,
                thisKeyField.PropertyName ?? thisKeyField.Name
            };

            var enumerator = handler.Response.Entities.Cast <IRow>();

            while (true)
            {
                var part = enumerator.Take(1000);
                if (!part.Any())
                {
                    break;
                }

                enumerator = enumerator.Skip(1000);

                listRequest.Criteria = thisKeyCriteria.In(
                    part.Select(x => idField.AsObject(x))) & filterCriteria;

                IListResponse response = listHandler.Process(
                    handler.Connection, listRequest);

                var lookup = response.Entities.Cast <IRow>()
                             .ToLookup(x => thisKeyField.AsObject(x).ToString());

                foreach (var row in part)
                {
                    var list     = listFactory();
                    var matching = lookup[idField.AsObject(row).ToString()];
                    foreach (var x in matching)
                    {
                        list.Add(itemKeyField.AsObject(x));
                    }

                    Target.AsObject(row, list);
                }
            }
        }
        public void OnReturn(IListRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                !handler.AllowSelectField(Target) ||
                !handler.ShouldSelectField(Target) ||
                handler.Response.Entities.IsEmptyOrNull())
            {
                return;
            }

            var idField = (Field)((handler.Row as IIdRow).IdField);

            var listHandler = listHandlerFactory();

            var listRequest = new ListRequest
            {
                ColumnSelection = this.attr.ColumnSelection,
                IncludeColumns  = this.includeColumns
            };

            var enumerator = handler.Response.Entities.Cast <Row>();

            while (true)
            {
                var part = enumerator.Take(1000);
                if (!part.Any())
                {
                    break;
                }

                enumerator = enumerator.Skip(1000);

                listRequest.Criteria = foreignKeyCriteria.In(
                    part.Select(x => idField.AsObject(x))) & filterCriteria;

                IListResponse response = listHandler.Process(
                    handler.Connection, listRequest);

                var lookup = response.Entities.Cast <Row>()
                             .ToLookup(x => foreignKeyField.AsObject(x).ToString());

                foreach (var row in part)
                {
                    var list     = rowListFactory();
                    var matching = lookup[idField.AsObject(row).ToString()];
                    foreach (var x in matching)
                    {
                        list.Add(x);
                    }

                    Target.AsObject(row, list);
                }
            }
        }
Esempio n. 6
0
        public void OnPrepareQuery(IListRequestHandler handler, SqlQuery query)
        {
            if (ReferenceEquals(null, Target) ||
                handler.Request.EqualityFilter == null ||
                !attr.HandleEqualityFilter)
            {
                return;
            }

            object value;

            if (handler.Request.EqualityFilter.TryGetValue(Target.PropertyName, out value) ||
                handler.Request.EqualityFilter.TryGetValue(Target.Name, out value))
            {
                if (value == null || value as string == "")
                {
                    return;
                }

                var values = new List <object>();

                if (!(value is string) && value is IEnumerable)
                {
                    foreach (var val in (IEnumerable)value)
                    {
                        values.Add(itemKeyField.ConvertValue(val, CultureInfo.InvariantCulture));
                    }
                }
                else
                {
                    values.Add(itemKeyField.ConvertValue(value, CultureInfo.InvariantCulture));
                }

                if (values.Count > 0)
                {
                    var ls = new Alias(itemKeyField.Fields.TableName, "__ls");

                    query.Where(Criteria.Exists(
                                    query.SubQuery()
                                    .From(ls)
                                    .Select("1")
                                    .Where(
                                        new Criteria(ls[thisKeyField]) == new Criteria((Field)((IIdRow)handler.Row).IdField) &
                                        new Criteria(ls[itemKeyField]).In(values))
                                    .ToString()));
                }

                handler.IgnoreEqualityFilter(Target.PropertyName);
                handler.IgnoreEqualityFilter(Target.Name);
            }
        }
        public void OnReturn(IListRequestHandler handler)
        {
            if (Target is null ||
                !handler.AllowSelectField(Target) ||
                !handler.ShouldSelectField(Target) ||
                handler.Response.Entities.IsEmptyOrNull())
            {
                return;
            }

            var listHandler = handlerFactory.CreateHandler <IListRequestProcessor>(rowType);
            var listRequest = listHandler.CreateRequest();

            listRequest.ColumnSelection = attr.ColumnSelection;
            listRequest.IncludeColumns  = includeColumns;

            var enumerator = handler.Response.Entities.Cast <IRow>();

            while (true)
            {
                var part = enumerator.Take(1000);
                if (!part.Any())
                {
                    break;
                }

                enumerator = enumerator.Skip(1000);

                listRequest.Criteria = foreignKeyCriteria.In(
                    part.Select(x => masterKeyField.AsObject(x))) & filterCriteria;

                IListResponse response = listHandler.Process(
                    handler.Connection, listRequest);

                var lookup = response.Entities.Cast <IRow>()
                             .ToLookup(x => foreignKeyField.AsObject(x).ToString());

                foreach (var row in part)
                {
                    var list     = rowListFactory();
                    var matching = lookup[masterKeyField.AsObject(row).ToString()];
                    foreach (var x in matching)
                    {
                        list.Add(x);
                    }

                    Target.AsObject(row, list);
                }
            }
        }
Esempio n. 8
0
        public void OnReturn(IListRequestHandler handler)
        {
            if (handler.Response.Entities.Count == 0)
            {
                return;
            }
            var entities = handler.Response.Entities.Cast <OMPLoggingRow>().ToList();

            var insertUserIds = entities
                                .Where(l => l.InsertUserId != null)
                                .Select(l => l.InsertUserId);
            var updateUserIds = entities
                                .Where(l => l.UpdateUserId != null)
                                .Select(l => l.UpdateUserId);

            var allIdsList = new List <int?>();

            allIdsList.AddRange(insertUserIds);
            allIdsList.AddRange(updateUserIds);

            allIdsList = allIdsList.Distinct().ToList();

            using (var connection = SqlConnections.NewFor <UserRow>())
            {
                var users = connection.List <UserRow>(UserRow.Fields.UserId.In(allIdsList));

                foreach (var entity in handler.Response.Entities.Cast <OMPLoggingRow>())
                {
                    if (entity.InsertUserId.HasValue)
                    {
                        entity.InsertUserName = users.FirstOrDefault(u => u.UserId == entity.InsertUserId.Value)?.DisplayName;
                    }

                    if (entity.UpdateUserId.HasValue)
                    {
                        entity.UpdateUserName = users.FirstOrDefault(u => u.UserId == entity.UpdateUserId.Value)?.DisplayName;
                    }
                }
            }
        }
 public void OnValidateRequest(IListRequestHandler handler) { }
Esempio n. 10
0
 public void OnBeforeExecuteQuery(IListRequestHandler handler) { }
Esempio n. 11
0
 public void OnValidateRequest(IListRequestHandler handler) { }
 public static ListRequest CreateRequest(this IListRequestHandler handler)
 {
     return((ListRequest)Activator.CreateInstance(handler.GetRequestType()));
 }
        public void OnReturn(IListRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                !handler.AllowSelectField(Target) ||
                !handler.ShouldSelectField(Target) ||
                handler.Response.Entities.IsEmptyOrNull())
                return;

            var idField = (Field)((handler.Row as IIdRow).IdField);

            var listHandler = listHandlerFactory();

            var listRequest = new ListRequest
            {
                ColumnSelection = ColumnSelection.KeyOnly,
                IncludeColumns = new HashSet<string>
                {
                    itemKeyField.PropertyName ?? itemKeyField.Name,
                    thisKeyField.PropertyName ?? thisKeyField.Name
                }
            };

            var enumerator = handler.Response.Entities.Cast<Row>();
            while (true)
            {
                var part = enumerator.Take(1000);
                if (!part.Any())
                    break;

                enumerator = enumerator.Skip(1000);

                listRequest.Criteria = thisKeyCriteria.In(
                    part.Select(x => idField.AsObject(x))) & filterCriteria;

                IListResponse response = listHandler.Process(
                    handler.Connection, listRequest);

                var lookup = response.Entities.Cast<Row>()
                    .ToLookup(x => thisKeyField.AsObject(x).ToString());

                foreach (var row in part)
                {
                    var list = listFactory();
                    var matching = lookup[idField.AsObject(row).ToString()];
                    foreach (var x in matching)
                        list.Add(itemKeyField.AsObject(x));

                    Target.AsObject(row, list);
                }
            }
        }
        public void OnPrepareQuery(IListRequestHandler handler, SqlQuery query)
        {
            if (ReferenceEquals(null, Target) ||
                handler.Request.EqualityFilter == null ||
                !attr.HandleEqualityFilter)
                return;

            object value;
            if (handler.Request.EqualityFilter.TryGetValue(Target.PropertyName, out value) ||
                handler.Request.EqualityFilter.TryGetValue(Target.Name, out value))
            {
                if (value == null || value as string == "")
                    return;

                var values = new List<object>();

                if (!(value is string) && value is IEnumerable)
                {
                    foreach (var val in (IEnumerable)value)
                        values.Add(itemKeyField.ConvertValue(val, CultureInfo.InvariantCulture));
                }
                else
                {
                    values.Add(itemKeyField.ConvertValue(value, CultureInfo.InvariantCulture));
                }

                if (values.Count > 0)
                {
                    var ls = new Alias(itemKeyField.Fields.TableName, "__ls");

                    query.Where(Criteria.Exists(
                        query.SubQuery()
                            .From(ls)
                            .Select("1")
                            .Where(
                                new Criteria(ls[thisKeyField]) == new Criteria((Field)((IIdRow)handler.Row).IdField) &
                                new Criteria(ls[itemKeyField]).In(values))
                            .ToString()));
                }

                handler.IgnoreEqualityFilter(Target.PropertyName);
                handler.IgnoreEqualityFilter(Target.Name);
            }
        }
 public void OnPrepareQuery(IListRequestHandler handler, SqlQuery query) { }
 public void OnPrepareQuery(IListRequestHandler handler, SqlQuery query)
 {
     var user = (UserDefinition)Authorization.UserDefinition;
     if (!Authorization.HasPermission(PermissionKeys.Tenants))
         query.Where(fldTenantId == user.TenantId);
 }
 public void OnAfterExecuteQuery(IListRequestHandler handler) { }
Esempio n. 18
0
 public void OnReturn(IListRequestHandler handler)
 {
 }
 public void OnApplyFilters(IListRequestHandler handler, SqlQuery query) { }
Esempio n. 20
0
 public void OnPrepareQuery(IListRequestHandler handler, SqlQuery query) { }
 public void OnBeforeExecuteQuery(IListRequestHandler handler) { }
Esempio n. 22
0
 public void OnApplyFilters(IListRequestHandler handler, SqlQuery query) { }
 public void OnReturn(IListRequestHandler handler) { }
Esempio n. 24
0
 public void OnAfterExecuteQuery(IListRequestHandler handler) { }
Esempio n. 25
0
        public void OnReturn(IListRequestHandler handler)
        {
            if (handler.Response.Entities.Count == 0)
            {
                return;
            }

            // Lets Get the main row and translate it
            var culture      = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
            var userLanguage = new LanguageRow();

            using (var connectionLanguage = SqlConnections.NewFor <LanguageRow>())
            {
                userLanguage = connectionLanguage.TryFirst <LanguageRow>(new Criteria(LanguageRow.Fields.LanguageId).Like($"%{culture}%"));
                if (userLanguage == null)
                {
                    return;
                }
            }

            var listHandler = DefaultHandlerFactory.ListHandlerFor(localRowType);
            var listRequest = DefaultHandlerFactory.ListRequestFor(localRowType);

            listRequest.ColumnSelection = ColumnSelection.List;

            List <IOMPLocalizationRow> localList = handler.Response.Entities.Cast <IOMPLocalizationRow>().ToList();

            listRequest.Criteria = (foreignKeyCriteria.In(localList.Select(s => s.IdField[s as Row])) && languageIdCriteria == userLanguage.Id.Value);

            var translationsResponse = listHandler.Process(handler.Connection, listRequest);

            if (translationsResponse.Entities.Count > 0)
            {
                var responseLang = translationsResponse.Entities.Cast <IOMPLocalizationLangRow>();
                // Validate They have IName row
                foreach (IOMPLocalizationRow responseEntity in handler.Response.Entities)
                {
                    var entityLang = responseLang
                                     .FirstOrDefault(s =>
                                                     (Int32)foreignKeyField.AsObject(s as Row) ==
                                                     responseEntity.IdField[responseEntity as Row]);

                    if (entityLang != null && !string.IsNullOrEmpty(entityLang?.NameField[entityLang as Row]))
                    {
                        responseEntity.NameField[responseEntity as Row] = entityLang?.NameField[entityLang as Row];
                    }
                }
            }

            // How about the joined tables, lets translate them too
            var localizationRowFields = handler.Row.GetFields();

            foreach (var localizationRowField in localizationRowFields.Where(f =>
                                                                             !String.IsNullOrEmpty(f.ForeignTable)))
            {
                var foreignKeyAttr   = localizationRowField.GetAttribute <ForeignKeyAttribute>();
                var textualFieldAttr = localizationRowField.GetAttribute <TextualFieldAttribute>();
                if (foreignKeyAttr.RowType == null || textualFieldAttr == null || string.IsNullOrEmpty(textualFieldAttr.Value))
                {
                    continue;
                }

                var foreignRowFactory = FastReflection.DelegateForConstructor <Row>(foreignKeyAttr.RowType);
                var foreignRow        = foreignRowFactory();
                var foreignAttr       = foreignRow.GetType().GetCustomAttribute <LocalizationRowAttribute>();

                if (foreignAttr == null)
                {
                    continue;
                }

                var foreignLangType = foreignAttr.LocalizationRow;

                var foreignLangRowFactory = FastReflection.DelegateForConstructor <Row>(foreignLangType);
                var foreignLangRow        = foreignLangRowFactory();

                var externalForeignKeyFieldName =
                    foreignAttr.MappedIdField ?? ((Field)((IIdRow)foreignRow).IdField).PropertyName;
                var externalForeignKeyField = foreignLangRow.FindFieldByPropertyName(externalForeignKeyFieldName) ??
                                              foreignLangRow.FindField(externalForeignKeyFieldName);

                var listForeignHandler = DefaultHandlerFactory.ListHandlerFor(foreignLangType);
                var listForeignRequest = DefaultHandlerFactory.ListRequestFor(foreignLangType);
                listRequest.ColumnSelection = ColumnSelection.List;

                var externalForeignCriteria =
                    new Criteria(externalForeignKeyField.PropertyName ?? externalForeignKeyField.Name);

                var idList = new List <Int32>();
                foreach (IOMPLocalizationRow responseEntity in handler.Response.Entities)
                {
                    var idToAdd = (Int32?)localizationRowField.AsObject(responseEntity as Row);
                    if (idToAdd.HasValue)
                    {
                        idList.Add(idToAdd.Value);
                    }
                }
                if (!idList.Any())
                {
                    continue;
                }
                listForeignRequest.Criteria =
                    externalForeignCriteria.In(idList.Distinct()) &&
                    languageIdCriteria == userLanguage.Id.Value;

                var translationsForeignResponse =
                    listForeignHandler.Process(handler.Connection, listForeignRequest);

                if (translationsForeignResponse.TotalCount > 0)
                {
                    foreach (IOMPLocalizationRow responseEntity in handler.Response.Entities)
                    {
                        var localId = (Int32?)localizationRowField.AsObject(responseEntity as Row);

                        var entityLang = translationsForeignResponse.Entities.Cast <IOMPLocalizationLangRow>()
                                         .FirstOrDefault(s =>
                                                         (Int32?)externalForeignKeyField.AsObject(s as Row) == localId);

                        if (entityLang != null)
                        {
                            var foreignEntityName = entityLang?.NameField[entityLang as Row];

                            var textualFieldExternal = (responseEntity as Row).FindField(textualFieldAttr.Value);
                            if (!string.IsNullOrEmpty(foreignEntityName))
                            {
                                textualFieldExternal.AsObject(responseEntity as Row, foreignEntityName);
                            }
                        }
                    }
                }
            }
        }