internal static ScriptFile ParseFile(IAddonManager addonManager, string content) { if (addonManager == null) { addonManager = AddonManager.Create(); addonManager.AddAssembly(typeof(Math).Assembly, false); addonManager.AddAssembly(typeof(Enumerable).Assembly, false); } addonManager.AddAssembly(AddonManager.StepBroCoreAssembly, true); // Add StepBro.Core always. ITokenSource lexer = new Grammar.StepBroLexer(new AntlrInputStream(content)); ITokenStream tokens = new CommonTokenStream(lexer); var parser = new SBP(tokens); var file = new ScriptFile(); parser.RemoveErrorListeners(); parser.AddErrorListener(file.Errors as ErrorCollector); parser.BuildParseTree = true; var listener = new StepBroListener(file.Errors as ErrorCollector, addonManager, file); var context = parser.compilationUnit(); var walker = new ParseTreeWalker(); walker.Walk(listener, context); if (file.Errors.ErrorCount > 0) { throw new Exception("PARSING ERRORS: " + file.Errors[0].ToString()); } //file?.InitializeFileVariables(); return(file); }
public PanelView(IPanelPresenter presenter, IAddonManager addonManager, IPanelItemFactoryManager factoryManager) { InitializeComponent(); // init presenters m_Presenter = presenter; m_Presenter.View = this; m_AddonManager = addonManager; m_FactoryManager = factoryManager; // setup items cache var cache = new ListViewItemCache(this); //LV.CacheVirtualItems += m_Cache.CacheVirtualItems; LV.RetrieveVirtualItem += cache.RetrieveVirtualItem; // set dropdown direction for sub-menus (actual for dual-monitor system) //mComp.DropDownDirection = ToolStripDropDownDirection.AboveLeft; //mSendToNewTab.DropDownDirection = ToolStripDropDownDirection.AboveLeft; // focus listview when panel got focus GotFocus += (sender, args) => ActiveControl = LV; // set filter's presenter pFilter.Presenter = App.Resolve <IFilterPresenter>(); pFilter.Presenter.View = pFilter; }
public void TestLoadTestModule() { IAddonManager addons = AddonManager.Create(); var testFile = GetTestModulePath(); addons.LoadAssembly(testFile, false); var typeReference = addons.TryGetType(null, "TestModule.TestClassWithOnlyProperties"); Assert.IsNotNull(typeReference); typeReference = addons.TryGetType(null, "TestModule.SubNamespace.Deep.VeryDeep.MuchDeeper.TestClassInDeepNamespace"); Assert.IsNotNull(typeReference); typeReference = addons.TryGetType(null, "TestModule.SubNamespace.Deep.VeryDeep.MuchDeeper.TestClassInDeepNamespace.SubClass"); Assert.IsNotNull(typeReference); var usings = new UsingData[] { new UsingData(-1, addons.Lookup(null, "TestModule")) }; typeReference = addons.TryGetType(usings, "TestClassWithOnlyProperties"); Assert.IsNotNull(typeReference); Assert.AreEqual("TestClassWithOnlyProperties", typeReference.Name); typeReference = addons.TryGetType(usings, "SubNamespace.Deep.VeryDeep.MuchDeeper.TestClassInDeepNamespace.SubClass"); Assert.IsNotNull(typeReference); Assert.AreEqual("SubClass", typeReference.Name); usings = new UsingData[] { new UsingData(-1, addons.Lookup(null, "TestModule")), new UsingData(-1, addons.Lookup(null, "TestModule.SubNamespace.Deep")) }; typeReference = addons.TryGetType(usings, "VeryDeep.MuchDeeper.TestClassInDeepNamespace.SubClass"); Assert.IsNotNull(typeReference); Assert.AreEqual("SubClass", typeReference.Name); //var moduleClass = typeReference as ICodeModuleClass; //Assert.IsNotNull(moduleClass); }
internal static FileBuilder ParseProcedure( IAddonManager addonManager, string[] usings, Type usingType, params string[] content) { if (addonManager == null) { addonManager = AddonManager.Create(); addonManager.AddAssembly(typeof(Math).Assembly, false); addonManager.AddAssembly(typeof(Enumerable).Assembly, false); } addonManager.AddAssembly(AddonManager.StepBroCoreAssembly, true); // Add StepBro.Core always. if (usingType != null) { addonManager.AddAssembly(usingType.Assembly, false); } var contentBuilder = new StringBuilder(); foreach (var s in content) { contentBuilder.AppendLine(s); } var file = new ScriptFile(); file.AddNamespaceUsing(-1, addonManager.Lookup(null, "System")); file.AddNamespaceUsing(-1, addonManager.Lookup(null, "System.Linq")); file.AddNamespaceUsing(-1, addonManager.Lookup(null, typeof(StepBro.Core.DataReport).Namespace)); if (usings != null) { foreach (var u in usings) { file.AddNamespaceUsing(-1, addonManager.Lookup(null, u)); } } if (usingType != null) { file.AddNamespaceUsing(-1, addonManager.Lookup(null, usingType.Namespace)); } var builder = new FileBuilder(new AntlrInputStream(contentBuilder.ToString()), addonManager, file); builder.Listener.PrepareForExpressionParsing("StepBroFileBuilder.ParseExpression"); var context = builder.Parser.procedureDeclaration(); var walker = new ParseTreeWalker(); walker.Walk(builder.Listener, context); if (file.Errors.ErrorCount > 0) { throw new Exception("PARSING ERRORS"); } return(builder); }
public override void Init(IAddonManager addonManager) { base.Init(addonManager); SetupTimers(); OnAgentResponseHandler += OnAgentResponse; }
[Ignore] // Enable again when some extension methods actually are added. public void TestExtensionMethods() { var usings = new string[] { "StepBro.Core.Execution" }; IAddonManager addons = AddonManager.Create(); addons.AddAssembly(AddonManager.StepBroCoreAssembly, false); var methods = addons.ListExtensionMethods( typeof(IProcedureReference)).Where(mi => mi.Name == "DynamicInvoke").ToList(); Assert.AreEqual(1, methods.Count); Assert.AreEqual("DynamicInvoke", methods[0].Name); }
internal static FileBuilder ParseExpression(ScriptFile fileContext, IAddonManager addons, string expression) { var builder = new FileBuilder(new AntlrInputStream(expression), addons, fileContext); builder.Listener.PrepareForExpressionParsing("StepBroFileBuilder.ParseExpression"); var context = builder.Parser.parExpression(); var walker = new ParseTreeWalker(); walker.Walk(builder.Listener, context); return(builder); }
public void TestPeakCANModuleLoad() { IAddonManager addons = AddonManager.Create(); var baseDir = GetBasePath(); var canFile = System.IO.Path.Combine(baseDir, "modules\\StepBro.CAN.dll"); addons.LoadAssembly(canFile, true); var pcanFile = System.IO.Path.Combine(baseDir, "modules\\StepBro.PeakCANPlugin.dll"); addons.LoadAssembly(pcanFile, true); }
public override void Init(IAddonManager addonManager) { base.Init(addonManager); _temperatureTopic = "Stats/CPU/Temperature"; GetManager().PublishDiscoveryMessage(this, _temperatureTopic, "CPU", new HassDiscoveryOptions { Id = "Temperature", Unit = "°C", Name = "Temperature", Component = HomeAssistantComponent.Sensor, Icon = "mdi:thermometer" }); _monitorTimer = new Timer(); _monitorTimer.Interval = 10000; _monitorTimer.Elapsed += TimerElapsed; _monitorTimer.Start(); }
internal FileBuilder(AntlrInputStream code, IAddonManager addons = null, ScriptFile file = null) { m_file = file; m_errors = new ErrorCollector(file, false); var lexer = new Grammar.StepBroLexer(code); lexer.RemoveErrorListeners(); lexer.AddErrorListener(m_errors); ITokenStream tokens = new CommonTokenStream(lexer); m_parser = new SBP(tokens); m_parser.RemoveErrorListeners(); m_parser.AddErrorListener(m_errors); #if DEBUG m_parser.Interpreter.PredictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION; #endif m_parser.BuildParseTree = true; m_listener = new StepBroListener(m_errors, addons, file); }
public void TestExtensionMethodBrowsing() { var usings = new string[] { "System", "System.Linq" }; IAddonManager addons = AddonManager.Create(); addons.AddAssembly(typeof(System.Linq.Enumerable).Assembly, false); var methods = new List <System.Reflection.MethodInfo>( addons.ListExtensionMethods( typeof(IEnumerable <int>)).Where(mi => mi.Name == "Select")); Assert.IsTrue(methods.Select(mi => mi.Name).Contains("Select")); methods = new List <System.Reflection.MethodInfo>( addons.ListExtensionMethods( typeof(List <int>)).Where(mi => mi.Name == "Select")); Assert.IsTrue(methods.Select(mi => mi.Name).Contains("Select")); }
internal static void DeinitializeInternal(bool reset) { m_loadedFilesManager.UnloadAllFilesWithoutDependants(); TaskContextDummy taskContext = new TaskContextDummy(); m_serviceManagerAdmin.StopServices(taskContext, reset); if (reset) { m_serviceManagerAdmin = null; m_mainLogger = null; m_loadedFilesManager = null; m_addonManager = null; m_logSinkManager = null; m_scriptExecutionManager = null; m_dynamicObjectManager = null; m_uiCalculator = null; m_serviceManagerAdmin = ServiceManager.Create(); } }
public override void Init(IAddonManager addonManager) { base.Init(addonManager); GetManager().SubscribeTopic(this, "audio/volume", OnAudioVolumeSetMessage); GetManager().SubscribeTopic(this, "audio/mute", OnAudioMuteMessage); GetManager().SubscribeTopic(this, "audio/default", OnAudioSetDefaultMessage); GetManager().SubscribeTopic(this, "audio/default-comms", OnAudioSetDefaultCommsMessage); GetManager().PublishDiscoveryMessage(this, _audioTopic, "Volume", new HassDiscoveryOptions { Id = "Volume", Name = "Volume", Component = HomeAssistantComponent.Sensor, Icon = "mdi:volume-high" }); _monitorTimer = new Timer(); _monitorTimer.Interval = 10000; _monitorTimer.Elapsed += TimerElapsed; _monitorTimer.Start(); }
public MainForm(IAddonManager addonManager, IPanelItemFactoryManager factoryManager) { InitializeComponent(); m_AddonManager = addonManager; m_FactoryManager = factoryManager; if (App.TR.RightToLeft) { RightToLeftLayout = true; RightToLeft = RightToLeft.Yes; } Menu = MainMenu; // show computer name lCompName.Text = SystemInformation.ComputerName; lCompName.ImageIndex = App.Images.IndexOf(PanelImageNames.COMPUTER); // show current user lUserName.Text = SystemInformation.UserName; lUserName.ImageIndex = App.Images.IndexOf(PanelImageNames.USER); }
public override void Init(IAddonManager addonManager) { base.Init(addonManager); OnAgentRequestHandler += OnAgentRequest; }
public static FileBuilder Parse <T>( string returnValueExpression = "0", string statements = "", bool varGeneration = true, bool varDummyClass = false) { string typeName = ""; if (typeof(T) == typeof(long)) { typeName = "int"; } else if (typeof(T) == typeof(double)) { typeName = "decimal"; } else if (typeof(T) == typeof(bool)) { typeName = "bool"; } else if (typeof(T) == typeof(string)) { typeName = "string"; } else if (typeof(T) == typeof(TimeSpan)) { typeName = "timespan"; } else if (typeof(T) == typeof(DateTime)) { typeName = "datetime"; } else if (typeof(T) == typeof(Verdict)) { typeName = "verdict"; } else if (typeof(T) == typeof(DummyDataClass)) { typeName = "DummyDataClass"; } else if (typeof(T) == typeof(DataReport)) { typeName = "DataReport"; } else { throw new NotImplementedException(); } StringBuilder source = new StringBuilder(); source.AppendLine(typeName + " ExpressionProcedure(){"); if (varGeneration || varDummyClass) { AddLocalVariables(source, varDummyClass); } source.AppendLine(statements); source.AppendLine(typeName + " result = " + returnValueExpression + ";"); source.AppendLine("return result;"); source.AppendLine("}"); IAddonManager addons = AddonManager.Create(); addons.AddAssembly(typeof(Enumerable).Assembly, false); addons.AddAssembly(typeof(ExpressionParser).Assembly, false); return(FileBuilder.ParseProcedure( addons, new string[] { typeof(DataReport).Namespace, typeof(DummyClass).FullName, typeof(DummyClass).Namespace }, null, source.ToString())); }
public SafeguardDevOpsService() { CheckGenerateUniqueIdentifier(); var webSslCert = CheckDefaultCertificate(); if (webSslCert == null) { Log.Logger.Error("Failed to find or change the default SSL certificate."); Environment.Exit(1); } if (bool.Parse(Environment.GetEnvironmentVariable("DOCKER_RUNNING") ?? "false")) { Log.Logger.Information("Running in Docker container"); if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DOCKER_HOST_IP"))) { var hostEntry = Dns.GetHostEntry("host.docker.internal"); Log.Logger.Information($"Using host.docker.internal IP: {hostEntry.AddressList[0]}"); Environment.SetEnvironmentVariable("DOCKER_HOST_IP", hostEntry.AddressList[0].ToString()); } Log.Logger.Information($"Docker host IP: {Environment.GetEnvironmentVariable("DOCKER_HOST_IP")}"); } Log.Logger.Information($"Thumbprint for {webSslCert.Subject}: {webSslCert.Thumbprint}"); Log.Logger.Information(webSslCert.ToPemFormat()); Log.Logger.Information($"Configuration file location: {WellKnownData.AppSettingsFile}"); var configuration = new ConfigurationBuilder() .AddJsonFile(WellKnownData.AppSettingsFile, optional: true, reloadOnChange: true) .AddEnvironmentVariables() .Build(); var httpsPort = configuration["HttpsPort"] ?? WellKnownData.DefaultServicePort; var logLevel = configuration["LogLevel"]; if (logLevel != null) { if (Enum.TryParse(logLevel, out DevOpsLogLevel level)) { var logLevelSwitch = LogLevelSwitcher.Instance.LogLevelSwitch; switch (level) { case DevOpsLogLevel.Information: logLevelSwitch.MinimumLevel = LogEventLevel.Information; break; case DevOpsLogLevel.Debug: logLevelSwitch.MinimumLevel = LogEventLevel.Debug; break; case DevOpsLogLevel.Error: logLevelSwitch.MinimumLevel = LogEventLevel.Error; break; case DevOpsLogLevel.Warning: logLevelSwitch.MinimumLevel = LogEventLevel.Warning; break; case DevOpsLogLevel.Fatal: logLevelSwitch.MinimumLevel = LogEventLevel.Fatal; break; case DevOpsLogLevel.Verbose: logLevelSwitch.MinimumLevel = LogEventLevel.Verbose; break; } } else { Log.Logger.Error($"{logLevel} is not not a recognized log level. Continuing to use the default log level."); } } _host = new WebHostBuilder() .UseSerilog() .UseKestrel(options => { if (int.TryParse(httpsPort, out var port) == false) { Log.Logger.Warning($"Failed to parse HttpsPort from appsettings.json '{httpsPort}'"); port = int.Parse(WellKnownData.DefaultServicePort); } Log.Logger.Information($"Binding web server to port: {port}."); options.ListenAnyIP(port, listenOptions => { listenOptions.UseHttps(webSslCert); }); }) .ConfigureServices(services => services.AddAutofac()) .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup <Startup>() .Build(); _monitoringLogic = (IMonitoringLogic)_host.Services.GetService(typeof(IMonitoringLogic)); _pluginManager = (IPluginManager)_host.Services.GetService(typeof(IPluginManager)); _addonManager = (IAddonManager)_host.Services.GetService(typeof(IAddonManager)); }
public static void Initialize(IEnumerable <IService> hostServices = null) { IService service; m_mainLogger = new MainLogger(out service); m_rootLogger = m_mainLogger.Logger.RootLogger; m_serviceManagerAdmin.Manager.Register(service); m_loadedFilesManager = new LoadedFilesManager(out service); m_serviceManagerAdmin.Manager.Register(service); m_addonManager = new AddonManager( (IAddonManager m) => { // **** LOAD THE ADDON MODULES **** m.AddAssembly(typeof(DateTime).Assembly, false); m.AddAssembly(typeof(Enumerable).Assembly, false); m.AddAssembly(typeof(Math).Assembly, false); m.AddAssembly(AddonManager.StepBroCoreAssembly, true); var modulesFolder = Path.Combine(Path.GetDirectoryName(typeof(AddonManager).Assembly.Location), "Modules"); foreach (var f in Directory.GetFiles(modulesFolder, "*.dll")) { m.LoadAssembly(f, false); } }, out service); m_serviceManagerAdmin.Manager.Register(service); m_logSinkManager = new LogSinkManager(out service); m_serviceManagerAdmin.Manager.Register(service); m_taskManager = new TaskManager(out service); m_serviceManagerAdmin.Manager.Register(service); m_hostActions = new HostApplicationActionQueue(out service); m_serviceManagerAdmin.Manager.Register(service); m_scriptExecutionManager = new ScriptExecutionManager(out service); m_serviceManagerAdmin.Manager.Register(service); m_dynamicObjectManager = new DynamicObjectManager(out service); m_serviceManagerAdmin.Manager.Register(service); m_uiCalculator = new UICalculator(out service); m_serviceManagerAdmin.Manager.Register(service); if (hostServices != null) { foreach (var hs in hostServices) { m_serviceManagerAdmin.Manager.Register(hs); } } TaskContextDummy taskContext = new TaskContextDummy(); try { m_serviceManagerAdmin.StartServices(taskContext); } catch (Exception ex) { // Roll back (stop) the services that actually did start. try { m_serviceManagerAdmin.StopServices(taskContext); } catch { /* Ignore exceptions during stop */ } throw new Exception("Failed to start all services. " + ex.GetType().Name + ", " + ex.ToString()); } m_initialized = true; m_initIndex++; }