Example #1
0
        private static ViewType[] ReadAvailableViewTypes(string absoluteBaseDir, string bundlesPrefx, string[] viewAssemblies)
        {
            var viewTypes = Reflect.GetAllNonAbstractSubclasses(typeof(ViewBase)).ToList();

            viewTypes.AddRange(viewAssemblies.SelectMany(LoadTypesFromAssemblyFile));

            var result = new List <ViewType>();

            foreach (Type type in viewTypes)
            {
                Identify?id = type.GetCustomAttribute <Identify>();
                if (id != null)
                {
                    string viewBundle     = "ViewBundle_" + id.Bundle;
                    string viewBundlePath = Path.Combine(absoluteBaseDir, viewBundle);
                    bool   url            = type == typeof(View_ExtURL);
                    if (url || Directory.Exists(viewBundlePath))
                    {
                        var vt = new ViewType()
                        {
                            Name     = id.ID,
                            HtmlPath = $"/{bundlesPrefx}/" + viewBundle + "/" + id.Path, // "/" + dir.Name + "/" + indexFile,
                            Type     = type,
                            Icon     = id.Icon ?? ""
                        };
                        result.Add(vt);
                    }
                    else
                    {
                        logWarn($"No ViewBundle folder found for View {id.ID} in {absoluteBaseDir}");
                    }
                }
            }
            return(result.ToArray());
        }
Example #2
0
        public override Task OnActivate()
        {
            if (Config.NonEmpty)
            {
                configuration = Config.Object <Config>() ?? new Config();
                // configuration = Example.Get();
            }

            widgetTypes = Reflect
                          .GetAllNonAbstractSubclasses(typeof(WidgetBase))
                          .Where(t => t.GetCustomAttribute <IdentifyWidget>() != null)
                          .ToImmutableDictionary(t => t.GetCustomAttribute <IdentifyWidget>() !.ID);

            foreach (var page in configuration.Pages)
            {
                Pages[page.ID] = new PageState(page, Connection, widgetTypes, this);
            }

            return(Task.FromResult(true));
        }
Example #3
0
        public override async Task Init(ModuleInitInfo info, VariableValue[] restoreVariableValues, Notifier notifier, ModuleThread moduleThread)
        {
            this.moduleThread = moduleThread;
            this.initInfo     = info;
            this.moduleConfig = info.GetConfigReader();

            await base.Init(info, restoreVariableValues, notifier, moduleThread);

            string strAssemblies = moduleConfig.GetOptionalString("adapter-assemblies", "");

            const string releaseDebugPlaceHolder = "{RELEASE_OR_DEBUG}";

            if (strAssemblies.Contains(releaseDebugPlaceHolder))
            {
#if DEBUG
                strAssemblies = strAssemblies.Replace(releaseDebugPlaceHolder, "Debug");
#else
                strAssemblies = strAssemblies.Replace(releaseDebugPlaceHolder, "Release");
#endif
            }

            string[] assemblies = strAssemblies
                                  .Split(new char[] { ';', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
                                  .Select(s => s.Trim())
                                  .ToArray();

            string[] absoluteAssemblies = assemblies.Select(d => Path.GetFullPath(d)).ToArray();
            foreach (string assembly in absoluteAssemblies)
            {
                if (!File.Exists(assembly))
                {
                    throw new Exception($"calculation-assembly does not exist: {assembly}");
                }
            }

            var adapterTypes = Reflect.GetAllNonAbstractSubclasses(typeof(CalculationBase)).ToList();
            adapterTypes.AddRange(absoluteAssemblies.SelectMany(fLoadCalcTypesFromAssembly));

            adapterTypesAttribute.Clear();
            mapAdapterTypes.Clear();
            foreach (Type type in adapterTypes)
            {
                Identify?id = type.GetCustomAttribute <Identify>();
                if (id != null)
                {
                    mapAdapterTypes[id.ID] = type;
                    adapterTypesAttribute.Add(id);
                }
            }

            foreach (CalcInstance adapter in adapters)
            {
                adapter.CreateInstance(mapAdapterTypes);
            }

            Dictionary <VariableRef, VTQ> varMap = restoreVariableValues.ToDictionary(v => v.Variable, v => v.Value);
            foreach (CalcInstance adapter in adapters)
            {
                adapter.SetInitialOutputValues(varMap);
                adapter.SetInitialStateValues(varMap);
            }

            try {
                Task[] initTasks = adapters.Select(InitAdapter).ToArray();
                await Task.WhenAll(initTasks);
            }
            catch (Exception exp) {
                string[] failedAdapters = adapters
                                          .Where(a => a.State == State.InitError)
                                          .Select(a => "Init of calculation '" + a.CalcConfig.Name + "' failed: " + a.LastError)
                                          .ToArray();

                string errMessage = failedAdapters.Length > 0 ? string.Join("; ", failedAdapters) : exp.Message;
                Console.Error.WriteLine(errMessage);
                await Shutdown();

                throw new Exception(errMessage);
            }
        }
Example #4
0
        public override async Task Init(ModuleInitInfo info, VariableValue[] restoreVariableValues, Notifier notifier, ModuleThread moduleThread)
        {
            this.moduleThread = moduleThread;
            await base.Init(info, restoreVariableValues, notifier, moduleThread);

            var config = info.GetConfigReader();

            string strAssemblies = config.GetOptionalString("adapter-assemblies", "");

            const string releaseDebugPlaceHolder = "{RELEASE_OR_DEBUG}";

            if (strAssemblies.Contains(releaseDebugPlaceHolder))
            {
#if DEBUG
                strAssemblies = strAssemblies.Replace(releaseDebugPlaceHolder, "Debug");
#else
                strAssemblies = strAssemblies.Replace(releaseDebugPlaceHolder, "Release");
#endif
            }

            string[] assemblies = strAssemblies.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            string[] absoluteAssemblies = assemblies.Select(d => Path.GetFullPath(d)).ToArray();
            foreach (string assembly in absoluteAssemblies)
            {
                if (!File.Exists(assembly))
                {
                    throw new Exception($"adapter-assembly does not exist: {assembly}");
                }
            }

            foreach (VariableValue v in restoreVariableValues)
            {
                string dataItemID = v.Variable.Object.LocalObjectID;
                if (dataItemsState.ContainsKey(dataItemID))
                {
                    dataItemsState[dataItemID].LastReadValue = v.Value;
                }
            }

            var adapterTypes = Reflect.GetAllNonAbstractSubclasses(typeof(AdapterBase)).ToList();
            adapterTypes.AddRange(absoluteAssemblies.SelectMany(fLoadAdaptersFromAssembly));

            mapAdapterTypes.Clear();
            foreach (var type in adapterTypes)
            {
                Identify id = type.GetCustomAttribute <Identify>();
                if (id != null)
                {
                    mapAdapterTypes[id.ID] = type;
                }
            }

            foreach (AdapterState adapter in adapters)
            {
                adapter.CreateInstance(mapAdapterTypes);
            }

            try {
                Task[] initTasks = adapters.Select(InitAdapter).ToArray();
                await Task.WhenAll(initTasks);
            }
            catch (Exception exp) {
                string[] failedAdapters = adapters
                                          .Where(a => a.State == State.InitError)
                                          .Select(a => "Init of IO adapter '" + a.Config.Name + "' failed: " + a.LastError)
                                          .ToArray();

                string errMessage = failedAdapters.Length > 0 ? string.Join("; ", failedAdapters) : exp.Message;
                Console.Error.WriteLine(errMessage);
                await Shutdown();

                throw new Exception(errMessage);
            }
        }