public async Task ConnectToCoreAsync(ICoreConnectionParams connectionParams) { EndPoint endPoint = connectionParams.EndPoint; if (CoreProxy != null) { Log.Error("Cannot connect to core, there is still a core proxy present"); throw new InvalidOperationException( "There is still a core proxy present"); } if (connectionParams.IsCoreLocal) { if (m_process == null) { await m_charmdRunner.StartIfNotRunningAndWaitAsync( Path.Combine(connectionParams.CoreProcessParams.WorkingDirectory, CharmdRelativePath), CharmdStartWaitMs); // TODO(HonzaS): Move this elsewhere when we have finer local process control. Log.Info("Starting a local core process"); m_process = m_coreProcessFactory.Create(connectionParams.CoreProcessParams); } endPoint = m_process.EndPoint; } if (endPoint == null) { Log.Error("Endpoint not set up, cannot connect to core"); throw new InvalidOperationException("Endpoint not set"); } m_isCoreLocal = connectionParams.IsCoreLocal; Log.Info("Connecting to Core running at {hostname:l}:{port}", endPoint.Hostname, endPoint.Port); ICoreLink coreLink = m_coreLinkFactory.Create(endPoint); // TODO(HonzaS): Check if the endpoint exists (handshake), await the response. // TODO(HonzaS): Move these inside the factory method. ICoreController coreController = m_coreControllerFactory.Create(coreLink); IModelUpdater modelUpdater = m_modelUpdaterFactory.Create(coreLink, coreController); CoreProxy = m_coreProxyFactory.Create(coreController, modelUpdater); RegisterCoreEvents(); }
public static List <ICoreProcess> LoadProcesses() { List <ICoreProcess> processesLoaded = new List <ICoreProcess>(); FileInfo executingAssemblyInfo = new FileInfo(Assembly.GetExecutingAssembly().Location); string path = executingAssemblyInfo.DirectoryName; string reportsPath = executingAssemblyInfo.DirectoryName + @"\Reports\"; try { if (Directory.Exists(reportsPath)) { ICollection <Assembly> assemblies = new List <Assembly>(); string[] dllFileNames = Directory.GetFiles(reportsPath, "*.dll"); foreach (string dllFile in dllFileNames) { AssemblyName an = AssemblyName.GetAssemblyName(dllFile); Assembly assembly = Assembly.Load(an); assemblies.Add(assembly); } dllFileNames = Directory.GetFiles(path, "*.dll"); foreach (string dllFile in dllFileNames) { AssemblyName an = AssemblyName.GetAssemblyName(dllFile); try { Assembly assembly = Assembly.Load(an); assemblies.Add(assembly); } catch (FileLoadException) { } } Type reportType = typeof(ICoreProcess); ICollection <Type> reportTypes = new List <Type>(); foreach (Assembly assembly in assemblies) { if (assembly != null) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.IsInterface || type.IsAbstract) { continue; } if (type.GetInterface(reportType.FullName) != null) { reportTypes.Add(type); } } } } foreach (Type type in reportTypes) { ICoreProcess process = (ICoreProcess)Activator.CreateInstance(type); processesLoaded.Add(process); } } } catch (Exception e) { Emailer.SendEmail("*****@*****.**", "NoCoreDataReportService", "Process Loader", e); } return(processesLoaded); }
private void KillLocalCore() { // For remote core this is already null, for local core we have lost network contact with it. m_process?.Dispose(); m_process = null; }