Explorar el Código

Removed PartialObjectCopier stuff; fixed ObjectConverterDescriptor.AddNullMemberConverter; misc

develop
Robin Thoni hace 6 años
padre
commit
dfa8f9456f

+ 0
- 10
.idea/.idea.luticate2/.idea/contentModel.xml Ver fichero

@@ -14,11 +14,6 @@
14 14
         <e p="Auth" t="Include">
15 15
           <e p="Business" t="Include">
16 16
             <e p="LuGroupsBusiness.cs" t="Include" />
17
-            <e p="PartialObjectCopier" t="Include">
18
-              <e p="LuPOCGroupsToDbo.cs" t="Include" />
19
-              <e p="LuPOCGroupsToModel.cs" t="Include" />
20
-              <e p="LuPOCObjectsMetadataToDbo.cs" t="Include" />
21
-            </e>
22 17
           </e>
23 18
           <e p="DataAccess" t="Include">
24 19
             <e p="Luticate2DbContext.cs" t="Include" />
@@ -72,10 +67,6 @@
72 67
               <e p="LuFilterParser.cs" t="Include" />
73 68
               <e p="LuOrderByParser.cs" t="Include" />
74 69
             </e>
75
-            <e p="PartialObjectCopier" t="Include">
76
-              <e p="LuPartialObjectCopier.cs" t="Include" />
77
-              <e p="LuPartialObjectCopierExtensions.cs" t="Include" />
78
-            </e>
79 70
             <e p="Serializers" t="Include">
80 71
               <e p="PartialJson" t="Include">
81 72
                 <e p="LuJsonSerializerExtensions.cs" t="Include" />
@@ -119,7 +110,6 @@
119 110
             <e p="ILuCrud.cs" t="Include" />
120 111
             <e p="ILuObjectConverter.cs" t="Include" />
121 112
             <e p="ILuObjectConverterDescriptor.cs" t="Include" />
122
-            <e p="ILuPartialObjectCopier.cs" t="Include" />
123 113
           </e>
124 114
         </e>
125 115
         <e p="bin" t="ExcludeRecursive" />

+ 0
- 6
Luticate2.Auth.ConsoleSample/Program.cs Ver fichero

@@ -1,11 +1,9 @@
1 1
 using System;
2 2
 using Luticate2.Auth.Auth.Business;
3
-using Luticate2.Auth.Auth.Business.PartialObjectCopier;
4 3
 using Luticate2.Auth.Auth.DataAccess;
5 4
 using Luticate2.Auth.Auth.DataAccess.Models;
6 5
 using Luticate2.Auth.Auth.Dbo;
7 6
 using Luticate2.Auth.ConsoleSample.Commands;
8
-using Luticate2.Auth.Utils.Interfaces;
9 7
 using Microsoft.EntityFrameworkCore;
10 8
 using Microsoft.Extensions.DependencyInjection;
11 9
 using NClap.Metadata;
@@ -42,10 +40,6 @@ namespace Luticate2.Auth.ConsoleSample
42 40
             
43 41
             services.AddScoped<LuGroupsBusiness>();
44 42
 
45
-            services.AddSingleton<ILuPartialObjectCopier<LuObjectsMetadata, LuObjectsMetadataDbo>, LuPOCObjectsMetadataToDbo>();
46
-            services.AddSingleton<ILuPartialObjectCopier<LuGroups, LuGroupDbo>, LuPOCGroupsToDbo>();
47
-            services.AddSingleton<ILuPartialObjectCopier<LuGroupDbo, LuGroups>, LuPOCGroupsToModel>();
48
-
49 43
 
50 44
 //            services.AddSingleton<ILuDboModelExpressionConverter<TestDbo1, TestModel1>, LuDMECTest1>();
51 45
 //            AddILuExpressionConverter<LuGroupDbo, LuGroups, LuDMECGroupsToModel>(services);

+ 1
- 1
Luticate2.Auth.Tests/Business/ExpressionConverter/Objects.cs Ver fichero

@@ -20,7 +20,7 @@ namespace Luticate2.Auth.Tests.Business.ExpressionConverter
20 20
 
21 21
         public IList<TestDbo2> TestDbo2s { get; set; }
22 22
 
23
-        public string ToString()
23
+        public override string ToString()
24 24
         {
25 25
             throw new NotImplementedException();
26 26
         }

+ 2
- 5
Luticate2.Auth.Tests/Business/ObjectConverter/ObjectConverterTests.cs Ver fichero

@@ -1,16 +1,13 @@
1 1
 using System;
2
-using System.Collections;
3 2
 using System.Collections.Generic;
4 3
 using System.Collections.ObjectModel;
5 4
 using System.Linq;
6 5
 using System.Linq.Expressions;
7 6
 using Luticate2.Auth.Utils.Business.Converters;
8
-using Luticate2.Auth.Utils.Business.ExpressionConverter;
9 7
 using Luticate2.Auth.Utils.Business.Fields;
10 8
 using Luticate2.Auth.Utils.Business.ObjectConverter;
11 9
 using Luticate2.Auth.Utils.Business.ObjectConverterDescriptor;
12 10
 using Luticate2.Auth.Utils.Dbo;
13
-using Luticate2.Auth.Utils.Dbo.Fields;
14 11
 using Luticate2.Auth.Utils.Dbo.Result;
15 12
 using Luticate2.Auth.Utils.Interfaces;
16 13
 using Microsoft.Extensions.DependencyInjection;
@@ -115,8 +112,8 @@ namespace Luticate2.Auth.Tests.Business.ObjectConverter
115 112
                 Assert.Equal(e.Model.id, e.Dbo.Id);
116 113
                 Assert.Equal(e.Model.name, e.Dbo.Name);
117 114
                 Assert.Equal(e.Model.name + " " + e.Model.name, e.Dbo.NameVirtual);
118
-                Assert.Equal(null, e.Dbo.Parent);
119
-                Assert.Equal(null, e.Dbo.TestDbo1);
115
+                Assert.Null(e.Dbo.Parent);
116
+                Assert.Null(e.Dbo.TestDbo1);
120 117
             }
121 118
         }
122 119
     }

+ 2
- 2
Luticate2.Auth.Tests/Business/ObjectConverter/Objects.cs Ver fichero

@@ -20,7 +20,7 @@ namespace Luticate2.Auth.Tests.Business.ObjectConverter
20 20
 
21 21
         public IList<TestDbo2> TestDbo2s { get; set; }
22 22
 
23
-        public string ToString()
23
+        public override string ToString()
24 24
         {
25 25
             throw new NotImplementedException();
26 26
         }
@@ -86,7 +86,7 @@ namespace Luticate2.Auth.Tests.Business.ObjectConverter
86 86
             AddMemberConverter(x => x.NameVirtual, y => y.name + " " + y.name);
87 87
             AddMemberConverter(x => x.TestDbo1, y => y.test_model1);
88 88
             AddMemberConverter(x => x.Parent, y => y.parent);
89
-            AddMemberConverter((LambdaExpression) (Expression<Func<TestDbo2, TestDbo1>>) (x => x.Unused), (Expression<Func<TestModel2, TestModel1>>) (y => null));
89
+            AddNullMemberConverter<TestDbo1>(x => x.Unused);
90 90
         }
91 91
     }
92 92
 }

+ 5
- 5
Luticate2.Auth/Auth/Business/LuGroupsBusiness.cs Ver fichero

@@ -43,12 +43,13 @@ namespace Luticate2.Auth.Auth.Business
43 43
             {
44 44
                 foreach (var dbo in dbos)
45 45
                 {
46
-                    var model = new LuGroups();
47
-                    var addResult = ConvertDboToModel(partialInput, dbo, model);
46
+                    var addResult = ConvertDboToModel(partialInput, dbo);
48 47
                     if (!addResult)
49 48
                     {
50 49
                         return addResult.To<bool>();
51 50
                     }
51
+
52
+                    var model = addResult.Data;
52 53
                     model.IdNavigation = new LuObjectsMetadata();
53 54
                     set.Add(model);
54 55
                     addedModels.Add(model);
@@ -68,13 +69,12 @@ namespace Luticate2.Auth.Auth.Business
68 69
 
69 70
             foreach (var addedModel in addedModels)
70 71
             {
71
-                var addedDbo = new LuGroupDbo();
72
-                var convertResult = ConvertModelToDbo(partialResponse, addedModel, addedDbo);
72
+                var convertResult = ConvertModelToDbo(partialResponse, addedModel);
73 73
                 if (!convertResult)
74 74
                 {
75 75
                     return convertResult.To<IList<LuGroupDbo>>();
76 76
                 }
77
-                addedDbos.Add(addedDbo);
77
+                addedDbos.Add(convertResult.Data);
78 78
             }
79 79
 
80 80
             return LuResult<IList<LuGroupDbo>>.Ok(addedDbos);

+ 0
- 27
Luticate2.Auth/Auth/Business/PartialObjectCopier/LuPOCGroupsToDbo.cs Ver fichero

@@ -1,27 +0,0 @@
1
-using System;
2
-using Luticate2.Auth.Auth.DataAccess.Models;
3
-using Luticate2.Auth.Auth.Dbo;
4
-using Luticate2.Auth.Utils.Business.PartialObjectCopier;
5
-using Luticate2.Auth.Utils.Dbo.Fields;
6
-using Luticate2.Auth.Utils.Dbo.PartialObjectCopier;
7
-using Luticate2.Auth.Utils.Dbo.Result;
8
-
9
-namespace Luticate2.Auth.Auth.Business.PartialObjectCopier
10
-{
11
-    public class LuPOCGroupsToDbo : LuPartialObjectCopier<LuGroups, LuGroupDbo>
12
-    {
13
-        public LuPOCGroupsToDbo(IServiceProvider serviceProvider) : base(serviceProvider)
14
-        {
15
-        }
16
-
17
-        public override LuResult<LuGroupDbo> Copy(LuFieldDbo path, LuPartialFieldsDbo fields, LuGroups modelFrom,
18
-            LuGroupDbo dboTo, LuPartialObjectCopierOptions options)
19
-        {
20
-            MayCopy(path, fields, dboTo, dbo => dbo.Id, () => modelFrom.Id);
21
-            MayCopySubProperty(path, fields, modelFrom, dboTo, x => x.IdNavigation, x => x.Metadata, options);
22
-            MayCopy(path, fields, dboTo, dbo => dbo.Name, () => modelFrom.Name);
23
-
24
-            return LuResult<LuGroupDbo>.Ok(dboTo);
25
-        }
26
-    }
27
-}

+ 0
- 26
Luticate2.Auth/Auth/Business/PartialObjectCopier/LuPOCGroupsToModel.cs Ver fichero

@@ -1,26 +0,0 @@
1
-using System;
2
-using Luticate2.Auth.Auth.DataAccess.Models;
3
-using Luticate2.Auth.Auth.Dbo;
4
-using Luticate2.Auth.Utils.Business.PartialObjectCopier;
5
-using Luticate2.Auth.Utils.Dbo.Fields;
6
-using Luticate2.Auth.Utils.Dbo.PartialObjectCopier;
7
-using Luticate2.Auth.Utils.Dbo.Result;
8
-
9
-namespace Luticate2.Auth.Auth.Business.PartialObjectCopier
10
-{
11
-    public class LuPOCGroupsToModel : LuPartialObjectCopier<LuGroupDbo, LuGroups>
12
-    {
13
-        public LuPOCGroupsToModel(IServiceProvider serviceProvider) : base(serviceProvider)
14
-        {
15
-        }
16
-
17
-        public override LuResult<LuGroups> Copy(LuFieldDbo path, LuPartialFieldsDbo fields, LuGroupDbo dboFrom, LuGroups modelTo,
18
-            LuPartialObjectCopierOptions options)
19
-        {
20
-            MayCopy(path, fields, modelTo, model => model.Id, () => dboFrom.Id);
21
-            MayCopy(path, fields, modelTo, model => model.Name, () => dboFrom.Name);
22
-
23
-            return LuResult<LuGroups>.Ok(modelTo);
24
-        }
25
-    }
26
-}

+ 0
- 27
Luticate2.Auth/Auth/Business/PartialObjectCopier/LuPOCObjectsMetadataToDbo.cs Ver fichero

@@ -1,27 +0,0 @@
1
-using System;
2
-using Luticate2.Auth.Auth.DataAccess.Models;
3
-using Luticate2.Auth.Auth.Dbo;
4
-using Luticate2.Auth.Utils.Business.PartialObjectCopier;
5
-using Luticate2.Auth.Utils.Dbo.Fields;
6
-using Luticate2.Auth.Utils.Dbo.PartialObjectCopier;
7
-using Luticate2.Auth.Utils.Dbo.Result;
8
-
9
-namespace Luticate2.Auth.Auth.Business.PartialObjectCopier
10
-{
11
-    public class LuPOCObjectsMetadataToDbo : LuPartialObjectCopier<LuObjectsMetadata, LuObjectsMetadataDbo>
12
-    {
13
-        public LuPOCObjectsMetadataToDbo(IServiceProvider serviceProvider) : base(serviceProvider)
14
-        {
15
-        }
16
-
17
-        public override LuResult<LuObjectsMetadataDbo> Copy(LuFieldDbo path, LuPartialFieldsDbo fields, LuObjectsMetadata modelFrom, LuObjectsMetadataDbo dboTo,
18
-            LuPartialObjectCopierOptions options)
19
-        {
20
-            MayCopy(path, fields, dboTo, dbo => dbo.Id, () => modelFrom.Id);
21
-            MayCopy(path, fields, dboTo, dbo => dbo.CreatedAt, () => modelFrom.CreatedAt);
22
-            MayCopy(path, fields, dboTo, dbo => dbo.UpdatedAt, () => modelFrom.UpdatedAt);
23
-
24
-            return LuResult<LuObjectsMetadataDbo>.Ok(dboTo);
25
-        }
26
-    }
27
-}

+ 22
- 16
Luticate2.Auth/Utils/Business/Crud/LuEfCrudBusiness.cs Ver fichero

@@ -7,7 +7,6 @@ using Luticate2.Auth.Utils.Business.ExpressionConverter;
7 7
 using Luticate2.Auth.Utils.Dbo;
8 8
 using Luticate2.Auth.Utils.Dbo.Fields;
9 9
 using Luticate2.Auth.Utils.Dbo.Pagination;
10
-using Luticate2.Auth.Utils.Dbo.PartialObjectCopier;
11 10
 using Luticate2.Auth.Utils.Dbo.Result;
12 11
 using Luticate2.Auth.Utils.Interfaces;
13 12
 using Microsoft.EntityFrameworkCore;
@@ -18,7 +17,7 @@ namespace Luticate2.Auth.Utils.Business.Crud
18 17
     public class LuEfCrudBusiness<TDbo, TModel, TDbContext> : ILuCrud<TDbo>
19 18
         where TModel : class
20 19
         where TDbContext : DbContext
21
-        where TDbo : new()
20
+        where TDbo : class, new()
22 21
     {
23 22
         protected IServiceProvider ServiceProvider { get; }
24 23
 
@@ -27,26 +26,33 @@ namespace Luticate2.Auth.Utils.Business.Crud
27 26
             ServiceProvider = serviceProvider;
28 27
         }
29 28
 
30
-        protected virtual LuResult<TModel> ConvertDboToModel(LuPartialFieldsDbo partialInput, TDbo dbo, TModel model)
29
+        protected virtual LuConvertersOptions GetOptions()
31 30
         {
32
-            var copier = ServiceProvider.GetService<ILuPartialObjectCopier<TDbo, TModel>>();
31
+            return new LuConvertersOptions();// TODO
32
+        }
33
+
34
+        protected virtual LuResult<TModel> ConvertDboToModel(LuPartialFieldsDbo partialInput, TDbo dbo)
35
+        {
36
+            var copier = ServiceProvider.GetService<ILuObjectConverter<TDbo, TModel>>();
33 37
             if (copier == null)
34 38
             {
35
-                return LuResult<TModel>.Error(LuStatus.InternalError.ToInt(), $"Could not get service: ILuPartialObjectCopier<{typeof(TDbo).Name}, {typeof(TModel).Name}>");
39
+                return LuResult<TModel>.Error(LuStatus.InternalError.ToInt(),
40
+                    $"Could not get service: {nameof(ILuObjectConverter)}<{typeof(TDbo).Name}, {typeof(TModel).Name}>");
36 41
             }
37
-            var result = copier.Copy(partialInput, dbo, model, new LuPartialObjectCopierOptions());
38
-            return result;
42
+            var result = copier.Convert(dbo, partialInput, GetOptions());
43
+            return result.Select(o => o as TModel);
39 44
         }
40 45
 
41
-        protected virtual LuResult<TDbo> ConvertModelToDbo(LuPartialFieldsDbo partialResponse, TModel model, TDbo dbo)
46
+        protected virtual LuResult<TDbo> ConvertModelToDbo(LuPartialFieldsDbo partialResponse, TModel model)
42 47
         {
43
-            var copier = ServiceProvider.GetService<ILuPartialObjectCopier<TModel, TDbo>>();
48
+            var copier = ServiceProvider.GetService<ILuObjectConverter<TModel, TDbo>>();
44 49
             if (copier == null)
45 50
             {
46
-                return LuResult<TDbo>.Error(LuStatus.InternalError.ToInt(), $"Could not get service: ILuPartialObjectCopier<{typeof(TModel).Name}, {typeof(TDbo).Name}>");
51
+                return LuResult<TDbo>.Error(LuStatus.InternalError.ToInt(),
52
+                    $"Could not get service: {nameof(ILuObjectConverter)}<{typeof(TModel).Name}, {typeof(TDbo).Name}>");
47 53
             }
48
-            var result = copier.Copy(partialResponse, model, dbo, new LuPartialObjectCopierOptions());
49
-            return result;
54
+            var result = copier.Convert(model, partialResponse, GetOptions());
55
+            return result.Select(o => o as TDbo);
50 56
         }
51 57
 
52 58
         protected virtual LuResult<T> HandleError<T>(Exception e)
@@ -82,7 +88,8 @@ namespace Luticate2.Auth.Utils.Business.Crud
82 88
             var options = new LuConvertersOptions
83 89
             {
84 90
                 Parameters = new Dictionary<ParameterExpression, Expression>(), // TODO
85
-                TypeConverter = null // TODO
91
+                TypeConverter = null, // TODO
92
+                Allocator = null // TODO
86 93
             };
87 94
             var converter = new LuExpressionConverterVisitor(options, ServiceProvider);
88 95
             var lamdbaModel = converter.Visit(lamdbaDbo) as Expression<Func<TModel, bool>>;// TODO Handle errors
@@ -174,9 +181,8 @@ namespace Luticate2.Auth.Utils.Business.Crud
174 181
 
175 182
                 var data = paginated.AsEnumerable().Select(model =>
176 183
                     {
177
-                        var dbo = new TDbo();
178
-                        ConvertModelToDbo(partialResponse, model, dbo);
179
-                        return dbo;
184
+                        var convertResult = ConvertModelToDbo(partialResponse, model); // TODO Handle error
185
+                        return convertResult.Data;
180 186
                     }).ToList();
181 187
 
182 188
                 return LuResult<LuPaginatedDbo<TDbo>>.Ok(new LuPaginatedDbo<TDbo>

+ 10
- 13
Luticate2.Auth/Utils/Business/ObjectConverter/LuObjectConverterPoco.cs Ver fichero

@@ -36,22 +36,19 @@ namespace Luticate2.Auth.Utils.Business.ObjectConverter
36 36
                 var srcPropExpression = descriptor.GetMemberValueExpression(memberInfo, options);
37 37
                 var srcPropDelegate = srcPropExpression.Compile();
38 38
                 var srcProp = srcPropDelegate.DynamicInvoke(srcObj);
39
-                object dstProp = null;
40
-                if (srcProp != null)
41
-                {
42
-                    var srcType = srcProp.GetType();
43
-
44
-                    // TODO Handle objectConverter == null
45
-                    var objectConverter = LuObjectConverterUtils.GetObjectConverter(ServiceProvider, srcType, memberInfo.GetUnderlyingType());
46
-                    var dstPropResult = objectConverter.Convert(srcProp, fields, options);
47
-                    if (!dstPropResult)
48
-                    {
49
-                        return dstPropResult;
50
-                    }
39
+                var srcType = srcProp != null ? srcProp.GetType() : srcPropExpression.ReturnType;
40
+                var dstType = memberInfo.GetUnderlyingType();
51 41
 
52
-                    dstProp = dstPropResult.Data;
42
+                // TODO Handle objectConverter == null
43
+                var objectConverter = LuObjectConverterUtils.GetObjectConverter(ServiceProvider, srcType, dstType);
44
+                var dstPropResult = objectConverter.Convert(srcProp, fields, options);
45
+                if (!dstPropResult)
46
+                {
47
+                    return dstPropResult;
53 48
                 }
54 49
 
50
+                var dstProp = dstPropResult.Data;
51
+
55 52
                 var result = LuExpressionUtils.SetValueFromMember(memberInfo, dstObj, dstProp);
56 53
                 if (!result)
57 54
                 {

+ 5
- 2
Luticate2.Auth/Utils/Business/ObjectConverterDescriptor/LuObjectConverterDescriptor.cs Ver fichero

@@ -123,9 +123,12 @@ namespace Luticate2.Auth.Utils.Business.ObjectConverterDescriptor
123 123
             AddMemberConverter((LambdaExpression) memberFrom, valueExpression);
124 124
         }
125 125
 
126
-        protected void AddNullMemberConverter(Expression<Func<TTypeFrom, object>> memberFrom)
126
+        protected void AddNullMemberConverter<TType>(Expression<Func<TTypeFrom, object>> memberFrom)
127 127
         {
128
-            AddMemberConverter(memberFrom, to => null);
128
+            var nullExp = Expression.Constant(null, typeof(TType));
129
+            var param = Expression.Parameter(typeof(TTypeTo));
130
+            var lambda = Expression.Lambda(nullExp, param);
131
+            AddMemberConverter(memberFrom, lambda);
129 132
         }
130 133
     }
131 134
 }

+ 0
- 115
Luticate2.Auth/Utils/Business/PartialObjectCopier/LuPartialObjectCopier.cs Ver fichero

@@ -1,115 +0,0 @@
1
-using System;
2
-using System.Collections.Generic;
3
-using System.Linq.Expressions;
4
-using Luticate2.Auth.Utils.Business.Fields;
5
-using Luticate2.Auth.Utils.Business.Utils;
6
-using Luticate2.Auth.Utils.Dbo;
7
-using Luticate2.Auth.Utils.Dbo.Fields;
8
-using Luticate2.Auth.Utils.Dbo.PartialObjectCopier;
9
-using Luticate2.Auth.Utils.Dbo.Result;
10
-using Luticate2.Auth.Utils.Interfaces;
11
-using Microsoft.Extensions.DependencyInjection;
12
-
13
-namespace Luticate2.Auth.Utils.Business.PartialObjectCopier
14
-{
15
-    public abstract class LuPartialObjectCopier<TTypeFrom, TTypeTo> : ILuPartialObjectCopier<TTypeFrom, TTypeTo>
16
-    {
17
-        protected IServiceProvider ServiceProvider { get; }
18
-
19
-        protected LuPartialObjectCopier(IServiceProvider serviceProvider)
20
-        {
21
-            ServiceProvider = serviceProvider;
22
-        }
23
-
24
-        protected LuResult<TPropertyTo> MayCopySubProperty<TPropertyFrom, TPropertyTo>(LuFieldDbo path,
25
-            LuPartialFieldsDbo fields, TTypeFrom modelFrom, TTypeTo dboTo,
26
-            Expression<Func<TTypeFrom, TPropertyFrom>> propFrom, Expression<Func<TTypeTo, TPropertyTo>> propTo,
27
-            LuPartialObjectCopierOptions options) where TPropertyTo : new()
28
-        {
29
-            var member = LuExpressionUtils.GetSingleMemberFromExpression(propTo);
30
-            var subpath = LuFieldDbo.Make(path).Add(member.Name);
31
-            if (fields.Fields.IsIncluded(subpath))
32
-            {
33
-                var propToValue = LuExpressionUtils.GetValueFromExpression(propTo, dboTo);
34
-                if (!propToValue)
35
-                {
36
-                    return propToValue.To<TPropertyTo>();
37
-                }
38
-                if (propToValue.Data == null)
39
-                {
40
-                    propToValue.Data = new TPropertyTo();
41
-                    var res = LuExpressionUtils.SetValueFromExpression(propTo, dboTo, propToValue.Data);
42
-                    if (!res)
43
-                    {
44
-                        return res.To<TPropertyTo>();
45
-                    }
46
-                }
47
-                var propFromValue = LuExpressionUtils.GetValueFromExpression(propFrom, modelFrom);
48
-                if (!propFromValue)
49
-                {
50
-                    return propFromValue.To<TPropertyTo>();
51
-                }
52
-
53
-                var service = ServiceProvider.GetService<ILuPartialObjectCopier<TPropertyFrom, TPropertyTo>>();
54
-                var result = service.Copy(subpath, fields, propFromValue.Data, propToValue.Data, options);
55
-                return result;
56
-            }
57
-            return LuResult<TPropertyTo>.Ok(default(TPropertyTo));
58
-        }
59
-
60
-        protected LuResult<IList<TPropertyTo>> MayCopySubPropertyList<TPropertyFrom, TPropertyTo>(
61
-            LuFieldDbo path, LuPartialFieldsDbo fields, IEnumerable<TPropertyFrom> modelFrom,
62
-            TTypeTo dboTo, Expression<Func<TTypeTo, IEnumerable<TPropertyTo>>> propTo,
63
-            LuPartialObjectCopierOptions options) where TPropertyTo : new()
64
-        {
65
-            var member = LuExpressionUtils.GetSingleMemberFromExpression(propTo);
66
-            var subpath = LuFieldDbo.Make(path).Add(member.Name);
67
-            if (fields.Fields.IsIncluded(subpath))
68
-            {
69
-                var list = new List<TPropertyTo>();
70
-                var res = LuExpressionUtils.SetValueFromExpression(propTo, dboTo, list);
71
-                if (!res)
72
-                {
73
-                    return res.To<IList<TPropertyTo>>();
74
-                }
75
-
76
-                foreach (var subDboFrom in modelFrom)
77
-                {
78
-                    var subDboTo = new TPropertyTo();
79
-
80
-                    var service = ServiceProvider.GetService<ILuPartialObjectCopier<TPropertyFrom, TPropertyTo>>();
81
-                    var result = service.Copy(subpath, fields, subDboFrom, subDboTo, options);
82
-
83
-                    list.Add(subDboTo);
84
-                }
85
-            }
86
-            return LuResult<IList<TPropertyTo>>.Ok(null);
87
-        }
88
-
89
-        protected LuResult<TProperty> MayCopy<TProperty, TTypeTo2>(LuFieldDbo path, LuPartialFieldsDbo fields,
90
-            TTypeTo2 dboTo, Expression<Func<TTypeTo2, TProperty>> property, Func<TProperty> getValue)
91
-        {
92
-            var memberInfo = LuExpressionUtils.GetSingleMemberFromExpression(property);
93
-            if (memberInfo != null)
94
-            {
95
-                if (fields.Fields.IsIncluded(LuFieldDbo.Make(path).Add(memberInfo.Name)))
96
-                {
97
-                    var value = getValue();
98
-                    var result = LuExpressionUtils.SetValueFromExpression(property, dboTo, value);
99
-                    return result;
100
-                }
101
-
102
-                return LuResult<TProperty>.Ok(default(TProperty));
103
-            }
104
-
105
-            return LuResult<TProperty>.Error(LuStatus.InternalError.ToInt(), "Bad member expression");
106
-        }
107
-
108
-        public abstract LuResult<TTypeTo> Copy(LuFieldDbo path, LuPartialFieldsDbo fields, TTypeFrom dboFrom, TTypeTo dboTo, LuPartialObjectCopierOptions options);
109
-
110
-        public LuResult<TTypeTo> Copy(LuPartialFieldsDbo fields, TTypeFrom dboFrom, TTypeTo dboTo, LuPartialObjectCopierOptions options)
111
-        {
112
-            return Copy(new LuFieldDbo(), fields, dboFrom, dboTo, options);
113
-        }
114
-    }
115
-}

+ 0
- 11
Luticate2.Auth/Utils/Business/PartialObjectCopier/LuPartialObjectCopierExtensions.cs Ver fichero

@@ -1,11 +0,0 @@
1
-namespace Luticate2.Auth.Utils.Business.PartialObjectCopier
2
-{
3
-    public static class LuPartialObjectCopierExtensions
4
-    {
5
-//        public static LuResult<TTypeTo> CopyList<TTypeFrom, TTypeTo>(this ILuPartialObjectCopier<TTypeFrom, TTypeTo> copier,
6
-//            ILuPartialFields fields, TTypeFrom dboFrom, TTypeTo dboTo)
7
-//        {
8
-//
9
-//        }
10
-    }
11
-}

+ 0
- 8
Luticate2.Auth/Utils/Dbo/Fields/LuFieldDbo.cs Ver fichero

@@ -33,14 +33,6 @@ namespace Luticate2.Auth.Utils.Dbo.Fields
33 33
             var partialFieldpath = new LuFieldDbo();
34 34
             return partialFieldpath.Add(property);
35 35
         }
36
-
37
-        public LuFieldDbo Copy()
38
-        {
39
-            return new LuFieldDbo
40
-            {
41
-                Parts = Parts.ToList()
42
-            };
43
-        }
44 36
         
45 37
         public override string ToString()
46 38
         {

+ 11
- 1
Luticate2.Auth/Utils/Dbo/LuDboExtensions.cs Ver fichero

@@ -1,4 +1,5 @@
1
-using Luticate2.Auth.Utils.Dbo.Result;
1
+using System;
2
+using Luticate2.Auth.Utils.Dbo.Result;
2 3
 
3 4
 namespace Luticate2.Auth.Utils.Dbo
4 5
 {
@@ -8,5 +9,14 @@ namespace Luticate2.Auth.Utils.Dbo
8 9
         {
9 10
             return (int) status;
10 11
         }
12
+
13
+        public static LuResult<TTypeTo> Select<TTypeFrom, TTypeTo>(this LuResult<TTypeFrom> result, Func<TTypeFrom, TTypeTo> convert)
14
+        {
15
+            if (!result)
16
+            {
17
+                return result.To<TTypeTo>();
18
+            }
19
+            return LuResult<TTypeTo>.Ok(convert(result.Data));
20
+        }
11 21
     }
12 22
 }

+ 0
- 13
Luticate2.Auth/Utils/Interfaces/ILuPartialObjectCopier.cs Ver fichero

@@ -1,13 +0,0 @@
1
-using Luticate2.Auth.Utils.Dbo.Fields;
2
-using Luticate2.Auth.Utils.Dbo.PartialObjectCopier;
3
-using Luticate2.Auth.Utils.Dbo.Result;
4
-
5
-namespace Luticate2.Auth.Utils.Interfaces
6
-{
7
-    public interface ILuPartialObjectCopier<TTypeFrom, TTypeTo>
8
-    {
9
-        LuResult<TTypeTo> Copy(LuFieldDbo path, LuPartialFieldsDbo fields, TTypeFrom dboFrom, TTypeTo dboTo, LuPartialObjectCopierOptions options);
10
-
11
-        LuResult<TTypeTo> Copy(LuPartialFieldsDbo fields, TTypeFrom dboFrom, TTypeTo dboTo, LuPartialObjectCopierOptions options);
12
-    }
13
-}

Loading…
Cancelar
Guardar