public static string GetDescription(this ISetup setup) { Type type = setup.GetType(); string result = null; SetupAttribute attr = type.GetCustomAttribute<SetupAttribute>(); if(attr != null) { result = attr.Description; } return result; }
public static string[] GetLinks(this ISetup setup) { Type type = setup.GetType(); string[] result = null; SetupAttribute attr = type.GetCustomAttribute<SetupAttribute>(); if(attr != null) { result = attr.Links; } return result; }
private static async Task <bool> RunSetup(ISetup operation, bool Depends = true) { var depends = operation.GetType().GetCustomAttributes(typeof(DependsAttribute), true).FirstOrDefault() as DependsAttribute; if (Depends && depends != null) { foreach (var depend in depends.Depends) { if (!await RunSetup(depend).ConfigureAwait(false)) { Logger.Error($"Failed to run operation {depend}"); } } } var name = operation.GetType().GetCustomAttributes(typeof(OperationAttribute), true).FirstOrDefault() as OperationAttribute; var start = DateTime.UtcNow; Logger.Info("**************************************************************"); Logger.Info($" Running operation {name.Name}"); Logger.Info("**************************************************************"); if (!await operation.Initialize().ConfigureAwait(false)) { Logger.Info("ERROR - Failed to seed entities!"); return(false); } Logger.Info("**************************************************************"); Logger.Info($" Finished operation {name.Name} in {DateTime.UtcNow - start}"); Logger.Info("**************************************************************"); return(true); }
public static string GetDisplayName(this ISetup setup) { Type type = setup.GetType(); string result; SetupAttribute attr = type.GetCustomAttribute<SetupAttribute>(); if(attr != null && attr.DisplayName != null) { result = attr.DisplayName; } else { result = type.Name; } return result; }
public void Add <T>(ISetup <T> setup) where T : class { var methodInfo = (MethodInfo)setup .GetType() .GetRuntimeProperty("Method") .GetValue(setup); _methodInfoSequence.Add(methodInfo); setup.Callback(() => { var currentMethod = _methodInfoSequence.ElementAt(0); if (currentMethod != methodInfo) { throw new Exception($"Expected {methodInfo} to be called but {currentMethod} has been called."); } _methodInfoSequence.RemoveAt(0); }); }
private static IModelProvider <ISetup, IModelSetup, object> CreateWrappedModelProvider(ISetup setup, IModelSetup?modelSetup, Type modelType, IModelProvider modelProvider) { return((IModelProvider <ISetup, IModelSetup, object>)Activator.CreateInstance( typeof(ModelProviderAdapter <, ,>).MakeGenericType(setup.GetType(), modelSetup?.GetType() ?? typeof(IModelSetup), modelType), modelProvider)); }