Skip to content

Commit 2bf64c9

Browse files
committed
2 parents 2c4745f + fa1112b commit 2bf64c9

File tree

8 files changed

+115
-4
lines changed

8 files changed

+115
-4
lines changed

Cinotam.AbpModuleZero.Core/Cinotam.AbpModuleZero.Core.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
<Compile Include="LocalizableContent\Caching\AbpCinotamLocalizableContentCacheItem.cs" />
145145
<Compile Include="LocalizableContent\Caching\ILocalizableContentCache.cs" />
146146
<Compile Include="LocalizableContent\Caching\LocalizableContentCache.cs" />
147+
<Compile Include="LocalizableContent\Contracts\IsSharedProperty.cs" />
147148
<Compile Include="LocalizableContent\Contracts\LocalizableContent.cs" />
148149
<Compile Include="LocalizableContent\Contracts\ILocalizableContent.cs" />
149150
<Compile Include="LocalizableContent\Entities\AbpCinotamLocalizableContent.cs" />
@@ -179,6 +180,10 @@
179180
<EmbeddedResource Include="Localization\SourceZero\AbpModuleZero.xml" />
180181
</ItemGroup>
181182
<ItemGroup>
183+
<ProjectReference Include="..\Cinotam.AbpModuleZero.Tools\Cinotam.AbpModuleZero.Tools.csproj">
184+
<Project>{9AB7EE8A-5411-4D24-AE46-158065006F00}</Project>
185+
<Name>Cinotam.AbpModuleZero.Tools</Name>
186+
</ProjectReference>
182187
<ProjectReference Include="..\Cinotam.FileManager.Contracts\Cinotam.FileManager.Contracts.csproj">
183188
<Project>{B1AD0F0D-EC22-4426-88D9-60C2F19E1DAE}</Project>
184189
<Name>Cinotam.FileManager.Contracts</Name>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace Cinotam.AbpModuleZero.LocalizableContent.Contracts
4+
{
5+
public class IsSharedProperty : Attribute
6+
{
7+
}
8+
}

Cinotam.AbpModuleZero.Core/LocalizableContent/Contracts/LocalizableContent.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,23 @@ public LocalizableContent(T entity, TContentType contentType, string lang)
1919
SerializeContent(contentType);
2020
}
2121

22+
//public string SerializeContent(TContentType obj)
23+
//{
24+
// dynamic objToSerialize = new ExpandoObject();
25+
// objToSerialize.Content = obj;
26+
// var shareableProps = ClassCheckers.HasAttribute(typeof(IsSharedProperty), obj.GetType().GetProperties(), obj);
27+
// objToSerialize.SharedProps = shareableProps;
28+
// var json = new JavaScriptSerializer().Serialize(objToSerialize);
29+
// Properties = json;
30+
// return json;
31+
//}
2232
public string SerializeContent(TContentType obj)
2333
{
2434
var json = new JavaScriptSerializer().Serialize(obj);
2535
Properties = json;
2636
return json;
2737
}
2838

29-
3039
public static TContentType DeserializeContent(string json)
3140
{
3241
try

Cinotam.AbpModuleZero.Core/LocalizableContent/ILocalizableContentManager.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ public interface ILocalizableContentManager<T, TContentType> : IDomainService wh
1212
{
1313

1414
Task<LocalizationContentResult> CreateLocalizationContent(ILocalizableContent<T, TContentType> input, bool overwrite = false, int? tenantId = null);
15-
Task<Entities.AbpCinotamLocalizableContent> GetLocalizableContent(T entity, string lang);
16-
Task<Entities.AbpCinotamLocalizableContent> GetLocalizableContent(T entity, string lang, Type dtoType);
17-
Task<IEnumerable<Entities.AbpCinotamLocalizableContent>> GetLocalizableContent(T entity);
15+
Task<AbpCinotamLocalizableContent> GetLocalizableContent(T entity, string lang);
16+
Task<AbpCinotamLocalizableContent> GetLocalizableContent(T entity, string lang, Type dtoType);
17+
Task<IEnumerable<AbpCinotamLocalizableContent>> GetLocalizableContent(T entity);
1818
Task DeleteContent(AbpCinotamLocalizableContent content);
19+
Task<IEnumerable<AbpCinotamLocalizableContent>> SearchAsync(string[] lookInProperties, string search);
20+
Task<object> GetContentTypeAsync(T entity, string lang);
1921
}
2022
}

Cinotam.AbpModuleZero.Core/LocalizableContent/LocalizableContentManager.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Cinotam.AbpModuleZero.LocalizableContent.Entities;
44
using Cinotam.AbpModuleZero.LocalizableContent.Helpers;
55
using Cinotam.AbpModuleZero.LocalizableContent.Store;
6+
using Cinotam.AbpModuleZero.Tools.Extensions;
67
using System;
78
using System.Collections.Generic;
89
using System.Linq;
@@ -88,5 +89,50 @@ public Task DeleteContent(AbpCinotamLocalizableContent content)
8889
{
8990
return _localizationContentStore.RemoveContent(content);
9091
}
92+
93+
public async Task<IEnumerable<AbpCinotamLocalizableContent>> SearchAsync(string[] lookInProperties, string search)
94+
{
95+
var elements = await Task.FromResult(_localizationContentStore.LocalizableContents);
96+
var result = new List<AbpCinotamLocalizableContent>();
97+
foreach (var abpCinotamLocalizableContent in elements)
98+
{
99+
var deserealized = LocalizableContent<T, TContentType>.DeserializeContent(abpCinotamLocalizableContent.Properties);
100+
101+
result.AddRange(from lookInProperty
102+
in lookInProperties
103+
where deserealized.HasProperty(lookInProperty)
104+
select deserealized.GetType().GetProperty(lookInProperty).GetValue(deserealized)
105+
into propertyValue
106+
where propertyValue != null
107+
where propertyValue.ToString().Contains(search)
108+
select abpCinotamLocalizableContent);
109+
110+
111+
/* Or
112+
113+
foreach (var lookInProperty in lookInProperties)
114+
{
115+
if (!ClassCheckers.HasProperty(lookInProperty, deserealized)) continue;
116+
var propertyValue = deserealized.GetType().GetProperty(lookInProperty).GetValue(deserealized);
117+
118+
if(propertyValue == null) continue;
119+
if (propertyValue.ToString().Contains(search))
120+
{
121+
result.Add(abpCinotamLocalizableContent);
122+
}
123+
}
124+
125+
*/
126+
127+
}
128+
return result;
129+
}
130+
131+
public async Task<object> GetContentTypeAsync(T entity, string lang)
132+
{
133+
var localizableContent = await GetLocalizableContent(entity, lang);
134+
return LocalizableContent<T, TContentType>.DeserializeContent(localizableContent.Properties);
135+
}
136+
91137
}
92138
}

Cinotam.AbpModuleZero.Tools/Cinotam.AbpModuleZero.Tools.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<Compile Include="DatatablesJsModels\GenericTypes\ReturnModel.cs" />
4747
<Compile Include="DatatablesJsModels\ReflectionHelpers\InputBuilder.cs" />
4848
<Compile Include="DatatablesJsModels\ReflectionHelpers\QueryableHelper.cs" />
49+
<Compile Include="Extensions\ClassCheckers.cs" />
4950
<Compile Include="Extensions\ServerHelpers.cs" />
5051
<Compile Include="Extensions\Slugger.cs" />
5152
<Compile Include="Properties\AssemblyInfo.cs" />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
6+
namespace Cinotam.AbpModuleZero.Tools.Extensions
7+
{
8+
public static class ClassCheckers
9+
{
10+
public static IDictionary<string, string> HasAttribute(Type attribute, IEnumerable<PropertyInfo> properties, object obj)
11+
{
12+
var dic = new Dictionary<string, string>();
13+
foreach (var propertyInfo in properties)
14+
{
15+
16+
var equals = propertyInfo.GetCustomAttributes(attribute, false).Length > 0;
17+
if (equals)
18+
{
19+
dic.Add(propertyInfo.Name, propertyInfo.GetValue(obj).ToString());
20+
}
21+
}
22+
return dic;
23+
}
24+
public static bool HasProperty(this object obj, string propertyName)
25+
{
26+
return obj.GetType().GetProperties().FirstOrDefault(a => a.Name == propertyName) != null;
27+
}
28+
}
29+
}

Cinotam.SimplePost.Application/Posts/Dto/NewPostInput.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Abp.Application.Services.Dto;
2+
using Cinotam.AbpModuleZero.LocalizableContent.Contracts;
23

34
namespace Cinotam.SimplePost.Application.Posts.Dto
45
{
@@ -14,5 +15,15 @@ public class Content : EntityDto
1415
public string ContentString { get; set; }
1516
public string Lang { get; set; }
1617

18+
[IsSharedProperty]
19+
public string SharedString { get; set; } = "Shared string";
1720
}
21+
22+
23+
24+
//public class LocalizableContentDto<T> where T : class
25+
//{
26+
// public T Content { get; set; }
27+
// public Dictionary<string, string> SharedProps { get; set; }
28+
//}
1829
}

0 commit comments

Comments
 (0)