public MockMethodBuilder WithFilteredHook(LibType hook, params string[] tags)
        {
            var mockFilteredHook = new Mock <Type>();

            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.FilteredHookAttribute)).Returns(mockFilteredHook.Object);

            var mockHookType = new Mock <Type>();

            mockHookType.Setup(x => x.IsSubclassOf(mockFilteredHook.Object)).Returns(true);
            var hookAttribute = new TestFilteredHook {
                FilterTags = tags.Length > 0 ? tags : null
            };

            mockHookType.Setup(x => x.IsInstanceOfType(It.IsAny <TestFilteredHook>())).Returns(true);
            mockAssemblyLoader.Setup(a => a.GetLibType(hook)).Returns(mockHookType.Object);

            methodAttributes.Add(hookAttribute);

            var mockTagAggregationBehaviourType = new Mock <Type>();

            mockTagAggregationBehaviourType.Setup(x => x.IsInstanceOfType(It.IsAny <TestTagAggregation>()))
            .Returns(true);
            mockAssemblyLoader.Setup(a => a.GetLibType(LibType.TagAggregationBehaviourAttribute))
            .Returns(mockTagAggregationBehaviourType.Object);
            return(this);
        }
Exemple #2
0
        public HookMethod(LibType hookType, MethodInfo methodInfo, IAssemblyLoader assemblyLoader)
        {
            Method     = methodInfo.FullyQuallifiedName();
            FilterTags = Enumerable.Empty <string>();

            var type = assemblyLoader.GetLibType(hookType);

            if (!type.IsSubclassOf(assemblyLoader.GetLibType(LibType.FilteredHookAttribute)))
            {
                return;
            }
            var customAttributes      = methodInfo.GetCustomAttributes(false);
            var filteredHookAttribute = customAttributes.FirstOrDefault(type.IsInstanceOfType);

            if (filteredHookAttribute == null)
            {
                return;
            }

            FilterTags = (string[])GetPropValue(filteredHookAttribute, "FilterTags");

            var     targetTagBehaviourType           = assemblyLoader.GetLibType(LibType.TagAggregationBehaviourAttribute);
            dynamic tagAggregationBehaviourAttribute =
                customAttributes.FirstOrDefault(targetTagBehaviourType.IsInstanceOfType);

            if (tagAggregationBehaviourAttribute != null)
            {
                TagAggregation = (int)GetPropValue(tagAggregationBehaviourAttribute, "TagAggregation");
            }
        }
Exemple #3
0
        private string GetApiRequestUrl(LibGuidesFilter libGuidesFilter, LibType libType)
        {
            string url = apiEndPoint + "/" + libType + "?site_id=" + siteId + "&key=" + apiToken + "&sort_by=count_hit&expand=owner&type_id=3";

            url += string.IsNullOrEmpty(libGuidesFilter.SubjectId)? string.Empty: "subject_id=" + libGuidesFilter.SubjectId;
            url += string.IsNullOrEmpty(libGuidesFilter.TypeId)? string.Empty : "type_id=" + libGuidesFilter.TypeId;

            return(url);
        }
Exemple #4
0
        public IEnumerable <MethodInfo> GetMethods(LibType type)
        {
            var attributeType = _targetLibAssembly.GetType(type.FullName());

            bool methodFilter(MethodInfo info) => info.GetCustomAttributes(false)
            .Any(attributeType.IsInstanceOfType);
            IEnumerable <MethodInfo> methodSelector(Type t) => _reflectionWrapper.GetMethods(t).Where(methodFilter);

            return(AssembliesReferencingGaugeLib.SelectMany(assembly => assembly.GetTypes().SelectMany(methodSelector)));
        }
Exemple #5
0
 public Type GetLibType(LibType type)
 {
     try
     {
         return(_targetLibAssembly.ExportedTypes.First(t => t.FullName == type.FullName()));
     }
     catch (InvalidOperationException ex)
     {
         throw new InvalidOperationException($"Cannot locate {type.FullName()} in Gauge.CSharp.Lib", ex);
     }
 }
 private void AddHookOfType(LibType hookType, IEnumerable <MethodInfo> hooks)
 {
     foreach (var methodInfo in hooks)
     {
         var fullyQuallifiedName = methodInfo.FullyQuallifiedName();
         if (!_methodMap.ContainsKey(fullyQuallifiedName))
         {
             _methodMap.Add(fullyQuallifiedName, methodInfo);
         }
     }
     _hooks[hookType].UnionWith(hooks.Select(info => new HookMethod(hookType, info, _assemblyLoader)));
 }
Exemple #7
0
        public LibaryDialog(string RootPath, string title, LibType _Type)
        {
            InitializeComponent();

            this.CreateClassifyBtn(RootPath);
            ClassifyBtn Btn = this.TableLayout.Controls[0] as ClassifyBtn;

            Btn.TriggerClick();
            Type           = _Type;
            this._RootPath = RootPath;
            this.Text      = title;
        }
Exemple #8
0
        public IEnumerable <MethodInfo> GetMethods(LibType type)
        {
            var attributeType = _targetLibAssembly.ExportedTypes.First(x => x.FullName == type.FullName());

            IEnumerable <MethodInfo> MethodSelector(Type t)
            {
                return(_reflectionWrapper.GetMethods(t)
                       .Where(info => info.GetCustomAttributes(false).Any(attributeType.IsInstanceOfType)));
            }

            return(AssembliesReferencingGaugeLib.SelectMany(assembly => assembly.ExportedTypes.SelectMany(MethodSelector)));
        }
Exemple #9
0
        public IActionResult Index(LibType lib = LibType.None)
        {
            switch (lib)
            {
            case LibType.Angular2:
                return(View("Index-Angular2"));

            case LibType.Aurelia:
                return(View("Index-Aurelia"));

            default:
                return(View());
            }
        }
Exemple #10
0
 public Type GetLibType(LibType type)
 {
     return(_targetLibAssembly.GetType(type.FullName()));
 }
Exemple #11
0
 public static string FullName(this LibType type)
 {
     return(typeNames[type]);
 }
Exemple #12
0
 public byte[] Build(IEnumerable <string> sourceFiles, LibType libType)
 {
     return(libType == LibType.Assembly ? BuildAssembly(sourceFiles) : BuildScript(sourceFiles));
 }
Exemple #13
0
        public async Task <object> Get(string connectionString, string databaseName, string workspaceDir, LibType libType)
        {
            await Task.Yield();

            try
            {
                var scaffolder    = new Scaffolder();
                var sourceBuilder = new SourceBuilder();
                var scriptBuilder = new ScriptGenerator();

                var @namespace  = libType == LibType.Assembly ? "GeneratedNamespace" : "System";
                var contextName = $"{databaseName}Context";

                var userFolder = Environment.GetEnvironmentVariable("LocalAppData");
                var appFolder  = $"{userFolder}\\SqlMapper";
                var directory  = new DirectoryInfo(appFolder);
                if (!directory.Exists)
                {
                    directory.Create();
                }
                var libraryPath = libType == LibType.Assembly ? $"{appFolder}\\generatedAssembly.dll" : $"{appFolder}\\generatedAssembly.csx";
                var scriptPath  = $"{workspaceDir}\\main.csx";

                var queryableExtensionsSource = File.ReadAllText($"{AppContext.BaseDirectory}/IQueryableExtensions.cs");
                var scaffolding = scaffolder.ScaffoldDatabase(connectionString, @namespace, contextName);
                scaffolding.AdditionalFiles.Add(queryableExtensionsSource);

                var libraryData            = sourceBuilder.Build(scaffolding.AllFiles, libType);
                var firstDbsetPropertyName = scriptBuilder.GetPropertyName(scaffolding.DbContextSource);
                var script = scriptBuilder.BuildMainScript(@namespace, contextName, libraryPath, firstDbsetPropertyName);

                File.WriteAllBytes(libraryPath, libraryData);
                File.WriteAllText(scriptPath, script);

                return(new { ScriptPath = scriptPath });
            }
#pragma warning disable 168
            catch (Exception ex)
#pragma warning restore 168
            {
                throw;
            }
        }