コード例 #1
0
ファイル: Issue.cs プロジェクト: radekhubner/HlidacStatu
        public Issue(
            IIssueAnalyzer analyzer, int issueTypeId, string title, string description, ImportanceLevel?importance = null, dynamic affectedParams = null, bool publicVisible = true, bool permanent = false)
        {
            this.IssueTypeId = issueTypeId;

            this.AnalyzerType = analyzer != null?analyzer.GetType().FullName : "Manual";

            this.Title           = title;
            this.TextDescription = description;
            this.Importance      = (importance.HasValue ? importance.Value :  IssueType.IssueImportance(issueTypeId));
            this.Public          = publicVisible;
            this.Permanent       = permanent;
            if (affectedParams != null)
            {
                this.AffectedParams = ((object)affectedParams).GetType()
                                      .GetProperties()
                                      .ToDictionary(p => p.Name, p => p.GetValue(affectedParams, null))
                                      .Select(m => new KeyValue()
                {
                    Key = m.Key, Value = m.Value.ToString()
                })
                                      .ToArray();
            }
        }
コード例 #2
0
ファイル: Util.cs プロジェクト: radekhubner/HlidacStatu
        public static List <IIssueAnalyzer> GetIssueAnalyzers(string moreFromPath = null)
        {
            if (issueAnalyzers != null)
            {
                return(issueAnalyzers);
            }

            lock (objLock)
            {
                ////load DLL's from disk
                List <System.Reflection.Assembly> dlls = new List <System.Reflection.Assembly>();
                string pathForDlls = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                foreach (var file in System.IO.Directory.EnumerateFiles(pathForDlls, "*plugin*.dll"))
                {
                    try
                    {
                        string filename = System.IO.Path.GetFileNameWithoutExtension(file);
                        dlls.Add(System.Reflection.Assembly.Load(filename));
                    }
                    catch (Exception)
                    {
                    }
                }



                var typeI = typeof(IIssueAnalyzer);
                List <System.Type> types = null;
                var t = AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes()).Where(p => p.FullName.StartsWith("HlidacStatu.Plugin.IssueAnalyzers")).ToList();
                try
                {
                    types = AppDomain.CurrentDomain.GetAssemblies()
                            .Union(dlls)
                            .SelectMany(s => s.GetTypes())
                            .Where(p =>
                                   typeI.IsAssignableFrom(p) &&
                                   p.IsAbstract == false
                                   )
                            .ToList();
                }
                catch (System.Reflection.ReflectionTypeLoadException lex)
                {
                    StringBuilder sb = new StringBuilder();
                    if (lex.LoaderExceptions != null)
                    {
                        foreach (Exception ex in lex.LoaderExceptions)
                        {
                            sb.AppendFormat("{0}\n----------------\n", ex.ToString());
                        }
                    }

                    HlidacStatu.Util.Consts.Logger.Fatal("Cannot make list of issueAnalyzer instances, reason: " + sb.ToString(), lex);
                }
                catch (Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Fatal("Cannot make list of issueAnalyzer plugin instances ", e);

                    throw;
                }

                var ps = new List <IIssueAnalyzer>();
                foreach (var type in types)
                {
                    try
                    {
                        IIssueAnalyzer parser = (IIssueAnalyzer)Activator.CreateInstance(type);
                        ps.Add(parser);
                        HlidacStatu.Util.Consts.Logger.Info("Creating instance of plugin " + type.FullName);
                    }
                    catch (Exception e)
                    {
                        //NoveInzeraty.Lib.Constants.NIRoot.Error("Cannot make instance of parser " + type.FullName, e);
                    }
                }
                issueAnalyzers = ps;
                return(issueAnalyzers);
            }
        }