Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
usercode committed Jan 27, 2024
1 parent f330694 commit 0fef0ea
Show file tree
Hide file tree
Showing 31 changed files with 101 additions and 117 deletions.
9 changes: 7 additions & 2 deletions src/DragonFly.App.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using DragonFly.MongoDB;
using DragonFlyABC;
using DragonFlyTEST;
using FFMpegCore;
using ImageWizard;
using ImageWizard.Caches;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -45,6 +46,12 @@
options.KnownProxies.Clear();
});

GlobalFFOptions.Configure(x =>
{
x.BinaryFolder = "C:\\Users\\admin\\Downloads";
x.TemporaryFilesFolder = "C:\\Users\\admin\\Downloads";
});

//DragonFly services
builder.Services.AddDragonFly()
.AddImageWizard()
Expand All @@ -63,8 +70,6 @@
})
;



var app = builder.Build();

//init DragonFly
Expand Down
9 changes: 0 additions & 9 deletions src/DragonFly.AspNetCore/Assets/VideoProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
// MIT License

using FFMpegCore;
using FFMpegCore.Builders.MetaData;
using Microsoft.AspNetCore.Components.Forms;
using SixLabors.ImageSharp;

namespace DragonFly.AspNetCore;

Expand All @@ -27,12 +24,6 @@ public bool CanUse(string mimeType)

public async Task<bool> OnAssetChangedAsync(IAssetProcessingContext context)
{
GlobalFFOptions.Configure(x =>
{
x.BinaryFolder = "C:\\Users\\admin\\Downloads";
x.TemporaryFilesFolder = "C:\\Users\\admin\\Downloads";
});

using Stream stream = await context.OpenAssetStreamAsync();

IMediaAnalysis mediaInfo = FFProbe.Analyse(stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public BlockFieldAttribute()
{
}

public override void AddToSchema(ContentSchema schema, string property)
public override void ApplyToSchema(ContentSchema schema, string property)
{
schema.AddField(
name: property,
Expand Down
14 changes: 11 additions & 3 deletions src/DragonFly.Client/Extensions/DragonFlyApiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ namespace DragonFly;

public static class DragonFlyApiExtensions
{
public static FieldAdded WithFieldView<TFieldView>(this FieldAdded field)
//public static IFieldAdded<T> WithFieldView2<T>(this IFieldAdded<T> field, Func<IFieldComponent<T>> component)
// where T : ContentField
//{
// ComponentManager.Default.Add(typeof(T), typeof(TFieldView));

// return field;
//}

public static IFieldAdded WithFieldView<TFieldView>(this IFieldAdded field)
where TFieldView : IFieldComponent, new()
{
Type fieldType = new TFieldView().FieldType;
Expand All @@ -19,7 +27,7 @@ public static FieldAdded WithFieldView<TFieldView>(this FieldAdded field)
return field;
}

public static FieldAdded WithOptionView<TFieldOptionsView>(this FieldAdded field)
public static IFieldAdded WithOptionView<TFieldOptionsView>(this IFieldAdded field)
where TFieldOptionsView : IFieldOptionsComponent, new()
{
Type optionsType = new TFieldOptionsView().OptionsType;
Expand All @@ -29,7 +37,7 @@ public static FieldAdded WithOptionView<TFieldOptionsView>(this FieldAdded field
return field;
}

public static FieldAdded WithQueryView<TFieldQueryView>(this FieldAdded field)
public static IFieldAdded WithQueryView<TFieldQueryView>(this IFieldAdded field)
where TFieldQueryView : IFieldQueryComponent, new()
{
Type queryType = new TFieldQueryView().QueryType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// MIT License

using System;
using Microsoft.AspNetCore.Components;

namespace DragonFly.Client;

public interface IAssetMetadataComponent
public interface IAssetMetadataComponent : IComponent
{
AssetMetadata Metadata { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace DragonFly.Client;

public abstract class FieldComponent<TField, TFieldOptions> : ComponentBase, IFieldComponent
public abstract class FieldComponent<TField, TFieldOptions> : ComponentBase, IFieldComponent<TField>
where TField : ContentField
where TFieldOptions : FieldOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace DragonFly.Client;
/// <summary>
/// FieldComponent
/// </summary>
public abstract class FieldComponent<TField> : ComponentBase, IFieldComponent
public abstract class FieldComponent<TField> : ComponentBase, IFieldComponent<TField>
where TField : ContentField
{
[Parameter]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ public interface IFieldComponent : IComponent

FieldOptions Options { get; }
}

public interface IFieldComponent<TField> : IFieldComponent
where TField : ContentField
{
new Type FieldType => typeof(TField);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// MIT License

using System;
using DragonFly.Query;
using Microsoft.AspNetCore.Components;

namespace DragonFly.Client;

public interface IFieldQueryComponent
public interface IFieldQueryComponent : IComponent
{
SchemaField Field { get; }

Expand Down
16 changes: 6 additions & 10 deletions src/DragonFly.Client/Services/ComponentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,26 @@ public sealed class ComponentManager
/// </summary>
public static ComponentManager Default { get; } = new ComponentManager();

private IDictionary<Type, Type> _cacheFieldView;

private ComponentManager()
{
_cacheFieldView = new Dictionary<Type, Type>();
}
private IDictionary<Type, Type> _cacheFieldView = new Dictionary<Type, Type>();

public void Add(Type fieldType, Type componentType)
{
_cacheFieldView[fieldType] = componentType;
}

public Type GetComponentType(Type type)
public Type GetComponentType(Type fieldType)
{
if (_cacheFieldView.TryGetValue(type, out Type componentType))
if (_cacheFieldView.TryGetValue(fieldType, out Type componentType))
{
return componentType;
}

return null;
}

public Type GetComponentType<T>()
public Type GetComponentType<TField>()
where TField : ContentField
{
return GetComponentType(typeof(T));
return GetComponentType(typeof(TField));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,47 @@ namespace DragonFly;
/// <summary>
/// FieldFactory
/// </summary>
public sealed class FieldFactory
public sealed class FieldFactory(
string fieldName,
Type fieldType,
Type? optionsType,
Type? queryType,
Func<ContentField> factoryField,
Func<FieldOptions>? factoryOptions,
Func<FieldQuery>? factoryQuery)
{
public FieldFactory(
string fieldName,
Type fieldType,
Type? optionsType,
Type? queryType,
Func<ContentField> factoryField,
Func<FieldOptions>? factoryOptions,
Func<FieldQuery>? factoryQuery)
{
FieldName = fieldName;
FieldType = fieldType;
OptionsType = optionsType;
QueryType = queryType;
_createField = factoryField;
_createOptions = factoryOptions;
_createQuery = factoryQuery;
}

/// <summary>
/// FieldName
/// </summary>
public string FieldName { get; }
public string FieldName { get; } = fieldName;

/// <summary>
/// FieldType
/// </summary>
public Type FieldType { get; }
public Type FieldType { get; } = fieldType;

/// <summary>
/// OptionsType
/// </summary>
public Type? OptionsType { get; }
public Type? OptionsType { get; } = optionsType;

/// <summary>
/// QueryType
/// </summary>
public Type? QueryType { get; }


private Func<ContentField> _createField;
public Type? QueryType { get; } = queryType;

/// <summary>
/// CreateField
/// </summary>
public ContentField CreateField() => _createField();

private Func<FieldOptions>? _createOptions;
public ContentField CreateField() => factoryField();

/// <summary>
/// CreateOptions
/// </summary>
public FieldOptions? CreateOptions() => _createOptions?.Invoke();

private Func<FieldQuery>? _createQuery;
public FieldOptions? CreateOptions() => factoryOptions?.Invoke();

/// <summary>
/// CreateQuery
/// </summary>
public FieldQuery? CreateQuery() => _createQuery?.Invoke();
public FieldQuery? CreateQuery() => factoryQuery?.Invoke();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public sealed class FieldManager
/// <summary>
/// Adds <typeparamref name="TField"/> to field manager.
/// </summary>
public FieldAdded<TField> Add<TField>()
where TField : ContentField, IContentField
public IFieldAdded<TField> Add<TField>()
where TField : ContentField, IContentFieldFactory
{
FieldFactory factory = TField.Factory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ namespace DragonFly;
/// <summary>
/// FieldAdded
/// </summary>
public abstract class FieldAdded
/// <typeparam name="T"></typeparam>
public class FieldAdded<T> : IFieldAdded<T>
where T : ContentField
{
/// <summary>
/// FieldType
/// </summary>
public abstract Type FieldType { get; }
public Type FieldType => typeof(T);
}

/// <summary>
/// FieldAdded
/// </summary>
/// <typeparam name="T"></typeparam>
public class FieldAdded<T> : FieldAdded
where T : ContentField
public interface IFieldAdded
{

}

public interface IFieldAdded<out T> : IFieldAdded
{
public override Type FieldType => typeof(T);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ public abstract class FieldOptions
/// </summary>
public bool IsSearchable { get; set; }

/// <summary>
/// CreateContentField
/// </summary>
public abstract ContentField CreateContentField();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) usercode
// https://github.com/usercode/DragonFly
// MIT License

namespace DragonFly;

public interface IContentFieldFactory
{
static abstract FieldFactory Factory { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace DragonFly;
/// </summary>
public abstract class SingleValueField<T> : ContentField, ISingleValueField
{

private T? _value;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public AssetFieldAttribute()

public bool ShowPreview { get; set; }

public override void AddToSchema(ContentSchema schema, string property)
public override void ApplyToSchema(ContentSchema schema, string property)
{
base.AddToSchema(schema, property);
base.ApplyToSchema(schema, property);

schema.AddAsset(property, x =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class BaseFieldAttribute : Attribute

public bool Index { get; set; }

public virtual void AddToSchema(ContentSchema schema, string property)
public virtual void ApplyToSchema(ContentSchema schema, string property)
{
if (ListField)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace DragonFly.Generator;

public class BoolFieldAttribute : BaseFieldAttribute
{
public override void AddToSchema(ContentSchema schema, string property)
public override void ApplyToSchema(ContentSchema schema, string property)
{
base.AddToSchema(schema, property);
base.ApplyToSchema(schema, property);

schema.AddBool(property, x =>
{
Expand Down
Loading

0 comments on commit 0fef0ea

Please sign in to comment.