Browse Source

Merge branch 'master' into feature-proposal

pull/285/head
Sebastian 8 years ago
parent
commit
bae64ac93d
  1. 2
      src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs
  2. 2
      src/Squidex.Domain.Users/IUserEvents.cs
  3. 4
      src/Squidex.Domain.Users/NoopUserEvents.cs
  4. 8
      src/Squidex.Infrastructure/Orleans/J.cs
  5. 17
      src/Squidex.Infrastructure/Orleans/JExtensions.cs
  6. 23
      src/Squidex.Infrastructure/Orleans/J{T}.cs
  7. 2
      src/Squidex/Areas/IdentityServer/Controllers/Account/AccountController.cs
  8. 11
      src/Squidex/Config/Domain/SerializationServices.cs
  9. 3
      src/Squidex/Config/Domain/StoreServices.cs
  10. 5
      src/Squidex/Config/Orleans/ClientWrapper.cs
  11. 2
      src/Squidex/Config/Orleans/SiloWrapper.cs
  12. 4
      src/Squidex/app/framework/angular/forms/jscript-editor.component.ts
  13. 2
      src/Squidex/app/framework/angular/forms/transform-input.directive.ts
  14. 5
      src/Squidex/app/shared/components/markdown-editor.component.ts
  15. 5
      src/Squidex/app/shared/components/rich-editor.component.ts

2
src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs

@ -130,7 +130,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
await Collection.Find(x => x.SchemaIdId == schemaId && ids.Contains(x.Id) && x.IsDeleted == false).Only(x => x.Id) await Collection.Find(x => x.SchemaIdId == schemaId && ids.Contains(x.Id) && x.IsDeleted == false).Only(x => x.Id)
.ToListAsync(); .ToListAsync();
return ids.Except(contentEntities.Select(x => Guid.Parse(x["id"].AsString))).ToList(); return ids.Except(contentEntities.Select(x => Guid.Parse(x["_id"].AsString))).ToList();
} }
public async Task<IContentEntity> FindContentAsync(IAppEntity app, ISchemaEntity schema, Guid id) public async Task<IContentEntity> FindContentAsync(IAppEntity app, ISchemaEntity schema, Guid id)

2
src/Squidex.Domain.Users/IUserEvents.cs

@ -12,5 +12,7 @@ namespace Squidex.Domain.Users
public interface IUserEvents public interface IUserEvents
{ {
void OnUserRegistered(IUser user); void OnUserRegistered(IUser user);
void OnConsentGiven(IUser user);
} }
} }

4
src/Squidex.Domain.Users/NoopUserEvents.cs

@ -11,6 +11,10 @@ namespace Squidex.Domain.Users
{ {
public sealed class NoopUserEvents : IUserEvents public sealed class NoopUserEvents : IUserEvents
{ {
public void OnConsentGiven(IUser user)
{
}
public void OnUserRegistered(IUser user) public void OnUserRegistered(IUser user)
{ {
} }

8
src/Squidex.Infrastructure/Orleans/J.cs

@ -6,15 +6,15 @@
// ========================================================================== // ==========================================================================
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json;
#pragma warning disable SA1401 // Fields must be private
namespace Squidex.Infrastructure.Orleans namespace Squidex.Infrastructure.Orleans
{ {
public static class J public static class J
{ {
public static JsonSerializer Serializer = new JsonSerializer(); public static J<T> AsJ<T>(this T value)
{
return new J<T>(value);
}
public static J<T> Of<T>(T value) public static J<T> Of<T>(T value)
{ {

17
src/Squidex.Infrastructure/Orleans/JExtensions.cs

@ -1,17 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Infrastructure.Orleans
{
public static class JExtensions
{
public static J<T> AsJ<T>(this T value)
{
return new J<T>(value);
}
}
}

23
src/Squidex.Infrastructure/Orleans/J{T}.cs

@ -8,6 +8,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json; using Newtonsoft.Json;
using Orleans.CodeGeneration; using Orleans.CodeGeneration;
using Orleans.Serialization; using Orleans.Serialization;
@ -17,6 +18,8 @@ namespace Squidex.Infrastructure.Orleans
{ {
public struct J<T> public struct J<T>
{ {
private static readonly JsonSerializer DefaultSerializer = JsonSerializer.CreateDefault();
public T Value { get; } public T Value { get; }
[JsonConstructor] [JsonConstructor]
@ -56,11 +59,13 @@ namespace Squidex.Infrastructure.Orleans
{ {
using (Profile.Method(nameof(J))) using (Profile.Method(nameof(J)))
{ {
var jsonSerializer = GetSerializer(context);
var stream = new MemoryStream(); var stream = new MemoryStream();
using (var writer = new JsonTextWriter(new StreamWriter(stream))) using (var writer = new JsonTextWriter(new StreamWriter(stream)))
{ {
J.Serializer.Serialize(writer, input); jsonSerializer.Serialize(writer, input);
writer.Flush(); writer.Flush();
} }
@ -77,6 +82,8 @@ namespace Squidex.Infrastructure.Orleans
{ {
using (Profile.Method(nameof(J))) using (Profile.Method(nameof(J)))
{ {
var jsonSerializer = GetSerializer(context);
var outLength = context.StreamReader.ReadInt(); var outLength = context.StreamReader.ReadInt();
var outBytes = context.StreamReader.ReadBytes(outLength); var outBytes = context.StreamReader.ReadBytes(outLength);
@ -84,9 +91,21 @@ namespace Squidex.Infrastructure.Orleans
using (var reader = new JsonTextReader(new StreamReader(stream))) using (var reader = new JsonTextReader(new StreamReader(stream)))
{ {
return J.Serializer.Deserialize(reader, expected); return jsonSerializer.Deserialize(reader, expected);
} }
} }
} }
private static JsonSerializer GetSerializer(ISerializerContext context)
{
try
{
return context?.ServiceProvider?.GetService<JsonSerializer>() ?? DefaultSerializer;
}
catch
{
return DefaultSerializer;
}
}
} }
} }

2
src/Squidex/Areas/IdentityServer/Controllers/Account/AccountController.cs

@ -123,6 +123,8 @@ namespace Squidex.Areas.IdentityServer.Controllers.Account
await userManager.UpdateAsync(user); await userManager.UpdateAsync(user);
userEvents.OnConsentGiven(user);
return RedirectToReturnUrl(returnUrl); return RedirectToReturnUrl(returnUrl);
} }

11
src/Squidex/Config/Domain/SerializationServices.cs

@ -20,7 +20,6 @@ using Squidex.Domain.Apps.Events;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Json; using Squidex.Infrastructure.Json;
using Squidex.Infrastructure.MongoDb;
namespace Squidex.Config.Domain namespace Squidex.Config.Domain
{ {
@ -74,16 +73,14 @@ namespace Squidex.Config.Domain
ConfigureJson(DefaultJsonSettings, TypeNameHandling.Auto); ConfigureJson(DefaultJsonSettings, TypeNameHandling.Auto);
DefaultJsonSerializer = JsonSerializer.Create(DefaultJsonSettings); DefaultJsonSerializer = JsonSerializer.Create(DefaultJsonSettings);
BsonJsonConvention.Register(DefaultJsonSerializer);
} }
public static IServiceCollection AddMySerializers(this IServiceCollection services) public static IServiceCollection AddMySerializers(this IServiceCollection services)
{ {
services.AddSingletonAs(t => FieldRegistry); services.AddSingleton(FieldRegistry);
services.AddSingletonAs(t => DefaultJsonSettings); services.AddSingleton(DefaultJsonSettings);
services.AddSingletonAs(t => DefaultJsonSerializer); services.AddSingleton(DefaultJsonSerializer);
services.AddSingletonAs(t => TypeNameRegistry); services.AddSingleton(TypeNameRegistry);
return services; return services;
} }

3
src/Squidex/Config/Domain/StoreServices.cs

@ -30,6 +30,7 @@ using Squidex.Domain.Users.MongoDb.Infrastructure;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Migrations; using Squidex.Infrastructure.Migrations;
using Squidex.Infrastructure.MongoDb;
using Squidex.Infrastructure.States; using Squidex.Infrastructure.States;
using Squidex.Infrastructure.UsageTracking; using Squidex.Infrastructure.UsageTracking;
using Squidex.Shared.Users; using Squidex.Shared.Users;
@ -44,6 +45,8 @@ namespace Squidex.Config.Domain
{ {
["MongoDB"] = () => ["MongoDB"] = () =>
{ {
BsonJsonConvention.Register(SerializationServices.DefaultJsonSerializer);
var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration"); var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration");
var mongoDatabaseName = config.GetRequiredValue("store:mongoDb:database"); var mongoDatabaseName = config.GetRequiredValue("store:mongoDb:database");
var mongoContentDatabaseName = config.GetOptionalValue("store:mongoDb:contentDatabase", mongoDatabaseName); var mongoContentDatabaseName = config.GetOptionalValue("store:mongoDb:contentDatabase", mongoDatabaseName);

5
src/Squidex/Config/Orleans/ClientWrapper.cs

@ -10,6 +10,7 @@ using System.Net;
using Orleans; using Orleans;
using Orleans.Configuration; using Orleans.Configuration;
using Orleans.Runtime; using Orleans.Runtime;
using Squidex.Config.Domain;
using Squidex.Domain.Apps.Entities; using Squidex.Domain.Apps.Entities;
using Squidex.Infrastructure; using Squidex.Infrastructure;
@ -31,6 +32,10 @@ namespace Squidex.Config.Orleans
{ {
options.ClusterId = "squidex"; options.ClusterId = "squidex";
}) })
.ConfigureServices((context, services) =>
{
services.AddMySerializers();
})
.ConfigureApplicationParts(builder => .ConfigureApplicationParts(builder =>
{ {
builder.AddApplicationPart(SquidexEntities.Assembly); builder.AddApplicationPart(SquidexEntities.Assembly);

2
src/Squidex/Config/Orleans/SiloWrapper.cs

@ -53,8 +53,6 @@ namespace Squidex.Config.Orleans
silo = new Lazy<ISiloHost>(() => silo = new Lazy<ISiloHost>(() =>
{ {
J.Serializer = SerializationServices.DefaultJsonSerializer;
var hostBuilder = new SiloHostBuilder() var hostBuilder = new SiloHostBuilder()
.UseDashboard(options => options.HostSelf = false) .UseDashboard(options => options.HostSelf = false)
.AddStartupTask<Bootstrap<IContentSchedulerGrain>>() .AddStartupTask<Bootstrap<IContentSchedulerGrain>>()

4
src/Squidex/app/framework/angular/forms/jscript-editor.component.ts

@ -9,7 +9,7 @@ import { AfterViewInit, Component, ElementRef, forwardRef, ViewChild } from '@an
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { ResourceLoaderService } from '@app/framework/internal'; import { ResourceLoaderService, Types } from '@app/framework/internal';
declare var ace: any; declare var ace: any;
@ -40,7 +40,7 @@ export class JscriptEditorComponent implements ControlValueAccessor, AfterViewIn
} }
public writeValue(obj: any) { public writeValue(obj: any) {
this.value = obj + ''; this.value = Types.isString(obj) ? obj : '';
if (this.aceEditor) { if (this.aceEditor) {
this.setValue(this.value); this.setValue(this.value);

2
src/Squidex/app/framework/angular/forms/transform-input.directive.ts

@ -71,7 +71,7 @@ export class TransformInputDirective implements ControlValueAccessor {
} }
public writeValue(obj: any) { public writeValue(obj: any) {
const normalizedValue = this.transformValue(obj + ''); const normalizedValue = this.transformValue(Types.isString(obj) ? obj : '');
this.renderer.setProperty(this.element.nativeElement, 'value', normalizedValue); this.renderer.setProperty(this.element.nativeElement, 'value', normalizedValue);
} }

5
src/Squidex/app/shared/components/markdown-editor.component.ts

@ -11,7 +11,8 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { import {
AssetDto, AssetDto,
ModalView, ModalView,
ResourceLoaderService ResourceLoaderService,
Types
} from '@app/shared/internal'; } from '@app/shared/internal';
declare var SimpleMDE: any; declare var SimpleMDE: any;
@ -54,7 +55,7 @@ export class MarkdownEditorComponent implements ControlValueAccessor, AfterViewI
} }
public writeValue(obj: any) { public writeValue(obj: any) {
this.value = obj + ''; this.value = Types.isString(obj) ? obj : '';
if (this.simplemde) { if (this.simplemde) {
this.simplemde.value(this.value); this.simplemde.value(this.value);

5
src/Squidex/app/shared/components/rich-editor.component.ts

@ -11,7 +11,8 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { import {
AssetDto, AssetDto,
ModalView, ModalView,
ResourceLoaderService ResourceLoaderService,
Types
} from '@app/shared/internal'; } from '@app/shared/internal';
declare var tinymce: any; declare var tinymce: any;
@ -112,7 +113,7 @@ export class RichEditorComponent implements ControlValueAccessor, AfterViewInit,
} }
public writeValue(obj: any) { public writeValue(obj: any) {
this.value = obj + ''; this.value = Types.isString(obj) ? obj : '';
if (this.tinyEditor) { if (this.tinyEditor) {
this.tinyEditor.setContent(this.value); this.tinyEditor.setContent(this.value);

Loading…
Cancel
Save