예제 #1
0
        public bool Attach(string libName = null)
        {
            string assemblyFullpath;
            string assemblyFilename;
            string assemblyNameSpace;

            Regex          rx;
            Assembly       asm;
            Type           asmType;
            DynamicInvoker inv;
            ISubComponent  component;

            string[] fileNames = Directory.GetFiles(_currentEntryAssemblyPath);

            if (libName == null)
            {
                rx = new Regex(@"(SensorMonitor.Component.\w+.\w+).dll",
                               RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOptions.Compiled);
            }
            else
            {
                rx = new Regex($@"(SensorMonitor.Component.{libName}.\w+).dll",
                               RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOptions.Compiled);
            }
            //rx.Match("abc").
            var assemblyCandidates = (from file in fileNames
                                      where rx.IsMatch(file)
                                      orderby file
                                      select new
            {
                fullpath = file,
                filename = rx.Match(file).Groups[0].Value,
                ns = rx.Match(file).Groups[1].Value
            }).ToList();

            if (!assemblyCandidates.Any())
            {
                return(false);
            }

            foreach (var candidate in assemblyCandidates)
            {
                assemblyFullpath  = candidate.fullpath;
                assemblyFilename  = candidate.filename;
                assemblyNameSpace = candidate.ns;

                try
                {
                    asm       = Assembly.LoadFrom(assemblyFullpath);
                    asmType   = asm.GetType(assemblyNameSpace + ".Entry");
                    inv       = new DynamicInvoker(asmType);
                    component = inv.CreateInstance() as ISubComponent;
                }
                catch (Exception e)
                {
                    string msg = "Assembly.LoadFrom(dataAssemblyFullpath) / Exceptiuon : " + e.ToString();
                    L(msg, LogEvt.MessageType.Error);
                    continue;
                }

                if (component != null)
                {
                    component.ConnectBus(_busHub);
                    component.Log += SubComponentLogEvtConsumer;
                    _subComponents.Add(component);
                }
            }
            return(true);
        }
예제 #2
0
        public bool Attach(string libName = null)
        {
            string assemblyFullpath;
            string assemblyFilename;
            string assemblyNameSpace;

            Regex rx;
            Assembly asm;
            Type asmType;
            DynamicInvoker inv;
            ISubComponent component;

            string[] fileNames = Directory.GetFiles(_currentEntryAssemblyPath);

            if (libName == null)
            {
                rx = new Regex(@"(SensorMonitor.Component.\w+.\w+).dll",
                    RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOptions.Compiled);
            }
            else
            {
                rx = new Regex($@"(SensorMonitor.Component.{libName}.\w+).dll",
                    RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOptions.Compiled);
            }
            //rx.Match("abc").
            var assemblyCandidates = (from file in fileNames
                                         where rx.IsMatch(file)
                                         orderby file
                                         select new
                                         {
                                             fullpath = file,
                                             filename = rx.Match(file).Groups[0].Value,
                                             ns = rx.Match(file).Groups[1].Value
                                         }).ToList();
            if (!assemblyCandidates.Any())
                return false;

            foreach (var candidate in assemblyCandidates)
            {
                assemblyFullpath = candidate.fullpath;
                assemblyFilename = candidate.filename;
                assemblyNameSpace = candidate.ns;

                try
                {
                    asm = Assembly.LoadFrom(assemblyFullpath);
                    asmType = asm.GetType(assemblyNameSpace + ".Entry");
                    inv = new DynamicInvoker(asmType);
                    component = inv.CreateInstance() as ISubComponent;
                }
                catch (Exception e)
                {
                    string msg = "Assembly.LoadFrom(dataAssemblyFullpath) / Exceptiuon : " + e.ToString();
                    L(msg, LogEvt.MessageType.Error);
                    continue;
                }

                if (component != null)
                {
                    component.ConnectBus(_busHub);
                    component.Log += SubComponentLogEvtConsumer;
                    _subComponents.Add(component);
                }
            }
            return true;
        }