示例#1
0
        private void AssembliesLoader_DoWork(object sender, DoWorkEventArgs e)
        {
            Assemblies.Clear();

            // Add default assembly
            Assemblies.Add(new AssemblyInfo(typeof(Node).Assembly, true, false));

            // Load domain assemblies
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                AnalyzeAssembly(assembly, true);
            }

            // Load local plugins
            foreach (string path in Directory.GetFiles(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "FlowTomator.*.dll"))
            {
                FileInfo fileInfo = new FileInfo(path);

                if (!fileInfo.Exists || Assemblies.Any(a => a.Path == fileInfo.FullName))
                {
                    continue;
                }

                try
                {
                    Assembly assembly = Assembly.ReflectionOnlyLoadFrom(path);
                    AnalyzeAssembly(assembly, false);
                }
                catch
                {
                    continue;
                }
            }
        }
示例#2
0
        internal DocsProject GenerateAssemblyFiles()
        {
            if (!Assemblies.Any())
            {
                throw new ArgumentException("Assemblies property must contain at least one Assembly to document.");
            }

            // Create, validate, and log assemblies folder
            LogVerbose($"Creating {Settings.AssembliesFolder} folder...");
            Directory.CreateDirectory(Settings.AssembliesFolder);
            ValidateFolder(Settings.TempFolder);
            LogVerbose($"Creating {Settings.AssembliesFolder} folder complete.");

            Assemblies.ToList().ForEach(a => {
                var outfile = Path.Combine(Settings.AssembliesFolder, a.ToFileName() + ".md");
                var file    = new DocsFile(outfile, DocsFileType.Assembly, DocsProjectOutputFormat.Markdown)
                              .SetTitle(a.GetSimpleName())
                              .UseEngine(new AssemblyFileGenerator(a, Settings, a.GetSimpleName()));
                //.Compile();

                file.Compile();
                Console.WriteLine($"Assembly file created for {a.GetSimpleName()} at {outfile}");
            });

            return(this);
        }
示例#3
0
 /// <summary>
 /// Check if assembly already exists on conveyor
 /// </summary>
 /// <param name="assemblyName"></param>
 /// <returns></returns>
 public bool containsAssembly(string assemblyName)
 {
     if (Assemblies != null)
     {
         return(Assemblies.Any(i => i.Name == assemblyName));
     }
     return(false);
 }
示例#4
0
        public void Process(PipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (!Enabled)
            {
                return;
            }

            Assert.IsNotNullOrEmpty(RouteName, "You must configure a RouteName");
            Assert.IsNotNullOrEmpty(RoutePath, "You must configure a RoutePath");
            Assert.IsTrue(Assemblies.Any(), "You must configure at least one assembly");
            RegisterRoutes();
        }
示例#5
0
        public void LoadAssemblyWithReferenced(string fullName, List <string> depSearchPath = null)
        {
            // Eww
            try {
                if (Assemblies.Any(a => Regex.IsMatch(fullName, $"^{a.GetName().Name},")))
                {
                    return;
                }

                try {
                    Assemblies.Add(Assembly.Load(fullName));
                } catch {
                    try {
                        if (depSearchPath == null)
                        {
                            throw;
                        }
                        else
                        {
                            foreach (var path in depSearchPath)
                            {
                                try {
                                    Assemblies.Add(Assembly.LoadFile(Path.Combine(path, fullName)));
                                } catch {
                                    continue;
                                }

                                break;
                            }
                        }
                    } catch {
                        throw;
                    }
                }

                // Console.Error.WriteLine($"Loaded: {fullName}");
            } catch {
                // Console.Error.WriteLine($"Skipped: {fullName}");

                return;
            }

            foreach (var asmName in Assemblies.Last().GetReferencedAssemblies())
            {
                LoadAssemblyWithReferenced(asmName.FullName);
            }
        }
示例#6
0
        public TTypeInfo Get <T, TProvider, TTypeInfo>()
            where TProvider : class, IMetadataProvider
            where TTypeInfo : class, ITypeInfo
        {
            if (Assemblies == null || !Assemblies.Any())
            {
                throw new Exception($"No assemblies specified for ExportCatalog.");
            }

            var types  = GetTypes <TProvider>();
            var result = types.FirstOrDefault(o => o.Native.AssemblyQualifiedName.Equals(typeof(T).AssemblyQualifiedName));

            if (result == null)
            {
                throw new NullReferenceException($"Tried to get type {typeof(T).Name} from ExportCatalog but it was not found.");
            }

            return((TTypeInfo)result);
        }
示例#7
0
        private void AnalyzeAssembly(Assembly assembly, bool enabled)
        {
            if (assembly.IsDynamic || Assemblies.Any(a => a.Path == assembly.Location))
            {
                return;
            }

            if (assembly.ReflectionOnly)
            {
                foreach (AssemblyName assemblyName in assembly.GetReferencedAssemblies())
                {
                    try
                    {
                        Assembly.ReflectionOnlyLoad(assemblyName.FullName);
                    }
                    catch (FileNotFoundException) { }
                }
            }

            IEnumerable <Type> nodeTypes;

            try
            {
                nodeTypes = assembly.GetTypes();
            }
            catch (ReflectionTypeLoadException e)
            {
                nodeTypes = e.Types.Where(t => t != null);
            }

            nodeTypes = nodeTypes.Where(t => !t.IsAbstract)
                        .Where(t => t.IsSubclassOf(typeof(Node)) || t.IsSubclassOf(reflectionNodeType))
                        .Where(t => t != typeof(Flow) && t != reflectionFlowType)
                        .Where(t => !t.IsSubclassOf(typeof(Flow)) && !t.IsSubclassOf(reflectionFlowType))
                        .Where(t => t.GetConstructor(Type.EmptyTypes) != null);

            if (nodeTypes.Any())
            {
                Assemblies.Add(new AssemblyInfo(assembly, enabled));
            }
        }
示例#8
0
        private async void Export()
        {
            if (Assemblies.Count == 0)
            {
                MessageBox.Show("There are no assemblies to export.");
                return;
            }

            if (!Assemblies.Any(a => a.Export == true))
            {
                MessageBox.Show("Please select at least one assembly to export.");
                return;
            }

            var folderBrowser = new FolderBrowserDialog
            {
                Description         = "Please select a location to save the selected assemblies",
                ShowNewFolderButton = true
            };

            var dialogResult = folderBrowser.ShowDialog();

            if (dialogResult == DialogResult.OK &&
                !string.IsNullOrEmpty(folderBrowser.SelectedPath))
            {
                IsBusy = true;

                foreach (var assembly in Assemblies.Where(a => a.Export == true))
                {
                    var path = Path.Combine(folderBrowser.SelectedPath, assembly.Name + ".dll");

                    var bytes = await DownloadAssembly(assembly.AssemblyId);

                    File.WriteAllBytes(path, bytes);
                }

                IsBusy = false;
            }

            var toExport = Assemblies.Where(a => a.Export == true).ToList();
        }
示例#9
0
        private void AddAssemblyButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Title       = "Open an existing .NET assembly";
            dialog.Filter      = ".NET Assemblies|*.dll|All files|*.*";
            dialog.FilterIndex = 1;

            if (dialog.ShowDialog(this) != true)
            {
                return;
            }

            FileInfo fileInfo = new FileInfo(dialog.FileName);

            if (!fileInfo.Exists)
            {
                MessageBox.Show("Unable to find the specified file", App.Name, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (Assemblies.Any(a => a.Path == fileInfo.FullName))
            {
                MessageBox.Show("The specified file has already been added", App.Name, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                Assembly assembly = Assembly.ReflectionOnlyLoadFrom(fileInfo.FullName);
                AnalyzeAssembly(assembly, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to load the specified assembly. " + ex, App.Name, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }
示例#10
0
        internal DocsProject GenerateIndexFile()
        {
            // Throw error if no assemblies in Assemblies property.
            if (!Assemblies.Any())
            {
                throw new ArgumentException("Assemblies property must contain at least one Assembly to document.");
            }

            var filename = Path.Combine(Settings.OutputFolder, "index.md");
            var file     = new DocsFile(filename, DocsFileType.Index, DocsProjectOutputFormat.Markdown)
                           .SetTitle(Settings.ProjectName)
                           .UseEngine(new IndexFileGenerator(Assemblies, Settings));

            //.Compile();

            file.Compile();

            //dll.GetAllNamespaces().ToList().ForEach(a => output.WriteLine("[" + a + "](./namespaces/" + a.Replace(".", "-") + ".md)"));
            // File.WriteAllLines(filename, output.ToString().Split(Environment.NewLine, StringSplitOptions.None));
            LogVerbose($"Index file created at {filename}");

            return(this);
        }
示例#11
0
        private void CollectAssemblyDefinedTypeConfigurations()
        {
            if (!Assemblies.Any())
            {
                return;
            }

            foreach (var assembly in Assemblies)
            {
                var typeConfigurationTypeInfo = typeof(TypeConfiguration).GetTypeInfo();
                var types = assembly.ExportedTypes
                            .Select(t => t.GetTypeInfo())
                            .Where(t => !t.IsAbstract && typeConfigurationTypeInfo.IsAssignableFrom(t))
                            .ToList();

                foreach (var type in types)
                {
                    var baseTypeConfigurationType = FindGenericBaseTypeConfigurationType(type);
                    if (baseTypeConfigurationType == null)
                    {
                        throw new InvalidOperationException("You should extend from the generic version of TypeConfiguration.");
                    }

                    var instance    = (TypeConfiguration)Activator.CreateInstance(type.AsType());
                    var elementType = GetElementTypeFromConcreteTypeConfiguration(baseTypeConfigurationType);
                    var existing    = TypeConfigurations.FirstOrDefault(tc => tc.Type == elementType);
                    if (existing != null)
                    {
                        existing.Combine(instance);
                    }
                    else
                    {
                        TypeConfigurations.Add(instance);
                    }
                }
            }
        }
示例#12
0
        public Opts(string[] argArray)
        {
            var  args            = new List <string>(argArray);
            var  index           = 0;
            bool doneWithOptions = false;

            while (index < args.Count)
            {
                if (WantUsage)
                {
                    break;
                }
                string key   = args[index];
                string value = (index + 1 >= args.Count) ? null : args[index + 1];
                if (!doneWithOptions && (key.StartsWith("-") || key.StartsWith("/")))
                {
                    key = key.Remove(0, 1);
                    switch (key)
                    {
                    case "A":
                    case "authtoken":
                        AuthToken = value;
                        index++;
                        break;

                    case "h":
                    case "host":
                        DekiApi = Plug.New(string.Format("http://{0}/@api/deki", value));
                        index++;
                        break;

                    case "I":
                    case "importreltopath":
                        ImportReltoPath = Title.FromUIUri(null, value).AsPrefixedDbPath();
                        index++;
                        break;

                    case "importrelto":
                        ImportRelto = int.Parse(value);
                        index++;
                        break;

                    case "o":
                    case "output":
                        OutputPath = value;
                        Mode       = Mode.Generate;
                        index++;
                        break;

                    case "P":
                    case "password":
                        Password = value;
                        index++;
                        break;

                    case "R":
                    case "retries":
                        Retries = int.Parse(value);
                        index++;
                        break;

                    case "U":
                    case "user":
                        User = value;
                        index++;
                        break;

                    case "u":
                    case "uri":
                        DekiApi = Plug.New(value);
                        index++;
                        break;

                    case "?":
                    case "usage":
                        WantUsage = true;
                        break;

                    case "t":
                        Test = true;
                        break;

                    default:
                        throw new ConfigurationException("Unknown option {0}", key);
                    }
                }
                else
                {
                    doneWithOptions = true;
                    Assemblies.Add(key);
                }
                index++;
            }
            if (WantUsage)
            {
                return;
            }
            if (!Assemblies.Any())
            {
                throw new ConfigurationException("Missing {0} Directory", Mode);
            }
        }